modbus extension code cleanup, from smarteh's patch
authorEdouard Tisserant
Tue, 30 Jan 2018 16:23:50 +0100
changeset 1913 338e2f51b685
parent 1912 8391c11477f4
child 1914 99f8cfa80b15
modbus extension code cleanup, from smarteh's patch
modbus/mb_runtime.c
modbus/modbus.py
--- a/modbus/mb_runtime.c	Tue Jan 30 16:06:58 2018 +0100
+++ b/modbus/mb_runtime.c	Tue Jan 30 16:23:50 2018 +0100
@@ -206,16 +206,11 @@
 
 
 static int __read_inwords  (void *mem_map, u16 start_addr, u16 word_count, u16 *data_words) {
-  u16 count;
-  // return -ERR_ILLEGAL_FUNCTION; /* function not yet supported *//* ERR_ILLEGAL_FUNCTION defined in mb_util.h */
-  
+
   if ((start_addr + word_count) > MEM_AREA_SIZE)
     return -ERR_ILLEGAL_DATA_ADDRESS; /* ERR_ILLEGAL_DATA_ADDRESS defined in mb_util.h */
-  
-  /* use memcpy() as it is more efficient...
-  for (count = 0; count < word_count ; count++)
-    data_words[count] = ((server_mem_t *)mem_map)->ro_words[count + start_addr];
-  */
+
+  /* use memcpy() because loop with pointers (u16 *) caused alignment problems */
   memcpy(/* dest */ (void *)data_words,
          /* src  */ (void *)&(((server_mem_t *)mem_map)->ro_words[start_addr]),
          /* size */ word_count * 2);
@@ -225,16 +220,11 @@
 
 
 static int __read_outwords (void *mem_map, u16 start_addr, u16 word_count, u16 *data_words) {
-  u16 count;
-  // return -ERR_ILLEGAL_FUNCTION; /* function not yet supported *//* ERR_ILLEGAL_FUNCTION defined in mb_util.h */
-  
+
   if ((start_addr + word_count) > MEM_AREA_SIZE)
     return -ERR_ILLEGAL_DATA_ADDRESS; /* ERR_ILLEGAL_DATA_ADDRESS defined in mb_util.h */
-  
-  /* use memcpy() as it is more efficient...
-  for (count = 0; count < word_count ; count++)
-    data_words[count] = ((server_mem_t *)mem_map)->rw_words[count + start_addr];
-  */
+
+  /* use memcpy() because loop with pointers (u16 *) caused alignment problems */
   memcpy(/* dest */ (void *)data_words,
          /* src  */ (void *)&(((server_mem_t *)mem_map)->rw_words[start_addr]),
          /* size */ word_count * 2);
@@ -245,9 +235,7 @@
 
 
 static int __write_outwords(void *mem_map, u16 start_addr, u16 word_count, u16 *data_words) {
-  u16 count;
-  // return -ERR_ILLEGAL_FUNCTION; /* function not yet supported *//* ERR_ILLEGAL_FUNCTION defined in mb_util.h */
-  
+
   if ((start_addr + word_count) > MEM_AREA_SIZE)
     return -ERR_ILLEGAL_DATA_ADDRESS; /* ERR_ILLEGAL_DATA_ADDRESS defined in mb_util.h */
 
@@ -397,7 +385,7 @@
 }
 
 
-
+int __cleanup_%(locstr)s ();
 int __init_%(locstr)s (int argc, char **argv){
 	int index;
 
--- a/modbus/modbus.py	Tue Jan 30 16:06:58 2018 +0100
+++ b/modbus/modbus.py	Tue Jan 30 16:23:50 2018 +0100
@@ -779,7 +779,8 @@
         #LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_rtu.o")    + "\"")
         #LDFLAGS.append("\"" + os.path.join(ModbusPath, "mb_ascii.o")    + "\"")
         #LDFLAGS.append("\"" + os.path.join(ModbusPath, "sin_util.o")  + "\"")
-        if os.name == 'nt':   # other possible values: 'posix' 'os2' 'ce' 'java' 'riscos'
-            LDFLAGS.append(" -lws2_32 ")  # on windows we need to load winsock library!
+        # Target is ARM with linux and not win on x86 so winsock2 (ws2_32) library is useless !!!
+        #if os.name == 'nt':   # other possible values: 'posix' 'os2' 'ce' 'java' 'riscos'
+        #    LDFLAGS.append(" -lws2_32 ")  # on windows we need to load winsock library!        
 
         return [(Gen_MB_c_path, ' -I"'+ModbusPath+'"')], LDFLAGS, True