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