objdictgen/gen_cfile.py
author etisserant
Thu, 20 Mar 2008 15:28:11 +0100
changeset 428 25b06f59f123
parent 422 43a4d6deb007
child 432 b4d313998bee
permissions -rw-r--r--
Endianization fix in pdo.c
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 = {}
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    41
default_string_size = 10
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    42
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
# Format a string for making a C++ variable
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
def FormatName(name):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
    wordlist = [word for word in word_model.findall(name) if word != '']
227
f76c64f66097 Bugs on cfile generation fixed
lbessard
parents: 224
diff changeset
    46
    return "_".join(wordlist)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
# Extract the informations from a given type name
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    49
def GetValidTypeInfos(typename, items=[]):
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    50
    if typename in internal_types:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    51
        return internal_types[typename]
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    52
    else:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    53
        result = type_model.match(typename)
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    54
        if result:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    55
            values = result.groups()
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    56
            if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    57
                typeinfos = ("UNS%s"%values[1], None, "uint%s"%values[1], True)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    58
            elif values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    59
                typeinfos = ("INTEGER%s"%values[1], None, "int%s"%values[1], False)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    60
            elif values[0] == "REAL" and int(values[1]) in (32, 64):
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    61
                typeinfos = ("%s%s"%(values[0], values[1]), None, "real%s"%values[1], False)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    62
            elif values[0] == "VISIBLE_STRING":
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    63
                size = default_string_size
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    64
                for item in items:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    65
                    size = max(size, len(item))
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    66
                if values[1] != "":
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    67
                    size = max(size, int(values[1]))
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    68
                typeinfos = ("UNS8", size, "visible_string", False)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    69
            elif values[0] == "DOMAIN":
420
a42335b39bf4 Bug on domain size calculation fixed
lbessard
parents: 418
diff changeset
    70
                size = 0
a42335b39bf4 Bug on domain size calculation fixed
lbessard
parents: 418
diff changeset
    71
                for item in items:
a42335b39bf4 Bug on domain size calculation fixed
lbessard
parents: 418
diff changeset
    72
                    size = max(size, len(item))
a42335b39bf4 Bug on domain size calculation fixed
lbessard
parents: 418
diff changeset
    73
                typeinfos = ("UNS8*", size, "domain", False)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    74
            elif values[0] == "BOOLEAN":
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    75
                typeinfos = ("UNS8", None, "boolean", False)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    76
            else:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    77
                raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    78
            internal_types[typename] = typeinfos
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    79
        else:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    80
            raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    81
    return typeinfos
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
def WriteFile(filepath, content):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
    cfile = open(filepath,"w")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
    cfile.write(content)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
    cfile.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
    88
def GenerateFileContent(Node, headerfilepath):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
    global type
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
    90
    global internal_types
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    91
    global default_string_size
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
    92
    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
    texts = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
    texts["maxPDOtransmit"] = 0
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
    95
    texts["NodeName"] = Node.GetNodeName()
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
    96
    texts["NodeID"] = Node.GetNodeID()
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
    97
    texts["NodeType"] = Node.GetNodeType()
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
    98
    texts["Description"] = Node.GetNodeDescription()
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
    texts["iam_a_slave"] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
    if (texts["NodeType"] == "slave"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
        texts["iam_a_slave"] = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
    
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   103
    default_string_size = Node.GetDefaultStringSize()
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   104
    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
    # Compiling lists of indexes
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   106
    rangelist = [idx for idx in Node.GetIndexes() if 0 <= idx <= 0x260]
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   107
    listIndex = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0xFFFF]
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   108
    communicationlist = [idx for idx in Node.GetIndexes() if 0x1000 <= idx <= 0x11FF]
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   109
    sdolist = [idx for idx in Node.GetIndexes() if 0x1200 <= idx <= 0x12FF]
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   110
    pdolist = [idx for idx in Node.GetIndexes() if 0x1400 <= idx <= 0x1BFF]
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   111
    variablelist = [idx for idx in Node.GetIndexes() if 0x2000 <= idx <= 0xBFFF]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
#                       Declaration of the value range types
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
#-------------------------------------------------------------------------------    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
    valueRangeContent = ""
