canfestival/config_utils.py
changeset 1782 5b6ad7a7fd9d
parent 1768 691083b5682a
child 1826 91796f408540
equal deleted inserted replaced
1781:b112bfdde5cc 1782:5b6ad7a7fd9d
    59 VariableDirText = {TPDO: "__I", RPDO: "__Q"}
    59 VariableDirText = {TPDO: "__I", RPDO: "__Q"}
    60 VariableTypeOffset = dict(zip(["", "X", "B", "W", "D", "L"], range(6)))
    60 VariableTypeOffset = dict(zip(["", "X", "B", "W", "D", "L"], range(6)))
    61 
    61 
    62 TrashVariables = [(1, 0x01), (8, 0x05), (16, 0x06), (32, 0x07), (64, 0x1B)]
    62 TrashVariables = [(1, 0x01), (8, 0x05), (16, 0x06), (32, 0x07), (64, 0x1B)]
    63 
    63 
    64 #-------------------------------------------------------------------------------
    64 # -------------------------------------------------------------------------------
    65 #                  Specific exception for PDO mapping errors
    65 #                  Specific exception for PDO mapping errors
    66 #-------------------------------------------------------------------------------
    66 # -------------------------------------------------------------------------------
    67 
    67 
    68 
    68 
    69 class PDOmappingException(Exception):
    69 class PDOmappingException(Exception):
    70     pass
    70     pass
    71 
    71 
   338         @param locations: list of locations to be mapped
   338         @param locations: list of locations to be mapped
   339         @param current_location: tuple of the located prefixes not to be considered
   339         @param current_location: tuple of the located prefixes not to be considered
   340         @param sync_TPDOs: indicate if TPDO must be synchronous
   340         @param sync_TPDOs: indicate if TPDO must be synchronous
   341         """
   341         """
   342 
   342 
   343         #-------------------------------------------------------------------------------
   343         # -------------------------------------------------------------------------------
   344         #               Verify that locations correspond to real slave variables
   344         #               Verify that locations correspond to real slave variables
   345         #-------------------------------------------------------------------------------
   345         # -------------------------------------------------------------------------------
   346 
   346 
   347         # Get list of locations check if exists and mappables -> put them in IECLocations
   347         # Get list of locations check if exists and mappables -> put them in IECLocations
   348         for location in locations:
   348         for location in locations:
   349             COlocationtype = IECToCOType[location["IEC_TYPE"]]
   349             COlocationtype = IECToCOType[location["IEC_TYPE"]]
   350             name = location["NAME"]
   350             name = location["NAME"]
   418                 else:
   418                 else:
   419                     raise PDOmappingException(
   419                     raise PDOmappingException(
   420                         _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").
   420                         _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").
   421                         format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex))
   421                         format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex))
   422 
   422 
   423         #-------------------------------------------------------------------------------
   423         # -------------------------------------------------------------------------------
   424         #                         Search for locations already mapped
   424         #                         Search for locations already mapped
   425         #-------------------------------------------------------------------------------
   425         # -------------------------------------------------------------------------------
   426 
   426 
   427         for name, locationinfos in self.IECLocations.items():
   427         for name, locationinfos in self.IECLocations.items():
   428             node = self.NodeList.SlaveNodes[locationinfos["nodeid"]]["Node"]
   428             node = self.NodeList.SlaveNodes[locationinfos["nodeid"]]["Node"]
   429 
   429 
   430             # Search if slave has a PDO mapping this locations
   430             # Search if slave has a PDO mapping this locations
   470                 # Add location to those that haven't been mapped yet
   470                 # Add location to those that haven't been mapped yet
   471                 if locationinfos["nodeid"] not in self.LocationsNotMapped.keys():
   471                 if locationinfos["nodeid"] not in self.LocationsNotMapped.keys():
   472                     self.LocationsNotMapped[locationinfos["nodeid"]] = {TPDO: [], RPDO: []}
   472                     self.LocationsNotMapped[locationinfos["nodeid"]] = {TPDO: [], RPDO: []}
   473                 self.LocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos))
   473                 self.LocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos))
   474 
   474 
   475         #-------------------------------------------------------------------------------
   475         # -------------------------------------------------------------------------------
   476         #                         Build concise DCF for the others locations
   476         #                         Build concise DCF for the others locations
   477         #-------------------------------------------------------------------------------
   477         # -------------------------------------------------------------------------------
   478 
   478 
   479         for nodeid, locations in self.LocationsNotMapped.items():
   479         for nodeid, locations in self.LocationsNotMapped.items():
   480             node = self.NodeList.SlaveNodes[nodeid]["Node"]
   480             node = self.NodeList.SlaveNodes[nodeid]["Node"]
   481 
   481 
   482             # Initialize number of params and data to add to node DCF
   482             # Initialize number of params and data to add to node DCF
   518                         nbparams += nbaddedparams
   518                         nbparams += nbaddedparams
   519 
   519 
   520             # Add number of params and data to node DCF
   520             # Add number of params and data to node DCF
   521             self.AddParamsToDCF(nodeid, dataparams, nbparams)
   521             self.AddParamsToDCF(nodeid, dataparams, nbparams)
   522 
   522 
   523         #-------------------------------------------------------------------------------
   523         # -------------------------------------------------------------------------------
   524         #                         Master Node Configuration
   524         #                         Master Node Configuration
   525         #-------------------------------------------------------------------------------
   525         # -------------------------------------------------------------------------------
   526 
   526 
   527         # Generate Master's Configuration from informations stored in MasterMapping
   527         # Generate Master's Configuration from informations stored in MasterMapping
   528         for cobid, pdo_infos in self.MasterMapping.items():
   528         for cobid, pdo_infos in self.MasterMapping.items():
   529             # Get next PDO index in MasterNode for this PDO type
   529             # Get next PDO index in MasterNode for this PDO type
   530             current_idx = self.CurrentPDOParamsIdx[pdo_infos["type"]]
   530             current_idx = self.CurrentPDOParamsIdx[pdo_infos["type"]]