233 if res: |
233 if res: |
234 raise Exception, res |
234 raise Exception, res |
235 res = eds_utils.GenerateEDSFile(os.path.join(buildpath, "Slave_%s.eds" % prefix), slave) |
235 res = eds_utils.GenerateEDSFile(os.path.join(buildpath, "Slave_%s.eds" % prefix), slave) |
236 if res: |
236 if res: |
237 raise Exception, res |
237 raise Exception, res |
238 return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
238 return [(Gen_OD_path, local_canfestival_config.getCFLAGS(CanFestivalPath))], "", False |
239 |
239 |
240 def LoadPrevious(self): |
240 def LoadPrevious(self): |
241 self.LoadCurrentPrevious() |
241 self.LoadCurrentPrevious() |
242 |
242 |
243 def LoadNext(self): |
243 def LoadNext(self): |
443 # define a unique name for the generated C file |
443 # define a unique name for the generated C file |
444 prefix = "_".join(map(str, current_location)) |
444 prefix = "_".join(map(str, current_location)) |
445 Gen_OD_path = os.path.join(buildpath, "OD_%s.c" % prefix ) |
445 Gen_OD_path = os.path.join(buildpath, "OD_%s.c" % prefix ) |
446 # Create a new copy of the model with DCF loaded with PDO mappings for desired location |
446 # Create a new copy of the model with DCF loaded with PDO mappings for desired location |
447 try: |
447 try: |
448 master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s" % prefix) |
448 master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(), "OD_%s" % prefix) |
449 except config_utils.PDOmappingException, e: |
449 except config_utils.PDOmappingException, e: |
450 raise Exception, e.message |
450 raise Exception, e.message |
451 # Do generate C file. |
451 # Do generate C file. |
452 res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers) |
452 res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers) |
453 if res: |
453 if res: |
455 |
455 |
456 file = open(os.path.join(buildpath, "MasterGenerated.od"), "w") |
456 file = open(os.path.join(buildpath, "MasterGenerated.od"), "w") |
457 dump(master, file) |
457 dump(master, file) |
458 file.close() |
458 file.close() |
459 |
459 |
460 return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
460 return [(Gen_OD_path, local_canfestival_config.getCFLAGS(CanFestivalPath))], "", False |
461 |
461 |
462 def LoadPrevious(self): |
462 def LoadPrevious(self): |
463 self.Manager.LoadCurrentPrevious() |
463 self.Manager.LoadCurrentPrevious() |
464 |
464 |
465 def LoadNext(self): |
465 def LoadNext(self): |
478 </xsd:complexType> |
478 </xsd:complexType> |
479 </xsd:element> |
479 </xsd:element> |
480 </xsd:schema> |
480 </xsd:schema> |
481 """ |
481 """ |
482 |
482 |
483 CTNChildrenTypes = [("CanOpenNode",_NodeListCTN, "CanOpen Master"), |
483 CTNChildrenTypes = [("CanOpenNode", _NodeListCTN, "CanOpen Master"), |
484 ("CanOpenSlave",_SlaveCTN, "CanOpen Slave")] |
484 ("CanOpenSlave", _SlaveCTN, "CanOpen Slave" )] |
485 def GetParamsAttributes(self, path = None): |
485 def GetParamsAttributes(self, path = None): |
486 infos = ConfigTreeNode.GetParamsAttributes(self, path = path) |
486 infos = ConfigTreeNode.GetParamsAttributes(self, path = path) |
487 for element in infos: |
487 for element in infos: |
488 if element["name"] == "CanFestivalInstance": |
488 if element["name"] == "CanFestivalInstance": |
489 for child in element["children"]: |
489 for child in element["children"]: |
508 can_driver_name = can_drv_prefix + "libcanfestival_" + can_driver + can_drv_ext |
508 can_driver_name = can_drv_prefix + "libcanfestival_" + can_driver + can_drv_ext |
509 else: |
509 else: |
510 can_driver_name = "" |
510 can_driver_name = "" |
511 |
511 |
512 |
512 |
513 format_dict = {"locstr": "_".join(map(str,self.GetCurrentLocation())), |
513 format_dict = {"locstr": "_".join(map(str, self.GetCurrentLocation())), |
514 "candriver": can_driver_name, |
514 "candriver": can_driver_name, |
515 "nodes_includes": "", |
515 "nodes_includes": "", |
516 "board_decls": "", |
516 "board_decls": "", |
517 "nodes_init": "", |
517 "nodes_init": "", |
518 "nodes_open": "", |
518 "nodes_open": "", |
526 "post_sync_register": "", |
526 "post_sync_register": "", |
527 "pre_op": "", |
527 "pre_op": "", |
528 "pre_op_register": "", |
528 "pre_op_register": "", |
529 } |
529 } |
530 for child in self.IECSortedChildren(): |
530 for child in self.IECSortedChildren(): |
531 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
531 childlocstr = "_".join(map(str, child.GetCurrentLocation())) |
532 nodename = "OD_%s" % childlocstr |
532 nodename = "OD_%s" % childlocstr |
533 |
533 |
534 # Try to get Slave Node |
534 # Try to get Slave Node |
535 child_data = getattr(child, "CanFestivalSlaveNode", None) |
535 child_data = getattr(child, "CanFestivalSlaveNode", None) |
536 if child_data is None: |
536 if child_data is None: |
555 "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n" % (nodename)+ |
555 "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n" % (nodename)+ |
556 " check_and_start_node(d, nodeId);\n"+ |
556 " check_and_start_node(d, nodeId);\n"+ |
557 "}\n") |
557 "}\n") |
558 # register previously declared func as post_SlaveBootup callback for that node |
558 # register previously declared func as post_SlaveBootup callback for that node |
559 format_dict["slavebootup_register"] += ( |
559 format_dict["slavebootup_register"] += ( |
560 "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n" % (nodename,nodename)) |
560 "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n" % (nodename, nodename)) |
561 format_dict["pre_op"] += ( |
561 format_dict["pre_op"] += ( |
562 "static void %s_preOperational(CO_Data* d){\n " % (nodename)+ |
562 "static void %s_preOperational(CO_Data* d){\n " % (nodename)+ |
563 "".join([" masterSendNMTstateChange(d, %d, NMT_Reset_Comunication);\n" % NdId for NdId in SlaveIDs])+ |
563 "".join([" masterSendNMTstateChange(d, %d, NMT_Reset_Comunication);\n" % NdId for NdId in SlaveIDs])+ |
564 "}\n") |
564 "}\n") |
565 format_dict["pre_op_register"] += ( |
565 format_dict["pre_op_register"] += ( |
566 "%s_Data.preOperational = %s_preOperational;\n" % (nodename,nodename)) |
566 "%s_Data.preOperational = %s_preOperational;\n" % (nodename, nodename)) |
567 else: |
567 else: |
568 # Slave node |
568 # Slave node |
569 align = child_data.getSync_Align() |
569 align = child_data.getSync_Align() |
570 align_ratio=child_data.getSync_Align_Ratio() |
570 align_ratio=child_data.getSync_Align_Ratio() |
571 if align > 0: |
571 if align > 0: |
578 " }else{\n"+ |
578 " }else{\n"+ |
579 " align_tick(%d);\n" % (align_ratio)+ |
579 " align_tick(%d);\n" % (align_ratio)+ |
580 " }\n"+ |
580 " }\n"+ |
581 "}\n") |
581 "}\n") |
582 format_dict["post_sync_register"] += ( |
582 format_dict["post_sync_register"] += ( |
583 "%s_Data.post_sync = %s_post_sync;\n" % (nodename,nodename)) |
583 "%s_Data.post_sync = %s_post_sync;\n" % (nodename, nodename)) |
584 format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n ' % ( |
584 format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n ' % ( |
585 nodename, |
585 nodename, |
586 child_data.getNodeId()) |
586 child_data.getNodeId()) |
587 |
587 |
588 # Include generated OD headers |
588 # Include generated OD headers |
594 child_data.getCAN_Baudrate()) |
594 child_data.getCAN_Baudrate()) |
595 format_dict["nodes_open"] += 'NODE_OPEN(%s)\n ' % (nodename) |
595 format_dict["nodes_open"] += 'NODE_OPEN(%s)\n ' % (nodename) |
596 format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n ' % (nodename) |
596 format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n ' % (nodename) |
597 format_dict["nodes_stop"] += 'NODE_STOP(%s)\n ' % (nodename) |
597 format_dict["nodes_stop"] += 'NODE_STOP(%s)\n ' % (nodename) |
598 |
598 |
599 filename = paths.AbsNeighbourFile(__file__,"cf_runtime.c") |
599 filename = paths.AbsNeighbourFile(__file__, "cf_runtime.c") |
600 cf_main = open(filename).read() % format_dict |
600 cf_main = open(filename).read() % format_dict |
601 cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c" % format_dict) |
601 cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c" % format_dict) |
602 f = open(cf_main_path,'w') |
602 f = open(cf_main_path, 'w') |
603 f.write(cf_main) |
603 f.write(cf_main) |
604 f.close() |
604 f.close() |
605 |
605 |
606 res = [(cf_main_path, local_canfestival_config.getCFLAGS(CanFestivalPath))],local_canfestival_config.getLDFLAGS(CanFestivalPath), True |
606 res = [(cf_main_path, local_canfestival_config.getCFLAGS(CanFestivalPath))], local_canfestival_config.getLDFLAGS(CanFestivalPath), True |
607 |
607 |
608 if can_driver is not None: |
608 if can_driver is not None: |
609 can_driver_path = os.path.join(CanFestivalPath,"drivers",can_driver,can_driver_name) |
609 can_driver_path = os.path.join(CanFestivalPath, "drivers", can_driver, can_driver_name) |
610 if os.path.exists(can_driver_path): |
610 if os.path.exists(can_driver_path): |
611 res += ((can_driver_name, file(can_driver_path,"rb")),) |
611 res += ((can_driver_name, file(can_driver_path, "rb")),) |
612 |
612 |
613 return res |
613 return res |