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