author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 16 Aug 2017 12:53:23 +0300 | |
changeset 1750 | acf02488f37f |
parent 1749 | d73b64672238 |
child 1765 | ccf59c1f0b45 |
permissions | -rw-r--r-- |
58 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
58 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
58 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
58 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
58 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
19 |
# GNU General Public License for more details. |
58 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1278
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
58 | 24 |
|
25 |
from types import * |
|
26 |
||
27 |
# Translation between IEC types and Can Open types |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
28 |
IECToCOType = { |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
29 |
"BOOL": 0x01, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
30 |
"SINT": 0x02, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
31 |
"INT": 0x03, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
32 |
"DINT": 0x04, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
33 |
"LINT": 0x10, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
34 |
"USINT": 0x05, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
35 |
"UINT": 0x06, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
36 |
"UDINT": 0x07, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
37 |
"ULINT": 0x1B, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
38 |
"REAL": 0x08, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
39 |
"LREAL": 0x11, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
40 |
"STRING": 0x09, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
41 |
"BYTE": 0x05, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
42 |
"WORD": 0x06, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
43 |
"DWORD": 0x07, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
44 |
"LWORD": 0x1B, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
45 |
"WSTRING": 0x0B |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
46 |
} |
58 | 47 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
48 |
# Constants for PDO types |
58 | 49 |
RPDO = 1 |
50 |
TPDO = 2 |
|
51 |
||
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
52 |
SlavePDOType = {"I": TPDO, "Q": RPDO} |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
53 |
InvertPDOType = {RPDO: TPDO, TPDO: RPDO} |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
54 |
PDOTypeBaseIndex = {RPDO: 0x1400, TPDO: 0x1800} |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
55 |
PDOTypeBaseCobId = {RPDO: 0x200, TPDO: 0x180} |
58 | 56 |
|
57 |
VariableIncrement = 0x100 |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
58 |
VariableStartIndex = {TPDO: 0x2000, RPDO: 0x4000} |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
59 |
VariableDirText = {TPDO: "__I", RPDO: "__Q"} |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
60 |
VariableTypeOffset = dict(zip(["", "X", "B", "W", "D", "L"], range(6))) |
58 | 61 |
|
62 |
TrashVariables = [(1, 0x01), (8, 0x05), (16, 0x06), (32, 0x07), (64, 0x1B)] |
|
63 |
||
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
64 |
#------------------------------------------------------------------------------- |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
65 |
# Specific exception for PDO mapping errors |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
66 |
#------------------------------------------------------------------------------- |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
67 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
68 |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
69 |
class PDOmappingException(Exception): |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
70 |
pass |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
71 |
|
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
72 |
|
58 | 73 |
def LE_to_BE(value, size): |
74 |
""" |
|
75 |
Convert Little Endian to Big Endian |
|
76 |
@param value: value expressed in integer |
|
77 |
@param size: number of bytes generated |
|
78 |
@return: a string containing the value converted |
|
79 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
80 |
|
58 | 81 |
data = ("%" + str(size * 2) + "." + str(size * 2) + "X") % value |
82 |
list_car = [data[i:i+2] for i in xrange(0, len(data), 2)] |
|
83 |
list_car.reverse() |
|
84 |
return "".join([chr(int(car, 16)) for car in list_car]) |
|
85 |
||
86 |
||
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
87 |
def GetNodePDOIndexes(node, type, parameters=False): |
58 | 88 |
""" |
89 |
Find the PDO indexes of a node |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
90 |
@param node: node |
58 | 91 |
@param type: type of PDO searched (RPDO or TPDO or both) |
92 |
@param parameters: indicate which indexes are expected (PDO paramaters : True or PDO mappings : False) |
|
93 |
@return: a list of indexes found |
|
94 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
95 |
|
58 | 96 |
indexes = [] |
97 |
if type & RPDO: |
|
98 |
indexes.extend([idx for idx in node.GetIndexes() if 0x1400 <= idx <= 0x15FF]) |
|
99 |
if type & TPDO: |
|
100 |
indexes.extend([idx for idx in node.GetIndexes() if 0x1800 <= idx <= 0x19FF]) |
|
101 |
if not parameters: |
|
102 |
return [idx + 0x200 for idx in indexes] |
|
103 |
else: |
|
104 |
return indexes |
|
105 |
||
106 |
||
107 |
def SearchNodePDOMapping(loc_infos, node): |
|
108 |
""" |
|
109 |
Find the PDO indexes of a node |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
110 |
@param node: node |
58 | 111 |
@param type: type of PDO searched (RPDO or TPDO or both) |
112 |
@param parameters: indicate which indexes are expected (PDO paramaters : True or PDO mappings : False) |
|
113 |
@return: a list of indexes found |
|
114 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
115 |
|
270 | 116 |
model = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
117 |
|
58 | 118 |
for PDOidx in GetNodePDOIndexes(node, loc_infos["pdotype"]): |
119 |
values = node.GetEntry(PDOidx) |
|
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
120 |
if values is not None: |
58 | 121 |
for subindex, mapping in enumerate(values): |
270 | 122 |
if subindex != 0 and mapping & 0xFFFFFF00 == model: |
58 | 123 |
return PDOidx, subindex |
124 |
return None |
|
125 |
||
126 |
||
127 |
def GeneratePDOMappingDCF(idx, cobid, transmittype, pdomapping): |
|
128 |
""" |
|
129 |
Build concise DCF value for configuring a PDO |
|
130 |
@param idx: index of PDO parameters |
|
131 |
@param cobid: PDO generated COB ID |
|
132 |
@param transmittype : PDO transmit type |
|
133 |
@param pdomapping: list of PDO mappings |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
134 |
@return: a tuple of value and number of parameters to add to DCF |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
135 |
""" |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
136 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
137 |
dcfdata = [] |
58 | 138 |
# Create entry for RPDO or TPDO parameters and Disable PDO |
1278
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
139 |
# ---- INDEX ----- --- SUBINDEX ---- ----- SIZE ------ ------ DATA ------ |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
140 |
dcfdata += [LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE(0x80000000 + cobid, 4)] |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
141 |
# Set Transmit type |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
142 |
dcfdata += [LE_to_BE(idx, 2) + LE_to_BE(0x02, 1) + LE_to_BE(0x01, 4) + LE_to_BE(transmittype, 1)] |
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
143 |
if len(pdomapping) > 0: |
1278
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
144 |
# Disable Mapping |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
145 |
dcfdata += [LE_to_BE(idx + 0x200, 2) + LE_to_BE(0x00, 1) + LE_to_BE(0x01, 4) + LE_to_BE(0x00, 1)] |
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
146 |
# Map Variables |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
147 |
for subindex, (name, loc_infos) in enumerate(pdomapping): |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
148 |
value = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + loc_infos["size"] |
1278
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
149 |
dcfdata += [LE_to_BE(idx + 0x200, 2) + LE_to_BE(subindex + 1, 1) + LE_to_BE(0x04, 4) + LE_to_BE(value, 4)] |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
150 |
# Re-enable Mapping |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
151 |
dcfdata += [LE_to_BE(idx + 0x200, 2) + LE_to_BE(0x00, 1) + LE_to_BE(0x01, 4) + LE_to_BE(len(pdomapping), 1)] |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
152 |
# Re-Enable PDO |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
153 |
dcfdata += [LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE(cobid, 4)] |
74afc7e86d00
CanFestival plugin fills master's DCF to prepare PDO mappings in a way conform to DSP-301
Edouard Tisserant
parents:
721
diff
changeset
|
154 |
return "".join(dcfdata), len(dcfdata) |
58 | 155 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
156 |
|
58 | 157 |
class ConciseDCFGenerator: |
158 |
||
159 |
def __init__(self, nodelist, nodename): |
|
160 |
# Dictionary of location informations classed by name |
|
161 |
self.IECLocations = {} |
|
162 |
# Dictionary of location that have not been mapped yet |
|
163 |
self.LocationsNotMapped = {} |
|
164 |
# Dictionary of location informations classed by name |
|
165 |
self.MasterMapping = {} |
|
166 |
# List of COB IDs available |
|
167 |
self.ListCobIDAvailable = range(0x180, 0x580) |
|
168 |
# Dictionary of mapping value where unexpected variables are stored |
|
169 |
self.TrashVariables = {} |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
170 |
# Dictionary of pointed variables |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
171 |
self.PointedVariables = {} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
172 |
|
58 | 173 |
self.NodeList = nodelist |
174 |
self.Manager = self.NodeList.Manager |
|
175 |
self.MasterNode = self.Manager.GetCurrentNodeCopy() |
|
176 |
self.MasterNode.SetNodeName(nodename) |
|
177 |
self.PrepareMasterNode() |
|
178 |
||
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
179 |
def GetPointedVariables(self): |
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
180 |
return self.PointedVariables |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
181 |
|
58 | 182 |
def RemoveUsedNodeCobId(self, node): |
183 |
""" |
|
184 |
Remove all PDO COB ID used by the given node from the list of available COB ID |
|
185 |
@param node: node |
|
186 |
@return: a tuple of number of RPDO and TPDO for the node |
|
187 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
188 |
|
58 | 189 |
# Get list of all node TPDO and RPDO indexes |
190 |
nodeRpdoIndexes = GetNodePDOIndexes(node, RPDO, True) |
|
191 |
nodeTpdoIndexes = GetNodePDOIndexes(node, TPDO, True) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
192 |
|
58 | 193 |
# Mark all the COB ID of the node already mapped PDO as not available |
194 |
for PdoIdx in nodeRpdoIndexes + nodeTpdoIndexes: |
|
195 |
pdo_cobid = node.GetEntry(PdoIdx, 0x01) |
|
196 |
# Extract COB ID, if PDO isn't active |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
197 |
if pdo_cobid > 0x600: |
58 | 198 |
pdo_cobid -= 0x80000000 |
199 |
# Remove COB ID from the list of available COB ID |
|
200 |
if pdo_cobid in self.ListCobIDAvailable: |
|
201 |
self.ListCobIDAvailable.remove(pdo_cobid) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
202 |
|
58 | 203 |
return len(nodeRpdoIndexes), len(nodeTpdoIndexes) |
204 |
||
205 |
def PrepareMasterNode(self): |
|
206 |
""" |
|
207 |
Add mandatory entries for DCF generation into MasterNode. |
|
208 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
209 |
|
58 | 210 |
# Adding DCF entry into Master node |
211 |
if not self.MasterNode.IsEntry(0x1F22): |
|
212 |
self.MasterNode.AddEntry(0x1F22, 1, "") |
|
213 |
self.Manager.AddSubentriesToCurrent(0x1F22, 127, self.MasterNode) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
214 |
|
58 | 215 |
# Adding trash mappable variables for unused mapped datas |
216 |
idxTrashVariables = 0x2000 + self.MasterNode.GetNodeID() |
|
217 |
# Add an entry for storing unexpected all variable |
|
218 |
self.Manager.AddMapVariableToCurrent(idxTrashVariables, self.MasterNode.GetNodeName()+"_trashvariables", 3, len(TrashVariables), self.MasterNode) |
|
219 |
for subidx, (size, typeidx) in enumerate(TrashVariables): |
|
220 |
# Add a subentry for storing unexpected variable of this size |
|
221 |
self.Manager.SetCurrentEntry(idxTrashVariables, subidx + 1, "TRASH%d" % size, "name", None, self.MasterNode) |
|
222 |
self.Manager.SetCurrentEntry(idxTrashVariables, subidx + 1, typeidx, "type", None, self.MasterNode) |
|
223 |
# Store the mapping value for this entry |
|
224 |
self.TrashVariables[size] = (idxTrashVariables << 16) + ((subidx + 1) << 8) + size |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
225 |
|
58 | 226 |
RPDOnumber, TPDOnumber = self.RemoveUsedNodeCobId(self.MasterNode) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
227 |
|
58 | 228 |
# Store the indexes of the first RPDO and TPDO available for MasterNode |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
229 |
self.CurrentPDOParamsIdx = {RPDO: 0x1400 + RPDOnumber, TPDO: 0x1800 + TPDOnumber} |
58 | 230 |
|
231 |
# Prepare MasterNode with all nodelist slaves |
|
232 |
for idx, (nodeid, nodeinfos) in enumerate(self.NodeList.SlaveNodes.items()): |
|
233 |
node = nodeinfos["Node"] |
|
234 |
node.SetNodeID(nodeid) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
235 |
|
58 | 236 |
RPDOnumber, TPDOnumber = self.RemoveUsedNodeCobId(node) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
237 |
|
58 | 238 |
# Get Slave's default SDO server parameters |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
239 |
RSDO_cobid = node.GetEntry(0x1200, 0x01) |
58 | 240 |
if not RSDO_cobid: |
241 |
RSDO_cobid = 0x600 + nodeid |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
242 |
TSDO_cobid = node.GetEntry(0x1200, 0x02) |
58 | 243 |
if not TSDO_cobid: |
244 |
TSDO_cobid = 0x580 + nodeid |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
245 |
|
58 | 246 |
# Configure Master's SDO parameters entries |
247 |
self.Manager.ManageEntriesOfCurrent([0x1280 + idx], [], self.MasterNode) |
|
248 |
self.MasterNode.SetEntry(0x1280 + idx, 0x01, RSDO_cobid) |
|
249 |
self.MasterNode.SetEntry(0x1280 + idx, 0x02, TSDO_cobid) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
250 |
self.MasterNode.SetEntry(0x1280 + idx, 0x03, nodeid) |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
251 |
|
58 | 252 |
def GetMasterNode(self): |
253 |
""" |
|
254 |
Return MasterNode. |
|
255 |
""" |
|
256 |
return self.MasterNode |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
257 |
|
58 | 258 |
def AddParamsToDCF(self, nodeid, data, nbparams): |
259 |
""" |
|
155 | 260 |
Add entry to DCF, for the requested nodeID |
58 | 261 |
@param nodeid: id of the slave (int) |
262 |
@param data: data to add to slave DCF (string) |
|
263 |
@param nbparams: number of params added to slave DCF (int) |
|
264 |
""" |
|
265 |
# Get current DCF for slave |
|
266 |
nodeDCF = self.MasterNode.GetEntry(0x1F22, nodeid) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
267 |
|
58 | 268 |
# Extract data and number of params in current DCF |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
269 |
if nodeDCF is not None and nodeDCF != '': |
58 | 270 |
tmpnbparams = [i for i in nodeDCF[:4]] |
271 |
tmpnbparams.reverse() |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
272 |
nbparams += int(''.join(["%2.2x" % ord(i) for i in tmpnbparams]), 16) |
58 | 273 |
data = nodeDCF[4:] + data |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
274 |
|
58 | 275 |
# Build new DCF |
276 |
dcf = LE_to_BE(nbparams, 0x04) + data |
|
277 |
# Set new DCF for slave |
|
278 |
self.MasterNode.SetEntry(0x1F22, nodeid, dcf) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
279 |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
280 |
def GetEmptyPDO(self, nodeid, pdotype, start_index=None): |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
281 |
""" |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
282 |
Search a not configured PDO for a slave |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
283 |
@param node: the slave node object |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
284 |
@param pdotype: type of PDO to generated (RPDO or TPDO) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
285 |
@param start_index: Index where search must start (default: None) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
286 |
@return tuple of PDO index, COB ID and number of subindex defined |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
287 |
""" |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
288 |
# If no start_index defined, start with PDOtype base index |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
289 |
if start_index is None: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
290 |
index = PDOTypeBaseIndex[pdotype] |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
291 |
else: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
292 |
index = start_index |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
293 |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
294 |
# Search for all PDO possible index until find a configurable PDO |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
295 |
# starting from start_index |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
296 |
while index < PDOTypeBaseIndex[pdotype] + 0x200: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
297 |
values = self.NodeList.GetSlaveNodeEntry(nodeid, index + 0x200) |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
298 |
if values is not None and values[0] > 0: |
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
299 |
# Check that all subindex upper than 0 equal 0 => configurable PDO |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
300 |
if reduce(lambda x, y: x and y, map(lambda x: x == 0, values[1:]), True): |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
301 |
cobid = self.NodeList.GetSlaveNodeEntry(nodeid, index, 1) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
302 |
# If no COB ID defined in PDO, generate a new one (not used) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
303 |
if cobid == 0: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
304 |
if len(self.ListCobIDAvailable) == 0: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
305 |
return None |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
306 |
# Calculate COB ID from standard values |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
307 |
if index < PDOTypeBaseIndex[pdotype] + 4: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
308 |
cobid = PDOTypeBaseCobId[pdotype] + 0x100 * (index - PDOTypeBaseIndex[pdotype]) + nodeid |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
309 |
if cobid not in self.ListCobIDAvailable: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
310 |
cobid = self.ListCobIDAvailable.pop(0) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
311 |
return index, cobid, values[0] |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
312 |
index += 1 |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
313 |
return None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
314 |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
315 |
def AddPDOMapping(self, nodeid, pdotype, pdoindex, pdocobid, pdomapping, sync_TPDOs): |
58 | 316 |
""" |
155 | 317 |
Record a new mapping request for a slave, and add related slave config to the DCF |
58 | 318 |
@param nodeid: id of the slave (int) |
319 |
@param pdotype: type of PDO to generated (RPDO or TPDO) |
|
320 |
@param pdomapping: list od variables to map with PDO |
|
321 |
""" |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
322 |
# Add an entry to MasterMapping |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
323 |
self.MasterMapping[pdocobid] = {"type": InvertPDOType[pdotype], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
324 |
"mapping": [None] + [(loc_infos["type"], name) for name, loc_infos in pdomapping]} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
325 |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
326 |
# Return the data to add to DCF |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
327 |
if sync_TPDOs: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
328 |
return GeneratePDOMappingDCF(pdoindex, pdocobid, 0x01, pdomapping) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
329 |
else: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
330 |
return GeneratePDOMappingDCF(pdoindex, pdocobid, 0xFF, pdomapping) |
58 | 331 |
return 0, "" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
332 |
|
58 | 333 |
def GenerateDCF(self, locations, current_location, sync_TPDOs): |
334 |
""" |
|
335 |
Generate Concise DCF of MasterNode for the locations list given |
|
336 |
@param locations: list of locations to be mapped |
|
337 |
@param current_location: tuple of the located prefixes not to be considered |
|
338 |
@param sync_TPDOs: indicate if TPDO must be synchronous |
|
339 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
340 |
|
58 | 341 |
#------------------------------------------------------------------------------- |
342 |
# Verify that locations correspond to real slave variables |
|
343 |
#------------------------------------------------------------------------------- |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
344 |
|
58 | 345 |
# Get list of locations check if exists and mappables -> put them in IECLocations |
346 |
for location in locations: |
|
347 |
COlocationtype = IECToCOType[location["IEC_TYPE"]] |
|
348 |
name = location["NAME"] |
|
349 |
if name in self.IECLocations: |
|
350 |
if self.IECLocations[name]["type"] != COlocationtype: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
351 |
raise PDOmappingException, _("Type conflict for location \"%s\"") % name |
58 | 352 |
else: |
353 |
# Get only the part of the location that concern this node |
|
354 |
loc = location["LOC"][len(current_location):] |
|
355 |
# loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
|
166 | 356 |
if len(loc) not in (2, 3, 4): |
361 | 357 |
raise PDOmappingException, _("Bad location size : %s") % str(loc) |
166 | 358 |
elif len(loc) == 2: |
359 |
continue |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
360 |
|
58 | 361 |
direction = location["DIR"] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
362 |
|
58 | 363 |
sizelocation = location["SIZE"] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
364 |
|
58 | 365 |
# Extract and check nodeid |
366 |
nodeid, index, subindex = loc[:3] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
367 |
|
58 | 368 |
# Check Id is in slave node list |
369 |
if nodeid not in self.NodeList.SlaveNodes.keys(): |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
370 |
raise PDOmappingException, _("Non existing node ID : {a1} (variable {a2})").format(a1=nodeid, a2=name) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
371 |
|
58 | 372 |
# Get the model for this node (made from EDS) |
373 |
node = self.NodeList.SlaveNodes[nodeid]["Node"] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
374 |
|
58 | 375 |
# Extract and check index and subindex |
376 |
if not node.IsEntry(index, subindex): |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
377 |
msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\ |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
378 |
format(a1="%x" % index, a2="%x" % subindex, a3=nodeid, a4=name) |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
379 |
raise PDOmappingException, msg |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
380 |
|
58 | 381 |
# Get the entry info |
382 |
subentry_infos = node.GetSubentryInfos(index, subindex) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
383 |
|
58 | 384 |
# If a PDO mappable |
385 |
if subentry_infos and subentry_infos["pdo"]: |
|
386 |
if sizelocation == "X" and len(loc) > 3: |
|
61 | 387 |
numbit = loc[3] |
58 | 388 |
elif sizelocation != "X" and len(loc) > 3: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
389 |
msg = _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))").\ |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
390 |
format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex) |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
391 |
raise PDOmappingException, msg |
58 | 392 |
else: |
393 |
numbit = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
394 |
|
166 | 395 |
if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype: |
1722
89824afffef2
fix some typos
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
396 |
raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\ |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
397 |
format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
398 |
|
58 | 399 |
typeinfos = node.GetEntryInfos(COlocationtype) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
400 |
self.IECLocations[name] = { |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
401 |
"type": COlocationtype, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
402 |
"pdotype": SlavePDOType[direction], |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
403 |
"nodeid": nodeid, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
404 |
"index": index, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
405 |
"subindex": subindex, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
406 |
"bit": numbit, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
407 |
"size": typeinfos["size"], |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
408 |
"sizelocation": sizelocation |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
409 |
} |
58 | 410 |
else: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
411 |
raise PDOmappingException, _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").\ |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
412 |
format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
413 |
|
58 | 414 |
#------------------------------------------------------------------------------- |
415 |
# Search for locations already mapped |
|
416 |
#------------------------------------------------------------------------------- |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
417 |
|
58 | 418 |
for name, locationinfos in self.IECLocations.items(): |
419 |
node = self.NodeList.SlaveNodes[locationinfos["nodeid"]]["Node"] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
420 |
|
58 | 421 |
# Search if slave has a PDO mapping this locations |
422 |
result = SearchNodePDOMapping(locationinfos, node) |
|
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
423 |
if result is not None: |
58 | 424 |
index, subindex = result |
425 |
# Get COB ID of the PDO |
|
426 |
cobid = self.NodeList.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
427 |
|
58 | 428 |
# Add PDO to MasterMapping |
429 |
if cobid not in self.MasterMapping.keys(): |
|
80 | 430 |
# Verify that PDO transmit type is conform to sync_TPDOs |
431 |
transmittype = self.NodeList.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 2) |
|
432 |
if sync_TPDOs and transmittype != 0x01 or transmittype != 0xFF: |
|
433 |
if sync_TPDOs: |
|
434 |
# Change TransmitType to SYNCHRONE |
|
435 |
data, nbparams = GeneratePDOMappingDCF(index - 0x200, cobid, 0x01, []) |
|
436 |
else: |
|
437 |
# Change TransmitType to ASYCHRONE |
|
438 |
data, nbparams = GeneratePDOMappingDCF(index - 0x200, cobid, 0xFF, []) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
439 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
440 |
# Add entry to slave dcf to change transmit type of |
80 | 441 |
self.AddParamsToDCF(locationinfos["nodeid"], data, nbparams) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
442 |
|
58 | 443 |
mapping = [None] |
444 |
values = node.GetEntry(index) |
|
445 |
# Store the size of each entry mapped in PDO |
|
446 |
for value in values[1:]: |
|
78 | 447 |
if value != 0: |
448 |
mapping.append(value % 0x100) |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
449 |
self.MasterMapping[cobid] = {"type": InvertPDOType[locationinfos["pdotype"]], "mapping": mapping} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
450 |
|
58 | 451 |
# Indicate that this PDO entry must be saved |
270 | 452 |
if locationinfos["bit"] is not None: |
453 |
if not isinstance(self.MasterMapping[cobid]["mapping"][subindex], ListType): |
|
454 |
self.MasterMapping[cobid]["mapping"][subindex] = [1] * self.MasterMapping[cobid]["mapping"][subindex] |
|
455 |
if locationinfos["bit"] < len(self.MasterMapping[cobid]["mapping"][subindex]): |
|
456 |
self.MasterMapping[cobid]["mapping"][subindex][locationinfos["bit"]] = (locationinfos["type"], name) |
|
457 |
else: |
|
458 |
self.MasterMapping[cobid]["mapping"][subindex] = (locationinfos["type"], name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
459 |
|
58 | 460 |
else: |
461 |
# Add location to those that haven't been mapped yet |
|
462 |
if locationinfos["nodeid"] not in self.LocationsNotMapped.keys(): |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
463 |
self.LocationsNotMapped[locationinfos["nodeid"]] = {TPDO: [], RPDO: []} |
58 | 464 |
self.LocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
465 |
|
58 | 466 |
#------------------------------------------------------------------------------- |
467 |
# Build concise DCF for the others locations |
|
468 |
#------------------------------------------------------------------------------- |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
469 |
|
58 | 470 |
for nodeid, locations in self.LocationsNotMapped.items(): |
61 | 471 |
node = self.NodeList.SlaveNodes[nodeid]["Node"] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
472 |
|
58 | 473 |
# Initialize number of params and data to add to node DCF |
474 |
nbparams = 0 |
|
475 |
dataparams = "" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
476 |
|
58 | 477 |
# Generate the best PDO mapping for each type of PDO |
478 |
for pdotype in (TPDO, RPDO): |
|
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
479 |
if len(locations[pdotype]) > 0: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
480 |
pdosize = 0 |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
481 |
pdomapping = [] |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
482 |
result = self.GetEmptyPDO(nodeid, pdotype) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
483 |
if result is None: |
415
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
361
diff
changeset
|
484 |
raise PDOmappingException, _("Unable to define PDO mapping for node %02x") % nodeid |
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
485 |
pdoindex, pdocobid, pdonbparams = result |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
486 |
for name, loc_infos in locations[pdotype]: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
487 |
pdosize += loc_infos["size"] |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
488 |
# If pdo's size > 64 bits |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
489 |
if pdosize > 64 or len(pdomapping) >= pdonbparams: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
490 |
# Generate a new PDO Mapping |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
491 |
data, nbaddedparams = self.AddPDOMapping(nodeid, pdotype, pdoindex, pdocobid, pdomapping, sync_TPDOs) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
492 |
dataparams += data |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
493 |
nbparams += nbaddedparams |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
494 |
pdosize = loc_infos["size"] |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
495 |
pdomapping = [(name, loc_infos)] |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
496 |
result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
497 |
if result is None: |
415
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
361
diff
changeset
|
498 |
raise PDOmappingException, _("Unable to define PDO mapping for node %02x") % nodeid |
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
499 |
pdoindex, pdocobid, pdonbparams = result |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
500 |
else: |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
501 |
pdomapping.append((name, loc_infos)) |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
502 |
# If there isn't locations yet but there is still a PDO to generate |
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
503 |
if len(pdomapping) > 0: |
58 | 504 |
# Generate a new PDO Mapping |
340
651b8fb572e7
Adding support for using only PDO define in EDS file and not configured for adding mapping in node
greg
parents:
307
diff
changeset
|
505 |
data, nbaddedparams = self.AddPDOMapping(nodeid, pdotype, pdoindex, pdocobid, pdomapping, sync_TPDOs) |
58 | 506 |
dataparams += data |
507 |
nbparams += nbaddedparams |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
508 |
|
58 | 509 |
# Add number of params and data to node DCF |
510 |
self.AddParamsToDCF(nodeid, dataparams, nbparams) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
511 |
|
58 | 512 |
#------------------------------------------------------------------------------- |
513 |
# Master Node Configuration |
|
514 |
#------------------------------------------------------------------------------- |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
515 |
|
58 | 516 |
# Generate Master's Configuration from informations stored in MasterMapping |
517 |
for cobid, pdo_infos in self.MasterMapping.items(): |
|
518 |
# Get next PDO index in MasterNode for this PDO type |
|
519 |
current_idx = self.CurrentPDOParamsIdx[pdo_infos["type"]] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
520 |
|
58 | 521 |
# Search if there is already a PDO in MasterNode with this cob id |
522 |
for idx in GetNodePDOIndexes(self.MasterNode, pdo_infos["type"], True): |
|
523 |
if self.MasterNode.GetEntry(idx, 1) == cobid: |
|
524 |
current_idx = idx |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
525 |
|
58 | 526 |
# Add a PDO to MasterNode if not PDO have been found |
527 |
if current_idx == self.CurrentPDOParamsIdx[pdo_infos["type"]]: |
|
528 |
addinglist = [current_idx, current_idx + 0x200] |
|
529 |
self.Manager.ManageEntriesOfCurrent(addinglist, [], self.MasterNode) |
|
530 |
self.MasterNode.SetEntry(current_idx, 0x01, cobid) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
531 |
|
58 | 532 |
# Increment the number of PDO for this PDO type |
533 |
self.CurrentPDOParamsIdx[pdo_infos["type"]] += 1 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
534 |
|
58 | 535 |
# Change the transmit type of the PDO |
536 |
if sync_TPDOs: |
|
537 |
self.MasterNode.SetEntry(current_idx, 0x02, 0x01) |
|
538 |
else: |
|
539 |
self.MasterNode.SetEntry(current_idx, 0x02, 0xFF) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
540 |
|
270 | 541 |
mapping = [] |
542 |
for item in pdo_infos["mapping"]: |
|
543 |
if isinstance(item, ListType): |
|
544 |
mapping.extend(item) |
|
545 |
else: |
|
546 |
mapping.append(item) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
547 |
|
58 | 548 |
# Add some subentries to PDO mapping if there is not enough |
270 | 549 |
if len(mapping) > 1: |
550 |
self.Manager.AddSubentriesToCurrent(current_idx + 0x200, len(mapping) - 1, self.MasterNode) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
551 |
|
58 | 552 |
# Generate MasterNode's PDO mapping |
270 | 553 |
for subindex, variable in enumerate(mapping): |
58 | 554 |
if subindex == 0: |
555 |
continue |
|
556 |
new_index = False |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
557 |
|
225 | 558 |
if isinstance(variable, (IntType, LongType)): |
58 | 559 |
# If variable is an integer then variable is unexpected |
560 |
self.MasterNode.SetEntry(current_idx + 0x200, subindex, self.TrashVariables[variable]) |
|
561 |
else: |
|
562 |
typeidx, varname = variable |
|
563 |
variable_infos = self.IECLocations[varname] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
564 |
|
58 | 565 |
# Calculate base index for storing variable |
566 |
mapvariableidx = VariableStartIndex[variable_infos["pdotype"]] + \ |
|
567 |
VariableTypeOffset[variable_infos["sizelocation"]] * VariableIncrement + \ |
|
568 |
variable_infos["nodeid"] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
569 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
570 |
# Generate entry name |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
571 |
indexname = "%s%s%s_%d" % (VariableDirText[variable_infos["pdotype"]], |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
572 |
variable_infos["sizelocation"], |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
573 |
'_'.join(map(str, current_location)), |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
574 |
variable_infos["nodeid"]) |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
575 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
576 |
# Search for an entry that has an empty subindex |
58 | 577 |
while mapvariableidx < VariableStartIndex[variable_infos["pdotype"]] + 0x2000: |
578 |
# Entry doesn't exist |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
579 |
if not self.MasterNode.IsEntry(mapvariableidx): |
58 | 580 |
# Add entry to MasterNode |
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
581 |
self.Manager.AddMapVariableToCurrent(mapvariableidx, "beremiz"+indexname, 3, 1, self.MasterNode) |
58 | 582 |
new_index = True |
583 |
nbsubentries = self.MasterNode.GetEntry(mapvariableidx, 0x00) |
|
584 |
else: |
|
585 |
# Get Number of subentries already defined |
|
586 |
nbsubentries = self.MasterNode.GetEntry(mapvariableidx, 0x00) |
|
587 |
# if entry is full, go to next entry possible or stop now |
|
588 |
if nbsubentries == 0xFF: |
|
589 |
mapvariableidx += 8 * VariableIncrement |
|
590 |
else: |
|
591 |
break |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
592 |
|
58 | 593 |
# Verify that a not full entry has been found |
594 |
if mapvariableidx < VariableStartIndex[variable_infos["pdotype"]] + 0x2000: |
|
595 |
# Generate subentry name |
|
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
596 |
if variable_infos["bit"] is not None: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
597 |
subindexname = "%(index)d_%(subindex)d_%(bit)d" % variable_infos |
58 | 598 |
else: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
599 |
subindexname = "%(index)d_%(subindex)d" % variable_infos |
58 | 600 |
# If entry have just been created, no subentry have to be added |
601 |
if not new_index: |
|
602 |
self.Manager.AddSubentriesToCurrent(mapvariableidx, 1, self.MasterNode) |
|
603 |
nbsubentries += 1 |
|
604 |
# Add informations to the new subentry created |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
605 |
self.MasterNode.SetMappingEntry(mapvariableidx, nbsubentries, values={"name": subindexname}) |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
606 |
self.MasterNode.SetMappingEntry(mapvariableidx, nbsubentries, values={"type": typeidx}) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
607 |
|
58 | 608 |
# Set value of the PDO mapping |
609 |
typeinfos = self.Manager.GetEntryInfos(typeidx) |
|
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
610 |
if typeinfos is not None: |
58 | 611 |
value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"] |
612 |
self.MasterNode.SetEntry(current_idx + 0x200, subindex, value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
613 |
|
163
482ca562d414
Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents:
155
diff
changeset
|
614 |
# Add variable to pointed variables |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
615 |
self.PointedVariables[(mapvariableidx, nbsubentries)] = "%s_%s" % (indexname, subindexname) |
58 | 616 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
617 |
|
58 | 618 |
def GenerateConciseDCF(locations, current_location, nodelist, sync_TPDOs, nodename): |
619 |
""" |
|
620 |
Fills a CanFestival network editor model, with DCF with requested PDO mappings. |
|
621 |
@param locations: List of complete variables locations \ |
|
622 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
|
623 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
624 |
"DIR" : direction "Q","I" or "M" |
|
625 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
626 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
627 |
}, ...] |
|
628 |
@param nodelist: CanFestival network editor model |
|
629 |
@return: a modified copy of the given CanFestival network editor model |
|
630 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
631 |
|
58 | 632 |
dcfgenerator = ConciseDCFGenerator(nodelist, nodename) |
633 |
dcfgenerator.GenerateDCF(locations, current_location, sync_TPDOs) |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
634 |
masternode, pointers = dcfgenerator.GetMasterNode(), dcfgenerator.GetPointedVariables() |
307
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
635 |
# allow access to local OD from Master PLC |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
636 |
pointers.update(LocalODPointers(locations, current_location, masternode)) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
637 |
return masternode, pointers |
58 | 638 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
639 |
|
166 | 640 |
def LocalODPointers(locations, current_location, slave): |
641 |
IECLocations = {} |
|
642 |
pointers = {} |
|
643 |
for location in locations: |
|
644 |
COlocationtype = IECToCOType[location["IEC_TYPE"]] |
|
645 |
name = location["NAME"] |
|
646 |
if name in IECLocations: |
|
647 |
if IECLocations[name] != COlocationtype: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
648 |
raise PDOmappingException, _("Type conflict for location \"%s\"") % name |
166 | 649 |
else: |
650 |
# Get only the part of the location that concern this node |
|
651 |
loc = location["LOC"][len(current_location):] |
|
652 |
# loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
|
653 |
if len(loc) not in (2, 3, 4): |
|
361 | 654 |
raise PDOmappingException, _("Bad location size : %s") % str(loc) |
166 | 655 |
elif len(loc) != 2: |
656 |
continue |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
657 |
|
166 | 658 |
# Extract and check nodeid |
659 |
index, subindex = loc[:2] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
660 |
|
166 | 661 |
# Extract and check index and subindex |
662 |
if not slave.IsEntry(index, subindex): |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
663 |
raise PDOmappingException, _("No such index/subindex ({a1},{a2}) (variable {a3})").\ |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
664 |
format(a1="%x" % index, a2="%x" % subindex, a3=name) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
665 |
|
166 | 666 |
# Get the entry info |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
667 |
subentry_infos = slave.GetSubentryInfos(index, subindex) |
166 | 668 |
if subentry_infos["type"] != COlocationtype: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
669 |
raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\ |
1747
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
670 |
format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
671 |
|
166 | 672 |
IECLocations[name] = COlocationtype |
673 |
pointers[(index, subindex)] = name |
|
674 |
return pointers |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
675 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
676 |
|
58 | 677 |
if __name__ == "__main__": |
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
678 |
import os |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
679 |
import sys |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
680 |
import getopt |
58 | 681 |
|
682 |
def usage(): |
|
683 |
print """ |
|
684 |
Usage of config_utils.py test : |
|
685 |
||
686 |
%s [options] |
|
687 |
||
688 |
Options: |
|
689 |
--help (-h) |
|
690 |
Displays help informations for config_utils |
|
691 |
||
692 |
--reset (-r) |
|
693 |
Reset the reference result of config_utils test. |
|
694 |
Use with caution. Be sure that config_utils |
|
695 |
is currently working properly. |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
696 |
""" % sys.argv[0] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
697 |
|
58 | 698 |
# Boolean that indicate if reference result must be redefined |
699 |
reset = False |
|
700 |
||
701 |
# Extract command options |
|
702 |
try: |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
703 |
opts, args = getopt.getopt(sys.argv[1:], "hr", ["help", "reset"]) |
58 | 704 |
except getopt.GetoptError: |
705 |
# print help information and exit: |
|
706 |
usage() |
|
707 |
sys.exit(2) |
|
708 |
||
709 |
# Test each option |
|
710 |
for o, a in opts: |
|
711 |
if o in ("-h", "--help"): |
|
712 |
usage() |
|
713 |
sys.exit() |
|
714 |
elif o in ("-r", "--reset"): |
|
715 |
reset = True |
|
716 |
||
717 |
# Extract workspace base folder |
|
718 |
base_folder = sys.path[0] |
|
719 |
for i in xrange(3): |
|
720 |
base_folder = os.path.split(base_folder)[0] |
|
721 |
# Add CanFestival folder to search pathes |
|
722 |
sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
723 |
|
58 | 724 |
from nodemanager import * |
725 |
from nodelist import * |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
726 |
|
58 | 727 |
# Open the test nodelist contained into test_config folder |
728 |
manager = NodeManager() |
|
729 |
nodelist = NodeList(manager) |
|
730 |
result = nodelist.LoadProject("test_config") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
731 |
|
58 | 732 |
# List of locations, we try to map for test |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
733 |
locations = [ |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
734 |
{"IEC_TYPE": "BYTE", "NAME": "__IB0_1_64_24576_1", "DIR": "I", "SIZE": "B", "LOC": (0, 1, 64, 24576, 1)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
735 |
{"IEC_TYPE": "INT", "NAME": "__IW0_1_64_25601_2", "DIR": "I", "SIZE": "W", "LOC": (0, 1, 64, 25601, 2)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
736 |
{"IEC_TYPE": "INT", "NAME": "__IW0_1_64_25601_3", "DIR": "I", "SIZE": "W", "LOC": (0, 1, 64, 25601, 3)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
737 |
{"IEC_TYPE": "INT", "NAME": "__QW0_1_64_25617_2", "DIR": "Q", "SIZE": "W", "LOC": (0, 1, 64, 25617, 1)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
738 |
{"IEC_TYPE": "BYTE", "NAME": "__IB0_1_64_24578_1", "DIR": "I", "SIZE": "B", "LOC": (0, 1, 64, 24578, 1)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
739 |
{"IEC_TYPE": "UDINT", "NAME": "__ID0_1_64_25638_1", "DIR": "I", "SIZE": "D", "LOC": (0, 1, 64, 25638, 1)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
740 |
{"IEC_TYPE": "UDINT", "NAME": "__ID0_1_64_25638_2", "DIR": "I", "SIZE": "D", "LOC": (0, 1, 64, 25638, 2)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
741 |
{"IEC_TYPE": "UDINT", "NAME": "__ID0_1_64_25638_3", "DIR": "I", "SIZE": "D", "LOC": (0, 1, 64, 25638, 3)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
742 |
{"IEC_TYPE": "UDINT", "NAME": "__ID0_1_64_25638_4", "DIR": "I", "SIZE": "D", "LOC": (0, 1, 64, 25638, 4)}, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
743 |
{"IEC_TYPE": "UDINT", "NAME": "__ID0_1_4096_0", "DIR": "I", "SIZE": "D", "LOC": (0, 1, 4096, 0)} |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
744 |
] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
745 |
|
58 | 746 |
# Generate MasterNode configuration |
747 |
try: |
|
307
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
748 |
masternode, pointedvariables = GenerateConciseDCF(locations, (0, 1), nodelist, True, "TestNode") |
58 | 749 |
except ValueError, message: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
750 |
print "%s\nTest Failed!" % message |
58 | 751 |
sys.exit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
752 |
|
307
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
753 |
import pprint |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
754 |
# Get Text corresponding to MasterNode |
307
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
755 |
result_node = masternode.PrintString() |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
756 |
result_vars = pprint.pformat(pointedvariables) |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
757 |
result = result_node + "\n********POINTERS*********\n" + result_vars + "\n" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
758 |
|
58 | 759 |
# If reset has been choosen |
760 |
if reset: |
|
761 |
# Write Text into reference result file |
|
307
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
762 |
testfile = open("test_config/result.txt", "w") |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
763 |
testfile.write(result) |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
764 |
testfile.close() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
765 |
|
58 | 766 |
print "Reset Successful!" |
767 |
else: |
|
150
204d515df3dd
Fixed non-regression test of config_utils in canfestival plugin
etisserant
parents:
80
diff
changeset
|
768 |
import os |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
769 |
|
307
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
770 |
testfile = open("test_config/result_tmp.txt", "w") |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
771 |
testfile.write(result) |
b80d3a84b8bf
Updated config_utils so that command line tests work.
etisserant
parents:
270
diff
changeset
|
772 |
testfile.close() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1722
diff
changeset
|
773 |
|
150
204d515df3dd
Fixed non-regression test of config_utils in canfestival plugin
etisserant
parents:
80
diff
changeset
|
774 |
os.system("diff test_config/result.txt test_config/result_tmp.txt") |
204d515df3dd
Fixed non-regression test of config_utils in canfestival plugin
etisserant
parents:
80
diff
changeset
|
775 |
os.remove("test_config/result_tmp.txt") |