8 import config_utils, gen_cfile |
8 import config_utils, gen_cfile |
9 from networkedit import networkedit |
9 from networkedit import networkedit |
10 from objdictedit import objdictedit |
10 from objdictedit import objdictedit |
11 import canfestival_config |
11 import canfestival_config |
12 from plugger import PlugTemplate |
12 from plugger import PlugTemplate |
|
13 from commondialogs import CreateNodeDialog |
|
14 import wx |
13 |
15 |
14 from gnosis.xml.pickle import * |
16 from gnosis.xml.pickle import * |
15 from gnosis.xml.pickle.util import setParanoia |
17 from gnosis.xml.pickle.util import setParanoia |
16 setParanoia(0) |
18 setParanoia(0) |
17 |
19 |
40 NodeManager.__init__(self) |
42 NodeManager.__init__(self) |
41 odfilepath = self.GetSlaveODPath() |
43 odfilepath = self.GetSlaveODPath() |
42 if(os.path.isfile(odfilepath)): |
44 if(os.path.isfile(odfilepath)): |
43 self.OpenFileInCurrent(odfilepath) |
45 self.OpenFileInCurrent(odfilepath) |
44 else: |
46 else: |
45 self.CreateNewNode("SlaveNode", # Name - will be changed at build time |
47 self.FilePath = "" |
46 0x00, # NodeID - will be changed at build time |
48 dialog = CreateNodeDialog(None, wx.OK) |
47 "slave", # Type |
49 dialog.Type.Enable(False) |
48 "", # description |
50 dialog.GenSYNC.Enable(False) |
49 "None", # profile |
51 if dialog.ShowModal() == wx.ID_OK: |
50 "", # prfile filepath |
52 name, id, nodetype, description = dialog.GetValues() |
51 "heartbeat", # NMT |
53 profile, filepath = dialog.GetProfile() |
52 []) # options |
54 NMT = dialog.GetNMTManagement() |
53 |
55 options = dialog.GetOptions() |
|
56 self.CreateNewNode(name, # Name - will be changed at build time |
|
57 id, # NodeID - will be changed at build time |
|
58 "slave", # Type |
|
59 description,# description |
|
60 profile, # profile |
|
61 filepath, # prfile filepath |
|
62 NMT, # NMT |
|
63 options) # options |
|
64 else: |
|
65 self.CreateNewNode("SlaveNode", # Name - will be changed at build time |
|
66 0x00, # NodeID - will be changed at build time |
|
67 "slave", # Type |
|
68 "", # description |
|
69 "None", # profile |
|
70 "", # prfile filepath |
|
71 "heartbeat", # NMT |
|
72 []) # options |
|
73 dialog.Destroy() |
54 _View = None |
74 _View = None |
55 def _OpenView(self, logger): |
75 def _OpenView(self, logger): |
56 if not self._View: |
76 if not self._View: |
57 def _onclose(): |
77 def _onclose(): |
58 self._View = None |
78 self._View = None |
158 masterpath = os.path.join(buildpath, "MasterGenerated.od") |
178 masterpath = os.path.join(buildpath, "MasterGenerated.od") |
159 if not os.path.exists(masterpath): |
179 if not os.path.exists(masterpath): |
160 logger.write_error("Error: No Master generated\n") |
180 logger.write_error("Error: No Master generated\n") |
161 return |
181 return |
162 |
182 |
163 new_dialog = objdictedit(None, [masterpath]) |
183 new_dialog = objdictedit(None, filesOpen=[masterpath]) |
164 new_dialog.Show() |
184 new_dialog.Show() |
165 |
185 |
166 PluginMethods = [ |
186 PluginMethods = [ |
167 {"bitmap" : os.path.join("images", "NetworkEdit"), |
187 {"bitmap" : os.path.join("images", "NetworkEdit"), |
168 "name" : "Edit network", |
188 "name" : "Edit network", |
225 <xsd:attribute name="Debug_mode" type="xsd:boolean" use="optional" default="false"/> |
245 <xsd:attribute name="Debug_mode" type="xsd:boolean" use="optional" default="false"/> |
226 </xsd:complexType> |
246 </xsd:complexType> |
227 </xsd:element> |
247 </xsd:element> |
228 </xsd:schema> |
248 </xsd:schema> |
229 """ |
249 """ |
230 PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"),("CanOpenSlave",_SlavePlug, "CanOpen Slave")] |
250 PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"), |
|
251 ("CanOpenSlave",_SlavePlug, "CanOpen Slave")] |
231 def GetParamsAttributes(self, path = None): |
252 def GetParamsAttributes(self, path = None): |
232 infos = PlugTemplate.GetParamsAttributes(self, path = None) |
253 infos = PlugTemplate.GetParamsAttributes(self, path = None) |
233 for element in infos: |
254 for element in infos: |
234 if element["name"] == "CanFestivalInstance": |
255 if element["name"] == "CanFestivalInstance": |
235 for child in element["children"]: |
256 for child in element["children"]: |
249 "nodes_declare" : "", |
270 "nodes_declare" : "", |
250 "nodes_init" : "", |
271 "nodes_init" : "", |
251 "nodes_open" : "", |
272 "nodes_open" : "", |
252 "nodes_close" : "", |
273 "nodes_close" : "", |
253 "nodes_send_sync" : "", |
274 "nodes_send_sync" : "", |
254 "nodes_proceed_sync" : ""} |
275 "nodes_proceed_sync" : "", |
|
276 "slavebootups" : ""} |
255 for child in self.IECSortedChilds(): |
277 for child in self.IECSortedChilds(): |
256 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
278 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
257 nodename = "OD_%s" % childlocstr |
279 nodename = "OD_%s" % childlocstr |
258 |
280 |
259 # Try to get Slave Node |
281 # Try to get Slave Node |
260 child_data = getattr(child, "CanFestivalSlaveNode", None) |
282 child_data = getattr(child, "CanFestivalSlaveNode", None) |
261 if child_data is None: |
283 if child_data is None: |
262 # Not a slave -> master |
284 # Not a slave -> master |
263 child_data = getattr(child, "CanFestivalNode") |
285 child_data = getattr(child, "CanFestivalNode") |
|
286 # Apply sync setting |
264 if child_data.getSync_TPDOs(): |
287 if child_data.getSync_TPDOs(): |
265 format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
288 format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
266 format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
289 format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
267 |
290 # initialize and declare node table for post_SlaveBootup lookup |
|
291 |
|
292 SlaveIDs = child.GetSlaveIDs() |
|
293 for id in SlaveIDs: |
|
294 format_dict["slavebootups"] += """ |
|
295 int %s_slave_%d_booted = 0; |
|
296 """%(nodename, id) |
|
297 format_dict["slavebootups"] += """ |
|
298 static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){ |
|
299 switch(nodeId){ |
|
300 """%(nodename) |
|
301 for id in SlaveIDs: |
|
302 format_dict["slavebootups"] += """ |
|
303 case %d: |
|
304 %s_slave_%d_booted = 1; |
|
305 break; |
|
306 """%(id, nodename, id) |
|
307 format_dict["slavebootups"] += """ |
|
308 default: |
|
309 break; |
|
310 } |
|
311 if( """ |
|
312 format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs]) |
|
313 |
|
314 format_dict["slavebootups"] += """ ) |
|
315 Master_post_SlaveBootup(d,nodeId); |
|
316 } |
|
317 %s_Data.post_SlaveBootup = %s_post_SlaveBootup; |
|
318 """%(nodename,nodename) |
|
319 |
268 format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
320 format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
269 format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( |
321 format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( |
270 nodename, |
322 nodename, |
271 child_data.getCAN_Device(), |
323 child_data.getCAN_Device(), |
272 child_data.getCAN_Baudrate()) |
324 child_data.getCAN_Baudrate()) |