Trains programming |
Customize trains itinerariesTo write our own trains itineraries, you should go to ./usr/src directory and edit usr.c and usr.h files. You must use functions listed in api_usr.h and constants from const_XXX.h. Others files don't need editing and are user program part. Simulator part is under ./src directory. API - availables functionsLog function : int TSAPI_trace(int type,char* message);Switches : int TSAPI_aiguillages_setPosition(char* aiguillage_num,char* aiguillage_pos);Blocks : int TSAPI_blocks_mutex_P(int block_num,int train_num); int TSAPI_blocks_mutex_V(int block_num,int train_num);Circuit : int TSAPI_circuit_relachement(void); int TSAPI_circuit_disjonction(void); int TSAPI_circuit_conjonction(void);Uncoupling rails : int TSAPI_detelages_getPosition(int detelage_num); int TSAPI_detelages_setPosition(char* detelage_name,int pos);Réceptivities : int TSAPI_receptivities_get(int octet,int bit);Signaling : int TSAPI_signalisation_setState(int signal_num, int state); int TSAPI_signalisation_getState(int signal_num);Trains : int TSAPI_trains_getSpeed(int train_num); int TSAPI_trains_getPosition(int train_num); int TSAPI_trains_setSpeed(int train_num,int speed,int fct); int TSAPI_trains_reverse(int train_num,int fct); int TSAPI_trains_createItinerary(int train_num,int startBlock_num,int cyclic_state, void (*initItinerary)(void),void (*itinerary)(void),void (*endItinerary)(void)); int TSAPI_trains_deleteItinerary(int train_num); Examplevoid TSUSR_train1_init(void){ int train_num=TRAINS_LOCOMOTIVE_1; //Depart block 14 TSAPI_blocks_mutex_P(BLOCKS_B14,train_num); } void TSUSR_train1_loop(void){ int train_num=TRAINS_LOCOMOTIVE_1; int train_speed=TRAINS_CMD_WITHFCT_VITESSE_5; int train_speed_stop=TRAINS_CMD_WITHFCT_ARRET; int train_fct=TRAINS_FCT_ON; //Block 8 TSAPI_blocks_mutex_P(BLOCKS_B8,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B14[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B8[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B8[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B14,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B14[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 2 TSAPI_blocks_mutex_P(BLOCKS_B2,train_num); TSAPI_aiguillages_setPosition("D2","droite"); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B8[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B2[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B2[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B8,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B8[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 1 TSAPI_blocks_mutex_P(BLOCKS_B1,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B2[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B1[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B1[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B2,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B2[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 3 TSAPI_blocks_mutex_P(BLOCKS_B3,train_num); TSAPI_aiguillages_setPosition("D1","gauche"); TSAPI_aiguillages_setPosition("S1","gauche"); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B1[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B3[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B3[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B1,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B1[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 9 TSAPI_blocks_mutex_P(BLOCKS_B9,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B3[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B9[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B9[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B3,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B3[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 15 TSAPI_blocks_mutex_P(BLOCKS_B15,train_num); TSAPI_aiguillages_setPosition("D3","droite"); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B9[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B15[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B15[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B9,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B9[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 16 TSAPI_blocks_mutex_P(BLOCKS_B16,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B15[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B16[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B16[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B15,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B15[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); //Block 14 TSAPI_blocks_mutex_P(BLOCKS_B14,train_num); TSAPI_aiguillages_setPosition("D4","gauche"); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B16[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_GREEN); while(TSAPI_receptivities_get( RECEPTIVITIES_B14[RECEPTIVITIES_OFFSET_OCTET], RECEPTIVITIES_B14[RECEPTIVITIES_OFFSET_R1] )==RECEPTIVITIES_STATE_OFF){ TSAPI_trains_setSpeed(train_num,train_speed,train_fct); } TSAPI_blocks_mutex_V(BLOCKS_B16,train_num); TSAPI_signalisation_setState( SIGNALISATION_SIGNAUX_B16[SIGNALISATION_SENS_1],SIGNALISATION_COLOR_RED); TSAPI_trains_setSpeed(train_num,train_speed_stop,train_fct); } void TSUSR_main(void){ //Creation des trains TSAPI_trace(TSUSR_TRACE_INFO,"usr : create trains"); TSAPI_trains_createItinerary(TRAINS_LOCOMOTIVE_1,BLOCKS_B14, TSUSR_TASKS_CYCLIC,TSUSR_train1_init,TSUSR_train1_loop,NULL); TSAPI_trace(TSUSR_TRACE_INFO,"usr : end create trains"); } |