From 265feabb593426b1bcab33e8bbdcc0ea1dac9b35 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 5 May 2017 13:51:07 +0200 Subject: [PATCH] Replaced term_req 0x10 with TERMREQ_OFF flag constant --- central-manager/lib/data.h | 1 + central-manager/lib/local/handler.c | 14 +++++++------- plane/plane.c | 4 ++-- plane/plane.h | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/central-manager/lib/data.h b/central-manager/lib/data.h index b5d5171..014fb4f 100644 --- a/central-manager/lib/data.h +++ b/central-manager/lib/data.h @@ -17,6 +17,7 @@ #define TERMREQ_CAP 0x02 #define TERMREQ_SPD 0x04 #define TERMREQ_ALT 0x08 + #define TERMREQ_OFF 0x10 #define PLANE_LEN ( sizeof(char)*6+sizeof(int)*5 ) struct plane{ diff --git a/central-manager/lib/local/handler.c b/central-manager/lib/local/handler.c index d65576e..0d06a80 100644 --- a/central-manager/lib/local/handler.c +++ b/central-manager/lib/local/handler.c @@ -137,7 +137,7 @@ void* managePlane(void* THREADABLE_ARGS){ } /* 4. On copie/met à jour les valeurs */ - if( tmpFlags != 0x10 ){ // gestion réponse ctrlTerm + if( tmpFlags != TERMREQ_OFF ){ // gestion réponse ctrlTerm arg->sgca->unit[pindex].flags = tmpFlags; // on met à jour les flags while( arg->sgca->unit[pindex].thrId == 0xf0 ); // on attend le numéro de thread printf("{tcp_com}(%d) Waking up UDP threaad@%d for ctrlTerm response\n", index, arg->sgca->unit[pindex].thrId); @@ -264,7 +264,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){ sent = recvfrom(arg->socket, buffer, 1, 0, (struct sockaddr*) &clientInfo, &len); /* 2. Gestion erreur (erreur ou mauvais feedback != 0x10) */ - if( sent <= 0 || buffer[0] != 0x10 ){ + if( sent <= 0 || buffer[0] != TERMREQ_OFF ){ printf("{udp_vterm}{com}(%d) Unable to recv feedback -> exiting\n", index); break; } @@ -420,7 +420,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){ /* 3. Si on a pas trouvé -> on quitte l'udpdate */ if( pindex <= -1 || arg->sgca->unit[pindex].socket <= -1 ){ printf("{udp_cterm}{com}(%d) Plane unknown or unreachable, passing\n", index); - request.flags = 0x10; + request.flags = TERMREQ_OFF; break; } @@ -439,7 +439,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){ /* 3. On envoie la requête à l'avion */ if( send(arg->sgca->unit[pindex].socket, buffer, count/sizeof(char), 0) <= 0 ){ printf("{udp_cterm}{com}(%d) Cannot send request to plane\n", index); - request.flags = 0x10; + request.flags = TERMREQ_OFF; break; } @@ -450,11 +450,11 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){ arg->sgca->unit[pindex].thrId = index; sleep(2); flags = arg->sgca->unit[pindex].flags; // on récupère les flags - arg->sgca->unit[pindex].flags = 0x10; // on reset les flags + arg->sgca->unit[pindex].flags = TERMREQ_OFF; // on reset les flags - if( flags == 0x10 ){ + if( flags == TERMREQ_OFF ){ printf("{udp_cterm}{com}(%d) Cannot get response from plane %d bytes (%d expected)\n", index, count, (int) PLANE_LEN); - request.flags = 0x10; + request.flags = TERMREQ_OFF; break; } diff --git a/plane/plane.c b/plane/plane.c index 68133c2..586efad 100644 --- a/plane/plane.c +++ b/plane/plane.c @@ -304,13 +304,13 @@ void update(){ int received; struct sgca_req request; char buffer[MAX_BUF_LEN] = {0}; - char persistentFlags = 0x10; + char persistentFlags = REQ_OFF; while( 1 ){ calc_ctrl(); send_data(persistentFlags); - persistentFlags = 0x10; + persistentFlags = REQ_OFF; /* [1] Gestion réception avec timeout =========================================================*/ diff --git a/plane/plane.h b/plane/plane.h index dd88ffb..67a682f 100644 --- a/plane/plane.h +++ b/plane/plane.h @@ -53,6 +53,7 @@ #define REQ_CAP 0x02 #define REQ_SPD 0x04 #define REQ_ALT 0x08 + #define REQ_OFF 0x10 struct sgca_req{ char flags;