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