286
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   118
    strDefine = "\n#define valueRange_EMC 0x9F /* Type for index 0x1003 subindex 0x00 (only set of value 0 is possible) */"
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   119
    strSwitch = """    case valueRange_EMC:
288
26015ee2c2c9 Modified codes in MSG_ERR and MSG_WAR in emcy.c
luis
parents: 287
diff changeset
   120
      if (*(UNS8*)value != (UNS8)0) return OD_VALUE_RANGE_EXCEEDED;
286
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   121
      break;\n"""
313
fed411af774a Adding standard default value to index 0x1014
lbessard
parents: 289
diff changeset
   122
    internal_types["valueRange_EMC"] = ("UNS8", "", "valueRange_EMC", True)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
    num = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
    for index in rangelist:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   125
        rangename = Node.GetEntryName(index)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
        result = range_model.match(rangename)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
            num += 1
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   129
            typeindex = Node.GetEntry(index, 1)
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   130
            typename = Node.GetTypeName(typeindex)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
            typeinfos = GetValidTypeInfos(typename)
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   132
            internal_types[rangename] = (typeinfos[0], typeinfos[1], "valueRange_%d"%num)
289
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   133
            minvalue = Node.GetEntry(index, 2)
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   134
            maxvalue = Node.GetEntry(index, 3)
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   135
            strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typeinfos[0],str(minvalue),str(maxvalue))
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   136
            strSwitch += "    case valueRange_%d:\n"%(num)
313
fed411af774a Adding standard default value to index 0x1014
lbessard
parents: 289
diff changeset
   137
            if typeinfos[3] and minvalue <= 0:
289
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   138
                strSwitch += "      /* Negative or null low limit ignored because of unsigned type */;\n"
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   139
            else:
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   140
                strSwitch += "      if (*(%s*)value < (%s)%s) return OD_VALUE_TOO_LOW;\n"%(typeinfos[0],typeinfos[0],str(minvalue))
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   141
            strSwitch += "      if (*(%s*)value > (%s)%s) return OD_VALUE_TOO_HIGH;\n"%(typeinfos[0],typeinfos[0],str(maxvalue))
a22ce0314063 Removed warning with lower boundary <= 0 in Valuerange test wuth unsigned types
etisserant
parents: 288
diff changeset
   142
            strSwitch += "    break;\n"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
    valueRangeContent += strDefine
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
    valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
    valueRangeContent += "\n  switch (typeValue) {\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
    valueRangeContent += strSwitch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
    valueRangeContent += "  }\n  return 0;\n}\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
#            Creation of the mapped variables and object dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
    mappedVariableContent = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
    strDeclareHeader = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
    strDeclareCallback = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
    indexContents = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
    indexCallbacks = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
    for index in listIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
        texts["index"] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
        strIndex = ""
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   162
        entry_infos = Node.GetEntryInfos(index)
229
b24906340673 Fixed unicode encoding in gen_cfile.py
etisserant
parents: 227
diff changeset
   163
        texts["EntryName"] = entry_infos["name"].encode('ascii','replace')
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   164
        values = Node.GetEntry(index)
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   165
        callbacks = Node.HasEntryCallbacks(index)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
        if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
            strIndex += "\n/* index 0x%(index)04X :   Mapped variable %(EntryName)s */\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
            strIndex += "\n/* index 0x%(index)04X :   %(EntryName)s. */\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
        # Entry type is VAR
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
        if type(values) != ListType:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   173
            subentry_infos = Node.GetSubentryInfos(index, 0)
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   174
            typename = Node.GetTypeName(subentry_infos["type"])
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   175
            typeinfos = GetValidTypeInfos(typename, [values])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
            texts["subIndexType"] = typeinfos[0]
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   177
            if typeinfos[1] is not None:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   178
                texts["suffixe"] = "[%d]"%typeinfos[1]
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   179
            else:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   180
                texts["suffixe"] = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
            if typeinfos[2] == "visible_string":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
                texts["value"] = "\"%s\""%values
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   183
                texts["comment"] = ""
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   184
            elif typeinfos[2] == "domain":
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   185
                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
   186
                texts["comment"] = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
                texts["value"] = "0x%X"%values
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   189
                texts["comment"] = "\t/* %s */"%str(values)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
            if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
                texts["name"] = FormatName(subentry_infos["name"])
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   192
                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
   193
                if callbacks:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   194
                    strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   195
                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
   196
            else:
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   197
                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
   198
            values = [values]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
        else:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   200
            subentry_infos = Node.GetSubentryInfos(index, 0)
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   201
            typename = Node.GetTypeName(subentry_infos["type"])
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   202
            typeinfos = GetValidTypeInfos(typename)
