def CTNGenerate_C(self, buildpath, locations): can_driver = self.GetCanDriver() if can_driver is not None: can_drivers = local_canfestival_config.DLL_LIST if can_driver not in can_drivers: can_driver = can_drivers[0] can_drv_ext = self.GetCTRoot().GetBuilder().extension can_drv_prefix = self.GetCTRoot().GetBuilder().dlopen_prefix can_driver_name = can_drv_prefix + "libcanfestival_" + can_driver + can_drv_ext else: can_driver_name = "" format_dict = { "locstr": "_".join(map(str, self.GetCurrentLocation())), "candriver": can_driver_name, "nodes_includes": "", "board_decls": "", "nodes_init": "", "nodes_open": "", "nodes_stop": "", "nodes_close": "", "nodes_send_sync": "", "nodes_proceed_sync": "", "slavebootups": "", "slavebootup_register": "", "post_sync": "", "post_sync_register": "", "pre_op": "", "pre_op_register": "", } for child in self.IECSortedChildren(): childlocstr = "_".join(map(str, child.GetCurrentLocation())) nodename = "OD_%s" % childlocstr # Try to get Slave Node child_data = getattr(child, "CanFestivalSlaveNode", None) if child_data is None: # Not a slave -> master child_data = getattr(child, "CanFestivalNode") # Apply sync setting format_dict[ "nodes_init"] += 'NODE_MASTER_INIT(%s, %s)\n ' % ( nodename, child_data.getNodeId()) if child_data.getSync_TPDOs(): format_dict[ "nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n ' % ( nodename) format_dict[ "nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n ' % ( nodename) # initialize and declare node boot status variables for post_SlaveBootup lookup SlaveIDs = child.GetSlaveIDs() if len(SlaveIDs) == 0: # define post_SlaveBootup lookup functions format_dict["slavebootups"] += ( "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){}\n" % (nodename)) else: format_dict["slavebootups"] += ( "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n" % (nodename) + " check_and_start_node(d, nodeId);\n" + "}\n") # register previously declared func as post_SlaveBootup callback for that node format_dict["slavebootup_register"] += ( "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n" % (nodename, nodename)) format_dict["pre_op"] += ( "static void %s_preOperational(CO_Data* d){\n " % (nodename) + "".join([ " masterSendNMTstateChange(d, %d, NMT_Reset_Comunication);\n" % NdId for NdId in SlaveIDs ]) + "}\n") format_dict["pre_op_register"] += ( "%s_Data.preOperational = %s_preOperational;\n" % (nodename, nodename)) else: # Slave node align = child_data.getSync_Align() align_ratio = child_data.getSync_Align_Ratio() if align > 0: format_dict["post_sync"] += ( "static int %s_CalCount = 0;\n" % (nodename) + "static void %s_post_sync(CO_Data* d){\n" % (nodename) + " if(%s_CalCount < %d){\n" % (nodename, align) + " %s_CalCount++;\n" % (nodename) + " align_tick(-1);\n" + " }else{\n" + " align_tick(%d);\n" % (align_ratio) + " }\n" + "}\n") format_dict["post_sync_register"] += ( "%s_Data.post_sync = %s_post_sync;\n" % (nodename, nodename)) format_dict[ "nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n ' % ( nodename, child_data.getNodeId()) # Include generated OD headers format_dict["nodes_includes"] += '#include "%s.h"\n' % (nodename) # Declare CAN channels according user filled config format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n' % ( nodename, child.GetCanDevice(), child_data.getCAN_Baudrate()) format_dict["nodes_open"] += 'NODE_OPEN(%s)\n ' % (nodename) format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n ' % (nodename) format_dict["nodes_stop"] += 'NODE_STOP(%s)\n ' % (nodename) filename = paths.AbsNeighbourFile(__file__, "cf_runtime.c") cf_main = open(filename).read() % format_dict cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c" % format_dict) f = open(cf_main_path, 'w') f.write(cf_main) f.close() res = [ (cf_main_path, local_canfestival_config.getCFLAGS(CanFestivalPath)) ], local_canfestival_config.getLDFLAGS(CanFestivalPath), True if can_driver is not None: can_driver_path = os.path.join(CanFestivalPath, "drivers", can_driver, can_driver_name) if os.path.exists(can_driver_path): res += ((can_driver_name, file(can_driver_path, "rb")), ) return res
def CTNGenerate_C(self, buildpath, locations): can_driver = self.GetCanDriver() if can_driver is not None: can_drivers = local_canfestival_config.DLL_LIST if can_driver not in can_drivers : can_driver = can_drivers[0] can_drv_ext = self.GetCTRoot().GetBuilder().extension can_drv_prefix = self.GetCTRoot().GetBuilder().dlopen_prefix can_driver_name = can_drv_prefix + "libcanfestival_" + can_driver + can_drv_ext else: can_driver_name = "" format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), "candriver" : can_driver_name, "nodes_includes" : "", "board_decls" : "", "nodes_init" : "", "nodes_open" : "", "nodes_stop" : "", "nodes_close" : "", "nodes_send_sync" : "", "nodes_proceed_sync" : "", "slavebootups" : "", "slavebootup_register" : "", "post_sync" : "", "post_sync_register" : "", "pre_op" : "", "pre_op_register" : "", } for child in self.IECSortedChildren(): childlocstr = "_".join(map(str,child.GetCurrentLocation())) nodename = "OD_%s" % childlocstr # Try to get Slave Node child_data = getattr(child, "CanFestivalSlaveNode", None) if child_data is None: # Not a slave -> master child_data = getattr(child, "CanFestivalNode") # Apply sync setting format_dict["nodes_init"] += 'NODE_MASTER_INIT(%s, %s)\n '%( nodename, child_data.getNodeId()) if child_data.getSync_TPDOs(): format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) # initialize and declare node boot status variables for post_SlaveBootup lookup SlaveIDs = child.GetSlaveIDs() if len(SlaveIDs) == 0: # define post_SlaveBootup lookup functions format_dict["slavebootups"] += ( "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){}\n"%(nodename)) else: format_dict["slavebootups"] += ( "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+ " check_and_start_node(d, nodeId);\n"+ "}\n") # register previously declared func as post_SlaveBootup callback for that node format_dict["slavebootup_register"] += ( "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename)) format_dict["pre_op"] += ( "static void %s_preOperational(CO_Data* d){\n "%(nodename)+ "".join([" masterSendNMTstateChange(d, %d, NMT_Reset_Comunication);\n"%NdId for NdId in SlaveIDs])+ "}\n") format_dict["pre_op_register"] += ( "%s_Data.preOperational = %s_preOperational;\n"%(nodename,nodename)) else: # Slave node align = child_data.getSync_Align() align_ratio=child_data.getSync_Align_Ratio() if align > 0: format_dict["post_sync"] += ( "static int %s_CalCount = 0;\n"%(nodename)+ "static void %s_post_sync(CO_Data* d){\n"%(nodename)+ " if(%s_CalCount < %d){\n"%(nodename, align)+ " %s_CalCount++;\n"%(nodename)+ " align_tick(-1);\n"+ " }else{\n"+ " align_tick(%d);\n"%(align_ratio)+ " }\n"+ "}\n") format_dict["post_sync_register"] += ( "%s_Data.post_sync = %s_post_sync;\n"%(nodename,nodename)) format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n '%( nodename, child_data.getNodeId()) # Include generated OD headers format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) # Declare CAN channels according user filled config format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( nodename, child.GetCanDevice(), child_data.getCAN_Baudrate()) format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) format_dict["nodes_stop"] += 'NODE_STOP(%s)\n '%(nodename) filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c") cf_main = open(filename).read() % format_dict cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c"%format_dict) f = open(cf_main_path,'w') f.write(cf_main) f.close() res = [(cf_main_path, local_canfestival_config.getCFLAGS(CanFestivalPath))],local_canfestival_config.getLDFLAGS(CanFestivalPath), True if can_driver is not None: can_driver_path = os.path.join(CanFestivalPath,"drivers",can_driver,can_driver_name) if os.path.exists(can_driver_path): res += ((can_driver_name, file(can_driver_path,"rb")),) return res