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: 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 != ''] etisserant@0: result = '' etisserant@0: sep = '' etisserant@0: for word in wordlist: etisserant@0: result += "%s%s"%(sep,word) etisserant@0: sep = '_' etisserant@0: return result etisserant@0: etisserant@0: # Extract the informations from a given type name etisserant@0: def GetValidTypeInfos(typename): etisserant@0: result = type_model.match(typename) etisserant@0: if result: etisserant@0: values = result.groups() etisserant@0: if values[0] in ("UNSIGNED", "INTEGER") and eval(values[1]) in [i * 8 for i in xrange(1, 9)]: etisserant@0: return "UNS%s"%values[1], "", "uint%s"%values[1] etisserant@0: elif values[0] == "REAL" and eval(values[1]) in (32, 64): etisserant@0: return "%s%s"%(values[0], values[1]), "", "real%s"%values[1] etisserant@0: elif values[0] == "VISIBLE_STRING": etisserant@0: if values[1] == "": etisserant@0: return "UNS8", "[10]", "visible_string" etisserant@0: else: etisserant@0: return "UNS8", "[%s]"%values[1], "visible_string" etisserant@0: return None 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: etisserant@0: def GenerateFileContent(Manager, headerfilepath): etisserant@0: global type etisserant@0: texts = {} etisserant@0: texts["maxPDOtransmit"] = 0 etisserant@0: texts["NodeName"], texts["NodeID"], texts["NodeType"] = Manager.GetCurrentNodeInfos() etisserant@0: internal_types = {} 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 etisserant@0: rangelist = [idx for name,idx in Manager.GetCurrentValidIndexes(0, 0x260)] etisserant@0: listIndex = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1000, 0xFFFF)] etisserant@0: communicationlist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1000, 0x11FF)] etisserant@0: sdolist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1200, 0x12FF)] etisserant@0: pdolist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1400, 0x1BFF)] etisserant@0: variablelist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x2000, 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: etisserant@0: rangename = Manager.GetEntryName(index) etisserant@0: result = range_model.match(rangename) etisserant@0: if result: etisserant@0: num += 1 etisserant@0: internal_types[rangename] = "valueRange_%d"%num etisserant@0: typeindex = Manager.GetCurrentEntry(index, 1) etisserant@0: typename = Manager.GetTypeName(typeindex) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: if typeinfos == None: etisserant@0: raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename etisserant@0: typename = typeinfos[0] etisserant@0: minvalue = str(Manager.GetCurrentEntry(index, 2)) etisserant@0: maxvalue = str(Manager.GetCurrentEntry(index, 3)) etisserant@0: strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typename,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; etisserant@0: break;\n"""%(num,typename,typename,minvalue,typename,typename,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 = "" etisserant@0: entry_infos = Manager.GetEntryInfos(index) etisserant@0: texts["EntryName"] = entry_infos["name"] etisserant@0: values = Manager.GetCurrentEntry(index) etisserant@0: callbacks = Manager.HasCurrentEntryCallbacks(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: if type(values) == ListType: etisserant@0: texts["value"] = values[0] frdupin@76: strIndex += " UNS8 %(NodeName)s_highestSubIndex_obj%(index)04X = %(value)d; /* number of subindex - 1*/\n"%texts etisserant@0: etisserant@0: # Entry type is VAR etisserant@0: if type(values) != ListType: etisserant@0: subentry_infos = Manager.GetSubentryInfos(index, 0) etisserant@0: typename = Manager.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: if typeinfos == None: etisserant@0: raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename etisserant@0: if typename not in internal_types: etisserant@0: internal_types[typename] = typeinfos[2] 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"] = "" 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: etisserant@0: etisserant@0: # Entry type is RECORD etisserant@0: if entry_infos["struct"] & OD_IdenticalSubindexes: etisserant@0: subentry_infos = Manager.GetSubentryInfos(index, 1) etisserant@0: typename = Manager.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: if typeinfos == None: etisserant@0: raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename etisserant@0: if typename not in internal_types: etisserant@0: internal_types[typename] = typeinfos[2] 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 etisserant@0: 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 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: etisserant@0: subentry_infos = Manager.GetSubentryInfos(index, subIndex) etisserant@0: typename = Manager.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: if typeinfos == None: etisserant@0: raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename etisserant@0: if typename not in internal_types: etisserant@0: internal_types[typename] = typeinfos[2] 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"] = "" etisserant@0: 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)): etisserant@0: subentry_infos = Manager.GetSubentryInfos(index, subIndex) etisserant@0: if subIndex < len(values) - 1: etisserant@0: sep = "," etisserant@0: else: etisserant@0: sep = "" etisserant@0: typename = Manager.GetTypeName(subentry_infos["type"]) etisserant@0: typeinfos = GetValidTypeInfos(typename) etisserant@0: if typename.startswith("VISIBLE_STRING"): etisserant@0: subIndexType = "visible_string" etisserant@0: elif typename in internal_types: etisserant@0: subIndexType = internal_types[typename] etisserant@0: else: etisserant@0: subIndexType = 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"])) etisserant@0: if subIndexType == "visible_string": etisserant@0: sizeof = name etisserant@0: else: etisserant@0: sizeof = typeinfos[0] etisserant@0: params = Manager.GetCurrentParamsEntry(index, subIndex) etisserant@0: if params["save"]: etisserant@0: save = "|TO_BE_SAVE" etisserant@0: else: etisserant@0: save = "" etisserant@0: strIndex += " { %s%s, %s, sizeof (%s), (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,subIndexType,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@0: if 0x1006 not in communicationlist: etisserant@0: entry_infos = Manager.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: etisserant@0: texts["nombre"] = Manager.GetCurrentEntry(0x1016, 0) etisserant@0: else: etisserant@0: texts["nombre"] = 0 etisserant@0: entry_infos = Manager.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; lbessard@73: UNS32 %(NodeName)s_obj1016[]; lbessard@73: subindex %(NodeName)s_Index1016[]; 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: etisserant@0: entry_infos = Manager.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: frdupin@76: /* 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@0: UNS8 %(NodeName)s_count_sync[%(maxPDOtransmit)d] = {0,}; etisserant@0: """%texts 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@73: HeaderFileContent = generated_tag + """ 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: /* prototypes of function to be filled by app. */ etisserant@0: void %(NodeName)s_SDOtimeoutError(UNS8 line); etisserant@0: void %(NodeName)s_heartbeatError(UNS8); etisserant@0: etisserant@0: UNS8 %(NodeName)s_canSend(Message *); etisserant@0: frdupin@60: void %(NodeName)s_initialisation(void); frdupin@60: void %(NodeName)s_preOperational(void); frdupin@60: void %(NodeName)s_operational(void); frdupin@60: void %(NodeName)s_stopped(void); frdupin@60: frdupin@60: void %(NodeName)s_post_sync(void); frdupin@60: void %(NodeName)s_post_TPDO(void); etisserant@0: frdupin@76: /* Master node data struct */ etisserant@0: extern CO_Data %(NodeName)s_Data; etisserant@0: etisserant@0: """%texts etisserant@0: HeaderFileContent += strDeclareHeader etisserant@0: etisserant@0: return fileContent,HeaderFileContent etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Main Function etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def GenerateFile(filepath, manager): etisserant@0: headerfilepath = os.path.splitext(filepath)[0]+".h" etisserant@0: content, header = GenerateFileContent(manager, os.path.split(headerfilepath)[1]) etisserant@0: WriteFile(filepath, content) etisserant@0: WriteFile(headerfilepath, header) etisserant@0: return True