objdictgen/eds_in.py
author etisserant
Tue, 24 Apr 2007 13:26:03 +0200
changeset 172 0248c2b148bb
parent 171 db7a030babb2
permissions -rw-r--r--
Removed SDOTimeout application callback.Please use SDO callbacks instead.
171
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     3
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     5
#
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     6
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     7
#
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     8
#See COPYING file for copyrights details.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
     9
#
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    14
#
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    18
#Lesser General Public License for more details.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    19
#
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    23
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    24
from xml.parsers import expat
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    25
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    26
import node
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    27
from node import *
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    28
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    29
maxObjects = 8
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    30
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    31
currentPDOIndex = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    32
currentBitsMapped = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    33
currentMaxObjects = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    34
currentNbMappedObjects = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    35
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    36
nextPdoIndex = {"rx":0x1400,"tx":0x1800}
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    37
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    38
valid_elements = ["node","heartbeat_consumers","sdo_clients","pdo","mapped_object",
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    39
    "pdo_param","pdo_receive","pdo_transmit","mapped_variable","mapped_table",
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    40
    "mapped_string_variable","mapped_string_table"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    41
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    42
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    43
#                       Callback method of parse
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    44
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    45
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    46
def StartElement(name, attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    47
    if name in valid_elements:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    48
        if name == "node":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    49
            startNode(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    50
        elif name == "heartbeat_consumers":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    51
            startHeartBeatConsumers(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    52
        elif name == "sdo_clients":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    53
            startSdoClients(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    54
        elif name in ["pdo_param","pdo_receive","pdo_transmit"]:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    55
            raise ValueError, """!!! The XML grammar has changed.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    56
Please, open your xml file, delete the tags pdo_param, pdo_receive and pdo_transmit.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    57
Use instead the tag pdo for each pdo to create, and (optional) use the tag mapped_object (menu pdo/map and object ...)."""
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    58
        elif name == "pdo":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    59
            startPdo(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    60
        elif name == "mapped_object":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    61
            startMappedObject(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    62
        elif name == "mapped_variable":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    63
            startMappedVariable(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    64
        elif name == "mapped_table":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    65
            startMappedTable(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    66
        elif name == "mapped_string_variable":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    67
            startMappedVariable(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    68
        elif name == "mapped_string_table":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    69
            startMappedTable(attrs)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    70
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    71
def EndElement(name):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    72
    if name in valid_elements:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    73
       if name == "node":
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    74
           stopNode()
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    75
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    76
def CharacterData(data):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    77
    pass
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    78
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    79
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    80
#                          Creation of Node
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    81
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    82
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    83
def startNode(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    84
    name = attrs["name"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    85
    Node.SetNodeName(name)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    86
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    87
    if "node_id" in attrs and len(attrs["node_id"]) > 0:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    88
        node_id = eval(attrs["node_id"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    89
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    90
        node_id = 0x01  # We define here a default node_id. 
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    91
    Node.SetNodeID(node_id)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    92
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    93
    typeNode = attrs["type_node"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    94
    Node.SetNodeType(typeNode)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    95
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    96
    if "device_type_1000" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    97
        device_type = eval(attrs["device_type_1000"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    98
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
    99
        device_type = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   100
    Node.AddEntry(0x1000, 0, device_type)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   101
    Node.AddEntry(0x1001, 0, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   102
    Node.AddEntry(0x1005, 0, 0x00000080)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   103
    Node.AddEntry(0x1006, 0, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   104
    Node.AddEntry(0x1007, 0, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   105
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   106
    if "manufacturer_device_name_1008" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   107
        manufacturer_device_name = attrs["manufacturer_device_name_1008"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   108
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   109
        manufacturer_device_name = ""
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   110
    Node.AddEntry(0x1008, 0, manufacturer_device_name)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   111
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   112
    if "manufacturer_hardware_version_1009" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   113
        manufacturer_hardware_version = attrs["manufacturer_hardware_version_1009"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   114
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   115
        manufacturer_hardware_version = "__DATE__"
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   116
    Node.AddEntry(0x1009, 0, manufacturer_hardware_version)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   117
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   118
    if "manufacturer_software_version_100A" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   119
        manufacturer_software_version = attrs["manufacturer_software_version_100A"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   120
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   121
        manufacturer_software_version = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   122
    Node.AddEntry(0x100A, 0,  manufacturer_software_version)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   123
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   124
    if "vendor_id_1018" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   125
        vendor_id = eval(attrs["vendor_id_1018"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   126
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   127
        vendor_id = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   128
    if "product_code_1018" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   129
        product_code = eval(attrs["product_code_1018"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   130
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   131
        product_code = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   132
    if "revision_number_1018" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   133
        revision_number = eval(attrs["revision_number_1018"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   134
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   135
        revision_number = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   136
    if "serial_number_1018" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   137
        serial_number = eval(attrs["serial_number_1018"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   138
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   139
        serial_number = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   140
    Node.AddEntry(0x1018, 1, vendor_id)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   141
    Node.AddEntry(0x1018, 2, product_code)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   142
    Node.AddEntry(0x1018, 3, revision_number)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   143
    Node.AddEntry(0x1018, 4, serial_number)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   144
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   145
def stopNode():
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   146
    heartBeatProducer()
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   147
    sdoServer()
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   148
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   149
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   150
#                      Creation of PDO in Object Dictionary
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   151
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   152
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   153
def startPdo(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   154
    global currentPdoIndex
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   155
    global currentMaxObjects
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   156
    global currentNbMappedObjects
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   157
    global currentBitsMapped
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   158
    global maxObjects
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   159
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   160
    cobId = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   161
    transmissionType = 253 # Default is on request. Why not ?
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   162
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   163
    # Find the type of the PDO and search the index of the last added
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   164
    type = attrs["type_rx_tx"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   165
    index = nextPdoIndex[type]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   166
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   167
    # If the index of the PDO is define, verify that it has a good index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   168
    if "index_communication_parameter" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   169
        index = eval(attrs["index_communication_parameter"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   170
    if type == "rx" and not 0x1400 <= index <= 0x15FF:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   171
        raise ValueError, """!!! Abort because Index PDO receive : 0x%04X not valid.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   172
Valid index is 0x1400 ... 0x15FF"""%index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   173
    if type == "tx" and not 0x1800 <= index <= 0x19FF:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   174
        raise ValueError, """!!! Abort because Index PDO transmit : 0x%04X not valid.
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   175
Valid index is 0x1800 ... 0x19FF"""%index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   176
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   177
    # Extract the PDO communication parameters
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   178
    if "cob_id" == attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   179
        cobId = eval(attrs["cob_id"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   180
    if "max_objects_in_pdo" == attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   181
        maxObjects = eval(attrs["max_objects_in_pdo"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   182
    if "transmission_type" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   183
        transmissionType = eval(attrs["transmission_type"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   184
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   185
    if Node.IsEntry(index):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   186
        raise ValueError, """!!! Abort because the PDO at index : 0x%04X have been already defined."""%index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   187
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   188
    # Communication parameters
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   189
    Node.AddEntry(index, 1, cobId)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   190
    Node.AddEntry(index, 2, transmissionType)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   191
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   192
    # Mapping parameters
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   193
    mapping_index = index + 0x200
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   194
    for i in xrange(1, maxObjects + 1):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   195
        Node.AddEntry(mapping_index, i, 0x0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   196
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   197
    currentPdoIndex = index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   198
    currentMaxObjects = maxObjects
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   199
    currentBitsMapped = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   200
    currentNbMappedObjects = 0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   201
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   202
    nextPdoIndex[type] = index + 1
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   203
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   204
def startMappedObject(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   205
    global currentPdoIndex
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   206
    global currentMaxObjects
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   207
    global currentNbMappedObjects
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   208
    global currentBitsMapped
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   209
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   210
    index = currentPdoIndex
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   211
    mapping_index = index + 0x200
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   212
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   213
    indexObject = eval(attrs["index"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   214
    subIndexObject = eval(attrs["sub_index"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   215
    sizeInBitsObject = eval(attrs["size_in_bits"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   216
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   217
    if currentMaxObjects == 0:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   218
        raise ValueError, """!!! Abort because of a bogue for mapped object (defined at index 0x%04X, subIndex 0x%025X)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   219
in PDO. index : 0x%04X is undefined."""%(indexObject,subindexObject,mapping_index)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   220
    if currentNbMappedObjects >= currentMaxObjects:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   221
        raise ValueError, """!!! Abort mapping object (defined at index 0x%04X, subIndex 0x%02X)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   222
in PDO index 0x%04X. max objects (%d) reached."""%(IndexObject,subIndexObject,mapping_index,pdo[mapping_index]["maxObjects"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   223
    if currentBitsMapped + sizeInBitsObject > 64:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   224
        raise ValueError, """!!! Abort mapping object (defined at index 0x%04X, subIndex 0x%02X)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   225
in PDO index 0x%04X. No room to put %d bits in the PDO."""%(IndexObject,subIndexObject,mapping_index,sizeInBitsObject)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   226
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   227
    value = eval("0x%04X%02X%02X"%(indexObject,subIndexObject,sizeInBitsObject))
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   228
    Node.SetEntry(mapping_index, currentNbMappedObjects + 1, value)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   229
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   230
    currentNbMappedObjects += 1
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   231
    currentBitsMapped += sizeInBitsObject
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   232
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   233
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   234
#                    Creation of mapped variable and table 
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   235
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   236
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   237
def startMappedVariable(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   238
    name = attrs["name"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   239
    index = eval(attrs["index"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   240
    subIndex = eval(attrs["sub_index"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   241
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   242
    if "size_in_bits" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   243
        size = eval(attrs["size_in_bits"]) # Numeric variable
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   244
        if "type" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   245
            type = attrs["type"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   246
            if (type == "UNS"):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   247
                type = "UNSIGNED"
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   248
        else: # Default type
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   249
            type = "UNSIGNED"
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   250
        typename = "%s%d"%(type,size)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   251
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   252
        type_index = Manager.GetTypeIndex(typename, False)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   253
        if type_index == None:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   254
            raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : Unrecognized type : %s"""%(name,index,subIndex,typename)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   255
        
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   256
        # Begin ValueRange support
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   257
        if "min_value" in attrs or "max_value" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   258
            if "min_value" in attrs and "max_value" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   259
                minValue = eval(attrs["min_value"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   260
                maxValue = eval(attrs["max_value"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   261
                if (minValue > maxValue):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   262
                    raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : error in value-range : min > max"""%(name,index,subIndex)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   263
            else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   264
                raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : You have defined only a min or a max value. \nIf you define one, you must define both."""%(name,index,subIndex)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   265
        
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   266
            type_index = findRangeType(type_index, minValue, maxValue)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   267
            if type_index == None:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   268
                raise ValueError, """!!! Sorry, too many different value range have been defined"""
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   269
        # End ValueRange support    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   270
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   271
    if "size_in_byte" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   272
        size = eval(attrs["size_in_byte"]) # String variable
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   273
        type_index = findStringType(Manager.GetTypeIndex("VISIBLE_STRING", False), size)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   274
        if type_index == None:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   275
            raise ValueError, """!!! Sorry, too many different string length have been defined"""
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   276
          
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   277
    if "access" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   278
        access = attrs["access"].lower()
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   279
    else: 
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   280
        access = "rw" # default value
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   281
 
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   282
    if index < 0x2000 or index > 0xBFFF:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   283
        raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : Variable can't be defined using this index-subindex."""%(name,index,subIndex)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   284
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   285
    if subIndex == 0:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   286
        Node.AddMappingEntry(index, name = name, struct = 1)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   287
    elif subIndex == 1:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   288
        Node.AddMappingEntry(index, struct = 3)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   289
        Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   290
    result = Node.AddMappingEntry(index, subIndex, values = {"name" : name, "type" : type_index, "access" : access, "pdo" : True})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   291
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   292
    if result:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   293
        Node.AddEntry(index, subIndex, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   294
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   295
        raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : Unable to map"""%(name,index,subIndex)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   296
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   297
def startMappedTable(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   298
    name = attrs["name"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   299
    number_elements = eval(attrs["number_elements"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   300
    index = eval(attrs["index"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   301
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   302
    if "size_in_bits" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   303
        size = eval(attrs["size_in_bits"]) # Numeric variable
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   304
        if "type" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   305
            type = attrs["type"]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   306
            if (type == "UNS"):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   307
                type = "UNSIGNED"
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   308
        else: # Default type
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   309
            type = "UNSIGNED"
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   310
        typename = "%s%d"%(type,size)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   311
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   312
        type_index = Manager.GetTypeIndex(typename, False)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   313
        if type_index == None:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   314
            raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : Unrecognized type : %s"""%(name,index,typename)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   315
        
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   316
        # Begin ValueRange support
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   317
        if "min_value" in attrs or "max_value" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   318
            if "min_value" in attrs and "max_value" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   319
                minValue = eval(attrs["min_value"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   320
                maxValue = eval(attrs["max_value"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   321
                if (minValue > maxValue):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   322
                    raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : error in value-range : min > max"""%(name,index)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   323
            else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   324
                raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : You have defined only a min or a max value. \nIf you define one, you must define both."""%(name,index)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   325
        
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   326
            type_index = findRangeType(type_index, minValue, maxValue)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   327
            if type_index == None:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   328
                raise ValueError, """!!! Sorry, too many different value range have been defined"""
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   329
        # End ValueRange support
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   330
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   331
    if "size_in_byte" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   332
        size = eval(attrs["size_in_byte"]) # String variable
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   333
        type_index = findStringType(Manager.GetTypeIndex("VISIBLE_STRING", False), size)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   334
        if type_index == None:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   335
            raise ValueError, """!!! Sorry, too many different string length have been defined"""
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   336
	      
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   337
    if "access" in attrs:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   338
        access = attrs["access"].lower()
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   339
    else:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   340
        access = "rw" # default value    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   341
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   342
    if index < 0x2000 or index > 0xBFFF:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   343
        raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : Variable can't be defined using this index-subindex."""%(name,index)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   344
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   345
    result = Node.AddMappingEntry(index, name = name, struct = 7)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   346
    if not result:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   347
        raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : Unable to map because a variable or a table is using this index"""%(name,index)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   348
    Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   349
    Node.AddMappingEntry(index, 1, values = {"name" : name, "type" : type_index, "access" : access, "pdo" : True, "nbmax" : number_elements})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   350
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   351
    for subIndex in xrange(1,number_elements+1):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   352
        Node.AddEntry(index, subIndex, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   353
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   354
def findRangeType(type, minValue, maxValue):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   355
    index = 0xA0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   356
    while index < 0x100 and Node.IsEntry(index):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   357
        current_type = Node.GetEntry(index, 1)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   358
        if current_type == type:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   359
            current_minValue = Node.GetEntry(index, 2)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   360
            current_maxValue = Node.GetEntry(index, 3)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   361
            if current_minValue == minValue and current_maxValue == maxValue:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   362
                return index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   363
        index += 1
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   364
    if index < 0x100:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   365
        infos = Manager.GetEntryInfos(type, False)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   366
        name = "%s[%d-%d]"%(infos["name"], minValue, maxValue)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   367
        Node.AddMappingEntry(index, name = name, struct = 3, size = infos["size"], default = infos["default"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   368
        Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   369
        Node.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   370
        Node.AddMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   371
        Node.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   372
        Node.AddEntry(index, 1, type)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   373
        Node.AddEntry(index, 2, minValue)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   374
        Node.AddEntry(index, 3, maxValue)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   375
        return index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   376
    return None
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   377
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   378
def findStringType(type, length):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   379
    index = 0xA0
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   380
    while index < 0x100 and Node.IsEntry(index):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   381
        current_type = Node.GetEntry(index, 1)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   382
        if current_type == type:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   383
            current_length = Node.GetEntry(index, 2)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   384
            if current_length == length:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   385
                return index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   386
        index += 1
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   387
    if index < 0x100:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   388
        infos = Manager.GetEntryInfos(type, False)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   389
        name = "%s%d"%(Manager.GetTypeName(type), length)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   390
        Node.AddMappingEntry(index, name = name, struct = 3, size = infos["size"], default = infos["default"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   391
        Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   392
        Node.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   393
        Node.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   394
        Node.AddEntry(index, 1, type)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   395
        Node.AddEntry(index, 2, length)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   396
        return index
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   397
    return None
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   398
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   399
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   400
#                   Creation HeartBeat Producer & Consumers
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   401
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   402
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   403
def heartBeatProducer():
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   404
    Node.AddEntry(0x1017, 0, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   405
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   406
def startHeartBeatConsumers(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   407
    nombre = eval(attrs["nombre"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   408
    for i in xrange(nombre):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   409
        Node.AddEntry(0x1016, i + 1, 0)		    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   410
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   411
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   412
#                       Creation of SDO Server & Clients
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   413
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   414
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   415
def sdoServer():
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   416
    Node.AddEntry(0x1200, 1, 0x600 + Node.GetNodeID())
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   417
    Node.AddEntry(0x1200, 2, 0x580 + Node.GetNodeID())
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   418
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   419
def startSdoClients(attrs):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   420
    nombre = eval(attrs["nombre"])
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   421
    for i in xrange(nombre):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   422
        Node.AddEntry(0x1280 + i, 1, 0x600)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   423
        Node.AddEntry(0x1280 + i, 2, 0x580)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   424
        Node.AddEntry(0x1280 + i, 3, 0)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   425
    
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   426
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   427
#                           Parse file with Saxe
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   428
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   429
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   430
def ParseFile(filepath):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   431
    return dict([(                          # Dict containing whole Eds
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   432
              blocktuple[0],                # EntryName : Assignements dict
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   433
              dict([assignment.split('=')   #  Name : Value
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   434
                for assignment in           # Assignements are
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   435
                blocktuple[-1].splitlines()    # all the lines
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   436
                if assignment.find('=') > 0 ]  # that contains '='
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   437
               )) for blocktuple in [       # Split the eds files into
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   438
                 block.split("]")           # (EntryName,Assignements) tuple
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   439
                 for block in               # for each blocks staring with '['
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   440
                 open(filepath,'r').read().split("[")]
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   441
               if blocktuple[0].isalnum()]) # if EntryName exists
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   442
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   443
def GenerateNode(filepath, manager):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   444
    global Node
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   445
    global Manager
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   446
    Manager = manager
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   447
    Node = node.Node()
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   448
    eds_dict = ParseFile(filepath)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   449
    ProfileNb=int(eds_dict["1000"]["DefaultValue"],16) & 0x0000ffff
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   450
    if ProfileNb not in [301, 302]:
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   451
        execfile("config/DS-%d.prf"%ProfileNb)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   452
        Node.SetProfileName("DS-%d"%ProfileNb)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   453
        Node.SetProfile(Mapping)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   454
        Node.SetSpecificMenu(AddMenuEntries)
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   455
    for Entry in ParseFile(filepath):
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   456
        pass
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   457
        
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   458
    return Node
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   459
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   460
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   461
#                             Main Function
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   462
#-------------------------------------------------------------------------------
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   463
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   464
if __name__ == '__main__':
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   465
    ParseFile("test.xml")
db7a030babb2 EDS import
etisserant
parents:
diff changeset
   466