plugins/canfestival/config_utils.py
changeset 361 331d698e1118
parent 340 651b8fb572e7
child 415 339fa2542481
equal deleted inserted replaced
360:32339ad7d9ae 361:331d698e1118
   330         for location in locations:
   330         for location in locations:
   331             COlocationtype = IECToCOType[location["IEC_TYPE"]]
   331             COlocationtype = IECToCOType[location["IEC_TYPE"]]
   332             name = location["NAME"]
   332             name = location["NAME"]
   333             if name in self.IECLocations:
   333             if name in self.IECLocations:
   334                 if self.IECLocations[name]["type"] != COlocationtype:
   334                 if self.IECLocations[name]["type"] != COlocationtype:
   335                     raise PDOmappingException, "Conflict type for location \"%s\"" % name 
   335                     raise PDOmappingException, _("Conflict type for location \"%s\"") % name 
   336             else:
   336             else:
   337                 # Get only the part of the location that concern this node
   337                 # Get only the part of the location that concern this node
   338                 loc = location["LOC"][len(current_location):]
   338                 loc = location["LOC"][len(current_location):]
   339                 # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
   339                 # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
   340                 if len(loc) not in (2, 3, 4):
   340                 if len(loc) not in (2, 3, 4):
   341                     raise PDOmappingException, "Bad location size : %s"%str(loc)
   341                     raise PDOmappingException, _("Bad location size : %s") % str(loc)
   342                 elif len(loc) == 2:
   342                 elif len(loc) == 2:
   343                     continue
   343                     continue
   344                 
   344                 
   345                 direction = location["DIR"]
   345                 direction = location["DIR"]
   346                 
   346                 
   349                 # Extract and check nodeid
   349                 # Extract and check nodeid
   350                 nodeid, index, subindex = loc[:3]
   350                 nodeid, index, subindex = loc[:3]
   351                 
   351                 
   352                 # Check Id is in slave node list
   352                 # Check Id is in slave node list
   353                 if nodeid not in self.NodeList.SlaveNodes.keys():
   353                 if nodeid not in self.NodeList.SlaveNodes.keys():
   354                     raise PDOmappingException, "Non existing node ID : %d (variable %s)" % (nodeid,name)
   354                     raise PDOmappingException, _("Non existing node ID : %d (variable %s)") % (nodeid,name)
   355                 
   355                 
   356                 # Get the model for this node (made from EDS)
   356                 # Get the model for this node (made from EDS)
   357                 node = self.NodeList.SlaveNodes[nodeid]["Node"]
   357                 node = self.NodeList.SlaveNodes[nodeid]["Node"]
   358                 
   358                 
   359                 # Extract and check index and subindex
   359                 # Extract and check index and subindex
   360                 if not node.IsEntry(index, subindex):
   360                 if not node.IsEntry(index, subindex):
   361                     raise PDOmappingException, "No such index/subindex (%x,%x) in ID : %d (variable %s)" % (index,subindex,nodeid,name)
   361                     raise PDOmappingException, _("No such index/subindex (%x,%x) in ID : %d (variable %s)") % (index,subindex,nodeid,name)
   362                 
   362                 
   363                 # Get the entry info
   363                 # Get the entry info
   364                 subentry_infos = node.GetSubentryInfos(index, subindex)
   364                 subentry_infos = node.GetSubentryInfos(index, subindex)
   365                 
   365                 
   366                 # If a PDO mappable
   366                 # If a PDO mappable
   367                 if subentry_infos and subentry_infos["pdo"]:
   367                 if subentry_infos and subentry_infos["pdo"]:
   368                     if sizelocation == "X" and len(loc) > 3:
   368                     if sizelocation == "X" and len(loc) > 3:
   369                         numbit = loc[3]
   369                         numbit = loc[3]
   370                     elif sizelocation != "X" and len(loc) > 3:
   370                     elif sizelocation != "X" and len(loc) > 3:
   371                         raise PDOmappingException, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
   371                         raise PDOmappingException, _("Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))") % (name,nodeid,index,subindex)
   372                     else:
   372                     else:
   373                         numbit = None
   373                         numbit = None
   374                     
   374                     
   375                     if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
   375                     if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
   376                         raise PDOmappingException, "Invalid type \"%s\"-> %d != %d  for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
   376                         raise PDOmappingException, _("Invalid type \"%s\"-> %d != %d  for location\"%s\"") % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
   377                     
   377                     
   378                     typeinfos = node.GetEntryInfos(COlocationtype)
   378                     typeinfos = node.GetEntryInfos(COlocationtype)
   379                     self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
   379                     self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
   380                                                 "nodeid": nodeid, "index": index,"subindex": subindex,
   380                                                 "nodeid": nodeid, "index": index,"subindex": subindex,
   381                                                 "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
   381                                                 "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
   382                 else:
   382                 else:
   383                     raise PDOmappingException, "Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
   383                     raise PDOmappingException, _("Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))") % (name,nodeid,index,subindex)
   384         
   384         
   385         #-------------------------------------------------------------------------------
   385         #-------------------------------------------------------------------------------
   386         #                         Search for locations already mapped
   386         #                         Search for locations already mapped
   387         #-------------------------------------------------------------------------------
   387         #-------------------------------------------------------------------------------
   388         
   388         
   450                 if len(locations[pdotype]) > 0:
   450                 if len(locations[pdotype]) > 0:
   451                     pdosize = 0
   451                     pdosize = 0
   452                     pdomapping = []
   452                     pdomapping = []
   453                     result = self.GetEmptyPDO(nodeid, pdotype)
   453                     result = self.GetEmptyPDO(nodeid, pdotype)
   454                     if result is None:
   454                     if result is None:
   455                         raise PDOmappingException, "Impossible to define PDO mapping for node %02x"%nodeid
   455                         raise PDOmappingException, _("Impossible to define PDO mapping for node %02x") % nodeid
   456                     pdoindex, pdocobid, pdonbparams = result
   456                     pdoindex, pdocobid, pdonbparams = result
   457                     for name, loc_infos in locations[pdotype]:
   457                     for name, loc_infos in locations[pdotype]:
   458                         pdosize += loc_infos["size"]
   458                         pdosize += loc_infos["size"]
   459                         # If pdo's size > 64 bits
   459                         # If pdo's size > 64 bits
   460                         if pdosize > 64 or len(pdomapping) >= pdonbparams:
   460                         if pdosize > 64 or len(pdomapping) >= pdonbparams:
   464                             nbparams += nbaddedparams
   464                             nbparams += nbaddedparams
   465                             pdosize = loc_infos["size"]
   465                             pdosize = loc_infos["size"]
   466                             pdomapping = [(name, loc_infos)]
   466                             pdomapping = [(name, loc_infos)]
   467                             result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1)
   467                             result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1)
   468                             if result is None:
   468                             if result is None:
   469                                 raise PDOmappingException, "Impossible to define PDO mapping for node %02x"%nodeid
   469                                 raise PDOmappingException, _("Impossible to define PDO mapping for node %02x") % nodeid
   470                             pdoindex, pdocobid, pdonbparams = result
   470                             pdoindex, pdocobid, pdonbparams = result
   471                         else:
   471                         else:
   472                             pdomapping.append((name, loc_infos))
   472                             pdomapping.append((name, loc_infos))
   473                     # If there isn't locations yet but there is still a PDO to generate
   473                     # If there isn't locations yet but there is still a PDO to generate
   474                     if len(pdomapping) > 0:
   474                     if len(pdomapping) > 0:
   612     for location in locations:
   612     for location in locations:
   613         COlocationtype = IECToCOType[location["IEC_TYPE"]]
   613         COlocationtype = IECToCOType[location["IEC_TYPE"]]
   614         name = location["NAME"]
   614         name = location["NAME"]
   615         if name in IECLocations:
   615         if name in IECLocations:
   616             if IECLocations[name] != COlocationtype:
   616             if IECLocations[name] != COlocationtype:
   617                 raise PDOmappingException, "Conflict type for location \"%s\"" % name 
   617                 raise PDOmappingException, _("Conflict type for location \"%s\"") % name 
   618         else:
   618         else:
   619             # Get only the part of the location that concern this node
   619             # Get only the part of the location that concern this node
   620             loc = location["LOC"][len(current_location):]
   620             loc = location["LOC"][len(current_location):]
   621             # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
   621             # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
   622             if len(loc) not in (2, 3, 4):
   622             if len(loc) not in (2, 3, 4):
   623                 raise PDOmappingException, "Bad location size : %s"%str(loc)
   623                 raise PDOmappingException, _("Bad location size : %s") % str(loc)
   624             elif len(loc) != 2:
   624             elif len(loc) != 2:
   625                 continue
   625                 continue
   626             
   626             
   627             # Extract and check nodeid
   627             # Extract and check nodeid
   628             index, subindex = loc[:2]
   628             index, subindex = loc[:2]
   629             
   629             
   630             # Extract and check index and subindex
   630             # Extract and check index and subindex
   631             if not slave.IsEntry(index, subindex):
   631             if not slave.IsEntry(index, subindex):
   632                 raise PDOmappingException, "No such index/subindex (%x,%x) (variable %s)" % (index, subindex, name)
   632                 raise PDOmappingException, _("No such index/subindex (%x,%x) (variable %s)") % (index, subindex, name)
   633             
   633             
   634             # Get the entry info
   634             # Get the entry info
   635             subentry_infos = slave.GetSubentryInfos(index, subindex)    
   635             subentry_infos = slave.GetSubentryInfos(index, subindex)    
   636             if subentry_infos["type"] != COlocationtype:
   636             if subentry_infos["type"] != COlocationtype:
   637                 raise PDOmappingException, "Invalid type \"%s\"-> %d != %d  for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
   637                 raise PDOmappingException, _("Invalid type \"%s\"-> %d != %d  for location\"%s\"") % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
   638             
   638             
   639             IECLocations[name] = COlocationtype
   639             IECLocations[name] = COlocationtype
   640             pointers[(index, subindex)] = name
   640             pointers[(index, subindex)] = name
   641     return pointers
   641     return pointers
   642         
   642