objdictgen/gen_cfile.py
changeset 5 e4365e7d47f0
parent 0 4472ee7c6c3e
child 28 e169fe15521b
equal deleted inserted replaced
4:986061160dbb 5:e4365e7d47f0
   157                 internal_types[typename] = typeinfos[2]
   157                 internal_types[typename] = typeinfos[2]
   158             texts["subIndexType"] = typeinfos[0]
   158             texts["subIndexType"] = typeinfos[0]
   159             texts["suffixe"] = typeinfos[1]
   159             texts["suffixe"] = typeinfos[1]
   160             if typeinfos[2] == "visible_string":
   160             if typeinfos[2] == "visible_string":
   161                 texts["value"] = "\"%s\""%values
   161                 texts["value"] = "\"%s\""%values
       
   162                 texts["comment"] = ""
   162             else:
   163             else:
   163                 texts["value"] = "0x%X"%values
   164                 texts["value"] = "0x%X"%values
       
   165                 texts["comment"] = "\t// %s"%str(values)
   164             if index in variablelist:
   166             if index in variablelist:
   165                 texts["name"] = FormatName(subentry_infos["name"])
   167                 texts["name"] = FormatName(subentry_infos["name"])
   166                 strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x00\n"%texts
   168                 strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x00\n"%texts
   167                 if callbacks:
   169                 if callbacks:
   168                     strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts
   170                     strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts
   169                 mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x00\n"%texts
   171                 mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x00\n"%texts
   170             else:
   172             else:
   171                 strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;\n"%texts
   173                 strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;%(comment)s\n"%texts
   172             values = [values]
   174             values = [values]
   173         else:
   175         else:
   174             
   176             
   175             # Entry type is RECORD
   177             # Entry type is RECORD
   176             if entry_infos["struct"] & OD_IdenticalSubindexes:
   178             if entry_infos["struct"] & OD_IdenticalSubindexes:
   190                     if callbacks:
   192                     if callbacks:
   191                         strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts
   193                         strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts
   192                     mappedVariableContent = "%(subIndexType)s %(name)s[] =\t\t// Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X\n  {\n"%texts
   194                     mappedVariableContent = "%(subIndexType)s %(name)s[] =\t\t// Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X\n  {\n"%texts
   193                     for subIndex, value in enumerate(values):
   195                     for subIndex, value in enumerate(values):
   194                         sep = ","
   196                         sep = ","
       
   197                         comment = ""
   195                         if subIndex > 0:
   198                         if subIndex > 0:
   196                             if subIndex == len(values)-1:
   199                             if subIndex == len(values)-1:
   197                                 sep = ""
   200                                 sep = ""
   198                             if typeinfos[2] == "visible_string":
   201                             if typeinfos[2] == "visible_string":
   199                                 value = "\"%s\""%value
   202                                 value = "\"%s\""%value
   200                             else:
   203                             else:
       
   204                                 comment = "\t// %s"%str(value)
   201                                 value = "0x%X"%value
   205                                 value = "0x%X"%value
   202                             mappedVariableContent += "    %s%s\n"%(value, sep)
   206                             mappedVariableContent += "    %s%s%s\n"%(value, sep, comment)
   203                     mappedVariableContent += "  }\n"
   207                     mappedVariableContent += "  }\n"
   204                 else:
   208                 else:
   205                     strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n                    {\n"%texts
   209                     strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n                    {\n"%texts
   206                     for subIndex, value in enumerate(values):
   210                     for subIndex, value in enumerate(values):
   207                         sep = ","
   211                         sep = ","
       
   212                         comment = ""
   208                         if subIndex > 0:
   213                         if subIndex > 0:
   209                             if subIndex == len(values)-1:
   214                             if subIndex == len(values)-1:
   210                                 sep = ""
   215                                 sep = ""
   211                             if typeinfos[2] == "visible_string":
   216                             if typeinfos[2] == "visible_string":
   212                                 value = "\"%s\""%value
   217                                 value = "\"%s\""%value
   213                             else:
   218                             else:
   214                                 value = str(value)
   219                                 comment = "\t// %s"%str(value)
   215                             strIndex += "                      %s%s\n"%(value, sep)
   220                                 value = "0x%X"%value
       
   221                             strIndex += "                      %s%s%s\n"%(value, sep, comment)
   216                     strIndex += "                    };\n"
   222                     strIndex += "                    };\n"
   217             else:
   223             else:
   218                 
   224                 
   219                 # Entry type is ARRAY
   225                 # Entry type is ARRAY
   220                 for subIndex, value in enumerate(values):
   226                 for subIndex, value in enumerate(values):
   229                             internal_types[typename] = typeinfos[2]
   235                             internal_types[typename] = typeinfos[2]
   230                         texts["subIndexType"] = typeinfos[0]
   236                         texts["subIndexType"] = typeinfos[0]
   231                         texts["suffixe"] = typeinfos[1]
   237                         texts["suffixe"] = typeinfos[1]
   232                         if typeinfos[2] == "visible_string":
   238                         if typeinfos[2] == "visible_string":
   233                             texts["value"] = "\"%s\""%value
   239                             texts["value"] = "\"%s\""%value
       
   240                             texts["comment"] = ""
   234                         else:
   241                         else:
   235                             texts["value"] = "0x%X"%value
   242                             texts["value"] = "0x%X"%value
       
   243                             texts["comment"] = "\t// %s"%str(value)
   236                         texts["name"] = FormatName(subentry_infos["name"])
   244                         texts["name"] = FormatName(subentry_infos["name"])
   237                         if index in variablelist:
   245                         if index in variablelist:
   238                             strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X\n"%texts
   246                             strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X\n"%texts
   239                             mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X\n"%texts
   247                             mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X\n"%texts
   240                         else:
   248                         else:
   241                             strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;\n"%texts
   249                             strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;%(comment)s\n"%texts
   242                 if callbacks:
   250                 if callbacks:
   243                     texts["name"] = FormatName(entry_infos["name"])
   251                     texts["name"] = FormatName(entry_infos["name"])
   244                     strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts
   252                     strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts
   245         
   253         
   246         # Generating Dictionary C++ entry
   254         # Generating Dictionary C++ entry
   307 
   315 
   308     if 0x1006 not in communicationlist:
   316     if 0x1006 not in communicationlist:
   309         entry_infos = Manager.GetEntryInfos(0x1006)
   317         entry_infos = Manager.GetEntryInfos(0x1006)
   310         texts["EntryName"] = entry_infos["name"]
   318         texts["EntryName"] = entry_infos["name"]
   311         indexContents[0x1006] = """\n/* index 0x1006 :   %(EntryName)s */
   319         indexContents[0x1006] = """\n/* index 0x1006 :   %(EntryName)s */
   312                     UNS32 %(NodeName)s_obj1006 = 0;
   320                     UNS32 %(NodeName)s_obj1006 = 0x0;   // 0
   313 """%texts
   321 """%texts
   314 
   322 
   315     if 0x1016 in communicationlist:
   323     if 0x1016 in communicationlist:
   316         texts["nombre"] = Manager.GetCurrentEntry(0x1016, 0)
   324         texts["nombre"] = Manager.GetCurrentEntry(0x1016, 0)
   317     else:
   325     else:
   330 
   338 
   331     if 0x1017 not in communicationlist:
   339     if 0x1017 not in communicationlist:
   332         entry_infos = Manager.GetEntryInfos(0x1017)
   340         entry_infos = Manager.GetEntryInfos(0x1017)
   333         texts["EntryName"] = entry_infos["name"]
   341         texts["EntryName"] = entry_infos["name"]
   334         indexContents[0x1017] = """\n/* index 0x1017 :   %(EntryName)s */ 
   342         indexContents[0x1017] = """\n/* index 0x1017 :   %(EntryName)s */ 
   335                     UNS16 %(NodeName)s_obj1017 = 0;
   343                     UNS16 %(NodeName)s_obj1017 = 0x0;   // 0
   336 """%texts
   344 """%texts
   337 
   345 
   338 #-------------------------------------------------------------------------------
   346 #-------------------------------------------------------------------------------
   339 #               Declaration of navigation in the Object Dictionary
   347 #               Declaration of navigation in the Object Dictionary
   340 #-------------------------------------------------------------------------------
   348 #-------------------------------------------------------------------------------