nico@207: nico@207: nico@207: CanFestival: /home/epimerde/documents/tc11/CanFestival-3/objdictgen/node.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/node.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 import cPickle
nico@207: 00025 from types import *
nico@207: 00026 import re
nico@207: 00027 
nico@207: 00028 """
nico@207: 00029 Dictionary of translation between access symbol and their signification
nico@207: 00030 """
nico@207: 00031 AccessType = {"ro" : "Read Only", "wo" : "Write Only", "rw" : "Read/Write"}
nico@207: 00032 
nico@207: 00033 BoolType = {True : "True", False : "False"} 
nico@207: 00034 OptionType = {True : "Yes", False : "No"}
nico@207: 00035 
nico@207: 00036 CustomisableTypes = [(0x02, 0), (0x03, 0), (0x04, 0), (0x05, 0), (0x06, 0), (0x07, 0),
nico@207: 00037     (0x08, 0), (0x09, 1), (0x0A, 1), (0x0B, 1), (0x10, 0), (0x11, 0), (0x12, 0),
nico@207: 00038     (0x13, 0), (0x14, 0), (0x15, 0), (0x16, 0), (0x18, 0), (0x19, 0), (0x1A, 0),
nico@207: 00039     (0x1B, 0)]
nico@207: 00040 
nico@207: 00041 DefaultParams = {"comment" : "", "save" : False}
nico@207: 00042 
nico@207: 00043 #-------------------------------------------------------------------------------
nico@207: 00044 #                      Dictionary Mapping and Organisation
nico@207: 00045 #-------------------------------------------------------------------------------
nico@207: 00046 
nico@207: 00047 """
nico@207: 00048 Properties of entry structure in the Object Dictionary
nico@207: 00049 """
nico@207: 00050 OD_Subindex = 1             # Entry has at least one subindex
nico@207: 00051 OD_MultipleSubindexes = 2   # Entry has more than one subindex
nico@207: 00052 OD_IdenticalSubindexes = 4  # Subindexes of entry have the same description
nico@207: 00053 OD_IdenticalIndexes = 8     # Entry has the same description on multiple indexes
nico@207: 00054 
nico@207: 00055 """
nico@207: 00056 Structures of entry in the Object Dictionary, sum of the properties described above
nico@207: 00057 for all sorts of entries use in CAN Open specification
nico@207: 00058 """
nico@207: 00059 nosub = 0 # Entry without subindex (only for type declaration)
nico@207: 00060 var = 1
nico@207: 00061 array = 3
nico@207: 00062 rec = 7
nico@207: 00063 # Entries identical on multiple indexes
nico@207: 00064 plurivar = 9
nico@207: 00065 pluriarray = 11 # Example : PDO Parameters
nico@207: 00066 plurirec = 15   # Example : PDO Mapping
nico@207: 00067 
nico@207: 00068 """
nico@207: 00069 MappingDictionary is the structure used for writing a good organised Object
nico@207: 00070 Dictionary. It follows the specifications of the CANOpen standard.
nico@207: 00071 Change the informations within it if there is a mistake. But don't modify the
nico@207: 00072 organisation of this object, it will involve in a malfunction of the application.
nico@207: 00073 """
nico@207: 00074 
nico@207: 00075 MappingDictionary = {
nico@207: 00076     0x0001 : {"name" : "BOOLEAN", "struct" : nosub, "size" : 1, "default" : False, "values" : []},
nico@207: 00077     0x0002 : {"name" : "INTEGER8", "struct" : nosub, "size" : 8, "default" : 0, "values" : []},
nico@207: 00078     0x0003 : {"name" : "INTEGER16", "struct" : nosub, "size" : 16, "default" : 0, "values" : []},
nico@207: 00079     0x0004 : {"name" : "INTEGER32", "struct" : nosub, "size" : 32, "default" : 0, "values" : []},
nico@207: 00080     0x0005 : {"name" : "UNSIGNED8", "struct" : nosub, "size" : 8, "default" : 0, "values" : []},
nico@207: 00081     0x0006 : {"name" : "UNSIGNED16", "struct" : nosub, "size" : 16, "default" : 0, "values" : []},
nico@207: 00082     0x0007 : {"name" : "UNSIGNED32", "struct" : nosub, "size" : 32, "default" : 0, "values" : []},
nico@207: 00083     0x0008 : {"name" : "REAL32", "struct" : nosub, "size" : 32, "default" : 0.0, "values" : []},
nico@207: 00084     0x0009 : {"name" : "VISIBLE_STRING", "struct" : nosub, "size" : 8, "default" : "", "values" : []},
nico@207: 00085     0x000A : {"name" : "OCTET_STRING", "struct" : nosub, "size" : 8, "default" : "", "values" : []},
nico@207: 00086     0x000B : {"name" : "UNICODE_STRING", "struct" : nosub, "size" : 16, "default" : "", "values" : []},
nico@207: 00087 #    0x000C : {"name" : "TIME_OF_DAY", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
nico@207: 00088 #    0x000D : {"name" : "TIME_DIFFERENCE", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
nico@207: 00089     0x000F : {"name" : "DOMAIN", "struct" : nosub, "size" : 0, "default" : "", "values" : []},
nico@207: 00090     0x0010 : {"name" : "INTEGER24", "struct" : nosub, "size" : 24, "default" : 0, "values" : []},
nico@207: 00091     0x0011 : {"name" : "REAL64", "struct" : nosub, "size" : 64, "default" : 0.0, "values" : []},
nico@207: 00092     0x0012 : {"name" : "INTEGER40", "struct" : nosub, "size" : 40, "default" : 0, "values" : []},
nico@207: 00093     0x0013 : {"name" : "INTEGER48", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
nico@207: 00094     0x0014 : {"name" : "INTEGER56", "struct" : nosub, "size" : 56, "default" : 0, "values" : []},
nico@207: 00095     0x0015 : {"name" : "INTEGER64", "struct" : nosub, "size" : 64, "default" : 0, "values" : []},
nico@207: 00096     0x0016 : {"name" : "UNSIGNED24", "struct" : nosub, "size" : 24, "default" : 0, "values" : []},
nico@207: 00097     0x0018 : {"name" : "UNSIGNED40", "struct" : nosub, "size" : 40, "default" : 0, "values" : []},
nico@207: 00098     0x0019 : {"name" : "UNSIGNED48", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
nico@207: 00099     0x001A : {"name" : "UNSIGNED56", "struct" : nosub, "size" : 56, "default" : 0, "values" : []},
nico@207: 00100     0x001B : {"name" : "UNSIGNED64", "struct" : nosub, "size" : 64, "default" : 0, "values" : []},
nico@207: 00101     0x1000 : {"name" : "Device Type", "struct" : var, "need" : True, "values" : 
nico@207: 00102                 [{"name" : "Device Type", "type" : 0x07, "access" : 'ro', "pdo" : False}]},
nico@207: 00103     0x1001 : {"name" : "Error Register", "struct" : var,  "need" : True, "values" : 
nico@207: 00104                 [{"name" : "Error Register", "type" : 0x05, "access": 'ro', "pdo" : True}]},
nico@207: 00105     0x1002 : {"name" : "Manufacturer Status Register", "struct" : var, "need" : False,  "values" :
nico@207: 00106                 [{"name" : "Manufacturer Status Register", "type" : 0x07, "access" : 'ro', "pdo" : True}]},
nico@207: 00107     0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False,  "values" :
nico@207: 00108                 [{"name" : "Number of Errors", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00109                  {"name" : "Standard Error Field", "type" : 0x07, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]},
nico@207: 00110     0x1005 : {"name" : "SYNC COB ID", "struct" : var, "need" : True, "callback" : True, "values" :
nico@207: 00111                 [{"name" : "SYNC COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
nico@207: 00112     0x1006 : {"name" : "Communication / Cycle Period", "struct" : var, "need" : False, "callback" : True, "values" :
nico@207: 00113                 [{"name" : "Communication Cycle Period", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
nico@207: 00114     0x1007 : {"name" : "Synchronous Window Length", "struct" : var, "need" : False, "values" :
nico@207: 00115                 [{"name" : "Synchronous Window Length", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
nico@207: 00116     0x1008 : {"name" : "Manufacturer Device Name", "struct" : var, "need" : False, "values" :
nico@207: 00117                 [{"name" : "Manufacturer Device Name", "type" : 0x09, "access" : 'ro', "pdo" : False}]},
nico@207: 00118     0x1009 : {"name" : "Manufacturer Hardware Version", "struct" : var, "need" : False, "values" :
nico@207: 00119                 [{"name" : "Manufacturer Hardware Version", "type" : 0x09, "access" : 'ro', "pdo" : False}]},
nico@207: 00120     0x100A : {"name" : "Manufacturer Software Version", "struct" : var, "need" : False, "values" :
nico@207: 00121                 [{"name" : "Manufacturer Software Version", "type" : 0x09, "access" : 'ro', "pdo" : False}]},
nico@207: 00122     0x100C : {"name" : "Guard Time", "struct" : var, "need" : False, "values" :
nico@207: 00123                 [{"name" : "Guard Time", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
nico@207: 00124     0x100D : {"name" : "Life Time Factor", "struct" : var, "need" : False, "values" :
nico@207: 00125                 [{"name" : "Life Time Factor", "type" : 0x05, "access" : 'rw', "pdo" : False}]},
nico@207: 00126     0x1010 : {"name" : "Store parameters", "struct" : array, "need" : False, "values" :
nico@207: 00127                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00128                  {"name" : "Save All Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00129                  {"name" : "Save Communication Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00130                  {"name" : "Save Application Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00131                  {"name" : "Save Manufacturer Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7C}]},
nico@207: 00132     0x1011 : {"name" : "Restore Default Parameters", "struct" : array, "need" : False, "values" :
nico@207: 00133                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00134                  {"name" : "Restore All Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00135                  {"name" : "Restore Communication Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00136                  {"name" : "Restore Application Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00137                  {"name" : "Restore Manufacturer Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7C}]},
nico@207: 00138     0x1012 : {"name" : "TIME COB ID", "struct" : var, "need" : False, "values" :
nico@207: 00139                 [{"name" : "TIME COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
nico@207: 00140     0x1013 : {"name" : "High Resolution Timestamp", "struct" : var, "need" : False, "values" :
nico@207: 00141                 [{"name" : "High Resolution Time Stamp", "type" : 0x07, "access" : 'rw', "pdo" : True}]},
nico@207: 00142     0x1014 : {"name" : "Emergency COB ID", "struct" : var, "need" : False, "values" :
nico@207: 00143                 [{"name" : "Emergency COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
nico@207: 00144     0x1015 : {"name" : "Inhibit Time Emergency", "struct" : var, "need" : False, "values" :
nico@207: 00145                 [{"name" : "Inhibit Time Emergency", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
nico@207: 00146     0x1016 : {"name" : "Consumer Heartbeat Time", "struct" : rec, "need" : False, "values" :
nico@207: 00147                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00148                  {"name" : "Consumer Heartbeat Time", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7F}]},
nico@207: 00149     0x1017 : {"name" : "Producer Heartbeat Time", "struct" : var, "need" : False, "callback" : True, "values" :
nico@207: 00150                 [{"name" : "Producer Heartbeat Time", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
nico@207: 00151     0x1018 : {"name" : "Identity", "struct" : array, "need" : True, "values" :
nico@207: 00152                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00153                  {"name" : "Vendor ID", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00154                  {"name" : "Product Code", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00155                  {"name" : "Revision Number", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00156                  {"name" : "Serial Number", "type" : 0x07, "access" : 'ro', "pdo" : False}]},
nico@207: 00157     0x1020 : {"name" : "Verify Configuration", "struct" : array, "need" : False, "values" :
nico@207: 00158                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00159                  {"name" : "Configuration Date", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00160                  {"name" : "Configuration Time", "type" : 0x07, "access" : 'ro', "pdo" : False}]},
nico@207: 00161 #    0x1021 : {"name" : "Store EDS", "struct" : var, "need" : False, "values" :
nico@207: 00162 #                [{"name" : "Store EDS", "type" : 0x0F, "access" : 'rw', "pdo" : False}]},
nico@207: 00163 #    0x1022 : {"name" : "Storage Format", "struct" : var, "need" : False, "values" :
nico@207: 00164 #                [{"name" : "Storage Format", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
nico@207: 00165     0x1023 : {"name" : "OS Command", "struct" : array, "need" : False, "values" :
nico@207: 00166                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00167                  {"name" : "Command", "type" : 0x0A, "access" : 'rw', "pdo" : False},
nico@207: 00168                  {"name" : "Status", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00169                  {"name" : "Reply", "type" : 0x0A, "access" : 'ro', "pdo" : False}]},
nico@207: 00170     0x1024 : {"name" : "OS Command Mode", "struct" : var, "need" : False, "values" :
nico@207: 00171                 [{"name" : "OS Command Mode", "type" : 0x05, "access" : 'wo', "pdo" : False}]},
nico@207: 00172     0x1025 : {"name" : "OS Debugger Interface", "struct" : array, "need" : False, "values" :
nico@207: 00173                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00174                  {"name" : "Command", "type" : 0x0A, "access" : 'rw', "pdo" : False},
nico@207: 00175                  {"name" : "Status", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00176                  {"name" : "Reply", "type" : 0x0A, "access" : 'ro', "pdo" : False}]},
nico@207: 00177     0x1026 : {"name" : "OS Prompt", "struct" : array, "need" : False, "values" :
nico@207: 00178                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00179                  {"name" : "StdIn", "type" : 0x05, "access" : 'wo', "pdo" : True},
nico@207: 00180                  {"name" : "StdOut", "type" : 0x05, "access" : 'ro', "pdo" : True},
nico@207: 00181                  {"name" : "StdErr", "type" : 0x05, "access" : 'ro', "pdo" : True}]},
nico@207: 00182     0x1027 : {"name" : "Module List", "struct" : rec, "need" : False, "values" :
nico@207: 00183                 [{"name" : "Number of Connected Modules", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00184                  {"name" : "Module %d[(sub)]", "type" : 0x06, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]},
nico@207: 00185     0x1028 : {"name" : "Emergency Consumer", "struct" : rec, "need" : False, "values" :
nico@207: 00186                 [{"name" : "Number of Consumed Emergency Objects", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00187                  {"name" : "Emergency Consumer", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7E}]},
nico@207: 00188     0x1029 : {"name" : "Error Behavior", "struct" : array, "need" : False, "values" :
nico@207: 00189                 [{"name" : "Number of Error Classes", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00190                  {"name" : "Communication Error", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00191                  {"name" : "Device Profile", "type" : 0x05, "access" : 'rw', "pdo" : False, "nbmax" : 0xFE}]},
nico@207: 00192     0x1200 : {"name" : "Server SDO Parameter", "struct" : array, "need" : False, "values" :
nico@207: 00193                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00194                  {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00195                  {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False}]},
nico@207: 00196     0x1201 : {"name" : "Additional Server SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x7F, "need" : False, "values" :
nico@207: 00197                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00198                  {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00199                  {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
nico@207: 00200                  {"name" : "Node ID of the SDO Client", "type" : 0x05, "access" : 'ro', "pdo" : False}]},
nico@207: 00201     0x1280 : {"name" : "Client SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x100, "need" : False, "values" :
nico@207: 00202                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00203                  {"name" : "COB ID Client to Server (Transmit SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00204                  {"name" : "COB ID Server to Client (Receive SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
nico@207: 00205                  {"name" : "Node ID of the SDO Server", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
nico@207: 00206     0x1400 : {"name" : "Receive PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
nico@207: 00207                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00208                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+2)*0x100,False:0}[base<4]"},
nico@207: 00209                  {"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00210                  {"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False},
nico@207: 00211                  {"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00212                  {"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
nico@207: 00213     0x1600 : {"name" : "Receive PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
nico@207: 00214                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00215                  {"name" : "PDO %d Mapping for an application object %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]},
nico@207: 00216     0x1800 : {"name" : "Transmit PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
nico@207: 00217                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
nico@207: 00218                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+1)*0x100+0x80,False:0}[base<4]"},
nico@207: 00219                  {"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00220                  {"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False},
nico@207: 00221                  {"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00222                  {"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
nico@207: 00223     0x1A00 : {"name" : "Transmit PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
nico@207: 00224                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False},
nico@207: 00225                  {"name" : "PDO %d Mapping for a process data variable %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]},
nico@207: 00226 }
nico@207: 00227 
nico@207: 00228 #-------------------------------------------------------------------------------
nico@207: 00229 #                         Search in a Mapping Dictionary
nico@207: 00230 #-------------------------------------------------------------------------------
nico@207: 00231 
nico@207: 00232 """
nico@207: 00233 Return the index of the typename given by searching in mappingdictionary 
nico@207: 00234 """
nico@207: 00235 def FindTypeIndex(typename, mappingdictionary):
nico@207: 00236     testdic = {}
nico@207: 00237     for index, values in mappingdictionary.iteritems():
nico@207: 00238         if index < 0x1000:
nico@207: 00239             testdic[values["name"]] = index
nico@207: 00240     if typename in testdic:
nico@207: 00241         return testdic[typename]
nico@207: 00242     return None
nico@207: 00243 
nico@207: 00244 """
nico@207: 00245 Return the name of the type by searching in mappingdictionary 
nico@207: 00246 """
nico@207: 00247 def FindTypeName(typeindex, mappingdictionary):
nico@207: 00248     if typeindex < 0x1000 and typeindex in mappingdictionary:
nico@207: 00249         return mappingdictionary[typeindex]["name"]
nico@207: 00250     return None
nico@207: 00251 
nico@207: 00252 """
nico@207: 00253 Return the default value of the type by searching in mappingdictionary 
nico@207: 00254 """
nico@207: 00255 def FindTypeDefaultValue(typeindex, mappingdictionary):
nico@207: 00256     if typeindex < 0x1000 and typeindex in mappingdictionary:
nico@207: 00257         return mappingdictionary[typeindex]["default"]
nico@207: 00258     return None
nico@207: 00259 
nico@207: 00260 """
nico@207: 00261 Return the list of types defined in mappingdictionary 
nico@207: 00262 """
nico@207: 00263 def FindTypeList(mappingdictionary):
nico@207: 00264     list = []
nico@207: 00265     for index in mappingdictionary.keys():
nico@207: 00266         if index < 0x1000:
nico@207: 00267             list.append(mappingdictionary[index]["name"])
nico@207: 00268     return list
nico@207: 00269 
nico@207: 00270 """
nico@207: 00271 Return the name of an entry by searching in mappingdictionary 
nico@207: 00272 """
nico@207: 00273 def FindEntryName(index, mappingdictionary):
nico@207: 00274     base_index = FindIndex(index, mappingdictionary)
nico@207: 00275     if base_index:
nico@207: 00276         infos = mappingdictionary[base_index]
nico@207: 00277         if infos["struct"] & OD_IdenticalIndexes:
nico@207: 00278             return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
nico@207: 00279         else:
nico@207: 00280             return infos["name"]
nico@207: 00281     return None
nico@207: 00282 
nico@207: 00283 """
nico@207: 00284 Return the informations of one entry by searching in mappingdictionary 
nico@207: 00285 """
nico@207: 00286 def FindEntryInfos(index, mappingdictionary):
nico@207: 00287     base_index = FindIndex(index, mappingdictionary)
nico@207: 00288     if base_index:
nico@207: 00289         copy = mappingdictionary[base_index].copy()
nico@207: 00290         if copy["struct"] & OD_IdenticalIndexes:
nico@207: 00291             copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
nico@207: 00292         copy.pop("values")
nico@207: 00293         return copy
nico@207: 00294     return None
nico@207: 00295 
nico@207: 00296 """
nico@207: 00297 Return the informations of one subentry of an entry by searching in mappingdictionary 
nico@207: 00298 """
nico@207: 00299 def FindSubentryInfos(index, subIndex, mappingdictionary):
nico@207: 00300     base_index = FindIndex(index, mappingdictionary)
nico@207: 00301     if base_index:
nico@207: 00302         struct = mappingdictionary[base_index]["struct"]
nico@207: 00303         if struct & OD_Subindex:
nico@207: 00304             if struct & OD_IdenticalSubindexes:
nico@207: 00305                 if struct & OD_IdenticalIndexes:
nico@207: 00306                     incr = mappingdictionary[base_index]["incr"]
nico@207: 00307                 else:
nico@207: 00308                     incr = 1
nico@207: 00309                 if subIndex == 0:
nico@207: 00310                     return mappingdictionary[base_index]["values"][0].copy()
nico@207: 00311                 elif 0 < subIndex <= mappingdictionary[base_index]["values"][1]["nbmax"]:
nico@207: 00312                     copy = mappingdictionary[base_index]["values"][1].copy()
nico@207: 00313                     copy["name"] = StringFormat(copy["name"], (index - base_index) / incr + 1, subIndex)
nico@207: 00314                     return copy
nico@207: 00315             elif struct & OD_MultipleSubindexes and 0 <= subIndex < len(mappingdictionary[base_index]["values"]):
nico@207: 00316                 return mappingdictionary[base_index]["values"][subIndex].copy()
nico@207: 00317             elif subIndex == 0:
nico@207: 00318                 return mappingdictionary[base_index]["values"][0].copy()
nico@207: 00319     return None
nico@207: 00320 
nico@207: 00321 """
nico@207: 00322 Return the list of variables that can be mapped defined in mappingdictionary 
nico@207: 00323 """
nico@207: 00324 def FindMapVariableList(mappingdictionary, Node):
nico@207: 00325     list = []
nico@207: 00326     for index in mappingdictionary.iterkeys():
nico@207: 00327         if Node.IsEntry(index):
nico@207: 00328             for subIndex, values in enumerate(mappingdictionary[index]["values"]):
nico@207: 00329                 if mappingdictionary[index]["values"][subIndex]["pdo"]:
nico@207: 00330                     infos = Node.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
nico@207: 00331                     if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
nico@207: 00332                         values = Node.GetEntry(index)
nico@207: 00333                         for i in xrange(len(values) - 1):
nico@207: 00334                             list.append((index, i + 1, infos["size"], StringFormat(mappingdictionary[index]["values"][subIndex]["name"],1,i+1)))
nico@207: 00335                     else:
nico@207: 00336                         list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"]))
nico@207: 00337     return list
nico@207: 00338 
nico@207: 00339 """
nico@207: 00340 Return the list of mandatory indexes defined in mappingdictionary 
nico@207: 00341 """
nico@207: 00342 def FindMandatoryIndexes(mappingdictionary):
nico@207: 00343     list = []
nico@207: 00344     for index in mappingdictionary.iterkeys():
nico@207: 00345         if index >= 0x1000 and mappingdictionary[index]["need"]:
nico@207: 00346             list.append(index)
nico@207: 00347     return list
nico@207: 00348 
nico@207: 00349 """
nico@207: 00350 Return the index of the informations in the Object Dictionary in case of identical
nico@207: 00351 indexes
nico@207: 00352 """
nico@207: 00353 def FindIndex(index, mappingdictionary):
nico@207: 00354     if index in mappingdictionary:
nico@207: 00355         return index
nico@207: 00356     else:
nico@207: 00357         listpluri = [idx for idx in mappingdictionary.keys() if mappingdictionary[idx]["struct"] & OD_IdenticalIndexes]
nico@207: 00358         listpluri.sort()
nico@207: 00359         for idx in listpluri:
nico@207: 00360             nb_max = mappingdictionary[idx]["nbmax"]
nico@207: 00361             incr = mappingdictionary[idx]["incr"]
nico@207: 00362             if idx < index < idx + incr * nb_max and (index - idx)%incr == 0:
nico@207: 00363                 return idx
nico@207: 00364     return None
nico@207: 00365 
nico@207: 00366 #-------------------------------------------------------------------------------
nico@207: 00367 #                           Formating Name of an Entry
nico@207: 00368 #-------------------------------------------------------------------------------
nico@207: 00369 
nico@207: 00370 name_model = re.compile('(.*)\[(.*)\]')
nico@207: 00371 
nico@207: 00372 """
nico@207: 00373 Format the text given with the index and subindex defined
nico@207: 00374 """
nico@207: 00375 def StringFormat(text, idx, sub):
nico@207: 00376     result = name_model.match(text)
nico@207: 00377     if result:
nico@207: 00378         format = result.groups()
nico@207: 00379         return format[0]%eval(format[1])
nico@207: 00380     else:
nico@207: 00381         return text
nico@207: 00382 
nico@207: 00383 #-------------------------------------------------------------------------------
nico@207: 00384 #                          Definition of Node Object
nico@207: 00385 #-------------------------------------------------------------------------------
nico@207: 00386 
nico@207: 00387 """
nico@207: 00388 Class recording the Object Dictionary entries. It checks at each modification
nico@207: 00389 that the structure of the Object Dictionary stay coherent
nico@207: 00390 """
nico@207: 00391 
nico@207: 00392 class Node:
nico@207: 00393     
nico@207: 00394     def __init__(self, name = "", type = "slave", id = 0, description = "", profilename = "DS-301", profile = {}, specificmenu = []):
nico@207: 00395         self.NameName = name
nico@207: 00396         self.TypeType = type
nico@207: 00397         self.IDID = id
nico@207: 00398         self.DescriptionDescription = description
nico@207: 00399         self.ProfileNameProfileName = profilename
nico@207: 00400         self.ProfileProfile = profile
nico@207: 00401         self.SpecificMenuSpecificMenu = specificmenu
nico@207: 00402         self.DictionaryDictionary = {}
nico@207: 00403         self.ParamsDictionaryParamsDictionary = {}
nico@207: 00404         self.DS302DS302 = {}
nico@207: 00405         self.UserMappingUserMapping = {}
nico@207: 00406     
nico@207: 00407     """
nico@207: 00408     Return the node name
nico@207: 00409     """
nico@207: 00410     def GetNodeName(self):
nico@207: 00411         return self.NameName
nico@207: 00412     
nico@207: 00413     """
nico@207: 00414     Define the node name
nico@207: 00415     """
nico@207: 00416     def SetNodeName(self, name):
nico@207: 00417         self.NameName = name
nico@207: 00418 
nico@207: 00419     """
nico@207: 00420     Return the node type ("master" or "slave")
nico@207: 00421     """
nico@207: 00422     def GetNodeType(self):
nico@207: 00423         return self.TypeType
nico@207: 00424     
nico@207: 00425     """
nico@207: 00426     Define the node type ("master" or "slave")
nico@207: 00427     """
nico@207: 00428     def SetNodeType(self, type):
nico@207: 00429         self.TypeType = type
nico@207: 00430 
nico@207: 00431     """
nico@207: 00432     Return the node ID
nico@207: 00433     """
nico@207: 00434     def GetNodeID(self):
nico@207: 00435         return self.IDID
nico@207: 00436     
nico@207: 00437     """
nico@207: 00438     Define the node ID
nico@207: 00439     """
nico@207: 00440     def SetNodeID(self, id):
nico@207: 00441         self.IDID = id
nico@207: 00442 
nico@207: 00443     """
nico@207: 00444     Return the node description
nico@207: 00445     """
nico@207: 00446     def GetNodeDescription(self):
nico@207: 00447         if getattr(self, "Description", False):
nico@207: 00448             return self.DescriptionDescription
nico@207: 00449         else:
nico@207: 00450             return ""
nico@207: 00451     
nico@207: 00452     """
nico@207: 00453     Define the node description
nico@207: 00454     """
nico@207: 00455     def SetNodeDescription(self, description):
nico@207: 00456         self.DescriptionDescription = description
nico@207: 00457 
nico@207: 00458     """
nico@207: 00459     Return the Specific Profile Name
nico@207: 00460     """
nico@207: 00461     def GetProfileName(self):
nico@207: 00462         return self.ProfileNameProfileName
nico@207: 00463     
nico@207: 00464     """
nico@207: 00465     Define the Specific Profile Name
nico@207: 00466     """
nico@207: 00467     def SetProfileName(self, profilename):
nico@207: 00468         self.ProfileNameProfileName = profilename
nico@207: 00469 
nico@207: 00470     """
nico@207: 00471     Return the Specific Profile
nico@207: 00472     """
nico@207: 00473     def GetProfile(self):
nico@207: 00474         return self.ProfileProfile
nico@207: 00475     
nico@207: 00476     """
nico@207: 00477     Define the Specific Profile
nico@207: 00478     """
nico@207: 00479     def SetProfile(self, profile):
nico@207: 00480         self.ProfileProfile = profile
nico@207: 00481     
nico@207: 00482     """
nico@207: 00483     Define the DS-302 Profile
nico@207: 00484     """
nico@207: 00485     def SetDS302Profile(self, profile):
nico@207: 00486         self.DS302DS302 = profile
nico@207: 00487     
nico@207: 00488     """
nico@207: 00489     Define the DS-302 Profile
nico@207: 00490     """
nico@207: 00491     def GetDS302Profile(self):
nico@207: 00492         return self.DS302DS302
nico@207: 00493     
nico@207: 00494     """
nico@207: 00495     Return the Specific Menu Entries
nico@207: 00496     """
nico@207: 00497     def GetSpecificMenu(self):
nico@207: 00498         return self.SpecificMenuSpecificMenu
nico@207: 00499     
nico@207: 00500     """
nico@207: 00501     Define the Specific Menu Entries
nico@207: 00502     """
nico@207: 00503     def SetSpecificMenu(self, specificmenu):
nico@207: 00504         self.SpecificMenuSpecificMenu = specificmenu
nico@207: 00505     
nico@207: 00506     """
nico@207: 00507     Extend the Specific Menu Entries
nico@207: 00508     """
nico@207: 00509     
nico@207: 00510     def ExtendSpecificMenu(self, specificmenu):
nico@207: 00511         self.SpecificMenuSpecificMenu.extend(specificmenu)
nico@207: 00512     
nico@207: 00513     """
nico@207: 00514     Function which return the different Mappings available for this node
nico@207: 00515     """
nico@207: 00516     def GetMappings(self, userdefinedtoo = True):
nico@207: 00517         if userdefinedtoo:
nico@207: 00518             return [self.ProfileProfile, self.DS302DS302, self.UserMappingUserMapping]
nico@207: 00519         else:
nico@207: 00520             return [self.ProfileProfile, self.DS302DS302]
nico@207: 00521     
nico@207: 00522     """
nico@207: 00523     Add a new entry in the Object Dictionary
nico@207: 00524     """
nico@207: 00525     def AddEntry(self, index, subIndex = None, value = None):
nico@207: 00526         if index not in self.DictionaryDictionary:
nico@207: 00527             if not subIndex:
nico@207: 00528                 self.DictionaryDictionary[index] = value
nico@207: 00529                 return True
nico@207: 00530             elif subIndex == 1:
nico@207: 00531                 self.DictionaryDictionary[index] = [value]
nico@207: 00532                 return True
nico@207: 00533         elif subIndex > 1 and type(self.DictionaryDictionary[index]) == ListType and subIndex == len(self.DictionaryDictionary[index]) + 1:
nico@207: 00534             self.DictionaryDictionary[index].append(value)
nico@207: 00535             return True
nico@207: 00536         return False
nico@207: 00537 
nico@207: 00538     """
nico@207: 00539     Warning ! Modifies an existing entry in the Object Dictionary. Can't add a new one.
nico@207: 00540     """
nico@207: 00541     def SetEntry(self, index, subIndex = None, value = None):
nico@207: 00542         if index in self.DictionaryDictionary:
nico@207: 00543             if not subIndex:
nico@207: 00544                 if value != None:
nico@207: 00545                     self.DictionaryDictionary[index] = value
nico@207: 00546                 return True
nico@207: 00547             elif type(self.DictionaryDictionary[index]) == ListType and 0 < subIndex <= len(self.DictionaryDictionary[index]):
nico@207: 00548                 if value != None:
nico@207: 00549                     self.DictionaryDictionary[index][subIndex - 1] = value
nico@207: 00550                 return True
nico@207: 00551         return False
nico@207: 00552     
nico@207: 00553     def SetParamsEntry(self, index, subIndex = None, comment = None, save = None, callback = None):
nico@207: 00554         if not getattr(self, "ParamsDictionary", False):
nico@207: 00555             self.ParamsDictionaryParamsDictionary = {}
nico@207: 00556         if index in self.DictionaryDictionary:
nico@207: 00557             if (comment != None or save != None or callback != None) and index not in self.ParamsDictionaryParamsDictionary:
nico@207: 00558                 self.ParamsDictionaryParamsDictionary[index] = {}
nico@207: 00559             if subIndex == None or type(self.DictionaryDictionary[index]) != ListType and subIndex == 0:
nico@207: 00560                 if comment != None:
nico@207: 00561                     self.ParamsDictionaryParamsDictionary[index]["comment"] = comment
nico@207: 00562                 if save != None:
nico@207: 00563                     self.ParamsDictionaryParamsDictionary[index]["save"] = save
nico@207: 00564                 if callback != None:
nico@207: 00565                     self.ParamsDictionaryParamsDictionary[index]["callback"] = callback
nico@207: 00566                 return True
nico@207: 00567             elif type(self.DictionaryDictionary[index]) == ListType and 0 <= subIndex <= len(self.DictionaryDictionary[index]):
nico@207: 00568                 if (comment != None or save != None or callback != None) and subIndex not in self.ParamsDictionaryParamsDictionary[index]:
nico@207: 00569                     self.ParamsDictionaryParamsDictionary[index][subIndex] = {}
nico@207: 00570                 if comment != None:
nico@207: 00571                     self.ParamsDictionaryParamsDictionary[index][subIndex]["comment"] = comment
nico@207: 00572                 if save != None:
nico@207: 00573                     self.ParamsDictionaryParamsDictionary[index][subIndex]["save"] = save
nico@207: 00574                 return True
nico@207: 00575         return False
nico@207: 00576     
nico@207: 00577     """
nico@207: 00578     Removes an existing entry in the Object Dictionary. If a subIndex is specified
nico@207: 00579     it will remove this subIndex only if it's the last of the index. If no subIndex
nico@207: 00580     is specified it removes the whole index and subIndexes from the Object Dictionary.
nico@207: 00581     """
nico@207: 00582     def RemoveEntry(self, index, subIndex = None):
nico@207: 00583         if not getattr(self, "ParamsDictionary", False):
nico@207: 00584             self.ParamsDictionaryParamsDictionary = {}
nico@207: 00585         if index in self.DictionaryDictionary:
nico@207: 00586             if not subIndex:
nico@207: 00587                 self.DictionaryDictionary.pop(index)
nico@207: 00588                 if index in self.ParamsDictionaryParamsDictionary:
nico@207: 00589                     self.ParamsDictionaryParamsDictionary.pop(index)
nico@207: 00590                 return True
nico@207: 00591             elif type(self.DictionaryDictionary[index]) == ListType and subIndex == len(self.DictionaryDictionary[index]):
nico@207: 00592                 self.DictionaryDictionary[index].pop(subIndex - 1)
nico@207: 00593                 if index in self.ParamsDictionaryParamsDictionary:
nico@207: 00594                     if subIndex in self.ParamsDictionaryParamsDictionary[index]:
nico@207: 00595                         self.ParamsDictionaryParamsDictionary[index].pop(subIndex)
nico@207: 00596                     if len(self.ParamsDictionaryParamsDictionary[index]) == 0:
nico@207: 00597                         self.ParamsDictionaryParamsDictionary.pop(index)
nico@207: 00598                 if len(self.DictionaryDictionary[index]) == 0:
nico@207: 00599                     self.DictionaryDictionary.pop(index)
nico@207: 00600                     if index in self.ParamsDictionaryParamsDictionary:
nico@207: 00601                         self.ParamsDictionaryParamsDictionary.pop(index)
nico@207: 00602                 return True
nico@207: 00603         return False
nico@207: 00604     
nico@207: 00605     """
nico@207: 00606     Check if an entry exists in the Object Dictionary and returns the answer.
nico@207: 00607     """
nico@207: 00608     def IsEntry(self, index, subIndex = None):
nico@207: 00609         if index in self.DictionaryDictionary:
nico@207: 00610             if not subIndex:
nico@207: 00611                 return True
nico@207: 00612             return subIndex <= len(self.DictionaryDictionary[index])
nico@207: 00613         return False
nico@207: 00614     
nico@207: 00615     """
nico@207: 00616     Returns the value of the entry asked. If the entry has the value "count", it
nico@207: 00617     returns the number of subIndex in the entry except the first.
nico@207: 00618     """
nico@207: 00619     def GetEntry(self, index, subIndex = None):
nico@207: 00620         if index in self.DictionaryDictionary:
nico@207: 00621             if subIndex == None:
nico@207: 00622                 if type(self.DictionaryDictionary[index]) == ListType:
nico@207: 00623                     values = [len(self.DictionaryDictionary[index])]
nico@207: 00624                     for value in self.DictionaryDictionary[index]:
nico@207: 00625                         values.append(self.CompileValueCompileValue(value, index))
nico@207: 00626                     return values
nico@207: 00627                 else:
nico@207: 00628                     return self.DictionaryDictionary[index]
nico@207: 00629             elif subIndex == 0:
nico@207: 00630                 if type(self.DictionaryDictionary[index]) == ListType:
nico@207: 00631                     return len(self.DictionaryDictionary[index])
nico@207: 00632                 else:
nico@207: 00633                     return self.CompileValueCompileValue(self.DictionaryDictionary[index], index)
nico@207: 00634             elif type(self.DictionaryDictionary[index]) == ListType and 0 < subIndex <= len(self.DictionaryDictionary[index]):
nico@207: 00635                 return self.CompileValueCompileValue(self.DictionaryDictionary[index][subIndex - 1], index)
nico@207: 00636         return None
nico@207: 00637 
nico@207: 00638     """
nico@207: 00639     Returns the value of the entry asked. If the entry has the value "count", it
nico@207: 00640     returns the number of subIndex in the entry except the first.
nico@207: 00641     """
nico@207: 00642     def GetParamsEntry(self, index, subIndex = None):
nico@207: 00643         if not getattr(self, "ParamsDictionary", False):
nico@207: 00644             self.ParamsDictionaryParamsDictionary = {}
nico@207: 00645         if index in self.DictionaryDictionary:
nico@207: 00646             if subIndex == None:
nico@207: 00647                 if type(self.DictionaryDictionary[index]) == ListType:
nico@207: 00648                     if index in self.ParamsDictionaryParamsDictionary:
nico@207: 00649                         result = []
nico@207: 00650                         for i in xrange(len(self.DictionaryDictionary[index]) + 1):
nico@207: 00651                             line = DefaultParams.copy()
nico@207: 00652                             if i in self.ParamsDictionaryParamsDictionary[index]:
nico@207: 00653                                 line.update(self.ParamsDictionaryParamsDictionary[index][i])
nico@207: 00654                             result.append(line)
nico@207: 00655                         return result
nico@207: 00656                     else:
nico@207: 00657                         return [DefaultParams.copy() for i in xrange(len(self.DictionaryDictionary[index]) + 1)]
nico@207: 00658                 else:
nico@207: 00659                     result = DefaultParams.copy()
nico@207: 00660                     if index in self.ParamsDictionaryParamsDictionary:
nico@207: 00661                         result.update(self.ParamsDictionaryParamsDictionary[index])
nico@207: 00662                     return result
nico@207: 00663             elif subIndex == 0 and type(self.DictionaryDictionary[index]) != ListType:
nico@207: 00664                 result = DefaultParams.copy()
nico@207: 00665                 if index in self.ParamsDictionaryParamsDictionary:
nico@207: 00666                     result.update(self.ParamsDictionaryParamsDictionary[index])
nico@207: 00667                 return result
nico@207: 00668             elif type(self.DictionaryDictionary[index]) == ListType and 0 <= subIndex <= len(self.DictionaryDictionary[index]):
nico@207: 00669                 result = DefaultParams.copy()
nico@207: 00670                 if index in self.ParamsDictionaryParamsDictionary and subIndex in self.ParamsDictionaryParamsDictionary[index]:
nico@207: 00671                     result.update(self.ParamsDictionaryParamsDictionary[index][subIndex])
nico@207: 00672                 return result
nico@207: 00673         return None
nico@207: 00674 
nico@207: 00675     def HasEntryCallbacks(self, index):
nico@207: 00676         if not getattr(self, "ParamsDictionary", False):
nico@207: 00677             self.ParamsDictionaryParamsDictionary = {}
nico@207: 00678         if index in self.DictionaryDictionary and index in self.ParamsDictionaryParamsDictionary and "callback" in self.ParamsDictionaryParamsDictionary[index]:
nico@207: 00679             return self.ParamsDictionaryParamsDictionary[index]["callback"]
nico@207: 00680         return False
nico@207: 00681 
nico@207: 00682     """
nico@207: 00683     Check if an entry exists in the User Mapping Dictionary and returns the answer.
nico@207: 00684     """
nico@207: 00685     def IsMappingEntry(self, index):
nico@207: 00686         if index in self.UserMappingUserMapping:
nico@207: 00687             return True
nico@207: 00688         return False
nico@207: 00689 
nico@207: 00690     """
nico@207: 00691     Add a new entry in the User Mapping Dictionary
nico@207: 00692     """
nico@207: 00693     def AddMappingEntry(self, index, subIndex = None, name = "Undefined", struct = 0, size = None, nbmax = None, default = None, values = None):
nico@207: 00694         if index not in self.UserMappingUserMapping:
nico@207: 00695             if values == None:
nico@207: 00696                 values = []
nico@207: 00697             if subIndex == None:
nico@207: 00698                 self.UserMappingUserMapping[index] = {"name" : name, "struct" : struct, "need" : False, "values" : values}
nico@207: 00699                 if size != None:
nico@207: 00700                     self.UserMappingUserMapping[index]["size"] = size
nico@207: 00701                 if nbmax != None:
nico@207: 00702                     self.UserMappingUserMapping[index]["nbmax"] = nbmax
nico@207: 00703                 if default != None:
nico@207: 00704                     self.UserMappingUserMapping[index]["default"] = default
nico@207: 00705                 return True
nico@207: 00706         elif subIndex != None and subIndex == len(self.UserMappingUserMapping[index]["values"]):
nico@207: 00707             if values == None:
nico@207: 00708                 values = {}
nico@207: 00709             self.UserMappingUserMapping[index]["values"].append(values)
nico@207: 00710             return True
nico@207: 00711         return False
nico@207: 00712 
nico@207: 00713     """
nico@207: 00714     Warning ! Modifies an existing entry in the User Mapping Dictionary. Can't add a new one.
nico@207: 00715     """
nico@207: 00716     def SetMappingEntry(self, index, subIndex = None, name = None, struct = None, size = None, nbmax = None, default = None, values = None):
nico@207: 00717         if index in self.UserMappingUserMapping:
nico@207: 00718             if subIndex == None:
nico@207: 00719                 if name != None:
nico@207: 00720                     self.UserMappingUserMapping[index]["name"] = name
nico@207: 00721                     if self.UserMappingUserMapping[index]["struct"] & OD_IdenticalSubindexes:
nico@207: 00722                         self.UserMappingUserMapping[index]["values"][1]["name"] = name + " %d[(sub)]"
nico@207: 00723                     elif not self.UserMappingUserMapping[index]["struct"] & OD_MultipleSubindexes:
nico@207: 00724                         self.UserMappingUserMapping[index]["values"][0]["name"] = name
nico@207: 00725                 if struct != None:
nico@207: 00726                     self.UserMappingUserMapping[index]["struct"] = struct
nico@207: 00727                 if size != None:
nico@207: 00728                     self.UserMappingUserMapping[index]["size"] = size
nico@207: 00729                 if nbmax != None:
nico@207: 00730                     self.UserMappingUserMapping[index]["nbmax"] = nbmax
nico@207: 00731                 if default != None:
nico@207: 00732                     self.UserMappingUserMapping[index]["default"] = default
nico@207: 00733                 if values != None:
nico@207: 00734                     self.UserMappingUserMapping[index]["values"] = values
nico@207: 00735                 return True
nico@207: 00736             elif 0 <= subIndex < len(self.UserMappingUserMapping[index]["values"]) and values != None:
nico@207: 00737                 self.UserMappingUserMapping[index]["values"][subIndex].update(values)
nico@207: 00738                 return True
nico@207: 00739         return False
nico@207: 00740     
nico@207: 00741     """
nico@207: 00742     Removes an existing entry in the User Mapping Dictionary. If a subIndex is specified
nico@207: 00743     it will remove this subIndex only if it's the last of the index. If no subIndex
nico@207: 00744     is specified it removes the whole index and subIndexes from the User Mapping Dictionary.
nico@207: 00745     """
nico@207: 00746     def RemoveMappingEntry(self, index, subIndex = None):
nico@207: 00747         if index in self.UserMappingUserMapping:
nico@207: 00748             if subIndex == None:
nico@207: 00749                 self.UserMappingUserMapping.pop(index)
nico@207: 00750                 return True
nico@207: 00751             elif subIndex == len(self.UserMappingUserMapping[index]["values"]) - 1:
nico@207: 00752                 self.UserMappingUserMapping[index]["values"].pop(subIndex)
nico@207: 00753                 return True
nico@207: 00754         return False
nico@207: 00755 
nico@207: 00756     def RemoveMapVariable(self, index, subIndex = None):
nico@207: 00757         model = index << 16
nico@207: 00758         mask = 0xFFFF << 16
nico@207: 00759         if subIndex:
nico@207: 00760             model += subIndex << 8
nico@207: 00761             mask = 0xFF << 8
nico@207: 00762         for i in self.DictionaryDictionary.iterkeys():
nico@207: 00763             if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF:
nico@207: 00764                 for j,value in enumerate(self.DictionaryDictionary[i]):
nico@207: 00765                     if (value & mask) == model:
nico@207: 00766                         self.DictionaryDictionary[i][j] = 0
nico@207: 00767     
nico@207: 00768     def UpdateMapVariable(self, index, subIndex, size):
nico@207: 00769         model = index << 16
nico@207: 00770         mask = 0xFFFF << 16
nico@207: 00771         if subIndex:
nico@207: 00772             model += subIndex << 8
nico@207: 00773             mask = 0xFF << 8
nico@207: 00774         for i in self.DictionaryDictionary.iterkeys():
nico@207: 00775             if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF:
nico@207: 00776                 for j,value in enumerate(self.DictionaryDictionary[i]):
nico@207: 00777                     if (value & mask) == model:
nico@207: 00778                         self.DictionaryDictionary[i][j] = model + size
nico@207: 00779     
nico@207: 00780     def RemoveLine(self, index, max, incr = 1):
nico@207: 00781         i = index
nico@207: 00782         while i < max and self.IsEntryIsEntry(i + incr):
nico@207: 00783             self.DictionaryDictionary[i] = self.DictionaryDictionary[i + incr]
nico@207: 00784             i += incr
nico@207: 00785         self.DictionaryDictionary.pop(i)
nico@207: 00786 
nico@207: 00787     def RemoveUserType(self, index):
nico@207: 00788         type = self.GetEntryGetEntry(index, 1)
nico@207: 00789         for i in self.UserMappingUserMapping:
nico@207: 00790             for value in self.UserMappingUserMapping[i]["values"]:
nico@207: 00791                 if value["type"] == index:
nico@207: 00792                     value["type"] = type
nico@207: 00793         self.RemoveMappingEntryRemoveMappingEntry(index)
nico@207: 00794         self.RemoveEntryRemoveEntry(index)
nico@207: 00795 
nico@207: 00796     """
nico@207: 00797     Return a copy of the node
nico@207: 00798     """
nico@207: 00799     def Copy(self):
nico@207: 00800         return cPickle.loads(cPickle.dumps(self))
nico@207: 00801 
nico@207: 00802     """
nico@207: 00803     Return a sorted list of indexes in Object Dictionary
nico@207: 00804     """
nico@207: 00805     def GetIndexes(self):
nico@207: 00806         listindex = self.DictionaryDictionary.keys()
nico@207: 00807         listindex.sort()
nico@207: 00808         return listindex
nico@207: 00809 
nico@207: 00810     """
nico@207: 00811     Print the Dictionary values
nico@207: 00812     """
nico@207: 00813     def Print(self):
nico@207: 00814         listindex = self.DictionaryDictionary.keys()
nico@207: 00815         listindex.sort()
nico@207: 00816         for index in listindex:
nico@207: 00817             print "%04X : %s"%(index, self.DictionaryDictionary[index])    
nico@207: 00818 
nico@207: 00819     def CompileValue(self, value, index):
nico@207: 00820         if type(value) == StringType and value.find("self.ID") != -1:
nico@207: 00821             base = self.GetBaseIndexGetBaseIndex(index)
nico@207: 00822             try:
nico@207: 00823                 return eval(value)
nico@207: 00824             except:
nico@207: 00825                 return 0
nico@207: 00826         else:
nico@207: 00827             return value
nico@207: 00828 
nico@207: 00829 #-------------------------------------------------------------------------------
nico@207: 00830 #                         Node Informations Functions
nico@207: 00831 #-------------------------------------------------------------------------------
nico@207: 00832 
nico@207: 00833     def GetBaseIndex(self, index):
nico@207: 00834         for mapping in self.GetMappingsGetMappings():
nico@207: 00835             result = FindIndex(index, mapping)
nico@207: 00836             if result != None:
nico@207: 00837                 return (index - result) / mapping[result]["incr"]
nico@207: 00838         result = FindIndex(index, MappingDictionary)
nico@207: 00839         if result != None:
nico@207: 00840             return (index - result) / MappingDictionary[result]["incr"]
nico@207: 00841         return 0
nico@207: 00842 
nico@207: 00843     def GetCustomisedTypeValues(self, index):
nico@207: 00844         values = self.GetEntryGetEntry(index)
nico@207: 00845         customisabletypes = self.GetCustomisableTypesGetCustomisableTypes()
nico@207: 00846         return values, customisabletypes[values[1]][1]
nico@207: 00847 
nico@207: 00848     def GetEntryName(self, index):
nico@207: 00849         result = None
nico@207: 00850         mappings = self.GetMappingsGetMappings()
nico@207: 00851         i = 0
nico@207: 00852         while not result and i < len(mappings):
nico@207: 00853             result = FindEntryName(index, mappings[i])
nico@207: 00854             i += 1
nico@207: 00855         if result == None:
nico@207: 00856             result = FindEntryName(index, MappingDictionary)
nico@207: 00857         return result
nico@207: 00858     
nico@207: 00859     def GetEntryInfos(self, index):
nico@207: 00860         result = None
nico@207: 00861         mappings = self.GetMappingsGetMappings()
nico@207: 00862         i = 0
nico@207: 00863         while not result and i < len(mappings):
nico@207: 00864             result = FindEntryInfos(index, mappings[i])
nico@207: 00865             i += 1
nico@207: 00866         if result == None:
nico@207: 00867             result = FindEntryInfos(index, MappingDictionary)
nico@207: 00868         return result
nico@207: 00869     
nico@207: 00870     def GetSubentryInfos(self, index, subIndex):
nico@207: 00871         result = None
nico@207: 00872         mappings = self.GetMappingsGetMappings()
nico@207: 00873         i = 0
nico@207: 00874         while not result and i < len(mappings):
nico@207: 00875             result = FindSubentryInfos(index, subIndex, mappings[i])
nico@207: 00876             if result:
nico@207: 00877                 result["user_defined"] = i == len(mappings) - 1 and index >= 0x1000
nico@207: 00878             i += 1
nico@207: 00879         if result == None:
nico@207: 00880             result = FindSubentryInfos(index, subIndex, MappingDictionary)
nico@207: 00881             if result:
nico@207: 00882                 result["user_defined"] = False
nico@207: 00883         return result
nico@207: 00884     
nico@207: 00885     def GetTypeIndex(self, typename):
nico@207: 00886         result = None
nico@207: 00887         mappings = self.GetMappingsGetMappings()
nico@207: 00888         i = 0
nico@207: 00889         while not result and i < len(mappings):
nico@207: 00890             result = FindTypeIndex(typename, mappings[i])
nico@207: 00891             i += 1
nico@207: 00892         if result == None:
nico@207: 00893             result = FindTypeIndex(typename, MappingDictionary)
nico@207: 00894         return result
nico@207: 00895     
nico@207: 00896     def GetTypeName(self, typeindex):
nico@207: 00897         result = None
nico@207: 00898         mappings = self.GetMappingsGetMappings()
nico@207: 00899         i = 0
nico@207: 00900         while not result and i < len(mappings):
nico@207: 00901             result = FindTypeName(typeindex, mappings[i])
nico@207: 00902             i += 1
nico@207: 00903         if result == None:
nico@207: 00904             result = FindTypeName(typeindex, MappingDictionary)
nico@207: 00905         return result
nico@207: 00906     
nico@207: 00907     def GetTypeDefaultValue(self, typeindex):
nico@207: 00908         result = None
nico@207: 00909         mappings = self.GetMappingsGetMappings()
nico@207: 00910         i = 0
nico@207: 00911         while not result and i < len(mappings):
nico@207: 00912             result = FindTypeDefaultValue(typeindex, mappings[i])
nico@207: 00913             i += 1
nico@207: 00914         if result == None:
nico@207: 00915             result = FindTypeDefaultValue(typeindex, MappingDictionary)
nico@207: 00916         return result
nico@207: 00917     
nico@207: 00918     def GetMapVariableList(self):
nico@207: 00919         list = FindMapVariableList(MappingDictionary, self)
nico@207: 00920         for mapping in self.GetMappingsGetMappings():
nico@207: 00921             list.extend(FindMapVariableList(mapping, self))
nico@207: 00922         list.sort()
nico@207: 00923         return list
nico@207: 00924     
nico@207: 00925     def GetMandatoryIndexes(self, node = None):
nico@207: 00926         list = FindMandatoryIndexes(MappingDictionary)
nico@207: 00927         for mapping in self.GetMappingsGetMappings():
nico@207: 00928             list.extend(FindMandatoryIndexes(mapping))
nico@207: 00929         return list
nico@207: 00930     
nico@207: 00931     def GetCustomisableTypes(self):
nico@207: 00932         dic = {}
nico@207: 00933         for index, valuetype in CustomisableTypes:
nico@207: 00934             name = self.GetTypeNameGetTypeName(index)
nico@207: 00935             dic[index] = [name, valuetype]
nico@207: 00936         return dic
nico@207: 00937 
nico@207: 00938 #-------------------------------------------------------------------------------
nico@207: 00939 #                            Type and Map Variable Lists
nico@207: 00940 #-------------------------------------------------------------------------------
nico@207: 00941     
nico@207: 00942     def GetTypeList(self):
nico@207: 00943         list = FindTypeList(MappingDictionary)
nico@207: 00944         for mapping in self.GetMappingsGetMappings():
nico@207: 00945             list.extend(FindTypeList(mapping))
nico@207: 00946         list.sort()
nico@207: 00947         return ",".join(list)
nico@207: 00948 
nico@207: 00949     """
nico@207: 00950     Generate the list of variables that can be mapped for the current node
nico@207: 00951     """
nico@207: 00952     def GenerateMapList(self):
nico@207: 00953         self.MapListMapList = "None"
nico@207: 00954         self.NameTranslationNameTranslation = {"None" : "00000000"}
nico@207: 00955         self.MapTranslationMapTranslation = {"00000000" : "None"}
nico@207: 00956         list = self.GetMapVariableListGetMapVariableList()
nico@207: 00957         for index, subIndex, size, name in list:
nico@207: 00958             self.MapListMapList += ",%s"%name
nico@207: 00959             map = "%04X%02X%02X"%(index,subIndex,size)
nico@207: 00960             self.NameTranslationNameTranslation[name] = map
nico@207: 00961             self.MapTranslationMapTranslation[map] = name
nico@207: 00962 
nico@207: 00963     def GetMapValue(self, mapname):
nico@207: 00964         if mapname == "None":
nico@207: 00965             return 0
nico@207: 00966         else:
nico@207: 00967             list = self.GetMapVariableListGetMapVariableList()
nico@207: 00968             for index, subIndex, size, name in list:
nico@207: 00969                 if mapname == name:
nico@207: 00970                     return (index << 16) + (subIndex << 8) + size
nico@207: 00971             return None
nico@207: 00972     
nico@207: 00973     def GetMapName(self, value):
nico@207: 00974         if value != 0:
nico@207: 00975             index = value >> 16
nico@207: 00976             subindex = (value >> 8) % (1 << 8)
nico@207: 00977             result = self.GetSubentryInfosGetSubentryInfos(index, subindex)
nico@207: 00978             if result:
nico@207: 00979                 return result["name"]
nico@207: 00980         return "None"
nico@207: 00981     
nico@207: 00982     """
nico@207: 00983     Return the list of variables that can be mapped for the current node
nico@207: 00984     """
nico@207: 00985     def GetMapList(self):
nico@207: 00986         list = ["None"] + [name for index, subIndex, size, name in self.GetMapVariableListGetMapVariableList()]
nico@207: 00987         return ",".join(list)
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: