author | greg |
Wed, 14 Oct 2009 16:37:37 +0200 | |
changeset 609 | c59dce78bbad |
parent 584 | e23359f62023 |
child 659 | 1041153c5fd2 |
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}]}, |
284 | 107 |
0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False, "callback" : True, "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}, |
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
131 |
{"name" : "Save Manufacturer Parameters %d[(sub - 3)]", "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}, |
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
137 |
{"name" : "Restore Manufacturer Defined Default Parameters %d[(sub - 3)]", "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" : |
313 | 143 |
[{"name" : "Emergency COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "\"$NODEID+0x80\""}]}, |
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}, |
299 | 148 |
{"name" : "Consumer Heartbeat Time", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 1, "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}, |
299 | 184 |
{"name" : "Module %d[(sub)]", "type" : 0x06, "access" : 'ro', "pdo" : False, "nbmin" : 1, "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}, |
299 | 187 |
{"name" : "Emergency Consumer", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 1, "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}, |
299 | 194 |
{"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False, "default" : "\"$NODEID+0x600\""}, |
195 |
{"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False, "default" : "\"$NODEID+0x580\""}]}, |
|
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}, |
317
f1c472b42327
Bug on default COB ID value for PDO transmit and receive 5 and higher fixed
lbessard
parents:
313
diff
changeset
|
208 |
{"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:\"$NODEID+0x%X00\"%(base+2),False:0x80000000}[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}, |
299 | 215 |
{"name" : "PDO %d Mapping for an application object %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 0, "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}, |
317
f1c472b42327
Bug on default COB ID value for PDO transmit and receive 5 and higher fixed
lbessard
parents:
313
diff
changeset
|
218 |
{"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:\"$NODEID+0x%X80\"%(base+1),False:0x80000000}[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}, |
299 | 225 |
{"name" : "PDO %d Mapping for a process data variable %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 0, "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 |
""" |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
273 |
def FindEntryName(index, mappingdictionary, compute=True): |
205 | 274 |
base_index = FindIndex(index, mappingdictionary) |
275 |
if base_index: |
|
276 |
infos = mappingdictionary[base_index] |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
277 |
if infos["struct"] & OD_IdenticalIndexes and compute: |
205 | 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 |
""" |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
286 |
def FindEntryInfos(index, mappingdictionary, compute=True): |
205 | 287 |
base_index = FindIndex(index, mappingdictionary) |
288 |
if base_index: |
|
289 |
copy = mappingdictionary[base_index].copy() |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
290 |
if copy["struct"] & OD_IdenticalIndexes and compute: |
205 | 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 |
""" |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
299 |
def FindSubentryInfos(index, subIndex, mappingdictionary, compute=True): |
205 | 300 |
base_index = FindIndex(index, mappingdictionary) |
301 |
if base_index: |
|
302 |
struct = mappingdictionary[base_index]["struct"] |
|
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
303 |
if struct & OD_IdenticalIndexes: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
304 |
incr = mappingdictionary[base_index]["incr"] |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
305 |
else: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
306 |
incr = 1 |
205 | 307 |
if struct & OD_Subindex: |
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
308 |
infos = None |
205 | 309 |
if struct & OD_IdenticalSubindexes: |
310 |
if subIndex == 0: |
|
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
311 |
infos = mappingdictionary[base_index]["values"][0].copy() |
205 | 312 |
elif 0 < subIndex <= mappingdictionary[base_index]["values"][1]["nbmax"]: |
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
313 |
infos = mappingdictionary[base_index]["values"][1].copy() |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
314 |
elif struct & OD_MultipleSubindexes: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
315 |
idx = 0 |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
316 |
for subindex_infos in mappingdictionary[base_index]["values"]: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
317 |
if "nbmax" in subindex_infos: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
318 |
if idx <= subIndex < idx + subindex_infos["nbmax"]: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
319 |
infos = subindex_infos.copy() |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
320 |
break; |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
321 |
idx += subindex_infos["nbmax"] |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
322 |
else: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
323 |
if subIndex == idx: |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
324 |
infos = subindex_infos.copy() |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
325 |
break; |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
326 |
idx += 1 |
205 | 327 |
elif subIndex == 0: |
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
328 |
infos = mappingdictionary[base_index]["values"][0].copy() |
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
329 |
if infos is not None and compute: |
510
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
330 |
infos["name"] = StringFormat(infos["name"], (index - base_index) / incr + 1, subIndex) |
96d50ac2dea3
Adding support for multiple element in 1010 and 1011
lbessard
parents:
453
diff
changeset
|
331 |
return infos |
205 | 332 |
return None |
333 |
||
334 |
""" |
|
335 |
Return the list of variables that can be mapped defined in mappingdictionary |
|
336 |
""" |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
337 |
def FindMapVariableList(mappingdictionary, Node, compute=True): |
205 | 338 |
list = [] |
339 |
for index in mappingdictionary.iterkeys(): |
|
340 |
if Node.IsEntry(index): |
|
341 |
for subIndex, values in enumerate(mappingdictionary[index]["values"]): |
|
342 |
if mappingdictionary[index]["values"][subIndex]["pdo"]: |
|
343 |
infos = Node.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"]) |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
344 |
name = mappingdictionary[index]["values"][subIndex]["name"] |
205 | 345 |
if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes: |
346 |
values = Node.GetEntry(index) |
|
347 |
for i in xrange(len(values) - 1): |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
348 |
computed_name = name |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
349 |
if compute: |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
350 |
computed_name = StringFormat(computed_name, 1, i + 1) |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
351 |
list.append((index, i + 1, infos["size"], computed_name)) |
205 | 352 |
else: |
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
353 |
computed_name = name |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
354 |
if compute: |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
355 |
computed_name = StringFormat(computed_name, 1, subIndex) |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
356 |
list.append((index, subIndex, infos["size"], computed_name)) |
205 | 357 |
return list |
358 |
||
359 |
""" |
|
360 |
Return the list of mandatory indexes defined in mappingdictionary |
|
361 |
""" |
|
362 |
def FindMandatoryIndexes(mappingdictionary): |
|
363 |
list = [] |
|
364 |
for index in mappingdictionary.iterkeys(): |
|
365 |
if index >= 0x1000 and mappingdictionary[index]["need"]: |
|
366 |
list.append(index) |
|
367 |
return list |
|
368 |
||
369 |
""" |
|
370 |
Return the index of the informations in the Object Dictionary in case of identical |
|
371 |
indexes |
|
372 |
""" |
|
373 |
def FindIndex(index, mappingdictionary): |
|
374 |
if index in mappingdictionary: |
|
375 |
return index |
|
376 |
else: |
|
377 |
listpluri = [idx for idx in mappingdictionary.keys() if mappingdictionary[idx]["struct"] & OD_IdenticalIndexes] |
|
378 |
listpluri.sort() |
|
379 |
for idx in listpluri: |
|
380 |
nb_max = mappingdictionary[idx]["nbmax"] |
|
381 |
incr = mappingdictionary[idx]["incr"] |
|
382 |
if idx < index < idx + incr * nb_max and (index - idx)%incr == 0: |
|
383 |
return idx |
|
384 |
return None |
|
385 |
||
386 |
#------------------------------------------------------------------------------- |
|
387 |
# Formating Name of an Entry |
|
388 |
#------------------------------------------------------------------------------- |
|
389 |
||
390 |
name_model = re.compile('(.*)\[(.*)\]') |
|
391 |
||
392 |
""" |
|
393 |
Format the text given with the index and subindex defined |
|
394 |
""" |
|
395 |
def StringFormat(text, idx, sub): |
|
396 |
result = name_model.match(text) |
|
397 |
if result: |
|
398 |
format = result.groups() |
|
399 |
return format[0]%eval(format[1]) |
|
400 |
else: |
|
401 |
return text |
|
402 |
||
403 |
#------------------------------------------------------------------------------- |
|
0 | 404 |
# Definition of Node Object |
405 |
#------------------------------------------------------------------------------- |
|
406 |
||
407 |
""" |
|
408 |
Class recording the Object Dictionary entries. It checks at each modification |
|
409 |
that the structure of the Object Dictionary stay coherent |
|
410 |
""" |
|
411 |
||
412 |
class Node: |
|
413 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
414 |
DefaultStringSize = 10 |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
415 |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
416 |
def __init__(self, name = "", type = "slave", id = 0, description = "", profilename = "DS-301", profile = {}, specificmenu = []): |
0 | 417 |
self.Name = name |
418 |
self.Type = type |
|
419 |
self.ID = id |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
420 |
self.Description = description |
0 | 421 |
self.ProfileName = profilename |
422 |
self.Profile = profile |
|
423 |
self.SpecificMenu = specificmenu |
|
424 |
self.Dictionary = {} |
|
425 |
self.ParamsDictionary = {} |
|
426 |
self.DS302 = {} |
|
427 |
self.UserMapping = {} |
|
428 |
||
429 |
""" |
|
430 |
Return the node name |
|
431 |
""" |
|
432 |
def GetNodeName(self): |
|
433 |
return self.Name |
|
434 |
||
435 |
""" |
|
436 |
Define the node name |
|
437 |
""" |
|
438 |
def SetNodeName(self, name): |
|
439 |
self.Name = name |
|
440 |
||
441 |
""" |
|
442 |
Return the node type ("master" or "slave") |
|
443 |
""" |
|
444 |
def GetNodeType(self): |
|
445 |
return self.Type |
|
446 |
||
447 |
""" |
|
448 |
Define the node type ("master" or "slave") |
|
449 |
""" |
|
450 |
def SetNodeType(self, type): |
|
451 |
self.Type = type |
|
452 |
||
453 |
""" |
|
454 |
Return the node ID |
|
455 |
""" |
|
456 |
def GetNodeID(self): |
|
457 |
return self.ID |
|
458 |
||
459 |
""" |
|
460 |
Define the node ID |
|
461 |
""" |
|
462 |
def SetNodeID(self, id): |
|
463 |
self.ID = id |
|
464 |
||
465 |
""" |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
466 |
Return the node description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
467 |
""" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
468 |
def GetNodeDescription(self): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
469 |
if getattr(self, "Description", False): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
470 |
return self.Description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
471 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
472 |
return "" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
473 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
474 |
""" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
475 |
Define the node description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
476 |
""" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
477 |
def SetNodeDescription(self, description): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
478 |
self.Description = description |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
479 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
177
diff
changeset
|
480 |
""" |
0 | 481 |
Return the Specific Profile Name |
482 |
""" |
|
483 |
def GetProfileName(self): |
|
484 |
return self.ProfileName |
|
485 |
||
486 |
""" |
|
487 |
Define the Specific Profile Name |
|
488 |
""" |
|
489 |
def SetProfileName(self, profilename): |
|
490 |
self.ProfileName = profilename |
|
491 |
||
492 |
""" |
|
493 |
Return the Specific Profile |
|
494 |
""" |
|
495 |
def GetProfile(self): |
|
496 |
return self.Profile |
|
497 |
||
498 |
""" |
|
499 |
Define the Specific Profile |
|
500 |
""" |
|
501 |
def SetProfile(self, profile): |
|
502 |
self.Profile = profile |
|
503 |
||
504 |
""" |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
505 |
Return the default string size |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
506 |
""" |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
507 |
def GetDefaultStringSize(self): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
508 |
return self.DefaultStringSize |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
509 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
510 |
""" |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
511 |
Define the default string size |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
512 |
""" |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
513 |
def SetDefaultStringSize(self, size): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
514 |
self.DefaultStringSize = size |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
515 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
327
diff
changeset
|
516 |
""" |
0 | 517 |
Define the DS-302 Profile |
518 |
""" |
|
519 |
def SetDS302Profile(self, profile): |
|
520 |
self.DS302 = profile |
|
521 |
||
522 |
""" |
|
523 |
Define the DS-302 Profile |
|
524 |
""" |
|
525 |
def GetDS302Profile(self): |
|
526 |
return self.DS302 |
|
527 |
||
528 |
""" |
|
529 |
Return the Specific Menu Entries |
|
530 |
""" |
|
531 |
def GetSpecificMenu(self): |
|
532 |
return self.SpecificMenu |
|
533 |
||
534 |
""" |
|
535 |
Define the Specific Menu Entries |
|
536 |
""" |
|
537 |
def SetSpecificMenu(self, specificmenu): |
|
538 |
self.SpecificMenu = specificmenu |
|
539 |
||
540 |
""" |
|
541 |
Extend the Specific Menu Entries |
|
542 |
""" |
|
543 |
||
544 |
def ExtendSpecificMenu(self, specificmenu): |
|
176 | 545 |
self.SpecificMenu.extend(specificmenu) |
0 | 546 |
|
547 |
""" |
|
548 |
Function which return the different Mappings available for this node |
|
549 |
""" |
|
550 |
def GetMappings(self, userdefinedtoo = True): |
|
551 |
if userdefinedtoo: |
|
552 |
return [self.Profile, self.DS302, self.UserMapping] |
|
553 |
else: |
|
554 |
return [self.Profile, self.DS302] |
|
555 |
||
556 |
""" |
|
557 |
Add a new entry in the Object Dictionary |
|
558 |
""" |
|
559 |
def AddEntry(self, index, subIndex = None, value = None): |
|
560 |
if index not in self.Dictionary: |
|
561 |
if not subIndex: |
|
562 |
self.Dictionary[index] = value |
|
563 |
return True |
|
564 |
elif subIndex == 1: |
|
565 |
self.Dictionary[index] = [value] |
|
566 |
return True |
|
299 | 567 |
elif subIndex > 0 and type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]) + 1: |
0 | 568 |
self.Dictionary[index].append(value) |
569 |
return True |
|
570 |
return False |
|
571 |
||
572 |
""" |
|
573 |
Warning ! Modifies an existing entry in the Object Dictionary. Can't add a new one. |
|
574 |
""" |
|
575 |
def SetEntry(self, index, subIndex = None, value = None): |
|
576 |
if index in self.Dictionary: |
|
577 |
if not subIndex: |
|
578 |
if value != None: |
|
579 |
self.Dictionary[index] = value |
|
580 |
return True |
|
581 |
elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]): |
|
582 |
if value != None: |
|
583 |
self.Dictionary[index][subIndex - 1] = value |
|
584 |
return True |
|
585 |
return False |
|
586 |
||
587 |
def SetParamsEntry(self, index, subIndex = None, comment = None, save = None, callback = None): |
|
588 |
if not getattr(self, "ParamsDictionary", False): |
|
589 |
self.ParamsDictionary = {} |
|
590 |
if index in self.Dictionary: |
|
591 |
if (comment != None or save != None or callback != None) and index not in self.ParamsDictionary: |
|
592 |
self.ParamsDictionary[index] = {} |
|
593 |
if subIndex == None or type(self.Dictionary[index]) != ListType and subIndex == 0: |
|
594 |
if comment != None: |
|
595 |
self.ParamsDictionary[index]["comment"] = comment |
|
596 |
if save != None: |
|
597 |
self.ParamsDictionary[index]["save"] = save |
|
598 |
if callback != None: |
|
599 |
self.ParamsDictionary[index]["callback"] = callback |
|
600 |
return True |
|
601 |
elif type(self.Dictionary[index]) == ListType and 0 <= subIndex <= len(self.Dictionary[index]): |
|
602 |
if (comment != None or save != None or callback != None) and subIndex not in self.ParamsDictionary[index]: |
|
603 |
self.ParamsDictionary[index][subIndex] = {} |
|
604 |
if comment != None: |
|
605 |
self.ParamsDictionary[index][subIndex]["comment"] = comment |
|
606 |
if save != None: |
|
607 |
self.ParamsDictionary[index][subIndex]["save"] = save |
|
608 |
return True |
|
609 |
return False |
|
610 |
||
611 |
""" |
|
612 |
Removes an existing entry in the Object Dictionary. If a subIndex is specified |
|
613 |
it will remove this subIndex only if it's the last of the index. If no subIndex |
|
614 |
is specified it removes the whole index and subIndexes from the Object Dictionary. |
|
615 |
""" |
|
616 |
def RemoveEntry(self, index, subIndex = None): |
|
617 |
if not getattr(self, "ParamsDictionary", False): |
|
618 |
self.ParamsDictionary = {} |
|
619 |
if index in self.Dictionary: |
|
620 |
if not subIndex: |
|
621 |
self.Dictionary.pop(index) |
|
622 |
if index in self.ParamsDictionary: |
|
623 |
self.ParamsDictionary.pop(index) |
|
624 |
return True |
|
625 |
elif type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]): |
|
626 |
self.Dictionary[index].pop(subIndex - 1) |
|
627 |
if index in self.ParamsDictionary: |
|
628 |
if subIndex in self.ParamsDictionary[index]: |
|
629 |
self.ParamsDictionary[index].pop(subIndex) |
|
630 |
if len(self.ParamsDictionary[index]) == 0: |
|
631 |
self.ParamsDictionary.pop(index) |
|
632 |
if len(self.Dictionary[index]) == 0: |
|
633 |
self.Dictionary.pop(index) |
|
634 |
if index in self.ParamsDictionary: |
|
635 |
self.ParamsDictionary.pop(index) |
|
636 |
return True |
|
637 |
return False |
|
638 |
||
639 |
""" |
|
640 |
Check if an entry exists in the Object Dictionary and returns the answer. |
|
641 |
""" |
|
205 | 642 |
def IsEntry(self, index, subIndex = None): |
0 | 643 |
if index in self.Dictionary: |
205 | 644 |
if not subIndex: |
645 |
return True |
|
646 |
return subIndex <= len(self.Dictionary[index]) |
|
0 | 647 |
return False |
648 |
||
649 |
""" |
|
650 |
Returns the value of the entry asked. If the entry has the value "count", it |
|
651 |
returns the number of subIndex in the entry except the first. |
|
652 |
""" |
|
299 | 653 |
def GetEntry(self, index, subIndex = None, compute = True): |
0 | 654 |
if index in self.Dictionary: |
655 |
if subIndex == None: |
|
656 |
if type(self.Dictionary[index]) == ListType: |
|
657 |
values = [len(self.Dictionary[index])] |
|
205 | 658 |
for value in self.Dictionary[index]: |
299 | 659 |
values.append(self.CompileValue(value, index, compute)) |
0 | 660 |
return values |
661 |
else: |
|
299 | 662 |
return self.CompileValue(self.Dictionary[index], index, compute) |
0 | 663 |
elif subIndex == 0: |
664 |
if type(self.Dictionary[index]) == ListType: |
|
665 |
return len(self.Dictionary[index]) |
|
666 |
else: |
|
299 | 667 |
return self.CompileValue(self.Dictionary[index], index, compute) |
0 | 668 |
elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]): |
299 | 669 |
return self.CompileValue(self.Dictionary[index][subIndex - 1], index, compute) |
0 | 670 |
return None |
671 |
||
672 |
""" |
|
673 |
Returns the value of the entry asked. If the entry has the value "count", it |
|
674 |
returns the number of subIndex in the entry except the first. |
|
675 |
""" |
|
676 |
def GetParamsEntry(self, index, subIndex = None): |
|
677 |
if not getattr(self, "ParamsDictionary", False): |
|
678 |
self.ParamsDictionary = {} |
|
679 |
if index in self.Dictionary: |
|
680 |
if subIndex == None: |
|
681 |
if type(self.Dictionary[index]) == ListType: |
|
682 |
if index in self.ParamsDictionary: |
|
683 |
result = [] |
|
684 |
for i in xrange(len(self.Dictionary[index]) + 1): |
|
685 |
line = DefaultParams.copy() |
|
686 |
if i in self.ParamsDictionary[index]: |
|
687 |
line.update(self.ParamsDictionary[index][i]) |
|
688 |
result.append(line) |
|
689 |
return result |
|
690 |
else: |
|
691 |
return [DefaultParams.copy() for i in xrange(len(self.Dictionary[index]) + 1)] |
|
692 |
else: |
|
693 |
result = DefaultParams.copy() |
|
694 |
if index in self.ParamsDictionary: |
|
695 |
result.update(self.ParamsDictionary[index]) |
|
696 |
return result |
|
697 |
elif subIndex == 0 and type(self.Dictionary[index]) != ListType: |
|
698 |
result = DefaultParams.copy() |
|
699 |
if index in self.ParamsDictionary: |
|
700 |
result.update(self.ParamsDictionary[index]) |
|
701 |
return result |
|
702 |
elif type(self.Dictionary[index]) == ListType and 0 <= subIndex <= len(self.Dictionary[index]): |
|
703 |
result = DefaultParams.copy() |
|
704 |
if index in self.ParamsDictionary and subIndex in self.ParamsDictionary[index]: |
|
64 | 705 |
result.update(self.ParamsDictionary[index][subIndex]) |
0 | 706 |
return result |
707 |
return None |
|
708 |
||
709 |
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
|
710 |
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
|
711 |
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
|
712 |
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
|
713 |
else: |
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
239
diff
changeset
|
714 |
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
|
715 |
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
|
716 |
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
|
717 |
return self.ParamsDictionary[index]["callback"] |
0 | 718 |
return False |
719 |
||
720 |
""" |
|
68
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
721 |
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
|
722 |
""" |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
723 |
def IsMappingEntry(self, index): |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
724 |
if index in self.UserMapping: |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
725 |
return True |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
726 |
return False |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
727 |
|
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
67
diff
changeset
|
728 |
""" |
0 | 729 |
Add a new entry in the User Mapping Dictionary |
730 |
""" |
|
731 |
def AddMappingEntry(self, index, subIndex = None, name = "Undefined", struct = 0, size = None, nbmax = None, default = None, values = None): |
|
732 |
if index not in self.UserMapping: |
|
733 |
if values == None: |
|
734 |
values = [] |
|
735 |
if subIndex == None: |
|
736 |
self.UserMapping[index] = {"name" : name, "struct" : struct, "need" : False, "values" : values} |
|
737 |
if size != None: |
|
738 |
self.UserMapping[index]["size"] = size |
|
739 |
if nbmax != None: |
|
740 |
self.UserMapping[index]["nbmax"] = nbmax |
|
741 |
if default != None: |
|
742 |
self.UserMapping[index]["default"] = default |
|
743 |
return True |
|
744 |
elif subIndex != None and subIndex == len(self.UserMapping[index]["values"]): |
|
745 |
if values == None: |
|
746 |
values = {} |
|
747 |
self.UserMapping[index]["values"].append(values) |
|
748 |
return True |
|
749 |
return False |
|
750 |
||
751 |
""" |
|
752 |
Warning ! Modifies an existing entry in the User Mapping Dictionary. Can't add a new one. |
|
753 |
""" |
|
754 |
def SetMappingEntry(self, index, subIndex = None, name = None, struct = None, size = None, nbmax = None, default = None, values = None): |
|
755 |
if index in self.UserMapping: |
|
756 |
if subIndex == None: |
|
757 |
if name != None: |
|
758 |
self.UserMapping[index]["name"] = name |
|
759 |
if self.UserMapping[index]["struct"] & OD_IdenticalSubindexes: |
|
760 |
self.UserMapping[index]["values"][1]["name"] = name + " %d[(sub)]" |
|
761 |
elif not self.UserMapping[index]["struct"] & OD_MultipleSubindexes: |
|
762 |
self.UserMapping[index]["values"][0]["name"] = name |
|
763 |
if struct != None: |
|
764 |
self.UserMapping[index]["struct"] = struct |
|
765 |
if size != None: |
|
766 |
self.UserMapping[index]["size"] = size |
|
767 |
if nbmax != None: |
|
768 |
self.UserMapping[index]["nbmax"] = nbmax |
|
769 |
if default != None: |
|
770 |
self.UserMapping[index]["default"] = default |
|
771 |
if values != None: |
|
772 |
self.UserMapping[index]["values"] = values |
|
773 |
return True |
|
774 |
elif 0 <= subIndex < len(self.UserMapping[index]["values"]) and values != None: |
|
281
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
775 |
if "type" in values: |
453 | 776 |
if self.UserMapping[index]["struct"] & OD_IdenticalSubindexes: |
777 |
if self.IsStringType(self.UserMapping[index]["values"][subIndex]["type"]): |
|
778 |
if self.IsRealType(values["type"]): |
|
779 |
for i in xrange(len(self.Dictionary[index])): |
|
780 |
self.SetEntry(index, i + 1, 0.) |
|
781 |
elif not self.IsStringType(values["type"]): |
|
782 |
for i in xrange(len(self.Dictionary[index])): |
|
783 |
self.SetEntry(index, i + 1, 0) |
|
784 |
elif self.IsRealType(self.UserMapping[index]["values"][subIndex]["type"]): |
|
785 |
if self.IsStringType(values["type"]): |
|
786 |
for i in xrange(len(self.Dictionary[index])): |
|
787 |
self.SetEntry(index, i + 1, "") |
|
788 |
elif not self.IsRealType(values["type"]): |
|
789 |
for i in xrange(len(self.Dictionary[index])): |
|
790 |
self.SetEntry(index, i + 1, 0) |
|
791 |
elif self.IsStringType(values["type"]): |
|
792 |
for i in xrange(len(self.Dictionary[index])): |
|
793 |
self.SetEntry(index, i + 1, "") |
|
794 |
elif self.IsRealType(values["type"]): |
|
795 |
for i in xrange(len(self.Dictionary[index])): |
|
796 |
self.SetEntry(index, i + 1, 0.) |
|
797 |
else: |
|
798 |
if self.IsStringType(self.UserMapping[index]["values"][subIndex]["type"]): |
|
799 |
if self.IsRealType(values["type"]): |
|
800 |
self.SetEntry(index, subIndex, 0.) |
|
801 |
elif not self.IsStringType(values["type"]): |
|
802 |
self.SetEntry(index, subIndex, 0) |
|
803 |
elif self.IsRealType(self.UserMapping[index]["values"][subIndex]["type"]): |
|
804 |
if self.IsStringType(values["type"]): |
|
805 |
self.SetEntry(index, subIndex, "") |
|
806 |
elif not self.IsRealType(values["type"]): |
|
807 |
self.SetEntry(index, subIndex, 0) |
|
808 |
elif self.IsStringType(values["type"]): |
|
809 |
self.SetEntry(index, subIndex, "") |
|
810 |
elif self.IsRealType(values["type"]): |
|
811 |
self.SetEntry(index, subIndex, 0.) |
|
0 | 812 |
self.UserMapping[index]["values"][subIndex].update(values) |
813 |
return True |
|
814 |
return False |
|
815 |
||
816 |
""" |
|
817 |
Removes an existing entry in the User Mapping Dictionary. If a subIndex is specified |
|
818 |
it will remove this subIndex only if it's the last of the index. If no subIndex |
|
819 |
is specified it removes the whole index and subIndexes from the User Mapping Dictionary. |
|
820 |
""" |
|
821 |
def RemoveMappingEntry(self, index, subIndex = None): |
|
822 |
if index in self.UserMapping: |
|
823 |
if subIndex == None: |
|
824 |
self.UserMapping.pop(index) |
|
825 |
return True |
|
826 |
elif subIndex == len(self.UserMapping[index]["values"]) - 1: |
|
827 |
self.UserMapping[index]["values"].pop(subIndex) |
|
828 |
return True |
|
829 |
return False |
|
830 |
||
205 | 831 |
def RemoveMapVariable(self, index, subIndex = None): |
0 | 832 |
model = index << 16 |
833 |
mask = 0xFFFF << 16 |
|
834 |
if subIndex: |
|
835 |
model += subIndex << 8 |
|
299 | 836 |
mask += 0xFF << 8 |
0 | 837 |
for i in self.Dictionary.iterkeys(): |
838 |
if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF: |
|
839 |
for j,value in enumerate(self.Dictionary[i]): |
|
840 |
if (value & mask) == model: |
|
841 |
self.Dictionary[i][j] = 0 |
|
842 |
||
63
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
843 |
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
|
844 |
model = index << 16 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
845 |
mask = 0xFFFF << 16 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
846 |
if subIndex: |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
847 |
model += subIndex << 8 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
848 |
mask = 0xFF << 8 |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
849 |
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
|
850 |
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
|
851 |
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
|
852 |
if (value & mask) == model: |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
62
diff
changeset
|
853 |
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
|
854 |
|
0 | 855 |
def RemoveLine(self, index, max, incr = 1): |
856 |
i = index |
|
857 |
while i < max and self.IsEntry(i + incr): |
|
858 |
self.Dictionary[i] = self.Dictionary[i + incr] |
|
859 |
i += incr |
|
860 |
self.Dictionary.pop(i) |
|
861 |
||
862 |
def RemoveUserType(self, index): |
|
863 |
type = self.GetEntry(index, 1) |
|
864 |
for i in self.UserMapping: |
|
865 |
for value in self.UserMapping[i]["values"]: |
|
866 |
if value["type"] == index: |
|
867 |
value["type"] = type |
|
868 |
self.RemoveMappingEntry(index) |
|
869 |
self.RemoveEntry(index) |
|
870 |
||
871 |
""" |
|
872 |
Return a copy of the node |
|
873 |
""" |
|
874 |
def Copy(self): |
|
875 |
return cPickle.loads(cPickle.dumps(self)) |
|
876 |
||
877 |
""" |
|
878 |
Return a sorted list of indexes in Object Dictionary |
|
879 |
""" |
|
880 |
def GetIndexes(self): |
|
881 |
listindex = self.Dictionary.keys() |
|
882 |
listindex.sort() |
|
883 |
return listindex |
|
884 |
||
885 |
""" |
|
886 |
Print the Dictionary values |
|
887 |
""" |
|
888 |
def Print(self): |
|
273 | 889 |
print self.PrintString() |
890 |
||
891 |
def PrintString(self): |
|
892 |
result = "" |
|
0 | 893 |
listindex = self.Dictionary.keys() |
894 |
listindex.sort() |
|
895 |
for index in listindex: |
|
273 | 896 |
name = self.GetEntryName(index) |
239 | 897 |
values = self.Dictionary[index] |
273 | 898 |
if isinstance(values, ListType): |
899 |
result += "%04X (%s):\n"%(index, name) |
|
900 |
for subidx, value in enumerate(values): |
|
901 |
subentry_infos = self.GetSubentryInfos(index, subidx + 1) |
|
902 |
if index == 0x1F22 and value: |
|
903 |
nb_params = BE_to_LE(value[:4]) |
|
904 |
data = value[4:] |
|
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
905 |
value = "%d arg defined"%nb_params |
273 | 906 |
i = 0 |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
907 |
count = 1 |
273 | 908 |
while i < len(data): |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
909 |
value += "\n%04X %02X, arg %d: "%(index, subidx+1, count) |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
910 |
value += "%04X"%BE_to_LE(data[i:i+2]) |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
911 |
value += " %02X"%BE_to_LE(data[i+2:i+3]) |
273 | 912 |
size = BE_to_LE(data[i+3:i+7]) |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
913 |
value += " %08X"%size |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
914 |
value += (" %0"+"%d"%(size * 2)+"X")%BE_to_LE(data[i+7:i+7+size]) |
273 | 915 |
i += 7 + size |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
916 |
count += 1 |
273 | 917 |
elif isinstance(value, IntType): |
918 |
value = "%X"%value |
|
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
919 |
result += "%04X %02X (%s): %s\n"%(index, subidx+1, subentry_infos["name"], value) |
273 | 920 |
else: |
274
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
921 |
if isinstance(values, IntType): |
39beb1c7542a
Modifying node Print function for displaying more informations
lbessard
parents:
273
diff
changeset
|
922 |
values = "%X"%values |
273 | 923 |
result += "%04X (%s): %s\n"%(index, name, values) |
924 |
return result |
|
925 |
||
299 | 926 |
def CompileValue(self, value, index, compute = True): |
541 | 927 |
if isinstance(value, (StringType, UnicodeType)) and value.upper().find("$NODEID") != -1: |
205 | 928 |
base = self.GetBaseIndex(index) |
929 |
try: |
|
299 | 930 |
raw = eval(value) |
931 |
if compute: |
|
513 | 932 |
return eval(raw.upper().replace("$NODEID","self.ID")) |
299 | 933 |
return raw |
205 | 934 |
except: |
935 |
return 0 |
|
936 |
else: |
|
937 |
return value |
|
938 |
||
939 |
#------------------------------------------------------------------------------- |
|
940 |
# Node Informations Functions |
|
941 |
#------------------------------------------------------------------------------- |
|
942 |
||
943 |
def GetBaseIndex(self, index): |
|
944 |
for mapping in self.GetMappings(): |
|
945 |
result = FindIndex(index, mapping) |
|
946 |
if result != None: |
|
227 | 947 |
return (index - result) / mapping[result].get("incr", 1) |
205 | 948 |
result = FindIndex(index, MappingDictionary) |
949 |
if result != None: |
|
227 | 950 |
return (index - result) / MappingDictionary[result].get("incr", 1) |
205 | 951 |
return 0 |
952 |
||
953 |
def GetCustomisedTypeValues(self, index): |
|
954 |
values = self.GetEntry(index) |
|
955 |
customisabletypes = self.GetCustomisableTypes() |
|
956 |
return values, customisabletypes[values[1]][1] |
|
957 |
||
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
958 |
def GetEntryName(self, index, compute=True): |
205 | 959 |
result = None |
960 |
mappings = self.GetMappings() |
|
961 |
i = 0 |
|
962 |
while not result and i < len(mappings): |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
963 |
result = FindEntryName(index, mappings[i], compute) |
205 | 964 |
i += 1 |
965 |
if result == None: |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
966 |
result = FindEntryName(index, MappingDictionary, compute) |
205 | 967 |
return result |
968 |
||
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
969 |
def GetEntryInfos(self, index, compute=True): |
205 | 970 |
result = None |
971 |
mappings = self.GetMappings() |
|
972 |
i = 0 |
|
973 |
while not result and i < len(mappings): |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
974 |
result = FindEntryInfos(index, mappings[i], compute) |
205 | 975 |
i += 1 |
976 |
if result == None: |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
977 |
result = FindEntryInfos(index, MappingDictionary, compute) |
205 | 978 |
return result |
979 |
||
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
980 |
def GetSubentryInfos(self, index, subIndex, compute=True): |
205 | 981 |
result = None |
982 |
mappings = self.GetMappings() |
|
983 |
i = 0 |
|
984 |
while not result and i < len(mappings): |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
985 |
result = FindSubentryInfos(index, subIndex, mappings[i], compute) |
205 | 986 |
if result: |
987 |
result["user_defined"] = i == len(mappings) - 1 and index >= 0x1000 |
|
988 |
i += 1 |
|
989 |
if result == None: |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
990 |
result = FindSubentryInfos(index, subIndex, MappingDictionary, compute) |
205 | 991 |
if result: |
992 |
result["user_defined"] = False |
|
993 |
return result |
|
994 |
||
995 |
def GetTypeIndex(self, typename): |
|
996 |
result = None |
|
997 |
mappings = self.GetMappings() |
|
998 |
i = 0 |
|
999 |
while not result and i < len(mappings): |
|
1000 |
result = FindTypeIndex(typename, mappings[i]) |
|
1001 |
i += 1 |
|
1002 |
if result == None: |
|
1003 |
result = FindTypeIndex(typename, MappingDictionary) |
|
1004 |
return result |
|
1005 |
||
1006 |
def GetTypeName(self, typeindex): |
|
1007 |
result = None |
|
1008 |
mappings = self.GetMappings() |
|
1009 |
i = 0 |
|
1010 |
while not result and i < len(mappings): |
|
1011 |
result = FindTypeName(typeindex, mappings[i]) |
|
1012 |
i += 1 |
|
1013 |
if result == None: |
|
1014 |
result = FindTypeName(typeindex, MappingDictionary) |
|
1015 |
return result |
|
1016 |
||
1017 |
def GetTypeDefaultValue(self, typeindex): |
|
1018 |
result = None |
|
1019 |
mappings = self.GetMappings() |
|
1020 |
i = 0 |
|
1021 |
while not result and i < len(mappings): |
|
1022 |
result = FindTypeDefaultValue(typeindex, mappings[i]) |
|
1023 |
i += 1 |
|
1024 |
if result == None: |
|
1025 |
result = FindTypeDefaultValue(typeindex, MappingDictionary) |
|
1026 |
return result |
|
1027 |
||
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
1028 |
def GetMapVariableList(self, compute=True): |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
1029 |
list = FindMapVariableList(MappingDictionary, self, compute) |
205 | 1030 |
for mapping in self.GetMappings(): |
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
1031 |
list.extend(FindMapVariableList(mapping, self, compute)) |
205 | 1032 |
list.sort() |
1033 |
return list |
|
1034 |
||
1035 |
def GetMandatoryIndexes(self, node = None): |
|
1036 |
list = FindMandatoryIndexes(MappingDictionary) |
|
1037 |
for mapping in self.GetMappings(): |
|
1038 |
list.extend(FindMandatoryIndexes(mapping)) |
|
1039 |
return list |
|
1040 |
||
1041 |
def GetCustomisableTypes(self): |
|
1042 |
dic = {} |
|
1043 |
for index, valuetype in CustomisableTypes: |
|
1044 |
name = self.GetTypeName(index) |
|
1045 |
dic[index] = [name, valuetype] |
|
1046 |
return dic |
|
1047 |
||
1048 |
#------------------------------------------------------------------------------- |
|
281
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1049 |
# Type helper functions |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1050 |
#------------------------------------------------------------------------------- |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1051 |
|
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1052 |
def IsStringType(self, index): |
523
8db762eb756b
Fixed bug in Node.py function IsStringType : add domain type
greg
parents:
513
diff
changeset
|
1053 |
if index in (0x9, 0xA, 0xB, 0xF): |
281
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1054 |
return True |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1055 |
elif 0xA0 <= index < 0x100: |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1056 |
result = self.GetEntry(index, 1) |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1057 |
if result is not None and result in (0x9, 0xA, 0xB): |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1058 |
return True |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1059 |
return False |
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1060 |
|
453 | 1061 |
def IsRealType(self, index): |
1062 |
if index in (0x8, 0x11): |
|
1063 |
return True |
|
1064 |
elif 0xA0 <= index < 0x100: |
|
1065 |
result = self.GetEntry(index, 1) |
|
1066 |
if result is not None and result in (0x8, 0x11): |
|
1067 |
return True |
|
1068 |
return False |
|
1069 |
||
281
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
274
diff
changeset
|
1070 |
#------------------------------------------------------------------------------- |
205 | 1071 |
# Type and Map Variable Lists |
1072 |
#------------------------------------------------------------------------------- |
|
1073 |
||
1074 |
def GetTypeList(self): |
|
1075 |
list = FindTypeList(MappingDictionary) |
|
1076 |
for mapping in self.GetMappings(): |
|
1077 |
list.extend(FindTypeList(mapping)) |
|
1078 |
list.sort() |
|
1079 |
return ",".join(list) |
|
1080 |
||
536
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1081 |
def GenerateMapName(self, name, index, subindex): |
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1082 |
return "%s (0x%4.4X)" % (name, index) |
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1083 |
|
205 | 1084 |
""" |
1085 |
Generate the list of variables that can be mapped for the current node |
|
1086 |
""" |
|
1087 |
def GenerateMapList(self): |
|
1088 |
self.MapList = "None" |
|
1089 |
self.NameTranslation = {"None" : "00000000"} |
|
1090 |
self.MapTranslation = {"00000000" : "None"} |
|
1091 |
list = self.GetMapVariableList() |
|
1092 |
for index, subIndex, size, name in list: |
|
1093 |
self.MapList += ",%s"%name |
|
1094 |
map = "%04X%02X%02X"%(index,subIndex,size) |
|
536
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1095 |
mapname = self.GenerateMapName(name, index, subIndex) |
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1096 |
self.NameTranslation[mapname] = map |
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1097 |
self.MapTranslation[map] = mapname |
205 | 1098 |
|
1099 |
def GetMapValue(self, mapname): |
|
1100 |
if mapname == "None": |
|
1101 |
return 0 |
|
1102 |
else: |
|
1103 |
list = self.GetMapVariableList() |
|
1104 |
for index, subIndex, size, name in list: |
|
536
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1105 |
if mapname == self.GenerateMapName(name, index, subIndex): |
205 | 1106 |
return (index << 16) + (subIndex << 8) + size |
1107 |
return None |
|
1108 |
||
1109 |
def GetMapName(self, value): |
|
1110 |
if value != 0: |
|
1111 |
index = value >> 16 |
|
1112 |
subindex = (value >> 8) % (1 << 8) |
|
1113 |
result = self.GetSubentryInfos(index, subindex) |
|
1114 |
if result: |
|
536
00935990f087
Adding index in PDO mapping names for differenciate mapped variables when they have the same name
lbessard
parents:
523
diff
changeset
|
1115 |
return self.GenerateMapName(result["name"], index, subindex) |
205 | 1116 |
return "None" |
1117 |
||
1118 |
""" |
|
1119 |
Return the list of variables that can be mapped for the current node |
|
1120 |
""" |
|
1121 |
def GetMapList(self): |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
541
diff
changeset
|
1122 |
list = [_("None")] + [self.GenerateMapName(name, index, subIndex) for index, subIndex, size, name in self.GetMapVariableList()] |
205 | 1123 |
return ",".join(list) |
273 | 1124 |
|
1125 |
def BE_to_LE(value): |
|
1126 |
""" |
|
1127 |
Convert Big Endian to Little Endian |
|
1128 |
@param value: value expressed in Big Endian |
|
1129 |
@param size: number of bytes generated |
|
1130 |
@return: a string containing the value converted |
|
1131 |
""" |
|
1132 |
||
1133 |
data = [char for char in value] |
|
1134 |
data.reverse() |
|
1135 |
return int("".join(["%2.2X"%ord(char) for char in data]), 16) |
|
327 | 1136 |
|
1137 |
def LE_to_BE(value, size): |
|
1138 |
""" |
|
1139 |
Convert Little Endian to Big Endian |
|
1140 |
@param value: value expressed in integer |
|
1141 |
@param size: number of bytes generated |
|
1142 |
@return: a string containing the value converted |
|
1143 |
""" |
|
1144 |
||
1145 |
data = ("%" + str(size * 2) + "." + str(size * 2) + "X") % value |
|
1146 |
list_car = [data[i:i+2] for i in xrange(0, len(data), 2)] |
|
1147 |
list_car.reverse() |
|
1148 |
return "".join([chr(int(car, 16)) for car in list_car]) |
|
1149 |