def _OpenView(self, name=None, onlyopened=False): if name == "Generated master": app_frame = self.GetCTRoot().AppFrame if self._GeneratedMasterView is None: buildpath = self._getBuildPath() # Eventually create build dir if not os.path.exists(buildpath): self.GetCTRoot().logger.write_error( _("Error: No PLC built\n")) return masterpath = os.path.join(buildpath, "MasterGenerated.od") if not os.path.exists(masterpath): self.GetCTRoot().logger.write_error( _("Error: No Master generated\n")) return manager = MiniNodeManager(self, masterpath, self.CTNFullName()) self._GeneratedMasterView = MasterViewer( app_frame.TabsOpened, manager, app_frame, name) if self._GeneratedMasterView is not None: app_frame.EditProjectElement( self._GeneratedMasterView, self._GeneratedMasterView.GetInstancePath()) return self._GeneratedMasterView else: ConfigTreeNode._OpenView(self, name, onlyopened) if self._View is not None: self._View.SetBusId(self.GetCurrentLocation()) return self._View
class _NodeListCTN(NodeList): XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="CanFestivalNode"> <xsd:complexType> <xsd:attribute name="CAN_Device" type="xsd:string" use="optional"/> <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional"/> <xsd:attribute name="NodeId" type="xsd:integer" use="optional" default="1"/> <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/> </xsd:complexType> </xsd:element> </xsd:schema> """ EditorType = NetworkEditor IconPath = os.path.join(CanFestivalPath, "objdictgen", "networkedit.png") def __init__(self): manager = _NodeManager(self) NodeList.__init__(self, manager) self.LoadProject(self.CTNPath()) self.SetNetworkName(self.BaseParams.getName()) def GetCanDevice(self): return self.CanFestivalNode.getCAN_Device() def SetParamsAttribute(self, path, value): if path == "CanFestivalNode.NodeId": nodeid = self.CanFestivalNode.getNodeId() if value != nodeid: slaves = self.GetSlaveIDs() dir = (value - nodeid) / abs(value - nodeid) while value in slaves and value >= 0: value += dir if value < 0: value = nodeid value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value) refresh_network = False # Filter IEC_Channel and Name, that have specific behavior if path == "BaseParams.IEC_Channel" and self._View is not None: self._View.SetBusId(self.GetCurrentLocation()) elif path == "BaseParams.Name": self.SetNetworkName(value) refresh_network = True elif path == "CanFestivalNode.NodeId": refresh_network = True if refresh_network and self._View is not None: wx.CallAfter(self._View.RefreshBufferState) return value, refresh def GetVariableLocationTree(self): current_location = self.GetCurrentLocation() nodeindexes = self.SlaveNodes.keys() nodeindexes.sort() children = [] children += [ GetSlaveLocationTree(self.Manager.GetCurrentNodeCopy(), current_location, _("Local entries")) ] children += [ GetSlaveLocationTree(self.SlaveNodes[nodeid]["Node"], current_location + (nodeid, ), self.SlaveNodes[nodeid]["Name"]) for nodeid in nodeindexes ] return { "name": self.BaseParams.getName(), "type": LOCATION_CONFNODE, "location": self.GetFullIEC_Channel(), "children": children } _GeneratedMasterView = None def _ShowGeneratedMaster(self): self._OpenView("Generated master") def _OpenView(self, name=None, onlyopened=False): if name == "Generated master": app_frame = self.GetCTRoot().AppFrame if self._GeneratedMasterView is None: buildpath = self._getBuildPath() # Eventually create build dir if not os.path.exists(buildpath): self.GetCTRoot().logger.write_error( _("Error: No PLC built\n")) return masterpath = os.path.join(buildpath, "MasterGenerated.od") if not os.path.exists(masterpath): self.GetCTRoot().logger.write_error( _("Error: No Master generated\n")) return manager = MiniNodeManager(self, masterpath, self.CTNFullName()) self._GeneratedMasterView = MasterViewer( app_frame.TabsOpened, manager, app_frame, name) if self._GeneratedMasterView is not None: app_frame.EditProjectElement( self._GeneratedMasterView, self._GeneratedMasterView.GetInstancePath()) return self._GeneratedMasterView else: ConfigTreeNode._OpenView(self, name, onlyopened) if self._View is not None: self._View.SetBusId(self.GetCurrentLocation()) return self._View ConfNodeMethods = [{ "bitmap": "ShowMaster", "name": _("Show Master"), "tooltip": _("Show Master generated by config_utils"), "method": "_ShowGeneratedMaster" }] def OnCloseEditor(self, view): ConfigTreeNode.OnCloseEditor(self, view) if self._GeneratedMasterView == view: self._GeneratedMasterView = None def OnCTNClose(self): ConfigTreeNode.OnCTNClose(self) self._CloseView(self._GeneratedMasterView) return True def CTNTestModified(self): return self.ChangesToSave or self.HasChanged() def OnCTNSave(self, from_project_path=None): self.SetRoot(self.CTNPath()) if from_project_path is not None: shutil.copytree(self.GetEDSFolder(from_project_path), self.GetEDSFolder()) return self.SaveProject() is None def CTNGenerate_C(self, buildpath, locations): """ Generate C code @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) @param locations: List of complete variables locations \ [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) "NAME" : name of the variable (generally "__IW0_1_2" style) "DIR" : direction "Q","I" or "M" "SIZE" : size "X", "B", "W", "D", "L" "LOC" : tuple of interger for IEC location (0,1,2,...) }, ...] @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND """ self._CloseView(self._GeneratedMasterView) current_location = self.GetCurrentLocation() # define a unique name for the generated C file prefix = "_".join(map(str, current_location)) Gen_OD_path = os.path.join(buildpath, "OD_%s.c" % prefix) # Create a new copy of the model with DCF loaded with PDO mappings for desired location try: master, pointers = config_utils.GenerateConciseDCF( locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(), "OD_%s" % prefix) except config_utils.PDOmappingException, e: raise Exception(e.message) # Do generate C file. res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers) if res: raise Exception(res) file = open(os.path.join(buildpath, "MasterGenerated.od"), "w") dump(master, file) file.close() return [ (Gen_OD_path, local_canfestival_config.getCFLAGS(CanFestivalPath)) ], "", False