--- a/LPCBeremiz.py Tue Feb 07 19:14:10 2012 +0100
+++ b/LPCBeremiz.py Sat Feb 11 00:02:02 2012 +0100
@@ -60,6 +60,8 @@
from plugger import PluginsRoot, PlugTemplate, opjimg, connectors
+from plugins.canfestival import RootClass as CanOpenRootClass +from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager from plcopen.structures import LOCATIONDATATYPES
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
@@ -188,6 +190,9 @@
return self.VariableLocationTree
raise KeyError, "Only 'children' key is available"
@@ -355,6 +360,93 @@
return [(Gen_Module_path, matiec_flags)],"",True
#-------------------------------------------------------------------------------
+# LPC CanFestival Plugin Class +#------------------------------------------------------------------------------- + "CAN_Baudrate": "125K", +class LPCCanOpenSlave(_SlavePlug): + XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> + <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <xsd:element name="CanFestivalSlaveNode"> + <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/> + <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/> + <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/> + <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50"> + <xsd:restriction base="xsd:integer"> + <xsd:minInclusive value="1"/> + <xsd:maxInclusive value="99"/> + # TODO change netname when name change + NodeManager.__init__(self) + odfilepath = self.GetSlaveODPath() + if(os.path.isfile(odfilepath)): + self.OpenFileInCurrent(odfilepath) + self.CreateNewNode("SlaveNode", # Name - will be changed at build time + 0x00, # NodeID - will be changed at build time + def GetCanDevice(self): + return str(self.BaseParams.getIEC_Channel()) +class LPCCanOpenMaster(_NodeListPlug): + XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> + <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <xsd:element name="CanFestivalNode"> + <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/> + <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/> + <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/> + def GetCanDevice(self): + return str(self.BaseParams.getIEC_Channel()) +class LPCCanOpen(CanOpenRootClass): + PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"), + ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")] + def GetCanDriver(self): + PlugTemplate.LoadChilds(self) + if self.GetChildByName("Master") is None: + master = self.PlugAddChild("Master", "CanOpenNode", 0) + master.BaseParams.setEnabled(False) + if self.GetChildByName("Slave") is None: + slave = self.PlugAddChild("Slave", "CanOpenSlave", 1) + slave.BaseParams.setEnabled(False) +#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -411,7 +503,7 @@
PluginsRoot.__init__(self, frame, logger)
- self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
+ self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] @@ -590,6 +682,11 @@
#Load and init all the childs
+ if self.GetChildByName("CanOpen") is None: + canopen = self.PlugAddChild("CanOpen", "CanOpen", 0) + canopen.BaseParams.setEnabled(False) if self.PlugTestModified():
@@ -1043,9 +1140,12 @@
self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
+ leftwindowvsizer = wx.BoxSizer(wx.VERTICAL) + leftwindow.SetSizer(leftwindowvsizer) leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
- leftwindow.SetSizer(leftwindowsizer)
+ leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0) st = wx.StaticText(leftwindow, -1)
st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
st.SetLabel(plugin.GetFullIEC_Channel())
@@ -1105,9 +1205,7 @@
st.SetLabel(plugin.MandatoryParams[1].getName())
leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
- rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
- rightwindow.SetBackgroundColour(bkgdclr)
+ rightwindow = self.GenerateParamsPanel(plugin, bkgdclr) self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
self.PluginInfos[plugin]["left"] = leftwindow
--- a/plugins/canfestival/canfestival.py Tue Feb 07 19:14:10 2012 +0100
+++ b/plugins/canfestival/canfestival.py Sat Feb 11 00:02:02 2012 +0100
@@ -13,6 +13,9 @@
from commondialogs import CreateNodeDialog
+from SlaveEditor import SlaveEditor +from NetworkEditor import NetworkEditor from gnosis.xml.pickle import *
from gnosis.xml.pickle.util import setParanoia
@@ -59,9 +62,8 @@
- def GetSlaveODPath(self):
- return os.path.join(self.PlugPath(), 'slave.od')
+ EditorType = SlaveEditor # TODO change netname when name change
@@ -97,34 +99,18 @@
+ def GetSlaveODPath(self): + return os.path.join(self.PlugPath(), 'slave.od') + def GetCanDevice(self): + return self.CanFestivalSlaveNode.getCan_Device()
- open_objdictedit = True
- has_permissions = self.GetPlugRoot().CheckProjectPathPerm()
- if not has_permissions:
- dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame,
- _("You don't have write permissions.\nOpen ObjDictEdit anyway ?"),
- wx.YES_NO|wx.ICON_QUESTION)
- open_objdictedit = dialog.ShowModal() == wx.ID_YES
- self.GetPlugRoot().SaveProject()
- self._View = objdictedit(self.GetPlugRoot().AppFrame, self)
- # TODO redefine BusId when IEC channel change
- self._View.SetBusId(self.GetCurrentLocation())
- self._View._onclose = _onclose
- self._View._onsave = _onsave
+ PlugTemplate._OpenView(self) + if self._View is not None: + self._View.SetBusId(self.GetCurrentLocation()) {"bitmap" : os.path.join("images", "NetworkEdit"),
@@ -143,6 +129,15 @@
return self.SaveCurrentInFile(self.GetSlaveODPath())
+ def SetParamsAttribute(self, path, value): + result = PlugTemplate.SetParamsAttribute(self, path, value) + # 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()) def PlugGenerate_C(self, buildpath, locations):
@@ -173,10 +168,38 @@
return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False
+ def LoadPrevious(self): + self.LoadCurrentPrevious() + def GetBufferState(self): + return self.GetCurrentBufferState() #--------------------------------------------------
#--------------------------------------------------
+class MiniNodeManager(NodeManager): + def __init__(self, parent, filepath, fullname): + NodeManager.__init__(self) + self.OpenFileInCurrent(filepath) + self.Fullname = fullname + def OnCloseEditor(self, view): + self.Parent.OnCloseEditor(view) + def PlugFullName(self): + def GetBufferState(self): + return self.GetCurrentBufferState() class _NodeListPlug(NodeList):
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
@@ -190,56 +213,61 @@
+ EditorType = NetworkEditor - # TODO change netname when name change
- NodeList.__init__(self, manager, self.BaseParams.getName())
+ NodeList.__init__(self, manager) self.LoadProject(self.PlugPath())
+ self.SetNetworkName(self.BaseParams.getName()) + def GetCanDevice(self): + return self.CanFestivalNode.getCan_Device() + def SetParamsAttribute(self, path, value): + result = PlugTemplate.SetParamsAttribute(self, path, value) + # 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)
- open_networkedit = True
- has_permissions = self.GetPlugRoot().CheckProjectPathPerm()
- if not has_permissions:
- dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame,
- _("You don't have write permissions.\nOpen NetworkEdit anyway ?"),
- wx.YES_NO|wx.ICON_QUESTION)
- open_networkedit = dialog.ShowModal() == wx.ID_YES
- self.GetPlugRoot().SaveProject()
- self._View = networkedit(self.GetPlugRoot().AppFrame, self)
- # TODO redefine BusId when IEC channel change
- self._View.SetBusId(self.GetCurrentLocation())
- self._View._onclose = _onclose
- self._View._onsave = _onsave
+ PlugTemplate._OpenView(self) + if self._View is not None: + self._View.SetBusId(self.GetCurrentLocation()) def _ShowMasterGenerated(self):
- buildpath = self._getBuildPath()
- # Eventually create build dir
- if not os.path.exists(buildpath):
- self.GetPlugRoot().logger.write_error(_("Error: No PLC built\n"))
- masterpath = os.path.join(buildpath, "MasterGenerated.od")
- if not os.path.exists(masterpath):
- self.GetPlugRoot().logger.write_error(_("Error: No Master generated\n"))
- new_dialog = objdictedit(None, filesOpen=[masterpath])
+ if self._GeneratedView is None: + buildpath = self._getBuildPath() + # Eventually create build dir + if not os.path.exists(buildpath): + self.GetPlugRoot().logger.write_error(_("Error: No PLC built\n")) + masterpath = os.path.join(buildpath, "MasterGenerated.od") + if not os.path.exists(masterpath): + self.GetPlugRoot().logger.write_error(_("Error: No Master generated\n")) + app_frame = self.GetPlugRoot().AppFrame + manager = MiniNodeManager(self, masterpath, self.PlugFullName() + ".generated_master") + self._GeneratedView = SlaveEditor(app_frame.TabsOpened, manager, app_frame, False) + app_frame.EditProjectElement(self._GeneratedView, "MasterGenerated") + def _CloseGenerateView(self): + if self._GeneratedView is not None: + app_frame = self.GetPlugRoot().AppFrame + if app_frame is not None: + app_frame.DeletePage(self._GeneratedView) {"bitmap" : os.path.join("images", "NetworkEdit"),
"name" : _("Edit network"),
@@ -250,10 +278,16 @@
"tooltip" : _("Show Master generated by config_utils"),
"method" : "_ShowMasterGenerated"}
+ def OnCloseEditor(self, view): + PlugTemplate.OnCloseEditor(self, view) + if self._GeneratedView == view: + self._GeneratedView = None
+ PlugTemplate.OnPlugClose(self) + self._CloseGenerateView() def PlugTestModified(self):
return self.ChangesToSave or self.HasChanged()
@@ -275,6 +309,7 @@
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
+ self._CloseGenerateView() current_location = self.GetCurrentLocation()
# define a unique name for the generated C file
prefix = "_".join(map(str, current_location))
@@ -295,6 +330,15 @@
return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False
+ def LoadPrevious(self): + self.Manager.LoadCurrentPrevious() + self.Manager.LoadCurrentNext() + def GetBufferState(self): + return self.Manager.GetCurrentBufferState() XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
@@ -317,14 +361,22 @@
if child["name"] == "CAN_Driver":
DLL_LIST= getattr(local_canfestival_config,"DLL_LIST",None)
- child["type"] = DLL_LIST
+ child["type"] = DLL_LIST
+ def GetCanDriver(self): + can_driver = self.CanFestivalInstance.getCAN_Driver() + if sys.platform == 'win32': + if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(can_driver + '_DEBUG.dll'))): + can_driver += '_DEBUG.dll' def PlugGenerate_C(self, buildpath, locations):
format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())),
- "candriver" : self.CanFestivalInstance.getCAN_Driver(),
+ "candriver" : self.GetCanDriver(), @@ -357,29 +409,34 @@
# initialize and declare node boot status variables for post_SlaveBootup lookup
SlaveIDs = child.GetSlaveIDs()
+ # define post_SlaveBootup lookup functions format_dict["slavebootups"] += (
- "int %s_slave_%d_booted = 0;\n"%(nodename, id))
- # define post_SlaveBootup lookup functions
- format_dict["slavebootups"] += (
- "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+
- # one case per declared node, mark node as booted
+ "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){}\n"%(nodename)) + format_dict["slavebootups"] += ( + "int %s_slave_%d_booted = 0;\n"%(nodename, id)) + # define post_SlaveBootup lookup functions format_dict["slavebootups"] += (
- " %s_slave_%d_booted = 1;\n"%(nodename, id)+
- format_dict["slavebootups"] += (
- # expression to test if all declared nodes booted
- format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs])
- format_dict["slavebootups"] += " )\n" + (
- " Master_post_SlaveBootup(d,nodeId);\n"+
+ "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+ + # one case per declared node, mark node as booted + format_dict["slavebootups"] += ( + " %s_slave_%d_booted = 1;\n"%(nodename, id)+ + format_dict["slavebootups"] += ( + # expression to test if all declared nodes booted + format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs]) + format_dict["slavebootups"] += " )\n" + ( + " Master_post_SlaveBootup(d,nodeId);\n"+ # register previously declared func as post_SlaveBootup callback for that node
format_dict["slavebootup_register"] += (
"%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename))
@@ -409,16 +466,11 @@
# Declare CAN channels according user filled config
format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%(
- child_data.getCAN_Device(),
child_data.getCAN_Baudrate())
format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename)
format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename)
- format_dict["nodes_stop"] += 'NODE_STOP(%s)\n '%(nodename)
- if sys.platform == 'win32':
- if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(format_dict["candriver"] + '_DEBUG.dll'))):
- format_dict["candriver"] += '_DEBUG.dll'
- format_dict["candriver"] += '.dll'
+ format_dict["nodes_stop"] += 'NODE_STOP(%s)\n '%(nodename) filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c")
cf_main = open(filename).read() % format_dict