nico@207: nico@207: nico@207: CanFestival: /home/epimerde/documents/tc11/CanFestival-3/objdictgen/xml_in.py Source File nico@207: nico@207: nico@207: nico@207: nico@207:
nico@207:
nico@207:
nico@207:
nico@207:

/home/epimerde/documents/tc11/CanFestival-3/objdictgen/xml_in.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
nico@207: 00002 # -*- coding: utf-8 -*-
nico@207: 00003 
nico@207: 00004 #This file is part of CanFestival, a library implementing CanOpen Stack. 
nico@207: 00005 #
nico@207: 00006 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
nico@207: 00007 #
nico@207: 00008 #See COPYING file for copyrights details.
nico@207: 00009 #
nico@207: 00010 #This library is free software; you can redistribute it and/or
nico@207: 00011 #modify it under the terms of the GNU Lesser General Public
nico@207: 00012 #License as published by the Free Software Foundation; either
nico@207: 00013 #version 2.1 of the License, or (at your option) any later version.
nico@207: 00014 #
nico@207: 00015 #This library is distributed in the hope that it will be useful,
nico@207: 00016 #but WITHOUT ANY WARRANTY; without even the implied warranty of
nico@207: 00017 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nico@207: 00018 #Lesser General Public License for more details.
nico@207: 00019 #
nico@207: 00020 #You should have received a copy of the GNU Lesser General Public
nico@207: 00021 #License along with this library; if not, write to the Free Software
nico@207: 00022 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
nico@207: 00023 
nico@207: 00024 from xml.parsers import expat
nico@207: 00025 
nico@207: 00026 import node
nico@207: 00027 from node import *
nico@207: 00028 
nico@207: 00029 maxObjects = 8
nico@207: 00030 
nico@207: 00031 currentPDOIndex = 0
nico@207: 00032 currentBitsMapped = 0
nico@207: 00033 currentMaxObjects = 0
nico@207: 00034 currentNbMappedObjects = 0
nico@207: 00035 
nico@207: 00036 nextPdoIndex = {"rx":0x1400,"tx":0x1800}
nico@207: 00037 
nico@207: 00038 valid_elements = ["node","heartbeat_consumers","sdo_clients","pdo","mapped_object",
nico@207: 00039     "pdo_param","pdo_receive","pdo_transmit","mapped_variable","mapped_table",
nico@207: 00040     "mapped_string_variable","mapped_string_table"]
nico@207: 00041 
nico@207: 00042 #-------------------------------------------------------------------------------
nico@207: 00043 #                       Callback method of parse
nico@207: 00044 #-------------------------------------------------------------------------------
nico@207: 00045 
nico@207: 00046 def StartElement(name, attrs):
nico@207: 00047     if name in valid_elements:
nico@207: 00048         if name == "node":
nico@207: 00049             startNode(attrs)
nico@207: 00050         elif name == "heartbeat_consumers":
nico@207: 00051             startHeartBeatConsumers(attrs)
nico@207: 00052         elif name == "sdo_clients":
nico@207: 00053             startSdoClients(attrs)
nico@207: 00054         elif name in ["pdo_param","pdo_receive","pdo_transmit"]:
nico@207: 00055             raise ValueError, """!!! The XML grammar has changed.
nico@207: 00056 Please, open your xml file, delete the tags pdo_param, pdo_receive and pdo_transmit.
nico@207: 00057 Use instead the tag pdo for each pdo to create, and (optional) use the tag mapped_object (menu pdo/map and object ...)."""
nico@207: 00058         elif name == "pdo":
nico@207: 00059             startPdo(attrs)
nico@207: 00060         elif name == "mapped_object":
nico@207: 00061             startMappedObject(attrs)
nico@207: 00062         elif name == "mapped_variable":
nico@207: 00063             startMappedVariable(attrs)
nico@207: 00064         elif name == "mapped_table":
nico@207: 00065             startMappedTable(attrs)
nico@207: 00066         elif name == "mapped_string_variable":
nico@207: 00067             startMappedVariable(attrs)
nico@207: 00068         elif name == "mapped_string_table":
nico@207: 00069             startMappedTable(attrs)
nico@207: 00070 
nico@207: 00071 def EndElement(name):
nico@207: 00072     if name in valid_elements:
nico@207: 00073        if name == "node":
nico@207: 00074            stopNode()
nico@207: 00075 
nico@207: 00076 def CharacterData(data):
nico@207: 00077     pass
nico@207: 00078 
nico@207: 00079 #-------------------------------------------------------------------------------
nico@207: 00080 #                          Creation of Node
nico@207: 00081 #-------------------------------------------------------------------------------
nico@207: 00082 
nico@207: 00083 def startNode(attrs):
nico@207: 00084     name = attrs["name"]
nico@207: 00085     Node.SetNodeName(name)
nico@207: 00086     
nico@207: 00087     if "node_id" in attrs and len(attrs["node_id"]) > 0:
nico@207: 00088         node_id = eval(attrs["node_id"])
nico@207: 00089     else:
nico@207: 00090         node_id = 0x01  # We define here a default node_id. 
nico@207: 00091     Node.SetNodeID(node_id)
nico@207: 00092     
nico@207: 00093     typeNode = attrs["type_node"]
nico@207: 00094     Node.SetNodeType(typeNode)
nico@207: 00095     
nico@207: 00096     if "device_type_1000" in attrs:
nico@207: 00097         device_type = eval(attrs["device_type_1000"])
nico@207: 00098     else:
nico@207: 00099         device_type = 0
nico@207: 00100     Node.AddEntry(0x1000, 0, device_type)
nico@207: 00101     Node.AddEntry(0x1001, 0, 0)
nico@207: 00102     Node.AddEntry(0x1005, 0, 0x00000080)
nico@207: 00103     Node.AddEntry(0x1006, 0, 0)
nico@207: 00104     Node.AddEntry(0x1007, 0, 0)
nico@207: 00105 
nico@207: 00106     if "manufacturer_device_name_1008" in attrs:
nico@207: 00107         manufacturer_device_name = attrs["manufacturer_device_name_1008"]
nico@207: 00108     else:
nico@207: 00109         manufacturer_device_name = ""
nico@207: 00110     Node.AddEntry(0x1008, 0, manufacturer_device_name)
nico@207: 00111     
nico@207: 00112     if "manufacturer_hardware_version_1009" in attrs:
nico@207: 00113         manufacturer_hardware_version = attrs["manufacturer_hardware_version_1009"]
nico@207: 00114     else:
nico@207: 00115         manufacturer_hardware_version = "__DATE__"
nico@207: 00116     Node.AddEntry(0x1009, 0, manufacturer_hardware_version)
nico@207: 00117 
nico@207: 00118     if "manufacturer_software_version_100A" in attrs:
nico@207: 00119         manufacturer_software_version = attrs["manufacturer_software_version_100A"]
nico@207: 00120     else:
nico@207: 00121         manufacturer_software_version = 0
nico@207: 00122     Node.AddEntry(0x100A, 0,  manufacturer_software_version)
nico@207: 00123 
nico@207: 00124     if "vendor_id_1018" in attrs:
nico@207: 00125         vendor_id = eval(attrs["vendor_id_1018"])
nico@207: 00126     else:
nico@207: 00127         vendor_id = 0
nico@207: 00128     if "product_code_1018" in attrs:
nico@207: 00129         product_code = eval(attrs["product_code_1018"])
nico@207: 00130     else:
nico@207: 00131         product_code = 0
nico@207: 00132     if "revision_number_1018" in attrs:
nico@207: 00133         revision_number = eval(attrs["revision_number_1018"])
nico@207: 00134     else:
nico@207: 00135         revision_number = 0
nico@207: 00136     if "serial_number_1018" in attrs:
nico@207: 00137         serial_number = eval(attrs["serial_number_1018"])
nico@207: 00138     else:
nico@207: 00139         serial_number = 0
nico@207: 00140     Node.AddEntry(0x1018, 1, vendor_id)
nico@207: 00141     Node.AddEntry(0x1018, 2, product_code)
nico@207: 00142     Node.AddEntry(0x1018, 3, revision_number)
nico@207: 00143     Node.AddEntry(0x1018, 4, serial_number)
nico@207: 00144 
nico@207: 00145 def stopNode():
nico@207: 00146     heartBeatProducer()
nico@207: 00147     sdoServer()
nico@207: 00148 
nico@207: 00149 #-------------------------------------------------------------------------------
nico@207: 00150 #                      Creation of PDO in Object Dictionary
nico@207: 00151 #-------------------------------------------------------------------------------
nico@207: 00152 
nico@207: 00153 def startPdo(attrs):
nico@207: 00154     global currentPdoIndex
nico@207: 00155     global currentMaxObjects
nico@207: 00156     global currentNbMappedObjects
nico@207: 00157     global currentBitsMapped
nico@207: 00158     global maxObjects
nico@207: 00159     
nico@207: 00160     cobId = 0
nico@207: 00161     transmissionType = 253 # Default is on request. Why not ?
nico@207: 00162 
nico@207: 00163     # Find the type of the PDO and search the index of the last added
nico@207: 00164     type = attrs["type_rx_tx"]
nico@207: 00165     index = nextPdoIndex[type]
nico@207: 00166     
nico@207: 00167     # If the index of the PDO is define, verify that it has a good index
nico@207: 00168     if "index_communication_parameter" in attrs:
nico@207: 00169         index = eval(attrs["index_communication_parameter"])
nico@207: 00170     if type == "rx" and not 0x1400 <= index <= 0x15FF:
nico@207: 00171         raise ValueError, """!!! Abort because Index PDO receive : 0x%04X not valid.
nico@207: 00172 Valid index is 0x1400 ... 0x15FF"""%index
nico@207: 00173     if type == "tx" and not 0x1800 <= index <= 0x19FF:
nico@207: 00174         raise ValueError, """!!! Abort because Index PDO transmit : 0x%04X not valid.
nico@207: 00175 Valid index is 0x1800 ... 0x19FF"""%index
nico@207: 00176     
nico@207: 00177     # Extract the PDO communication parameters
nico@207: 00178     if "cob_id" == attrs:
nico@207: 00179         cobId = eval(attrs["cob_id"])
nico@207: 00180     if "max_objects_in_pdo" == attrs:
nico@207: 00181         maxObjects = eval(attrs["max_objects_in_pdo"])
nico@207: 00182     if "transmission_type" in attrs:
nico@207: 00183         transmissionType = eval(attrs["transmission_type"])
nico@207: 00184 
nico@207: 00185     if Node.IsEntry(index):
nico@207: 00186         raise ValueError, """!!! Abort because the PDO at index : 0x%04X have been already defined."""%index
nico@207: 00187 
nico@207: 00188     # Communication parameters
nico@207: 00189     Node.AddEntry(index, 1, cobId)
nico@207: 00190     Node.AddEntry(index, 2, transmissionType)
nico@207: 00191     
nico@207: 00192     # Mapping parameters
nico@207: 00193     mapping_index = index + 0x200
nico@207: 00194     for i in xrange(1, maxObjects + 1):
nico@207: 00195         Node.AddEntry(mapping_index, i, 0x0)
nico@207: 00196 
nico@207: 00197     currentPdoIndex = index
nico@207: 00198     currentMaxObjects = maxObjects
nico@207: 00199     currentBitsMapped = 0
nico@207: 00200     currentNbMappedObjects = 0
nico@207: 00201     
nico@207: 00202     nextPdoIndex[type] = index + 1
nico@207: 00203 
nico@207: 00204 def startMappedObject(attrs):
nico@207: 00205     global currentPdoIndex
nico@207: 00206     global currentMaxObjects
nico@207: 00207     global currentNbMappedObjects
nico@207: 00208     global currentBitsMapped
nico@207: 00209     
nico@207: 00210     index = currentPdoIndex
nico@207: 00211     mapping_index = index + 0x200
nico@207: 00212     
nico@207: 00213     indexObject = eval(attrs["index"])
nico@207: 00214     subIndexObject = eval(attrs["sub_index"])
nico@207: 00215     sizeInBitsObject = eval(attrs["size_in_bits"])
nico@207: 00216 
nico@207: 00217     if currentMaxObjects == 0:
nico@207: 00218         raise ValueError, """!!! Abort because of a bogue for mapped object (defined at index 0x%04X, subIndex 0x%025X)
nico@207: 00219 in PDO. index : 0x%04X is undefined."""%(indexObject,subindexObject,mapping_index)
nico@207: 00220     if currentNbMappedObjects >= currentMaxObjects:
nico@207: 00221         raise ValueError, """!!! Abort mapping object (defined at index 0x%04X, subIndex 0x%02X)
nico@207: 00222 in PDO index 0x%04X. max objects (%d) reached."""%(IndexObject,subIndexObject,mapping_index,pdo[mapping_index]["maxObjects"])
nico@207: 00223     if currentBitsMapped + sizeInBitsObject > 64:
nico@207: 00224         raise ValueError, """!!! Abort mapping object (defined at index 0x%04X, subIndex 0x%02X)
nico@207: 00225 in PDO index 0x%04X. No room to put %d bits in the PDO."""%(IndexObject,subIndexObject,mapping_index,sizeInBitsObject)
nico@207: 00226 
nico@207: 00227     value = eval("0x%04X%02X%02X"%(indexObject,subIndexObject,sizeInBitsObject))
nico@207: 00228     Node.SetEntry(mapping_index, currentNbMappedObjects + 1, value)
nico@207: 00229     
nico@207: 00230     currentNbMappedObjects += 1
nico@207: 00231     currentBitsMapped += sizeInBitsObject
nico@207: 00232 
nico@207: 00233 #-------------------------------------------------------------------------------
nico@207: 00234 #                    Creation of mapped variable and table 
nico@207: 00235 #-------------------------------------------------------------------------------
nico@207: 00236 
nico@207: 00237 def startMappedVariable(attrs):
nico@207: 00238     name = attrs["name"]
nico@207: 00239     index = eval(attrs["index"])
nico@207: 00240     subIndex = eval(attrs["sub_index"])
nico@207: 00241     
nico@207: 00242     if "size_in_bits" in attrs:
nico@207: 00243         size = eval(attrs["size_in_bits"]) # Numeric variable
nico@207: 00244         if "type" in attrs:
nico@207: 00245             type = attrs["type"]
nico@207: 00246             if (type == "UNS"):
nico@207: 00247                 type = "UNSIGNED"
nico@207: 00248         else: # Default type
nico@207: 00249             type = "UNSIGNED"
nico@207: 00250         typename = "%s%d"%(type,size)
nico@207: 00251 
nico@207: 00252         type_index = Manager.GetTypeIndex(typename, False)
nico@207: 00253         if type_index == None:
nico@207: 00254             raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : Unrecognized type : %s"""%(name,index,subIndex,typename)
nico@207: 00255         
nico@207: 00256         # Begin ValueRange support
nico@207: 00257         if "min_value" in attrs or "max_value" in attrs:
nico@207: 00258             if "min_value" in attrs and "max_value" in attrs:
nico@207: 00259                 minValue = eval(attrs["min_value"])
nico@207: 00260                 maxValue = eval(attrs["max_value"])
nico@207: 00261                 if (minValue > maxValue):
nico@207: 00262                     raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : error in value-range : min > max"""%(name,index,subIndex)
nico@207: 00263             else:
nico@207: 00264                 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)
nico@207: 00265         
nico@207: 00266             type_index = findRangeType(type_index, minValue, maxValue)
nico@207: 00267             if type_index == None:
nico@207: 00268                 raise ValueError, """!!! Sorry, too many different value range have been defined"""
nico@207: 00269         # End ValueRange support    
nico@207: 00270 
nico@207: 00271     if "size_in_byte" in attrs:
nico@207: 00272         size = eval(attrs["size_in_byte"]) # String variable
nico@207: 00273         type_index = findStringType(Manager.GetTypeIndex("VISIBLE_STRING", False), size)
nico@207: 00274         if type_index == None:
nico@207: 00275             raise ValueError, """!!! Sorry, too many different string length have been defined"""
nico@207: 00276           
nico@207: 00277     if "access" in attrs:
nico@207: 00278         access = attrs["access"].lower()
nico@207: 00279     else: 
nico@207: 00280         access = "rw" # default value
nico@207: 00281  
nico@207: 00282     if index < 0x2000 or index > 0xBFFF:
nico@207: 00283         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)
nico@207: 00284 
nico@207: 00285     if subIndex == 0:
nico@207: 00286         Node.AddMappingEntry(index, name = name, struct = 1)
nico@207: 00287     elif subIndex == 1:
nico@207: 00288         Node.AddMappingEntry(index, struct = 3)
nico@207: 00289         Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})    
nico@207: 00290     result = Node.AddMappingEntry(index, subIndex, values = {"name" : name, "type" : type_index, "access" : access, "pdo" : True})
nico@207: 00291     
nico@207: 00292     if result:
nico@207: 00293         Node.AddEntry(index, subIndex, 0)
nico@207: 00294     else:
nico@207: 00295         raise ValueError, """!!! ERROR : For variable "%s" at index 0x%04X, subindex 0x%02X : Unable to map"""%(name,index,subIndex)
nico@207: 00296 
nico@207: 00297 def startMappedTable(attrs):
nico@207: 00298     name = attrs["name"]
nico@207: 00299     number_elements = eval(attrs["number_elements"])
nico@207: 00300     index = eval(attrs["index"])
nico@207: 00301 
nico@207: 00302     if "size_in_bits" in attrs:
nico@207: 00303         size = eval(attrs["size_in_bits"]) # Numeric variable
nico@207: 00304         if "type" in attrs:
nico@207: 00305             type = attrs["type"]
nico@207: 00306             if (type == "UNS"):
nico@207: 00307                 type = "UNSIGNED"
nico@207: 00308         else: # Default type
nico@207: 00309             type = "UNSIGNED"
nico@207: 00310         typename = "%s%d"%(type,size)
nico@207: 00311 
nico@207: 00312         type_index = Manager.GetTypeIndex(typename, False)
nico@207: 00313         if type_index == None:
nico@207: 00314             raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : Unrecognized type : %s"""%(name,index,typename)
nico@207: 00315         
nico@207: 00316         # Begin ValueRange support
nico@207: 00317         if "min_value" in attrs or "max_value" in attrs:
nico@207: 00318             if "min_value" in attrs and "max_value" in attrs:
nico@207: 00319                 minValue = eval(attrs["min_value"])
nico@207: 00320                 maxValue = eval(attrs["max_value"])
nico@207: 00321                 if (minValue > maxValue):
nico@207: 00322                     raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : error in value-range : min > max"""%(name,index)
nico@207: 00323             else:
nico@207: 00324                 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)
nico@207: 00325         
nico@207: 00326             type_index = findRangeType(type_index, minValue, maxValue)
nico@207: 00327             if type_index == None:
nico@207: 00328                 raise ValueError, """!!! Sorry, too many different value range have been defined"""
nico@207: 00329         # End ValueRange support
nico@207: 00330 
nico@207: 00331     if "size_in_byte" in attrs:
nico@207: 00332         size = eval(attrs["size_in_byte"]) # String variable
nico@207: 00333         type_index = findStringType(Manager.GetTypeIndex("VISIBLE_STRING", False), size)
nico@207: 00334         if type_index == None:
nico@207: 00335             raise ValueError, """!!! Sorry, too many different string length have been defined"""
nico@207: 00336               
nico@207: 00337     if "access" in attrs:
nico@207: 00338         access = attrs["access"].lower()
nico@207: 00339     else:
nico@207: 00340         access = "rw" # default value    
nico@207: 00341 
nico@207: 00342     if index < 0x2000 or index > 0xBFFF:
nico@207: 00343         raise ValueError, """!!! ERROR : For table \"%s\" at index 0x%04X : Variable can't be defined using this index-subindex."""%(name,index)
nico@207: 00344 
nico@207: 00345     result = Node.AddMappingEntry(index, name = name, struct = 7)
nico@207: 00346     if not result:
nico@207: 00347         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)
nico@207: 00348     Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
nico@207: 00349     Node.AddMappingEntry(index, 1, values = {"name" : name, "type" : type_index, "access" : access, "pdo" : True, "nbmax" : number_elements})
nico@207: 00350     
nico@207: 00351     for subIndex in xrange(1,number_elements+1):
nico@207: 00352         Node.AddEntry(index, subIndex, 0)
nico@207: 00353 
nico@207: 00354 def findRangeType(type, minValue, maxValue):
nico@207: 00355     index = 0xA0
nico@207: 00356     while index < 0x100 and Node.IsEntry(index):
nico@207: 00357         current_type = Node.GetEntry(index, 1)
nico@207: 00358         if current_type == type:
nico@207: 00359             current_minValue = Node.GetEntry(index, 2)
nico@207: 00360             current_maxValue = Node.GetEntry(index, 3)
nico@207: 00361             if current_minValue == minValue and current_maxValue == maxValue:
nico@207: 00362                 return index
nico@207: 00363         index += 1
nico@207: 00364     if index < 0x100:
nico@207: 00365         infos = Manager.GetEntryInfos(type, False)
nico@207: 00366         name = "%s[%d-%d]"%(infos["name"], minValue, maxValue)
nico@207: 00367         Node.AddMappingEntry(index, name = name, struct = 3, size = infos["size"], default = infos["default"])
nico@207: 00368         Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
nico@207: 00369         Node.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
nico@207: 00370         Node.AddMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
nico@207: 00371         Node.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False})
nico@207: 00372         Node.AddEntry(index, 1, type)
nico@207: 00373         Node.AddEntry(index, 2, minValue)
nico@207: 00374         Node.AddEntry(index, 3, maxValue)
nico@207: 00375         return index
nico@207: 00376     return None
nico@207: 00377 
nico@207: 00378 def findStringType(type, length):
nico@207: 00379     index = 0xA0
nico@207: 00380     while index < 0x100 and Node.IsEntry(index):
nico@207: 00381         current_type = Node.GetEntry(index, 1)
nico@207: 00382         if current_type == type:
nico@207: 00383             current_length = Node.GetEntry(index, 2)
nico@207: 00384             if current_length == length:
nico@207: 00385                 return index
nico@207: 00386         index += 1
nico@207: 00387     if index < 0x100:
nico@207: 00388         infos = Manager.GetEntryInfos(type, False)
nico@207: 00389         name = "%s%d"%(Manager.GetTypeName(type), length)
nico@207: 00390         Node.AddMappingEntry(index, name = name, struct = 3, size = infos["size"], default = infos["default"])
nico@207: 00391         Node.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
nico@207: 00392         Node.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
nico@207: 00393         Node.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
nico@207: 00394         Node.AddEntry(index, 1, type)
nico@207: 00395         Node.AddEntry(index, 2, length)
nico@207: 00396         return index
nico@207: 00397     return None
nico@207: 00398 
nico@207: 00399 #-------------------------------------------------------------------------------
nico@207: 00400 #                   Creation HeartBeat Producer & Consumers
nico@207: 00401 #-------------------------------------------------------------------------------
nico@207: 00402 
nico@207: 00403 def heartBeatProducer():
nico@207: 00404     Node.AddEntry(0x1017, 0, 0)
nico@207: 00405     
nico@207: 00406 def startHeartBeatConsumers(attrs):
nico@207: 00407     nombre = eval(attrs["nombre"])
nico@207: 00408     for i in xrange(nombre):
nico@207: 00409         Node.AddEntry(0x1016, i + 1, 0)             
nico@207: 00410 
nico@207: 00411 #-------------------------------------------------------------------------------
nico@207: 00412 #                       Creation of SDO Server & Clients
nico@207: 00413 #-------------------------------------------------------------------------------
nico@207: 00414 
nico@207: 00415 def sdoServer():
nico@207: 00416     Node.AddEntry(0x1200, 1, 0x600 + Node.GetNodeID())
nico@207: 00417     Node.AddEntry(0x1200, 2, 0x580 + Node.GetNodeID())
nico@207: 00418     
nico@207: 00419 def startSdoClients(attrs):
nico@207: 00420     nombre = eval(attrs["nombre"])
nico@207: 00421     for i in xrange(nombre):
nico@207: 00422         Node.AddEntry(0x1280 + i, 1, 0x600)
nico@207: 00423         Node.AddEntry(0x1280 + i, 2, 0x580)
nico@207: 00424         Node.AddEntry(0x1280 + i, 3, 0)
nico@207: 00425     
nico@207: 00426 #-------------------------------------------------------------------------------
nico@207: 00427 #                           Parse file with Saxe
nico@207: 00428 #-------------------------------------------------------------------------------
nico@207: 00429 
nico@207: 00430 def ParseFile(filepath):
nico@207: 00431     xmlfile = open(filepath,"r")
nico@207: 00432     Parser = expat.ParserCreate()
nico@207: 00433     Parser.StartElementHandler = StartElement
nico@207: 00434     Parser.EndElementHandler = EndElement
nico@207: 00435     Parser.CharacterDataHandler = CharacterData
nico@207: 00436     ParserStatus = Parser.ParseFile(xmlfile)
nico@207: 00437     xmlfile.close()    
nico@207: 00438 
nico@207: 00439 def GenerateNode(filepath, manager):
nico@207: 00440     global Node
nico@207: 00441     global Manager
nico@207: 00442     Manager = manager
nico@207: 00443     Node = node.Node()
nico@207: 00444     ParseFile(filepath)
nico@207: 00445     return Node
nico@207: 00446 
nico@207: 00447 #-------------------------------------------------------------------------------
nico@207: 00448 #                             Main Function
nico@207: 00449 #-------------------------------------------------------------------------------
nico@207: 00450 
nico@207: 00451 if __name__ == '__main__':
nico@207: 00452     ParseFile("test.xml")
nico@207: 00453 
nico@207: 

Generated on Mon Jun 4 16:29:06 2007 for CanFestival by  nico@207: nico@207: doxygen 1.5.1
nico@207: nico@207: