author | edouard |
Mon, 07 Dec 2009 14:00:33 +0100 | |
changeset 471 | 98a39261db9e |
parent 427 | 7ac746c07ff2 |
child 512 | 36aeab46f27d |
permissions | -rw-r--r-- |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
1 |
import os, sys |
20 | 2 |
base_folder = os.path.split(sys.path[0])[0] |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
3 |
CanFestivalPath = os.path.join(base_folder, "CanFestival-3") |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
4 |
sys.path.append(os.path.join(CanFestivalPath, "objdictgen")) |
20 | 5 |
|
11 | 6 |
from nodelist import NodeList |
7 |
from nodemanager import NodeManager |
|
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
8 |
import config_utils, gen_cfile, eds_utils |
12 | 9 |
from networkedit import networkedit |
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
10 |
from objdictedit import objdictedit |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
11 |
import canfestival_config |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
12 |
from plugger import PlugTemplate |
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
|
13 |
from commondialogs import CreateNodeDialog |
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 |
import wx |
11 | 15 |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
16 |
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
|
17 |
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
|
18 |
setParanoia(0) |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
19 |
|
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
20 |
if wx.Platform == '__WXMSW__': |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
21 |
DEFAULT_SETTINGS = { |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
22 |
"CAN_Driver": "can_tcp_win32", |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
23 |
"CAN_Device": "127.0.0.1", |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
24 |
"CAN_Baudrate": "125K", |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
25 |
"Slave_NodeId": 2, |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
26 |
"Master_NodeId": 1, |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
27 |
} |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
28 |
else: |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
29 |
DEFAULT_SETTINGS = { |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
30 |
"CAN_Driver": "../CanFestival-3/drivers/can_socket/libcanfestival_can_socket.so", |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
31 |
"CAN_Device": "vcan0", |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
32 |
"CAN_Baudrate": "125K", |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
33 |
"Slave_NodeId": 2, |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
34 |
"Master_NodeId": 1, |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
35 |
} |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
36 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
37 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
38 |
# SLAVE |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
39 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
40 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
41 |
class _SlavePlug(NodeManager): |
12 | 42 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
43 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
166 | 44 |
<xsd:element name="CanFestivalSlaveNode"> |
12 | 45 |
<xsd:complexType> |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
46 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/> |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
47 |
<xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/> |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
48 |
<xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/> |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
49 |
<xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/> |
203 | 50 |
<xsd:attribute name="Sync_Align_Ratio" use="optional" default="50"> |
51 |
<xsd:simpleType> |
|
52 |
<xsd:restriction base="xsd:integer"> |
|
53 |
<xsd:minInclusive value="1"/> |
|
54 |
<xsd:maxInclusive value="99"/> |
|
55 |
</xsd:restriction> |
|
56 |
</xsd:simpleType> |
|
57 |
</xsd:attribute> |
|
12 | 58 |
</xsd:complexType> |
59 |
</xsd:element> |
|
60 |
</xsd:schema> |
|
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
61 |
""" % DEFAULT_SETTINGS |
12 | 62 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
63 |
def GetSlaveODPath(self): |
166 | 64 |
return os.path.join(self.PlugPath(), 'slave.od') |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
65 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
66 |
def __init__(self): |
23 | 67 |
# TODO change netname when name change |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
68 |
NodeManager.__init__(self) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
69 |
odfilepath = self.GetSlaveODPath() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
70 |
if(os.path.isfile(odfilepath)): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
71 |
self.OpenFileInCurrent(odfilepath) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
"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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
"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
|
94 |
"", # 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
|
95 |
"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
|
96 |
"", # 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
|
97 |
"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
|
98 |
[]) # 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
|
99 |
dialog.Destroy() |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
100 |
_View = None |
203 | 101 |
def _OpenView(self): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
102 |
if not self._View: |
427 | 103 |
open_objdictedit = True |
104 |
has_permissions = self.GetPlugRoot().CheckProjectPathPerm() |
|
105 |
if not has_permissions: |
|
106 |
dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, |
|
107 |
_("You don't have write permissions.\nOpen ObjDictEdit anyway ?"), |
|
108 |
_("Open ObjDictEdit"), |
|
109 |
wx.YES_NO|wx.ICON_QUESTION) |
|
110 |
open_objdictedit = dialog.ShowModal() == wx.ID_YES |
|
111 |
dialog.Destroy() |
|
112 |
if open_objdictedit: |
|
113 |
def _onclose(): |
|
114 |
self._View = None |
|
115 |
if has_permissions: |
|
116 |
def _onsave(): |
|
117 |
self.GetPlugRoot().SaveProject() |
|
118 |
else: |
|
119 |
def _onsave(): |
|
120 |
pass |
|
121 |
||
122 |
self._View = objdictedit(self.GetPlugRoot().AppFrame, self) |
|
123 |
# TODO redefine BusId when IEC channel change |
|
124 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
125 |
self._View._onclose = _onclose |
|
126 |
self._View._onsave = _onsave |
|
127 |
self._View.Show() |
|
23 | 128 |
|
65 | 129 |
PluginMethods = [ |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
77
diff
changeset
|
130 |
{"bitmap" : os.path.join("images", "NetworkEdit"), |
166 | 131 |
"name" : "Edit slave", |
132 |
"tooltip" : "Edit CanOpen slave with ObjdictEdit", |
|
105
434aed8dc58d
Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents:
95
diff
changeset
|
133 |
"method" : "_OpenView"}, |
65 | 134 |
] |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
135 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
136 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
137 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
138 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
139 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
140 |
def PlugTestModified(self): |
166 | 141 |
return self.ChangesToSave or self.OneFileHasChanged() |
12 | 142 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
143 |
def OnPlugSave(self): |
166 | 144 |
return self.SaveCurrentInFile(self.GetSlaveODPath()) |
12 | 145 |
|
203 | 146 |
def PlugGenerate_C(self, buildpath, locations): |
12 | 147 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
148 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
149 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
150 |
@param locations: List of complete variables locations \ |
22 | 151 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
152 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
153 |
"DIR" : direction "Q","I" or "M" |
|
154 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
155 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
156 |
}, ...] |
|
157 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 158 |
""" |
24 | 159 |
current_location = self.GetCurrentLocation() |
22 | 160 |
# define a unique name for the generated C file |
166 | 161 |
prefix = "_".join(map(str, current_location)) |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
162 |
Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix ) |
166 | 163 |
# Create a new copy of the model |
164 |
slave = self.GetCurrentNodeCopy() |
|
165 |
slave.SetNodeName("OD_%s"%prefix) |
|
166 |
# allow access to local OD from Slave PLC |
|
167 |
pointers = config_utils.LocalODPointers(locations, current_location, slave) |
|
168 |
res = gen_cfile.GenerateFile(Gen_OD_path, slave, pointers) |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
169 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
170 |
raise Exception, res |
172
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
171 |
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
|
172 |
if res : |
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
173 |
raise Exception, res |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
174 |
return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
175 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
176 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
177 |
# MASTER |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
178 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
179 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
180 |
class _NodeListPlug(NodeList): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
181 |
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
|
182 |
<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
|
183 |
<xsd:element name="CanFestivalNode"> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
184 |
<xsd:complexType> |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
185 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/> |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
186 |
<xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/> |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
187 |
<xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/> |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
188 |
<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
|
189 |
</xsd:complexType> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
190 |
</xsd:element> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
191 |
</xsd:schema> |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
192 |
""" % DEFAULT_SETTINGS |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
193 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
194 |
def __init__(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
195 |
manager = NodeManager() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
196 |
# TODO change netname when name change |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
197 |
NodeList.__init__(self, manager, self.BaseParams.getName()) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
198 |
self.LoadProject(self.PlugPath()) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
199 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
200 |
_View = None |
203 | 201 |
def _OpenView(self): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
202 |
if not self._View: |
427 | 203 |
open_networkedit = True |
204 |
has_permissions = self.GetPlugRoot().CheckProjectPathPerm() |
|
205 |
if not has_permissions: |
|
206 |
dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, |
|
207 |
_("You don't have write permissions.\nOpen NetworkEdit anyway ?"), |
|
208 |
_("Open NetworkEdit"), |
|
209 |
wx.YES_NO|wx.ICON_QUESTION) |
|
210 |
open_networkedit = dialog.ShowModal() == wx.ID_YES |
|
211 |
dialog.Destroy() |
|
212 |
if open_networkedit: |
|
213 |
def _onclose(): |
|
214 |
self._View = None |
|
215 |
if has_permissions: |
|
216 |
def _onsave(): |
|
217 |
self.GetPlugRoot().SaveProject() |
|
218 |
else: |
|
219 |
def _onsave(): |
|
220 |
pass |
|
221 |
self._View = networkedit(self.GetPlugRoot().AppFrame, self) |
|
222 |
# TODO redefine BusId when IEC channel change |
|
223 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
224 |
self._View._onclose = _onclose |
|
225 |
self._View._onsave = _onsave |
|
226 |
self._View.Show() |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
227 |
|
203 | 228 |
def _ShowMasterGenerated(self): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
229 |
buildpath = self._getBuildPath() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
230 |
# Eventually create build dir |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
231 |
if not os.path.exists(buildpath): |
421 | 232 |
self.GetPlugRoot().logger.write_error(_("Error: No PLC built\n")) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
233 |
return |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
234 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
235 |
masterpath = os.path.join(buildpath, "MasterGenerated.od") |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
236 |
if not os.path.exists(masterpath): |
421 | 237 |
self.GetPlugRoot().logger.write_error(_("Error: No Master generated\n")) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
238 |
return |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
239 |
|
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
|
240 |
new_dialog = objdictedit(None, filesOpen=[masterpath]) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
241 |
new_dialog.Show() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
242 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
243 |
PluginMethods = [ |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
244 |
{"bitmap" : os.path.join("images", "NetworkEdit"), |
361 | 245 |
"name" : _("Edit network"), |
246 |
"tooltip" : _("Edit CanOpen Network with NetworkEdit"), |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
247 |
"method" : "_OpenView"}, |
372
35cc4c6a2936
Added ShowMaster button icon for Canfestival plugin
edouard
parents:
361
diff
changeset
|
248 |
{"bitmap" : os.path.join("images", "ShowMaster"), |
35cc4c6a2936
Added ShowMaster button icon for Canfestival plugin
edouard
parents:
361
diff
changeset
|
249 |
"name" : _("Show Master"), |
361 | 250 |
"tooltip" : _("Show Master generated by config_utils"), |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
251 |
"method" : "_ShowMasterGenerated"} |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
252 |
] |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
253 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
254 |
def OnPlugClose(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
255 |
if self._View: |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
256 |
self._View.Close() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
257 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
258 |
def PlugTestModified(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
259 |
return self.ChangesToSave or self.HasChanged() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
260 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
261 |
def OnPlugSave(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
262 |
self.SetRoot(self.PlugPath()) |
250 | 263 |
return self.SaveProject() is None |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
264 |
|
203 | 265 |
def PlugGenerate_C(self, buildpath, locations): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
266 |
""" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
267 |
Generate C code |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
268 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
269 |
@param locations: List of complete variables locations \ |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
270 |
[{"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
|
271 |
"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
|
272 |
"DIR" : direction "Q","I" or "M" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
273 |
"SIZE" : size "X", "B", "W", "D", "L" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
274 |
"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
|
275 |
}, ...] |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
276 |
@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
|
277 |
""" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
278 |
current_location = self.GetCurrentLocation() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
279 |
# define a unique name for the generated C file |
166 | 280 |
prefix = "_".join(map(str, current_location)) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
281 |
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
|
282 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
341 | 283 |
try: |
284 |
master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix) |
|
285 |
except config_utils.PDOmappingException, e: |
|
286 |
raise Exception, e.message |
|
166 | 287 |
# Do generate C file. |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
288 |
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
|
289 |
if res : |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
290 |
raise Exception, res |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
291 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
292 |
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
|
293 |
dump(master, file) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
294 |
file.close() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
295 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
296 |
return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
12 | 297 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
298 |
class RootClass: |
12 | 299 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
300 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
301 |
<xsd:element name="CanFestivalInstance"> |
|
302 |
<xsd:complexType> |
|
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
303 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="optional" default="%(CAN_Driver)s"/> |
157 | 304 |
<xsd:attribute name="Debug_mode" type="xsd:boolean" use="optional" default="false"/> |
12 | 305 |
</xsd:complexType> |
306 |
</xsd:element> |
|
307 |
</xsd:schema> |
|
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
308 |
""" % DEFAULT_SETTINGS |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
309 |
|
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
|
310 |
PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"), |
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
|
311 |
("CanOpenSlave",_SlavePlug, "CanOpen Slave")] |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
312 |
def GetParamsAttributes(self, path = None): |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
313 |
infos = PlugTemplate.GetParamsAttributes(self, path = None) |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
314 |
for element in infos: |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
315 |
if element["name"] == "CanFestivalInstance": |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
316 |
for child in element["children"]: |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
317 |
if child["name"] == "CAN_Driver": |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
318 |
DLL_LIST= getattr(canfestival_config,"DLL_LIST",None) |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
319 |
if DLL_LIST is not None: |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
320 |
child["type"] = DLL_LIST |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
321 |
return infos |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
322 |
return infos |
11 | 323 |
|
203 | 324 |
def PlugGenerate_C(self, buildpath, locations): |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
325 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
326 |
format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
327 |
"candriver" : self.CanFestivalInstance.getCAN_Driver(), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
328 |
"nodes_includes" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
329 |
"board_decls" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
330 |
"nodes_init" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
331 |
"nodes_open" : "", |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
307
diff
changeset
|
332 |
"nodes_stop" : "", |
57 | 333 |
"nodes_close" : "", |
334 |
"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
|
335 |
"nodes_proceed_sync" : "", |
174 | 336 |
"slavebootups" : "", |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
337 |
"slavebootup_register" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
338 |
"post_sync" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
339 |
"post_sync_register" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
340 |
} |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
341 |
for child in self.IECSortedChilds(): |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
342 |
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
|
343 |
nodename = "OD_%s" % childlocstr |
166 | 344 |
|
345 |
# Try to get Slave Node |
|
346 |
child_data = getattr(child, "CanFestivalSlaveNode", None) |
|
347 |
if child_data is None: |
|
348 |
# Not a slave -> master |
|
349 |
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
|
350 |
# Apply sync setting |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
351 |
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
|
352 |
nodename, |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
353 |
child_data.getNodeId()) |
166 | 354 |
if child_data.getSync_TPDOs(): |
355 |
format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
|
356 |
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
|
357 |
|
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
358 |
# 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
|
359 |
SlaveIDs = child.GetSlaveIDs() |
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
|
360 |
for id in SlaveIDs: |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
361 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
362 |
"int %s_slave_%d_booted = 0;\n"%(nodename, id)) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
363 |
# define post_SlaveBootup lookup functions |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
364 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
365 |
"static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
366 |
" switch(nodeId){\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
367 |
# one case per declared node, mark node as booted |
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
|
368 |
for id in SlaveIDs: |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
369 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
370 |
" case %d:\n"%(id)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
371 |
" %s_slave_%d_booted = 1;\n"%(nodename, id)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
372 |
" break;\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
373 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
374 |
" default:\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
375 |
" break;\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
376 |
" }\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
377 |
" if( ") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
378 |
# expression to test if all declared nodes booted |
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
|
379 |
format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs]) |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
380 |
format_dict["slavebootups"] += " )\n" + ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
381 |
" Master_post_SlaveBootup(d,nodeId);\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
382 |
"}\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
383 |
# 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
|
384 |
format_dict["slavebootup_register"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
385 |
"%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename)) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
386 |
else: |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
387 |
# Slave node |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
388 |
align = child_data.getSync_Align() |
203 | 389 |
align_ratio=child_data.getSync_Align_Ratio() |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
390 |
if align > 0: |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
391 |
format_dict["post_sync"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
392 |
"static int %s_CalCount = 0;\n"%(nodename)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
393 |
"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
|
394 |
" if(%s_CalCount < %d){\n"%(nodename, align)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
395 |
" %s_CalCount++;\n"%(nodename)+ |
203 | 396 |
" align_tick(-1);\n"+ |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
397 |
" }else{\n"+ |
203 | 398 |
" align_tick(%d);\n"%(align_ratio)+ |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
399 |
" }\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
400 |
"}\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
401 |
format_dict["post_sync_register"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
402 |
"%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
|
403 |
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
|
404 |
nodename, |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
405 |
child_data.getNodeId()) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
406 |
|
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
407 |
# Include generated OD headers |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
408 |
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
|
409 |
# 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
|
410 |
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
|
411 |
nodename, |
166 | 412 |
child_data.getCAN_Device(), |
413 |
child_data.getCAN_Baudrate()) |
|
57 | 414 |
format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
415 |
format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) |
|
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
307
diff
changeset
|
416 |
format_dict["nodes_stop"] += 'NODE_STOP(%s)\n '%(nodename) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
417 |
if sys.platform == 'win32': |
157 | 418 |
if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(format_dict["candriver"] + '_DEBUG.dll'))): |
419 |
format_dict["candriver"] += '_DEBUG.dll' |
|
420 |
else: |
|
421 |
format_dict["candriver"] += '.dll' |
|
422 |
||
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
f.write(cf_main) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
428 |
f.close() |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
429 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
430 |
return [(cf_main_path, canfestival_config.getCFLAGS(CanFestivalPath))],canfestival_config.getLDFLAGS(CanFestivalPath), True |
11 | 431 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
432 |