136 # List of COB IDs available |
136 # List of COB IDs available |
137 self.ListCobIDAvailable = range(0x180, 0x580) |
137 self.ListCobIDAvailable = range(0x180, 0x580) |
138 self.SlavesPdoNumber = {} |
138 self.SlavesPdoNumber = {} |
139 # Dictionary of mapping value where unexpected variables are stored |
139 # Dictionary of mapping value where unexpected variables are stored |
140 self.TrashVariables = {} |
140 self.TrashVariables = {} |
|
141 # Dictionary of pointed variables |
|
142 self.PointedVariables = {} |
141 |
143 |
142 self.NodeList = nodelist |
144 self.NodeList = nodelist |
143 self.Manager = self.NodeList.Manager |
145 self.Manager = self.NodeList.Manager |
144 self.MasterNode = self.Manager.GetCurrentNodeCopy() |
146 self.MasterNode = self.Manager.GetCurrentNodeCopy() |
145 self.MasterNode.SetNodeName(nodename) |
147 self.MasterNode.SetNodeName(nodename) |
146 self.PrepareMasterNode() |
148 self.PrepareMasterNode() |
147 |
149 |
|
150 def GetPointedVariables(self): |
|
151 return self.PointedVariables |
148 |
152 |
149 def RemoveUsedNodeCobId(self, node): |
153 def RemoveUsedNodeCobId(self, node): |
150 """ |
154 """ |
151 Remove all PDO COB ID used by the given node from the list of available COB ID |
155 Remove all PDO COB ID used by the given node from the list of available COB ID |
152 @param node: node |
156 @param node: node |
513 # Calculate base index for storing variable |
517 # Calculate base index for storing variable |
514 mapvariableidx = VariableStartIndex[variable_infos["pdotype"]] + \ |
518 mapvariableidx = VariableStartIndex[variable_infos["pdotype"]] + \ |
515 VariableTypeOffset[variable_infos["sizelocation"]] * VariableIncrement + \ |
519 VariableTypeOffset[variable_infos["sizelocation"]] * VariableIncrement + \ |
516 variable_infos["nodeid"] |
520 variable_infos["nodeid"] |
517 |
521 |
|
522 # Generate entry name |
|
523 indexname = "%s%s%s_%d"%(VariableDirText[variable_infos["pdotype"]], |
|
524 variable_infos["sizelocation"], |
|
525 '_'.join(map(str,current_location)), |
|
526 variable_infos["nodeid"]) |
|
527 |
518 # Search for an entry that has an empty subindex |
528 # Search for an entry that has an empty subindex |
519 while mapvariableidx < VariableStartIndex[variable_infos["pdotype"]] + 0x2000: |
529 while mapvariableidx < VariableStartIndex[variable_infos["pdotype"]] + 0x2000: |
520 # Entry doesn't exist |
530 # Entry doesn't exist |
521 if not self.MasterNode.IsEntry(mapvariableidx): |
531 if not self.MasterNode.IsEntry(mapvariableidx): |
522 # Generate entry name |
|
523 indexname = "%s%s%s_%d"%(VariableDirText[variable_infos["pdotype"]], |
|
524 variable_infos["sizelocation"], |
|
525 '_'.join(map(str,current_location)), |
|
526 variable_infos["nodeid"]) |
|
527 # Add entry to MasterNode |
532 # Add entry to MasterNode |
528 self.Manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, self.MasterNode) |
533 self.Manager.AddMapVariableToCurrent(mapvariableidx, "beremiz"+indexname, 3, 1, self.MasterNode) |
529 new_index = True |
534 new_index = True |
530 nbsubentries = self.MasterNode.GetEntry(mapvariableidx, 0x00) |
535 nbsubentries = self.MasterNode.GetEntry(mapvariableidx, 0x00) |
531 else: |
536 else: |
532 # Get Number of subentries already defined |
537 # Get Number of subentries already defined |
533 nbsubentries = self.MasterNode.GetEntry(mapvariableidx, 0x00) |
538 nbsubentries = self.MasterNode.GetEntry(mapvariableidx, 0x00) |
555 # Set value of the PDO mapping |
560 # Set value of the PDO mapping |
556 typeinfos = self.Manager.GetEntryInfos(typeidx) |
561 typeinfos = self.Manager.GetEntryInfos(typeidx) |
557 if typeinfos != None: |
562 if typeinfos != None: |
558 value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"] |
563 value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"] |
559 self.MasterNode.SetEntry(current_idx + 0x200, subindex, value) |
564 self.MasterNode.SetEntry(current_idx + 0x200, subindex, value) |
|
565 |
|
566 # Add variable to pointed variables |
|
567 self.PointedVariables[(mapvariableidx, nbsubentries)] = "%s_%s"%(indexname, subindexname) |
560 |
568 |
561 def GenerateConciseDCF(locations, current_location, nodelist, sync_TPDOs, nodename): |
569 def GenerateConciseDCF(locations, current_location, nodelist, sync_TPDOs, nodename): |
562 """ |
570 """ |
563 Fills a CanFestival network editor model, with DCF with requested PDO mappings. |
571 Fills a CanFestival network editor model, with DCF with requested PDO mappings. |
564 @param locations: List of complete variables locations \ |
572 @param locations: List of complete variables locations \ |
572 @return: a modified copy of the given CanFestival network editor model |
580 @return: a modified copy of the given CanFestival network editor model |
573 """ |
581 """ |
574 |
582 |
575 dcfgenerator = ConciseDCFGenerator(nodelist, nodename) |
583 dcfgenerator = ConciseDCFGenerator(nodelist, nodename) |
576 dcfgenerator.GenerateDCF(locations, current_location, sync_TPDOs) |
584 dcfgenerator.GenerateDCF(locations, current_location, sync_TPDOs) |
577 return dcfgenerator.GetMasterNode() |
585 return dcfgenerator.GetMasterNode(), dcfgenerator.GetPointedVariables() |
578 |
586 |
579 if __name__ == "__main__": |
587 if __name__ == "__main__": |
580 import os, sys, getopt |
588 import os, sys, getopt |
581 |
589 |
582 def usage(): |
590 def usage(): |