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