objdictgen/gen_cfile.py
author etisserant
Wed, 18 Apr 2007 13:05:15 +0200
changeset 168 f379cdef1f8e
parent 160 636d875c85dd
child 176 5d57fe1e3a5b
permissions -rw-r--r--
Added install target for MicroMod
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
73
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     3
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     5
#
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     6
#Copyright (C): Edouard TISSERANT and Francis DUPIN
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     7
#
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     8
#See COPYING file for copyrights details.
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
     9
#
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    10
#This library is free software; you can redistribute it and/or
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    12
#License as published by the Free Software Foundation; either
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    14
#
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    15
#This library is distributed in the hope that it will be useful,
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    18
#Lesser General Public License for more details.
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    19
#
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    21
#License along with this library; if not, write to the Free Software
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
from node import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
from types import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
import re, os
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
word_model = re.compile('([a-zA-Z_0-9]*)')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
type_model = re.compile('([\_A-Z]*)([0-9]*)')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
categories = [("SDO_SVR", 0x1200, 0x127F), ("SDO_CLT", 0x1280, 0x12FF),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
              ("PDO_RCV", 0x1400, 0x15FF), ("PDO_RCV_MAP", 0x1600, 0x17FF),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
              ("PDO_TRS", 0x1800, 0x19FF), ("PDO_TRS_MAP", 0x1A00, 0x1BFF)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
index_categories = ["firstIndex", "lastIndex"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
generated_tag = """\n/* File generated by gen_cfile.py. Should not be modified. */\n"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
# Format a string for making a C++ variable
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
def FormatName(name):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
    wordlist = [word for word in word_model.findall(name) if word != '']
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
    result = ''
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
    sep = ''
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
    for word in wordlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
        result += "%s%s"%(sep,word)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
        sep = '_'
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
    return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
# Extract the informations from a given type name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
def GetValidTypeInfos(typename):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
    result = type_model.match(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
    if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
        values = result.groups()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
        if values[0] in ("UNSIGNED", "INTEGER") and eval(values[1]) in [i * 8 for i in xrange(1, 9)]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
            return "UNS%s"%values[1], "", "uint%s"%values[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
        elif values[0] == "REAL" and eval(values[1]) in (32, 64):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
            return "%s%s"%(values[0], values[1]), "", "real%s"%values[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
        elif values[0] == "VISIBLE_STRING":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
            if values[1] == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
                return "UNS8", "[10]", "visible_string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
                return "UNS8", "[%s]"%values[1], "visible_string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
def WriteFile(filepath, content):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
    cfile = open(filepath,"w")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
    cfile.write(content)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
    cfile.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
def GenerateFileContent(Manager, headerfilepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
    global type
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
    texts = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
    texts["maxPDOtransmit"] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
    texts["NodeName"], texts["NodeID"], texts["NodeType"] = Manager.GetCurrentNodeInfos()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
    internal_types = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
    texts["iam_a_slave"] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
    if (texts["NodeType"] == "slave"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
        texts["iam_a_slave"] = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
    # Compiling lists of indexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
    rangelist = [idx for name,idx in Manager.GetCurrentValidIndexes(0, 0x260)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
    listIndex = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1000, 0xFFFF)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
    communicationlist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1000, 0x11FF)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
    sdolist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1200, 0x12FF)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
    pdolist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x1400, 0x1BFF)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
    variablelist = [idx for name,idx in Manager.GetCurrentValidIndexes(0x2000, 0xBFFF)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
#                       Declaration of the value range types
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
#-------------------------------------------------------------------------------    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
    valueRangeContent = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
    strDefine = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
    strSwitch = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
    num = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
    for index in rangelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
        rangename = Manager.GetEntryName(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
        result = range_model.match(rangename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
            num += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
            internal_types[rangename] = "valueRange_%d"%num
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
            typeindex = Manager.GetCurrentEntry(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
            typename = Manager.GetTypeName(typeindex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
            typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
            if typeinfos == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
                raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
            typename = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
            minvalue = str(Manager.GetCurrentEntry(index, 2))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
            maxvalue = str(Manager.GetCurrentEntry(index, 3))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
            strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typename,minvalue,maxvalue)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
            strSwitch += """    case valueRange_%d:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
      if (*(%s*)Value < (%s)%s) return OD_VALUE_TOO_LOW;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
      if (*(%s*)Value > (%s)%s) return OD_VALUE_TOO_HIGH;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
      break;\n"""%(num,typename,typename,minvalue,typename,typename,maxvalue)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
    valueRangeContent += strDefine
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
    valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
    valueRangeContent += "\n  switch (typeValue) {\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
    valueRangeContent += strSwitch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
    valueRangeContent += "  }\n  return 0;\n}\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
#            Creation of the mapped variables and object dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
    mappedVariableContent = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
    strDeclareHeader = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
    strDeclareCallback = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
    indexContents = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
    indexCallbacks = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
    for index in listIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
        texts["index"] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
        strIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
        entry_infos = Manager.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
        values = Manager.GetCurrentEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
        callbacks = Manager.HasCurrentEntryCallbacks(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
        if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
            strIndex += "\n/* index 0x%(index)04X :   Mapped variable %(EntryName)s */\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
            strIndex += "\n/* index 0x%(index)04X :   %(EntryName)s. */\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
        if type(values) == ListType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
            texts["value"] = values[0]
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   145
            strIndex += "                    UNS8 %(NodeName)s_highestSubIndex_obj%(index)04X = %(value)d; /* number of subindex - 1*/\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
        # Entry type is VAR
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
        if type(values) != ListType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
            subentry_infos = Manager.GetSubentryInfos(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
            typename = Manager.GetTypeName(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
            typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
            if typeinfos == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
                raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
            if typename not in internal_types:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
                internal_types[typename] = typeinfos[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
            texts["subIndexType"] = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
            texts["suffixe"] = typeinfos[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
            if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
                texts["value"] = "\"%s\""%values
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   160
                texts["comment"] = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
                texts["value"] = "0x%X"%values
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   163
                texts["comment"] = "\t/* %s */"%str(values)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
            if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
                texts["name"] = FormatName(subentry_infos["name"])
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   166
                strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
                if callbacks:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   168
                    strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   169
                mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
            else:
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   171
                strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;%(comment)s\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
            values = [values]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
            
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
            # Entry type is RECORD
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
            if entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
                subentry_infos = Manager.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
                typename = Manager.GetTypeName(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
                typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
                if typeinfos == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
                    raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
                if typename not in internal_types:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
                    internal_types[typename] = typeinfos[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
                texts["subIndexType"] = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
                texts["suffixe"] = typeinfos[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
                texts["length"] = values[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
                if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
                    texts["name"] = FormatName(entry_infos["name"])
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   189
                    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
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
                    if callbacks:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   191
                        strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   192
                    mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n  {\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
                    for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
                        sep = ","
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   195
                        comment = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
                        if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
                            if subIndex == len(values)-1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
                                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
                            if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
                                value = "\"%s\""%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
                            else:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   202
                                comment = "\t/* %s */"%str(value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
                                value = "0x%X"%value
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   204
                            mappedVariableContent += "    %s%s%s\n"%(value, sep, comment)
28
e169fe15521b *** empty log message ***
lbessard
parents: 5
diff changeset
   205
                    mappedVariableContent += "  };\n"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
                    strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n                    {\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
                    for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
                        sep = ","
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   210
                        comment = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
                        if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
                            if subIndex == len(values)-1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
                                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
                            if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
                                value = "\"%s\""%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
                            else:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   217
                                comment = "\t/* %s */"%str(value)
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   218
                                value = "0x%X"%value
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   219
                            strIndex += "                      %s%s%s\n"%(value, sep, comment)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
                    strIndex += "                    };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
                
66
94212a58c097 gen_cfile.py modified for avoiding possible conflict in mapped variable names
lbessard
parents: 64
diff changeset
   223
                texts["parent"] = FormatName(entry_infos["name"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
                # Entry type is ARRAY
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
                for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
                    texts["subIndex"] = subIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
                    if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
                        subentry_infos = Manager.GetSubentryInfos(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
                        typename = Manager.GetTypeName(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
                        typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
                        if typeinfos == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
                            raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
                        if typename not in internal_types:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
                            internal_types[typename] = typeinfos[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
                        texts["subIndexType"] = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
                        texts["suffixe"] = typeinfos[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
                        if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
                            texts["value"] = "\"%s\""%value
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   239
                            texts["comment"] = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
                            texts["value"] = "0x%X"%value
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   242
                            texts["comment"] = "\t/* %s */"%str(value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
                        texts["name"] = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
                        if index in variablelist:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   245
                            strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   246
                            mappedVariableContent += "%(subIndexType)s %(parent)s_%(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
                        else:
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   248
                            strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;%(comment)s\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
                if callbacks:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   250
                    strDeclareHeader += "extern ODCallback_t %(parent)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
        # Generating Dictionary C++ entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
        if callbacks:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
            if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
                name = FormatName(entry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
                name = "%(NodeName)s_Index%(index)04X"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
            strIndex += "                    ODCallback_t %s_callbacks[] = \n                     {\n"%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
            for subIndex in xrange(len(values)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
                strIndex += "                       NULL,\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
            strIndex += "                     };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
            indexCallbacks[index] = "*callbacks = %s_callbacks; "%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
            indexCallbacks[index] = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
        strIndex += "                    subindex %(NodeName)s_Index%(index)04X[] = \n                     {\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
        for subIndex in xrange(len(values)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
            subentry_infos = Manager.GetSubentryInfos(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
            if subIndex < len(values) - 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
                sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
            typename = Manager.GetTypeName(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
            typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
            if typename.startswith("VISIBLE_STRING"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
                subIndexType = "visible_string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
            elif typename in internal_types:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
                subIndexType = internal_types[typename]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
                subIndexType = typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
            if subIndex == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
                if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
                    name = "%(NodeName)s_highestSubIndex_obj%(index)04X"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
                elif index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
                    name = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
                    name = FormatName("%s_obj%04X"%(texts["NodeName"], texts["index"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
            elif entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
                if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
                    name = "%s[%d]"%(FormatName(entry_infos["name"]), subIndex - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
                    name = "%s_obj%04X[%d]"%(texts["NodeName"], texts["index"], subIndex - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
                if index in variablelist:
70
f36f09f08b62 Bug corrected on gen_cfile
lbessard
parents: 66
diff changeset
   294
                    name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"]))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
                    name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
            if subIndexType == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
                sizeof = name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
                sizeof = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
            params = Manager.GetCurrentParamsEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
            if params["save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
                save = "|TO_BE_SAVE"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
                save = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
            strIndex += "                       { %s%s, %s, sizeof (%s), (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,subIndexType,sizeof,name,sep)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
        strIndex += "                     };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
        indexContents[index] = strIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
#                     Declaration of Particular Parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
    if 0x1006 not in communicationlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
        entry_infos = Manager.GetEntryInfos(0x1006)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
        indexContents[0x1006] = """\n/* index 0x1006 :   %(EntryName)s */
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   318
                    UNS32 %(NodeName)s_obj1006 = 0x0;   /* 0 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
    if 0x1016 in communicationlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
        texts["nombre"] = Manager.GetCurrentEntry(0x1016, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
        texts["nombre"] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
        entry_infos = Manager.GetEntryInfos(0x1016)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
        indexContents[0x1016] = """\n/* index 0x1016 :   %(EntryName)s */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
                    UNS8 %(NodeName)s_highestSubIndex_obj1016 = 0;
91
ed2612282988 - Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents: 76
diff changeset
   329
                    UNS32 %(NodeName)s_obj1016[]={0};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
    if texts["nombre"] > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
        strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(nombre)d] = {TIMER_NONE,};\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
    else:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   334
        strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[1];\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
    if 0x1017 not in communicationlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
        entry_infos = Manager.GetEntryInfos(0x1017)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
        indexContents[0x1017] = """\n/* index 0x1017 :   %(EntryName)s */ 
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   340
                    UNS16 %(NodeName)s_obj1017 = 0x0;   /* 0 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
#               Declaration of navigation in the Object Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
    strDeclareIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
    strDeclareSwitch = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
    strQuickIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
    quick_index = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
    for index_cat in index_categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
        quick_index[index_cat] = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
        for cat, idx_min, idx_max in categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
            quick_index[index_cat][cat] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
    maxPDOtransmit = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
    for i, index in enumerate(listIndex):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
        texts["index"] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
        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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
        strDeclareSwitch += "		case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
        for cat, idx_min, idx_max in categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
            if idx_min <= index <= idx_max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
                quick_index["lastIndex"][cat] = i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
                if quick_index["firstIndex"][cat] == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
                    quick_index["firstIndex"][cat] = i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
                if cat == "PDO_TRS":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
                    maxPDOtransmit += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
    texts["maxPDOtransmit"] = max(1, maxPDOtransmit)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
    for index_cat in index_categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
        strQuickIndex += "\nquick_index %s_%s = {\n"%(texts["NodeName"], index_cat)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
        sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
        for i, (cat, idx_min, idx_max) in enumerate(categories):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
            if i == len(categories) - 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
                sep = ""
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   374
            strQuickIndex += "  %d%s /* %s */\n"%(quick_index[index_cat][cat],sep,cat)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
        strQuickIndex += "};\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
#                            Write File Content
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
73
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
   381
    fileContent = generated_tag + """
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
#include "%s"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
"""%(headerfilepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
/* Declaration of the mapped variables                                    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
""" + mappedVariableContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
/* Declaration of the value range types                                   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
""" + valueRangeContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
/* The node id                                                            */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
/* node_id default value.*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   404
/**************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
/* Array of message processing information */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
    fileContent += strTimers
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
    fileContent += """
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   413
/*
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   414
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   415
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   416
                               OBJECT DICTIONARY
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   417
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   418
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   419
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
    contentlist = indexContents.keys()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
    contentlist.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
    for index in contentlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
        fileContent += indexContents[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
const indextable %(NodeName)s_objdict[] = 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
    fileContent += strDeclareIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
    fileContent += """};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
	int i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
	*callbacks = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
	switch(wIndex){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
    fileContent += strDeclareSwitch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
    fileContent += """		default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
			*errorCode = OD_NO_SUCH_OBJECT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
			return NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
	*errorCode = OD_SUCCESSFUL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
	return &%(NodeName)s_objdict[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   448
/* To count at which received SYNC a PDO must be sent.
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   449
 * Even if no pdoTransmit are defined, at least one entry is computed
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   450
 * for compilations issues.
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   451
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
UNS8 %(NodeName)s_count_sync[%(maxPDOtransmit)d] = {0,};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
    fileContent += strQuickIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
#                          Write Header File Content
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
73
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
   466
    HeaderFileContent = generated_tag + """
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
#include "data.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   469
/* Prototypes of function provided by object dictionnary */
63
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 60
diff changeset
   470
UNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value);
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 60
diff changeset
   471
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks);
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 60
diff changeset
   472
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   473
/* Master node data struct */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
extern CO_Data %(NodeName)s_Data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
    HeaderFileContent += strDeclareHeader
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
    return fileContent,HeaderFileContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
#                             Main Function
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
def GenerateFile(filepath, manager):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
    headerfilepath = os.path.splitext(filepath)[0]+".h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
    content, header = GenerateFileContent(manager, os.path.split(headerfilepath)[1])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
    WriteFile(filepath, content)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
    WriteFile(headerfilepath, header)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
    return True