11
|
1 |
#!/usr/bin/env python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
#This file is part of Beremiz, a Integrated Development Environment for
|
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
|
|
6 |
#
|
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
|
|
8 |
#
|
|
9 |
#See COPYING file for copyrights details.
|
|
10 |
#
|
|
11 |
#This library is free software; you can redistribute it and/or
|
|
12 |
#modify it under the terms of the GNU General Public
|
|
13 |
#License as published by the Free Software Foundation; either
|
|
14 |
#version 2.1 of the License, or (at your option) any later version.
|
|
15 |
#
|
|
16 |
#This library is distributed in the hope that it will be useful,
|
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 |
#General Public License for more details.
|
|
20 |
#
|
|
21 |
#You should have received a copy of the GNU General Public
|
|
22 |
#License along with this library; if not, write to the Free Software
|
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 |
|
|
25 |
from types import *
|
|
26 |
|
|
27 |
DicoTypes = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
|
|
28 |
"USINT":0x05,"UINT":0x06,"UDINT":0x07,"ULINT":0x1B,"REAL":0x08,
|
|
29 |
"LREAL":0x11,"STRING":0x09,"BYTE":0x02,"WORD":0x03,"DWORD":0x04,
|
|
30 |
"LWORD":0x1B,"WSTRING":0x0B}
|
|
31 |
|
|
32 |
DictLocations = {}
|
|
33 |
DictCobID = {}
|
|
34 |
DictLocationsNotMapped = {}
|
|
35 |
ListCobIDAvailable = []
|
|
36 |
SlavesPdoNumber = {}
|
|
37 |
|
|
38 |
# Constants for PDO types
|
|
39 |
RPDO = 1
|
|
40 |
TPDO = 2
|
|
41 |
SlavePDOType = {"I" : TPDO, "Q" : RPDO}
|
|
42 |
InvertPDOType = {RPDO : TPDO, TPDO : RPDO}
|
|
43 |
|
|
44 |
DefaultTransmitTypeMaster = 0x01
|
|
45 |
|
|
46 |
GenerateMasterMapping = lambda x:[None] + [(loc_infos["type"], name) for name, loc_infos in x]
|
|
47 |
|
|
48 |
TrashVariableSizes = {1 : 0x01, 8 : 0x05, 16 : 0x06, 32 : 0x07, 64 : 0x1B}
|
|
49 |
|
|
50 |
|
|
51 |
def GetSlavePDOIndexes(slave, type, parameters = False):
|
|
52 |
indexes = []
|
|
53 |
if type & RPDO:
|
|
54 |
indexes.extend([idx for idx in slave.GetIndexes() if 0x1400 <= idx <= 0x15FF])
|
|
55 |
if type & TPDO:
|
|
56 |
indexes.extend([idx for idx in slave.GetIndexes() if 0x1800 <= idx <= 0x19FF])
|
|
57 |
if not parameters:
|
|
58 |
return [idx + 0x200 for idx in indexes]
|
|
59 |
else:
|
|
60 |
return indexes
|
|
61 |
|
|
62 |
|
|
63 |
def LE_to_BE(value, size): # Convert Little Endian to Big Endian
|
|
64 |
data = ("%" + str(size * 2) + "." + str(size * 2) + "X") % value
|
|
65 |
list_car = [data[i:i+2] for i in xrange(0, len(data), 2)]
|
|
66 |
list_car.reverse()
|
|
67 |
return "".join([chr(int(car, 16)) for car in list_car])
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
def SearchSlavePDOMapping(loc_infos, slave): # Search the TPDO or RPDO mapping where location is defined on the slave
|
|
72 |
typeinfos = slave.GetEntryInfos(loc_infos["type"])
|
|
73 |
model = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + typeinfos["size"]
|
|
74 |
slavePDOidxlist = GetSlavePDOIndexes(slave, loc_infos["pdotype"])
|
|
75 |
|
|
76 |
for PDOidx in slavePDOidxlist:
|
|
77 |
values = slave.GetEntry(PDOidx)
|
|
78 |
if values != None:
|
|
79 |
for subindex, mapping in enumerate(values):
|
|
80 |
if subindex != 0 and mapping == model:
|
|
81 |
return PDOidx, subindex
|
|
82 |
return None
|
|
83 |
|
|
84 |
def GenerateMappingDCF(cobid, idx, pdomapping, mapped): # Build concise DCF
|
|
85 |
|
|
86 |
# Create entry for RPDO or TPDO parameters and Disable PDO
|
|
87 |
dcfdata = LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE((0x80000000 + cobid), 4)
|
|
88 |
# Set Transmit type synchrone
|
|
89 |
dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x02, 1) + LE_to_BE(0x01, 4) + LE_to_BE(DefaultTransmitTypeSlave, 1)
|
|
90 |
# Re-Enable PDO
|
|
91 |
# ---- INDEX ----- --- SUBINDEX ---- ----- SIZE ------ ------ DATA ------
|
|
92 |
dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE(0x00000000 + cobid, 4)
|
|
93 |
nbparams = 3
|
|
94 |
if mapped == False and pdomapping != None:
|
|
95 |
# Map Variables
|
|
96 |
for subindex, (name, loc_infos) in enumerate(pdomapping):
|
|
97 |
value = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + loc_infos["size"]
|
|
98 |
dcfdata += LE_to_BE(idx + 0x200, 2) + LE_to_BE(subindex + 1, 1) + LE_to_BE(0x04, 4) + LE_to_BE(value, 4)
|
|
99 |
nbparams += 1
|
|
100 |
return dcfdata, nbparams
|
|
101 |
|
|
102 |
def GetNewCobID(nodeid, type): # Return a cobid not used
|
|
103 |
global ListCobIDAvailable, SlavesPdoNumber
|
|
104 |
|
|
105 |
if len(ListCobIDAvailable) == 0:
|
|
106 |
return None
|
|
107 |
|
|
108 |
nbSlavePDO = SlavesPdoNumber[nodeid][type]
|
|
109 |
if type == RPDO:
|
|
110 |
if nbSlavePDO < 4:
|
|
111 |
# For the fourth PDO -> cobid = 0x200 + ( numPdo parameters * 0x100) + nodeid
|
|
112 |
newcobid = (0x200 + nbSlavePDO * 0x100 + nodeid)
|
|
113 |
if newcobid in ListCobIDAvailable:
|
|
114 |
ListCobIDAvailable.remove(newcobid)
|
|
115 |
return newcobid, 0x1400 + nbSlavePDO
|
|
116 |
return ListCobIDAvailable.pop(0), 0x1400 + nbSlavePDO
|
|
117 |
|
|
118 |
elif type == TPDO:
|
|
119 |
if nbSlavePDO < 4:
|
|
120 |
# For the fourth PDO -> cobid = 0x180 + (numPdo parameters * 0x100) + nodeid
|
|
121 |
newcobid = (0x180 + nbSlavePDO * 0x100 + nodeid)
|
|
122 |
if newcobid in ListCobIDAvailable:
|
|
123 |
ListCobIDAvailable.remove(newcobid)
|
|
124 |
return newcobid, 0x1800 + nbSlavePDO
|
|
125 |
return ListCobIDAvailable.pop(0), 0x1800 + nbSlavePDO
|
|
126 |
|
|
127 |
for number in xrange(4):
|
|
128 |
if type == RPDO:
|
|
129 |
# For the fourth PDO -> cobid = 0x200 + ( numPdo * 0x100) + nodeid
|
|
130 |
newcobid = (0x200 + number * 0x100 + nodeid)
|
|
131 |
elif type == TPDO:
|
|
132 |
# For the fourth PDO -> cobid = 0x180 + (numPdo * 0x100) + nodeid
|
|
133 |
newcobid = (0x180 + number * 0x100 + nodeid)
|
|
134 |
else:
|
|
135 |
return None
|
|
136 |
if newcobid in ListCobIDAvailable:
|
|
137 |
ListCobIDAvailable.remove(newcobid)
|
|
138 |
return newcobid
|
|
139 |
return ListCobIDAvailable.pop(0)
|
|
140 |
|
|
141 |
|
|
142 |
def GenerateConciseDCF(locations, busname, nodelist):
|
|
143 |
global DictLocations, DictCobID, DictLocationsNotMapped, ListCobIDAvailable, SlavesPdoNumber, DefaultTransmitTypeSlave
|
|
144 |
|
|
145 |
DictLocations = {}
|
|
146 |
DictCobID = {}
|
|
147 |
DictLocationsNotMapped = {}
|
|
148 |
DictSDOparams = {}
|
|
149 |
ListCobIDAvailable = range(0x180, 0x580)
|
|
150 |
SlavesPdoNumber = {}
|
|
151 |
DictNameVariable = { "" : 1, "X": 2, "B": 3, "W": 4, "D": 5, "L": 6, "increment": 0x100, 1:("__I", 0x2000), 2:("__Q", 0x4000)}
|
|
152 |
DefaultTransmitTypeSlave = 0xFF
|
|
153 |
# Master Node initialisation
|
|
154 |
|
|
155 |
manager = nodelist.Manager
|
|
156 |
masternode = manager.GetCurrentNodeCopy()
|
|
157 |
if not masternode.IsEntry(0x1F22):
|
|
158 |
masternode.AddEntry(0x1F22, 1, "")
|
|
159 |
manager.AddSubentriesToCurrent(0x1F22, 127, masternode)
|
|
160 |
# Adding trash mappable variables for unused mapped datas
|
|
161 |
idxTrashVariables = 0x2000 + masternode.GetNodeID()
|
|
162 |
TrashVariableValue = {}
|
|
163 |
manager.AddMapVariableToCurrent(idxTrashVariables, "trashvariables", 3, len(TrashVariableSizes), masternode)
|
|
164 |
for subidx, (size, typeidx) in enumerate(TrashVariableSizes.items()):
|
|
165 |
manager.SetCurrentEntry(idxTrashVariables, subidx + 1, "TRASH%d" % size, "name", None, masternode)
|
|
166 |
manager.SetCurrentEntry(idxTrashVariables, subidx + 1, typeidx, "type", None, masternode)
|
|
167 |
TrashVariableValue[size] = (idxTrashVariables << 16) + ((subidx + 1) << 8) + size
|
|
168 |
|
|
169 |
|
|
170 |
# Extract Master Node current empty mapping index
|
|
171 |
CurrentPDOParamsIdx = {RPDO : 0x1400 + len(GetSlavePDOIndexes(masternode, RPDO)),
|
|
172 |
TPDO : 0x1800 + len(GetSlavePDOIndexes(masternode, TPDO))}
|
|
173 |
|
|
174 |
# Get list of all Slave's CobID and Slave's default SDO server parameters
|
|
175 |
for nodeid, nodeinfos in nodelist.SlaveNodes.items():
|
|
176 |
node = nodeinfos["Node"]
|
|
177 |
node.SetNodeID(nodeid)
|
|
178 |
DictSDOparams[nodeid] = {"RSDO" : node.GetEntry(0x1200,0x01), "TSDO" : node.GetEntry(0x1200,0x02)}
|
|
179 |
slaveRpdoIndexes = GetSlavePDOIndexes(node, RPDO, True)
|
|
180 |
slaveTpdoIndexes = GetSlavePDOIndexes(node, TPDO, True)
|
|
181 |
SlavesPdoNumber[nodeid] = {RPDO : len(slaveRpdoIndexes), TPDO : len(slaveTpdoIndexes)}
|
|
182 |
for PdoIdx in slaveRpdoIndexes + slaveTpdoIndexes:
|
|
183 |
pdo_cobid = node.GetEntry(PdoIdx, 0x01)
|
|
184 |
if pdo_cobid > 0x600 :
|
|
185 |
pdo_cobid -= 0x80000000
|
|
186 |
if pdo_cobid in ListCobIDAvailable:
|
|
187 |
ListCobIDAvailable.remove(pdo_cobid)
|
|
188 |
|
|
189 |
# Get list of locations check if exists and mappables -> put them in DictLocations
|
|
190 |
for locationtype, name in locations:
|
|
191 |
if name in DictLocations.keys():
|
|
192 |
if DictLocations[name]["type"] != DicoTypes[locationtype]:
|
|
193 |
raise ValueError, "Conflict type for location \"%s\"" % name
|
|
194 |
else:
|
|
195 |
loc = [i for i in name.split("_") if len(i) > 0]
|
|
196 |
if len(loc) not in (4, 5):
|
|
197 |
continue
|
|
198 |
|
|
199 |
prefix = loc[0][0]
|
|
200 |
|
|
201 |
# Extract and check busname
|
|
202 |
if loc[0][1].isdigit():
|
|
203 |
sizelocation = ""
|
|
204 |
busnamelocation = int(loc[0][1:])
|
|
205 |
else:
|
|
206 |
sizelocation = loc[0][1]
|
|
207 |
busnamelocation = int(loc[0][2:])
|
|
208 |
if busnamelocation != busname:
|
|
209 |
continue # A ne pas remplacer par un message d'erreur
|
|
210 |
|
|
211 |
# Extract and check nodeid
|
|
212 |
nodeid = int(loc[1])
|
|
213 |
if nodeid not in nodelist.SlaveNodes.keys():
|
|
214 |
continue
|
|
215 |
node = nodelist.SlaveNodes[nodeid]["Node"]
|
|
216 |
|
|
217 |
# Extract and check index and subindex
|
|
218 |
index = int(loc[2])
|
|
219 |
subindex = int(loc[3])
|
|
220 |
if not node.IsEntry(index, subindex):
|
|
221 |
continue
|
|
222 |
subentry_infos = node.GetSubentryInfos(index, subindex)
|
|
223 |
|
|
224 |
if subentry_infos and subentry_infos["pdo"]:
|
|
225 |
if sizelocation == "X" and len(loc) > 4:
|
|
226 |
numbit = loc[4]
|
|
227 |
elif sizelocation != "X" and len(loc) > 4:
|
|
228 |
continue
|
|
229 |
else:
|
|
230 |
numbit = None
|
|
231 |
|
|
232 |
locationtype = DicoTypes[locationtype]
|
|
233 |
entryinfos = node.GetSubentryInfos(index, subindex)
|
|
234 |
if entryinfos["type"] != locationtype:
|
|
235 |
raise ValueError, "Invalid type for location \"%s\"" % name
|
|
236 |
|
|
237 |
typeinfos = node.GetEntryInfos(locationtype)
|
|
238 |
DictLocations[name] = {"type":locationtype, "pdotype":SlavePDOType[prefix],
|
|
239 |
"nodeid": nodeid, "index": index,"subindex": subindex,
|
|
240 |
"bit": numbit, "size": typeinfos["size"], "busname": busname, "sizelocation": sizelocation}
|
|
241 |
|
|
242 |
# Create DictCobID with variables already mapped and add them in DictValidLocations
|
|
243 |
for name, locationinfos in DictLocations.items():
|
|
244 |
node = nodelist.SlaveNodes[locationinfos["nodeid"]]["Node"]
|
|
245 |
result = SearchSlavePDOMapping(locationinfos, node)
|
|
246 |
if result != None:
|
|
247 |
index, subindex = result
|
|
248 |
cobid = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1)
|
|
249 |
if cobid not in DictCobID.keys():
|
|
250 |
mapping = [None]
|
|
251 |
values = node.GetEntry(index)
|
|
252 |
for value in values[1:]:
|
|
253 |
mapping.append(value % 0x100)
|
|
254 |
DictCobID[cobid] = {"type" : InvertPDOType[locationinfos["pdotype"]], "mapping" : mapping}
|
|
255 |
|
|
256 |
DictCobID[cobid]["mapping"][subindex] = (locationinfos["type"], name)
|
|
257 |
|
|
258 |
else:
|
|
259 |
if locationinfos["nodeid"] not in DictLocationsNotMapped.keys():
|
|
260 |
DictLocationsNotMapped[locationinfos["nodeid"]] = {TPDO : [], RPDO : []}
|
|
261 |
DictLocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos))
|
|
262 |
|
|
263 |
# Check Master Pdo parameters for cobid already used and remove it in ListCobIDAvailable
|
|
264 |
ListPdoParams = [idx for idx in masternode.GetIndexes() if 0x1400 <= idx <= 0x15FF or 0x1800 <= idx <= 0x19FF]
|
|
265 |
for idx in ListPdoParams:
|
|
266 |
cobid = masternode.GetEntry(idx, 0x01)
|
|
267 |
if cobid not in DictCobID.keys():
|
|
268 |
ListCobIDAvailable.pop(cobid)
|
|
269 |
|
|
270 |
#-------------------------------------------------------------------------------
|
|
271 |
# Build concise DCF for the others locations
|
|
272 |
#-------------------------------------------------------------------------------
|
|
273 |
|
|
274 |
for nodeid, locations in DictLocationsNotMapped.items():
|
|
275 |
# Get current concise DCF
|
|
276 |
node = nodelist.SlaveNodes[nodeid]["Node"]
|
|
277 |
nodeDCF = masternode.GetEntry(0x1F22, nodeid)
|
|
278 |
|
|
279 |
if nodeDCF != None and nodeDCF != '':
|
|
280 |
tmpnbparams = [i for i in nodeDCF[:4]]
|
|
281 |
tmpnbparams.reverse()
|
|
282 |
nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16)
|
|
283 |
dataparams = nodeDCF[4:]
|
|
284 |
else:
|
|
285 |
nbparams = 0
|
|
286 |
dataparams = ""
|
|
287 |
|
|
288 |
for pdotype in (TPDO, RPDO):
|
|
289 |
pdosize = 0
|
|
290 |
pdomapping = []
|
|
291 |
for name, loc_infos in locations[pdotype]:
|
|
292 |
pdosize += loc_infos["size"]
|
|
293 |
# If pdo's size > 64 bits
|
|
294 |
if pdosize > 64:
|
|
295 |
result = GetNewCobID(nodeid, pdotype)
|
|
296 |
if result:
|
|
297 |
SlavesPdoNumber[nodeid][pdotype] += 1
|
|
298 |
new_cobid, new_idx = result
|
|
299 |
data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
|
|
300 |
dataparams += data
|
|
301 |
nbparams += nbaddedparams
|
|
302 |
DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
|
|
303 |
pdosize = loc_infos["size"]
|
|
304 |
pdomapping = [(name, loc_infos)]
|
|
305 |
else:
|
|
306 |
pdomapping.append((name, loc_infos))
|
|
307 |
if len(pdomapping) > 0:
|
|
308 |
result = GetNewCobID(nodeid, pdotype)
|
|
309 |
if result:
|
|
310 |
SlavesPdoNumber[nodeid][pdotype] += 1
|
|
311 |
new_cobid, new_idx = result
|
|
312 |
data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
|
|
313 |
dataparams += data
|
|
314 |
nbparams += nbaddedparams
|
|
315 |
DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
|
|
316 |
|
|
317 |
dcf = LE_to_BE(nbparams, 0x04) + dataparams
|
|
318 |
masternode.SetEntry(0x1F22, nodeid, dcf)
|
|
319 |
|
|
320 |
|
|
321 |
#-------------------------------------------------------------------------------
|
|
322 |
# Master Node Configuration
|
|
323 |
#-------------------------------------------------------------------------------
|
|
324 |
|
|
325 |
# Configure Master's SDO parameters entries
|
|
326 |
for nodeid, SDOparams in DictSDOparams.items():
|
|
327 |
SdoClient_index = [0x1280 + nodeid]
|
|
328 |
manager.ManageEntriesOfCurrent(SdoClient_index,[], masternode)
|
|
329 |
if SDOparams["RSDO"] != None:
|
|
330 |
RSDO_cobid = SDOparams["RSDO"]
|
|
331 |
else:
|
|
332 |
RSDO_cobid = 0x600 + nodeid
|
|
333 |
|
|
334 |
if SDOparams["TSDO"] != None:
|
|
335 |
TSDO_cobid = SDOparams["TSDO"]
|
|
336 |
else:
|
|
337 |
TSDO_cobid = 0x580 + nodeid
|
|
338 |
|
|
339 |
masternode.SetEntry(SdoClient_index[0], 0x01, RSDO_cobid)
|
|
340 |
masternode.SetEntry(SdoClient_index[0], 0x02, TSDO_cobid)
|
|
341 |
masternode.SetEntry(SdoClient_index[0], 0x03, nodeid)
|
|
342 |
|
|
343 |
# Configure Master's PDO parameters entries and set cobid, transmit type
|
|
344 |
for cobid, pdo_infos in DictCobID.items():
|
|
345 |
current_idx = CurrentPDOParamsIdx[pdo_infos["type"]]
|
|
346 |
addinglist = [current_idx, current_idx + 0x200]
|
|
347 |
manager.ManageEntriesOfCurrent(addinglist, [], masternode)
|
|
348 |
masternode.SetEntry(current_idx, 0x01, cobid)
|
|
349 |
masternode.SetEntry(current_idx, 0x02, DefaultTransmitTypeMaster)
|
|
350 |
if len(pdo_infos["mapping"]) > 2:
|
|
351 |
manager.AddSubentriesToCurrent(current_idx + 0x200, len(pdo_infos["mapping"]) - 2, masternode)
|
|
352 |
|
|
353 |
# Create Master's PDO mapping
|
|
354 |
for subindex, variable in enumerate(pdo_infos["mapping"]):
|
|
355 |
if subindex == 0:
|
|
356 |
continue
|
|
357 |
new_index = False
|
|
358 |
|
|
359 |
if type(variable) != IntType:
|
|
360 |
|
|
361 |
typeidx, varname = variable
|
|
362 |
indexname = DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + DictLocations[variable[1]]["sizelocation"] + str(DictLocations[variable[1]]["busname"]) + "_" + str(DictLocations[variable[1]]["nodeid"])
|
|
363 |
mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] + DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
|
|
364 |
|
|
365 |
if not masternode.IsEntry(mapvariableidx):
|
|
366 |
manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
|
|
367 |
new_index = True
|
|
368 |
nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
|
|
369 |
else:
|
|
370 |
nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
|
|
371 |
mapvariableidxbase = mapvariableidx
|
|
372 |
while mapvariableidx < (mapvariableidxbase + 0x1FF) and nbsubentries == 0xFF:
|
|
373 |
mapvariableidx += 0x800
|
|
374 |
if not manager.IsCurrentEntry(mapvariableidx):
|
|
375 |
manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
|
|
376 |
new_index = True
|
|
377 |
nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
|
|
378 |
|
|
379 |
if mapvariableidx < 0x6000:
|
|
380 |
if DictLocations[variable[1]]["bit"] != None:
|
|
381 |
subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"]) + "_" + str(DictLocations[variable[1]]["bit"])
|
|
382 |
else:
|
|
383 |
subindexname = "_" + str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"])
|
|
384 |
if not new_index:
|
|
385 |
manager.AddSubentriesToCurrent(mapvariableidx, 1, masternode)
|
|
386 |
nbsubentries += 1
|
|
387 |
masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name" : subindexname})
|
|
388 |
masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type" : typeidx})
|
|
389 |
|
|
390 |
# Map Variable
|
|
391 |
typeinfos = manager.GetEntryInfos(typeidx)
|
|
392 |
if typeinfos != None:
|
|
393 |
value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
|
|
394 |
masternode.SetEntry(current_idx + 0x200, subindex, value)
|
|
395 |
else:
|
|
396 |
masternode.SetEntry(current_idx + 0x200, subindex, TrashVariableValue[variable])
|
|
397 |
|
|
398 |
CurrentPDOParamsIdx[pdo_infos["type"]] += 1
|
|
399 |
#masternode.Print()
|
|
400 |
return masternode
|
|
401 |
|
|
402 |
if __name__ == "__main__":
|
|
403 |
from nodemanager import *
|
|
404 |
from nodelist import *
|
|
405 |
import sys
|
|
406 |
|
|
407 |
manager = NodeManager(sys.path[0])
|
|
408 |
nodelist = NodeList(manager)
|
|
409 |
result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping")
|
|
410 |
|
|
411 |
## if result != None:
|
|
412 |
## print result
|
|
413 |
## else:
|
|
414 |
## print "MasterNode :"
|
|
415 |
## manager.CurrentNode.Print()
|
|
416 |
## for nodeid, node in nodelist.SlaveNodes.items():
|
|
417 |
## print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid)
|
|
418 |
## node["Node"].Print()
|
|
419 |
|
|
420 |
#filepath = "/home/deobox/beremiz/test_nodelist/listlocations.txt"
|
|
421 |
filepath = "/home/deobox/Desktop/TestMapping/listlocations.txt"
|
|
422 |
|
|
423 |
file = open(filepath,'r')
|
|
424 |
locations = [location.split(' ') for location in [line.strip() for line in file.readlines() if len(line) > 0]]
|
|
425 |
file.close()
|
|
426 |
GenerateConciseDCF(locations, 32, nodelist)
|
|
427 |
print "MasterNode :"
|
|
428 |
manager.CurrentNode.Print()
|
|
429 |
#masternode.Print() |