objdictgen/node.py
changeset 584 e23359f62023
parent 541 dcc7f1323ce5
child 659 1041153c5fd2
equal deleted inserted replaced
583:a2c74eca6bf2 584:e23359f62023
   268     return list
   268     return list
   269 
   269 
   270 """
   270 """
   271 Return the name of an entry by searching in mappingdictionary 
   271 Return the name of an entry by searching in mappingdictionary 
   272 """
   272 """
   273 def FindEntryName(index, mappingdictionary):
   273 def FindEntryName(index, mappingdictionary, compute=True):
   274     base_index = FindIndex(index, mappingdictionary)
   274     base_index = FindIndex(index, mappingdictionary)
   275     if base_index:
   275     if base_index:
   276         infos = mappingdictionary[base_index]
   276         infos = mappingdictionary[base_index]
   277         if infos["struct"] & OD_IdenticalIndexes:
   277         if infos["struct"] & OD_IdenticalIndexes and compute:
   278             return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
   278             return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
   279         else:
   279         else:
   280             return infos["name"]
   280             return infos["name"]
   281     return None
   281     return None
   282 
   282 
   283 """
   283 """
   284 Return the informations of one entry by searching in mappingdictionary 
   284 Return the informations of one entry by searching in mappingdictionary 
   285 """
   285 """
   286 def FindEntryInfos(index, mappingdictionary):
   286 def FindEntryInfos(index, mappingdictionary, compute=True):
   287     base_index = FindIndex(index, mappingdictionary)
   287     base_index = FindIndex(index, mappingdictionary)
   288     if base_index:
   288     if base_index:
   289         copy = mappingdictionary[base_index].copy()
   289         copy = mappingdictionary[base_index].copy()
   290         if copy["struct"] & OD_IdenticalIndexes:
   290         if copy["struct"] & OD_IdenticalIndexes and compute:
   291             copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
   291             copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
   292         copy.pop("values")
   292         copy.pop("values")
   293         return copy
   293         return copy
   294     return None
   294     return None
   295 
   295 
   296 """
   296 """
   297 Return the informations of one subentry of an entry by searching in mappingdictionary 
   297 Return the informations of one subentry of an entry by searching in mappingdictionary 
   298 """
   298 """
   299 def FindSubentryInfos(index, subIndex, mappingdictionary):
   299 def FindSubentryInfos(index, subIndex, mappingdictionary, compute=True):
   300     base_index = FindIndex(index, mappingdictionary)
   300     base_index = FindIndex(index, mappingdictionary)
   301     if base_index:
   301     if base_index:
   302         struct = mappingdictionary[base_index]["struct"]
   302         struct = mappingdictionary[base_index]["struct"]
   303         if struct & OD_IdenticalIndexes:
   303         if struct & OD_IdenticalIndexes:
   304             incr = mappingdictionary[base_index]["incr"]
   304             incr = mappingdictionary[base_index]["incr"]
   324                             infos = subindex_infos.copy()
   324                             infos = subindex_infos.copy()
   325                             break;
   325                             break;
   326                         idx += 1
   326                         idx += 1
   327             elif subIndex == 0:
   327             elif subIndex == 0:
   328                 infos = mappingdictionary[base_index]["values"][0].copy()
   328                 infos = mappingdictionary[base_index]["values"][0].copy()
   329             if infos is not None:
   329             if infos is not None and compute:
   330                 infos["name"] = StringFormat(infos["name"], (index - base_index) / incr + 1, subIndex)
   330                 infos["name"] = StringFormat(infos["name"], (index - base_index) / incr + 1, subIndex)
   331             return infos
   331             return infos
   332     return None
   332     return None
   333 
   333 
   334 """
   334 """
   335 Return the list of variables that can be mapped defined in mappingdictionary 
   335 Return the list of variables that can be mapped defined in mappingdictionary 
   336 """
   336 """
   337 def FindMapVariableList(mappingdictionary, Node):
   337 def FindMapVariableList(mappingdictionary, Node, compute=True):
   338     list = []
   338     list = []
   339     for index in mappingdictionary.iterkeys():
   339     for index in mappingdictionary.iterkeys():
   340         if Node.IsEntry(index):
   340         if Node.IsEntry(index):
   341             for subIndex, values in enumerate(mappingdictionary[index]["values"]):
   341             for subIndex, values in enumerate(mappingdictionary[index]["values"]):
   342                 if mappingdictionary[index]["values"][subIndex]["pdo"]:
   342                 if mappingdictionary[index]["values"][subIndex]["pdo"]:
   343                     infos = Node.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
   343                     infos = Node.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
       
   344                     name = mappingdictionary[index]["values"][subIndex]["name"]
   344                     if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
   345                     if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
   345                         values = Node.GetEntry(index)
   346                         values = Node.GetEntry(index)
   346                         for i in xrange(len(values) - 1):
   347                         for i in xrange(len(values) - 1):
   347                             list.append((index, i + 1, infos["size"], StringFormat(mappingdictionary[index]["values"][subIndex]["name"],1,i+1)))
   348                             computed_name = name
       
   349                             if compute:
       
   350                                 computed_name = StringFormat(computed_name, 1, i + 1)
       
   351                             list.append((index, i + 1, infos["size"], computed_name))
   348                     else:
   352                     else:
   349                         list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"]))
   353                         computed_name = name
       
   354                         if compute:
       
   355                             computed_name = StringFormat(computed_name, 1, subIndex)
       
   356                         list.append((index, subIndex, infos["size"], computed_name))
   350     return list
   357     return list
   351 
   358 
   352 """
   359 """
   353 Return the list of mandatory indexes defined in mappingdictionary 
   360 Return the list of mandatory indexes defined in mappingdictionary 
   354 """
   361 """
   946     def GetCustomisedTypeValues(self, index):
   953     def GetCustomisedTypeValues(self, index):
   947         values = self.GetEntry(index)
   954         values = self.GetEntry(index)
   948         customisabletypes = self.GetCustomisableTypes()
   955         customisabletypes = self.GetCustomisableTypes()
   949         return values, customisabletypes[values[1]][1]
   956         return values, customisabletypes[values[1]][1]
   950 
   957 
   951     def GetEntryName(self, index):
   958     def GetEntryName(self, index, compute=True):
   952         result = None
   959         result = None
   953         mappings = self.GetMappings()
   960         mappings = self.GetMappings()
   954         i = 0
   961         i = 0
   955         while not result and i < len(mappings):
   962         while not result and i < len(mappings):
   956             result = FindEntryName(index, mappings[i])
   963             result = FindEntryName(index, mappings[i], compute)
   957             i += 1
   964             i += 1
   958         if result == None:
   965         if result == None:
   959             result = FindEntryName(index, MappingDictionary)
   966             result = FindEntryName(index, MappingDictionary, compute)
   960         return result
   967         return result
   961     
   968     
   962     def GetEntryInfos(self, index):
   969     def GetEntryInfos(self, index, compute=True):
   963         result = None
   970         result = None
   964         mappings = self.GetMappings()
   971         mappings = self.GetMappings()
   965         i = 0
   972         i = 0
   966         while not result and i < len(mappings):
   973         while not result and i < len(mappings):
   967             result = FindEntryInfos(index, mappings[i])
   974             result = FindEntryInfos(index, mappings[i], compute)
   968             i += 1
   975             i += 1
   969         if result == None:
   976         if result == None:
   970             result = FindEntryInfos(index, MappingDictionary)
   977             result = FindEntryInfos(index, MappingDictionary, compute)
   971         return result
   978         return result
   972     
   979     
   973     def GetSubentryInfos(self, index, subIndex):
   980     def GetSubentryInfos(self, index, subIndex, compute=True):
   974         result = None
   981         result = None
   975         mappings = self.GetMappings()
   982         mappings = self.GetMappings()
   976         i = 0
   983         i = 0
   977         while not result and i < len(mappings):
   984         while not result and i < len(mappings):
   978             result = FindSubentryInfos(index, subIndex, mappings[i])
   985             result = FindSubentryInfos(index, subIndex, mappings[i], compute)
   979             if result:
   986             if result:
   980                 result["user_defined"] = i == len(mappings) - 1 and index >= 0x1000
   987                 result["user_defined"] = i == len(mappings) - 1 and index >= 0x1000
   981             i += 1
   988             i += 1
   982         if result == None:
   989         if result == None:
   983             result = FindSubentryInfos(index, subIndex, MappingDictionary)
   990             result = FindSubentryInfos(index, subIndex, MappingDictionary, compute)
   984             if result:
   991             if result:
   985                 result["user_defined"] = False
   992                 result["user_defined"] = False
   986         return result
   993         return result
   987     
   994     
   988     def GetTypeIndex(self, typename):
   995     def GetTypeIndex(self, typename):
  1016             i += 1
  1023             i += 1
  1017         if result == None:
  1024         if result == None:
  1018             result = FindTypeDefaultValue(typeindex, MappingDictionary)
  1025             result = FindTypeDefaultValue(typeindex, MappingDictionary)
  1019         return result
  1026         return result
  1020     
  1027     
  1021     def GetMapVariableList(self):
  1028     def GetMapVariableList(self, compute=True):
  1022         list = FindMapVariableList(MappingDictionary, self)
  1029         list = FindMapVariableList(MappingDictionary, self, compute)
  1023         for mapping in self.GetMappings():
  1030         for mapping in self.GetMappings():
  1024             list.extend(FindMapVariableList(mapping, self))
  1031             list.extend(FindMapVariableList(mapping, self, compute))
  1025         list.sort()
  1032         list.sort()
  1026         return list
  1033         return list
  1027     
  1034     
  1028     def GetMandatoryIndexes(self, node = None):
  1035     def GetMandatoryIndexes(self, node = None):
  1029         list = FindMandatoryIndexes(MappingDictionary)
  1036         list = FindMandatoryIndexes(MappingDictionary)
  1110     
  1117     
  1111     """
  1118     """
  1112     Return the list of variables that can be mapped for the current node
  1119     Return the list of variables that can be mapped for the current node
  1113     """
  1120     """
  1114     def GetMapList(self):
  1121     def GetMapList(self):
  1115         list = ["None"] + [self.GenerateMapName(name, index, subIndex) for index, subIndex, size, name in self.GetMapVariableList()]
  1122         list = [_("None")] + [self.GenerateMapName(name, index, subIndex) for index, subIndex, size, name in self.GetMapVariableList()]
  1116         return ",".join(list)
  1123         return ",".join(list)
  1117 
  1124 
  1118 def BE_to_LE(value):
  1125 def BE_to_LE(value):
  1119     """
  1126     """
  1120     Convert Big Endian to Little Endian 
  1127     Convert Big Endian to Little Endian