canfestival/config_utils.py
changeset 1744 69dfdb26f600
parent 1743 c3c3d1318130
child 1747 6046ffa2280f
equal deleted inserted replaced
1743:c3c3d1318130 1744:69dfdb26f600
    82     list_car = [data[i:i+2] for i in xrange(0, len(data), 2)]
    82     list_car = [data[i:i+2] for i in xrange(0, len(data), 2)]
    83     list_car.reverse()
    83     list_car.reverse()
    84     return "".join([chr(int(car, 16)) for car in list_car])
    84     return "".join([chr(int(car, 16)) for car in list_car])
    85 
    85 
    86 
    86 
    87 def GetNodePDOIndexes(node, type, parameters = False):
    87 def GetNodePDOIndexes(node, type, parameters=False):
    88     """
    88     """
    89     Find the PDO indexes of a node
    89     Find the PDO indexes of a node
    90     @param node: node
    90     @param node: node
    91     @param type: type of PDO searched (RPDO or TPDO or both)
    91     @param type: type of PDO searched (RPDO or TPDO or both)
    92     @param parameters: indicate which indexes are expected (PDO paramaters : True or PDO mappings : False)
    92     @param parameters: indicate which indexes are expected (PDO paramaters : True or PDO mappings : False)
   365                 # Extract and check nodeid
   365                 # Extract and check nodeid
   366                 nodeid, index, subindex = loc[:3]
   366                 nodeid, index, subindex = loc[:3]
   367 
   367 
   368                 # Check Id is in slave node list
   368                 # Check Id is in slave node list
   369                 if nodeid not in self.NodeList.SlaveNodes.keys():
   369                 if nodeid not in self.NodeList.SlaveNodes.keys():
   370                     raise PDOmappingException, _("Non existing node ID : {a1} (variable {a2})").format(a1 = nodeid, a2 = name)
   370                     raise PDOmappingException, _("Non existing node ID : {a1} (variable {a2})").format(a1=nodeid, a2=name)
   371 
   371 
   372                 # Get the model for this node (made from EDS)
   372                 # Get the model for this node (made from EDS)
   373                 node = self.NodeList.SlaveNodes[nodeid]["Node"]
   373                 node = self.NodeList.SlaveNodes[nodeid]["Node"]
   374 
   374 
   375                 # Extract and check index and subindex
   375                 # Extract and check index and subindex
   376                 if not node.IsEntry(index, subindex):
   376                 if not node.IsEntry(index, subindex):
   377                     msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\
   377                     msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\
   378                           format(a1 = "%x" % index, a2 ="%x" % subindex, a3 = nodeid, a4 = name)
   378                           format(a1="%x" % index, a2="%x" % subindex, a3=nodeid, a4=name)
   379                     raise PDOmappingException, msg
   379                     raise PDOmappingException, msg
   380 
   380 
   381                 # Get the entry info
   381                 # Get the entry info
   382                 subentry_infos = node.GetSubentryInfos(index, subindex)
   382                 subentry_infos = node.GetSubentryInfos(index, subindex)
   383 
   383 
   385                 if subentry_infos and subentry_infos["pdo"]:
   385                 if subentry_infos and subentry_infos["pdo"]:
   386                     if sizelocation == "X" and len(loc) > 3:
   386                     if sizelocation == "X" and len(loc) > 3:
   387                         numbit = loc[3]
   387                         numbit = loc[3]
   388                     elif sizelocation != "X" and len(loc) > 3:
   388                     elif sizelocation != "X" and len(loc) > 3:
   389                         msg = _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))").\
   389                         msg = _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))").\
   390                               format(a1 = name, a2 = nodeid, a3 = "%x" % index, a4 = "%x" % subindex)
   390                               format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)
   391                         raise PDOmappingException, msg
   391                         raise PDOmappingException, msg
   392                     else:
   392                     else:
   393                         numbit = None
   393                         numbit = None
   394 
   394 
   395                     if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
   395                     if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
   396                         raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3}  for location \"{a4}\"").\
   396                         raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3}  for location \"{a4}\"").\
   397                             format(a1 = location["IEC_TYPE"], a2 = COlocationtype, a3 = subentry_infos["type"], a4 = name)
   397                             format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name)
   398 
   398 
   399                     typeinfos = node.GetEntryInfos(COlocationtype)
   399                     typeinfos = node.GetEntryInfos(COlocationtype)
   400                     self.IECLocations[name] = {
   400                     self.IECLocations[name] = {
   401                         "type":         COlocationtype,
   401                         "type":         COlocationtype,
   402                         "pdotype":      SlavePDOType[direction],
   402                         "pdotype":      SlavePDOType[direction],
   407                         "size":         typeinfos["size"],
   407                         "size":         typeinfos["size"],
   408                         "sizelocation": sizelocation
   408                         "sizelocation": sizelocation
   409                     }
   409                     }
   410                 else:
   410                 else:
   411                     raise PDOmappingException, _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").\
   411                     raise PDOmappingException, _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").\
   412                         format(a1 = name, a2 = nodeid, a3 = "%x" % index, a4 = "%x" % subindex)
   412                         format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)
   413 
   413 
   414         #-------------------------------------------------------------------------------
   414         #-------------------------------------------------------------------------------
   415         #                         Search for locations already mapped
   415         #                         Search for locations already mapped
   416         #-------------------------------------------------------------------------------
   416         #-------------------------------------------------------------------------------
   417 
   417 
   600                         # If entry have just been created, no subentry have to be added
   600                         # If entry have just been created, no subentry have to be added
   601                         if not new_index:
   601                         if not new_index:
   602                             self.Manager.AddSubentriesToCurrent(mapvariableidx, 1, self.MasterNode)
   602                             self.Manager.AddSubentriesToCurrent(mapvariableidx, 1, self.MasterNode)
   603                             nbsubentries += 1
   603                             nbsubentries += 1
   604                         # Add informations to the new subentry created
   604                         # Add informations to the new subentry created
   605                         self.MasterNode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name": subindexname})
   605                         self.MasterNode.SetMappingEntry(mapvariableidx, nbsubentries, values={"name": subindexname})
   606                         self.MasterNode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type": typeidx})
   606                         self.MasterNode.SetMappingEntry(mapvariableidx, nbsubentries, values={"type": typeidx})
   607 
   607 
   608                         # Set value of the PDO mapping
   608                         # Set value of the PDO mapping
   609                         typeinfos = self.Manager.GetEntryInfos(typeidx)
   609                         typeinfos = self.Manager.GetEntryInfos(typeidx)
   610                         if typeinfos is not None:
   610                         if typeinfos is not None:
   611                             value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
   611                             value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
   659             index, subindex = loc[:2]
   659             index, subindex = loc[:2]
   660 
   660 
   661             # Extract and check index and subindex
   661             # Extract and check index and subindex
   662             if not slave.IsEntry(index, subindex):
   662             if not slave.IsEntry(index, subindex):
   663                 raise PDOmappingException, _("No such index/subindex ({a1},{a2}) (variable {a3})").\
   663                 raise PDOmappingException, _("No such index/subindex ({a1},{a2}) (variable {a3})").\
   664                     format(a1 = "%x" % index, a2 = "%x" % subindex, a3 = name)
   664                     format(a1="%x" % index, a2="%x" % subindex, a3=name)
   665 
   665 
   666             # Get the entry info
   666             # Get the entry info
   667             subentry_infos = slave.GetSubentryInfos(index, subindex)
   667             subentry_infos = slave.GetSubentryInfos(index, subindex)
   668             if subentry_infos["type"] != COlocationtype:
   668             if subentry_infos["type"] != COlocationtype:
   669                 raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\
   669                 raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\
   670                     format( a1 = location["IEC_TYPE"], a2 = COlocationtype, a3 = subentry_infos["type"], a4 = name)
   670                     format( a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name)
   671 
   671 
   672             IECLocations[name] = COlocationtype
   672             IECLocations[name] = COlocationtype
   673             pointers[(index, subindex)] = name
   673             pointers[(index, subindex)] = name
   674     return pointers
   674     return pointers
   675 
   675