# HG changeset patch # User Laurent Bessard # Date 1364336670 -3600 # Node ID de812e25821337168ddab4c22a81c9323f0937f0 # Parent 15c05ba95df48733e84d81c740305a230094b132 Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog diff -r 15c05ba95df4 -r de812e258213 canfestival/NetworkEditor.py --- a/canfestival/NetworkEditor.py Tue Mar 26 12:44:44 2013 +0900 +++ b/canfestival/NetworkEditor.py Tue Mar 26 23:24:30 2013 +0100 @@ -2,7 +2,7 @@ import wx from subindextable import EditingPanel -from networkedit import NetworkEditorTemplate +from networkeditortemplate import NetworkEditorTemplate from editors.ConfTreeNodeEditor import ConfTreeNodeEditor [ID_NETWORKEDITOR, diff -r 15c05ba95df4 -r de812e258213 canfestival/canfestival.py --- a/canfestival/canfestival.py Tue Mar 26 12:44:44 2013 +0900 +++ b/canfestival/canfestival.py Tue Mar 26 23:24:30 2013 +0100 @@ -9,12 +9,12 @@ from nodelist import NodeList from nodemanager import NodeManager import config_utils, gen_cfile, eds_utils -from networkedit import networkedit -from objdictedit import objdictedit import canfestival_config as local_canfestival_config from ConfigTreeNode import ConfigTreeNode from commondialogs import CreateNodeDialog - +from subindextable import IECTypeConversion, SizeConversion + +from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY from SlaveEditor import SlaveEditor, MasterViewer from NetworkEditor import NetworkEditor @@ -26,6 +26,32 @@ AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale")) #-------------------------------------------------- +# Location Tree Helper +#-------------------------------------------------- + +def GetSlaveLocationTree(slave_node, current_location, name): + entries = [] + for index, subindex, size, entry_name in slave_node.GetMapVariableList(): + subentry_infos = slave_node.GetSubentryInfos(index, subindex) + typeinfos = slave_node.GetEntryInfos(subentry_infos["type"]) + if typeinfos: + entries.append({ + "name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry_name), + "type": LOCATION_VAR_MEMORY, + "size": size, + "IEC_type": IECTypeConversion.get(typeinfos["name"]), + "var_name": "%s_%4.4x_%2.2x" % ("_".join(name.split()), index, subindex), + "location": "%s%s"%(SizeConversion[size], ".".join(map(str, current_location + + (index, subindex)))), + "description": "", + "children": []}) + return {"name": name, + "type": LOCATION_CONFNODE, + "location": ".".join([str(i) for i in current_location]) + ".x", + "children": entries + } + +#-------------------------------------------------- # SLAVE #-------------------------------------------------- @@ -139,7 +165,13 @@ self._View.SetBusId(self.GetCurrentLocation()) return result - + + def GetVariableLocationTree(self): + current_location = self.GetCurrentLocation() + return GetSlaveLocationTree(self.CurrentNode, + self.GetCurrentLocation(), + self.BaseParams.getName()) + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @@ -277,7 +309,23 @@ 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() + return {"name": self.BaseParams.getName(), + "type": LOCATION_CONFNODE, + "location": self.GetFullIEC_Channel(), + "children": [GetSlaveLocationTree(self.Manager.GetCurrentNodeCopy(), + current_location, + _("Local entries"))] + + [GetSlaveLocationTree(self.SlaveNodes[nodeid]["Node"], + current_location + (nodeid,), + self.SlaveNodes[nodeid]["Name"]) + for nodeid in nodeindexes] + } + _GeneratedMasterView = None def _ShowGeneratedMaster(self): self._OpenView("Generated master")