lpcmanager

163b46d0412b
Parents 2faf6a91e2d8
Children 4c317d315093
Moved CanFestival plugin customization code to LPCCanFestival.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCCanFestival.py Mon Feb 05 15:48:38 2018 +0100
@@ -0,0 +1,135 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from canfestival import RootClass as CanOpenRootClass
+from canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager
+from canfestival.NetworkEditor import NetworkEditor
+from canfestival.SlaveEditor import SlaveEditor
+
+from canfestival import canfestival
+defaultGetCFLAGS = canfestival.local_canfestival_config.getCFLAGS
+defaultGetLDFLAGS = canfestival.local_canfestival_config.getLDFLAGS
+
+def getCFLAGS(*args):
+ return str(defaultGetCFLAGS(*args))
+
+def getLDFLAGS(*args):
+ return str(defaultGetLDFLAGS(*args))
+
+canfestival.local_canfestival_config.getCFLAGS = getCFLAGS
+canfestival.local_canfestival_config.getLDFLAGS = getLDFLAGS
+
+DEFAULT_SETTINGS = {
+ "CAN_Baudrate": "125K",
+ "Slave_NodeId": 2,
+ "Master_NodeId": 1,
+}
+
+class LPCSlaveEditor(SlaveEditor):
+ # SHOW_BASE_PARAMS = False
+ pass
+
+
+class LPCCanOpenSlave(_SlaveCTN):
+ XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:element name="CanFestivalSlaveNode">
+ <xsd:complexType>
+ <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
+ <xsd:attribute name="NodeId" type="xsd:integer" 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:simpleType>
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="1"/>
+ <xsd:maxInclusive value="99"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ """ % DEFAULT_SETTINGS
+
+ EditorType = LPCSlaveEditor
+
+ def __init__(self):
+ # TODO change netname when name change
+ NodeManager.__init__(self)
+ odfilepath = self.GetSlaveODPath()
+ if (os.path.isfile(odfilepath)):
+ self.OpenFileInCurrent(odfilepath)
+ else:
+ self.CreateNewNode("SlaveNode", # Name - will be changed at build time
+ 0x00, # NodeID - will be changed at build time
+ "slave", # Type
+ "", # description
+ "None", # profile
+ "", # prfile filepath
+ "heartbeat", # NMT
+ []) # options
+ self.OnCTNSave()
+
+ def GetCanDevice(self):
+ return str(self.BaseParams.getIEC_Channel())
+
+ ConfNodeMethods = [
+ {"bitmap": "NetworkEdit",
+ "name": _("Edit slave"),
+ "tooltip": _("Edit CanOpen slave with ObjdictEdit"),
+ "method": "_OpenView"},
+ ] + _SlaveCTN.ConfNodeMethods
+
+
+class LPCNetworkEditor(NetworkEditor):
+ # SHOW_BASE_PARAMS = False
+ pass
+
+
+class LPCCanOpenMaster(_NodeListCTN):
+ 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_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
+ <xsd:attribute name="NodeId" type="xsd:integer" use="optional" default="%(Master_NodeId)d"/>
+ <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ """ % DEFAULT_SETTINGS
+
+ EditorType = LPCNetworkEditor
+
+ def GetCanDevice(self):
+ return str(self.BaseParams.getIEC_Channel())
+
+ ConfNodeMethods = [
+ {"bitmap": "NetworkEdit",
+ "name": _("Edit network"),
+ "tooltip": _("Edit CanOpen Network with NetworkEdit"),
+ "method": "_OpenView"},
+ ] + _NodeListCTN.ConfNodeMethods
+
+
+class LPCCanOpen(CanOpenRootClass):
+ XSD = None
+ CTNChildrenTypes = [("CanOpenNode", LPCCanOpenMaster, "CanOpen Master"),
+ ("CanOpenSlave", LPCCanOpenSlave, "CanOpen Slave")]
+
+ def GetCanDriver(self):
+ return None
+
+ def LoadChildren(self):
+ ConfigTreeNode.LoadChildren(self)
+
+ if self.GetChildByName("Master") is None:
+ master = self.CTNAddChild("Master", "CanOpenNode", 0)
+ # master.BaseParams.setEnabled(False)
+ master.CTNRequestSave()
+
+ if self.GetChildByName("Slave") is None:
+ slave = self.CTNAddChild("Slave", "CanOpenSlave", 1)
+ # slave.BaseParams.setEnabled(False)
+ slave.CTNRequestSave()
+
--- a/LPCManager.py Mon Feb 05 15:47:22 2018 +0100
+++ b/LPCManager.py Mon Feb 05 15:48:38 2018 +0100
@@ -822,36 +822,6 @@
return name
PLCControler.GenerateNewName = newGenerateNewName
-
-havecanfestival = False
-# try:
-from canfestival import RootClass as CanOpenRootClass
-from canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager
-from canfestival.NetworkEditor import NetworkEditor
-from canfestival.SlaveEditor import SlaveEditor
-
-havecanfestival = True
-# except:
-# havecanfestival = False
-
-# ConfTreeNodeEditor.SHOW_BASE_PARAMS = False
-
-# -------------------------------------------------------------------------------
-# CANFESTIVAL CONFNODE HACK
-# -------------------------------------------------------------------------------
-from canfestival import canfestival
-defaultGetCFLAGS = canfestival.local_canfestival_config.getCFLAGS
-defaultGetLDFLAGS = canfestival.local_canfestival_config.getLDFLAGS
-
-def getCFLAGS(*args):
- return str(defaultGetCFLAGS(*args))
-
-def getLDFLAGS(*args):
- return str(defaultGetLDFLAGS(*args))
-
-canfestival.local_canfestival_config.getCFLAGS = getCFLAGS
-canfestival.local_canfestival_config.getLDFLAGS = getLDFLAGS
-
import LPCBus as LPCBus_mod
if arch in PLC_module:
@@ -861,128 +831,6 @@
LPCBus_mod.LPCarch = arch
LPCBus_mod.arch = arch
-from LPCBus import *
-
-# -------------------------------------------------------------------------------
-# LPC CanFestival ConfNode Class
-# -------------------------------------------------------------------------------
-
-if havecanfestival:
- DEFAULT_SETTINGS = {
- "CAN_Baudrate": "125K",
- "Slave_NodeId": 2,
- "Master_NodeId": 1,
- }
-
-
-class LPCSlaveEditor(SlaveEditor):
- # SHOW_BASE_PARAMS = False
- pass
-
-
-class LPCCanOpenSlave(_SlaveCTN):
- XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:element name="CanFestivalSlaveNode">
- <xsd:complexType>
- <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
- <xsd:attribute name="NodeId" type="xsd:integer" 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:simpleType>
- <xsd:restriction base="xsd:integer">
- <xsd:minInclusive value="1"/>
- <xsd:maxInclusive value="99"/>
- </xsd:restriction>
- </xsd:simpleType>
- </xsd:attribute>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- """ % DEFAULT_SETTINGS
-
- EditorType = LPCSlaveEditor
-
- def __init__(self):
- # TODO change netname when name change
- NodeManager.__init__(self)
- odfilepath = self.GetSlaveODPath()
- if (os.path.isfile(odfilepath)):
- self.OpenFileInCurrent(odfilepath)
- else:
- self.CreateNewNode("SlaveNode", # Name - will be changed at build time
- 0x00, # NodeID - will be changed at build time
- "slave", # Type
- "", # description
- "None", # profile
- "", # prfile filepath
- "heartbeat", # NMT
- []) # options
- self.OnCTNSave()
-
- def GetCanDevice(self):
- return str(self.BaseParams.getIEC_Channel())
-
- ConfNodeMethods = [
- {"bitmap": "NetworkEdit",
- "name": _("Edit slave"),
- "tooltip": _("Edit CanOpen slave with ObjdictEdit"),
- "method": "_OpenView"},
- ] + _SlaveCTN.ConfNodeMethods
-
-
-class LPCNetworkEditor(NetworkEditor):
- # SHOW_BASE_PARAMS = False
- pass
-
-
-class LPCCanOpenMaster(_NodeListCTN):
- 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_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
- <xsd:attribute name="NodeId" type="xsd:integer" use="optional" default="%(Master_NodeId)d"/>
- <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- """ % DEFAULT_SETTINGS
-
- EditorType = LPCNetworkEditor
-
- def GetCanDevice(self):
- return str(self.BaseParams.getIEC_Channel())
-
- ConfNodeMethods = [
- {"bitmap": "NetworkEdit",
- "name": _("Edit network"),
- "tooltip": _("Edit CanOpen Network with NetworkEdit"),
- "method": "_OpenView"},
- ] + _NodeListCTN.ConfNodeMethods
-
-
-class LPCCanOpen(CanOpenRootClass):
- XSD = None
- CTNChildrenTypes = [("CanOpenNode", LPCCanOpenMaster, "CanOpen Master"),
- ("CanOpenSlave", LPCCanOpenSlave, "CanOpen Slave")]
-
- def GetCanDriver(self):
- return None
-
- def LoadChildren(self):
- ConfigTreeNode.LoadChildren(self)
-
- if self.GetChildByName("Master") is None:
- master = self.CTNAddChild("Master", "CanOpenNode", 0)
- # master.BaseParams.setEnabled(False)
- master.CTNRequestSave()
-
- if self.GetChildByName("Slave") is None:
- slave = self.CTNAddChild("Slave", "CanOpenSlave", 1)
- # slave.BaseParams.setEnabled(False)
- slave.CTNRequestSave()
-
if __name__ == '__main__':
--- a/LPCProjectController.py Mon Feb 05 15:47:22 2018 +0100
+++ b/LPCProjectController.py Mon Feb 05 15:48:38 2018 +0100
@@ -130,10 +130,7 @@
ProjectController.__init__(self, frame, logger)
- if havecanfestival:
- self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
- else:
- self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
+ self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
self.CTNType = "LPC"
self.OnlineMode = "NORMAL" if arch in PLC_module else "OFF"
@@ -361,14 +358,11 @@
self.LoadChildren()
canopen_child = self.GetChildByName("CanOpen")
- if havecanfestival and canopen_child is None:
+ if canopen_child is None:
canopen = self.CTNAddChild("CanOpen", "CanOpen", 0)
canopen.LoadChildren()
canopen.CTNRequestSave()
- elif not havecanfestival and canopen_child is not None:
- canopen_child.CTNRemove()
-
if self.CTNTestModified():
self.SaveProject()