[fixed] indianness sgca (plane viewTerm)
This commit is contained in:
parent
80f0aa95f6
commit
3c241a2a95
|
@ -81,7 +81,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 3. On parse la requête*/
|
/* 3. On parse la requête (indianness: network order) */
|
||||||
memcpy(&data.code, buffer+sizeof(char)*0+sizeof(int)*0, sizeof(char)*6);
|
memcpy(&data.code, buffer+sizeof(char)*0+sizeof(int)*0, sizeof(char)*6);
|
||||||
memcpy(&data.x, buffer+sizeof(char)*6+sizeof(int)*0, sizeof(int));
|
memcpy(&data.x, buffer+sizeof(char)*6+sizeof(int)*0, sizeof(int));
|
||||||
memcpy(&data.y, buffer+sizeof(char)*6+sizeof(int)*1, sizeof(int));
|
memcpy(&data.y, buffer+sizeof(char)*6+sizeof(int)*1, sizeof(int));
|
||||||
|
@ -89,6 +89,14 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
memcpy(&data.spd, buffer+sizeof(char)*6+sizeof(int)*4, sizeof(int));
|
memcpy(&data.spd, buffer+sizeof(char)*6+sizeof(int)*4, sizeof(int));
|
||||||
memcpy(&data.cap, buffer+sizeof(char)*6+sizeof(int)*3, sizeof(int));
|
memcpy(&data.cap, buffer+sizeof(char)*6+sizeof(int)*3, sizeof(int));
|
||||||
|
|
||||||
|
/* 4. Gestion de l'indianness */
|
||||||
|
data.x = ntohl(data.x);
|
||||||
|
data.y = ntohl(data.y);
|
||||||
|
data.z = ntohl(data.z);
|
||||||
|
data.cap = ntohl(data.cap);
|
||||||
|
data.spd = ntohl(data.spd);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (3) Gestion de la requête -> enregistrement
|
/* (3) Gestion de la requête -> enregistrement
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
|
@ -119,7 +127,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
/* 3. On copie les constantes */
|
/* 3. On copie les constantes */
|
||||||
memcpy(&arg->sgca->data[pindex], &data, sizeof(struct plane));
|
memcpy(&arg->sgca->data[pindex], &data, sizeof(struct plane));
|
||||||
|
|
||||||
printf("{tcp_com}(%d) stored (%d)'%s': {x = %d; y = %d; z = %d; cap = %d; spd = %d}\n", index, pindex, arg->sgca->data[pindex].code, arg->sgca->data[pindex].x, arg->sgca->data[pindex].y, arg->sgca->data[pindex].z, arg->sgca->data[pindex].cap, arg->sgca->data[pindex].spd);
|
if( DEBUGMOD&COM ) printf("{tcp_com}(%d) stored (%d)'%s': {x = %d; y = %d; z = %d; cap = %d; spd = %d}\n", index, pindex, arg->sgca->data[pindex].code, arg->sgca->data[pindex].x, arg->sgca->data[pindex].y, arg->sgca->data[pindex].z, arg->sgca->data[pindex].cap, arg->sgca->data[pindex].spd);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,11 +136,11 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* 1. ACK data */
|
/* 1. ACK data */
|
||||||
strcpy(data.code, arg->sgca->data[pindex].code);
|
strcpy(data.code, arg->sgca->data[pindex].code);
|
||||||
data.x = arg->sgca->data[pindex].x;
|
data.x = htonl(arg->sgca->data[pindex].x);
|
||||||
data.y = arg->sgca->data[pindex].y;
|
data.y = htonl(arg->sgca->data[pindex].y);
|
||||||
data.z = arg->sgca->data[pindex].z;
|
data.z = htonl(arg->sgca->data[pindex].z);
|
||||||
data.cap = arg->sgca->data[pindex].cap;
|
data.cap = htonl(arg->sgca->data[pindex].cap);
|
||||||
data.spd = arg->sgca->data[pindex].spd;
|
data.spd = htonl(arg->sgca->data[pindex].spd);
|
||||||
|
|
||||||
/* 2. Vérification du FLAG (modifications) si requêtes d'update */
|
/* 2. Vérification du FLAG (modifications) si requêtes d'update */
|
||||||
//TODO: Gestion arg->sgca->update[pindex].flags|UPD_SPEED etc.. pour ajout du flag+elements dans reponse
|
//TODO: Gestion arg->sgca->update[pindex].flags|UPD_SPEED etc.. pour ajout du flag+elements dans reponse
|
||||||
|
@ -211,7 +219,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
struct sockaddr_in clientInfo;
|
struct sockaddr_in clientInfo;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
char loop = 1;
|
char loop = 1;
|
||||||
int count, /*to_send, */sent; // compteurs d'envoi
|
int count, last, sent; // compteurs d'envoi
|
||||||
int i, index = -1; // Compteurs globaux
|
int i, index = -1; // Compteurs globaux
|
||||||
char buffer[MAX_BUF_LEN]; // Buffer d'envoi
|
char buffer[MAX_BUF_LEN]; // Buffer d'envoi
|
||||||
struct term_res request; // Requête
|
struct term_res request; // Requête
|
||||||
|
@ -245,41 +253,48 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
free(request.data);
|
free(request.data);
|
||||||
request.data = malloc( request.n * sizeof(struct plane) + 1 );
|
request.data = malloc( request.n * sizeof(struct plane) + 1 );
|
||||||
|
|
||||||
/* 2. On récupère la liste des avions */
|
/* 2. On récupère la liste des avions (network byte order) */
|
||||||
for( i = 0 ; i < request.n ; i++ )
|
for( i = 0 ; i < request.n ; i++ ){
|
||||||
memcpy(&request.data[i], &arg->sgca->data[i], sizeof(struct plane));
|
|
||||||
|
|
||||||
|
memcpy(&request.data[i].code, &arg->sgca->data[i].code, sizeof(char)*6);
|
||||||
|
request.data[i].x = htonl( arg->sgca->data[i].x );
|
||||||
|
request.data[i].y = htonl( arg->sgca->data[i].y );
|
||||||
|
request.data[i].z = htonl( arg->sgca->data[i].z );
|
||||||
|
request.data[i].cap = htonl( arg->sgca->data[i].cap );
|
||||||
|
request.data[i].spd = htonl( arg->sgca->data[i].spd );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* [3] Construction de la requête
|
/* [3] Construction de la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* 1. Initialisation du buffer */
|
/* 1. Initialisation du buffer */
|
||||||
bzero(buffer, MAX_BUF_LEN*sizeof(char));
|
bzero(buffer, MAX_BUF_LEN*sizeof(char));
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* 2. Copie des données globales */
|
/* 2. Copie des données globales */
|
||||||
memcpy(buffer+count, &request.flags, sizeof(char)); count += sizeof(char);
|
count = 0; last = sizeof(char); memcpy(buffer+count, &request.flags, last);
|
||||||
memcpy(buffer+count, &request.n, sizeof(char)); count += sizeof(char);
|
count += last; last = sizeof(char); memcpy(buffer+count, &request.n, last);
|
||||||
|
|
||||||
/* 3. Copie des données des avions */
|
/* 3. Copie des données des avions */
|
||||||
for( i = 0 ; i < request.n ; i++ ){
|
for( i = 0 ; i < request.n ; i++ ){
|
||||||
memcpy(buffer+count, &request.data[i].code, sizeof(char)*6 ); count += sizeof(char)*6;
|
count += last; last = sizeof(char)*6; memcpy(buffer+count, &request.data[i].code, last);
|
||||||
memcpy(buffer+count, &request.data[i].x, sizeof(int) ); count += sizeof(int);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].x, last);
|
||||||
memcpy(buffer+count, &request.data[i].y, sizeof(int) ); count += sizeof(int);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].y, last);
|
||||||
memcpy(buffer+count, &request.data[i].z, sizeof(int) ); count += sizeof(int);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].z, last);
|
||||||
memcpy(buffer+count, &request.data[i].cap, sizeof(int) ); count += sizeof(int);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].cap, last);
|
||||||
memcpy(buffer+count, &request.data[i].spd, sizeof(int) ); count += sizeof(int);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].spd, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count += last;
|
||||||
|
|
||||||
|
|
||||||
/* [4] Envoi de la requête
|
/* [4] Envoi de la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* 1. Gestion de l'envoi en plusieurs requêtes */
|
/* 1. Gestion de l'envoi en plusieurs requêtes */
|
||||||
|
|
||||||
/* 2. Envoi */
|
/* 2. Envoi */
|
||||||
|
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
sent = sendto(arg->socket, buffer, count/sizeof(char), 0, (struct sockaddr*) &clientInfo, len);
|
sent = sendto(arg->socket, buffer, count/sizeof(char) + 1, 0, (struct sockaddr*) &clientInfo, len);
|
||||||
|
|
||||||
/* 3. Gestion erreur */
|
/* 3. Gestion erreur */
|
||||||
if( sent <= 0 ){
|
if( sent <= 0 ){
|
||||||
|
|
Loading…
Reference in New Issue