author | lbessard |
Mon, 10 Dec 2007 15:53:55 +0100 | |
changeset 78 | 274a343d49d0 |
parent 77 | 7de69369373e |
child 82 | d7b4dd1f543f |
permissions | -rw-r--r-- |
20 | 1 |
import os, sys |
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 |
|
8 |
import config_utils, gen_cfile |
|
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 |
11 | 12 |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
13 |
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
|
14 |
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
|
15 |
setParanoia(0) |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
16 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
17 |
class _NetworkEdit(networkedit): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
18 |
" Overload some of CanFestival Network Editor methods " |
12 | 19 |
def OnCloseFrame(self, event): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
20 |
" Do reset _NodeListPlug.View when closed" |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
21 |
self._onclose() |
12 | 22 |
event.Skip() |
23 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
24 |
class _NodeListPlug(NodeList): |
12 | 25 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
26 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
27 |
<xsd:element name="CanFestivalNode"> |
|
28 |
<xsd:complexType> |
|
29 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="required" /> |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
30 |
<xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required" /> |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
31 |
<xsd:attribute name="NodeId" type="xsd:string" use="required" /> |
26 | 32 |
<xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/> |
12 | 33 |
</xsd:complexType> |
34 |
</xsd:element> |
|
35 |
</xsd:schema> |
|
36 |
""" |
|
37 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
38 |
def __init__(self): |
11 | 39 |
manager = NodeManager() |
23 | 40 |
# TODO change netname when name change |
41 |
NodeList.__init__(self, manager, self.BaseParams.getName()) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
42 |
self.LoadProject(self.PlugPath()) |
11 | 43 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
44 |
_View = None |
18 | 45 |
def _OpenView(self, logger): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
46 |
if not self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
47 |
def _onclose(): |
30 | 48 |
self._View = None |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
49 |
def _onsave(): |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
50 |
self.GetPlugRoot().SaveProject() |
23 | 51 |
self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self) |
52 |
# TODO redefine BusId when IEC channel change |
|
53 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
54 |
self._View._onclose = _onclose |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
55 |
self._View._onsave = _onsave |
23 | 56 |
self._View.Show() |
57 |
||
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
58 |
def _ShowMasterGenerated(self, logger): |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
59 |
buildpath = self._getBuildPath() |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
60 |
# Eventually create build dir |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
61 |
if not os.path.exists(buildpath): |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
62 |
logger.write_error("Error: No PLC built\n") |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
63 |
return |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
64 |
|
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
65 |
masterpath = os.path.join(buildpath, "MasterGenerated.od") |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
66 |
if not os.path.exists(masterpath): |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
67 |
logger.write_error("Error: No Master generated\n") |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
68 |
return |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
69 |
|
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
70 |
new_dialog = objdictedit(None, [masterpath]) |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
71 |
new_dialog.Show() |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
72 |
|
65 | 73 |
PluginMethods = [ |
74 |
{"bitmap" : os.path.join("images", "NetworkEdit.png"), |
|
75 |
"name" : "Edit network", |
|
76 |
"tooltip" : "Edit CanOpen Network with NetworkEdit", |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
77 |
"method" : _OpenView}, |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
78 |
{"name" : "Show Master", |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
79 |
"tooltip" : "Show Master generated by config_utils", |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
80 |
"method" : _ShowMasterGenerated} |
65 | 81 |
] |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
82 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
83 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
84 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
85 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
86 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
87 |
def PlugTestModified(self): |
12 | 88 |
return self.HasChanged() |
89 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
90 |
def OnPlugSave(self): |
32 | 91 |
self.SetRoot(self.PlugPath()) |
11 | 92 |
self.SaveProject() |
12 | 93 |
return True |
94 |
||
24 | 95 |
def PlugGenerate_C(self, buildpath, locations, logger): |
12 | 96 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
97 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
98 |
@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
|
99 |
@param locations: List of complete variables locations \ |
22 | 100 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
101 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
102 |
"DIR" : direction "Q","I" or "M" |
|
103 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
104 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
105 |
}, ...] |
|
106 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 107 |
""" |
24 | 108 |
current_location = self.GetCurrentLocation() |
22 | 109 |
# define a unique name for the generated C file |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
110 |
prefix = "_".join(map(lambda x:str(x), current_location)) |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
111 |
Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix ) |
22 | 112 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
57 | 113 |
master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix) |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
114 |
res = gen_cfile.GenerateFile(Gen_OD_path, master) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
115 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
116 |
raise Exception, res |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
117 |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
118 |
file = open(os.path.join(buildpath, "MasterGenerated.od"), "w") |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
119 |
dump(master, file) |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
120 |
file.close() |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
65
diff
changeset
|
121 |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
122 |
return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
12 | 123 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
124 |
class RootClass: |
12 | 125 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
126 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
127 |
<xsd:element name="CanFestivalInstance"> |
|
128 |
<xsd:complexType> |
|
129 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="required" /> |
|
130 |
</xsd:complexType> |
|
131 |
</xsd:element> |
|
132 |
</xsd:schema> |
|
133 |
""" |
|
11 | 134 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
135 |
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)] |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
136 |
|
24 | 137 |
def PlugGenerate_C(self, buildpath, locations, logger): |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
138 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
139 |
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
|
140 |
"candriver" : self.CanFestivalInstance.getCAN_Driver(), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
141 |
"nodes_includes" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
142 |
"board_decls" : "", |
59
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
143 |
"nodes_declare" : "", |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
144 |
"nodes_init" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
145 |
"nodes_open" : "", |
57 | 146 |
"nodes_close" : "", |
147 |
"nodes_send_sync" : "", |
|
148 |
"nodes_proceed_sync" : ""} |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
149 |
for child in self.IECSortedChilds(): |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
150 |
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
|
151 |
nodename = "OD_%s" % childlocstr |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
152 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
153 |
format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
154 |
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
|
155 |
nodename, |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
156 |
child.CanFestivalNode.getCAN_Device(), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
157 |
child.CanFestivalNode.getCAN_Baudrate()) |
59
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
158 |
format_dict["nodes_declare"] += 'NODE_DECLARE(%s, %s)\n '%( |
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
159 |
nodename, |
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
160 |
child.CanFestivalNode.getNodeId()) |
57 | 161 |
format_dict["nodes_init"] += 'NODE_INIT(%s, %s)\n '%( |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
162 |
nodename, |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
163 |
child.CanFestivalNode.getNodeId()) |
57 | 164 |
format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
165 |
format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) |
|
166 |
format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
|
167 |
format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
f.write(cf_main) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
173 |
f.close() |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
174 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
175 |
return [(cf_main_path, canfestival_config.getCFLAGS(CanFestivalPath))],canfestival_config.getLDFLAGS(CanFestivalPath), True |
11 | 176 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
177 |