author | etisserant |
Fri, 21 Sep 2007 08:04:00 +0200 | |
changeset 278 | 9d41c53dadac |
parent 274 | 39beb1c7542a |
child 281 | 685d9a26e4f9 |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of CanFestival, a library implementing CanOpen Stack. |
|
5 |
# |
|
6 |
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
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. |
|
14 |
# |
|
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. |
|
19 |
# |
|
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 |
|
23 |
||
24 |
import cPickle |
|
25 |
from types import * |
|
205 | 26 |
import re |
0 | 27 |
|
28 |
""" |
|
29 |
Dictionary of translation between access symbol and their signification |
|
30 |
""" |
|
31 |
AccessType = {"ro" : "Read Only", "wo" : "Write Only", "rw" : "Read/Write"} |
|
32 |
||
33 |
BoolType = {True : "True", False : "False"} |
|
34 |
OptionType = {True : "Yes", False : "No"} |
|
35 |
||
36 |
CustomisableTypes = [(0x02, 0), (0x03, 0), (0x04, 0), (0x05, 0), (0x06, 0), (0x07, 0), |
|
37 |
(0x08, 0), (0x09, 1), (0x0A, 1), (0x0B, 1), (0x10, 0), (0x11, 0), (0x12, 0), |
|
38 |
(0x13, 0), (0x14, 0), (0x15, 0), (0x16, 0), (0x18, 0), (0x19, 0), (0x1A, 0), |
|
39 |
(0x1B, 0)] |
|
40 |
||
41 |
DefaultParams = {"comment" : "", "save" : False} |
|
42 |
||
43 |
#------------------------------------------------------------------------------- |
|
44 |
# Dictionary Mapping and Organisation |
|
45 |
#------------------------------------------------------------------------------- |
|
46 |
||
47 |
""" |
|
48 |
Properties of entry structure in the Object Dictionary |
|
49 |
""" |
|
50 |
OD_Subindex = 1 # Entry has at least one subindex |
|
51 |
OD_MultipleSubindexes = 2 # Entry has more than one subindex |
|
52 |
OD_IdenticalSubindexes = 4 # Subindexes of entry have the same description |
|
53 |
OD_IdenticalIndexes = 8 # Entry has the same description on multiple indexes |
|
54 |
||
55 |
""" |
|
56 |
Structures of entry in the Object Dictionary, sum of the properties described above |
|
57 |
for all sorts of entries use in CAN Open specification |
|
58 |
""" |
|
59 |
nosub = 0 # Entry without subindex (only for type declaration) |
|
260 | 60 |
var = OD_Subindex |
61 |
array = OD_Subindex | OD_MultipleSubindexes |
|
62 |
rec = OD_Subindex | OD_MultipleSubindexes | OD_IdenticalSubindexes |
|
0 | 63 |
# Entries identical on multiple indexes |
260 | 64 |
plurivar = OD_Subindex | OD_IdenticalIndexes |
65 |
pluriarray = OD_Subindex | OD_MultipleSubindexes | OD_IdenticalIndexes # Example : PDO Parameters |
|
66 |
plurirec = OD_Subindex | OD_MultipleSubindexes | OD_IdenticalSubindexes |OD_IdenticalIndexes # Example : PDO Mapping |
|
0 | 67 |
|
68 |
""" |
|
69 |
MappingDictionary is the structure used for writing a good organised Object |
|
70 |
Dictionary. It follows the specifications of the CANOpen standard. |
|
71 |
Change the informations within it if there is a mistake. But don't modify the |
|
72 |
organisation of this object, it will involve in a malfunction of the application. |
|
73 |
""" |
|
74 |
||
75 |
MappingDictionary = { |
|
76 |
0x0001 : {"name" : "BOOLEAN", "struct" : nosub, "size" : 1, "default" : False, "values" : []}, |
|
77 |
0x0002 : {"name" : "INTEGER8", "struct" : nosub, "size" : 8, "default" : 0, "values" : []}, |
|
78 |
0x0003 : {"name" : "INTEGER16", "struct" : nosub, "size" : 16, "default" : 0, "values" : []}, |
|
79 |
0x0004 : {"name" : "INTEGER32", "struct" : nosub, "size" : 32, "default" : 0, "values" : []}, |
|
80 |
0x0005 : {"name" : "UNSIGNED8", "struct" : nosub, "size" : 8, "default" : 0, "values" : []}, |
|
81 |
0x0006 : {"name" : "UNSIGNED16", "struct" : nosub, "size" : 16, "default" : 0, "values" : []}, |
|
82 |
0x0007 : {"name" : "UNSIGNED32", "struct" : nosub, "size" : 32, "default" : 0, "values" : []}, |
|
83 |
0x0008 : {"name" : "REAL32", "struct" : nosub, "size" : 32, "default" : 0.0, "values" : []}, |
|
84 |
0x0009 : {"name" : "VISIBLE_STRING", "struct" : nosub, "size" : 8, "default" : "", "values" : []}, |
|
85 |
0x000A : {"name" : "OCTET_STRING", "struct" : nosub, "size" : 8, "default" : "", "values" : []}, |
|
86 |
0x000B : {"name" : "UNICODE_STRING", "struct" : nosub, "size" : 16, "default" : "", "values" : []}, |
|
67 | 87 |
# 0x000C : {"name" : "TIME_OF_DAY", "struct" : nosub, "size" : 48, "default" : 0, "values" : []}, |
88 |
# 0x000D : {"name" : "TIME_DIFFERENCE", "struct" : nosub, "size" : 48, "default" : 0, "values" : []}, |
|
176 | 89 |
0x000F : {"name" : "DOMAIN", "struct" : nosub, "size" : 0, "default" : "", "values" : []}, |
0 | 90 |
0x0010 : {"name" : "INTEGER24", "struct" : nosub, "size" : 24, "default" : 0, "values" : []}, |
91 |
0x0011 : {"name" : "REAL64", "struct" : nosub, "size" : 64, "default" : 0.0, "values" : []}, |
|
92 |
0x0012 : {"name" : "INTEGER40", "struct" : nosub, "size" : 40, "default" : 0, "values" : []}, |
|
93 |
0x0013 : {"name" : "INTEGER48", "struct" : nosub, "size" : 48, "default" : 0, "values" : []}, |
|
94 |
0x0014 : {"name" : "INTEGER56", "struct" : nosub, "size" : 56, "default" : 0, "values" : []}, |
|
95 |
0x0015 : {"name" : "INTEGER64", "struct" : nosub, "size" : 64, "default" : 0, "values" : []}, |
|
96 |
0x0016 : {"name" : "UNSIGNED24", "struct" : nosub, "size" : 24, "default" : 0, "values" : []}, |
|
97 |
0x0018 : {"name" : "UNSIGNED40", "struct" : nosub, "size" : 40, "default" : 0, "values" : []}, |
|
98 |
0x0019 : {"name" : "UNSIGNED48", "struct" : nosub, "size" : 48, "default" : 0, "values" : []}, |
|
99 |
0x001A : {"name" : "UNSIGNED56", "struct" : nosub, "size" : 56, "default" : 0, "values" : []}, |
|
100 |
0x001B : {"name" : "UNSIGNED64", "struct" : nosub, "size" : 64, "default" : 0, "values" : []}, |
|
101 |
0x1000 : {"name" : "Device Type", "struct" : var, "need" : True, "values" : |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
102 |
[{"name" : "Device Type", "type" : 0x07, "access" : 'ro', "pdo" : False}]}, |
0 | 103 |
0x1001 : {"name" : "Error Register", "struct" : var, "need" : True, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
104 |
[{"name" : "Error Register", "type" : 0x05, "access": 'ro', "pdo" : True}]}, |
0 | 105 |
0x1002 : {"name" : "Manufacturer Status Register", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
106 |
[{"name" : "Manufacturer Status Register", "type" : 0x07, "access" : 'ro', "pdo" : True}]}, |
0 | 107 |
0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
108 |
[{"name" : "Number of Errors", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
109 |
{"name" : "Standard Error Field", "type" : 0x07, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]}, |
258 | 110 |
0x1005 : {"name" : "SYNC COB ID", "struct" : var, "need" : False, "callback" : True, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
111 |
[{"name" : "SYNC COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, |
0 | 112 |
0x1006 : {"name" : "Communication / Cycle Period", "struct" : var, "need" : False, "callback" : True, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
113 |
[{"name" : "Communication Cycle Period", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, |
0 | 114 |
0x1007 : {"name" : "Synchronous Window Length", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
115 |
[{"name" : "Synchronous Window Length", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, |
0 | 116 |
0x1008 : {"name" : "Manufacturer Device Name", "struct" : var, "need" : False, "values" : |
117 |
[{"name" : "Manufacturer Device Name", "type" : 0x09, "access" : 'ro', "pdo" : False}]}, |
|
118 |
0x1009 : {"name" : "Manufacturer Hardware Version", "struct" : var, "need" : False, "values" : |
|
119 |
[{"name" : "Manufacturer Hardware Version", "type" : 0x09, "access" : 'ro', "pdo" : False}]}, |
|
120 |
0x100A : {"name" : "Manufacturer Software Version", "struct" : var, "need" : False, "values" : |
|
62 | 121 |
[{"name" : "Manufacturer Software Version", "type" : 0x09, "access" : 'ro', "pdo" : False}]}, |
0 | 122 |
0x100C : {"name" : "Guard Time", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
123 |
[{"name" : "Guard Time", "type" : 0x06, "access" : 'rw', "pdo" : False}]}, |
0 | 124 |
0x100D : {"name" : "Life Time Factor", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
125 |
[{"name" : "Life Time Factor", "type" : 0x05, "access" : 'rw', "pdo" : False}]}, |
0 | 126 |
0x1010 : {"name" : "Store parameters", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
127 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
128 |
{"name" : "Save All Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
129 |
{"name" : "Save Communication Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
130 |
{"name" : "Save Application Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
131 |
{"name" : "Save Manufacturer Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7C}]}, |
0 | 132 |
0x1011 : {"name" : "Restore Default Parameters", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
133 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
134 |
{"name" : "Restore All Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
135 |
{"name" : "Restore Communication Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
136 |
{"name" : "Restore Application Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
137 |
{"name" : "Restore Manufacturer Default Parameters", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7C}]}, |
0 | 138 |
0x1012 : {"name" : "TIME COB ID", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
139 |
[{"name" : "TIME COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, |
0 | 140 |
0x1013 : {"name" : "High Resolution Timestamp", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
141 |
[{"name" : "High Resolution Time Stamp", "type" : 0x07, "access" : 'rw', "pdo" : True}]}, |
0 | 142 |
0x1014 : {"name" : "Emergency COB ID", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
143 |
[{"name" : "Emergency COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, |
0 | 144 |
0x1015 : {"name" : "Inhibit Time Emergency", "struct" : var, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
145 |
[{"name" : "Inhibit Time Emergency", "type" : 0x06, "access" : 'rw', "pdo" : False}]}, |
0 | 146 |
0x1016 : {"name" : "Consumer Heartbeat Time", "struct" : rec, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
147 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
148 |
{"name" : "Consumer Heartbeat Time", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7F}]}, |
177 | 149 |
0x1017 : {"name" : "Producer Heartbeat Time", "struct" : var, "need" : False, "callback" : True, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
150 |
[{"name" : "Producer Heartbeat Time", "type" : 0x06, "access" : 'rw', "pdo" : False}]}, |
0 | 151 |
0x1018 : {"name" : "Identity", "struct" : array, "need" : True, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
152 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
153 |
{"name" : "Vendor ID", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
154 |
{"name" : "Product Code", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
155 |
{"name" : "Revision Number", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
156 |
{"name" : "Serial Number", "type" : 0x07, "access" : 'ro', "pdo" : False}]}, |
0 | 157 |
0x1020 : {"name" : "Verify Configuration", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
158 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
159 |
{"name" : "Configuration Date", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
160 |
{"name" : "Configuration Time", "type" : 0x07, "access" : 'ro', "pdo" : False}]}, |
59 | 161 |
# 0x1021 : {"name" : "Store EDS", "struct" : var, "need" : False, "values" : |
162 |
# [{"name" : "Store EDS", "type" : 0x0F, "access" : 'rw', "pdo" : False}]}, |
|
163 |
# 0x1022 : {"name" : "Storage Format", "struct" : var, "need" : False, "values" : |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
164 |
# [{"name" : "Storage Format", "type" : 0x06, "access" : 'rw', "pdo" : False}]}, |
0 | 165 |
0x1023 : {"name" : "OS Command", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
166 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
0 | 167 |
{"name" : "Command", "type" : 0x0A, "access" : 'rw', "pdo" : False}, |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
168 |
{"name" : "Status", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
0 | 169 |
{"name" : "Reply", "type" : 0x0A, "access" : 'ro', "pdo" : False}]}, |
170 |
0x1024 : {"name" : "OS Command Mode", "struct" : var, "need" : False, "values" : |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
171 |
[{"name" : "OS Command Mode", "type" : 0x05, "access" : 'wo', "pdo" : False}]}, |
0 | 172 |
0x1025 : {"name" : "OS Debugger Interface", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
173 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
174 |
{"name" : "Command", "type" : 0x0A, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
175 |
{"name" : "Status", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
176 |
{"name" : "Reply", "type" : 0x0A, "access" : 'ro', "pdo" : False}]}, |
0 | 177 |
0x1026 : {"name" : "OS Prompt", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
178 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
179 |
{"name" : "StdIn", "type" : 0x05, "access" : 'wo', "pdo" : True}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
180 |
{"name" : "StdOut", "type" : 0x05, "access" : 'ro', "pdo" : True}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
181 |
{"name" : "StdErr", "type" : 0x05, "access" : 'ro', "pdo" : True}]}, |
0 | 182 |
0x1027 : {"name" : "Module List", "struct" : rec, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
183 |
[{"name" : "Number of Connected Modules", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
184 |
{"name" : "Module %d[(sub)]", "type" : 0x06, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]}, |
0 | 185 |
0x1028 : {"name" : "Emergency Consumer", "struct" : rec, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
186 |
[{"name" : "Number of Consumed Emergency Objects", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
187 |
{"name" : "Emergency Consumer", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7E}]}, |
0 | 188 |
0x1029 : {"name" : "Error Behavior", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
189 |
[{"name" : "Number of Error Classes", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
190 |
{"name" : "Communication Error", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
191 |
{"name" : "Device Profile", "type" : 0x05, "access" : 'rw', "pdo" : False, "nbmax" : 0xFE}]}, |
0 | 192 |
0x1200 : {"name" : "Server SDO Parameter", "struct" : array, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
193 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
194 |
{"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
195 |
{"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False}]}, |
0 | 196 |
0x1201 : {"name" : "Additional Server SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x7F, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
197 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
198 |
{"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
199 |
{"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
200 |
{"name" : "Node ID of the SDO Client", "type" : 0x05, "access" : 'ro', "pdo" : False}]}, |
0 | 201 |
0x1280 : {"name" : "Client SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x100, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
202 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
203 |
{"name" : "COB ID Client to Server (Transmit SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
204 |
{"name" : "COB ID Server to Client (Receive SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False}, |
273 | 205 |
{"name" : "Node ID of the SDO Server", "type" : 0x05, "access" : 'rw', "pdo" : False}]}, |
0 | 206 |
0x1400 : {"name" : "Receive PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
207 |
[{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
205 | 208 |
{"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+2)*0x100,False:0}[base<4]"}, |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
209 |
{"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
210 |
{"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
211 |
{"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
212 |
{"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]}, |
0 | 213 |
0x1600 : {"name" : "Receive PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
214 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
215 |
{"name" : "PDO %d Mapping for an application object %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]}, |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
227
diff
changeset
|
216 |
0x1800 : {"name" : "Transmit PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "callback" : True, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
217 |
[{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False}, |
205 | 218 |
{"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+1)*0x100+0x80,False:0}[base<4]"}, |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
219 |
{"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
220 |
{"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
221 |
{"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
222 |
{"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]}, |
0 | 223 |
0x1A00 : {"name" : "Transmit PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" : |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
224 |
[{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False}, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
225 |
{"name" : "PDO %d Mapping for a process data variable %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]}, |
0 | 226 |
} |
227 |
||
228 |
#------------------------------------------------------------------------------- |
|
205 | 229 |
# Search in a Mapping Dictionary |
230 |
#------------------------------------------------------------------------------- |
|
231 |
||
232 |
""" |
|
233 |
Return the index of the typename given by searching in mappingdictionary |
|
234 |
""" |
|
235 |
def FindTypeIndex(typename, mappingdictionary): |
|
236 |
testdic = {} |
|
237 |
for index, values in mappingdictionary.iteritems(): |
|
238 |
if index < 0x1000: |
|
239 |
testdic[values["name"]] = index |
|
240 |
if typename in testdic: |
|
241 |
return testdic[typename] |
|
242 |
return None |
|
243 |
||
244 |
""" |
|
245 |
Return the name of the type by searching in mappingdictionary |
|
246 |
""" |
|
247 |
def FindTypeName(typeindex, mappingdictionary): |
|
248 |
if typeindex < 0x1000 and typeindex in mappingdictionary: |
|
249 |
return mappingdictionary[typeindex]["name"] |
|
250 |
return None |
|
251 |
||
252 |
""" |
|
253 |
Return the default value of the type by searching in mappingdictionary |
|
254 |
""" |
|
255 |
def FindTypeDefaultValue(typeindex, mappingdictionary): |
|
256 |
if typeindex < 0x1000 and typeindex in mappingdictionary: |
|
257 |
return mappingdictionary[typeindex]["default"] |
|
258 |
return None |
|
259 |
||
260 |
""" |
|
261 |
Return the list of types defined in mappingdictionary |
|
262 |
""" |
|
263 |
def FindTypeList(mappingdictionary): |
|
264 |
list = [] |
|
265 |
for index in mappingdictionary.keys(): |
|
266 |
if index < 0x1000: |
|
267 |
list.append(mappingdictionary[index]["name"]) |
|
268 |
return list |
|
269 |
||
270 |
""" |
|
271 |
Return the name of an entry by searching in mappingdictionary |
|
272 |
""" |
|
273 |
def FindEntryName(index, mappingdictionary): |
|
274 |
base_index = FindIndex(index, mappingdictionary) |
|
275 |
if base_index: |
|
276 |
infos = mappingdictionary[base_index] |
|
277 |
if infos["struct"] & OD_IdenticalIndexes: |
|
278 |
return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0) |
|
279 |
else: |
|
280 |
return infos["name"] |
|
281 |
return None |
|
282 |
||
283 |
""" |
|
284 |
Return the informations of one entry by searching in mappingdictionary |
|
285 |
""" |
|
286 |
def FindEntryInfos(index, mappingdictionary): |
|
287 |
base_index = FindIndex(index, mappingdictionary) |
|
288 |
if base_index: |
|
289 |
copy = mappingdictionary[base_index].copy() |
|
290 |
if copy["struct"] & OD_IdenticalIndexes: |
|
291 |
copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0) |
|
292 |
copy.pop("values") |
|
293 |
return copy |
|
294 |
return None |
|
295 |
||
296 |
""" |
|
297 |
Return the informations of one subentry of an entry by searching in mappingdictionary |
|
298 |
""" |
|
299 |
def FindSubentryInfos(index, subIndex, mappingdictionary): |
|
300 |
base_index = FindIndex(index, mappingdictionary) |
|
301 |
if base_index: |
|
302 |
struct = mappingdictionary[base_index]["struct"] |
|
303 |
if struct & OD_Subindex: |
|
304 |
if struct & OD_IdenticalSubindexes: |
|
305 |
if struct & OD_IdenticalIndexes: |
|
306 |
incr = mappingdictionary[base_index]["incr"] |
|
307 |
else: |
|
308 |
incr = 1 |
|
309 |
if subIndex == 0: |
|
310 |
return mappingdictionary[base_index]["values"][0].copy() |
|
311 |
elif 0 < subIndex <= mappingdictionary[base_index]["values"][1]["nbmax"]: |
|
312 |
copy = mappingdictionary[base_index]["values"][1].copy() |
|
313 |
copy["name"] = StringFormat(copy["name"], (index - base_index) / incr + 1, subIndex) |
|
314 |
return copy |
|
315 |
elif struct & OD_MultipleSubindexes and 0 <= subIndex < len(mappingdictionary[base_index]["values"]): |
|
316 |
return mappingdictionary[base_index]["values"][subIndex].copy() |
|
317 |
elif subIndex == 0: |
|
318 |
return mappingdictionary[base_index]["values"][0].copy() |
|
319 |
return None |
|
320 |
||
321 |
""" |
|
322 |
Return the list of variables that can be mapped defined in mappingdictionary |
|
323 |
""" |
|
324 |
def FindMapVariableList(mappingdictionary, Node): |
|
325 |
list = [] |
|
326 |
for index in mappingdictionary.iterkeys(): |
|
327 |
if Node.IsEntry(index): |
|
328 |
for subIndex, values in enumerate(mappingdictionary[index]["values"]): |
|
329 |
if mappingdictionary[index]["values"][subIndex]["pdo"]: |
|
330 |
infos = Node.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"]) |
|
331 |
if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes: |
|
332 |
values = Node.GetEntry(index) |
|
333 |
for i in xrange(len(values) - 1): |
|
334 |
list.append((index, i + 1, infos["size"], StringFormat(mappingdictionary[index]["values"][subIndex]["name"],1,i+1))) |
|
335 |
else: |
|
336 |
list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"])) |
|
337 |
return list |
|
338 |
||
339 |
""" |
|
340 |
Return the list of mandatory indexes defined in mappingdictionary |
|
341 |
""" |
|
342 |
def FindMandatoryIndexes(mappingdictionary): |
|
343 |
list = [] |
|
344 |
for index in mappingdictionary.iterkeys(): |
|
345 |
if index >= 0x1000 and mappingdictionary[index]["need"]: |
|
346 |
list.append(index) |
|
347 |
return list |
|
348 |
||
349 |
""" |
|
350 |
Return the index of the informations in the Object Dictionary in case of identical |
|
351 |
indexes |
|
352 |
""" |
|
353 |
def FindIndex(index, mappingdictionary): |
|
354 |
if index in mappingdictionary: |
|
355 |
return index |
|
356 |
else: |
|
357 |
listpluri = [idx for idx in mappingdictionary.keys() if mappingdictionary[idx]["struct"] & OD_IdenticalIndexes] |
|
358 |
listpluri.sort() |
|
359 |
for idx in listpluri: |
|
360 |
nb_max = mappingdictionary[idx]["nbmax"] |
|
361 |
incr = mappingdictionary[idx]["incr"] |
|
362 |
if idx < index < idx + incr * nb_max and (index - idx)%incr == 0: |
|
363 |
return idx |
|
364 |
return None |
|
365 |
||
366 |
#------------------------------------------------------------------------------- |
|
367 |
# Formating Name of an Entry |
|
368 |
#------------------------------------------------------------------------------- |
|
369 |
||
370 |
name_model = re.compile('(.*)\[(.*)\]') |
|
371 |
||
372 |
""" |
|
373 |
Format the text given with the index and subindex defined |
|
374 |
""" |
|
375 |
def StringFormat(text, idx, sub): |
|
376 |
result = name_model.match(text) |
|
377 |
if result: |
|
378 |
format = result.groups() |
|
379 |
return format[0]%eval(format[1]) |
|
380 |
else: |
|
381 |
return text |
|
382 |
||
383 |
#------------------------------------------------------------------------------- |
|
0 | 384 |
# Definition of Node Object |
385 |
#------------------------------------------------------------------------------- |
|
386 |
||
387 |
""" |
|
388 |
Class recording the Object Dictionary entries. It checks at each modification |
|
389 |
that the structure of the Object Dictionary stay coherent |
|
390 |
""" |
|
391 |
||
392 |
class Node: |
|
393 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
394 |
def __init__(self, name = "", type = "slave", id = 0, description = "", profilename = "DS-301", profile = {}, specificmenu = []): |
0 | 395 |
self.Name = name |
396 |
self.Type = type |
|
397 |
self.ID = id |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
398 |
self.Description = description |
0 | 399 |
self.ProfileName = profilename |
400 |
self.Profile = profile |
|
401 |
self.SpecificMenu = specificmenu |
|
402 |
self.Dictionary = {} |
|
403 |
self.ParamsDictionary = {} |
|
404 |
self.DS302 = {} |
|
405 |
self.UserMapping = {} |
|
406 |
||
407 |
""" |
|
408 |
Return the node name |
|
409 |
""" |
|
410 |
def GetNodeName(self): |
|
411 |
return self.Name |
|
412 |
||
413 |
""" |
|
414 |
Define the node name |
|
415 |
""" |
|
416 |
def SetNodeName(self, name): |
|
417 |
self.Name = name |
|
418 |
||
419 |
""" |
|
420 |
Return the node type ("master" or "slave") |
|
421 |
""" |
|
422 |
def GetNodeType(self): |
|
423 |
return self.Type |
|
424 |
||
425 |
""" |
|
426 |
Define the node type ("master" or "slave") |
|
427 |
""" |
|
428 |
def SetNodeType(self, type): |
|
429 |
self.Type = type |
|
430 |
||
431 |
""" |
|
432 |
Return the node ID |
|
433 |
""" |
|
434 |
def GetNodeID(self): |
|
435 |
return self.ID |
|
436 |
||
437 |
""" |
|
438 |
Define the node ID |
|
439 |
""" |
|
440 |
def SetNodeID(self, id): |
|
441 |
self.ID = id |
|
442 |
||
443 |
""" |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
444 |
Return the node description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
445 |
""" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
446 |
def GetNodeDescription(self): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
447 |
if getattr(self, "Description", False): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
448 |
return self.Description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
449 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
450 |
return "" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
451 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
452 |
""" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
453 |
Define the node description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
454 |
""" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
455 |
def SetNodeDescription(self, description): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
456 |
self.Description = description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
457 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
458 |
""" |
0 | 459 |
Return the Specific Profile Name |
460 |
""" |
|
461 |
def GetProfileName(self): |
|
462 |
return self.ProfileName |
|
463 |
||
464 |
""" |
|
465 |
Define the Specific Profile Name |
|
466 |
""" |
|
467 |
def SetProfileName(self, profilename): |
|
468 |
self.ProfileName = profilename |
|
469 |
||
470 |
""" |
|
471 |
Return the Specific Profile |
|
472 |
""" |
|
473 |
def GetProfile(self): |
|
474 |
return self.Profile |
|
475 |
||
476 |
""" |
|
477 |
Define the Specific Profile |
|
478 |
""" |
|
479 |
def SetProfile(self, profile): |
|
480 |
self.Profile = profile |
|
481 |
||
482 |
""" |
|
483 |
Define the DS-302 Profile |
|
484 |
""" |
|
485 |
def SetDS302Profile(self, profile): |
|
486 |
self.DS302 = profile |
|
487 |
||
488 |
""" |
|
489 |
Define the DS-302 Profile |
|
490 |
""" |
|
491 |
def GetDS302Profile(self): |
|
492 |
return self.DS302 |
|
493 |
||
494 |
""" |
|
495 |
Return the Specific Menu Entries |
|
496 |
""" |
|
497 |
def GetSpecificMenu(self): |
|
498 |
return self.SpecificMenu |
|
499 |
||
500 |
""" |
|
501 |
Define the Specific Menu Entries |
|
502 |
""" |
|
503 |
def SetSpecificMenu(self, specificmenu): |
|
504 |
self.SpecificMenu = specificmenu |
|
505 |
||
506 |
""" |
|
507 |
Extend the Specific Menu Entries |
|
508 |
""" |
|
509 |
||
510 |
def ExtendSpecificMenu(self, specificmenu): |
|
176 | 511 |
self.SpecificMenu.extend(specificmenu) |
0 | 512 |
|
513 |
""" |
|
514 |
Function which return the different Mappings available for this node |
|
515 |
""" |
|
516 |
def GetMappings(self, userdefinedtoo = True): |
|
517 |
if userdefinedtoo: |
|
518 |
return [self.Profile, self.DS302, self.UserMapping] |
|
519 |
else: |
|
520 |
return [self.Profile, self.DS302] |
|
521 |
||
522 |
""" |
|
523 |
Add a new entry in the Object Dictionary |
|
524 |
""" |
|
525 |
def AddEntry(self, index, subIndex = None, value = None): |
|
526 |
if index not in self.Dictionary: |
|
527 |
if not subIndex: |
|
528 |
self.Dictionary[index] = value |
|
529 |
return True |
|
530 |
elif subIndex == 1: |
|
531 |
self.Dictionary[index] = [value] |
|
532 |
return True |
|
533 |
elif subIndex > 1 and type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]) + 1: |
|
534 |
self.Dictionary[index].append(value) |
|
535 |
return True |
|
536 |
return False |
|
537 |
||
538 |
""" |
|
539 |
Warning ! Modifies an existing entry in the Object Dictionary. Can't add a new one. |
|
540 |
""" |
|
541 |
def SetEntry(self, index, subIndex = None, value = None): |
|
542 |
if index in self.Dictionary: |
|
543 |
if not subIndex: |
|
544 |
if value != None: |
|
545 |
self.Dictionary[index] = value |
|
546 |
return True |
|
547 |
elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]): |
|
548 |
if value != None: |
|
549 |
self.Dictionary[index][subIndex - 1] = value |
|
550 |
return True |
|
551 |
return False |
|
552 |
||
553 |
def SetParamsEntry(self, index, subIndex = None, comment = None, save = None, callback = None): |
|
554 |
if not getattr(self, "ParamsDictionary", False): |
|
555 |
self.ParamsDictionary = {} |
|
556 |
if index in self.Dictionary: |
|
557 |
if (comment != None or save != None or callback != None) and index not in self.ParamsDictionary: |
|
558 |
self.ParamsDictionary[index] = {} |
|
559 |
if subIndex == None or type(self.Dictionary[index]) != ListType and subIndex == 0: |
|
560 |
if comment != None: |
|
561 |
self.ParamsDictionary[index]["comment"] = comment |
|
562 |
if save != None: |
|
563 |
self.ParamsDictionary[index]["save"] = save |
|
564 |
if callback != None: |
|
565 |
self.ParamsDictionary[index]["callback"] = callback |
|
566 |
return True |
|
567 |
elif type(self.Dictionary[index]) == ListType and 0 <= subIndex <= len(self.Dictionary[index]): |
|
568 |
if (comment != None or save != None or callback != None) and subIndex not in self.ParamsDictionary[index]: |
|
569 |
self.ParamsDictionary[index][subIndex] = {} |
|
570 |
if comment != None: |
|
571 |
self.ParamsDictionary[index][subIndex]["comment"] = comment |
|
572 |
if save != None: |
|
573 |
self.ParamsDictionary[index][subIndex]["save"] = save |
|
574 |
return True |
|
575 |
return False |
|
576 |
||
577 |
""" |
|
578 |
Removes an existing entry in the Object Dictionary. If a subIndex is specified |
|
579 |
it will remove this subIndex only if it's the last of the index. If no subIndex |
|
580 |
is specified it removes the whole index and subIndexes from the Object Dictionary. |
|
581 |
""" |
|
582 |
def RemoveEntry(self, index, subIndex = None): |
|
583 |
if not getattr(self, "ParamsDictionary", False): |
|
584 |
self.ParamsDictionary = {} |
|
585 |
if index in self.Dictionary: |
|
586 |
if not subIndex: |
|
587 |
self.Dictionary.pop(index) |
|
588 |
if index in self.ParamsDictionary: |
|
589 |
self.ParamsDictionary.pop(index) |
|
590 |
return True |
|
591 |
elif type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]): |
|
592 |
self.Dictionary[index].pop(subIndex - 1) |
|
593 |
if index in self.ParamsDictionary: |
|
594 |
if subIndex in self.ParamsDictionary[index]: |
|
595 |
self.ParamsDictionary[index].pop(subIndex) |
|
596 |
if len(self.ParamsDictionary[index]) == 0: |
|
597 |
self.ParamsDictionary.pop(index) |
|
598 |
if len(self.Dictionary[index]) == 0: |
|
599 |
self.Dictionary.pop(index) |
|
600 |
if index in self.ParamsDictionary: |
|
601 |
self.ParamsDictionary.pop(index) |
|
602 |
return True |
|
603 |
return False |
|
604 |
||
605 |
""" |
|
606 |
Check if an entry exists in the Object Dictionary and returns the answer. |
|
607 |
""" |
|
205 | 608 |
def IsEntry(self, index, subIndex = None): |
0 | 609 |
if index in self.Dictionary: |
205 | 610 |
if not subIndex: |
611 |
return True |
|
612 |
return subIndex <= len(self.Dictionary[index]) |
|
0 | 613 |
return False |
614 |
||
615 |
""" |
|
616 |
Returns the value of the entry asked. If the entry has the value "count", it |
|
617 |
returns the number of subIndex in the entry except the first. |
|
618 |
""" |
|
619 |
def GetEntry(self, index, subIndex = None): |
|
620 |
if index in self.Dictionary: |
|
621 |
if subIndex == None: |
|
622 |
if type(self.Dictionary[index]) == ListType: |
|
623 |
values = [len(self.Dictionary[index])] |
|
205 | 624 |
for value in self.Dictionary[index]: |
625 |
values.append(self.CompileValue(value, index)) |
|
0 | 626 |
return values |
627 |
else: |
|
227 | 628 |
return self.CompileValue(self.Dictionary[index], index) |
0 | 629 |
elif subIndex == 0: |
630 |
if type(self.Dictionary[index]) == ListType: |
|
631 |
return len(self.Dictionary[index]) |
|
632 |
else: |
|
205 | 633 |
return self.CompileValue(self.Dictionary[index], index) |
0 | 634 |
elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]): |
205 | 635 |
return self.CompileValue(self.Dictionary[index][subIndex - 1], index) |
0 | 636 |
return None |
637 |
||
638 |
""" |
|
639 |
Returns the value of the entry asked. If the entry has the value "count", it |
|
640 |
returns the number of subIndex in the entry except the first. |
|
641 |
""" |
|
642 |
def GetParamsEntry(self, index, subIndex = None): |
|
643 |
if not getattr(self, "ParamsDictionary", False): |
|
644 |
self.ParamsDictionary = {} |
|
645 |
if index in self.Dictionary: |
|
646 |
if subIndex == None: |
|
647 |
if type(self.Dictionary[index]) == ListType: |
|
648 |
if index in self.ParamsDictionary: |
|
649 |
result = [] |
|
650 |
for i in xrange(len(self.Dictionary[index]) + 1): |
|
651 |
line = DefaultParams.copy() |
|
652 |
if i in self.ParamsDictionary[index]: |
|
653 |
line.update(self.ParamsDictionary[index][i]) |
|
654 |
result.append(line) |
|
655 |
return result |
|
656 |
else: |
|
657 |
return [DefaultParams.copy() for i in xrange(len(self.Dictionary[index]) + 1)] |
|
658 |
else: |
|
659 |
result = DefaultParams.copy() |
|
660 |
if index in self.ParamsDictionary: |
|
661 |
result.update(self.ParamsDictionary[index]) |
|
662 |
return result |
|
663 |
elif subIndex == 0 and type(self.Dictionary[index]) != ListType: |
|
664 |
result = DefaultParams.copy() |
|
665 |
if index in self.ParamsDictionary: |
|
666 |
result.update(self.ParamsDictionary[index]) |
|
667 |
return result |
|
668 |
elif type(self.Dictionary[index]) == ListType and 0 <= subIndex <= len(self.Dictionary[index]): |
|
669 |
result = DefaultParams.copy() |
|
670 |
if index in self.ParamsDictionary and subIndex in self.ParamsDictionary[index]: |
|
64 | 671 |
result.update(self.ParamsDictionary[index][subIndex]) |
0 | 672 |
return result |
673 |
return None |
|
674 |
||
675 |
def HasEntryCallbacks(self, index): |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
676 |
entry_infos = self.GetEntryInfos(index) |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
677 |
if entry_infos and "callback" in entry_infos: |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
678 |
return entry_infos["callback"] |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
679 |
else: |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
680 |
if not getattr(self, "ParamsDictionary", False): |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
681 |
self.ParamsDictionary = {} |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
682 |
if index in self.Dictionary and index in self.ParamsDictionary and "callback" in self.ParamsDictionary[index]: |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
683 |
return self.ParamsDictionary[index]["callback"] |
0 | 684 |
return False |
685 |
||
686 |
""" |
|
68
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
687 |
Check if an entry exists in the User Mapping Dictionary and returns the answer. |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
688 |
""" |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
689 |
def IsMappingEntry(self, index): |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
690 |
if index in self.UserMapping: |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
691 |
return True |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
692 |
return False |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
693 |
|
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
694 |
""" |
0 | 695 |
Add a new entry in the User Mapping Dictionary |
696 |
""" |
|
697 |
def AddMappingEntry(self, index, subIndex = None, name = "Undefined", struct = 0, size = None, nbmax = None, default = None, values = None): |
|
698 |
if index not in self.UserMapping: |
|
699 |
if values == None: |
|
700 |
values = [] |
|
701 |
if subIndex == None: |
|
702 |
self.UserMapping[index] = {"name" : name, "struct" : struct, "need" : False, "values" : values} |
|
703 |
if size != None: |
|
704 |
self.UserMapping[index]["size"] = size |
|
705 |
if nbmax != None: |
|
706 |
self.UserMapping[index]["nbmax"] = nbmax |
|
707 |
if default != None: |
|
708 |
self.UserMapping[index]["default"] = default |
|
709 |
return True |
|
710 |
elif subIndex != None and subIndex == len(self.UserMapping[index]["values"]): |
|
711 |
if values == None: |
|
712 |
values = {} |
|
713 |
self.UserMapping[index]["values"].append(values) |
|
714 |
return True |
|
715 |
return False |
|
716 |
||
717 |
""" |
|
718 |
Warning ! Modifies an existing entry in the User Mapping Dictionary. Can't add a new one. |
|
719 |
""" |
|
720 |
def SetMappingEntry(self, index, subIndex = None, name = None, struct = None, size = None, nbmax = None, default = None, values = None): |
|
721 |
if index in self.UserMapping: |
|
722 |
if subIndex == None: |
|
723 |
if name != None: |
|
724 |
self.UserMapping[index]["name"] = name |
|
725 |
if self.UserMapping[index]["struct"] & OD_IdenticalSubindexes: |
|
726 |
self.UserMapping[index]["values"][1]["name"] = name + " %d[(sub)]" |
|
727 |
elif not self.UserMapping[index]["struct"] & OD_MultipleSubindexes: |
|
728 |
self.UserMapping[index]["values"][0]["name"] = name |
|
729 |
if struct != None: |
|
730 |
self.UserMapping[index]["struct"] = struct |
|
731 |
if size != None: |
|
732 |
self.UserMapping[index]["size"] = size |
|
733 |
if nbmax != None: |
|
734 |
self.UserMapping[index]["nbmax"] = nbmax |
|
735 |
if default != None: |
|
736 |
self.UserMapping[index]["default"] = default |
|
737 |
if values != None: |
|
738 |
self.UserMapping[index]["values"] = values |
|
739 |
return True |
|
740 |
elif 0 <= subIndex < len(self.UserMapping[index]["values"]) and values != None: |
|
741 |
self.UserMapping[index]["values"][subIndex].update(values) |
|
742 |
return True |
|
743 |
return False |
|
744 |
||
745 |
""" |
|
746 |
Removes an existing entry in the User Mapping Dictionary. If a subIndex is specified |
|
747 |
it will remove this subIndex only if it's the last of the index. If no subIndex |
|
748 |
is specified it removes the whole index and subIndexes from the User Mapping Dictionary. |
|
749 |
""" |
|
750 |
def RemoveMappingEntry(self, index, subIndex = None): |
|
751 |
if index in self.UserMapping: |
|
752 |
if subIndex == None: |
|
753 |
self.UserMapping.pop(index) |
|
754 |
return True |
|
755 |
elif subIndex == len(self.UserMapping[index]["values"]) - 1: |
|
756 |
self.UserMapping[index]["values"].pop(subIndex) |
|
757 |
return True |
|
758 |
return False |
|
759 |
||
205 | 760 |
def RemoveMapVariable(self, index, subIndex = None): |
0 | 761 |
model = index << 16 |
762 |
mask = 0xFFFF << 16 |
|
763 |
if subIndex: |
|
764 |
model += subIndex << 8 |
|
765 |
mask = 0xFF << 8 |
|
766 |
for i in self.Dictionary.iterkeys(): |
|
767 |
if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF: |
|
768 |
for j,value in enumerate(self.Dictionary[i]): |
|
769 |
if (value & mask) == model: |
|
770 |
self.Dictionary[i][j] = 0 |
|
771 |
||
63
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
772 |
def UpdateMapVariable(self, index, subIndex, size): |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
773 |
model = index << 16 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
774 |
mask = 0xFFFF << 16 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
775 |
if subIndex: |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
776 |
model += subIndex << 8 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
777 |
mask = 0xFF << 8 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
778 |
for i in self.Dictionary.iterkeys(): |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
779 |
if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF: |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
780 |
for j,value in enumerate(self.Dictionary[i]): |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
781 |
if (value & mask) == model: |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
782 |
self.Dictionary[i][j] = model + size |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
783 |
|
0 | 784 |
def RemoveLine(self, index, max, incr = 1): |
785 |
i = index |
|
786 |
while i < max and self.IsEntry(i + incr): |
|
787 |
self.Dictionary[i] = self.Dictionary[i + incr] |
|
788 |
i += incr |
|
789 |
self.Dictionary.pop(i) |
|
790 |
||
791 |
def RemoveUserType(self, index): |
|
792 |
type = self.GetEntry(index, 1) |
|
793 |
for i in self.UserMapping: |
|
794 |
for value in self.UserMapping[i]["values"]: |
|
795 |
if value["type"] == index: |
|
796 |
value["type"] = type |
|
797 |
self.RemoveMappingEntry(index) |
|
798 |
self.RemoveEntry(index) |
|
799 |
||
800 |
""" |
|
801 |
Return a copy of the node |
|
802 |
""" |
|
803 |
def Copy(self): |
|
804 |
return cPickle.loads(cPickle.dumps(self)) |
|
805 |
||
806 |
""" |
|
807 |
Return a sorted list of indexes in Object Dictionary |
|
808 |
""" |
|
809 |
def GetIndexes(self): |
|
810 |
listindex = self.Dictionary.keys() |
|
811 |
listindex.sort() |
|
812 |
return listindex |
|
813 |
||
814 |
""" |
|
815 |
Print the Dictionary values |
|
816 |
""" |
|
817 |
def Print(self): |
|
273 | 818 |
print self.PrintString() |
819 |
||
820 |
def PrintString(self): |
|
821 |
result = "" |
|
0 | 822 |
listindex = self.Dictionary.keys() |
823 |
listindex.sort() |
|
824 |
for index in listindex: |
|
273 | 825 |
name = self.GetEntryName(index) |
239 | 826 |
values = self.Dictionary[index] |
273 | 827 |
if isinstance(values, ListType): |
828 |
result += "%04X (%s):\n"%(index, name) |
|
829 |
for subidx, value in enumerate(values): |
|
830 |
subentry_infos = self.GetSubentryInfos(index, subidx + 1) |
|
831 |
if index == 0x1F22 and value: |
|
832 |
nb_params = BE_to_LE(value[:4]) |
|
833 |
data = value[4:] |
|
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
834 |
value = "%d arg defined"%nb_params |
273 | 835 |
i = 0 |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
836 |
count = 1 |
273 | 837 |
while i < len(data): |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
838 |
value += "\n%04X %02X, arg %d: "%(index, subidx+1, count) |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
839 |
value += "%04X"%BE_to_LE(data[i:i+2]) |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
840 |
value += " %02X"%BE_to_LE(data[i+2:i+3]) |
273 | 841 |
size = BE_to_LE(data[i+3:i+7]) |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
842 |
value += " %08X"%size |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
843 |
value += (" %0"+"%d"%(size * 2)+"X")%BE_to_LE(data[i+7:i+7+size]) |
273 | 844 |
i += 7 + size |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
845 |
count += 1 |
273 | 846 |
elif isinstance(value, IntType): |
847 |
value = "%X"%value |
|
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
848 |
result += "%04X %02X (%s): %s\n"%(index, subidx+1, subentry_infos["name"], value) |
273 | 849 |
else: |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
850 |
if isinstance(values, IntType): |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
851 |
values = "%X"%values |
273 | 852 |
result += "%04X (%s): %s\n"%(index, name, values) |
853 |
return result |
|
854 |
||
205 | 855 |
def CompileValue(self, value, index): |
856 |
if type(value) == StringType and value.find("self.ID") != -1: |
|
857 |
base = self.GetBaseIndex(index) |
|
858 |
try: |
|
859 |
return eval(value) |
|
860 |
except: |
|
861 |
return 0 |
|
862 |
else: |
|
863 |
return value |
|
864 |
||
865 |
#------------------------------------------------------------------------------- |
|
866 |
# Node Informations Functions |
|
867 |
#------------------------------------------------------------------------------- |
|
868 |
||
869 |
def GetBaseIndex(self, index): |
|
870 |
for mapping in self.GetMappings(): |
|
871 |
result = FindIndex(index, mapping) |
|
872 |
if result != None: |
|
227 | 873 |
return (index - result) / mapping[result].get("incr", 1) |
205 | 874 |
result = FindIndex(index, MappingDictionary) |
875 |
if result != None: |
|
227 | 876 |
return (index - result) / MappingDictionary[result].get("incr", 1) |
205 | 877 |
return 0 |
878 |
||
879 |
def GetCustomisedTypeValues(self, index): |
|
880 |
values = self.GetEntry(index) |
|
881 |
customisabletypes = self.GetCustomisableTypes() |
|
882 |
return values, customisabletypes[values[1]][1] |
|
883 |
||
884 |
def GetEntryName(self, index): |
|
885 |
result = None |
|
886 |
mappings = self.GetMappings() |
|
887 |
i = 0 |
|
888 |
while not result and i < len(mappings): |
|
889 |
result = FindEntryName(index, mappings[i]) |
|
890 |
i += 1 |
|
891 |
if result == None: |
|
892 |
result = FindEntryName(index, MappingDictionary) |
|
893 |
return result |
|
894 |
||
895 |
def GetEntryInfos(self, index): |
|
896 |
result = None |
|
897 |
mappings = self.GetMappings() |
|
898 |
i = 0 |
|
899 |
while not result and i < len(mappings): |
|
900 |
result = FindEntryInfos(index, mappings[i]) |
|
901 |
i += 1 |
|
902 |
if result == None: |
|
903 |
result = FindEntryInfos(index, MappingDictionary) |
|
904 |
return result |
|
905 |
||
906 |
def GetSubentryInfos(self, index, subIndex): |
|
907 |
result = None |
|
908 |
mappings = self.GetMappings() |
|
909 |
i = 0 |
|
910 |
while not result and i < len(mappings): |
|
911 |
result = FindSubentryInfos(index, subIndex, mappings[i]) |
|
912 |
if result: |
|
913 |
result["user_defined"] = i == len(mappings) - 1 and index >= 0x1000 |
|
914 |
i += 1 |
|
915 |
if result == None: |
|
916 |
result = FindSubentryInfos(index, subIndex, MappingDictionary) |
|
917 |
if result: |
|
918 |
result["user_defined"] = False |
|
919 |
return result |
|
920 |
||
921 |
def GetTypeIndex(self, typename): |
|
922 |
result = None |
|
923 |
mappings = self.GetMappings() |
|
924 |
i = 0 |
|
925 |
while not result and i < len(mappings): |
|
926 |
result = FindTypeIndex(typename, mappings[i]) |
|
927 |
i += 1 |
|
928 |
if result == None: |
|
929 |
result = FindTypeIndex(typename, MappingDictionary) |
|
930 |
return result |
|
931 |
||
932 |
def GetTypeName(self, typeindex): |
|
933 |
result = None |
|
934 |
mappings = self.GetMappings() |
|
935 |
i = 0 |
|
936 |
while not result and i < len(mappings): |
|
937 |
result = FindTypeName(typeindex, mappings[i]) |
|
938 |
i += 1 |
|
939 |
if result == None: |
|
940 |
result = FindTypeName(typeindex, MappingDictionary) |
|
941 |
return result |
|
942 |
||
943 |
def GetTypeDefaultValue(self, typeindex): |
|
944 |
result = None |
|
945 |
mappings = self.GetMappings() |
|
946 |
i = 0 |
|
947 |
while not result and i < len(mappings): |
|
948 |
result = FindTypeDefaultValue(typeindex, mappings[i]) |
|
949 |
i += 1 |
|
950 |
if result == None: |
|
951 |
result = FindTypeDefaultValue(typeindex, MappingDictionary) |
|
952 |
return result |
|
953 |
||
954 |
def GetMapVariableList(self): |
|
955 |
list = FindMapVariableList(MappingDictionary, self) |
|
956 |
for mapping in self.GetMappings(): |
|
957 |
list.extend(FindMapVariableList(mapping, self)) |
|
958 |
list.sort() |
|
959 |
return list |
|
960 |
||
961 |
def GetMandatoryIndexes(self, node = None): |
|
962 |
list = FindMandatoryIndexes(MappingDictionary) |
|
963 |
for mapping in self.GetMappings(): |
|
964 |
list.extend(FindMandatoryIndexes(mapping)) |
|
965 |
return list |
|
966 |
||
967 |
def GetCustomisableTypes(self): |
|
968 |
dic = {} |
|
969 |
for index, valuetype in CustomisableTypes: |
|
970 |
name = self.GetTypeName(index) |
|
971 |
dic[index] = [name, valuetype] |
|
972 |
return dic |
|
973 |
||
974 |
#------------------------------------------------------------------------------- |
|
975 |
# Type and Map Variable Lists |
|
976 |
#------------------------------------------------------------------------------- |
|
977 |
||
978 |
def GetTypeList(self): |
|
979 |
list = FindTypeList(MappingDictionary) |
|
980 |
for mapping in self.GetMappings(): |
|
981 |
list.extend(FindTypeList(mapping)) |
|
982 |
list.sort() |
|
983 |
return ",".join(list) |
|
984 |
||
985 |
""" |
|
986 |
Generate the list of variables that can be mapped for the current node |
|
987 |
""" |
|
988 |
def GenerateMapList(self): |
|
989 |
self.MapList = "None" |
|
990 |
self.NameTranslation = {"None" : "00000000"} |
|
991 |
self.MapTranslation = {"00000000" : "None"} |
|
992 |
list = self.GetMapVariableList() |
|
993 |
for index, subIndex, size, name in list: |
|
994 |
self.MapList += ",%s"%name |
|
995 |
map = "%04X%02X%02X"%(index,subIndex,size) |
|
996 |
self.NameTranslation[name] = map |
|
997 |
self.MapTranslation[map] = name |
|
998 |
||
999 |
def GetMapValue(self, mapname): |
|
1000 |
if mapname == "None": |
|
1001 |
return 0 |
|
1002 |
else: |
|
1003 |
list = self.GetMapVariableList() |
|
1004 |
for index, subIndex, size, name in list: |
|
1005 |
if mapname == name: |
|
1006 |
return (index << 16) + (subIndex << 8) + size |
|
1007 |
return None |
|
1008 |
||
1009 |
def GetMapName(self, value): |
|
1010 |
if value != 0: |
|
1011 |
index = value >> 16 |
|
1012 |
subindex = (value >> 8) % (1 << 8) |
|
1013 |
result = self.GetSubentryInfos(index, subindex) |
|
1014 |
if result: |
|
1015 |
return result["name"] |
|
1016 |
return "None" |
|
1017 |
||
1018 |
""" |
|
1019 |
Return the list of variables that can be mapped for the current node |
|
1020 |
""" |
|
1021 |
def GetMapList(self): |
|
1022 |
list = ["None"] + [name for index, subIndex, size, name in self.GetMapVariableList()] |
|
1023 |
return ",".join(list) |
|
273 | 1024 |
|
1025 |
def BE_to_LE(value): |
|
1026 |
""" |
|
1027 |
Convert Big Endian to Little Endian |
|
1028 |
@param value: value expressed in Big Endian |
|
1029 |
@param size: number of bytes generated |
|
1030 |
@return: a string containing the value converted |
|
1031 |
""" |
|
1032 |
||
1033 |
data = [char for char in value] |
|
1034 |
data.reverse() |
|
1035 |
return int("".join(["%2.2X"%ord(char) for char in data]), 16) |
|
1036 |