]> rtime.felk.cvut.cz Git - CanFestival-3.git/commitdiff
Added support for null terminated strings as VISIBLE_STRING.
authoretisserant <etisserant>
Thu, 20 Mar 2008 10:41:06 +0000 (10:41 +0000)
committeretisserant <etisserant>
Thu, 20 Mar 2008 10:41:06 +0000 (10:41 +0000)
Also fixed size declaration problem with visible_strings.

examples/DS401_Slave_Gui/ObjDict.c
objdictgen/gen_cfile.py
src/objacces.c

index 141804aa1b4b068446d5434f065b9fd8a418e0e7..d950e1866800f5647f90e4685128e45ebf7c6abe 100644 (file)
@@ -167,21 +167,21 @@ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                     UNS8 ObjDict_obj1008[10] = "";
                     subindex ObjDict_Index1008[] = 
                      {
-                       { RO, visible_string, 0, (void*)&ObjDict_obj1008 }
+                       { RO, visible_string, 10, (void*)&ObjDict_obj1008 }
                      };
 
 /* index 0x1009 :   Manufacturer Hardware Version. */
                     UNS8 ObjDict_obj1009[10] = "";
                     subindex ObjDict_Index1009[] = 
                      {
-                       { RO, visible_string, 0, (void*)&ObjDict_obj1009 }
+                       { RO, visible_string, 10, (void*)&ObjDict_obj1009 }
                      };
 
 /* index 0x100A :   Manufacturer Software Version. */
                     UNS8 ObjDict_obj100A[10] = "";
                     subindex ObjDict_Index100A[] = 
                      {
-                       { RO, visible_string, 0, (void*)&ObjDict_obj100A }
+                       { RO, visible_string, 10, (void*)&ObjDict_obj100A }
                      };
 
 /* index 0x100C :   Guard Time. */
index 81472df5be27a1626d469e0b502e43ab1a43c0f7..485cf92168f2360e6d76499ef2068003fe334afb 100644 (file)
@@ -231,7 +231,7 @@ def GenerateFileContent(Node, headerfilepath):
                             if subIndex == len(values)-1:
                                 sep = ""
                             if typeinfos[2] == "visible_string":
-                                value = "\"%s\""%value
+                                value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
                             elif typeinfos[2] == "domain":
                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
                             else:
@@ -248,7 +248,7 @@ def GenerateFileContent(Node, headerfilepath):
                             if subIndex == len(values)-1:
                                 sep = ""
                             if typeinfos[2] == "visible_string":
-                                value = "\"%s\""%value
+                                value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
                             elif typeinfos[2] == "domain":
                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
                             else:
@@ -272,7 +272,7 @@ def GenerateFileContent(Node, headerfilepath):
                         else:
                             texts["suffixe"] = ""
                         if typeinfos[2] == "visible_string":
-                            texts["value"] = "\"%s\""%value
+                            texts["value"] = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
                             texts["comment"] = ""
                         elif typeinfos[2] == "domain":
                             texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
@@ -333,8 +333,10 @@ def GenerateFileContent(Node, headerfilepath):
                     name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"]))
                 else:
                     name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"]))
-            if typeinfos[2] in ["visible_string", "domain"]:
-                sizeof = typeinfos[1]
+            if typeinfos[2] == "visible_string":
+                sizeof = str(max(len(values[subIndex]), default_string_size))
+            elif typeinfos[2] == "domain":
+                sizeof = str(len(values[subIndex]))
             else:
                 sizeof = "sizeof (%s)"%typeinfos[0]
             params = Node.GetParamsEntry(index, subIndex)
index fb65c1be4c8d6537411664e449102adb40da6ff2..cb8bce8f022864ac96d80c436c7ac4eca94dcd67 100644 (file)
@@ -138,12 +138,13 @@ UNS32 _getODentry( CO_Data* d,
 
   if(*pExpectedSize == 0 ||
      *pExpectedSize == szData ||
-     (*pDataType == visible_string && *pExpectedSize < szData)) {
-    /* We
-      allow to fetch a shorter string than expected */
+     /* allow to fetch a shorter string than expected */
+     (*pDataType >= visible_string && *pExpectedSize < szData)) { 
 
 #  ifdef CANOPEN_BIG_ENDIAN
-    if(endianize && *pDataType > boolean && *pDataType < visible_string) {
+     if(endianize && dataType > boolean && !(
+            dataType >= visible_string && 
+            domain <= dataType)) {
       /* data must be transmited with low byte first */
       UNS8 i, j = 0;
       MSG_WAR(boolean, "data type ", *pDataType);
@@ -156,7 +157,7 @@ UNS32 _getODentry( CO_Data* d,
     }
     else /* no endianisation change */
 #  endif
-    if(*pDataType < visible_string) {
+    if(*pDataType != visible_string) {
         memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,szData);
         *pExpectedSize = szData;
     }else{
@@ -171,7 +172,11 @@ UNS32 _getODentry( CO_Data* d,
         while( *ptr && ptr < ptr_end){
             *((UNS8*)pDestData++) = *(ptr++);
         } 
-        *pExpectedSize = ptr - ptr_start; 
+         
+        *pExpectedSize = ptr - ptr_start;
+        /* terminate string if not maximum length */
+        if (*pExpectedSize < szData) 
+            *(ptr) = 0; 
     }
 
     return OD_SUCCESSFUL;
@@ -294,11 +299,14 @@ UNS32 _setODentry( CO_Data* d,
 
   if( *pExpectedSize == 0 ||
       *pExpectedSize == szData ||
-      (dataType == visible_string && *pExpectedSize < szData)) /* We
-                                                                  allow to store a shorter string than entry size */
+      /* allow to store a shorter string than entry size */
+      (dataType == visible_string && *pExpectedSize < szData))
     {
 #ifdef CANOPEN_BIG_ENDIAN
-      if(endianize && dataType > boolean && dataType < visible_string)
+      /* re-endianize do not occur for bool, strings time and domains */
+      if(endianize && dataType > boolean && !(
+            dataType >= visible_string && 
+            domain <= dataType))
         {
           /* we invert the data source directly. This let us do range
             testing without */
@@ -318,6 +326,14 @@ UNS32 _setODentry( CO_Data* d,
         return errorCode;
       }
       memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize);
+     /* TODO : CONFORM TO DS-301 : 
+      *  - stop using NULL terminated strings
+      *  - store string size in td_subindex 
+      * */
+      /* terminate visible_string with '\0' */
+      if(dataType == visible_string && *pExpectedSize < szData)
+        ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[*pExpectedSize] = 0;
+      
       *pExpectedSize = szData;
 
       /* Callbacks */