2 # -*- coding: utf-8 -*-
4 #This file is part of CanFestival, a library implementing CanOpen Stack.
6 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
8 #See COPYING file for copyrights details.
10 #This library is free software; you can redistribute it and/or
11 #modify it under the terms of the GNU Lesser General Public
12 #License as published by the Free Software Foundation; either
13 #version 2.1 of the License, or (at your option) any later version.
15 #This library is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 #Lesser General Public License for more details.
20 #You should have received a copy of the GNU Lesser General Public
21 #License along with this library; if not, write to the Free Software
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 Dictionary of translation between access symbol and their signification
30 AccessType = {"ro" : "Read Only", "wo" : "Write Only", "rw" : "Read/Write"}
32 BoolType = {True : "True", False : "False"}
33 OptionType = {True : "Yes", False : "No"}
35 CustomisableTypes = [(0x02, 0), (0x03, 0), (0x04, 0), (0x05, 0), (0x06, 0), (0x07, 0),
36 (0x08, 0), (0x09, 1), (0x0A, 1), (0x0B, 1), (0x10, 0), (0x11, 0), (0x12, 0),
37 (0x13, 0), (0x14, 0), (0x15, 0), (0x16, 0), (0x18, 0), (0x19, 0), (0x1A, 0),
40 DefaultParams = {"comment" : "", "save" : False}
42 #-------------------------------------------------------------------------------
43 # Dictionary Mapping and Organisation
44 #-------------------------------------------------------------------------------
47 Properties of entry structure in the Object Dictionary
49 OD_Subindex = 1 # Entry has at least one subindex
50 OD_MultipleSubindexes = 2 # Entry has more than one subindex
51 OD_IdenticalSubindexes = 4 # Subindexes of entry have the same description
52 OD_IdenticalIndexes = 8 # Entry has the same description on multiple indexes
55 Structures of entry in the Object Dictionary, sum of the properties described above
56 for all sorts of entries use in CAN Open specification
58 nosub = 0 # Entry without subindex (only for type declaration)
62 # Entries identical on multiple indexes
64 pluriarray = 11 # Example : PDO Parameters
65 plurirec = 15 # Example : PDO Mapping
68 MappingDictionary is the structure used for writing a good organised Object
69 Dictionary. It follows the specifications of the CANOpen standard.
70 Change the informations within it if there is a mistake. But don't modify the
71 organisation of this object, it will involve in a malfunction of the application.
75 0x0001 : {"name" : "BOOLEAN", "struct" : nosub, "size" : 1, "default" : False, "values" : []},
76 0x0002 : {"name" : "INTEGER8", "struct" : nosub, "size" : 8, "default" : 0, "values" : []},
77 0x0003 : {"name" : "INTEGER16", "struct" : nosub, "size" : 16, "default" : 0, "values" : []},
78 0x0004 : {"name" : "INTEGER32", "struct" : nosub, "size" : 32, "default" : 0, "values" : []},
79 0x0005 : {"name" : "UNSIGNED8", "struct" : nosub, "size" : 8, "default" : 0, "values" : []},
80 0x0006 : {"name" : "UNSIGNED16", "struct" : nosub, "size" : 16, "default" : 0, "values" : []},
81 0x0007 : {"name" : "UNSIGNED32", "struct" : nosub, "size" : 32, "default" : 0, "values" : []},
82 0x0008 : {"name" : "REAL32", "struct" : nosub, "size" : 32, "default" : 0.0, "values" : []},
83 0x0009 : {"name" : "VISIBLE_STRING", "struct" : nosub, "size" : 8, "default" : "", "values" : []},
84 0x000A : {"name" : "OCTET_STRING", "struct" : nosub, "size" : 8, "default" : "", "values" : []},
85 0x000B : {"name" : "UNICODE_STRING", "struct" : nosub, "size" : 16, "default" : "", "values" : []},
86 0x000C : {"name" : "TIME_OF_DAY", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
87 0x000D : {"name" : "TIME_DIFFERENCE", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
88 # 0x000F : {"name" : "DOMAIN", "struct" : nosub, "size" : 0, "default" : "", "values" : []},
89 0x0010 : {"name" : "INTEGER24", "struct" : nosub, "size" : 24, "default" : 0, "values" : []},
90 0x0011 : {"name" : "REAL64", "struct" : nosub, "size" : 64, "default" : 0.0, "values" : []},
91 0x0012 : {"name" : "INTEGER40", "struct" : nosub, "size" : 40, "default" : 0, "values" : []},
92 0x0013 : {"name" : "INTEGER48", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
93 0x0014 : {"name" : "INTEGER56", "struct" : nosub, "size" : 56, "default" : 0, "values" : []},
94 0x0015 : {"name" : "INTEGER64", "struct" : nosub, "size" : 64, "default" : 0, "values" : []},
95 0x0016 : {"name" : "UNSIGNED24", "struct" : nosub, "size" : 24, "default" : 0, "values" : []},
96 0x0018 : {"name" : "UNSIGNED40", "struct" : nosub, "size" : 40, "default" : 0, "values" : []},
97 0x0019 : {"name" : "UNSIGNED48", "struct" : nosub, "size" : 48, "default" : 0, "values" : []},
98 0x001A : {"name" : "UNSIGNED56", "struct" : nosub, "size" : 56, "default" : 0, "values" : []},
99 0x001B : {"name" : "UNSIGNED64", "struct" : nosub, "size" : 64, "default" : 0, "values" : []},
100 0x1000 : {"name" : "Device Type", "struct" : var, "need" : True, "values" :
101 [{"name" : "Device Type", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
102 0x1001 : {"name" : "Error Register", "struct" : var, "need" : True, "values" :
103 [{"name" : "Error Register", "type" : 0x02, "access": 'ro', "pdo" : True}]},
104 0x1002 : {"name" : "Manufacturer Status Register", "struct" : var, "need" : False, "values" :
105 [{"name" : "Manufacturer Status Register", "type" : 0x04, "access" : 'ro', "pdo" : True}]},
106 0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False, "values" :
107 [{"name" : "Number of Errors", "type" : 0x04, "access" : 'rw', "pdo" : False},
108 {"name" : "Standard Error Field", "type" : 0x04, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]},
109 0x1005 : {"name" : "SYNC COB ID", "struct" : var, "need" : True, "callback" : True, "values" :
110 [{"name" : "SYNC COB ID", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
111 0x1006 : {"name" : "Communication / Cycle Period", "struct" : var, "need" : False, "callback" : True, "values" :
112 [{"name" : "Communication Cycle Period", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
113 0x1007 : {"name" : "Synchronous Window Length", "struct" : var, "need" : False, "values" :
114 [{"name" : "Synchronous Window Length", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
115 0x1008 : {"name" : "Manufacturer Device Name", "struct" : var, "need" : False, "values" :
116 [{"name" : "Manufacturer Device Name", "type" : 0x09, "access" : 'ro', "pdo" : False}]},
117 0x1009 : {"name" : "Manufacturer Hardware Version", "struct" : var, "need" : False, "values" :
118 [{"name" : "Manufacturer Hardware Version", "type" : 0x09, "access" : 'ro', "pdo" : False}]},
119 0x100A : {"name" : "Manufacturer Software Version", "struct" : var, "need" : False, "values" :
120 [{"name" : "Manufacturer Software Version", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
121 0x100C : {"name" : "Guard Time", "struct" : var, "need" : False, "values" :
122 [{"name" : "Guard Time", "type" : 0x03, "access" : 'rw', "pdo" : False}]},
123 0x100D : {"name" : "Life Time Factor", "struct" : var, "need" : False, "values" :
124 [{"name" : "Life Time Factor", "type" : 0x02, "access" : 'rw', "pdo" : False}]},
125 0x1010 : {"name" : "Store parameters", "struct" : array, "need" : False, "values" :
126 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
127 {"name" : "Save All Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False},
128 {"name" : "Save Communication Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False},
129 {"name" : "Save Application Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False},
130 {"name" : "Save Manufacturer Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False, "nbmax" : 0x7C}]},
131 0x1011 : {"name" : "Restore Default Parameters", "struct" : array, "need" : False, "values" :
132 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
133 {"name" : "Restore All Default Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False},
134 {"name" : "Restore Communication Default Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False},
135 {"name" : "Restore Application Default Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False},
136 {"name" : "Restore Manufacturer Default Parameters", "type" : 0x04, "access" : 'rw', "pdo" : False, "nbmax" : 0x7C}]},
137 0x1012 : {"name" : "TIME COB ID", "struct" : var, "need" : False, "values" :
138 [{"name" : "TIME COB ID", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
139 0x1013 : {"name" : "High Resolution Timestamp", "struct" : var, "need" : False, "values" :
140 [{"name" : "High Resolution Time Stamp", "type" : 0x04, "access" : 'rw', "pdo" : True}]},
141 0x1014 : {"name" : "Emergency COB ID", "struct" : var, "need" : False, "values" :
142 [{"name" : "Emergency COB ID", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
143 0x1015 : {"name" : "Inhibit Time Emergency", "struct" : var, "need" : False, "values" :
144 [{"name" : "Inhibit Time Emergency", "type" : 0x03, "access" : 'rw', "pdo" : False}]},
145 0x1016 : {"name" : "Consumer Heartbeat Time", "struct" : rec, "need" : False, "values" :
146 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
147 {"name" : "Consumer Heartbeat Time", "type" : 0x04, "access" : 'rw', "pdo" : False, "nbmax" : 0x7F}]},
148 0x1017 : {"name" : "Producer Heartbeat Time", "struct" : var, "need" : False, "values" :
149 [{"name" : "Producer Heartbeat Time", "type" : 0x03, "access" : 'rw', "pdo" : False}]},
150 0x1018 : {"name" : "Identity", "struct" : array, "need" : True, "values" :
151 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
152 {"name" : "Vendor ID", "type" : 0x04, "access" : 'ro', "pdo" : False},
153 {"name" : "Product Code", "type" : 0x04, "access" : 'ro', "pdo" : False},
154 {"name" : "Revision Number", "type" : 0x04, "access" : 'ro', "pdo" : False},
155 {"name" : "Serial Number", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
156 0x1020 : {"name" : "Verify Configuration", "struct" : array, "need" : False, "values" :
157 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
158 {"name" : "Configuration Date", "type" : 0x04, "access" : 'ro', "pdo" : False},
159 {"name" : "Configuration Time", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
160 # 0x1021 : {"name" : "Store EDS", "struct" : var, "need" : False, "values" :
161 # [{"name" : "Store EDS", "type" : 0x0F, "access" : 'rw', "pdo" : False}]},
162 # 0x1022 : {"name" : "Storage Format", "struct" : var, "need" : False, "values" :
163 # [{"name" : "Storage Format", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
164 0x1023 : {"name" : "OS Command", "struct" : array, "need" : False, "values" :
165 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
166 {"name" : "Command", "type" : 0x0A, "access" : 'rw', "pdo" : False},
167 {"name" : "Status", "type" : 0x02, "access" : 'ro', "pdo" : False},
168 {"name" : "Reply", "type" : 0x0A, "access" : 'ro', "pdo" : False}]},
169 0x1024 : {"name" : "OS Command Mode", "struct" : var, "need" : False, "values" :
170 [{"name" : "OS Command Mode", "type" : 0x02, "access" : 'wo', "pdo" : False}]},
171 0x1025 : {"name" : "OS Debugger Interface", "struct" : array, "need" : False, "values" :
172 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
173 {"name" : "Command", "type" : 0x04, "access" : 'rw', "pdo" : False},
174 {"name" : "Status", "type" : 0x04, "access" : 'ro', "pdo" : False},
175 {"name" : "Reply", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
176 0x1026 : {"name" : "OS Prompt", "struct" : array, "need" : False, "values" :
177 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
178 {"name" : "StdIn", "type" : 0x02, "access" : 'wo', "pdo" : True},
179 {"name" : "StdOut", "type" : 0x02, "access" : 'ro', "pdo" : True},
180 {"name" : "StdErr", "type" : 0x02, "access" : 'ro', "pdo" : True}]},
181 0x1027 : {"name" : "Module List", "struct" : rec, "need" : False, "values" :
182 [{"name" : "Number of Connected Modules", "type" : 0x02, "access" : 'ro', "pdo" : False},
183 {"name" : "Module %d[(sub)]", "type" : 0x03, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]},
184 0x1028 : {"name" : "Emergency Consumer", "struct" : rec, "need" : False, "values" :
185 [{"name" : "Number of Consumed Emergency Objects", "type" : 0x02, "access" : 'ro', "pdo" : False},
186 {"name" : "Emergency Consumer", "type" : 0x04, "access" : 'rw', "pdo" : False, "nbmax" : 0x7E}]},
187 0x1029 : {"name" : "Error Behavior", "struct" : array, "need" : False, "values" :
188 [{"name" : "Number of Error Classes", "type" : 0x02, "access" : 'ro', "pdo" : False},
189 {"name" : "Communication Error", "type" : 0x02, "access" : 'rw', "pdo" : False},
190 {"name" : "Device Profile", "type" : 0x02, "access" : 'rw', "pdo" : False, "nbmax" : 0xFE}]},
191 0x1200 : {"name" : "Server SDO Parameter", "struct" : array, "need" : False, "values" :
192 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
193 {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x04, "access" : 'ro', "pdo" : False},
194 {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
195 0x1201 : {"name" : "Additional Server SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x7F, "need" : False, "values" :
196 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
197 {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x04, "access" : 'ro', "pdo" : False},
198 {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x04, "access" : 'ro', "pdo" : False},
199 {"name" : "Node ID of the SDO Client", "type" : 0x04, "access" : 'ro', "pdo" : False}]},
200 0x1280 : {"name" : "Client SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x100, "need" : False, "values" :
201 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
202 {"name" : "COB ID Client to Server (Transmit SDO)", "type" : 0x04, "access" : 'rw', "pdo" : False},
203 {"name" : "COB ID Server to Client (Receive SDO)", "type" : 0x04, "access" : 'rw', "pdo" : False},
204 {"name" : "Node ID of the SDO Server", "type" : 0x04, "access" : 'rw', "pdo" : False}]},
205 0x1400 : {"name" : "Receive PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
206 [{"name" : "Highest SubIndex Supported", "type" : 0x02, "access" : 'ro', "pdo" : False},
207 {"name" : "COB ID used by PDO", "type" : 0x04, "access" : 'rw', "pdo" : False},
208 {"name" : "Transmission Type", "type" : 0x02, "access" : 'rw', "pdo" : False},
209 {"name" : "Inhibit Time", "type" : 0x03, "access" : 'rw', "pdo" : False},
210 {"name" : "Compatibility Entry", "type" : 0x03, "access" : 'rw', "pdo" : False},
211 {"name" : "Event Timer", "type" : 0x03, "access" : 'rw', "pdo" : False}]},
212 0x1600 : {"name" : "Receive PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
213 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
214 {"name" : "PDO %d Mapping for an application object %d[(idx,sub)]", "type" : 0x04, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]},
215 0x1800 : {"name" : "Transmit PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
216 [{"name" : "Highest SubIndex Supported", "type" : 0x02, "access" : 'ro', "pdo" : False},
217 {"name" : "COB ID used by PDO", "type" : 0x04, "access" : 'rw', "pdo" : False},
218 {"name" : "Transmission Type", "type" : 0x02, "access" : 'rw', "pdo" : False},
219 {"name" : "Inhibit Time", "type" : 0x03, "access" : 'rw', "pdo" : False},
220 {"name" : "Compatibility Entry", "type" : 0x03, "access" : 'rw', "pdo" : False},
221 {"name" : "Event Timer", "type" : 0x03, "access" : 'rw', "pdo" : False}]},
222 0x1A00 : {"name" : "Transmit PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
223 [{"name" : "Number of Entries", "type" : 0x02, "access" : 'ro', "pdo" : False},
224 {"name" : "PDO %d Mapping for a process data variable %d[(idx,sub)]", "type" : 0x04, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]},
227 #-------------------------------------------------------------------------------
228 # Definition of Node Object
229 #-------------------------------------------------------------------------------
232 Class recording the Object Dictionary entries. It checks at each modification
233 that the structure of the Object Dictionary stay coherent
238 def __init__(self, name = "", type = "slave", id = 0, profilename = "DS-301", profile = {}, specificmenu = []):
242 self.ProfileName = profilename
243 self.Profile = profile
244 self.SpecificMenu = specificmenu
246 self.ParamsDictionary = {}
248 self.UserMapping = {}
253 def GetNodeName(self):
259 def SetNodeName(self, name):
263 Return the node type ("master" or "slave")
265 def GetNodeType(self):
269 Define the node type ("master" or "slave")
271 def SetNodeType(self, type):
283 def SetNodeID(self, id):
287 Return the Specific Profile Name
289 def GetProfileName(self):
290 return self.ProfileName
293 Define the Specific Profile Name
295 def SetProfileName(self, profilename):
296 self.ProfileName = profilename
299 Return the Specific Profile
301 def GetProfile(self):
305 Define the Specific Profile
307 def SetProfile(self, profile):
308 self.Profile = profile
311 Define the DS-302 Profile
313 def SetDS302Profile(self, profile):
317 Define the DS-302 Profile
319 def GetDS302Profile(self):
323 Return the Specific Menu Entries
325 def GetSpecificMenu(self):
326 return self.SpecificMenu
329 Define the Specific Menu Entries
331 def SetSpecificMenu(self, specificmenu):
332 self.SpecificMenu = specificmenu
335 Extend the Specific Menu Entries
338 def ExtendSpecificMenu(self, specificmenu):
339 self.SpecificMenu.extend(AddMenuEntries)
342 Function which return the different Mappings available for this node
344 def GetMappings(self, userdefinedtoo = True):
346 return [self.Profile, self.DS302, self.UserMapping]
348 return [self.Profile, self.DS302]
351 Add a new entry in the Object Dictionary
353 def AddEntry(self, index, subIndex = None, value = None):
354 if index not in self.Dictionary:
356 self.Dictionary[index] = value
359 self.Dictionary[index] = [value]
361 elif subIndex > 1 and type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]) + 1:
362 self.Dictionary[index].append(value)
367 Warning ! Modifies an existing entry in the Object Dictionary. Can't add a new one.
369 def SetEntry(self, index, subIndex = None, value = None):
370 if index in self.Dictionary:
373 self.Dictionary[index] = value
375 elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]):
377 self.Dictionary[index][subIndex - 1] = value
381 def SetParamsEntry(self, index, subIndex = None, comment = None, save = None, callback = None):
382 if not getattr(self, "ParamsDictionary", False):
383 self.ParamsDictionary = {}
384 if index in self.Dictionary:
385 if (comment != None or save != None or callback != None) and index not in self.ParamsDictionary:
386 self.ParamsDictionary[index] = {}
387 if subIndex == None or type(self.Dictionary[index]) != ListType and subIndex == 0:
389 self.ParamsDictionary[index]["comment"] = comment
391 self.ParamsDictionary[index]["save"] = save
393 self.ParamsDictionary[index]["callback"] = callback
395 elif type(self.Dictionary[index]) == ListType and 0 <= subIndex <= len(self.Dictionary[index]):
396 if (comment != None or save != None or callback != None) and subIndex not in self.ParamsDictionary[index]:
397 self.ParamsDictionary[index][subIndex] = {}
399 self.ParamsDictionary[index][subIndex]["comment"] = comment
401 self.ParamsDictionary[index][subIndex]["save"] = save
406 Removes an existing entry in the Object Dictionary. If a subIndex is specified
407 it will remove this subIndex only if it's the last of the index. If no subIndex
408 is specified it removes the whole index and subIndexes from the Object Dictionary.
410 def RemoveEntry(self, index, subIndex = None):
411 if not getattr(self, "ParamsDictionary", False):
412 self.ParamsDictionary = {}
413 if index in self.Dictionary:
415 self.Dictionary.pop(index)
416 if index in self.ParamsDictionary:
417 self.ParamsDictionary.pop(index)
419 elif type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]):
420 self.Dictionary[index].pop(subIndex - 1)
421 if index in self.ParamsDictionary:
422 if subIndex in self.ParamsDictionary[index]:
423 self.ParamsDictionary[index].pop(subIndex)
424 if len(self.ParamsDictionary[index]) == 0:
425 self.ParamsDictionary.pop(index)
426 if len(self.Dictionary[index]) == 0:
427 self.Dictionary.pop(index)
428 if index in self.ParamsDictionary:
429 self.ParamsDictionary.pop(index)
434 Check if an entry exists in the Object Dictionary and returns the answer.
436 def IsEntry(self, index):
437 if index in self.Dictionary:
442 Returns the value of the entry asked. If the entry has the value "count", it
443 returns the number of subIndex in the entry except the first.
445 def GetEntry(self, index, subIndex = None):
446 if index in self.Dictionary:
448 if type(self.Dictionary[index]) == ListType:
449 values = [len(self.Dictionary[index])]
450 values.extend(self.Dictionary[index])
453 return self.Dictionary[index]
455 if type(self.Dictionary[index]) == ListType:
456 return len(self.Dictionary[index])
458 return self.Dictionary[index]
459 elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]):
460 return self.Dictionary[index][subIndex - 1]
464 Returns the value of the entry asked. If the entry has the value "count", it
465 returns the number of subIndex in the entry except the first.
467 def GetParamsEntry(self, index, subIndex = None):
468 if not getattr(self, "ParamsDictionary", False):
469 self.ParamsDictionary = {}
470 if index in self.Dictionary:
472 if type(self.Dictionary[index]) == ListType:
473 if index in self.ParamsDictionary:
475 for i in xrange(len(self.Dictionary[index]) + 1):
476 line = DefaultParams.copy()
477 if i in self.ParamsDictionary[index]:
478 line.update(self.ParamsDictionary[index][i])
482 return [DefaultParams.copy() for i in xrange(len(self.Dictionary[index]) + 1)]
484 result = DefaultParams.copy()
485 if index in self.ParamsDictionary:
486 result.update(self.ParamsDictionary[index])
488 elif subIndex == 0 and type(self.Dictionary[index]) != ListType:
489 result = DefaultParams.copy()
490 if index in self.ParamsDictionary:
491 result.update(self.ParamsDictionary[index])
493 elif type(self.Dictionary[index]) == ListType and 0 <= subIndex <= len(self.Dictionary[index]):
494 result = DefaultParams.copy()
495 if index in self.ParamsDictionary and subIndex in self.ParamsDictionary[index]:
496 result.update(self.Dictionary[index][subIndex])
500 def HasEntryCallbacks(self, index):
501 if not getattr(self, "ParamsDictionary", False):
502 self.ParamsDictionary = {}
503 if index in self.Dictionary and index in self.ParamsDictionary and "callback" in self.ParamsDictionary[index]:
504 return self.ParamsDictionary[index]["callback"]
508 Add a new entry in the User Mapping Dictionary
510 def AddMappingEntry(self, index, subIndex = None, name = "Undefined", struct = 0, size = None, nbmax = None, default = None, values = None):
511 if index not in self.UserMapping:
515 self.UserMapping[index] = {"name" : name, "struct" : struct, "need" : False, "values" : values}
517 self.UserMapping[index]["size"] = size
519 self.UserMapping[index]["nbmax"] = nbmax
521 self.UserMapping[index]["default"] = default
523 elif subIndex != None and subIndex == len(self.UserMapping[index]["values"]):
526 self.UserMapping[index]["values"].append(values)
531 Warning ! Modifies an existing entry in the User Mapping Dictionary. Can't add a new one.
533 def SetMappingEntry(self, index, subIndex = None, name = None, struct = None, size = None, nbmax = None, default = None, values = None):
534 if index in self.UserMapping:
537 self.UserMapping[index]["name"] = name
538 if self.UserMapping[index]["struct"] & OD_IdenticalSubindexes:
539 self.UserMapping[index]["values"][1]["name"] = name + " %d[(sub)]"
540 elif not self.UserMapping[index]["struct"] & OD_MultipleSubindexes:
541 self.UserMapping[index]["values"][0]["name"] = name
543 self.UserMapping[index]["struct"] = struct
545 self.UserMapping[index]["size"] = size
547 self.UserMapping[index]["nbmax"] = nbmax
549 self.UserMapping[index]["default"] = default
551 self.UserMapping[index]["values"] = values
553 elif 0 <= subIndex < len(self.UserMapping[index]["values"]) and values != None:
554 self.UserMapping[index]["values"][subIndex].update(values)
559 Removes an existing entry in the User Mapping Dictionary. If a subIndex is specified
560 it will remove this subIndex only if it's the last of the index. If no subIndex
561 is specified it removes the whole index and subIndexes from the User Mapping Dictionary.
563 def RemoveMappingEntry(self, index, subIndex = None):
564 if index in self.UserMapping:
566 self.UserMapping.pop(index)
568 elif subIndex == len(self.UserMapping[index]["values"]) - 1:
569 self.UserMapping[index]["values"].pop(subIndex)
573 def RemoveMapVariable(self, index, subIndex):
577 model += subIndex << 8
579 for i in self.Dictionary.iterkeys():
580 if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF:
581 for j,value in enumerate(self.Dictionary[i]):
582 if (value & mask) == model:
583 self.Dictionary[i][j] = 0
585 def RemoveLine(self, index, max, incr = 1):
587 while i < max and self.IsEntry(i + incr):
588 self.Dictionary[i] = self.Dictionary[i + incr]
590 self.Dictionary.pop(i)
592 def RemoveUserType(self, index):
593 type = self.GetEntry(index, 1)
594 for i in self.UserMapping:
595 for value in self.UserMapping[i]["values"]:
596 if value["type"] == index:
598 self.RemoveMappingEntry(index)
599 self.RemoveEntry(index)
602 Return a copy of the node
605 return cPickle.loads(cPickle.dumps(self))
608 Return a sorted list of indexes in Object Dictionary
610 def GetIndexes(self):
611 listindex = self.Dictionary.keys()
616 Print the Dictionary values
619 listindex = self.Dictionary.keys()
621 for index in listindex:
622 print "%04X : %s"%(index, self.Dictionary[index])