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