From: etisserant Date: Thu, 20 Mar 2008 10:41:06 +0000 (+0000) Subject: Added support for null terminated strings as VISIBLE_STRING. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/CanFestival-3.git/commitdiff_plain/e28790da381f675a226f6c04f7bb1e63719299aa Added support for null terminated strings as VISIBLE_STRING. Also fixed size declaration problem with visible_strings. --- diff --git a/examples/DS401_Slave_Gui/ObjDict.c b/examples/DS401_Slave_Gui/ObjDict.c index 141804a..d950e18 100644 --- a/examples/DS401_Slave_Gui/ObjDict.c +++ b/examples/DS401_Slave_Gui/ObjDict.c @@ -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. */ diff --git a/objdictgen/gen_cfile.py b/objdictgen/gen_cfile.py index 81472df..485cf92 100644 --- a/objdictgen/gen_cfile.py +++ b/objdictgen/gen_cfile.py @@ -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) diff --git a/src/objacces.c b/src/objacces.c index fb65c1b..cb8bce8 100644 --- a/src/objacces.c +++ b/src/objacces.c @@ -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 */