objdictgen/gen_cfile.py
author etisserant
Wed, 10 May 2006 21:05:57 +0200
changeset 1 b3dc740b4b04
parent 0 4472ee7c6c3e
child 5 e4365e7d47f0
permissions -rw-r--r--
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
                texts["value"] = "0x%X"%values
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"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
                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
   167
                if callbacks:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
                    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
   169
                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
   170
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
                strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X%(suffixe)s = %(value)s;\n"%texts
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"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
                    strDeclareHeader += "%(subIndexType)s %(name)s[%(length)d]%(suffixe)s;\t\t// Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
                    if callbacks:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
                        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
   192
                    mappedVariableContent = "%(subIndexType)s %(name)s[] =\t\t// Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X\n  {\n"%texts
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 = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
                        if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
                            if subIndex == len(values)-1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
                                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
                            if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
                                value = "\"%s\""%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
                                value = "0x%X"%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
                            mappedVariableContent += "    %s%s\n"%(value, sep)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
                    mappedVariableContent += "  }\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
                    strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n                    {\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
                    for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
                        sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
                        if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
                            if subIndex == len(values)-1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
                                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
                            if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
                                value = "\"%s\""%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
                                value = str(value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
                            strIndex += "                      %s%s\n"%(value, sep)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
                    strIndex += "                    };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
                
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
                # Entry type is ARRAY
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
                for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
                    texts["subIndex"] = subIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
                    if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
                        subentry_infos = Manager.GetSubentryInfos(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
                        typename = Manager.GetTypeName(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
                        typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
                        if typeinfos == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
                            raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
                        if typename not in internal_types:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
                            internal_types[typename] = typeinfos[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
                        texts["subIndexType"] = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
                        texts["suffixe"] = typeinfos[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
                        if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
                            texts["value"] = "\"%s\""%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
                            texts["value"] = "0x%X"%value
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
                        texts["name"] = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
                        if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
                            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
   239
                            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
   240
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
                            strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X_%(name)s%(suffixe)s = %(value)s;\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
                if callbacks:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
                    texts["name"] = FormatName(entry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
                    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
   245
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
        # Generating Dictionary C++ entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
        if callbacks:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
            if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
                name = FormatName(entry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
                name = "%(NodeName)s_Index%(index)04X"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
            strIndex += "                    ODCallback_t %s_callbacks[] = \n                     {\n"%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
            for subIndex in xrange(len(values)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
                strIndex += "                       NULL,\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
            strIndex += "                     };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
            indexCallbacks[index] = "*callbacks = %s_callbacks; "%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
            indexCallbacks[index] = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
        strIndex += "                    subindex %(NodeName)s_Index%(index)04X[] = \n                     {\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
        for subIndex in xrange(len(values)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
            subentry_infos = Manager.GetSubentryInfos(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
            if subIndex < len(values) - 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
                sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
            typename = Manager.GetTypeName(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
            typeinfos = GetValidTypeInfos(typename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
            if typename.startswith("VISIBLE_STRING"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
                subIndexType = "visible_string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
            elif typename in internal_types:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
                subIndexType = internal_types[typename]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
                subIndexType = typename
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
            if subIndex == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
                if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
                    name = "%(NodeName)s_highestSubIndex_obj%(index)04X"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
                elif index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
                    name = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
                    name = FormatName("%s_obj%04X"%(texts["NodeName"], texts["index"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
            elif entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
                if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
                    name = "%s[%d]"%(FormatName(entry_infos["name"]), subIndex - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
                    name = "%s_obj%04X[%d]"%(texts["NodeName"], texts["index"], subIndex - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
                if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
                    name = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
                    name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
            if subIndexType == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
                sizeof = name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
                sizeof = typeinfos[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
            params = Manager.GetCurrentParamsEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
            if params["save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
                save = "|TO_BE_SAVE"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
                save = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
            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
   301
        strIndex += "                     };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
        indexContents[index] = strIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
#                     Declaration of Particular Parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
    if 0x1006 not in communicationlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
        entry_infos = Manager.GetEntryInfos(0x1006)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
        indexContents[0x1006] = """\n/* index 0x1006 :   %(EntryName)s */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
                    UNS32 %(NodeName)s_obj1006 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
    if 0x1016 in communicationlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
        texts["nombre"] = Manager.GetCurrentEntry(0x1016, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
        texts["nombre"] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
        entry_infos = Manager.GetEntryInfos(0x1016)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
        indexContents[0x1016] = """\n/* index 0x1016 :   %(EntryName)s */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
                    UNS8 %(NodeName)s_highestSubIndex_obj1016 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
                    UNS32 %(NodeName)s_obj1016[0];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
                    subindex %(NodeName)s_Index1016[0];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
    if texts["nombre"] > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
        strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(nombre)d] = {TIMER_NONE,};\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
        strTimers = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[0];\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
    if 0x1017 not in communicationlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
        entry_infos = Manager.GetEntryInfos(0x1017)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
        indexContents[0x1017] = """\n/* index 0x1017 :   %(EntryName)s */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
                    UNS16 %(NodeName)s_obj1017 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
#               Declaration of navigation in the Object Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
    strDeclareIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
    strDeclareSwitch = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
    strQuickIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
    quick_index = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
    for index_cat in index_categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
        quick_index[index_cat] = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
        for cat, idx_min, idx_max in categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
            quick_index[index_cat][cat] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
    maxPDOtransmit = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
    for i, index in enumerate(listIndex):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
        texts["index"] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
        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
   354
        strDeclareSwitch += "		case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
        for cat, idx_min, idx_max in categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
            if idx_min <= index <= idx_max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
                quick_index["lastIndex"][cat] = i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
                if quick_index["firstIndex"][cat] == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
                    quick_index["firstIndex"][cat] = i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
                if cat == "PDO_TRS":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
                    maxPDOtransmit += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
    texts["maxPDOtransmit"] = max(1, maxPDOtransmit)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
    for index_cat in index_categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
        strQuickIndex += "\nquick_index %s_%s = {\n"%(texts["NodeName"], index_cat)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
        sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
        for i, (cat, idx_min, idx_max) in enumerate(categories):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
            if i == len(categories) - 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
            strQuickIndex += "  %s : %d%s\n"%(cat, quick_index[index_cat][cat], sep)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
        strQuickIndex += "};\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
#                            Write File Content
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
    fileContent = copyright_notice + generated_tag + """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
#include "%s"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
"""%(headerfilepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
/* Declaration of the mapped variables                                    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
""" + mappedVariableContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
/* Declaration of the value range types                                   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
""" + valueRangeContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
/* The node id                                                            */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
/* node_id default value.*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
//*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
/* Array of message processing information */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
    fileContent += strTimers
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
//
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
//                       OBJECT DICTIONARY
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
//                   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
    contentlist = indexContents.keys()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
    contentlist.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
    for index in contentlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
        fileContent += indexContents[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
const indextable %(NodeName)s_objdict[] = 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
    fileContent += strDeclareIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
    fileContent += """};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
	int i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
	*callbacks = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
	switch(wIndex){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
    fileContent += strDeclareSwitch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
    fileContent += """		default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
			*errorCode = OD_NO_SUCH_OBJECT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
			return NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
	*errorCode = OD_SUCCESSFUL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
	return &%(NodeName)s_objdict[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
// To count at which received SYNC a PDO must be sent.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
// Even if no pdoTransmit are defined, at least one entry is computed
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
// for compilations issues.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
UNS8 %(NodeName)s_count_sync[%(maxPDOtransmit)d] = {0,};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
    fileContent += strQuickIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
#                          Write Header File Content
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
    HeaderFileContent = copyright_notice + generated_tag + """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
#include "data.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
// prototypes of function to be filled by app
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
void %(NodeName)s_SDOtimeoutError(UNS8 line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
void %(NodeName)s_heartbeatError(UNS8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
UNS8 %(NodeName)s_canSend(Message *);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
void %(NodeName)s_initialisation();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
void %(NodeName)s_preOperational();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
void %(NodeName)s_operational();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
void %(NodeName)s_stopped();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
void %(NodeName)s_post_sync();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
void %(NodeName)s_post_TPDO();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
// Master node data struct
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
extern CO_Data %(NodeName)s_Data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
    HeaderFileContent += strDeclareHeader
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
    return fileContent,HeaderFileContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
#                             Main Function
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
def GenerateFile(filepath, manager):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
    headerfilepath = os.path.splitext(filepath)[0]+".h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
    content, header = GenerateFileContent(manager, os.path.split(headerfilepath)[1])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
    WriteFile(filepath, content)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
    WriteFile(headerfilepath, header)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
    return True