etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- lbessard@73: lbessard@73: #This file is part of CanFestival, a library implementing CanOpen Stack. lbessard@73: # lbessard@73: #Copyright (C): Edouard TISSERANT and Francis DUPIN lbessard@73: # lbessard@73: #See COPYING file for copyrights details. lbessard@73: # lbessard@73: #This library is free software; you can redistribute it and/or lbessard@73: #modify it under the terms of the GNU Lesser General Public lbessard@73: #License as published by the Free Software Foundation; either lbessard@73: #version 2.1 of the License, or (at your option) any later version. lbessard@73: # lbessard@73: #This library is distributed in the hope that it will be useful, lbessard@73: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@73: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@73: #Lesser General Public License for more details. lbessard@73: # lbessard@73: #You should have received a copy of the GNU Lesser General Public lbessard@73: #License along with this library; if not, write to the Free Software lbessard@73: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: from node import * etisserant@0: from types import * etisserant@0: etisserant@0: import re, os etisserant@0: etisserant@0: word_model = re.compile('([a-zA-Z_0-9]*)') etisserant@0: type_model = re.compile('([\_A-Z]*)([0-9]*)') etisserant@0: range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]') etisserant@0: etisserant@0: categories = [("SDO_SVR", 0x1200, 0x127F), ("SDO_CLT", 0x1280, 0x12FF), etisserant@0: ("PDO_RCV", 0x1400, 0x15FF), ("PDO_RCV_MAP", 0x1600, 0x17FF), etisserant@0: ("PDO_TRS", 0x1800, 0x19FF), ("PDO_TRS_MAP", 0x1A00, 0x1BFF)] etisserant@0: index_categories = ["firstIndex", "lastIndex"] etisserant@0: etisserant@0: generated_tag = """\n/* File generated by gen_cfile.py. Should not be modified. */\n""" etisserant@0: lbessard@188: internal_types = {} lbessard@188: etisserant@0: # Format a string for making a C++ variable etisserant@0: def FormatName(name): etisserant@0: wordlist = [word for word in word_model.findall(name) if word != ''] lbessard@227: return "_".join(wordlist) etisserant@0: etisserant@0: # Extract the informations from a given type name etisserant@0: def GetValidTypeInfos(typename): lbessard@188: if typename in internal_types: lbessard@188: return internal_types[typename] lbessard@188: else: lbessard@188: result = type_model.match(typename) lbessard@188: if result: lbessard@188: values = result.groups() lbessard@188: if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]: lbessard@188: typeinfos = ("UNS%s"%values[1], "", "uint%s"%values[1]) lbessard@188: elif values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]: lbessard@188: typeinfos = ("INTEGER%s"%values[1], "", "int%s"%values[1]) lbessard@188: elif values[0] == "REAL" and int(values[1]) in (32, 64): lbessard@188: typeinfos = ("%s%s"%(values[0], values[1]), "", "real%s"%values[1]) lbessard@188: elif values[0] == "VISIBLE_STRING": lbessard@188: if values[1] == "": lbessard@188: typeinfos = ("UNS8", "[10]", "visible_string") lbessard@188: else: lbessard@188: typeinfos = ("UNS8", "[%s]"%values[1], "visible_string") lbessard@188: elif values[0] == "DOMAIN": lbessard@188: typeinfos = ("UNS8*", "", "domain") lbessard@188: elif values[0] == "BOOLEAN": lbessard@188: typeinfos = ("UNS8", "", "boolean") lbessard@188: else: lbessard@188: raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename lbessard@188: internal_types[typename] = typeinfos lbessard@188: else: lbessard@188: raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename lbessard@188: return typeinfos etisserant@0: etisserant@0: def WriteFile(filepath, content): etisserant@0: cfile = open(filepath,"w") etisserant@0: cfile.write(content) etisserant@0: cfile.close() etisserant@0: lbessard@245: def GenerateFileContent(Node, headerfilepath): etisserant@0: global type lbessard@188: global internal_types etisserant@0: texts = {} etisserant@0: texts["maxPDOtransmit"] = 0 lbessard@245: texts["NodeName"] = Node.GetNodeName() lbessard@245: texts["NodeID"] = Node.GetNodeID() lbessard@245: texts["NodeType"] = Node.GetNodeType() lbessard@245: texts["Description"] = Node.GetNodeDescription() etisserant@0: texts["iam_a_slave"] = 0 etisserant@0: if (texts["NodeType"] == "slave"): etisserant@0: texts["iam_a_slave"] = 1 etisserant@0: etisserant@0: # Compiling lists of indexes lbessard@245: rangelist = [idx for idx in Node.GetIndexes() if 0 <= idx <= 0x260] lbessard@245: listIndex = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0xFFFF] lbessard@245: communicationlist = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0x11FF] lbessard@245: sdolist = [idx for idx in Node.GetIndexes() if 0x1200 <= idx <= 0x12FF] lbessard@245: pdolist = [idx for idx in Node.GetIndexes() if 0x1400 <= idx <= 0x1BFF] lbessard@245: variablelist = [idx for idx in Node.GetIndexes() if 0x2000 <= idx <= 0xBFFF] etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Declaration of the value range types etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: valueRangeContent = "" etisserant@0: strDefine = "" etisserant@0: strSwitch = "" etisserant@0: num = 0 etisserant@0: for index in rangelist: lbessard@245: rangename = Node.GetEntryName(index) etisserant@0: result = range_model.match(rangename) etisserant@0: if result: etisserant@0: num += 1 lbessard@245: typeindex = Node.GetEntry(index, 1) lbessard@245: typename = Node.GetTypeName(typeindex) etisserant@0: typeinfos = GetValidTypeInfos(typename) lbessard@188: internal_types[rangename] = (typeinfos[0], typeinfos[1], "valueRange_%d"%num) lbessard@245: minvalue = str(Node.GetEntry(index, 2)) lbessard@245: maxvalue = str(Node.GetEntry(index, 3)) lbessard@188: strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typeinfos[0],minvalue,maxvalue) etisserant@0: strSwitch += """ case valueRange_%d: etisserant@0: if (*(%s*)Value < (%s)%s) return OD_VALUE_TOO_LOW; etisserant@0: if (*(%s*)Value > (%s)%s) return OD_VALUE_TOO_HIGH; lbessard@188: break;\n"""%(num,typeinfos[0],typeinfos[0],minvalue,typeinfos[0],typeinfos[0],maxvalue) etisserant@0: etisserant@0: valueRangeContent += strDefine etisserant@0: valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts etisserant@0: valueRangeContent += "\n switch (typeValue) {\n" etisserant@0: valueRangeContent += strSwitch etisserant@0: valueRangeContent += " }\n return 0;\n}\n" etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Creation of the mapped variables and object dictionary etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: mappedVariableContent = "" etisserant@0: strDeclareHeader = "" etisserant@0: strDeclareCallback = "" etisserant@0: indexContents = {} etisserant@0: indexCallbacks = {} etisserant@0: for index in listIndex: etisserant@0: texts["index"] = index etisserant@0: strIndex = "" lbessard@245: entry_infos = Node.GetEntryInfos(index) etisserant@229: texts["EntryName"] = entry_infos["name"].encode('ascii','replace') lbessard@245: values = Node.GetEntry(index) lbessard@245: callbacks = Node.HasEntryCallbacks(index) etisserant@0: if index in variablelist: etisserant@0: strIndex += "\n/* index 0x%(index)04X : Mapped variable %(EntryName)s */\n"%texts etisserant@0: else: etisserant@0: strIndex += "\n/* index 0x%(index)04X : %(EntryName)s. */\n"%texts etisserant@0: etisserant@0: # Entry type is VAR etisserant@0: if type(values) != ListType: lbessard@245: subentry_infos = Node.GetSubentryInfos(index, 0) lbessard@245: typename = Node.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: texts["subIndexType"] = typeinfos[0] etisserant@0: texts["suffixe"] = typeinfos[1] etisserant@0: if typeinfos[2] == "visible_string": etisserant@0: texts["value"] = "\"%s\""%values lbessard@5: texts["comment"] = "" lbessard@223: elif typeinfos[2] == "domain": lbessard@223: texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) lbessard@223: texts["comment"] = "" etisserant@0: else: etisserant@0: texts["value"] = "0x%X"%values frdupin@76: texts["comment"] = "\t/* %s */"%str(values) etisserant@0: if index in variablelist: etisserant@0: texts["name"] = FormatName(subentry_infos["name"]) frdupin@76: strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts etisserant@0: if callbacks: frdupin@76: strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts frdupin@76: mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts etisserant@0: else: lbessard@5: strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;%(comment)s\n"%texts etisserant@0: values = [values] etisserant@0: else: lbessard@245: subentry_infos = Node.GetSubentryInfos(index, 0) lbessard@245: typename = Node.GetTypeName(subentry_infos["type"]) lbessard@188: typeinfos = GetValidTypeInfos(typename) lbessard@188: texts["value"] = values[0] lbessard@188: texts["subIndexType"] = typeinfos[0] lbessard@188: strIndex += " %(subIndexType)s %(NodeName)s_highestSubIndex_obj%(index)04X = %(value)d; /* number of subindex - 1*/\n"%texts etisserant@0: etisserant@0: # Entry type is RECORD etisserant@0: if entry_infos["struct"] & OD_IdenticalSubindexes: lbessard@245: subentry_infos = Node.GetSubentryInfos(index, 1) lbessard@245: typename = Node.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: texts["subIndexType"] = typeinfos[0] etisserant@0: texts["suffixe"] = typeinfos[1] etisserant@0: texts["length"] = values[0] etisserant@0: if index in variablelist: etisserant@0: texts["name"] = FormatName(entry_infos["name"]) frdupin@76: 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 etisserant@0: if callbacks: frdupin@76: strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts frdupin@76: mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n {\n"%texts etisserant@0: for subIndex, value in enumerate(values): etisserant@0: sep = "," lbessard@5: comment = "" etisserant@0: if subIndex > 0: etisserant@0: if subIndex == len(values)-1: etisserant@0: sep = "" etisserant@0: if typeinfos[2] == "visible_string": etisserant@0: value = "\"%s\""%value lbessard@223: elif typeinfos[2] == "domain": lbessard@223: value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) lbessard@227: else: frdupin@76: comment = "\t/* %s */"%str(value) etisserant@0: value = "0x%X"%value lbessard@5: mappedVariableContent += " %s%s%s\n"%(value, sep, comment) lbessard@28: mappedVariableContent += " };\n" etisserant@0: else: etisserant@0: strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n {\n"%texts etisserant@0: for subIndex, value in enumerate(values): etisserant@0: sep = "," lbessard@5: comment = "" etisserant@0: if subIndex > 0: etisserant@0: if subIndex == len(values)-1: etisserant@0: sep = "" etisserant@0: if typeinfos[2] == "visible_string": etisserant@0: value = "\"%s\""%value lbessard@182: elif typeinfos[2] == "domain": greg@176: value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) etisserant@0: else: frdupin@76: comment = "\t/* %s */"%str(value) lbessard@5: value = "0x%X"%value lbessard@5: strIndex += " %s%s%s\n"%(value, sep, comment) etisserant@0: strIndex += " };\n" etisserant@0: else: etisserant@0: lbessard@66: texts["parent"] = FormatName(entry_infos["name"]) etisserant@0: # Entry type is ARRAY etisserant@0: for subIndex, value in enumerate(values): etisserant@0: texts["subIndex"] = subIndex etisserant@0: if subIndex > 0: lbessard@245: subentry_infos = Node.GetSubentryInfos(index, subIndex) lbessard@245: typename = Node.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: texts["subIndexType"] = typeinfos[0] etisserant@0: texts["suffixe"] = typeinfos[1] etisserant@0: if typeinfos[2] == "visible_string": etisserant@0: texts["value"] = "\"%s\""%value lbessard@5: texts["comment"] = "" lbessard@223: elif typeinfos[2] == "domain": lbessard@223: texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) lbessard@223: texts["comment"] = "" lbessard@227: else: etisserant@0: texts["value"] = "0x%X"%value frdupin@76: texts["comment"] = "\t/* %s */"%str(value) etisserant@0: texts["name"] = FormatName(subentry_infos["name"]) etisserant@0: if index in variablelist: frdupin@76: strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts frdupin@76: 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 etisserant@0: else: lbessard@5: strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;%(comment)s\n"%texts etisserant@0: if callbacks: frdupin@76: strDeclareHeader += "extern ODCallback_t %(parent)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts etisserant@0: etisserant@0: # Generating Dictionary C++ entry etisserant@0: if callbacks: etisserant@0: if index in variablelist: etisserant@0: name = FormatName(entry_infos["name"]) etisserant@0: else: etisserant@0: name = "%(NodeName)s_Index%(index)04X"%texts etisserant@0: strIndex += " ODCallback_t %s_callbacks[] = \n {\n"%name etisserant@0: for subIndex in xrange(len(values)): etisserant@0: strIndex += " NULL,\n" etisserant@0: strIndex += " };\n" etisserant@0: indexCallbacks[index] = "*callbacks = %s_callbacks; "%name etisserant@0: else: etisserant@0: indexCallbacks[index] = "" etisserant@0: strIndex += " subindex %(NodeName)s_Index%(index)04X[] = \n {\n"%texts etisserant@0: for subIndex in xrange(len(values)): lbessard@245: subentry_infos = Node.GetSubentryInfos(index, subIndex) etisserant@0: if subIndex < len(values) - 1: etisserant@0: sep = "," etisserant@0: else: etisserant@0: sep = "" lbessard@245: typename = Node.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: if subIndex == 0: etisserant@0: if entry_infos["struct"] & OD_MultipleSubindexes: etisserant@0: name = "%(NodeName)s_highestSubIndex_obj%(index)04X"%texts etisserant@0: elif index in variablelist: etisserant@0: name = FormatName(subentry_infos["name"]) etisserant@0: else: etisserant@0: name = FormatName("%s_obj%04X"%(texts["NodeName"], texts["index"])) etisserant@0: elif entry_infos["struct"] & OD_IdenticalSubindexes: etisserant@0: if index in variablelist: etisserant@0: name = "%s[%d]"%(FormatName(entry_infos["name"]), subIndex - 1) etisserant@0: else: etisserant@0: name = "%s_obj%04X[%d]"%(texts["NodeName"], texts["index"], subIndex - 1) etisserant@0: else: etisserant@0: if index in variablelist: lbessard@70: name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"])) etisserant@0: else: etisserant@0: name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"])) lbessard@188: if typeinfos[2] in ["visible_string", "domain"]: greg@176: sizeof = str(len(values[subIndex])) greg@176: else: greg@176: sizeof = "sizeof (%s)"%typeinfos[0] lbessard@245: params = Node.GetParamsEntry(index, subIndex) etisserant@0: if params["save"]: etisserant@0: save = "|TO_BE_SAVE" etisserant@0: else: etisserant@0: save = "" lbessard@188: strIndex += " { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,name,sep) etisserant@0: strIndex += " };\n" etisserant@0: indexContents[index] = strIndex etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Declaration of Particular Parameters etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@261: if 0x1005 not in communicationlist: etisserant@261: entry_infos = Node.GetEntryInfos(0x1005) etisserant@261: texts["EntryName"] = entry_infos["name"] etisserant@261: indexContents[0x1005] = """\n/* index 0x1005 : %(EntryName)s */ etisserant@261: UNS32 %(NodeName)s_obj1005 = 0x0; /* 0 */ etisserant@261: """%texts etisserant@261: etisserant@0: if 0x1006 not in communicationlist: lbessard@245: entry_infos = Node.GetEntryInfos(0x1006) etisserant@0: texts["EntryName"] = entry_infos["name"] etisserant@0: indexContents[0x1006] = """\n/* index 0x1006 : %(EntryName)s */ frdupin@76: UNS32 %(NodeName)s_obj1006 = 0x0; /* 0 */ etisserant@0: """%texts etisserant@0: etisserant@0: if 0x1016 in communicationlist: lbessard@245: texts["nombre"] = Node.GetEntry(0x1016, 0) etisserant@0: else: etisserant@0: texts["nombre"] = 0 lbessard@245: entry_infos = Node.GetEntryInfos(0x1016) etisserant@0: texts["EntryName"] = entry_infos["name"] etisserant@0: indexContents[0x1016] = """\n/* index 0x1016 : %(EntryName)s */ etisserant@0: UNS8 %(NodeName)s_highestSubIndex_obj1016 = 0; etisserant@91: UNS32 %(NodeName)s_obj1016[]={0}; etisserant@0: """%texts etisserant@0: if texts["nombre"] > 0: etisserant@0: strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(nombre)d] = {TIMER_NONE,};\n"%texts etisserant@0: else: frdupin@76: strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[1];\n"%texts etisserant@0: etisserant@0: if 0x1017 not in communicationlist: lbessard@245: entry_infos = Node.GetEntryInfos(0x1017) etisserant@0: texts["EntryName"] = entry_infos["name"] etisserant@0: indexContents[0x1017] = """\n/* index 0x1017 : %(EntryName)s */ frdupin@76: UNS16 %(NodeName)s_obj1017 = 0x0; /* 0 */ etisserant@0: """%texts etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Declaration of navigation in the Object Dictionary etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: strDeclareIndex = "" etisserant@0: strDeclareSwitch = "" etisserant@0: strQuickIndex = "" etisserant@0: quick_index = {} etisserant@0: for index_cat in index_categories: etisserant@0: quick_index[index_cat] = {} etisserant@0: for cat, idx_min, idx_max in categories: etisserant@0: quick_index[index_cat][cat] = 0 etisserant@0: maxPDOtransmit = 0 etisserant@0: for i, index in enumerate(listIndex): etisserant@0: texts["index"] = index etisserant@0: 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 etisserant@0: strDeclareSwitch += " case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index]) etisserant@0: for cat, idx_min, idx_max in categories: etisserant@0: if idx_min <= index <= idx_max: etisserant@0: quick_index["lastIndex"][cat] = i etisserant@0: if quick_index["firstIndex"][cat] == 0: etisserant@0: quick_index["firstIndex"][cat] = i etisserant@0: if cat == "PDO_TRS": etisserant@0: maxPDOtransmit += 1 etisserant@0: texts["maxPDOtransmit"] = max(1, maxPDOtransmit) etisserant@0: for index_cat in index_categories: etisserant@0: strQuickIndex += "\nquick_index %s_%s = {\n"%(texts["NodeName"], index_cat) etisserant@0: sep = "," etisserant@0: for i, (cat, idx_min, idx_max) in enumerate(categories): etisserant@0: if i == len(categories) - 1: etisserant@0: sep = "" frdupin@76: strQuickIndex += " %d%s /* %s */\n"%(quick_index[index_cat][cat],sep,cat) etisserant@0: strQuickIndex += "};\n" etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Write File Content etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@73: fileContent = generated_tag + """ etisserant@0: #include "%s" etisserant@0: """%(headerfilepath) etisserant@0: etisserant@0: fileContent += """ etisserant@0: /**************************************************************************/ etisserant@0: /* Declaration of the mapped variables */ etisserant@0: /**************************************************************************/ etisserant@0: """ + mappedVariableContent etisserant@0: etisserant@0: fileContent += """ etisserant@0: /**************************************************************************/ etisserant@0: /* Declaration of the value range types */ etisserant@0: /**************************************************************************/ etisserant@0: """ + valueRangeContent etisserant@0: etisserant@0: fileContent += """ etisserant@0: /**************************************************************************/ etisserant@0: /* The node id */ etisserant@0: /**************************************************************************/ etisserant@0: /* node_id default value.*/ etisserant@0: UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X; etisserant@0: frdupin@76: /**************************************************************************/ etisserant@0: /* Array of message processing information */ etisserant@0: etisserant@0: const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d; etisserant@0: etisserant@0: """%texts etisserant@0: fileContent += strTimers etisserant@0: etisserant@0: fileContent += """ frdupin@76: /* frdupin@76: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ frdupin@76: frdupin@76: OBJECT DICTIONARY frdupin@76: frdupin@76: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ frdupin@76: */ etisserant@0: """%texts etisserant@0: contentlist = indexContents.keys() etisserant@0: contentlist.sort() etisserant@0: for index in contentlist: etisserant@0: fileContent += indexContents[index] etisserant@0: etisserant@0: fileContent += """ etisserant@0: const indextable %(NodeName)s_objdict[] = etisserant@0: { etisserant@0: """%texts etisserant@0: fileContent += strDeclareIndex etisserant@0: fileContent += """}; etisserant@0: etisserant@0: const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks) etisserant@0: { etisserant@0: int i; etisserant@0: *callbacks = NULL; etisserant@0: switch(wIndex){ etisserant@0: """%texts etisserant@0: fileContent += strDeclareSwitch etisserant@0: fileContent += """ default: etisserant@0: *errorCode = OD_NO_SUCH_OBJECT; etisserant@0: return NULL; etisserant@0: } etisserant@0: *errorCode = OD_SUCCESSFUL; etisserant@0: return &%(NodeName)s_objdict[i]; etisserant@0: } etisserant@0: etisserant@235: /* etisserant@235: * To count at which received SYNC a PDO must be sent. frdupin@76: * Even if no pdoTransmit are defined, at least one entry is computed frdupin@76: * for compilations issues. frdupin@76: */ etisserant@235: s_PDO_status %(NodeName)s_PDO_status[%(maxPDOtransmit)d] = {"""%texts etisserant@235: etisserant@235: fileContent += ",".join(["s_PDO_staus_Initializer"]*texts["maxPDOtransmit"]) + """}; etisserant@235: """ etisserant@235: etisserant@0: fileContent += strQuickIndex etisserant@0: fileContent += """ etisserant@0: UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); etisserant@0: etisserant@0: CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s); etisserant@0: etisserant@0: """%texts etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Write Header File Content etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@223: texts["file_include_name"] = headerfilepath.replace(".", "_").upper() lbessard@73: HeaderFileContent = generated_tag + """ lbessard@224: #ifndef %(file_include_name)s lbessard@223: #define %(file_include_name)s lbessard@223: etisserant@0: #include "data.h" etisserant@0: frdupin@76: /* Prototypes of function provided by object dictionnary */ lbessard@63: UNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value); lbessard@63: const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks); lbessard@63: frdupin@76: /* Master node data struct */ etisserant@0: extern CO_Data %(NodeName)s_Data; etisserant@0: """%texts etisserant@0: HeaderFileContent += strDeclareHeader etisserant@0: lbessard@223: HeaderFileContent += "\n#endif // %(file_include_name)s\n"%texts lbessard@223: etisserant@0: return fileContent,HeaderFileContent etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Main Function etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@245: def GenerateFile(filepath, node): lbessard@188: try: lbessard@188: headerfilepath = os.path.splitext(filepath)[0]+".h" lbessard@245: content, header = GenerateFileContent(node, os.path.split(headerfilepath)[1]) lbessard@188: WriteFile(filepath, content) lbessard@188: WriteFile(headerfilepath, header) lbessard@188: return None lbessard@188: except ValueError, message: lbessard@188: return "Unable to Generate C File\n%s"%message lbessard@188: