Ver Fonte

Change no_set_check parameter name. Move Python wrap to separate directory.

Vasilii Chernov há 8 anos atrás
pai
commit
d7fc669bf0
12 ficheiros alterados com 231 adições e 32 exclusões
  1. 1 0
      CMakeLists.txt
  2. 1 12
      pcilib/CMakeLists.txt
  3. 1 1
      pcilib/pcilib.h
  4. 4 4
      pcilib/py.c
  5. 11 8
      pcilib/xml.c
  6. 1 1
      pcitool/cli.c
  7. 22 0
      pywrap/CMakeLists.txt
  8. 3 3
      pywrap/pcipywrap.c
  9. 1 1
      pywrap/pcipywrap.i
  10. 184 0
      pywrap/server.py
  11. 1 1
      xml/test_pywrap/props.xml
  12. 1 1
      xml/types.xsd

+ 1 - 0
CMakeLists.txt

@@ -79,6 +79,7 @@ add_subdirectory(dma)
 add_subdirectory(protocols)
 add_subdirectory(views)
 add_subdirectory(pcilib)
+add_subdirectory(pywrap)
 add_subdirectory(pcitool)
 add_subdirectory(apps)
 add_subdirectory(xml)

+ 1 - 12
pcilib/CMakeLists.txt

@@ -9,21 +9,10 @@ include_directories(
 )
 
 set(HEADERS pcilib.h pci.h datacpy.h memcpy.h pagecpy.h cpu.h timing.h export.h value.h bar.h fifo.h model.h bank.h register.h view.h property.h unit.h xml.h py.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h)
-add_library(pcilib SHARED pci.c pcipywrap.c datacpy.c memcpy.c pagecpy.c cpu.c timing.c export.c value.c bar.c fifo.c model.c bank.c register.c view.c unit.c property.c xml.c py.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c )
+add_library(pcilib SHARED pci.c datacpy.c memcpy.c pagecpy.c cpu.c timing.c export.c value.c bar.c fifo.c model.c bank.c register.c view.c unit.c property.c xml.c py.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c )
 target_link_libraries(pcilib dma protocols views ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES})
 add_dependencies(pcilib dma protocols views)
 
-#Creating python wrapping
-INCLUDE(${SWIG_USE_FILE})
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-
-SET(CMAKE_SWIG_FLAGS "")
-
-SET_SOURCE_FILES_PROPERTIES(pcipywrap.i PROPERTIES SWIG_FLAGS "-includeall")
-SWIG_ADD_MODULE(pcipywrap python pcipywrap.i)
-SWIG_LINK_LIBRARIES(pcipywrap ${PYTHON_LIBRARIES} pcilib)
-
 install(TARGETS pcilib
     LIBRARY DESTINATION lib${LIB_SUFFIX}
 )

+ 1 - 1
pcilib/pcilib.h

