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