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