etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: copyright_notice="""/* etisserant@0: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: etisserant@0: Copyright (C): Edouard TISSERANT and Francis DUPIN etisserant@0: etisserant@0: See COPYING file for copyrights details. etisserant@0: etisserant@0: This library is free software; you can redistribute it and/or etisserant@0: modify it under the terms of the GNU Lesser General Public etisserant@0: License as published by the Free Software Foundation; either etisserant@0: version 2.1 of the License, or (at your option) any later version. etisserant@0: etisserant@0: This library is distributed in the hope that it will be useful, etisserant@0: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: Lesser General Public License for more details. etisserant@0: etisserant@0: You should have received a copy of the GNU Lesser General Public etisserant@0: License along with this library; if not, write to the Free Software etisserant@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: */ etisserant@0: """ 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] etisserant@0: 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 etisserant@0: else: etisserant@0: texts["value"] = "0x%X"%values etisserant@0: if index in variablelist: etisserant@0: texts["name"] = FormatName(subentry_infos["name"]) etisserant@0: strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x00\n"%texts etisserant@0: if callbacks: etisserant@0: strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts etisserant@0: mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x00\n"%texts etisserant@0: else: etisserant@0: strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)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"]) etisserant@0: strDeclareHeader += "%(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: etisserant@0: strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t// Callbacks of index0x%(index)04X\n"%texts etisserant@0: 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 = "," 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: etisserant@0: value = "0x%X"%value etisserant@0: mappedVariableContent += " %s%s\n"%(value, sep) etisserant@0: 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 = "," 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: etisserant@0: value = str(value) etisserant@0: strIndex += " %s%s\n"%(value, sep) etisserant@0: strIndex += " };\n" etisserant@0: else: etisserant@0: 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 etisserant@0: else: etisserant@0: texts["value"] = "0x%X"%value etisserant@0: texts["name"] = FormatName(subentry_infos["name"]) etisserant@0: if index in variablelist: etisserant@0: strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X\n"%texts etisserant@0: mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X\n"%texts etisserant@0: else: etisserant@0: strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;\n"%texts etisserant@0: if callbacks: etisserant@0: texts["name"] = FormatName(entry_infos["name"]) etisserant@0: strDeclareHeader += "extern ODCallback_t %(name)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: etisserant@0: name = FormatName(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 */ etisserant@0: UNS32 %(NodeName)s_obj1006 = 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; etisserant@0: UNS32 %(NodeName)s_obj1016[0]; etisserant@0: subindex %(NodeName)s_Index1016[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: etisserant@0: strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[0];\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 */ etisserant@0: UNS16 %(NodeName)s_obj1017 = 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 = "" etisserant@0: strQuickIndex += " %s : %d%s\n"%(cat, quick_index[index_cat][cat], sep) etisserant@0: strQuickIndex += "};\n" etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Write File Content etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: fileContent = copyright_notice + 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: etisserant@0: //*****************************************************************************/ 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 += """ etisserant@0: //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ etisserant@0: // etisserant@0: // OBJECT DICTIONARY etisserant@0: // etisserant@0: //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 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@0: // To count at which received SYNC a PDO must be sent. etisserant@0: // Even if no pdoTransmit are defined, at least one entry is computed etisserant@0: // for compilations issues. 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: etisserant@0: HeaderFileContent = copyright_notice + generated_tag + """ etisserant@0: #include "data.h" etisserant@0: etisserant@0: // 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: etisserant@0: void %(NodeName)s_initialisation(); etisserant@0: void %(NodeName)s_preOperational(); etisserant@0: void %(NodeName)s_operational(); etisserant@0: void %(NodeName)s_stopped(); etisserant@0: etisserant@0: void %(NodeName)s_post_sync(); etisserant@0: void %(NodeName)s_post_TPDO(); etisserant@0: etisserant@0: // 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