author | leonid |
Wed, 14 Feb 2007 22:19:53 +0100 | |
changeset 109 | 46010c1b6c6e |
parent 91 | ed2612282988 |
child 160 | 636d875c85dd |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
73 | 3 |
|
4 |
#This file is part of CanFestival, a library implementing CanOpen Stack. |
|
5 |
# |
|
6 |
#Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
10 |
#This library is free software; you can redistribute it and/or |
|
11 |
#modify it under the terms of the GNU Lesser General Public |
|
12 |
#License as published by the Free Software Foundation; either |
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
|
14 |
# |
|
15 |
#This library is distributed in the hope that it will be useful, |
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
#Lesser General Public License for more details. |
|
19 |
# |
|
20 |
#You should have received a copy of the GNU Lesser General Public |
|
21 |
#License along with this library; if not, write to the Free Software |
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
0 | 23 |
|
24 |
from node import * |
|
25 |
from types import * |
|
26 |
||
27 |
import re, os |
|
28 |
||
29 |
word_model = re.compile('([a-zA-Z_0-9]*)') |
|
30 |
type_model = re.compile('([\_A-Z]*)([0-9]*)') |
|
31 |
range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]') |
|
32 |
||
33 |
categories = [("SDO_SVR", 0x1200, 0x127F), ("SDO_CLT", 0x1280, 0x12FF), |
|
34 |
("PDO_RCV", 0x1400, 0x15FF), ("PDO_RCV_MAP", 0x1600, 0x17FF), |
|
35 |
("PDO_TRS", 0x1800, 0x19FF), ("PDO_TRS_MAP", 0x1A00, 0x1BFF)] |
|
36 |
index_categories = ["firstIndex", "lastIndex"] |
|
37 |
||
38 |
generated_tag = """\n/* File generated by gen_cfile.py. Should not be modified. */\n""" |
|
39 |
||
40 |
# Format a string for making a C++ variable |
|
41 |
def FormatName(name): |
|
42 |
wordlist = [word for word in word_model.findall(name) if word != ''] |
|
43 |
result = '' |
|
44 |
sep = '' |
|
45 |
for word in wordlist: |
|
46 |
result += "%s%s"%(sep,word) |
|
47 |
sep = '_' |
|
48 |
return result |
|
49 |
||
50 |
# Extract the informations from a given type name |
|
51 |
def GetValidTypeInfos(typename): |
|
52 |
result = type_model.match(typename) |
|
53 |
if result: |
|
54 |
values = result.groups() |
|
55 |
if values[0] in ("UNSIGNED", "INTEGER") and eval(values[1]) in [i * 8 for i in xrange(1, 9)]: |
|
56 |
return "UNS%s"%values[1], "", "uint%s"%values[1] |
|
57 |
elif values[0] == "REAL" and eval(values[1]) in (32, 64): |
|
58 |
return "%s%s"%(values[0], values[1]), "", "real%s"%values[1] |
|
59 |
elif values[0] == "VISIBLE_STRING": |
|
60 |
if values[1] == "": |
|
61 |
return "UNS8", "[10]", "visible_string" |
|
62 |
else: |
|
63 |
return "UNS8", "[%s]"%values[1], "visible_string" |
|
64 |
return None |
|
65 |
||
66 |
def WriteFile(filepath, content): |
|
67 |
cfile = open(filepath,"w") |
|
68 |
cfile.write(content) |
|
69 |
cfile.close() |
|
70 |
||
71 |
def GenerateFileContent(Manager, headerfilepath): |
|
72 |
global type |
|
73 |
texts = {} |
|
74 |
texts["maxPDOtransmit"] = 0 |
|
75 |
texts["NodeName"], texts["NodeID"], texts["NodeType"] = Manager.GetCurrentNodeInfos() |
|
76 |
internal_types = {} |
|
77 |
texts["iam_a_slave"] = 0 |
|
78 |
if (texts["NodeType"] == "slave"): |
|
79 |
texts["iam_a_slave"] = 1 |
|
80 |
||
81 |
# Compiling lists of indexes |
|
82 |
rangelist = [idx for name,idx in Manager.GetCurrentValidIndexes(0, 0x260)] |
|
83 |
listIndex = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1000, 0xFFFF)] |
|
84 |
communicationlist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1000, 0x11FF)] |
|
85 |
sdolist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1200, 0x12FF)] |
|
86 |
pdolist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1400, 0x1BFF)] |
|
87 |
variablelist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x2000, 0xBFFF)] |
|
88 |
||
89 |
#------------------------------------------------------------------------------- |
|
90 |
# Declaration of the value range types |
|
91 |
#------------------------------------------------------------------------------- |
|
92 |
||
93 |
valueRangeContent = "" |
|
94 |
strDefine = "" |
|
95 |
strSwitch = "" |
|
96 |
num = 0 |
|
97 |
for index in rangelist: |
|
98 |
rangename = Manager.GetEntryName(index) |
|
99 |
result = range_model.match(rangename) |
|
100 |
if result: |
|
101 |
num += 1 |
|
102 |
internal_types[rangename] = "valueRange_%d"%num |
|
103 |
typeindex = Manager.GetCurrentEntry(index, 1) |
|
104 |
typename = Manager.GetTypeName(typeindex) |
|
105 |
typeinfos = GetValidTypeInfos(typename) |
|
106 |
if typeinfos == None: |
|
107 |
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
|
108 |
typename = typeinfos[0] |
|
109 |
minvalue = str(Manager.GetCurrentEntry(index, 2)) |
|
110 |
maxvalue = str(Manager.GetCurrentEntry(index, 3)) |
|
111 |
strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typename,minvalue,maxvalue) |
|
112 |
strSwitch += """ case valueRange_%d: |
|
113 |
if (*(%s*)Value < (%s)%s) return OD_VALUE_TOO_LOW; |
|
114 |
if (*(%s*)Value > (%s)%s) return OD_VALUE_TOO_HIGH; |
|
115 |
break;\n"""%(num,typename,typename,minvalue,typename,typename,maxvalue) |
|
116 |
||
117 |
valueRangeContent += strDefine |
|
118 |
valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts |
|
119 |
valueRangeContent += "\n switch (typeValue) {\n" |
|
120 |
valueRangeContent += strSwitch |
|
121 |
valueRangeContent += " }\n return 0;\n}\n" |
|
122 |
||
123 |
#------------------------------------------------------------------------------- |
|
124 |
# Creation of the mapped variables and object dictionary |
|
125 |
#------------------------------------------------------------------------------- |
|
126 |
||
127 |
mappedVariableContent = "" |
|
128 |
strDeclareHeader = "" |
|
129 |
strDeclareCallback = "" |
|
130 |
indexContents = {} |
|
131 |
indexCallbacks = {} |
|
132 |
for index in listIndex: |
|
133 |
texts["index"] = index |
|
134 |
strIndex = "" |
|
135 |
entry_infos = Manager.GetEntryInfos(index) |
|
136 |
texts["EntryName"] = entry_infos["name"] |
|
137 |
values = Manager.GetCurrentEntry(index) |
|
138 |
callbacks = Manager.HasCurrentEntryCallbacks(index) |
|
139 |
if index in variablelist: |
|
140 |
strIndex += "\n/* index 0x%(index)04X : Mapped variable %(EntryName)s */\n"%texts |
|
141 |
else: |
|
142 |
strIndex += "\n/* index 0x%(index)04X : %(EntryName)s. */\n"%texts |
|
143 |
if type(values) == ListType: |
|
144 |
texts["value"] = values[0] |
|
76 | 145 |
strIndex += " UNS8 %(NodeName)s_highestSubIndex_obj%(index)04X = %(value)d; /* number of subindex - 1*/\n"%texts |
0 | 146 |
|
147 |
# Entry type is VAR |
|
148 |
if type(values) != ListType: |
|
149 |
subentry_infos = Manager.GetSubentryInfos(index, 0) |
|
150 |
typename = Manager.GetTypeName(subentry_infos["type"]) |
|
151 |
typeinfos = GetValidTypeInfos(typename) |
|
152 |
if typeinfos == None: |
|
153 |
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
|
154 |
if typename not in internal_types: |
|
155 |
internal_types[typename] = typeinfos[2] |
|
156 |
texts["subIndexType"] = typeinfos[0] |
|
157 |
texts["suffixe"] = typeinfos[1] |
|
158 |
if typeinfos[2] == "visible_string": |
|
159 |
texts["value"] = "\"%s\""%values |
|
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
160 |
texts["comment"] = "" |
0 | 161 |
else: |
162 |
texts["value"] = "0x%X"%values |
|
76 | 163 |
texts["comment"] = "\t/* %s */"%str(values) |
0 | 164 |
if index in variablelist: |
165 |
texts["name"] = FormatName(subentry_infos["name"]) |
|
76 | 166 |
strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts |
0 | 167 |
if callbacks: |
76 | 168 |
strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts |
169 |
mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts |
|
0 | 170 |
else: |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
171 |
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;%(comment)s\n"%texts |
0 | 172 |
values = [values] |
173 |
else: |
|
174 |
||
175 |
# Entry type is RECORD |
|
176 |
if entry_infos["struct"] & OD_IdenticalSubindexes: |
|
177 |
subentry_infos = Manager.GetSubentryInfos(index, 1) |
|
178 |
typename = Manager.GetTypeName(subentry_infos["type"]) |
|
179 |
typeinfos = GetValidTypeInfos(typename) |
|
180 |
if typeinfos == None: |
|
181 |
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
|
182 |
if typename not in internal_types: |
|
183 |
internal_types[typename] = typeinfos[2] |
|
184 |
texts["subIndexType"] = typeinfos[0] |
|
185 |
texts["suffixe"] = typeinfos[1] |
|
186 |
texts["length"] = values[0] |
|
187 |
if index in variablelist: |
|
188 |
texts["name"] = FormatName(entry_infos["name"]) |
|
76 | 189 |
strDeclareHeader += "extern %(subIndexType)s %(name)s[%(length)d]%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n"%texts |
0 | 190 |
if callbacks: |
76 | 191 |
strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts |
192 |
mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n {\n"%texts |
|
0 | 193 |
for subIndex, value in enumerate(values): |
194 |
sep = "," |
|
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
195 |
comment = "" |
0 | 196 |
if subIndex > 0: |
197 |
if subIndex == len(values)-1: |
|
198 |
sep = "" |
|
199 |
if typeinfos[2] == "visible_string": |
|
200 |
value = "\"%s\""%value |
|
201 |
else: |
|
76 | 202 |
comment = "\t/* %s */"%str(value) |
0 | 203 |
value = "0x%X"%value |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
204 |
mappedVariableContent += " %s%s%s\n"%(value, sep, comment) |
28 | 205 |
mappedVariableContent += " };\n" |
0 | 206 |
else: |
207 |
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n {\n"%texts |
|
208 |
for subIndex, value in enumerate(values): |
|
209 |
sep = "," |
|
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
210 |
comment = "" |
0 | 211 |
if subIndex > 0: |
212 |
if subIndex == len(values)-1: |
|
213 |
sep = "" |
|
214 |
if typeinfos[2] == "visible_string": |
|
215 |
value = "\"%s\""%value |
|
216 |
else: |
|
76 | 217 |
comment = "\t/* %s */"%str(value) |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
218 |
value = "0x%X"%value |
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
219 |
strIndex += " %s%s%s\n"%(value, sep, comment) |
0 | 220 |
strIndex += " };\n" |
221 |
else: |
|
222 |
||
66
94212a58c097
gen_cfile.py modified for avoiding possible conflict in mapped variable names
lbessard
parents:
64
diff
changeset
|
223 |
texts["parent"] = FormatName(entry_infos["name"]) |
0 | 224 |
# Entry type is ARRAY |
225 |
for subIndex, value in enumerate(values): |
|
226 |
texts["subIndex"] = subIndex |
|
227 |
if subIndex > 0: |
|
228 |
subentry_infos = Manager.GetSubentryInfos(index, subIndex) |
|
229 |
typename = Manager.GetTypeName(subentry_infos["type"]) |
|
230 |
typeinfos = GetValidTypeInfos(typename) |
|
231 |
if typeinfos == None: |
|
232 |
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
|
233 |
if typename not in internal_types: |
|
234 |
internal_types[typename] = typeinfos[2] |
|
235 |
texts["subIndexType"] = typeinfos[0] |
|
236 |
texts["suffixe"] = typeinfos[1] |
|
237 |
if typeinfos[2] == "visible_string": |
|
238 |
texts["value"] = "\"%s\""%value |
|
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
239 |
texts["comment"] = "" |
0 | 240 |
else: |
241 |
texts["value"] = "0x%X"%value |
|
76 | 242 |
texts["comment"] = "\t/* %s */"%str(value) |
0 | 243 |
texts["name"] = FormatName(subentry_infos["name"]) |
244 |
if index in variablelist: |
|
76 | 245 |
strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
246 |
mappedVariableContent += "%(subIndexType)s %(parent)s_%(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
|
0 | 247 |
else: |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
248 |
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;%(comment)s\n"%texts |
0 | 249 |
if callbacks: |
76 | 250 |
strDeclareHeader += "extern ODCallback_t %(parent)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts |
0 | 251 |
|
252 |
# Generating Dictionary C++ entry |
|
253 |
if callbacks: |
|
254 |
if index in variablelist: |
|
255 |
name = FormatName(entry_infos["name"]) |
|
256 |
else: |
|
257 |
name = "%(NodeName)s_Index%(index)04X"%texts |
|
258 |
strIndex += " ODCallback_t %s_callbacks[] = \n {\n"%name |
|
259 |
for subIndex in xrange(len(values)): |
|
260 |
strIndex += " NULL,\n" |
|
261 |
strIndex += " };\n" |
|
262 |
indexCallbacks[index] = "*callbacks = %s_callbacks; "%name |
|
263 |
else: |
|
264 |
indexCallbacks[index] = "" |
|
265 |
strIndex += " subindex %(NodeName)s_Index%(index)04X[] = \n {\n"%texts |
|
266 |
for subIndex in xrange(len(values)): |
|
267 |
subentry_infos = Manager.GetSubentryInfos(index, subIndex) |
|
268 |
if subIndex < len(values) - 1: |
|
269 |
sep = "," |
|
270 |
else: |
|
271 |
sep = "" |
|
272 |
typename = Manager.GetTypeName(subentry_infos["type"]) |
|
273 |
typeinfos = GetValidTypeInfos(typename) |
|
274 |
if typename.startswith("VISIBLE_STRING"): |
|
275 |
subIndexType = "visible_string" |
|
276 |
elif typename in internal_types: |
|
277 |
subIndexType = internal_types[typename] |
|
278 |
else: |
|
279 |
subIndexType = typename |
|
280 |
if subIndex == 0: |
|
281 |
if entry_infos["struct"] & OD_MultipleSubindexes: |
|
282 |
name = "%(NodeName)s_highestSubIndex_obj%(index)04X"%texts |
|
283 |
elif index in variablelist: |
|
284 |
name = FormatName(subentry_infos["name"]) |
|
285 |
else: |
|
286 |
name = FormatName("%s_obj%04X"%(texts["NodeName"], texts["index"])) |
|
287 |
elif entry_infos["struct"] & OD_IdenticalSubindexes: |
|
288 |
if index in variablelist: |
|
289 |
name = "%s[%d]"%(FormatName(entry_infos["name"]), subIndex - 1) |
|
290 |
else: |
|
291 |
name = "%s_obj%04X[%d]"%(texts["NodeName"], texts["index"], subIndex - 1) |
|
292 |
else: |
|
293 |
if index in variablelist: |
|
70 | 294 |
name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"])) |
0 | 295 |
else: |
296 |
name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"])) |
|
297 |
if subIndexType == "visible_string": |
|
298 |
sizeof = name |
|
299 |
else: |
|
300 |
sizeof = typeinfos[0] |
|
301 |
params = Manager.GetCurrentParamsEntry(index, subIndex) |
|
302 |
if params["save"]: |
|
303 |
save = "|TO_BE_SAVE" |
|
304 |
else: |
|
305 |
save = "" |
|
306 |
strIndex += " { %s%s, %s, sizeof (%s), (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,subIndexType,sizeof,name,sep) |
|
307 |
strIndex += " };\n" |
|
308 |
indexContents[index] = strIndex |
|
309 |
||
310 |
#------------------------------------------------------------------------------- |
|
311 |
# Declaration of Particular Parameters |
|
312 |
#------------------------------------------------------------------------------- |
|
313 |
||
314 |
if 0x1006 not in communicationlist: |
|
315 |
entry_infos = Manager.GetEntryInfos(0x1006) |
|
316 |
texts["EntryName"] = entry_infos["name"] |
|
317 |
indexContents[0x1006] = """\n/* index 0x1006 : %(EntryName)s */ |
|
76 | 318 |
UNS32 %(NodeName)s_obj1006 = 0x0; /* 0 */ |
0 | 319 |
"""%texts |
320 |
||
321 |
if 0x1016 in communicationlist: |
|
322 |
texts["nombre"] = Manager.GetCurrentEntry(0x1016, 0) |
|
323 |
else: |
|
324 |
texts["nombre"] = 0 |
|
325 |
entry_infos = Manager.GetEntryInfos(0x1016) |
|
326 |
texts["EntryName"] = entry_infos["name"] |
|
327 |
indexContents[0x1016] = """\n/* index 0x1016 : %(EntryName)s */ |
|
328 |
UNS8 %(NodeName)s_highestSubIndex_obj1016 = 0; |
|
91
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
76
diff
changeset
|
329 |
UNS32 %(NodeName)s_obj1016[]={0}; |
0 | 330 |
"""%texts |
331 |
if texts["nombre"] > 0: |
|
332 |
strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(nombre)d] = {TIMER_NONE,};\n"%texts |
|
333 |
else: |
|
76 | 334 |
strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[1];\n"%texts |
0 | 335 |
|
336 |
if 0x1017 not in communicationlist: |
|
337 |
entry_infos = Manager.GetEntryInfos(0x1017) |
|
338 |
texts["EntryName"] = entry_infos["name"] |
|
339 |
indexContents[0x1017] = """\n/* index 0x1017 : %(EntryName)s */ |
|
76 | 340 |
UNS16 %(NodeName)s_obj1017 = 0x0; /* 0 */ |
0 | 341 |
"""%texts |
342 |
||
343 |
#------------------------------------------------------------------------------- |
|
344 |
# Declaration of navigation in the Object Dictionary |
|
345 |
#------------------------------------------------------------------------------- |
|
346 |
||
347 |
strDeclareIndex = "" |
|
348 |
strDeclareSwitch = "" |
|
349 |
strQuickIndex = "" |
|
350 |
quick_index = {} |
|
351 |
for index_cat in index_categories: |
|
352 |
quick_index[index_cat] = {} |
|
353 |
for cat, idx_min, idx_max in categories: |
|
354 |
quick_index[index_cat][cat] = 0 |
|
355 |
maxPDOtransmit = 0 |
|
356 |
for i, index in enumerate(listIndex): |
|
357 |
texts["index"] = index |
|
358 |
strDeclareIndex += " { (subindex*)%(NodeName)s_Index%(index)04X,sizeof(%(NodeName)s_Index%(index)04X)/sizeof(%(NodeName)s_Index%(index)04X[0]), 0x%(index)04X},\n"%texts |
|
359 |
strDeclareSwitch += " case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index]) |
|
360 |
for cat, idx_min, idx_max in categories: |
|
361 |
if idx_min <= index <= idx_max: |
|
362 |
quick_index["lastIndex"][cat] = i |
|
363 |
if quick_index["firstIndex"][cat] == 0: |
|
364 |
quick_index["firstIndex"][cat] = i |
|
365 |
if cat == "PDO_TRS": |
|
366 |
maxPDOtransmit += 1 |
|
367 |
texts["maxPDOtransmit"] = max(1, maxPDOtransmit) |
|
368 |
for index_cat in index_categories: |
|
369 |
strQuickIndex += "\nquick_index %s_%s = {\n"%(texts["NodeName"], index_cat) |
|
370 |
sep = "," |
|
371 |
for i, (cat, idx_min, idx_max) in enumerate(categories): |
|
372 |
if i == len(categories) - 1: |
|
373 |
sep = "" |
|
76 | 374 |
strQuickIndex += " %d%s /* %s */\n"%(quick_index[index_cat][cat],sep,cat) |
0 | 375 |
strQuickIndex += "};\n" |
376 |
||
377 |
#------------------------------------------------------------------------------- |
|
378 |
# Write File Content |
|
379 |
#------------------------------------------------------------------------------- |
|
380 |
||
73 | 381 |
fileContent = generated_tag + """ |
0 | 382 |
#include "%s" |
383 |
"""%(headerfilepath) |
|
384 |
||
385 |
fileContent += """ |
|
386 |
/**************************************************************************/ |
|
387 |
/* Declaration of the mapped variables */ |
|
388 |
/**************************************************************************/ |
|
389 |
""" + mappedVariableContent |
|
390 |
||
391 |
fileContent += """ |
|
392 |
/**************************************************************************/ |
|
393 |
/* Declaration of the value range types */ |
|
394 |
/**************************************************************************/ |
|
395 |
""" + valueRangeContent |
|
396 |
||
397 |
fileContent += """ |
|
398 |
/**************************************************************************/ |
|
399 |
/* The node id */ |
|
400 |
/**************************************************************************/ |
|
401 |
/* node_id default value.*/ |
|
402 |
UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X; |
|
403 |
||
76 | 404 |
/**************************************************************************/ |
0 | 405 |
/* Array of message processing information */ |
406 |
||
407 |
const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d; |
|
408 |
||
409 |
"""%texts |
|
410 |
fileContent += strTimers |
|
411 |
||
412 |
fileContent += """ |
|
76 | 413 |
/* |
414 |
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
|
415 |
||
416 |
OBJECT DICTIONARY |
|
417 |
||
418 |
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
|
419 |
*/ |
|
0 | 420 |
"""%texts |
421 |
contentlist = indexContents.keys() |
|
422 |
contentlist.sort() |
|
423 |
for index in contentlist: |
|
424 |
fileContent += indexContents[index] |
|
425 |
||
426 |
fileContent += """ |
|
427 |
const indextable %(NodeName)s_objdict[] = |
|
428 |
{ |
|
429 |
"""%texts |
|
430 |
fileContent += strDeclareIndex |
|
431 |
fileContent += """}; |
|
432 |
||
433 |
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks) |
|
434 |
{ |
|
435 |
int i; |
|
436 |
*callbacks = NULL; |
|
437 |
switch(wIndex){ |
|
438 |
"""%texts |
|
439 |
fileContent += strDeclareSwitch |
|
440 |
fileContent += """ default: |
|
441 |
*errorCode = OD_NO_SUCH_OBJECT; |
|
442 |
return NULL; |
|
443 |
} |
|
444 |
*errorCode = OD_SUCCESSFUL; |
|
445 |
return &%(NodeName)s_objdict[i]; |
|
446 |
} |
|
447 |
||
76 | 448 |
/* To count at which received SYNC a PDO must be sent. |
449 |
* Even if no pdoTransmit are defined, at least one entry is computed |
|
450 |
* for compilations issues. |
|
451 |
*/ |
|
0 | 452 |
UNS8 %(NodeName)s_count_sync[%(maxPDOtransmit)d] = {0,}; |
453 |
"""%texts |
|
454 |
fileContent += strQuickIndex |
|
455 |
fileContent += """ |
|
456 |
UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); |
|
457 |
||
458 |
CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s); |
|
459 |
||
460 |
"""%texts |
|
461 |
||
462 |
#------------------------------------------------------------------------------- |
|
463 |
# Write Header File Content |
|
464 |
#------------------------------------------------------------------------------- |
|
465 |
||
73 | 466 |
HeaderFileContent = generated_tag + """ |
0 | 467 |
#include "data.h" |
468 |
||
76 | 469 |
/* Prototypes of function provided by object dictionnary */ |
63
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
60
diff
changeset
|
470 |
UNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value); |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
60
diff
changeset
|
471 |
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks); |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
60
diff
changeset
|
472 |
|
76 | 473 |
/* prototypes of function to be filled by app. */ |
0 | 474 |
void %(NodeName)s_SDOtimeoutError(UNS8 line); |
475 |
void %(NodeName)s_heartbeatError(UNS8); |
|
476 |
||
477 |
UNS8 %(NodeName)s_canSend(Message *); |
|
478 |
||
60 | 479 |
void %(NodeName)s_initialisation(void); |
480 |
void %(NodeName)s_preOperational(void); |
|
481 |
void %(NodeName)s_operational(void); |
|
482 |
void %(NodeName)s_stopped(void); |
|
483 |
||
484 |
void %(NodeName)s_post_sync(void); |
|
485 |
void %(NodeName)s_post_TPDO(void); |
|
0 | 486 |
|
76 | 487 |
/* Master node data struct */ |
0 | 488 |
extern CO_Data %(NodeName)s_Data; |
489 |
||
490 |
"""%texts |
|
491 |
HeaderFileContent += strDeclareHeader |
|
492 |
||
493 |
return fileContent,HeaderFileContent |
|
494 |
||
495 |
#------------------------------------------------------------------------------- |
|
496 |
# Main Function |
|
497 |
#------------------------------------------------------------------------------- |
|
498 |
||
499 |
def GenerateFile(filepath, manager): |
|
500 |
headerfilepath = os.path.splitext(filepath)[0]+".h" |
|
501 |
content, header = GenerateFileContent(manager, os.path.split(headerfilepath)[1]) |
|
502 |
WriteFile(filepath, content) |
|
503 |
WriteFile(headerfilepath, header) |
|
504 |
return True |