author | 'Laurent Bessard <laurent.bessard@lolitech.fr>' |
Fri, 16 Oct 2009 10:50:16 +0200 | |
changeset 420 | c093ec48f2fd |
parent 411 | 8261c8f1e365 |
child 421 | c9ec111ad275 |
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: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
103 |
def _onclose(): |
30 | 104 |
self._View = None |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
105 |
def _onsave(): |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
106 |
self.GetPlugRoot().SaveProject() |
166 | 107 |
self._View = objdictedit(self.GetPlugRoot().AppFrame, self) |
23 | 108 |
# TODO redefine BusId when IEC channel change |
109 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
110 |
self._View._onclose = _onclose |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
111 |
self._View._onsave = _onsave |
23 | 112 |
self._View.Show() |
113 |
||
65 | 114 |
PluginMethods = [ |
82
d7b4dd1f543f
Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents:
77
diff
changeset
|
115 |
{"bitmap" : os.path.join("images", "NetworkEdit"), |
166 | 116 |
"name" : "Edit slave", |
117 |
"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
|
118 |
"method" : "_OpenView"}, |
65 | 119 |
] |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
120 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
121 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
122 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
123 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
124 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
125 |
def PlugTestModified(self): |
166 | 126 |
return self.ChangesToSave or self.OneFileHasChanged() |
12 | 127 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
128 |
def OnPlugSave(self): |
166 | 129 |
return self.SaveCurrentInFile(self.GetSlaveODPath()) |
12 | 130 |
|
203 | 131 |
def PlugGenerate_C(self, buildpath, locations): |
12 | 132 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
133 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
134 |
@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
|
135 |
@param locations: List of complete variables locations \ |
22 | 136 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
137 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
138 |
"DIR" : direction "Q","I" or "M" |
|
139 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
140 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
141 |
}, ...] |
|
142 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 143 |
""" |
24 | 144 |
current_location = self.GetCurrentLocation() |
22 | 145 |
# define a unique name for the generated C file |
166 | 146 |
prefix = "_".join(map(str, current_location)) |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
147 |
Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix ) |
166 | 148 |
# Create a new copy of the model |
149 |
slave = self.GetCurrentNodeCopy() |
|
150 |
slave.SetNodeName("OD_%s"%prefix) |
|
151 |
# allow access to local OD from Slave PLC |
|
152 |
pointers = config_utils.LocalODPointers(locations, current_location, slave) |
|
153 |
res = gen_cfile.GenerateFile(Gen_OD_path, slave, pointers) |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
154 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
155 |
raise Exception, res |
172
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
156 |
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
|
157 |
if res : |
8eefeccbd021
Adding support for modification in CanFestival eds_utils
lbessard
parents:
169
diff
changeset
|
158 |
raise Exception, res |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
159 |
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
|
160 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
161 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
162 |
# MASTER |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
163 |
#-------------------------------------------------- |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
164 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
165 |
class _NodeListPlug(NodeList): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
166 |
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
|
167 |
<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
|
168 |
<xsd:element name="CanFestivalNode"> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
169 |
<xsd:complexType> |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
170 |
<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
|
171 |
<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
|
172 |
<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
|
173 |
<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
|
174 |
</xsd:complexType> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
175 |
</xsd:element> |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
176 |
</xsd:schema> |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
177 |
""" % DEFAULT_SETTINGS |
163
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 |
def __init__(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
180 |
manager = NodeManager() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
181 |
# TODO change netname when name change |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
182 |
NodeList.__init__(self, manager, self.BaseParams.getName()) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
183 |
self.LoadProject(self.PlugPath()) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
184 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
185 |
_View = None |
203 | 186 |
def _OpenView(self): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
187 |
if not self._View: |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
188 |
def _onclose(): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
189 |
self._View = None |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
190 |
def _onsave(): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
191 |
self.GetPlugRoot().SaveProject() |
166 | 192 |
self._View = networkedit(self.GetPlugRoot().AppFrame, self) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
193 |
# TODO redefine BusId when IEC channel change |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
194 |
self._View.SetBusId(self.GetCurrentLocation()) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
195 |
self._View._onclose = _onclose |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
196 |
self._View._onsave = _onsave |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
197 |
self._View.Show() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
198 |
|
203 | 199 |
def _ShowMasterGenerated(self): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
200 |
buildpath = self._getBuildPath() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
201 |
# Eventually create build dir |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
202 |
if not os.path.exists(buildpath): |
361 | 203 |
self.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
|
204 |
return |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
205 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
206 |
masterpath = os.path.join(buildpath, "MasterGenerated.od") |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
207 |
if not os.path.exists(masterpath): |
361 | 208 |
self.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
|
209 |
return |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
210 |
|
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
|
211 |
new_dialog = objdictedit(None, filesOpen=[masterpath]) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
212 |
new_dialog.Show() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
213 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
214 |
PluginMethods = [ |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
215 |
{"bitmap" : os.path.join("images", "NetworkEdit"), |
361 | 216 |
"name" : _("Edit network"), |
217 |
"tooltip" : _("Edit CanOpen Network with NetworkEdit"), |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
218 |
"method" : "_OpenView"}, |
372
35cc4c6a2936
Added ShowMaster button icon for Canfestival plugin
edouard
parents:
361
diff
changeset
|
219 |
{"bitmap" : os.path.join("images", "ShowMaster"), |
35cc4c6a2936
Added ShowMaster button icon for Canfestival plugin
edouard
parents:
361
diff
changeset
|
220 |
"name" : _("Show Master"), |
361 | 221 |
"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
|
222 |
"method" : "_ShowMasterGenerated"} |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
223 |
] |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
224 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
225 |
def OnPlugClose(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
226 |
if self._View: |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
227 |
self._View.Close() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
228 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
229 |
def PlugTestModified(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
230 |
return self.ChangesToSave or self.HasChanged() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
231 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
232 |
def OnPlugSave(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
233 |
self.SetRoot(self.PlugPath()) |
250 | 234 |
return self.SaveProject() is None |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
235 |
|
203 | 236 |
def PlugGenerate_C(self, buildpath, locations): |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
237 |
""" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
238 |
Generate C code |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
239 |
@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
|
240 |
@param locations: List of complete variables locations \ |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
241 |
[{"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
|
242 |
"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
|
243 |
"DIR" : direction "Q","I" or "M" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
244 |
"SIZE" : size "X", "B", "W", "D", "L" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
245 |
"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
|
246 |
}, ...] |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
247 |
@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
|
248 |
""" |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
249 |
current_location = self.GetCurrentLocation() |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
250 |
# define a unique name for the generated C file |
166 | 251 |
prefix = "_".join(map(str, current_location)) |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
252 |
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
|
253 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
341 | 254 |
try: |
255 |
master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix) |
|
256 |
except config_utils.PDOmappingException, e: |
|
257 |
raise Exception, e.message |
|
166 | 258 |
# Do generate C file. |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
259 |
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
|
260 |
if res : |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
261 |
raise Exception, res |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
262 |
|
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
263 |
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
|
264 |
dump(master, file) |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
265 |
file.close() |
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 |
return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
12 | 268 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
269 |
class RootClass: |
12 | 270 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
271 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
272 |
<xsd:element name="CanFestivalInstance"> |
|
273 |
<xsd:complexType> |
|
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
274 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="optional" default="%(CAN_Driver)s"/> |
157 | 275 |
<xsd:attribute name="Debug_mode" type="xsd:boolean" use="optional" default="false"/> |
12 | 276 |
</xsd:complexType> |
277 |
</xsd:element> |
|
278 |
</xsd:schema> |
|
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
279 |
""" % DEFAULT_SETTINGS |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
372
diff
changeset
|
280 |
|
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
|
281 |
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
|
282 |
("CanOpenSlave",_SlavePlug, "CanOpen Slave")] |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
283 |
def GetParamsAttributes(self, path = None): |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
284 |
infos = PlugTemplate.GetParamsAttributes(self, path = None) |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
285 |
for element in infos: |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
159
diff
changeset
|
286 |
if element["name"] == "CanFestivalInstance": |
95
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
287 |
for child in element["children"]: |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
288 |
if child["name"] == "CAN_Driver": |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
289 |
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
|
290 |
if DLL_LIST is not None: |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
291 |
child["type"] = DLL_LIST |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
292 |
return infos |
646a44a12e2a
add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents:
86
diff
changeset
|
293 |
return infos |
11 | 294 |
|
203 | 295 |
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
|
296 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
297 |
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
|
298 |
"candriver" : self.CanFestivalInstance.getCAN_Driver(), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
299 |
"nodes_includes" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
300 |
"board_decls" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
301 |
"nodes_init" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
302 |
"nodes_open" : "", |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
307
diff
changeset
|
303 |
"nodes_stop" : "", |
57 | 304 |
"nodes_close" : "", |
305 |
"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
|
306 |
"nodes_proceed_sync" : "", |
174 | 307 |
"slavebootups" : "", |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
308 |
"slavebootup_register" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
309 |
"post_sync" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
310 |
"post_sync_register" : "", |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
311 |
} |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
312 |
for child in self.IECSortedChilds(): |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
313 |
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
|
314 |
nodename = "OD_%s" % childlocstr |
166 | 315 |
|
316 |
# Try to get Slave Node |
|
317 |
child_data = getattr(child, "CanFestivalSlaveNode", None) |
|
318 |
if child_data is None: |
|
319 |
# Not a slave -> master |
|
320 |
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
|
321 |
# Apply sync setting |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
322 |
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
|
323 |
nodename, |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
324 |
child_data.getNodeId()) |
166 | 325 |
if child_data.getSync_TPDOs(): |
326 |
format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
|
327 |
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
|
328 |
|
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
329 |
# 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
|
330 |
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
|
331 |
for id in SlaveIDs: |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
332 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
333 |
"int %s_slave_%d_booted = 0;\n"%(nodename, id)) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
334 |
# define post_SlaveBootup lookup functions |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
335 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
336 |
"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
|
337 |
" switch(nodeId){\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
338 |
# 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
|
339 |
for id in SlaveIDs: |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
340 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
341 |
" case %d:\n"%(id)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
342 |
" %s_slave_%d_booted = 1;\n"%(nodename, id)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
343 |
" break;\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
344 |
format_dict["slavebootups"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
345 |
" default:\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
346 |
" break;\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
347 |
" }\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
348 |
" if( ") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
349 |
# 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
|
350 |
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
|
351 |
format_dict["slavebootups"] += " )\n" + ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
352 |
" Master_post_SlaveBootup(d,nodeId);\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
353 |
"}\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
354 |
# 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
|
355 |
format_dict["slavebootup_register"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
356 |
"%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
|
357 |
else: |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
358 |
# Slave node |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
359 |
align = child_data.getSync_Align() |
203 | 360 |
align_ratio=child_data.getSync_Align_Ratio() |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
361 |
if align > 0: |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
362 |
format_dict["post_sync"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
363 |
"static int %s_CalCount = 0;\n"%(nodename)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
364 |
"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
|
365 |
" if(%s_CalCount < %d){\n"%(nodename, align)+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
366 |
" %s_CalCount++;\n"%(nodename)+ |
203 | 367 |
" align_tick(-1);\n"+ |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
368 |
" }else{\n"+ |
203 | 369 |
" align_tick(%d);\n"%(align_ratio)+ |
178
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
370 |
" }\n"+ |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
371 |
"}\n") |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
372 |
format_dict["post_sync_register"] += ( |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
373 |
"%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
|
374 |
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
|
375 |
nodename, |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
376 |
child_data.getNodeId()) |
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
377 |
|
2390b409eb93
Added PLC tick alignement on external synchronization source feature.
etisserant
parents:
174
diff
changeset
|
378 |
# Include generated OD headers |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
379 |
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
|
380 |
# 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
|
381 |
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
|
382 |
nodename, |
166 | 383 |
child_data.getCAN_Device(), |
384 |
child_data.getCAN_Baudrate()) |
|
57 | 385 |
format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
386 |
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
|
387 |
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
|
388 |
if sys.platform == 'win32': |
157 | 389 |
if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(format_dict["candriver"] + '_DEBUG.dll'))): |
390 |
format_dict["candriver"] += '_DEBUG.dll' |
|
391 |
else: |
|
392 |
format_dict["candriver"] += '.dll' |
|
393 |
||
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
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
|
398 |
f.write(cf_main) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
399 |
f.close() |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
400 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
401 |
return [(cf_main_path, canfestival_config.getCFLAGS(CanFestivalPath))],canfestival_config.getLDFLAGS(CanFestivalPath), True |
11 | 402 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
403 |