267 |
268 |
268 format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
269 format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
269 "candriver" : self.CanFestivalInstance.getCAN_Driver(), |
270 "candriver" : self.CanFestivalInstance.getCAN_Driver(), |
270 "nodes_includes" : "", |
271 "nodes_includes" : "", |
271 "board_decls" : "", |
272 "board_decls" : "", |
272 "nodes_declare" : "", |
|
273 "nodes_init" : "", |
273 "nodes_init" : "", |
274 "nodes_open" : "", |
274 "nodes_open" : "", |
275 "nodes_close" : "", |
275 "nodes_close" : "", |
276 "nodes_send_sync" : "", |
276 "nodes_send_sync" : "", |
277 "nodes_proceed_sync" : "", |
277 "nodes_proceed_sync" : "", |
278 "slavebootups" : "", |
278 "slavebootups" : "", |
279 "slavebootup_register" : ""} |
279 "slavebootup_register" : "", |
|
280 "post_sync" : "", |
|
281 "post_sync_register" : "", |
|
282 } |
280 for child in self.IECSortedChilds(): |
283 for child in self.IECSortedChilds(): |
281 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
284 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
282 nodename = "OD_%s" % childlocstr |
285 nodename = "OD_%s" % childlocstr |
283 |
286 |
284 # Try to get Slave Node |
287 # Try to get Slave Node |
285 child_data = getattr(child, "CanFestivalSlaveNode", None) |
288 child_data = getattr(child, "CanFestivalSlaveNode", None) |
286 if child_data is None: |
289 if child_data is None: |
287 # Not a slave -> master |
290 # Not a slave -> master |
288 child_data = getattr(child, "CanFestivalNode") |
291 child_data = getattr(child, "CanFestivalNode") |
289 # Apply sync setting |
292 # Apply sync setting |
|
293 format_dict["nodes_init"] += 'NODE_MASTER_INIT(%s, %s)\n '%( |
|
294 nodename, |
|
295 child_data.getNodeId()) |
290 if child_data.getSync_TPDOs(): |
296 if child_data.getSync_TPDOs(): |
291 format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
297 format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
292 format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
298 format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
293 # initialize and declare node table for post_SlaveBootup lookup |
299 |
294 |
300 # initialize and declare node boot status variables for post_SlaveBootup lookup |
295 SlaveIDs = child.GetSlaveIDs() |
301 SlaveIDs = child.GetSlaveIDs() |
296 for id in SlaveIDs: |
302 for id in SlaveIDs: |
297 format_dict["slavebootups"] += """ |
303 format_dict["slavebootups"] += ( |
298 int %s_slave_%d_booted = 0; |
304 "int %s_slave_%d_booted = 0;\n"%(nodename, id)) |
299 """%(nodename, id) |
305 # define post_SlaveBootup lookup functions |
300 format_dict["slavebootups"] += """ |
306 format_dict["slavebootups"] += ( |
301 static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){ |
307 "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+ |
302 switch(nodeId){ |
308 " switch(nodeId){\n") |
303 """%(nodename) |
309 # one case per declared node, mark node as booted |
304 for id in SlaveIDs: |
310 for id in SlaveIDs: |
305 format_dict["slavebootups"] += """ |
311 format_dict["slavebootups"] += ( |
306 case %d: |
312 " case %d:\n"%(id)+ |
307 %s_slave_%d_booted = 1; |
313 " %s_slave_%d_booted = 1;\n"%(nodename, id)+ |
308 break; |
314 " break;\n") |
309 """%(id, nodename, id) |
315 format_dict["slavebootups"] += ( |
310 format_dict["slavebootups"] += """ |
316 " default:\n"+ |
311 default: |
317 " break;\n"+ |
312 break; |
318 " }\n"+ |
313 } |
319 " if( ") |
314 if( """ |
320 # expression to test if all declared nodes booted |
315 format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs]) |
321 format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs]) |
316 |
322 format_dict["slavebootups"] += " )\n" + ( |
317 format_dict["slavebootups"] += """ ) |
323 " Master_post_SlaveBootup(d,nodeId);\n"+ |
318 Master_post_SlaveBootup(d,nodeId); |
324 "}\n") |
319 } |
325 # register previously declared func as post_SlaveBootup callback for that node |
320 """ |
326 format_dict["slavebootup_register"] += ( |
321 format_dict["slavebootup_register"] += """ |
327 "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename)) |
322 %s_Data.post_SlaveBootup = %s_post_SlaveBootup; |
328 else: |
323 """%(nodename,nodename) |
329 # Slave node |
324 |
330 align = child_data.getSync_Align() |
|
331 if align > 0: |
|
332 format_dict["post_sync"] += ( |
|
333 "static int %s_CalCount = 0;\n"%(nodename)+ |
|
334 "static void %s_post_sync(CO_Data* d){\n"%(nodename)+ |
|
335 " if(%s_CalCount < %d){\n"%(nodename, align)+ |
|
336 " %s_CalCount++;\n"%(nodename)+ |
|
337 " align_tick(1);\n"+ |
|
338 " }else{\n"+ |
|
339 " align_tick(0);\n"+ |
|
340 " }\n"+ |
|
341 "}\n") |
|
342 format_dict["post_sync_register"] += ( |
|
343 "%s_Data.post_sync = %s_post_sync;\n"%(nodename,nodename)) |
|
344 format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n '%( |
|
345 nodename, |
|
346 child_data.getNodeId()) |
|
347 |
|
348 # Include generated OD headers |
325 format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
349 format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
|
350 # Declare CAN channels according user filled config |
326 format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( |
351 format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( |
327 nodename, |
352 nodename, |
328 child_data.getCAN_Device(), |
353 child_data.getCAN_Device(), |
329 child_data.getCAN_Baudrate()) |
354 child_data.getCAN_Baudrate()) |
330 format_dict["nodes_declare"] += 'NODE_DECLARE(%s, %s)\n '%( |
|
331 nodename, |
|
332 child_data.getNodeId()) |
|
333 format_dict["nodes_init"] += 'NODE_INIT(%s, %s)\n '%( |
|
334 nodename, |
|
335 child_data.getNodeId()) |
|
336 format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
355 format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
337 format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) |
356 format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) |
338 |
357 |
339 if sys.platform == 'win32': |
358 if sys.platform == 'win32': |
340 if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(format_dict["candriver"] + '_DEBUG.dll'))): |
359 if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(format_dict["candriver"] + '_DEBUG.dll'))): |