author | etisserant |
Tue, 29 Jul 2008 17:20:45 +0200 | |
changeset 506 | c17e2e17aca8 |
parent 493 | a204a86a71f1 |
child 512 | e84806c0ada4 |
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 |
||
188 | 40 |
internal_types = {} |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
41 |
default_string_size = 10 |
188 | 42 |
|
0 | 43 |
# Format a string for making a C++ variable |
44 |
def FormatName(name): |
|
45 |
wordlist = [word for word in word_model.findall(name) if word != ''] |
|
227 | 46 |
return "_".join(wordlist) |
0 | 47 |
|
48 |
# Extract the informations from a given type name |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
49 |
def GetValidTypeInfos(typename, items=[]): |
188 | 50 |
if typename in internal_types: |
51 |
return internal_types[typename] |
|
52 |
else: |
|
53 |
result = type_model.match(typename) |
|
54 |
if result: |
|
55 |
values = result.groups() |
|
56 |
if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]: |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
57 |
typeinfos = ("UNS%s"%values[1], None, "uint%s"%values[1], True) |
188 | 58 |
elif values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
59 |
typeinfos = ("INTEGER%s"%values[1], None, "int%s"%values[1], False) |
188 | 60 |
elif values[0] == "REAL" and int(values[1]) in (32, 64): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
61 |
typeinfos = ("%s%s"%(values[0], values[1]), None, "real%s"%values[1], False) |
188 | 62 |
elif values[0] == "VISIBLE_STRING": |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
63 |
size = default_string_size |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
64 |
for item in items: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
65 |
size = max(size, len(item)) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
66 |
if values[1] != "": |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
67 |
size = max(size, int(values[1])) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
68 |
typeinfos = ("UNS8", size, "visible_string", False) |
188 | 69 |
elif values[0] == "DOMAIN": |
420 | 70 |
size = 0 |
71 |
for item in items: |
|
72 |
size = max(size, len(item)) |
|
73 |
typeinfos = ("UNS8*", size, "domain", False) |
|
188 | 74 |
elif values[0] == "BOOLEAN": |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
75 |
typeinfos = ("UNS8", None, "boolean", False) |
188 | 76 |
else: |
77 |
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
|
78 |
internal_types[typename] = typeinfos |
|
79 |
else: |
|
80 |
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
|
81 |
return typeinfos |
|
0 | 82 |
|
453 | 83 |
def ComputeValue(type, value): |
84 |
if type == "visible_string": |
|
85 |
return "\"%s\""%value, "" |
|
86 |
elif type == "domain": |
|
87 |
return "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]), "" |
|
88 |
elif type.startswith("real"): |
|
89 |
return "%f"%value, "" |
|
90 |
else: |
|
91 |
return "0x%X"%value, "\t/* %s */"%str(value) |
|
92 |
||
0 | 93 |
def WriteFile(filepath, content): |
94 |
cfile = open(filepath,"w") |
|
95 |
cfile.write(content) |
|
96 |
cfile.close() |
|
97 |
||
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
98 |
def GenerateFileContent(Node, headerfilepath, pointers_dict = {}): |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
99 |
""" |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
100 |
pointers_dict = {(Idx,Sidx):"VariableName",...} |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
101 |
""" |
0 | 102 |
global type |
188 | 103 |
global internal_types |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
104 |
global default_string_size |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
105 |
|
0 | 106 |
texts = {} |
107 |
texts["maxPDOtransmit"] = 0 |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
108 |
texts["NodeName"] = Node.GetNodeName() |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
109 |
texts["NodeID"] = Node.GetNodeID() |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
110 |
texts["NodeType"] = Node.GetNodeType() |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
111 |
texts["Description"] = Node.GetNodeDescription() |
0 | 112 |
texts["iam_a_slave"] = 0 |
113 |
if (texts["NodeType"] == "slave"): |
|
114 |
texts["iam_a_slave"] = 1 |
|
115 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
116 |
default_string_size = Node.GetDefaultStringSize() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
117 |
|
0 | 118 |
# Compiling lists of indexes |
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
119 |
rangelist = [idx for idx in Node.GetIndexes() if 0 <= idx <= 0x260] |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
120 |
listIndex = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0xFFFF] |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
121 |
communicationlist = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0x11FF] |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
122 |
sdolist = [idx for idx in Node.GetIndexes() if 0x1200 <= idx <= 0x12FF] |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
123 |
pdolist = [idx for idx in Node.GetIndexes() if 0x1400 <= idx <= 0x1BFF] |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
124 |
variablelist = [idx for idx in Node.GetIndexes() if 0x2000 <= idx <= 0xBFFF] |
0 | 125 |
|
126 |
#------------------------------------------------------------------------------- |
|
127 |
# Declaration of the value range types |
|
128 |
#------------------------------------------------------------------------------- |
|
129 |
||
130 |
valueRangeContent = "" |
|
286
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
131 |
strDefine = "\n#define valueRange_EMC 0x9F /* Type for index 0x1003 subindex 0x00 (only set of value 0 is possible) */" |
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
132 |
strSwitch = """ case valueRange_EMC: |
288 | 133 |
if (*(UNS8*)value != (UNS8)0) return OD_VALUE_RANGE_EXCEEDED; |
286
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
134 |
break;\n""" |
313 | 135 |
internal_types["valueRange_EMC"] = ("UNS8", "", "valueRange_EMC", True) |
0 | 136 |
num = 0 |
137 |
for index in rangelist: |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
138 |
rangename = Node.GetEntryName(index) |
0 | 139 |
result = range_model.match(rangename) |
140 |
if result: |
|
141 |
num += 1 |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
142 |
typeindex = Node.GetEntry(index, 1) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
143 |
typename = Node.GetTypeName(typeindex) |
0 | 144 |
typeinfos = GetValidTypeInfos(typename) |
188 | 145 |
internal_types[rangename] = (typeinfos[0], typeinfos[1], "valueRange_%d"%num) |
289
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
146 |
minvalue = Node.GetEntry(index, 2) |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
147 |
maxvalue = Node.GetEntry(index, 3) |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
148 |
strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typeinfos[0],str(minvalue),str(maxvalue)) |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
149 |
strSwitch += " case valueRange_%d:\n"%(num) |
313 | 150 |
if typeinfos[3] and minvalue <= 0: |
289
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
151 |
strSwitch += " /* Negative or null low limit ignored because of unsigned type */;\n" |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
152 |
else: |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
153 |
strSwitch += " if (*(%s*)value < (%s)%s) return OD_VALUE_TOO_LOW;\n"%(typeinfos[0],typeinfos[0],str(minvalue)) |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
154 |
strSwitch += " if (*(%s*)value > (%s)%s) return OD_VALUE_TOO_HIGH;\n"%(typeinfos[0],typeinfos[0],str(maxvalue)) |
a22ce0314063
Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents:
288
diff
changeset
|
155 |
strSwitch += " break;\n" |
0 | 156 |
|
157 |
valueRangeContent += strDefine |
|
158 |
valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts |
|
159 |
valueRangeContent += "\n switch (typeValue) {\n" |
|
160 |
valueRangeContent += strSwitch |
|
161 |
valueRangeContent += " }\n return 0;\n}\n" |
|
162 |
||
163 |
#------------------------------------------------------------------------------- |
|
164 |
# Creation of the mapped variables and object dictionary |
|
165 |
#------------------------------------------------------------------------------- |
|
166 |
||
167 |
mappedVariableContent = "" |
|
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
168 |
pointedVariableContent = "" |
0 | 169 |
strDeclareHeader = "" |
170 |
strDeclareCallback = "" |
|
171 |
indexContents = {} |
|
172 |
indexCallbacks = {} |
|
173 |
for index in listIndex: |
|
174 |
texts["index"] = index |
|
175 |
strIndex = "" |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
176 |
entry_infos = Node.GetEntryInfos(index) |
229 | 177 |
texts["EntryName"] = entry_infos["name"].encode('ascii','replace') |
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
178 |
values = Node.GetEntry(index) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
179 |
callbacks = Node.HasEntryCallbacks(index) |
0 | 180 |
if index in variablelist: |
181 |
strIndex += "\n/* index 0x%(index)04X : Mapped variable %(EntryName)s */\n"%texts |
|
182 |
else: |
|
183 |
strIndex += "\n/* index 0x%(index)04X : %(EntryName)s. */\n"%texts |
|
184 |
||
185 |
# Entry type is VAR |
|
186 |
if type(values) != ListType: |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
187 |
subentry_infos = Node.GetSubentryInfos(index, 0) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
188 |
typename = Node.GetTypeName(subentry_infos["type"]) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
189 |
typeinfos = GetValidTypeInfos(typename, [values]) |
0 | 190 |
texts["subIndexType"] = typeinfos[0] |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
191 |
if typeinfos[1] is not None: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
192 |
texts["suffixe"] = "[%d]"%typeinfos[1] |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
193 |
else: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
194 |
texts["suffixe"] = "" |
453 | 195 |
texts["value"], texts["comment"] = ComputeValue(typeinfos[2], values) |
0 | 196 |
if index in variablelist: |
197 |
texts["name"] = FormatName(subentry_infos["name"]) |
|
76 | 198 |
strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts |
199 |
mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts |
|
0 | 200 |
else: |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
201 |
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;%(comment)s\n"%texts |
0 | 202 |
values = [values] |
203 |
else: |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
204 |
subentry_infos = Node.GetSubentryInfos(index, 0) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
205 |
typename = Node.GetTypeName(subentry_infos["type"]) |
188 | 206 |
typeinfos = GetValidTypeInfos(typename) |
286
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
207 |
if index == 0x1003: |
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
208 |
texts["value"] = 0 |
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
209 |
else: |
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
210 |
texts["value"] = values[0] |
188 | 211 |
texts["subIndexType"] = typeinfos[0] |
212 |
strIndex += " %(subIndexType)s %(NodeName)s_highestSubIndex_obj%(index)04X = %(value)d; /* number of subindex - 1*/\n"%texts |
|
0 | 213 |
|
214 |
# Entry type is RECORD |
|
215 |
if entry_infos["struct"] & OD_IdenticalSubindexes: |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
216 |
subentry_infos = Node.GetSubentryInfos(index, 1) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
217 |
typename = Node.GetTypeName(subentry_infos["type"]) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
218 |
typeinfos = GetValidTypeInfos(typename, values[1:]) |
0 | 219 |
texts["subIndexType"] = typeinfos[0] |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
220 |
if typeinfos[1] is not None: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
221 |
texts["suffixe"] = "[%d]"%typeinfos[1] |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
222 |
else: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
223 |
texts["suffixe"] = "" |
0 | 224 |
texts["length"] = values[0] |
225 |
if index in variablelist: |
|
226 |
texts["name"] = FormatName(entry_infos["name"]) |
|
76 | 227 |
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 |
228 |
mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n {\n"%texts |
|
0 | 229 |
for subIndex, value in enumerate(values): |
230 |
sep = "," |
|
231 |
if subIndex > 0: |
|
232 |
if subIndex == len(values)-1: |
|
233 |
sep = "" |
|
453 | 234 |
value, comment = ComputeValue(typeinfos[2], value) |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
235 |
mappedVariableContent += " %s%s%s\n"%(value, sep, comment) |
28 | 236 |
mappedVariableContent += " };\n" |
0 | 237 |
else: |
238 |
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n {\n"%texts |
|
239 |
for subIndex, value in enumerate(values): |
|
240 |
sep = "," |
|
241 |
if subIndex > 0: |
|
242 |
if subIndex == len(values)-1: |
|
243 |
sep = "" |
|
453 | 244 |
value, comment = ComputeValue(typeinfos[2], value) |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
245 |
strIndex += " %s%s%s\n"%(value, sep, comment) |
0 | 246 |
strIndex += " };\n" |
247 |
else: |
|
248 |
||
66
94212a58c097
gen_cfile.py modified for avoiding possible conflict in mapped variable names
lbessard
parents:
64
diff
changeset
|
249 |
texts["parent"] = FormatName(entry_infos["name"]) |
0 | 250 |
# Entry type is ARRAY |
251 |
for subIndex, value in enumerate(values): |
|
252 |
texts["subIndex"] = subIndex |
|
253 |
if subIndex > 0: |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
254 |
subentry_infos = Node.GetSubentryInfos(index, subIndex) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
255 |
typename = Node.GetTypeName(subentry_infos["type"]) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
256 |
typeinfos = GetValidTypeInfos(typename, [values[subIndex]]) |
0 | 257 |
texts["subIndexType"] = typeinfos[0] |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
258 |
if typeinfos[1] is not None: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
259 |
texts["suffixe"] = "[%d]"%typeinfos[1] |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
260 |
else: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
261 |
texts["suffixe"] = "" |
453 | 262 |
texts["value"], texts["comment"] = ComputeValue(typeinfos[2], value) |
0 | 263 |
texts["name"] = FormatName(subentry_infos["name"]) |
264 |
if index in variablelist: |
|
76 | 265 |
strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
266 |
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 | 267 |
else: |
5
e4365e7d47f0
Bug on number in hexa computed by gen_cfile corrected
lbessard
parents:
0
diff
changeset
|
268 |
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;%(comment)s\n"%texts |
0 | 269 |
|
270 |
# Generating Dictionary C++ entry |
|
271 |
if callbacks: |
|
272 |
if index in variablelist: |
|
273 |
name = FormatName(entry_infos["name"]) |
|
274 |
else: |
|
275 |
name = "%(NodeName)s_Index%(index)04X"%texts |
|
276 |
strIndex += " ODCallback_t %s_callbacks[] = \n {\n"%name |
|
277 |
for subIndex in xrange(len(values)): |
|
278 |
strIndex += " NULL,\n" |
|
279 |
strIndex += " };\n" |
|
280 |
indexCallbacks[index] = "*callbacks = %s_callbacks; "%name |
|
281 |
else: |
|
282 |
indexCallbacks[index] = "" |
|
283 |
strIndex += " subindex %(NodeName)s_Index%(index)04X[] = \n {\n"%texts |
|
284 |
for subIndex in xrange(len(values)): |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
285 |
subentry_infos = Node.GetSubentryInfos(index, subIndex) |
0 | 286 |
if subIndex < len(values) - 1: |
287 |
sep = "," |
|
288 |
else: |
|
289 |
sep = "" |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
290 |
typename = Node.GetTypeName(subentry_infos["type"]) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
291 |
if entry_infos["struct"] & OD_IdenticalSubindexes: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
292 |
typeinfos = GetValidTypeInfos(typename, values) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
293 |
else: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
366
diff
changeset
|
294 |
typeinfos = GetValidTypeInfos(typename, [values[subIndex]]) |
0 | 295 |
if subIndex == 0: |
286
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
296 |
if index == 0x1003: |
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
297 |
typeinfos = GetValidTypeInfos("valueRange_EMC") |
0 | 298 |
if entry_infos["struct"] & OD_MultipleSubindexes: |
299 |
name = "%(NodeName)s_highestSubIndex_obj%(index)04X"%texts |
|
300 |
elif index in variablelist: |
|
301 |
name = FormatName(subentry_infos["name"]) |
|
302 |
else: |
|
303 |
name = FormatName("%s_obj%04X"%(texts["NodeName"], texts["index"])) |
|
304 |
elif entry_infos["struct"] & OD_IdenticalSubindexes: |
|
305 |
if index in variablelist: |
|
306 |
name = "%s[%d]"%(FormatName(entry_infos["name"]), subIndex - 1) |
|
307 |
else: |
|
308 |
name = "%s_obj%04X[%d]"%(texts["NodeName"], texts["index"], subIndex - 1) |
|
309 |
else: |
|
310 |
if index in variablelist: |
|
70 | 311 |
name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"])) |
0 | 312 |
else: |
313 |
name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"])) |
|
421
6221b4db8c42
Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents:
420
diff
changeset
|
314 |
if typeinfos[2] == "visible_string": |
6221b4db8c42
Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents:
420
diff
changeset
|
315 |
sizeof = str(max(len(values[subIndex]), default_string_size)) |
6221b4db8c42
Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents:
420
diff
changeset
|
316 |
elif typeinfos[2] == "domain": |
6221b4db8c42
Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents:
420
diff
changeset
|
317 |
sizeof = str(len(values[subIndex])) |
176 | 318 |
else: |
319 |
sizeof = "sizeof (%s)"%typeinfos[0] |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
320 |
params = Node.GetParamsEntry(index, subIndex) |
0 | 321 |
if params["save"]: |
322 |
save = "|TO_BE_SAVE" |
|
323 |
else: |
|
324 |
save = "" |
|
188 | 325 |
strIndex += " { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,name,sep) |
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
326 |
pointer_name = pointers_dict.get((index, subIndex), None) |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
327 |
if pointer_name is not None: |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
328 |
pointedVariableContent += "%s* %s = &%s;\n"%(typeinfos[0], pointer_name, name) |
0 | 329 |
strIndex += " };\n" |
330 |
indexContents[index] = strIndex |
|
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
331 |
|
0 | 332 |
#------------------------------------------------------------------------------- |
333 |
# Declaration of Particular Parameters |
|
334 |
#------------------------------------------------------------------------------- |
|
335 |
||
284 | 336 |
if 0x1003 not in communicationlist: |
337 |
entry_infos = Node.GetEntryInfos(0x1003) |
|
338 |
texts["EntryName"] = entry_infos["name"] |
|
339 |
indexContents[0x1003] = """\n/* index 0x1003 : %(EntryName)s */ |
|
340 |
UNS8 %(NodeName)s_highestSubIndex_obj1003 = 0; /* number of subindex - 1*/ |
|
341 |
UNS32 %(NodeName)s_obj1003[] = |
|
342 |
{ |
|
343 |
0x0 /* 0 */ |
|
344 |
}; |
|
345 |
ODCallback_t %(NodeName)s_Index1003_callbacks[] = |
|
346 |
{ |
|
347 |
NULL, |
|
348 |
NULL, |
|
349 |
}; |
|
350 |
subindex %(NodeName)s_Index1003[] = |
|
351 |
{ |
|
286
85d5361179f3
Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents:
284
diff
changeset
|
352 |
{ RW, valueRange_EMC, sizeof (UNS8), (void*)&%(NodeName)s_highestSubIndex_obj1003 }, |
284 | 353 |
{ RO, uint32, sizeof (UNS32), (void*)&%(NodeName)s_obj1003[0] } |
354 |
}; |
|
355 |
"""%texts |
|
356 |
||
261
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
357 |
if 0x1005 not in communicationlist: |
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
358 |
entry_infos = Node.GetEntryInfos(0x1005) |
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
359 |
texts["EntryName"] = entry_infos["name"] |
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
360 |
indexContents[0x1005] = """\n/* index 0x1005 : %(EntryName)s */ |
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
361 |
UNS32 %(NodeName)s_obj1005 = 0x0; /* 0 */ |
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
362 |
"""%texts |
dbcd80bcab82
Prevent potential problem with missing 0x1005 OD entry
etisserant
parents:
245
diff
changeset
|
363 |
|
0 | 364 |
if 0x1006 not in communicationlist: |
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
365 |
entry_infos = Node.GetEntryInfos(0x1006) |
0 | 366 |
texts["EntryName"] = entry_infos["name"] |
367 |
indexContents[0x1006] = """\n/* index 0x1006 : %(EntryName)s */ |
|
76 | 368 |
UNS32 %(NodeName)s_obj1006 = 0x0; /* 0 */ |
0 | 369 |
"""%texts |
370 |
||
314
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
313
diff
changeset
|
371 |
if 0x1014 not in communicationlist: |
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
313
diff
changeset
|
372 |
entry_infos = Node.GetEntryInfos(0x1014) |
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
313
diff
changeset
|
373 |
texts["EntryName"] = entry_infos["name"] |
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
313
diff
changeset
|
374 |
indexContents[0x1014] = """\n/* index 0x1014 : %(EntryName)s */ |
493
a204a86a71f1
Modified initial value of 1014h to 0x80 + nodeid when 1014 is not included explicitly in the OD.
luis
parents:
484
diff
changeset
|
375 |
UNS32 %(NodeName)s_obj1014 = 0x80 + 0x%(NodeID)02X; /* 128 + NodeID */ |
314
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
313
diff
changeset
|
376 |
"""%texts |
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
313
diff
changeset
|
377 |
|
0 | 378 |
if 0x1016 in communicationlist: |
325 | 379 |
texts["heartBeatTimers_number"] = Node.GetEntry(0x1016, 0) |
0 | 380 |
else: |
325 | 381 |
texts["heartBeatTimers_number"] = 0 |
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
382 |
entry_infos = Node.GetEntryInfos(0x1016) |
0 | 383 |
texts["EntryName"] = entry_infos["name"] |
384 |
indexContents[0x1016] = """\n/* index 0x1016 : %(EntryName)s */ |
|
385 |
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
|
386 |
UNS32 %(NodeName)s_obj1016[]={0}; |
0 | 387 |
"""%texts |
325 | 388 |
|
0 | 389 |
if 0x1017 not in communicationlist: |
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
235
diff
changeset
|
390 |
entry_infos = Node.GetEntryInfos(0x1017) |
0 | 391 |
texts["EntryName"] = entry_infos["name"] |
392 |
indexContents[0x1017] = """\n/* index 0x1017 : %(EntryName)s */ |
|
76 | 393 |
UNS16 %(NodeName)s_obj1017 = 0x0; /* 0 */ |
0 | 394 |
"""%texts |
395 |
||
396 |
#------------------------------------------------------------------------------- |
|
397 |
# Declaration of navigation in the Object Dictionary |
|
398 |
#------------------------------------------------------------------------------- |
|
399 |
||
400 |
strDeclareIndex = "" |
|
401 |
strDeclareSwitch = "" |
|
402 |
strQuickIndex = "" |
|
403 |
quick_index = {} |
|
404 |
for index_cat in index_categories: |
|
405 |
quick_index[index_cat] = {} |
|
406 |
for cat, idx_min, idx_max in categories: |
|
407 |
quick_index[index_cat][cat] = 0 |
|
408 |
maxPDOtransmit = 0 |
|
409 |
for i, index in enumerate(listIndex): |
|
410 |
texts["index"] = index |
|
411 |
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 |
|
412 |
strDeclareSwitch += " case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index]) |
|
413 |
for cat, idx_min, idx_max in categories: |
|
414 |
if idx_min <= index <= idx_max: |
|
415 |
quick_index["lastIndex"][cat] = i |
|
416 |
if quick_index["firstIndex"][cat] == 0: |
|
417 |
quick_index["firstIndex"][cat] = i |
|
418 |
if cat == "PDO_TRS": |
|
419 |
maxPDOtransmit += 1 |
|
420 |
texts["maxPDOtransmit"] = max(1, maxPDOtransmit) |
|
421 |
for index_cat in index_categories: |
|
479
92891f53630b
Defining quick_index structures and ObjdictSize as constants
lbessard
parents:
453
diff
changeset
|
422 |
strQuickIndex += "\nconst quick_index %s_%s = {\n"%(texts["NodeName"], index_cat) |
0 | 423 |
sep = "," |
424 |
for i, (cat, idx_min, idx_max) in enumerate(categories): |
|
425 |
if i == len(categories) - 1: |
|
426 |
sep = "" |
|
76 | 427 |
strQuickIndex += " %d%s /* %s */\n"%(quick_index[index_cat][cat],sep,cat) |
0 | 428 |
strQuickIndex += "};\n" |
429 |
||
430 |
#------------------------------------------------------------------------------- |
|
431 |
# Write File Content |
|
432 |
#------------------------------------------------------------------------------- |
|
433 |
||
73 | 434 |
fileContent = generated_tag + """ |
0 | 435 |
#include "%s" |
436 |
"""%(headerfilepath) |
|
437 |
||
438 |
fileContent += """ |
|
439 |
/**************************************************************************/ |
|
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
440 |
/* Declaration of mapped variables */ |
0 | 441 |
/**************************************************************************/ |
442 |
""" + mappedVariableContent |
|
443 |
||
444 |
fileContent += """ |
|
445 |
/**************************************************************************/ |
|
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
446 |
/* Declaration of value range types */ |
0 | 447 |
/**************************************************************************/ |
448 |
""" + valueRangeContent |
|
449 |
||
450 |
fileContent += """ |
|
451 |
/**************************************************************************/ |
|
452 |
/* The node id */ |
|
453 |
/**************************************************************************/ |
|
454 |
/* node_id default value.*/ |
|
455 |
UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X; |
|
456 |
||
76 | 457 |
/**************************************************************************/ |
0 | 458 |
/* Array of message processing information */ |
459 |
||
460 |
const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d; |
|
461 |
||
462 |
"""%texts |
|
325 | 463 |
if texts["heartBeatTimers_number"] > 0: |
422
43a4d6deb007
Fixed herbeat timer array partial initialization in generated OD code.
etisserant
parents:
421
diff
changeset
|
464 |
declaration = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(heartBeatTimers_number)d]"%texts |
43a4d6deb007
Fixed herbeat timer array partial initialization in generated OD code.
etisserant
parents:
421
diff
changeset
|
465 |
initializer = "{TIMER_NONE" + ",TIMER_NONE" * (texts["heartBeatTimers_number"] - 1) + "}" |
43a4d6deb007
Fixed herbeat timer array partial initialization in generated OD code.
etisserant
parents:
421
diff
changeset
|
466 |
fileContent += declaration + " = " + initializer + ";\n" |
325 | 467 |
else: |
468 |
fileContent += "TIMER_HANDLE %(NodeName)s_heartBeatTimers[1];\n"%texts |
|
0 | 469 |
|
470 |
fileContent += """ |
|
76 | 471 |
/* |
472 |
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
|
473 |
||
474 |
OBJECT DICTIONARY |
|
475 |
||
476 |
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
|
477 |
*/ |
|
0 | 478 |
"""%texts |
479 |
contentlist = indexContents.keys() |
|
480 |
contentlist.sort() |
|
481 |
for index in contentlist: |
|
482 |
fileContent += indexContents[index] |
|
483 |
||
484 |
fileContent += """ |
|
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
485 |
/**************************************************************************/ |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
486 |
/* Declaration of pointed variables */ |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
487 |
/**************************************************************************/ |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
488 |
""" + pointedVariableContent |
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
489 |
|
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
490 |
fileContent += """ |
0 | 491 |
const indextable %(NodeName)s_objdict[] = |
492 |
{ |
|
493 |
"""%texts |
|
494 |
fileContent += strDeclareIndex |
|
495 |
fileContent += """}; |
|
496 |
||
497 |
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks) |
|
498 |
{ |
|
499 |
int i; |
|
500 |
*callbacks = NULL; |
|
501 |
switch(wIndex){ |
|
502 |
"""%texts |
|
503 |
fileContent += strDeclareSwitch |
|
504 |
fileContent += """ default: |
|
505 |
*errorCode = OD_NO_SUCH_OBJECT; |
|
506 |
return NULL; |
|
507 |
} |
|
508 |
*errorCode = OD_SUCCESSFUL; |
|
509 |
return &%(NodeName)s_objdict[i]; |
|
510 |
} |
|
511 |
||
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
229
diff
changeset
|
512 |
/* |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
229
diff
changeset
|
513 |
* To count at which received SYNC a PDO must be sent. |
76 | 514 |
* Even if no pdoTransmit are defined, at least one entry is computed |
515 |
* for compilations issues. |
|
516 |
*/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
229
diff
changeset
|
517 |
s_PDO_status %(NodeName)s_PDO_status[%(maxPDOtransmit)d] = {"""%texts |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
229
diff
changeset
|
518 |
|
366 | 519 |
fileContent += ",".join(["s_PDO_status_Initializer"]*texts["maxPDOtransmit"]) + """}; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
229
diff
changeset
|
520 |
""" |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
229
diff
changeset
|
521 |
|
0 | 522 |
fileContent += strQuickIndex |
523 |
fileContent += """ |
|
479
92891f53630b
Defining quick_index structures and ObjdictSize as constants
lbessard
parents:
453
diff
changeset
|
524 |
const UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); |
0 | 525 |
|
526 |
CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s); |
|
527 |
||
528 |
"""%texts |
|
529 |
||
530 |
#------------------------------------------------------------------------------- |
|
531 |
# Write Header File Content |
|
532 |
#------------------------------------------------------------------------------- |
|
533 |
||
223 | 534 |
texts["file_include_name"] = headerfilepath.replace(".", "_").upper() |
73 | 535 |
HeaderFileContent = generated_tag + """ |
224 | 536 |
#ifndef %(file_include_name)s |
223 | 537 |
#define %(file_include_name)s |
538 |
||
0 | 539 |
#include "data.h" |
540 |
||
76 | 541 |
/* 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
|
542 |
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
|
543 |
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
|
544 |
|
76 | 545 |
/* Master node data struct */ |
0 | 546 |
extern CO_Data %(NodeName)s_Data; |
547 |
"""%texts |
|
548 |
HeaderFileContent += strDeclareHeader |
|
549 |
||
223 | 550 |
HeaderFileContent += "\n#endif // %(file_include_name)s\n"%texts |
551 |
||
0 | 552 |
return fileContent,HeaderFileContent |
553 |
||
554 |
#------------------------------------------------------------------------------- |
|
555 |
# Main Function |
|
556 |
#------------------------------------------------------------------------------- |
|
557 |
||
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
558 |
def GenerateFile(filepath, node, pointers_dict = {}): |
188 | 559 |
try: |
560 |
headerfilepath = os.path.splitext(filepath)[0]+".h" |
|
484
f59d1cdde42b
Added pointer variable list in GenCfile.py, for use with Beremiz's generated code.
etisserant
parents:
479
diff
changeset
|
561 |
content, header = GenerateFileContent(node, os.path.split(headerfilepath)[1], pointers_dict) |
188 | 562 |
WriteFile(filepath, content) |
563 |
WriteFile(headerfilepath, header) |
|
564 |
return None |
|
565 |
except ValueError, message: |
|
566 |
return "Unable to Generate C File\n%s"%message |
|
567 |