author | Laurent Bessard |
Thu, 06 Dec 2012 16:07:46 +0100 | |
changeset 765 | 90b738e4ede5 |
parent 748 | 18ed0f3b030a |
child 781 | 77fe158d6ccd |
permissions | -rw-r--r-- |
205 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of CanFestival, a library implementing CanOpen Stack. |
|
5 |
# |
|
6 |
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
10 |
#This library is free software; you can redistribute it and/or |
|
11 |
#modify it under the terms of the GNU Lesser General Public |
|
12 |
#License as published by the Free Software Foundation; either |
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
|
14 |
# |
|
15 |
#This library is distributed in the hope that it will be useful, |
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
#Lesser General Public License for more details. |
|
19 |
# |
|
20 |
#You should have received a copy of the GNU Lesser General Public |
|
21 |
#License along with this library; if not, write to the Free Software |
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
||
24 |
from node import * |
|
25 |
import eds_utils |
|
268 | 26 |
import os, shutil, types |
205 | 27 |
|
28 |
#------------------------------------------------------------------------------- |
|
29 |
# Definition of NodeList Object |
|
30 |
#------------------------------------------------------------------------------- |
|
31 |
||
32 |
""" |
|
33 |
Class recording a node list for a CANOpen network. |
|
34 |
""" |
|
35 |
||
36 |
class NodeList: |
|
37 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
38 |
def __init__(self, manager, netname = ""): |
205 | 39 |
self.Root = "" |
258 | 40 |
self.EDSFolder = "" |
205 | 41 |
self.Manager = manager |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
42 |
self.NetworkName = netname |
205 | 43 |
self.SlaveNodes = {} |
44 |
self.EDSNodes = {} |
|
45 |
self.CurrentSelected = None |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
46 |
self.Changed = False |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
47 |
|
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
48 |
def HasChanged(self): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
49 |
return self.Changed or not self.Manager.CurrentIsSaved() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
50 |
|
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
51 |
def ForceChanged(self, changed): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
52 |
self.Changed = changed |
205 | 53 |
|
54 |
def GetNetworkName(self): |
|
55 |
return self.NetworkName |
|
56 |
||
57 |
def SetNetworkName(self, name): |
|
58 |
self.NetworkName = name |
|
59 |
||
60 |
def GetManager(self): |
|
61 |
return self.Manager |
|
62 |
||
63 |
def GetRoot(self): |
|
64 |
return self.Root |
|
272
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
65 |
|
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
66 |
def SetRoot(self, newrootpath): |
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
67 |
""" |
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
68 |
Define a new path for the CanOpen network project |
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
69 |
!!! Does not check if new path is valid !!! |
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
70 |
""" |
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
71 |
self.Root = newrootpath |
bbdbf0c17d3c
Added SetRoot in networkedit to change project root on the fly
etisserant
parents:
270
diff
changeset
|
72 |
self.Manager.SetCurrentFilePath(os.path.join(self.Root, "master.od")) |
205 | 73 |
|
748
18ed0f3b030a
Fixing networkedit to deal with non-null master nodeid
Laurent Bessard
parents:
744
diff
changeset
|
74 |
def GetMasterNodeID(self): |
18ed0f3b030a
Fixing networkedit to deal with non-null master nodeid
Laurent Bessard
parents:
744
diff
changeset
|
75 |
return self.Manager.GetCurrentNodeID() |
18ed0f3b030a
Fixing networkedit to deal with non-null master nodeid
Laurent Bessard
parents:
744
diff
changeset
|
76 |
|
205 | 77 |
def GetSlaveNumber(self): |
78 |
return len(self.SlaveNodes) |
|
79 |
||
740
b6646a975f23
Fix bug when importing and loading not well formatted eds files
Laurent Bessard
parents:
580
diff
changeset
|
80 |
def GetSlaveName(self, idx): |
b6646a975f23
Fix bug when importing and loading not well formatted eds files
Laurent Bessard
parents:
580
diff
changeset
|
81 |
return self.SlaveNodes[idx]["Name"] |
b6646a975f23
Fix bug when importing and loading not well formatted eds files
Laurent Bessard
parents:
580
diff
changeset
|
82 |
|
205 | 83 |
def GetSlaveNames(self): |
84 |
nodes = self.SlaveNodes.keys() |
|
85 |
nodes.sort() |
|
86 |
return ["0x%2.2X %s"%(idx, self.SlaveNodes[idx]["Name"]) for idx in nodes] |
|
87 |
||
88 |
def GetSlaveIDs(self): |
|
89 |
nodes = self.SlaveNodes.keys() |
|
90 |
nodes.sort() |
|
91 |
return nodes |
|
92 |
||
93 |
def SetCurrentSelected(self, selected): |
|
94 |
self.CurrentSelected = selected |
|
95 |
||
96 |
def GetCurrentSelected(self): |
|
97 |
return self.CurrentSelected |
|
98 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
99 |
def LoadProject(self, root, netname = None): |
205 | 100 |
self.SlaveNodes = {} |
101 |
self.EDSNodes = {} |
|
102 |
||
103 |
self.Root = root |
|
104 |
if not os.path.exists(self.Root): |
|
580 | 105 |
return _("\"%s\" folder doesn't exist")%self.Root |
205 | 106 |
|
107 |
self.EDSFolder = os.path.join(self.Root, "eds") |
|
108 |
if not os.path.exists(self.EDSFolder): |
|
265
36cc4c87cdaa
Create "eds" folder if it doesn't exist in any case
lbessard
parents:
258
diff
changeset
|
109 |
os.mkdir(self.EDSFolder) |
36cc4c87cdaa
Create "eds" folder if it doesn't exist in any case
lbessard
parents:
258
diff
changeset
|
110 |
#return "\"%s\" folder doesn't contain a \"eds\" folder"%self.Root |
205 | 111 |
|
112 |
files = os.listdir(self.EDSFolder) |
|
113 |
for file in files: |
|
243 | 114 |
filepath = os.path.join(self.EDSFolder, file) |
115 |
if os.path.isfile(filepath) and os.path.splitext(filepath)[-1] == ".eds": |
|
116 |
result = self.LoadEDS(file) |
|
117 |
if result != None: |
|
118 |
return result |
|
270 | 119 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
120 |
result = self.LoadMasterNode(netname) |
205 | 121 |
if result != None: |
122 |
return result |
|
123 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
124 |
result = self.LoadSlaveNodes(netname) |
205 | 125 |
if result != None: |
126 |
return result |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
127 |
|
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
128 |
self.NetworkName = netname |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
129 |
|
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
130 |
def SaveProject(self, netname = None): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
131 |
result = self.SaveMasterNode(netname) |
205 | 132 |
if result != None: |
133 |
return result |
|
134 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
135 |
result = self.SaveNodeList(netname) |
205 | 136 |
if result != None: |
137 |
return result |
|
138 |
||
505
88956169c8b5
Adding support for replace imported EDS in nodelist
lbessard
parents:
337
diff
changeset
|
139 |
def ImportEDSFile(self, edspath, force = False): |
205 | 140 |
dir, file = os.path.split(edspath) |
141 |
eds = os.path.join(self.EDSFolder, file) |
|
505
88956169c8b5
Adding support for replace imported EDS in nodelist
lbessard
parents:
337
diff
changeset
|
142 |
if not force and os.path.isfile(eds): |
740
b6646a975f23
Fix bug when importing and loading not well formatted eds files
Laurent Bessard
parents:
580
diff
changeset
|
143 |
return _("EDS file already imported"), True |
205 | 144 |
else: |
145 |
shutil.copy(edspath, self.EDSFolder) |
|
740
b6646a975f23
Fix bug when importing and loading not well formatted eds files
Laurent Bessard
parents:
580
diff
changeset
|
146 |
return self.LoadEDS(file), False |
205 | 147 |
|
148 |
def LoadEDS(self, eds): |
|
149 |
edspath = os.path.join(self.EDSFolder, eds) |
|
258 | 150 |
node = eds_utils.GenerateNode(edspath) |
205 | 151 |
if isinstance(node, Node): |
152 |
self.EDSNodes[eds] = node |
|
153 |
return None |
|
154 |
else: |
|
155 |
return node |
|
156 |
||
157 |
def AddSlaveNode(self, nodeName, nodeID, eds): |
|
158 |
if eds in self.EDSNodes.keys(): |
|
159 |
slave = {"Name" : nodeName, "EDS" : eds, "Node" : self.EDSNodes[eds]} |
|
160 |
self.SlaveNodes[nodeID] = slave |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
161 |
self.Changed = True |
205 | 162 |
return None |
163 |
else: |
|
580 | 164 |
return _("\"%s\" EDS file is not available")%eds |
205 | 165 |
|
166 |
def RemoveSlaveNode(self, index): |
|
167 |
if index in self.SlaveNodes.keys(): |
|
168 |
self.SlaveNodes.pop(index) |
|
744
bc1bbbb5ef71
Fix bug with 'not saved' state for network when removing a slave
Laurent Bessard
parents:
740
diff
changeset
|
169 |
self.Changed = True |
205 | 170 |
return None |
171 |
else: |
|
580 | 172 |
return _("Node with \"0x%2.2X\" ID doesn't exist") |
205 | 173 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
174 |
def LoadMasterNode(self, netname = None): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
175 |
if netname: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
176 |
masterpath = os.path.join(self.Root, "%s_master.od"%netname) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
177 |
else: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
178 |
masterpath = os.path.join(self.Root, "master.od") |
205 | 179 |
if os.path.isfile(masterpath): |
268 | 180 |
result = self.Manager.OpenFileInCurrent(masterpath) |
181 |
else: |
|
182 |
result = self.Manager.CreateNewNode("MasterNode", 0x00, "master", "", "None", "", "heartbeat", ["DS302"]) |
|
183 |
if not isinstance(result, types.IntType): |
|
184 |
return result |
|
185 |
return None |
|
205 | 186 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
187 |
def SaveMasterNode(self, netname = None): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
188 |
if netname: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
189 |
masterpath = os.path.join(self.Root, "%s_master.od"%netname) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
190 |
else: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
191 |
masterpath = os.path.join(self.Root, "master.od") |
205 | 192 |
if self.Manager.SaveCurrentInFile(masterpath): |
193 |
return None |
|
194 |
else: |
|
580 | 195 |
return _("Fail to save Master Node") |
205 | 196 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
197 |
def LoadSlaveNodes(self, netname = None): |
205 | 198 |
cpjpath = os.path.join(self.Root, "nodelist.cpj") |
199 |
if os.path.isfile(cpjpath): |
|
200 |
try: |
|
201 |
networks = eds_utils.ParseCPJFile(cpjpath) |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
202 |
network = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
203 |
if netname: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
204 |
for net in networks: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
205 |
if net["Name"] == netname: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
206 |
network = net |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
207 |
self.NetworkName = netname |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
208 |
elif len(networks) > 0: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
209 |
network = networks[0] |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
210 |
self.NetworkName = network["Name"] |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
211 |
if network: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
212 |
for nodeid, node in network["Nodes"].items(): |
205 | 213 |
if node["Present"] == 1: |
214 |
result = self.AddSlaveNode(node["Name"], nodeid, node["DCFName"]) |
|
215 |
if result != None: |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
216 |
return result |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
217 |
self.Changed = False |
205 | 218 |
except SyntaxError, message: |
580 | 219 |
return _("Unable to load CPJ file\n%s")%message |
205 | 220 |
return None |
221 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
222 |
def SaveNodeList(self, netname = None): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
223 |
try: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
224 |
cpjpath = os.path.join(self.Root, "nodelist.cpj") |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
225 |
content = eds_utils.GenerateCPJContent(self) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
226 |
if netname: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
227 |
file = open(cpjpath, "a") |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
228 |
else: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
229 |
file = open(cpjpath, "w") |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
230 |
file.write(content) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
231 |
file.close() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
232 |
self.Changed = False |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
233 |
return None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
234 |
except: |
580 | 235 |
return _("Fail to save node list") |
205 | 236 |
|
237 |
def GetSlaveNodeEntry(self, nodeid, index, subindex = None): |
|
238 |
if nodeid in self.SlaveNodes.keys(): |
|
239 |
self.SlaveNodes[nodeid]["Node"].SetNodeID(nodeid) |
|
240 |
return self.SlaveNodes[nodeid]["Node"].GetEntry(index, subindex) |
|
241 |
else: |
|
580 | 242 |
return _("Node 0x%2.2X doesn't exist")%nodeid |
205 | 243 |
|
244 |
def GetMasterNodeEntry(self, index, subindex = None): |
|
245 |
return self.Manager.GetCurrentEntry(index, subindex) |
|
246 |
||
247 |
def SetMasterNodeEntry(self, index, subindex = None, value = None): |
|
248 |
self.Manager.SetCurrentEntry(index, subindex, value) |
|
249 |
||
250 |
def GetOrderNumber(self, nodeid): |
|
251 |
nodeindexes = self.SlaveNodes.keys() |
|
252 |
nodeindexes.sort() |
|
253 |
return nodeindexes.index(nodeid) + 1 |
|
254 |
||
255 |
def GetNodeByOrder(self, order): |
|
256 |
if order > 0: |
|
257 |
nodeindexes = self.SlaveNodes.keys() |
|
258 |
nodeindexes.sort() |
|
259 |
if order <= len(nodeindexes): |
|
260 |
return self.SlaveNodes[nodeindexes[order - 1]]["Node"] |
|
261 |
return None |
|
262 |
||
263 |
def IsCurrentEntry(self, index): |
|
264 |
if self.CurrentSelected != None: |
|
265 |
if self.CurrentSelected == 0: |
|
266 |
return self.Manager.IsCurrentEntry(index) |
|
267 |
else: |
|
268 |
node = self.SlaveNodes[self.CurrentSelected]["Node"] |
|
269 |
if node: |
|
273 | 270 |
node.SetNodeID(self.CurrentSelected) |
205 | 271 |
return node.IsEntry(index) |
272 |
return False |
|
273 |
||
274 |
def GetEntryInfos(self, index): |
|
275 |
if self.CurrentSelected != None: |
|
276 |
if self.CurrentSelected == 0: |
|
277 |
return self.Manager.GetEntryInfos(index) |
|
278 |
else: |
|
279 |
node = self.SlaveNodes[self.CurrentSelected]["Node"] |
|
280 |
if node: |
|
273 | 281 |
node.SetNodeID(self.CurrentSelected) |
205 | 282 |
return node.GetEntryInfos(index) |
283 |
return None |
|
284 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
285 |
def GetSubentryInfos(self, index, subindex): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
286 |
if self.CurrentSelected != None: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
287 |
if self.CurrentSelected == 0: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
288 |
return self.Manager.GetSubentryInfos(index, subindex) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
289 |
else: |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
290 |
node = self.SlaveNodes[self.CurrentSelected]["Node"] |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
291 |
if node: |
273 | 292 |
node.SetNodeID(self.CurrentSelected) |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
293 |
return node.GetSubentryInfos(index, subindex) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
294 |
return None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
295 |
|
205 | 296 |
def GetCurrentValidIndexes(self, min, max): |
297 |
if self.CurrentSelected != None: |
|
298 |
if self.CurrentSelected == 0: |
|
299 |
return self.Manager.GetCurrentValidIndexes(min, max) |
|
300 |
else: |
|
301 |
node = self.SlaveNodes[self.CurrentSelected]["Node"] |
|
302 |
if node: |
|
273 | 303 |
node.SetNodeID(self.CurrentSelected) |
205 | 304 |
validindexes = [] |
305 |
for index in node.GetIndexes(): |
|
306 |
if min <= index <= max: |
|
307 |
validindexes.append((node.GetEntryName(index), index)) |
|
308 |
return validindexes |
|
309 |
else: |
|
580 | 310 |
print _("Can't find node") |
205 | 311 |
return [] |
312 |
||
313 |
def GetCurrentEntryValues(self, index): |
|
314 |
if self.CurrentSelected != None: |
|
315 |
node = self.SlaveNodes[self.CurrentSelected]["Node"] |
|
316 |
if node: |
|
273 | 317 |
node.SetNodeID(self.CurrentSelected) |
205 | 318 |
return self.Manager.GetNodeEntryValues(node, index) |
319 |
else: |
|
580 | 320 |
print _("Can't find node") |
205 | 321 |
return [], [] |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
322 |
|
327 | 323 |
def AddToMasterDCF(self, node_id, index, subindex, size, value): |
324 |
# Adding DCF entry into Master node |
|
325 |
if not self.Manager.IsCurrentEntry(0x1F22): |
|
337 | 326 |
self.Manager.ManageEntriesOfCurrent([0x1F22], []) |
327 | 327 |
self.Manager.AddSubentriesToCurrent(0x1F22, 127) |
328 |
||
329 |
self.Manager.AddToDCF(node_id, index, subindex, size, value) |
|
330 |
||
205 | 331 |
if __name__ == "__main__": |
332 |
from nodemanager import * |
|
333 |
import os, sys, shutil |
|
334 |
||
335 |
manager = NodeManager(sys.path[0]) |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
336 |
|
205 | 337 |
nodelist = NodeList(manager) |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
338 |
|
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
339 |
result = nodelist.LoadProject("/home/laurent/test_nodelist") |
205 | 340 |
if result != None: |
341 |
print result |
|
342 |
else: |
|
343 |
print "MasterNode :" |
|
344 |
manager.CurrentNode.Print() |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
345 |
|
205 | 346 |
for nodeid, node in nodelist.SlaveNodes.items(): |
347 |
print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid) |
|
348 |
node["Node"].Print() |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
349 |
|
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
239
diff
changeset
|
350 |