286
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   203
            if index == 0x1003:
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   204
                texts["value"] = 0
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   205
            else:
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   206
                texts["value"] = values[0]
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   207
            texts["subIndexType"] = typeinfos[0]
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   208
            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
   209
            
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
            # Entry type is RECORD
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
            if entry_infos["struct"] & OD_IdenticalSubindexes:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   212
                subentry_infos = Node.GetSubentryInfos(index, 1)
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   213
                typename = Node.GetTypeName(subentry_infos["type"])
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   214
                typeinfos = GetValidTypeInfos(typename, values[1:])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
                texts["subIndexType"] = typeinfos[0]
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   216
                if typeinfos[1] is not None:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   217
                    texts["suffixe"] = "[%d]"%typeinfos[1]
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   218
                else:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   219
                    texts["suffixe"] = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
                texts["length"] = values[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
                if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
                    texts["name"] = FormatName(entry_infos["name"])
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   223
                    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
   224
                    if callbacks:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   225
                        strDeclareHeader += "extern ODCallback_t %(name)s_callbacks[];\t\t/* Callbacks of index0x%(index)04X */\n"%texts
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   226
                    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
   227
                    for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
                        sep = ","
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   229
                        comment = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
                        if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
                            if subIndex == len(values)-1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
                                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
                            if typeinfos[2] == "visible_string":
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   234
                                value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   235
                            elif typeinfos[2] == "domain":
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   236
                                value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
227
f76c64f66097 Bugs on cfile generation fixed
lbessard
parents: 224
diff changeset
   237
                            else:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   238
                                comment = "\t/* %s */"%str(value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
                                value = "0x%X"%value
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   240
                            mappedVariableContent += "    %s%s%s\n"%(value, sep, comment)
28
e169fe15521b *** empty log message ***
lbessard
parents: 5
diff changeset
   241
                    mappedVariableContent += "  };\n"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
                    strIndex += "                    %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n                    {\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
                    for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
                        sep = ","
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   246
                        comment = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
                        if subIndex > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
                            if subIndex == len(values)-1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
                                sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
                            if typeinfos[2] == "visible_string":
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   251
                                value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   252
                            elif typeinfos[2] == "domain":
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 160
diff changeset
   253
                                value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
                            else:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   255
                                comment = "\t/* %s */"%str(value)
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   256
                                value = "0x%X"%value
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   257
                            strIndex += "                      %s%s%s\n"%(value, sep, comment)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
                    strIndex += "                    };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
                
66
94212a58c097 gen_cfile.py modified for avoiding possible conflict in mapped variable names
lbessard
parents: 64
diff changeset
   261
                texts["parent"] = FormatName(entry_infos["name"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
                # Entry type is ARRAY
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
                for subIndex, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
                    texts["subIndex"] = subIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
                    if subIndex > 0:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   266
                        subentry_infos = Node.GetSubentryInfos(index, subIndex)
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   267
                        typename = Node.GetTypeName(subentry_infos["type"])
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   268
                        typeinfos = GetValidTypeInfos(typename, [values[subIndex]])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
                        texts["subIndexType"] = typeinfos[0]
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   270
                        if typeinfos[1] is not None:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   271
                            texts["suffixe"] = "[%d]"%typeinfos[1]
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   272
                        else:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   273
                            texts["suffixe"] = ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
                        if typeinfos[2] == "visible_string":
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   275
                            texts["value"] = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   276
                            texts["comment"] = ""
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   277
                        elif typeinfos[2] == "domain":
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   278
                            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
   279
                            texts["comment"] = ""			
227
f76c64f66097 Bugs on cfile generation fixed
lbessard
parents: 224
diff changeset
   280
                        else:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
                            texts["value"] = "0x%X"%value
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   282
                            texts["comment"] = "\t/* %s */"%str(value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
                        texts["name"] = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
                        if index in variablelist:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   285
                            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
   286
                            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
   287
                        else:
5
e4365e7d47f0 Bug on number in hexa computed by gen_cfile corrected
lbessard
parents: 0
diff changeset
   288
                            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
   289
                if callbacks:
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   290
                    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
   291
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
        # Generating Dictionary C++ entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
        if callbacks:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
            if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
                name = FormatName(entry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
                name = "%(NodeName)s_Index%(index)04X"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
            strIndex += "                    ODCallback_t %s_callbacks[] = \n                     {\n"%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
            for subIndex in xrange(len(values)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
                strIndex += "                       NULL,\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
            strIndex += "                     };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
            indexCallbacks[index] = "*callbacks = %s_callbacks; "%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
            indexCallbacks[index] = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
        strIndex += "                    subindex %(NodeName)s_Index%(index)04X[] = \n                     {\n"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
        for subIndex in xrange(len(values)):
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   307
            subentry_infos = Node.GetSubentryInfos(index, subIndex)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
            if subIndex < len(values) - 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
                sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
                sep = ""
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   312
            typename = Node.GetTypeName(subentry_infos["type"])
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   313
            if entry_infos["struct"] & OD_IdenticalSubindexes:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   314
                typeinfos = GetValidTypeInfos(typename, values)
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   315
            else:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 366
diff changeset
   316
                typeinfos = GetValidTypeInfos(typename, [values[subIndex]])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
            if subIndex == 0:
286
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   318
                if index == 0x1003:
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   319
                    typeinfos = GetValidTypeInfos("valueRange_EMC")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
                if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
                    name = "%(NodeName)s_highestSubIndex_obj%(index)04X"%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
                elif index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
                    name = FormatName(subentry_infos["name"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
                    name = FormatName("%s_obj%04X"%(texts["NodeName"], texts["index"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
            elif entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
                if index in variablelist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
                    name = "%s[%d]"%(FormatName(entry_infos["name"]), subIndex - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
                    name = "%s_obj%04X[%d]"%(texts["NodeName"], texts["index"], subIndex - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
                if index in variablelist:
70
f36f09f08b62 Bug corrected on gen_cfile
lbessard
parents: 66
diff changeset
   333
                    name = FormatName("%s_%s"%(entry_infos["name"],subentry_infos["name"]))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
                    name = "%s_obj%04X_%s"%(texts["NodeName"], texts["index"], FormatName(subentry_infos["name"]))
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   336
            if typeinfos[2] == "visible_string":
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   337
                sizeof = str(max(len(values[subIndex]), default_string_size))
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   338
            elif typeinfos[2] == "domain":
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 420
diff changeset
   339
                sizeof = str(len(values[subIndex]))
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 160
diff changeset
   340
            else:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 160
diff changeset
   341
                sizeof = "sizeof (%s)"%typeinfos[0]
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   342
            params = Node.GetParamsEntry(index, subIndex)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
            if params["save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
                save = "|TO_BE_SAVE"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
                save = ""
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   347
            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
   348
        strIndex += "                     };\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
        indexContents[index] = strIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
#                     Declaration of Particular Parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   355
    if 0x1003 not in communicationlist:
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   356
        entry_infos = Node.GetEntryInfos(0x1003)
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   357
        texts["EntryName"] = entry_infos["name"]
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   358
        indexContents[0x1003] = """\n/* index 0x1003 :   %(EntryName)s */
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   359
                    UNS8 %(NodeName)s_highestSubIndex_obj1003 = 0; /* number of subindex - 1*/
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   360
                    UNS32 %(NodeName)s_obj1003[] = 
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   361
                    {
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   362
                      0x0	/* 0 */
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   363
                    };
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   364
                    ODCallback_t %(NodeName)s_Index1003_callbacks[] = 
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   365
                     {
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   366
                       NULL,
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   367
                       NULL,
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   368
                     };
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   369
                    subindex %(NodeName)s_Index1003[] = 
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   370
                     {
286
85d5361179f3 Adding support for restricting user to only dynamically set 0 to index 0x1003 subindex 0x00 in gen_cfile.py
lbessard
parents: 284
diff changeset
   371
                       { RW, valueRange_EMC, sizeof (UNS8), (void*)&%(NodeName)s_highestSubIndex_obj1003 },
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   372
                       { RO, uint32, sizeof (UNS32), (void*)&%(NodeName)s_obj1003[0] }
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   373
                     };
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   374
"""%texts
24bf3d692993 Implemented EMCY objects.
luis
parents: 261
diff changeset
   375
261
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   376
    if 0x1005 not in communicationlist:
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   377
        entry_infos = Node.GetEntryInfos(0x1005)
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   378
        texts["EntryName"] = entry_infos["name"]
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   379
        indexContents[0x1005] = """\n/* index 0x1005 :   %(EntryName)s */
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   380
                    UNS32 %(NodeName)s_obj1005 = 0x0;   /* 0 */
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   381
"""%texts
dbcd80bcab82 Prevent potential problem with missing 0x1005 OD entry
etisserant
parents: 245
diff changeset
   382
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
    if 0x1006 not in communicationlist:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   384
        entry_infos = Node.GetEntryInfos(0x1006)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
        indexContents[0x1006] = """\n/* index 0x1006 :   %(EntryName)s */
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   387
                    UNS32 %(NodeName)s_obj1006 = 0x0;   /* 0 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
314
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   390
    if 0x1014 not in communicationlist:
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   391
        entry_infos = Node.GetEntryInfos(0x1014)
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   392
        texts["EntryName"] = entry_infos["name"]
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   393
        indexContents[0x1014] = """\n/* index 0x1014 :   %(EntryName)s */
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   394
                    UNS32 %(NodeName)s_obj1014 = 0x0;   /* 0 */
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   395
"""%texts
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 313
diff changeset
   396
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
    if 0x1016 in communicationlist:
325
65b1b2d9e20b Modification of 0x1016 index c code generation
lbessard
parents: 314
diff changeset
   398
        texts["heartBeatTimers_number"] = Node.GetEntry(0x1016, 0)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
    else:
325
65b1b2d9e20b Modification of 0x1016 index c code generation
lbessard
parents: 314
diff changeset
   400
        texts["heartBeatTimers_number"] = 0
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   401
        entry_infos = Node.GetEntryInfos(0x1016)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
        indexContents[0x1016] = """\n/* index 0x1016 :   %(EntryName)s */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
                    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
   405
                    UNS32 %(NodeName)s_obj1016[]={0};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
"""%texts
325
65b1b2d9e20b Modification of 0x1016 index c code generation
lbessard
parents: 314
diff changeset
   407
    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
    if 0x1017 not in communicationlist:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   409
        entry_infos = Node.GetEntryInfos(0x1017)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
        texts["EntryName"] = entry_infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
        indexContents[0x1017] = """\n/* index 0x1017 :   %(EntryName)s */ 
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   412
                    UNS16 %(NodeName)s_obj1017 = 0x0;   /* 0 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
#               Declaration of navigation in the Object Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
    strDeclareIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
    strDeclareSwitch = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
    strQuickIndex = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
    quick_index = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
    for index_cat in index_categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
        quick_index[index_cat] = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
        for cat, idx_min, idx_max in categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
            quick_index[index_cat][cat] = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
    maxPDOtransmit = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
    for i, index in enumerate(listIndex):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
        texts["index"] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
        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
   431
        strDeclareSwitch += "		case 0x%04X: i = %d;%sbreak;\n"%(index, i, indexCallbacks[index])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
        for cat, idx_min, idx_max in categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
            if idx_min <= index <= idx_max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
                quick_index["lastIndex"][cat] = i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
                if quick_index["firstIndex"][cat] == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
                    quick_index["firstIndex"][cat] = i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
                if cat == "PDO_TRS":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
                    maxPDOtransmit += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
    texts["maxPDOtransmit"] = max(1, maxPDOtransmit)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
    for index_cat in index_categories:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
        strQuickIndex += "\nquick_index %s_%s = {\n"%(texts["NodeName"], index_cat)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
        sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
        for i, (cat, idx_min, idx_max) in enumerate(categories):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
            if i == len(categories) - 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
                sep = ""
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   446
            strQuickIndex += "  %d%s /* %s */\n"%(quick_index[index_cat][cat],sep,cat)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
        strQuickIndex += "};\n"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
#                            Write File Content
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
73
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
   453
    fileContent = generated_tag + """
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
#include "%s"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
"""%(headerfilepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
/* Declaration of the mapped variables                                    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
""" + mappedVariableContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
/* Declaration of the value range types                                   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
""" + valueRangeContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
/* The node id                                                            */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
/* node_id default value.*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
UNS8 %(NodeName)s_bDeviceNodeId = 0x%(NodeID)02X;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   476
/**************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
/* Array of message processing information */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
const UNS8 %(NodeName)s_iam_a_slave = %(iam_a_slave)d;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
"""%texts
325
65b1b2d9e20b Modification of 0x1016 index c code generation
lbessard
parents: 314
diff changeset
   482
    if texts["heartBeatTimers_number"] > 0:
422
43a4d6deb007 Fixed herbeat timer array partial initialization in generated OD code.
etisserant
parents: 421
diff changeset
   483
        declaration = "TIMER_HANDLE %(NodeName)s_heartBeatTimers[%(heartBeatTimers_number)d]"%texts
43a4d6deb007 Fixed herbeat timer array partial initialization in generated OD code.
etisserant
parents: 421
diff changeset
   484
        initializer = "{TIMER_NONE" + ",TIMER_NONE" * (texts["heartBeatTimers_number"] - 1) + "}"
43a4d6deb007 Fixed herbeat timer array partial initialization in generated OD code.
etisserant
parents: 421
diff changeset
   485
        fileContent += declaration + " = " + initializer + ";\n"
325
65b1b2d9e20b Modification of 0x1016 index c code generation
lbessard
parents: 314
diff changeset
   486
    else:
65b1b2d9e20b Modification of 0x1016 index c code generation
lbessard
parents: 314
diff changeset
   487
        fileContent += "TIMER_HANDLE %(NodeName)s_heartBeatTimers[1];\n"%texts
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
    fileContent += """
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   490
/*
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   491
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   492
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   493
                               OBJECT DICTIONARY
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   494
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   495
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   496
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
    contentlist = indexContents.keys()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
    contentlist.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
    for index in contentlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
        fileContent += indexContents[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
const indextable %(NodeName)s_objdict[] = 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
    fileContent += strDeclareIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
    fileContent += """};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
const indextable * %(NodeName)s_scanIndexOD (UNS16 wIndex, UNS32 * errorCode, ODCallback_t **callbacks)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
	int i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
	*callbacks = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
	switch(wIndex){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
    fileContent += strDeclareSwitch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
    fileContent += """		default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
			*errorCode = OD_NO_SUCH_OBJECT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
			return NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
	*errorCode = OD_SUCCESSFUL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
	return &%(NodeName)s_objdict[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 229
diff changeset
   525
/* 
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 229
diff changeset
   526
 * To count at which received SYNC a PDO must be sent.
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   527
 * Even if no pdoTransmit are defined, at least one entry is computed
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   528
 * for compilations issues.
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   529
 */
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 229
diff changeset
   530
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
   531
366
47763dd15e00 Fixed Peter Christen remarks as regards typo
etisserant
parents: 325
diff changeset
   532
    fileContent += ",".join(["s_PDO_status_Initializer"]*texts["maxPDOtransmit"]) + """};
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 229
diff changeset
   533
"""
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 229
diff changeset
   534
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
    fileContent += strQuickIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
    fileContent += """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
UNS16 %(NodeName)s_ObjdictSize = sizeof(%(NodeName)s_objdict)/sizeof(%(NodeName)s_objdict[0]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
CO_Data %(NodeName)s_Data = CANOPEN_NODE_DATA_INITIALIZER(%(NodeName)s);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
#                          Write Header File Content
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   547
    texts["file_include_name"] = headerfilepath.replace(".", "_").upper()
73
60441122e121 LGPL copyright on generated files removed
lbessard
parents: 70
diff changeset
   548
    HeaderFileContent = generated_tag + """
224
ae7edca3b7c4 Bug on header file writing in gen_cfile fixed
lbessard
parents: 223
diff changeset
   549
#ifndef %(file_include_name)s
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   550
#define %(file_include_name)s
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   551
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
#include "data.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   554
/* 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
   555
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
   556
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
   557
76
68e1c52d603d compilers compatibility
frdupin
parents: 73
diff changeset
   558
/* Master node data struct */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
extern CO_Data %(NodeName)s_Data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
"""%texts
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
    HeaderFileContent += strDeclareHeader
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
    
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   563
    HeaderFileContent += "\n#endif // %(file_include_name)s\n"%texts
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 188
diff changeset
   564
    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
    return fileContent,HeaderFileContent
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
#                             Main Function
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   571
def GenerateFile(filepath, node):
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   572
    try:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   573
        headerfilepath = os.path.splitext(filepath)[0]+".h"
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 235
diff changeset
   574
        content, header = GenerateFileContent(node, os.path.split(headerfilepath)[1])
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   575
        WriteFile(filepath, content)
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   576
        WriteFile(headerfilepath, header)
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   577
        return None
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   578
    except ValueError, message:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   579
        return "Unable to Generate C File\n%s"%message
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   580