From a31c97942b300aa6aa22b557b0e56fa580ec1c2d Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 29 Apr 2017 17:31:38 +0200 Subject: [PATCH] [fix] request switch management (plane thread let ctrlTerm use common socket) --- central-manager/lib/local/handler.c | 10 +++++----- plane/plane.c | 17 ++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/central-manager/lib/local/handler.c b/central-manager/lib/local/handler.c index 8771bdd..549fb2d 100644 --- a/central-manager/lib/local/handler.c +++ b/central-manager/lib/local/handler.c @@ -79,7 +79,7 @@ void* managePlane(void* THREADABLE_ARGS){ } /* 3. Si pas pour nous -> on attends puis on reboucle */ - if( buffer[0] != 0x55 ){ // '01010101'(2) '55'(16) + if( buffer[0] == 0x55 ){ // '01010101'(2) '55'(16) if( DEBUGMOD&BUF ) printf("{tcp_com}(%d) Let request to update routine\n", index); sleep(0.5); continue; @@ -88,7 +88,7 @@ void* managePlane(void* THREADABLE_ARGS){ /* (2) Données ---------------------------------------------------------*/ /* 1. On lit sur la socket */ - read = recv(SOCKET, buffer, MAX_BUF_LEN, 0); + read = recv(SOCKET, buffer+1, MAX_BUF_LEN-1, 0); /* 2.1. Si erreur reception (-1:erreur, 0:fermeture client propre) */ if( read <= 0 ){ @@ -97,8 +97,8 @@ void* managePlane(void* THREADABLE_ARGS){ } /* 2.2. Si message trop court */ - if( read != PLANE_LEN ){ - if( DEBUGMOD&BUF ) printf("{tcp_com}(%d) read: %d (expected: %d)\n", index, read, (int) PLANE_LEN); + if( read != PLANE_LEN-1 ){ + if( DEBUGMOD&BUF ) printf("{tcp_com}(%d) read: %d (expected: %d)\n", index, read+1, (int) PLANE_LEN); continue; } @@ -418,7 +418,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){ /* 3. Si on a pas trouvé -> on quitte l'udpdate */ if( pindex <= -1 || arg->sgca->socket[pindex] <= -1 ){ - printf("{udp_cterm}{com}(%d) Plane unknown or unreachable, passing\n", index); + printf("{udp_cterm}{com}(%d) Plane unknown or unreachable, passing\n", index); break; } diff --git a/plane/plane.c b/plane/plane.c index e092c61..d7c195a 100644 --- a/plane/plane.c +++ b/plane/plane.c @@ -142,15 +142,14 @@ void send_data(){ request.spd = htonl( ctrl.speed ); /* 3. Copie buffer */ - buffer[0] = 0x55; - memcpy(buffer+sizeof(char)*1+sizeof(int)*0, &request.code, sizeof(char)*6 ); - memcpy(buffer+sizeof(char)*7+sizeof(int)*0, &request.x, sizeof(int) ); - memcpy(buffer+sizeof(char)*7+sizeof(int)*1, &request.y, sizeof(int) ); - memcpy(buffer+sizeof(char)*7+sizeof(int)*2, &request.z, sizeof(int) ); - memcpy(buffer+sizeof(char)*7+sizeof(int)*3, &request.cap, sizeof(int) ); - memcpy(buffer+sizeof(char)*7+sizeof(int)*4, &request.spd, sizeof(int) ); + memcpy(buffer+sizeof(char)*0+sizeof(int)*0, &request.code, sizeof(char)*6 ); + memcpy(buffer+sizeof(char)*6+sizeof(int)*0, &request.x, sizeof(int) ); + memcpy(buffer+sizeof(char)*6+sizeof(int)*1, &request.y, sizeof(int) ); + memcpy(buffer+sizeof(char)*6+sizeof(int)*2, &request.z, sizeof(int) ); + memcpy(buffer+sizeof(char)*6+sizeof(int)*3, &request.cap, sizeof(int) ); + memcpy(buffer+sizeof(char)*6+sizeof(int)*4, &request.spd, sizeof(int) ); - read = send(commu_socket, buffer, PLANE_DATA_LEN/sizeof(char) + 1, 0); + read = send(commu_socket, buffer, PLANE_DATA_LEN/sizeof(char), 0); if( read <= 0 ){ printf("Cannot send\n"); @@ -338,7 +337,7 @@ void update(){ /* [3] Gestion de la réponse =========================================================*/ /* 1. On prépare la réponse */ - buffer[0] = 0; + buffer[0] = 0x55; buffer[1] = request.flags; printf("Response flags : %d\n", request.flags);