@@ -54,7 +54,7 @@ typedef enum {
     PCILIB_REGISTER_RW1C = 5,
     PCILIB_REGISTER_W1I = 8,			/**< writting 1 inversts the bit, writting 0 keeps the value */
     PCILIB_REGISTER_RW1I = 9,
-    PCILIB_REGISTER_NO_CHK = 16		/**< dont check register value after set*/
+    PCILIB_REGISTER_INCONSISTENT = 0x1000		/**< dont check register value after set*/
 } pcilib_register_mode_t;
 
 typedef enum {

+ 4 - 4
pcilib/py.c

@@ -293,15 +293,15 @@ int pcilib_init_py_script(pcilib_t *ctx, char* module_name, pcilib_script_t **mo
 	char* pcipywrap_path;
 	if(app_dir)
 	{
-		pcipywrap_path = malloc(strlen(app_dir) + strlen("/pcilib"));
+		pcipywrap_path = malloc(strlen(app_dir) + strlen("/pywrap"));
 		if (!pcipywrap_path) return PCILIB_ERROR_MEMORY;
-		sprintf(pcipywrap_path, "%s/%s", "/pcilib", ctx->model);
+		sprintf(pcipywrap_path, "%s/%s", "/pywrap", ctx->model);
 	}
 	else
 	{
-		pcipywrap_path = malloc(strlen("./pcilib"));
+		pcipywrap_path = malloc(strlen("./pywrap"));
 		if (!pcipywrap_path) return PCILIB_ERROR_MEMORY;
-		sprintf(pcipywrap_path, "%s", "./pcilib");
+		sprintf(pcipywrap_path, "%s", "./pywrap");
 
 	}
 	

+ 11 - 8
pcilib/xml.c

@@ -493,7 +493,7 @@ static int pcilib_xml_parse_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDoc
     xmlAttrPtr cur;
     const char *value, *name;
     
-    int register_no_chk = 0;
+    int register_incosistent = 0;
 
     for (cur = node->properties; cur != NULL; cur = cur->next) {
         if (!cur->children) continue;
@@ -541,14 +541,17 @@ static int pcilib_xml_parse_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDoc
                 return PCILIB_ERROR_INVALID_DATA;
             }
         }
-		else if (!strcasecmp(name, "no_set_check")) {
-			if (!strcasecmp(value, "1"))
-				register_no_chk = 1;
+		else if (!strcasecmp(name, "write_verification")) {
+			if (!strcasecmp(value, "0"))
+			{
+				register_incosistent = 1;
+			}
 		}
 	}
-	if(register_no_chk)
+	
+	if(register_incosistent)
 	{
-		desc->mode |= PCILIB_REGISTER_NO_CHK;
+		desc->mode |= PCILIB_REGISTER_INCONSISTENT;
 	}
 
     return 0;
@@ -560,7 +563,7 @@ static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xp
     const char *value, *name;
     pcilib_view_context_t *view_ctx;
 
-    pcilib_access_mode_t mode = PCILIB_REGISTER_NO_CHK;
+    pcilib_access_mode_t mode = PCILIB_REGISTER_INCONSISTENT;
     pcilib_transform_view_description_t desc = {{0}};
 
     desc.base.api = &pcilib_transform_view_api;
@@ -603,7 +606,7 @@ static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xp
 			
 			err = pcilib_init_py_script(ctx, script_name, &(desc.script), &mode);
 			if(err) return err;
-			mode |= PCILIB_REGISTER_NO_CHK;
+			mode |= PCILIB_REGISTER_INCONSISTENT;
 			break;
         }
     }

+ 1 - 1
pcitool/cli.c

@@ -1706,7 +1706,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info
 	    err = pcilib_read_register(handle, bank, reg, &verify);
 	    if (err) Error("Error reading back register %s for verification\n", reg);
 		
