Programmation des trains |
Personnaliser les parcours de trainsPour écrire vos programmes de trains aller dans le dossier ./usr/src puis éditer usr.c et usr.h en écrivant vos propres programmes de trains en utilisant les fonctions présentes dans api_usr.h et les constantes définies dans les fichiers const_XXX.h, les autres fichiers de ce répertoire n'ont pas être modifiés et constitue la partie utilisateur du programme. La partie simulation étant dans le dossier ./src. API - fonctions disponiblesFonction de log : int TSAPI_trace(int type,char* message);Aiguillages : int TSAPI_aiguillages_setPosition(char* aiguillage_num,char* aiguillage_pos);Blocs : 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);Dételages : int TSAPI_detelages_getPosition(int detelage_num); int TSAPI_detelages_setPosition(char* detelage_name,int pos);Réceptivités : int TSAPI_receptivities_get(int octet,int bit);Signalisation : 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); Exemplevoid 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"); } |