]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - objdictgen/gen_cfile.py
Adding standard default value to index 0x1014
[CanFestival-3.git] / objdictgen / gen_cfile.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
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
23
24 from node import *
25 from types import *
26
27 import re, os
28
29 word_model = re.compile('([a-zA-Z_0-9]*)')
30 type_model = re.compile('([\_A-Z]*)([0-9]*)')
31 range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]')
32
33 categories = [("SDO_SVR", 0x1200, 0x127F), ("SDO_CLT", 0x1280, 0x12FF),
34               ("PDO_RCV", 0x1400, 0x15FF), ("PDO_RCV_MAP", 0x1600, 0x17FF),
35               ("PDO_TRS", 0x1800, 0x19FF), ("PDO_TRS_MAP", 0x1A00, 0x1BFF)]
36 index_categories = ["firstIndex", "lastIndex"]
37
38 generated_tag = """\n/* File generated by gen_cfile.py. Should not be modified. */\n"""
39
40 internal_types = {}
41
42 # Format a string for making a C++ variable
43 def FormatName(name):
44     wordlist = [word for word in word_model.findall(name) if word != '']
45     return "_".join(wordlist)
46
47 # Extract the informations from a given type name
48 def GetValidTypeInfos(typename):
49     if typename in internal_types:
50         return internal_types[typename]
51     else:
52         result = type_model.match(typename)
53         if result:
54             values = result.groups()
55             if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
56                 typeinfos = ("UNS%s"%values[1], "", "uint%s"%values[1], True)
57             elif values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
58                 typeinfos = ("INTEGER%s"%values[1], "", "int%s"%values[1], False)
59             elif values[0] == "REAL" and int(values[1]) in (32, 64):
60                 typeinfos = ("%s%s"%(values[0], values[1]), "", "real%s"%values[1], False)
61             elif values[0] == "VISIBLE_STRING":
62                 if values[1] == "":
63                     typeinfos = ("UNS8", "[10]", "visible_string", False)
64                 else:
65                     typeinfos = ("UNS8", "[%s]"%values[1], "visible_string", False)
66             elif values[0] == "DOMAIN":
67                 typeinfos = ("UNS8*", "", "domain", True)
68             elif values[0] == "BOOLEAN":
69                 typeinfos = ("UNS8", "", "boolean", True)
70             else:
71                 raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
72             internal_types[typename] = typeinfos
73         else:
74             raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
75     return typeinfos
76
77 def WriteFile(filepath, content):
78     cfile = open(filepath,"w")
79     cfile.write(content)
80     cfile.close()
81
82 def GenerateFileContent(Node, headerfilepath):
83     global type
84     global internal_types
85     texts = {}
86     texts["maxPDOtransmit"] = 0
87     texts["NodeName"] = Node.GetNodeName()
88     texts["NodeID"] = Node.GetNodeID()
89     texts["NodeType"] = Node.GetNodeType()
90     texts["Description"] = Node.GetNodeDescription()
91     texts["iam_a_slave"] = 0
92     if (texts["NodeType"] == "slave"):
93         texts["iam_a_slave"] = 1
94     
95     # Compiling lists of indexes
96     rangelist = [idx for idx in Node.GetIndexes() if 0 <= idx <= 0x260]
97     listIndex = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0xFFFF]
98     communicationlist = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0x11FF]
99     sdolist = [idx for idx in Node.GetIndexes() if 0x1200 <= idx <= 0x12FF]
100     pdolist = [idx for idx in Node.GetIndexes() if 0x1400 <= idx <= 0x1BFF]
101     variablelist = [idx for idx in Node.GetIndexes() if 0x2000 <= idx <= 0xBFFF]
102
103 #-------------------------------------------------------------------------------
104 #                       Declaration of the value range types
105 #-------------------------------------------------------------------------------    
106     
107     valueRangeContent = ""
108     strDefine = "\n#define valueRange_EMC 0x9F /* Type for index 0x1003 subindex 0x00 (only set of value 0 is possible) */"
109     strSwitch = """    case valueRange_EMC:
110       if (*(UNS8*)value != (UNS8)0) return OD_VALUE_RANGE_EXCEEDED;
111       break;\n"""
112     internal_types["valueRange_EMC"] = ("UNS8", "", "valueRange_EMC", True)
113     num = 0
114     for index in rangelist:
115         rangename = Node.GetEntryName(index)
116         result = range_model.match(rangename)
117         if result:
118             num += 1
119             typeindex = Node.GetEntry(index, 1)
120             typename = Node.GetTypeName(typeindex)
121             typeinfos = GetValidTypeInfos(typename)
122             internal_types[rangename] = (typeinfos[0], typeinfos[1], "valueRange_%d"%num)
123             minvalue = Node.GetEntry(index, 2)
124             maxvalue = Node.GetEntry(index, 3)
125             strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typeinfos[0],str(minvalue),str(maxvalue))
126             strSwitch += "    case valueRange_%d:\n"%(num)
127             if typeinfos[3] and minvalue <= 0:
128                 strSwitch += "      /* Negative or null low limit ignored because of unsigned type */;\n"
129             else:
130                 strSwitch += "      if (*(%s*)value < (%s)%s) return OD_VALUE_TOO_LOW;\n"%(typeinfos[0],typeinfos[0],str(minvalue))
131             strSwitch += "      if (*(%s*)value > (%s)%s) return OD_VALUE_TOO_HIGH;\n"%(typeinfos[0],typeinfos[0],str(maxvalue))
132             strSwitch += "    break;\n"
133
134     valueRangeContent += strDefine
135     valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts
136     valueRangeContent += "\n  switch (typeValue) {\n"
137     valueRangeContent += strSwitch
138     valueRangeContent += "  }\n  return 0;\n}\n"
139
140 #-------------------------------------------------------------------------------
141 #            Creation of the mapped variables and object dictionary
142 #-------------------------------------------------------------------------------
143
144     mappedVariableContent = ""
145     strDeclareHeader = ""
146     strDeclareCallback = ""
147     indexContents = {}
148     indexCallbacks = {}
149     for index in listIndex:
150         texts["index"] = index
151         strIndex = ""
152         entry_infos = Node.GetEntryInfos(index)
153         texts["EntryName"] = entry_infos["name"].encode('ascii','replace')
154         values = Node.GetEntry(index)
155         callbacks = Node.HasEntryCallbacks(index)
156         if index in variablelist:
157             strIndex += "\n/* index 0x%(index)04X :   Mapped variable %(EntryName)s */\n"%texts
158         else:
159             strIndex += "\n/* index 0x%(index)04X :   %(EntryName)s. */\n"%texts
160         
161         # Entry type is VAR
162         if type(values) != ListType:
163             subentry_infos = Node.GetSubentryInfos(index, 0)
164             typename = Node.GetTypeName(subentry_infos["type"])
165             typeinfos = GetValidTypeInfos(typename)
166             texts["subIndexType"] = typeinfos[0]
167             texts["suffixe"] = typeinfos[1]
168             if typeinfos[2] == "visible_string":
169                 texts["value"] = "\"%s\""%values
170                 texts["comment"] = ""
171             elif typeinfos[2] == "domain":
172                 texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
173                 texts["comment"] = ""
174             else:
175                 texts["value"] = "0x%X"%values
176                 texts["comment"] = "\t/* %s */"%str(values)
177             if index in variablelist:
178                 texts["name"] = FormatName(subentry_infos["name"])
179                 strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts
180                 if callbacks:
181                     strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
182                 mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts
183             else:
184                 strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;%(comment)s\n"%texts
185             values = [values]
186         else:
187             subentry_infos = Node.GetSubentryInfos(index, 0)
188             typename = Node.GetTypeName(subentry_infos["type"])
189             typeinfos = GetValidTypeInfos(typename)
190             if index == 0x1003:
191                 texts["value"] = 0
192             else:
193                 texts["value"] = values[0]
194             texts["subIndexType"] = typeinfos[0]
195             strIndex += "                    %(subIndexType)s %(NodeName)s_highestSubIndex_obj%(index)04X = %(value)d; /* number of subindex - 1*/\n"%texts
196             
197             # Entry type is RECORD
198             if entry_infos["struct"] & OD_IdenticalSubindexes:
199                 subentry_infos = Node.GetSubentryInfos(index, 1)
200                 typename = Node.GetTypeName(subentry_infos["type"])
201                 typeinfos = GetValidTypeInfos(typename)
202                 texts["subIndexType"] = typeinfos[0]
203                 texts["suffixe"] = typeinfos[1]
204                 texts["length"] = values[0]
205                 if index in variablelist:
206                     texts["name"] = FormatName(entry_infos["name"])
207                     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
208                     if callbacks:
209                         strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
210                     mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n  {\n"%texts
211                     for subIndex, value in enumerate(values):
212                         sep = ","
213                         comment = ""
214                         if subIndex > 0:
215                             if subIndex == len(values)-1:
216                                 sep = ""
217                             if typeinfos[2] == "visible_string":
218                                 value = "\"%s\""%value
219                             elif typeinfos[2] == "domain":
220                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
221                             else:
222                                 comment = "\t/* %s */"%str(value)
223                                 value = "0x%X"%value
224                             mappedVariableContent += "    %s%s%s\n"%(value, sep, comment)
225                     mappedVariableContent += "  };\n"
226                 else:
227                     strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n                    {\n"%texts
228                     for subIndex, value in enumerate(values):
229                         sep = ","
230                         comment = ""
231                         if subIndex > 0:
232                             if subIndex == len(values)-1:
233                                 sep = ""
234                             if typeinfos[2] == "visible_string":
235                                 value = "\"%s\""%value
236                             elif typeinfos[2] == "domain":
237                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
238                             else:
239                                 comment = "\t/* %s */"%str(value)
240                                 value = "0x%X"%value
241                             strIndex += "                      %s%s%s\n"%(value, sep, comment)
242                     strIndex += "                    };\n"
243             else:
244                 
245                 texts["parent"] = FormatName(entry_infos["name"])
246                 # Entry type is ARRAY
247                 for subIndex, value in enumerate(values):
248                     texts["subIndex"] = subIndex
249                     if subIndex > 0:
250                         subentry_infos = Node.GetSubentryInfos(index, subIndex)
251                         typename = Node.GetTypeName(subentry_infos["type"])
252                         typeinfos = GetValidTypeInfos(typename)
253                         texts["subIndexType"] = typeinfos[0]
254                         texts["suffixe"] = typeinfos[1]
255                         if typeinfos[2] == "visible_string":
256                             texts["value"] = "\"%s\""%value
257                             texts["comment"] = ""
258                         elif typeinfos[2] == "domain":
259                             texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
260                             texts["comment"] = ""                       
261                         else:
262                             texts["value"] = "0x%X"%value
263                             texts["comment"] = "\t/* %s */"%str(value)
264                         texts["name"] = FormatName(subentry_infos["name"])
265                         if index in variablelist:
266                             strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts
267                             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
268                         else:
269                             strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;%(comment)s\n"%texts
270                 if callbacks:
271                     strDeclareHeader += "extern ODCallback_t %(parent)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
272         
273         # Generating Dictionary C++ entry
274         if callbacks:
275             if index in variablelist:
276                 name = FormatName(entry_infos["name"])
277             else:
278                 name = "%(NodeName)s_Index%(index)04X"%texts
279             strIndex += "                    ODCallback_t %s_callbacks[] = \n                     {\n"%name
280             for subIndex in xrange(len(values)):
281                 strIndex += "                       NULL,\n"
282             strIndex += "                     };\n"
283             indexCallbacks[index] = "*callbacks = %s_callbacks; "%name
284         else:
285             indexCallbacks[index] = ""
286         strIndex += "                    subindex %(NodeName)s_Index%(index)04X[] = \n                     {\n"%texts
287         for subIndex in xrange(len(values)):
288             subentry_infos = Node.GetSubentryInfos(index, subIndex)
289             if subIndex < len(values) - 1:
290                 sep = ","
291             else:
292                 sep = ""
293             typename = Node.GetTypeName(subentry_infos["type"])
294             typeinfos = GetValidTypeInfos(typename)
295             if subIndex == 0:
296                 if index == 0x1003:
297                     typeinfos = GetValidTypeInfos("valueRange_EMC")
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:
311                     name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"]))
312                 else:
313                     name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"]))
314             if typeinfos[2] in ["visible_string", "domain"]:
315                 sizeof = str(len(values[subIndex]))
316             else:
317                 sizeof = "sizeof (%s)"%typeinfos[0]
318             params = Node.GetParamsEntry(index, subIndex)
319             if params["save"]:
320                 save = "|TO_BE_SAVE"
321             else:
322                 save = ""
323             strIndex += "                       { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,name,sep)
324         strIndex += "                     };\n"
325         indexContents[index] = strIndex
326
327 #-------------------------------------------------------------------------------
328 #                     Declaration of Particular Parameters
329 #-------------------------------------------------------------------------------
330
331     if 0x1003 not in communicationlist:
332         entry_infos = Node.GetEntryInfos(0x1003)
333         texts["EntryName"] = entry_infos["name"]
334         indexContents[0x1003] = """\n/* index 0x1003 :   %(EntryName)s */
335                     UNS8 %(NodeName)s_highestSubIndex_obj1003 = 0; /* number of subindex - 1*/
336                     UNS32 %(NodeName)s_obj1003[] = 
337                     {
338                       0x0       /* 0 */
339                     };
340                     ODCallback_t %(NodeName)s_Index1003_callbacks[] = 
341                      {
342                        NULL,
343                        NULL,
344                      };
345                     subindex %(NodeName)s_Index1003[] = 
346                      {
347                        { RW, valueRange_EMC, sizeof (UNS8), (void*)&%(NodeName)s_highestSubIndex_obj1003 },
348                        { RO, uint32, sizeof (UNS32), (void*)&%(NodeName)s_obj1003[0] }
349                      };
350 """%texts
351
352     if 0x1005 not in communicationlist:
353         entry_infos = Node.GetEntryInfos(0x1005)
354         texts["EntryName"] = entry_infos["name"]
355         indexContents[0x1005] = """\n/* index 0x1005 :   %(EntryName)s */
356                     UNS32 %(NodeName)s_obj1005 = 0x0;   /* 0 */
357 """%texts
358
359     if 0x1006 not in communicationlist:
360         entry_infos = Node.GetEntryInfos(0x1006)
361         texts["EntryName"] = entry_infos["name"]
362         indexContents[0x1006] = """\n/* index 0x1006 :   %(EntryName)s */
363                     UNS32 %(NodeName)s_obj1006 = 0x0;   /* 0 */
364 """%texts
365
366     if 0x1016 in communicationlist:
367         texts["nombre"] = Node.GetEntry(0x1016, 0)
368     else:
369         texts["nombre"] = 0
370         entry_infos = Node.GetEntryInfos(0x1016)
371         texts["EntryName"] = entry_infos["name"]
372         indexContents[0x1016] = """\n/* index 0x1016 :   %(EntryName)s */
373                     UNS8 %(NodeName)s_highestSubIndex_obj1016 = 0;
374                     UNS32 %(NodeName)s_obj1016[]={0};
375 """%texts
376     if texts["nombre"] > 0:
377         strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(nombre)d] = {TIMER_NONE,};\n"%texts
378     else:
379         strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[1];\n"%texts
380
381     if 0x1017 not in communicationlist:
382         entry_infos = Node.GetEntryInfos(0x1017)
383         texts["EntryName"] = entry_infos["name"]
384         indexContents[0x1017] = """\n/* index 0x1017 :   %(EntryName)s */ 
385                     UNS16 %(NodeName)s_obj1017 = 0x0;   /* 0 */
386 """%texts
387
388 #-------------------------------------------------------------------------------
389 #               Declaration of navigation in the Object Dictionary
390 #-------------------------------------------------------------------------------
391
392     strDeclareIndex = ""
393     strDeclareSwitch = ""
394     strQuickIndex = ""
395     quick_index = {}
396     for index_cat in index_categories:
397         quick_index[index_cat] = {}
398         for cat, idx_min, idx_max in categories:
399             quick_index[index_cat][cat] = 0
400     maxPDOtransmit = 0
401     for i, index in enumerate(listIndex):
402         texts["index"] = index
403         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
404         strDeclareSwitch += "           case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index])
405         for cat, idx_min, idx_max in categories:
406             if idx_min <= index <= idx_max:
407                 quick_index["lastIndex"][cat] = i
408                 if quick_index["firstIndex"][cat] == 0:
409                     quick_index["firstIndex"][cat] = i
410                 if cat == "PDO_TRS":
411                     maxPDOtransmit += 1
412     texts["maxPDOtransmit"] = max(1, maxPDOtransmit)
413     for index_cat in index_categories:
414         strQuickIndex += "\nquick_index %s_%s = {\n"%(texts["NodeName"], index_cat)
415         sep = ","
416         for i, (cat, idx_min, idx_max) in enumerate(categories):
417             if i == len(categories) - 1:
418                 sep = ""
419             strQuickIndex += "  %d%s /* %s */\n"%(quick_index[index_cat][cat],sep,cat)
420         strQuickIndex += "};\n"
421
422 #-------------------------------------------------------------------------------
423 #                            Write File Content
424 #-------------------------------------------------------------------------------
425
426     fileContent = generated_tag + """
427 #include "%s"
428 """%(headerfilepath)
429
430     fileContent += """
431 /**************************************************************************/
432 /* Declaration of the mapped variables                                    */
433 /**************************************************************************/
434 """ + mappedVariableContent
435
436     fileContent += """
437 /**************************************************************************/
438 /* Declaration of the value range types                                   */
439 /**************************************************************************/
440 """ + valueRangeContent
441
442     fileContent += """
443 /**************************************************************************/
444 /* The node id                                                            */
445 /**************************************************************************/
446 /* node_id default value.*/
447 UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X;
448
449 /**************************************************************************/
450 /* Array of message processing information */
451
452 const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d;
453
454 """%texts
455     fileContent += strTimers
456     
457     fileContent += """
458 /*
459 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
460
461                                OBJECT DICTIONARY
462
463 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
464 */
465 """%texts
466     contentlist = indexContents.keys()
467     contentlist.sort()
468     for index in contentlist:
469         fileContent += indexContents[index]
470
471     fileContent += """
472 const indextable %(NodeName)s_objdict[] = 
473 {
474 """%texts
475     fileContent += strDeclareIndex
476     fileContent += """};
477
478 const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks)
479 {
480         int i;
481         *callbacks = NULL;
482         switch(wIndex){
483 """%texts
484     fileContent += strDeclareSwitch
485     fileContent += """          default:
486                         *errorCode = OD_NO_SUCH_OBJECT;
487                         return NULL;
488         }
489         *errorCode = OD_SUCCESSFUL;
490         return &%(NodeName)s_objdict[i];
491 }
492
493 /* 
494  * To count at which received SYNC a PDO must be sent.
495  * Even if no pdoTransmit are defined, at least one entry is computed
496  * for compilations issues.
497  */
498 s_PDO_status %(NodeName)s_PDO_status[%(maxPDOtransmit)d] = {"""%texts
499
500     fileContent += ",".join(["s_PDO_staus_Initializer"]*texts["maxPDOtransmit"]) + """};
501 """
502
503     fileContent += strQuickIndex
504     fileContent += """
505 UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); 
506
507 CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s);
508
509 """%texts
510
511 #-------------------------------------------------------------------------------
512 #                          Write Header File Content
513 #-------------------------------------------------------------------------------
514
515     texts["file_include_name"] = headerfilepath.replace(".", "_").upper()
516     HeaderFileContent = generated_tag + """
517 #ifndef %(file_include_name)s
518 #define %(file_include_name)s
519
520 #include "data.h"
521
522 /* Prototypes of function provided by object dictionnary */
523 UNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value);
524 const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks);
525
526 /* Master node data struct */
527 extern CO_Data %(NodeName)s_Data;
528 """%texts
529     HeaderFileContent += strDeclareHeader
530     
531     HeaderFileContent += "\n#endif // %(file_include_name)s\n"%texts
532     
533     return fileContent,HeaderFileContent
534
535 #-------------------------------------------------------------------------------
536 #                             Main Function
537 #-------------------------------------------------------------------------------
538
539 def GenerateFile(filepath, node):
540     try:
541         headerfilepath = os.path.splitext(filepath)[0]+".h"
542         content, header = GenerateFileContent(node, os.path.split(headerfilepath)[1])
543         WriteFile(filepath, content)
544         WriteFile(headerfilepath, header)
545         return None
546     except ValueError, message:
547         return "Unable to Generate C File\n%s"%message
548