author | Edouard Tisserant |
Wed, 25 Feb 2015 13:59:01 +0100 | |
changeset 1451 | 94e620cbd9de |
parent 1279 | 0eb9f8af479f |
child 1464 | 2b4a0d87becb |
permissions | -rw-r--r-- |
1061 | 1 |
import os, sys, shutil |
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
802
diff
changeset
|
2 |
|
20 | 3 |
base_folder = os.path.split(sys.path[0])[0] |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
4 |
CanFestivalPath = os.path.join(base_folder, "CanFestival-3") |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
5 |
sys.path.append(os.path.join(CanFestivalPath, "objdictgen")) |
20 | 6 |
|
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
802
diff
changeset
|
7 |
import wx |
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
802
diff
changeset
|
8 |
|
11 | 9 |
from nodelist import NodeList |
10 |
from nodemanager import NodeManager |
|
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
11 |
import config_utils, gen_cfile, eds_utils |
512
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
427
diff
changeset
|
12 |
import canfestival_config as local_canfestival_config |
725 | 13 |
from ConfigTreeNode import ConfigTreeNode |
169
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
14 |
from commondialogs import CreateNodeDialog |
1003
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
15 |
from subindextable import IECTypeConversion, SizeConversion |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
16 |
|
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
17 |
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
777 | 18 |
from SlaveEditor import SlaveEditor, MasterViewer |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
19 |
from NetworkEditor import NetworkEditor |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
20 |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
21 |
from gnosis.xml.pickle import * |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
22 |
from gnosis.xml.pickle.util import setParanoia |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
23 |
setParanoia(0) |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
24 |
|
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
802
diff
changeset
|
25 |
from util.TranslationCatalogs import AddCatalog |
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
802
diff
changeset
|
26 |
AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale")) |
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
802
diff
changeset
|
27 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
28 |
#-------------------------------------------------- |
1003
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
29 |
# Location Tree Helper |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
30 |
#-------------------------------------------------- |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
31 |
|
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
32 |
def GetSlaveLocationTree(slave_node, current_location, name): |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
33 |
entries = [] |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
34 |
for index, subindex, size, entry_name in slave_node.GetMapVariableList(): |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
35 |
subentry_infos = slave_node.GetSubentryInfos(index, subindex) |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
36 |
typeinfos = slave_node.GetEntryInfos(subentry_infos["type"]) |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
37 |
if typeinfos: |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
38 |
entries.append({ |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
39 |
"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry_name), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
40 |
"type": LOCATION_VAR_MEMORY, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
41 |
"size": size, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
42 |
"IEC_type": IECTypeConversion.get(typeinfos["name"]), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
43 |
"var_name": "%s_%4.4x_%2.2x" % ("_".join(name.split()), index, subindex), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
44 |
"location": "%s%s"%(SizeConversion[size], ".".join(map(str, current_location + |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
45 |
(index, subindex)))), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
46 |
"description": "", |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
47 |
"children": []}) |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
48 |
return {"name": name, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
49 |
"type": LOCATION_CONFNODE, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
50 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
51 |
"children": entries |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
52 |
} |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
53 |
|
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
54 |
#-------------------------------------------------- |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
55 |
# SLAVE |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
56 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
57 |
|
718 | 58 |
class _SlaveCTN(NodeManager): |
12 | 59 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
60 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
166 | 61 |
<xsd:element name="CanFestivalSlaveNode"> |
12 | 62 |
<xsd:complexType> |
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
63 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="optional"/> |
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
64 |
<xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional"/> |
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
65 |
<xsd:attribute name="NodeId" type="xsd:integer" use="optional" default="2"/> |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
66 |
<xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/> |
203 | 67 |
<xsd:attribute name="Sync_Align_Ratio" use="optional" default="50"> |
68 |
<xsd:simpleType> |
|
69 |
<xsd:restriction base="xsd:integer"> |
|
70 |
<xsd:minInclusive value="1"/> |
|
71 |
<xsd:maxInclusive value="99"/> |
|
72 |
</xsd:restriction> |
|
73 |
</xsd:simpleType> |
|
74 |
</xsd:attribute> |
|
12 | 75 |
</xsd:complexType> |
76 |
</xsd:element> |
|
77 |
</xsd:schema> |
|
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
78 |
""" |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
79 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
80 |
EditorType = SlaveEditor |
738 | 81 |
IconPath = os.path.join(CanFestivalPath, "objdictgen", "networkedit.png") |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
82 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
83 |
def __init__(self): |
23 | 84 |
# TODO change netname when name change |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
85 |
NodeManager.__init__(self) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
86 |
odfilepath = self.GetSlaveODPath() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
87 |
if(os.path.isfile(odfilepath)): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
88 |
self.OpenFileInCurrent(odfilepath) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
89 |
else: |
169
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
90 |
self.FilePath = "" |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
91 |
dialog = CreateNodeDialog(None, wx.OK) |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
92 |
dialog.Type.Enable(False) |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
93 |
dialog.GenSYNC.Enable(False) |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
94 |
if dialog.ShowModal() == wx.ID_OK: |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
95 |
name, id, nodetype, description = dialog.GetValues() |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
96 |
profile, filepath = dialog.GetProfile() |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
97 |
NMT = dialog.GetNMTManagement() |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
98 |
options = dialog.GetOptions() |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
99 |
self.CreateNewNode(name, # Name - will be changed at build time |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
100 |
id, # NodeID - will be changed at build time |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
101 |
"slave", # Type |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
102 |
description,# description |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
103 |
profile, # profile |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
104 |
filepath, # prfile filepath |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
105 |
NMT, # NMT |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
106 |
options) # options |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
107 |
else: |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
108 |
self.CreateNewNode("SlaveNode", # Name - will be changed at build time |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
109 |
0x00, # NodeID - will be changed at build time |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
110 |
"slave", # Type |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
111 |
"", # description |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
112 |
"None", # profile |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
113 |
"", # prfile filepath |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
114 |
"heartbeat", # NMT |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
115 |
[]) # options |
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
116 |
dialog.Destroy() |
718 | 117 |
self.OnCTNSave() |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
118 |
|
845
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
119 |
def GetCurrentNodeName(self): |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
120 |
return self.CTNName() |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
121 |
|
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
122 |
def GetSlaveODPath(self): |
718 | 123 |
return os.path.join(self.CTNPath(), 'slave.od') |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
124 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
125 |
def GetCanDevice(self): |
948
89fead207c35
Fix semantic error while compiling project including canfestival extension instances
Laurent Bessard
parents:
847
diff
changeset
|
126 |
return self.CanFestivalSlaveNode.getCAN_Device() |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
127 |
|
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
782
diff
changeset
|
128 |
def _OpenView(self, name=None, onlyopened=False): |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
782
diff
changeset
|
129 |
ConfigTreeNode._OpenView(self, name, onlyopened) |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
130 |
if self._View is not None: |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
131 |
self._View.SetBusId(self.GetCurrentLocation()) |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
132 |
return self._View |
777 | 133 |
|
134 |
def _ExportSlave(self): |
|
847
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
135 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, |
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
136 |
_("Choose a file"), |
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
137 |
os.path.expanduser("~"), |
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
138 |
"%s.eds" % self.CTNName(), |
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
139 |
_("EDS files (*.eds)|*.eds|All files|*.*"), |
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
140 |
wx.SAVE|wx.OVERWRITE_PROMPT) |
777 | 141 |
if dialog.ShowModal() == wx.ID_OK: |
142 |
result = eds_utils.GenerateEDSFile(dialog.GetPath(), self.GetCurrentNodeCopy()) |
|
143 |
if result: |
|
144 |
self.GetCTRoot().logger.write_error(_("Error: Export slave failed\n")) |
|
145 |
dialog.Destroy() |
|
146 |
||
717 | 147 |
ConfNodeMethods = [ |
777 | 148 |
{"bitmap" : "ExportSlave", |
149 |
"name" : _("Export slave"), |
|
150 |
"tooltip" : _("Export CanOpen slave to EDS file"), |
|
151 |
"method" : "_ExportSlave"}, |
|
65 | 152 |
] |
777 | 153 |
|
718 | 154 |
def CTNTestModified(self): |
166 | 155 |
return self.ChangesToSave or self.OneFileHasChanged() |
12 | 156 |
|
1061 | 157 |
def OnCTNSave(self, from_project_path=None): |
166 | 158 |
return self.SaveCurrentInFile(self.GetSlaveODPath()) |
12 | 159 |
|
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
160 |
def SetParamsAttribute(self, path, value): |
717 | 161 |
result = ConfigTreeNode.SetParamsAttribute(self, path, value) |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
162 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
163 |
# Filter IEC_Channel and Name, that have specific behavior |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
164 |
if path == "BaseParams.IEC_Channel" and self._View is not None: |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
165 |
self._View.SetBusId(self.GetCurrentLocation()) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
166 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
167 |
return result |
1003
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
168 |
|
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
169 |
def GetVariableLocationTree(self): |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
170 |
current_location = self.GetCurrentLocation() |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
171 |
return GetSlaveLocationTree(self.CurrentNode, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
172 |
self.GetCurrentLocation(), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
173 |
self.BaseParams.getName()) |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
174 |
|
718 | 175 |
def CTNGenerate_C(self, buildpath, locations): |
12 | 176 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
177 |
Generate C code |
717 | 178 |
@param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
179 |
@param locations: List of complete variables locations \ |
22 | 180 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
181 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
182 |
"DIR" : direction "Q","I" or "M" |
|
183 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
184 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
185 |
}, ...] |
|
186 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 187 |
""" |
24 | 188 |
current_location = self.GetCurrentLocation() |
22 | 189 |
# define a unique name for the generated C file |
166 | 190 |
prefix = "_".join(map(str, current_location)) |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
191 |
Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix ) |
166 | 192 |
# Create a new copy of the model |
193 |
slave = self.GetCurrentNodeCopy() |
|
194 |
slave.SetNodeName("OD_%s"%prefix) |
|
195 |
# allow access to local OD from Slave PLC |
|
196 |
pointers = config_utils.LocalODPointers(locations, current_location, slave) |
|
197 |
res = gen_cfile.GenerateFile(Gen_OD_path, slave, pointers) |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
198 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
199 |
raise Exception, res |
172
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
200 |
res = eds_utils.GenerateEDSFile(os.path.join(buildpath, "Slave_%s.eds"%prefix), slave) |
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
201 |
if res : |
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
202 |
raise Exception, res |
512
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
427
diff
changeset
|
203 |
return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
204 |
|
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
205 |
def LoadPrevious(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
206 |
self.LoadCurrentPrevious() |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
207 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
208 |
def LoadNext(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
209 |
self.LoadCurrentNext() |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
210 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
211 |
def GetBufferState(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
212 |
return self.GetCurrentBufferState() |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
213 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
214 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
215 |
# MASTER |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
216 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
217 |
|
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
218 |
class MiniNodeManager(NodeManager): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
219 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
220 |
def __init__(self, parent, filepath, fullname): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
221 |
NodeManager.__init__(self) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
222 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
223 |
self.OpenFileInCurrent(filepath) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
224 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
225 |
self.Parent = parent |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
226 |
self.Fullname = fullname |
777 | 227 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
777
diff
changeset
|
228 |
def GetIconName(self): |
777 | 229 |
return None |
230 |
||
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
231 |
def OnCloseEditor(self, view): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
232 |
self.Parent.OnCloseEditor(view) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
233 |
|
718 | 234 |
def CTNFullName(self): |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
235 |
return self.Fullname |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
236 |
|
777 | 237 |
def CTNTestModified(self): |
238 |
return False |
|
239 |
||
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
240 |
def GetBufferState(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
241 |
return self.GetCurrentBufferState() |
777 | 242 |
|
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
243 |
ConfNodeMethods = [] |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
244 |
|
845
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
245 |
class _NodeManager(NodeManager): |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
246 |
|
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
247 |
def __init__(self, parent, *args, **kwargs): |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
248 |
NodeManager.__init__(self, *args, **kwargs) |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
249 |
self.Parent = parent |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
250 |
|
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
251 |
def __del__(self): |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
252 |
self.Parent = None |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
253 |
|
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
254 |
def GetCurrentNodeName(self): |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
255 |
return self.Parent.CTNName() |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
256 |
|
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
257 |
def GetCurrentNodeID(self): |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
258 |
return self.Parent.CanFestivalNode.getNodeId() |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
259 |
|
718 | 260 |
class _NodeListCTN(NodeList): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
261 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
262 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
263 |
<xsd:element name="CanFestivalNode"> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
264 |
<xsd:complexType> |
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
265 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="optional"/> |
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
266 |
<xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional"/> |
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
267 |
<xsd:attribute name="NodeId" type="xsd:integer" use="optional" default="1"/> |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
268 |
<xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
269 |
</xsd:complexType> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
270 |
</xsd:element> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
271 |
</xsd:schema> |
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
272 |
""" |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
273 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
274 |
EditorType = NetworkEditor |
738 | 275 |
IconPath = os.path.join(CanFestivalPath, "objdictgen", "networkedit.png") |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
276 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
277 |
def __init__(self): |
845
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
278 |
manager = _NodeManager(self) |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
279 |
NodeList.__init__(self, manager) |
718 | 280 |
self.LoadProject(self.CTNPath()) |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
281 |
self.SetNetworkName(self.BaseParams.getName()) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
282 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
283 |
def GetCanDevice(self): |
948
89fead207c35
Fix semantic error while compiling project including canfestival extension instances
Laurent Bessard
parents:
847
diff
changeset
|
284 |
return self.CanFestivalNode.getCAN_Device() |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
285 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
286 |
def SetParamsAttribute(self, path, value): |
845
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
287 |
if path == "CanFestivalNode.NodeId": |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
288 |
nodeid = self.CanFestivalNode.getNodeId() |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
289 |
if value != nodeid: |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
290 |
slaves = self.GetSlaveIDs() |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
291 |
dir = (value - nodeid) / abs(value - nodeid) |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
292 |
while value in slaves and value >= 0: |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
293 |
value += dir |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
294 |
if value < 0: |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
295 |
value = nodeid |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
296 |
|
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
297 |
value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value) |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
298 |
refresh_network = False |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
299 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
300 |
# Filter IEC_Channel and Name, that have specific behavior |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
301 |
if path == "BaseParams.IEC_Channel" and self._View is not None: |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
302 |
self._View.SetBusId(self.GetCurrentLocation()) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
303 |
elif path == "BaseParams.Name": |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
304 |
self.SetNetworkName(value) |
845
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
305 |
refresh_network = True |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
306 |
elif path == "CanFestivalNode.NodeId": |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
307 |
refresh_network = True |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
308 |
|
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
309 |
if refresh_network and self._View is not None: |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
310 |
wx.CallAfter(self._View.RefreshBufferState) |
412a9f05070f
Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents:
815
diff
changeset
|
311 |
return value, refresh |
1003
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
312 |
|
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
313 |
def GetVariableLocationTree(self): |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
314 |
current_location = self.GetCurrentLocation() |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
315 |
nodeindexes = self.SlaveNodes.keys() |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
316 |
nodeindexes.sort() |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
317 |
return {"name": self.BaseParams.getName(), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
318 |
"type": LOCATION_CONFNODE, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
319 |
"location": self.GetFullIEC_Channel(), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
320 |
"children": [GetSlaveLocationTree(self.Manager.GetCurrentNodeCopy(), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
321 |
current_location, |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
322 |
_("Local entries"))] + |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
323 |
[GetSlaveLocationTree(self.SlaveNodes[nodeid]["Node"], |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
324 |
current_location + (nodeid,), |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
325 |
self.SlaveNodes[nodeid]["Name"]) |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
326 |
for nodeid in nodeindexes] |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
327 |
} |
de812e258213
Fixed CanFestival extension, adding CANOpen entries in BrowseLocationsDialog
Laurent Bessard
parents:
976
diff
changeset
|
328 |
|
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
329 |
_GeneratedMasterView = None |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
330 |
def _ShowGeneratedMaster(self): |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
331 |
self._OpenView("Generated master") |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
332 |
|
782 | 333 |
def _OpenView(self, name=None, onlyopened=False): |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
334 |
if name == "Generated master": |
782 | 335 |
app_frame = self.GetCTRoot().AppFrame |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
336 |
if self._GeneratedMasterView is None: |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
337 |
buildpath = self._getBuildPath() |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
338 |
# Eventually create build dir |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
339 |
if not os.path.exists(buildpath): |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
340 |
self.GetCTRoot().logger.write_error(_("Error: No PLC built\n")) |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
341 |
return |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
342 |
|
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
343 |
masterpath = os.path.join(buildpath, "MasterGenerated.od") |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
344 |
if not os.path.exists(masterpath): |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
345 |
self.GetCTRoot().logger.write_error(_("Error: No Master generated\n")) |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
346 |
return |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
347 |
|
847
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
348 |
manager = MiniNodeManager(self, masterpath, self.CTNFullName()) |
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
349 |
self._GeneratedMasterView = MasterViewer(app_frame.TabsOpened, manager, app_frame, name) |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
350 |
|
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
782
diff
changeset
|
351 |
if self._GeneratedMasterView is not None: |
847
b157705a9024
Fix bug in generated master panel in CanFestival extension
laurent
parents:
845
diff
changeset
|
352 |
app_frame.EditProjectElement(self._GeneratedMasterView, self._GeneratedMasterView.GetInstancePath()) |
782 | 353 |
|
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
354 |
return self._GeneratedMasterView |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
355 |
else: |
782 | 356 |
ConfigTreeNode._OpenView(self, name, onlyopened) |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
357 |
if self._View is not None: |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
358 |
self._View.SetBusId(self.GetCurrentLocation()) |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
359 |
return self._View |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
360 |
|
717 | 361 |
ConfNodeMethods = [ |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
738
diff
changeset
|
362 |
{"bitmap" : "ShowMaster", |
372
35cc4c6a2936
Added ShowMaster button icon for Canfestival plugin
edouard
parents:
361
diff
changeset
|
363 |
"name" : _("Show Master"), |
361 | 364 |
"tooltip" : _("Show Master generated by config_utils"), |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
365 |
"method" : "_ShowGeneratedMaster"} |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
366 |
] |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
367 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
368 |
def OnCloseEditor(self, view): |
717 | 369 |
ConfigTreeNode.OnCloseEditor(self, view) |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
370 |
if self._GeneratedMasterView == view: |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
371 |
self._GeneratedMasterView = None |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
372 |
|
718 | 373 |
def OnCTNClose(self): |
374 |
ConfigTreeNode.OnCTNClose(self) |
|
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
375 |
self._CloseView(self._GeneratedMasterView) |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
376 |
return True |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
377 |
|
718 | 378 |
def CTNTestModified(self): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
379 |
return self.ChangesToSave or self.HasChanged() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
380 |
|
1061 | 381 |
def OnCTNSave(self, from_project_path=None): |
718 | 382 |
self.SetRoot(self.CTNPath()) |
1063 | 383 |
if from_project_path is not None: |
384 |
shutil.copytree(self.GetEDSFolder(from_project_path), |
|
385 |
self.GetEDSFolder()) |
|
250 | 386 |
return self.SaveProject() is None |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
387 |
|
718 | 388 |
def CTNGenerate_C(self, buildpath, locations): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
389 |
""" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
390 |
Generate C code |
717 | 391 |
@param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
392 |
@param locations: List of complete variables locations \ |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
393 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
394 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
395 |
"DIR" : direction "Q","I" or "M" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
396 |
"SIZE" : size "X", "B", "W", "D", "L" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
397 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
398 |
}, ...] |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
399 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
400 |
""" |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
762
diff
changeset
|
401 |
self._CloseView(self._GeneratedMasterView) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
402 |
current_location = self.GetCurrentLocation() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
403 |
# define a unique name for the generated C file |
166 | 404 |
prefix = "_".join(map(str, current_location)) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
405 |
Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix ) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
406 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
341 | 407 |
try: |
408 |
master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix) |
|
409 |
except config_utils.PDOmappingException, e: |
|
410 |
raise Exception, e.message |
|
166 | 411 |
# Do generate C file. |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
412 |
res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
413 |
if res : |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
414 |
raise Exception, res |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
415 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
416 |
file = open(os.path.join(buildpath, "MasterGenerated.od"), "w") |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
417 |
dump(master, file) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
418 |
file.close() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
419 |
|
512
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
427
diff
changeset
|
420 |
return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
12 | 421 |
|
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
422 |
def LoadPrevious(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
423 |
self.Manager.LoadCurrentPrevious() |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
424 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
425 |
def LoadNext(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
426 |
self.Manager.LoadCurrentNext() |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
427 |
|
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
428 |
def GetBufferState(self): |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
429 |
return self.Manager.GetCurrentBufferState() |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
430 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
431 |
class RootClass: |
12 | 432 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
433 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
434 |
<xsd:element name="CanFestivalInstance"> |
|
435 |
<xsd:complexType> |
|
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
436 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="optional"/> |
12 | 437 |
</xsd:complexType> |
438 |
</xsd:element> |
|
439 |
</xsd:schema> |
|
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
440 |
""" |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
441 |
|
718 | 442 |
CTNChildrenTypes = [("CanOpenNode",_NodeListCTN, "CanOpen Master"), |
443 |
("CanOpenSlave",_SlaveCTN, "CanOpen Slave")] |
|
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
444 |
def GetParamsAttributes(self, path = None): |
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
445 |
infos = ConfigTreeNode.GetParamsAttributes(self, path = path) |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
446 |
for element in infos: |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
447 |
if element["name"] == "CanFestivalInstance": |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
448 |
for child in element["children"]: |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
449 |
if child["name"] == "CAN_Driver": |
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
450 |
child["type"] = local_canfestival_config.DLL_LIST |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
451 |
return infos |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
452 |
|
974 | 453 |
def GetCanDriver(self): |
976 | 454 |
res = self.CanFestivalInstance.getCAN_Driver() |
455 |
if not res : |
|
456 |
return "" |
|
457 |
return res |
|
974 | 458 |
|
459 |
def CTNGenerate_C(self, buildpath, locations): |
|
976 | 460 |
can_driver = self.GetCanDriver() |
461 |
if can_driver is not None: |
|
462 |
can_drivers = local_canfestival_config.DLL_LIST |
|
463 |
if can_driver not in can_drivers : |
|
464 |
can_driver = can_drivers[0] |
|
465 |
can_drv_ext = self.GetCTRoot().GetBuilder().extension |
|
1279
0eb9f8af479f
Added 'dlopen_prefix' class attributes to targets, in order to handle dlopen of shared object passed to runtime as extra file, and then in PWD (was working with windows only)
Edouard Tisserant
parents:
1063
diff
changeset
|
466 |
can_drv_prefix = self.GetCTRoot().GetBuilder().dlopen_prefix |
0eb9f8af479f
Added 'dlopen_prefix' class attributes to targets, in order to handle dlopen of shared object passed to runtime as extra file, and then in PWD (was working with windows only)
Edouard Tisserant
parents:
1063
diff
changeset
|
467 |
can_driver_name = can_drv_prefix + "libcanfestival_" + can_driver + can_drv_ext |
976 | 468 |
else: |
469 |
can_driver_name = "" |
|
470 |
||
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
471 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
472 |
format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
960
d72a866cf9b0
Cleanup in canfestival plugin. No more meaningless default values.
Edouard Tisserant
parents:
957
diff
changeset
|
473 |
"candriver" : can_driver_name, |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
474 |
"nodes_includes" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
475 |
"board_decls" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
476 |
"nodes_init" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
477 |
"nodes_open" : "", |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
307
diff
changeset
|
478 |
"nodes_stop" : "", |
57 | 479 |
"nodes_close" : "", |
480 |
"nodes_send_sync" : "", |
|
169
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
481 |
"nodes_proceed_sync" : "", |
174 | 482 |
"slavebootups" : "", |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
483 |
"slavebootup_register" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
484 |
"post_sync" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
485 |
"post_sync_register" : "", |
778 | 486 |
"pre_op" : "", |
487 |
"pre_op_register" : "", |
|
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
488 |
} |
718 | 489 |
for child in self.IECSortedChildren(): |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
490 |
childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
491 |
nodename = "OD_%s" % childlocstr |
166 | 492 |
|
493 |
# Try to get Slave Node |
|
494 |
child_data = getattr(child, "CanFestivalSlaveNode", None) |
|
495 |
if child_data is None: |
|
496 |
# Not a slave -> master |
|
497 |
child_data = getattr(child, "CanFestivalNode") |
|
169
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
498 |
# Apply sync setting |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
499 |
format_dict["nodes_init"] += 'NODE_MASTER_INIT(%s, %s)\n '%( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
500 |
nodename, |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
501 |
child_data.getNodeId()) |
166 | 502 |
if child_data.getSync_TPDOs(): |
503 |
format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
|
504 |
format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
|
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
505 |
|
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
506 |
# initialize and declare node boot status variables for post_SlaveBootup lookup |
169
8e87b69286c0
SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents:
166
diff
changeset
|
507 |
SlaveIDs = child.GetSlaveIDs() |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
508 |
if len(SlaveIDs) == 0: |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
509 |
# define post_SlaveBootup lookup functions |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
510 |
format_dict["slavebootups"] += ( |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
511 |
"static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){}\n"%(nodename)) |
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
512 |
else: |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
513 |
format_dict["slavebootups"] += ( |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
514 |
"static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+ |
776
c81397b665b6
Fixed generated CF code to match latest changes
Edouard Tisserant
parents:
774
diff
changeset
|
515 |
" check_and_start_node(d, nodeId);\n"+ |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
516 |
"}\n") |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
517 |
# register previously declared func as post_SlaveBootup callback for that node |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
518 |
format_dict["slavebootup_register"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
519 |
"%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename)) |
779 | 520 |
format_dict["pre_op"] += ( |
521 |
"static void %s_preOperational(CO_Data* d){\n "%(nodename)+ |
|
522 |
"".join([" masterSendNMTstateChange(d, %d, NMT_Reset_Comunication);\n"%NdId for NdId in SlaveIDs])+ |
|
523 |
"}\n") |
|
524 |
format_dict["pre_op_register"] += ( |
|
525 |
"%s_Data.preOperational = %s_preOperational;\n"%(nodename,nodename)) |
|
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
526 |
else: |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
527 |
# Slave node |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
528 |
align = child_data.getSync_Align() |
203 | 529 |
align_ratio=child_data.getSync_Align_Ratio() |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
530 |
if align > 0: |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
531 |
format_dict["post_sync"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
532 |
"static int %s_CalCount = 0;\n"%(nodename)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
533 |
"static void %s_post_sync(CO_Data* d){\n"%(nodename)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
534 |
" if(%s_CalCount < %d){\n"%(nodename, align)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
535 |
" %s_CalCount++;\n"%(nodename)+ |
203 | 536 |
" align_tick(-1);\n"+ |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
537 |
" }else{\n"+ |
203 | 538 |
" align_tick(%d);\n"%(align_ratio)+ |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
539 |
" }\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
540 |
"}\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
541 |
format_dict["post_sync_register"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
542 |
"%s_Data.post_sync = %s_post_sync;\n"%(nodename,nodename)) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
543 |
format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n '%( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
544 |
nodename, |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
545 |
child_data.getNodeId()) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
546 |
|
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
547 |
# Include generated OD headers |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
548 |
format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
549 |
# Declare CAN channels according user filled config |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
550 |
format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
551 |
nodename, |
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
552 |
child.GetCanDevice(), |
166 | 553 |
child_data.getCAN_Baudrate()) |
57 | 554 |
format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
555 |
format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) |
|
682
9d20df7c144a
Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
512
diff
changeset
|
556 |
format_dict["nodes_stop"] += 'NODE_STOP(%s)\n '%(nodename) |
157 | 557 |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
558 |
filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c") |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
559 |
cf_main = open(filename).read() % format_dict |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
560 |
cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c"%format_dict) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
561 |
f = open(cf_main_path,'w') |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
562 |
f.write(cf_main) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
563 |
f.close() |
957
463d4b2b058d
CanFestival plugin now sends driver as extra file to runtime if matching target. Helps on windows to resolve DLL
Edouard Tisserant
parents:
948
diff
changeset
|
564 |
|
463d4b2b058d
CanFestival plugin now sends driver as extra file to runtime if matching target. Helps on windows to resolve DLL
Edouard Tisserant
parents:
948
diff
changeset
|
565 |
res = [(cf_main_path, local_canfestival_config.getCFLAGS(CanFestivalPath))],local_canfestival_config.getLDFLAGS(CanFestivalPath), True |
974 | 566 |
|
976 | 567 |
if can_driver is not None: |
974 | 568 |
can_driver_path = os.path.join(CanFestivalPath,"drivers",can_driver,can_driver_name) |
569 |
if os.path.exists(can_driver_path): |
|
570 |
res += ((can_driver_name, file(can_driver_path,"rb")),) |
|
957
463d4b2b058d
CanFestival plugin now sends driver as extra file to runtime if matching target. Helps on windows to resolve DLL
Edouard Tisserant
parents:
948
diff
changeset
|
571 |
|
463d4b2b058d
CanFestival plugin now sends driver as extra file to runtime if matching target. Helps on windows to resolve DLL
Edouard Tisserant
parents:
948
diff
changeset
|
572 |
return res |
463d4b2b058d
CanFestival plugin now sends driver as extra file to runtime if matching target. Helps on windows to resolve DLL
Edouard Tisserant
parents:
948
diff
changeset
|
573 |