void communiquer(void *arg) { DMessage *msg = d_new_message(); int var1 = 1; int num_msg = 0; rt_printf("tserver : Début de l'exécution de serveur\n"); serveur->open(serveur, "8000"); rt_printf("tserver : Connexion\n"); rt_mutex_acquire(&mutexEtat, TM_INFINITE); etatCommMoniteur = 0; rt_mutex_release(&mutexEtat); while (var1 > 0) { rt_printf("tserver : Attente d'un message\n"); var1 = serveur->receive(serveur, msg); num_msg++; if (var1 > 0) { switch (msg->get_type(msg)) { case MESSAGE_TYPE_ACTION: rt_printf("tserver : Le message %d reçu est une action\n", num_msg); DAction *action = d_new_action(); action->from_message(action, msg); switch (action->get_order(action)) { case ACTION_CONNECT_ROBOT: rt_printf("tserver : Action connecter robot\n"); rt_sem_v(&semConnecterRobot); break; } break; case MESSAGE_TYPE_MOVEMENT: rt_printf("tserver : Le message reçu %d est un mouvement\n", num_msg); rt_mutex_acquire(&mutexMove, TM_INFINITE); move->from_message(move, msg); move->print(move); rt_mutex_release(&mutexMove); break; } } } }
void communiquer(void *arg) { DMessage *msg = d_new_message(); DMessage *to_send = d_new_message(); DAction *action = d_new_action(); int var1 = 1; int num_msg = 0; while (1) { rt_printf("tserver : Début de l'exécution de serveur\n"); serveur->open(serveur, "8000"); rt_printf("tserver : Connexion\n"); rt_mutex_acquire(&mutexEtat, TM_INFINITE); etatCommMoniteur = 0; rt_mutex_release(&mutexEtat); while (var1 > 0) { //rt_printf("tserver : Attente d'un message\n"); var1 = serveur->receive(serveur, msg); num_msg++; if (var1 > 0) { switch (msg->get_type(msg)) { case MESSAGE_TYPE_ACTION: rt_printf("tserver : Le message %d reçu est une action\n", num_msg); action->from_message(action, msg); switch (action->get_order(action)) { case ACTION_CONNECT_ROBOT: rt_printf("tserver : Action connecter robot\n"); rt_sem_v(&semConnecterRobot); break; case ACTION_FIND_ARENA: rt_printf("tserver : Demande de detection de l'arene\n"); rt_mutex_acquire(&mutexEtatCamera, TM_INFINITE); if (etat_camera == 2) etat_camera = 3; else etat_camera = 1; rt_mutex_release(&mutexEtatCamera); break; case ACTION_COMPUTE_CONTINUOUSLY_POSITION: rt_printf("tserver : Demande de detection du robot\n"); rt_mutex_acquire(&mutexEtatCamera, TM_INFINITE); if (etat_camera == 1) etat_camera = 3; else etat_camera = 2; rt_mutex_release(&mutexEtatCamera); break; case ACTION_STOP_COMPUTE_POSITION: rt_printf("tserver : Fin de detection\n"); rt_mutex_acquire(&mutexEtatCamera, TM_INFINITE); etat_camera = 0; rt_mutex_release(&mutexEtatCamera); break; } break; case MESSAGE_TYPE_MOVEMENT: rt_printf("tserver : Le message reçu %d est un mouvement\n", num_msg); rt_mutex_acquire(&mutexMove, TM_INFINITE); move->from_message(move, msg); //move->print(move); rt_mutex_release(&mutexMove); break; case MESSAGE_TYPE_MISSION: rt_printf("tserver : Nouvelle mission\n", num_msg); mission_s->from_message(mission_s, msg); mission_s->print(mission_s); mission_s->get_position(mission_s, position_dest); position_dest->print(position_dest); mission_s->print(mission_s); rt_sem_v(&semMissionLancee); break; case MISSION_TYPE_STOP: to_send->mission_terminate(to_send, mission_s->get_id(mission_s)); serveur->send(serveur, to_send); //rt_sem_p(&semMissionLancee, TM_INFINITE); break; } } else { rt_printf("tserver : Perte de communication avec le moniteur\n"); serveur->close(serveur); rt_mutex_acquire(&mutexEtat, TM_INFINITE); etatCommMoniteur = 1; rt_mutex_release(&mutexEtat); } } } }