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