-	    if (!((model_info->registers[regid].mode&PCILIB_REGISTER_NO_CHK) ==  PCILIB_REGISTER_NO_CHK) && 
+	    if (!((model_info->registers[regid].mode&PCILIB_REGISTER_INCONSISTENT) ==  PCILIB_REGISTER_INCONSISTENT) && 
 	        verify != value) {
 	        Error("Failed to write register %s: %lu is written and %lu is read back", reg, value, verify);
 	    } else {

+ 22 - 0
pywrap/CMakeLists.txt

@@ -0,0 +1,22 @@
+include_directories(
+    ${CMAKE_SOURCE_DIR}
+    ${CMAKE_BINARY_DIR}
+    ${CMAKE_SOURCE_DIR}/pcilib
+    ${CMAKE_BINARY_DIR}/pcilib
+    ${LIBXML2_INCLUDE_DIRS}
+    ${PYTHON_INCLUDE_DIR}
+    ${UTHASH_INCLUDE_DIRS}
+)
+
+#Creating python wrapping
+INCLUDE(${SWIG_USE_FILE})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+SET(CMAKE_SWIG_FLAGS "")
+
+SET_SOURCE_FILES_PROPERTIES(pcipywrap.i PROPERTIES SWIG_FLAGS "-includeall")
+SWIG_ADD_MODULE(pcipywrap python pcipywrap.i pcipywrap.c)
+SWIG_LINK_LIBRARIES(pcipywrap ${PYTHON_LIBRARIES} pcilib)
+
+configure_file(server.py server.py)

+ 3 - 3
pcilib/pcipywrap.c → pywrap/pcipywrap.c

@@ -341,7 +341,7 @@ PyObject * pcilib_convert_property_info_to_pyobject(pcilib_property_info_t listI
         PyList_Append(modes, PyString_FromString("W"));
     if((listItem.mode & PCILIB_ACCESS_RW ) == PCILIB_REGISTER_RW)
         PyList_Append(modes, PyString_FromString("RW"));
-    if((listItem.mode & PCILIB_REGISTER_NO_CHK) == PCILIB_REGISTER_NO_CHK)
+    if((listItem.mode & PCILIB_REGISTER_INCONSISTENT) == PCILIB_REGISTER_INCONSISTENT)
         PyList_Append(modes, PyString_FromString("NO_CHK"));
 
     PyDict_SetItem(pylistItem,
@@ -402,7 +402,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_register_info_t listI
         PyList_Append(modes, PyString_FromString("W1I"));
     if((listItem.mode & PCILIB_REGISTER_RW1I) == PCILIB_REGISTER_RW1I)
         PyList_Append(modes, PyString_FromString("RW1I"));
-    if((listItem.mode & PCILIB_REGISTER_NO_CHK) == PCILIB_REGISTER_NO_CHK)
+    if((listItem.mode & PCILIB_REGISTER_INCONSISTENT) == PCILIB_REGISTER_INCONSISTENT)
         PyList_Append(modes, PyString_FromString("NO_CHK"));
 
     PyDict_SetItem(pylistItem,
@@ -471,7 +471,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_register_info_t listI
     return pylistItem;
 }
 
-PyObject* get_register_list(const char *bank)
+PyObject* get_registers_list(const char *bank)
 {
 	if(!__ctx)
 	{

+ 1 - 1
pcilib/pcipywrap.i → pywrap/pcipywrap.i

@@ -15,7 +15,7 @@ extern PyObject* write_register(PyObject* val, const char *regname, const char *
 extern PyObject* get_property(const char *prop);
 extern PyObject* set_property(const char *prop, PyObject* val);
 
-extern PyObject* get_register_list(const char *bank = NULL);
+extern PyObject* get_registers_list(const char *bank = NULL);
 extern PyObject* get_register_info(const char* reg,const char *bank = NULL);
 
 extern PyObject* get_property_info(const char* branch = NULL);

+ 184 - 0
pywrap/server.py

@@ -0,0 +1,184 @@
+import time
+import os #delete later
+import pcipywrap
+import json
+import BaseHTTPServer
+
+class PcilibServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+	
+   def do_HEAD(s):
+      s.send_response(200)
+      s.send_header('content-type', 'application/json')
+      s.end_headers()
+      
+   def do_GET(s):
+      length = int(s.headers['Content-Length'])
+      
+      #deserialize input data
+      data = json.loads(s.rfile.read(length).decode('utf-8'))
+      
+      if 'command' in data:
+         command = data['command']
+         if(command == 'help'):
+            s.help(data)
+                     
+         elif(command == 'open'):
+            #check required arguments
+            if not 'device' in data:
+               s.error('message doesnt contains "device" field, '
+                       'which is required for "open" command', data)
+               return
+            #parse command arguments and convert them to string
+            device = str(data.get('device', None))
+            model = data.get('model', None)
+            if not model is None:
+				model = str(model)
+            
+            try:
+               s.openPcilibInstance(device, model)
+            except Exception as e:
+               s.error(str(e), data) 
+               return
+		
+            #Success! Create and send reply
+            s.send_response(200)
+            s.send_header('content-type', 'application/json')
+            s.end_headers()
+            out = dict()
+            out['status'] = 'ok'
+            s.wrapMessageAndSend(out, data)
+                   
+         elif(command == 'get_registers_list'):
+            #parse command arguments and convert them to string
+            bank = data.get('bank', None)
+            if not bank is None:
+               bank = str(bank)
+
+            registers = dict()
+            try:
+               registers = pcipywrap.get_registers_list(bank)
+            except Exception as e:
+               s.error(str(e), data) 
+               return
+               
+            #Success! Create and send reply
+            s.send_response(200)
+            s.send_header('content-type', 'application/json')
+            s.end_headers()
+            out = dict()
+            out['status'] = 'ok'
+            out['registers'] = registers
+            s.wrapMessageAndSend(out, data)
+            
+       	 elif(command == 'get_register_info'):
+       	    #check required arguments
+            if not 'reg' in data:
+               s.error('message doesnt contains "reg" field, '
+                       'which is required for "get_register_info" command', data)
+               return
+               
+            #parse command arguments and convert them to string
+            reg = str(data.get('reg', None))
+            bank = data.get('bank', None)
+            if not bank is None:
+				bank = str(bank)
+            
+            register = dict()
+            try:
+               register = pcipywrap.get_register_info(reg, bank)
+            except Exception as e:
+               s.error(str(e), data) 
+               return
+		
+            #Success! Create and send reply
+            s.send_response(200)
+            s.send_header('content-type', 'application/json')
+            s.end_headers()
+            out = dict()
+            out['status'] = 'ok'
+            out['register'] = register
+            s.wrapMessageAndSend(out, data)
+		 
+         elif(command == 'get_property_info'):   
+            #parse command arguments and convert them to string
+            branch = data.get('branch', None)
+            if not branch is None:
+				branch = str(bank)
+            
+            properties = dict()
+            try:
+               properties = pcipywrap.get_property_info(branch)
+            except Exception as e:
+               s.error(str(e), data) 
+               return
+            	
+            #Success! Create and send reply
+            s.send_response(200)
+            s.send_header('content-type', 'application/json')
+            s.end_headers()
+            out = dict()
+            out['status'] = 'ok'
+            out['properties'] = properties
+            s.wrapMessageAndSend(out, data)
+            	
+         else:
+		    s.error('command "' + command + '" undefined', data)
+		    return
+      else:
+		  s.error('message doesnt contains "command" field, which is required', data)
+		  return
+		  
+       
+      #print str(s.headers['content-type'])
+      #print post_data['some']
+      
+   """open device context """
+   def openPcilibInstance(s, device, model):
+      pcipywrap.closeCurrentPcilibInstance()
+      
+      lib = pcipywrap.createPcilibInstance(device, model)
+      pcipywrap.setPcilib(lib)
+         
+   """Send help message"""
+   def help(s, received_message = None):
+      s.send_response(200)
+      s.send_header('content-type', 'application/json')
+      s.end_headers()
+      out = {'status': 'ok', 'help' : 'under construction'}
+      s.wrapMessageAndSend(out, received_message)
+   
+   """Send error message with text description"""     
+   def error(s, info, received_message = None):
+      s.send_response(400)
+      s.send_header('content-type', 'application/json')
+      s.end_headers()
+      out = dict()
+      
+      out['status'] = 'error'
+      out['description'] = info
+      out['note'] = 'send {"command" : "help"} to get help'
+      s.wrapMessageAndSend(out, received_message)
+        
+   def wrapMessageAndSend(s, message, received_message = None):
+      if not received_message is None:
+         message['received_message'] = received_message
+      s.wfile.write(json.dumps(message))
+
+HOST_NAME = '' # !!!REMEMBER TO CHANGE THIS!!!
+PORT_NUMBER = 12412 # Maybe set this to 9000.
+
+if __name__ == '__main__':
+   #initialize variables test (to remove)
+   os.environ["APP_PATH"] = '/home/vchernov/1215N/pcitool'
+   os.environ["PCILIB_MODEL_DIR"] = os.environ["APP_PATH"] + "/xml"
+   os.environ["LD_LIBRARY_PATH"] = os.environ["APP_PATH"] + "/pcilib"
+   
+   pcilib_server = BaseHTTPServer.HTTPServer
+   httpd = pcilib_server((HOST_NAME, PORT_NUMBER), PcilibServerHandler)
+   print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
+   try:
+      httpd.serve_forever()
+   except KeyboardInterrupt:
+      pass
+   httpd.server_close()
+   print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)

+ 1 - 1
xml/test_pywrap/props.xml

@@ -10,7 +10,7 @@
 	  unit="C"
 	  script="test_prop2.py"
 	  description="test python script #1"
-	  no_set_check="1"/>
+	  write_verification="0"/>
   <transform path="/test/prop3"
 	  register="test_prop3"
 	  unit="C"

+ 1 - 1
xml/types.xsd

@@ -59,7 +59,7 @@
     <xsd:attribute name="unit" type="xsd:string" />
     <xsd:attribute name="type" type="pcilib_data_type_t" />
     <xsd:attribute name="mode" type="pcilib_access_mode_t" />
-    <xsd:attribute name="no_set_check" type="bool_t" default="0"/>
+    <xsd:attribute name="write_verification" type="bool_t" default="1"/>
     <xsd:attribute name="visible" type="bool_t" default="0" />
     <xsd:attribute name="description" type="xsd:string" />
   </xsd:complexType>