finalisation emulation ctrlTerm
This commit is contained in:
parent
a31c97942b
commit
c5e59ccbd8
|
@ -71,12 +71,15 @@ int main(int argc, char* argv[]){
|
|||
struct term_req tr;
|
||||
struct term_res trs;
|
||||
int i, nb;
|
||||
struct plane tmp;
|
||||
int count, last;
|
||||
|
||||
strcpy(tmp.code, "\0");
|
||||
|
||||
/************************************************
|
||||
**** DEMANDE MULTICAST ****
|
||||
************************************************/
|
||||
printf("DEMANDE MCAST\n=============\n\n");
|
||||
printf("\n\nDEMANDE MCAST\n=============\n");
|
||||
if( 1 ){
|
||||
|
||||
/* [1] Initialisation socket
|
||||
|
@ -133,7 +136,7 @@ int main(int argc, char* argv[]){
|
|||
/************************************************
|
||||
**** CONNECTION UDP ****
|
||||
************************************************/
|
||||
printf("CONNECTION UDP\n==============\n\n");
|
||||
printf("\n\nCONNECTION UDP\n==============\n");
|
||||
if( 1 ){
|
||||
|
||||
/* [1] Initialisation socket
|
||||
|
@ -159,6 +162,7 @@ int main(int argc, char* argv[]){
|
|||
printf("Cannot send message through command socket.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Connected to UDP socket\n");
|
||||
|
||||
}
|
||||
|
||||
|
@ -170,7 +174,7 @@ int main(int argc, char* argv[]){
|
|||
**** DEMANDE INFO CLASSIQUE ****
|
||||
************************************************/
|
||||
if( 1 ){
|
||||
printf("DEMANDE DES DONNEES UNIQUEMENT\n==============================\n\n");
|
||||
printf("\n\nDEMANDE DES DONNEES UNIQUEMENT\n==============================\n");
|
||||
|
||||
/* [1] Preparing request
|
||||
=========================================================*/
|
||||
|
@ -245,6 +249,9 @@ int main(int argc, char* argv[]){
|
|||
printf("Plane[%s@%d] { (%d,%d,%d), cap: %d, spd: %d}\n", trs.data[i].code, i, trs.data[i].x, trs.data[i].y, trs.data[i].z, trs.data[i].cap, trs.data[i].spd);
|
||||
}
|
||||
|
||||
if( trs.n > 0 )
|
||||
memcpy(&tmp, &trs.data[0], sizeof(struct plane));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -254,7 +261,7 @@ int main(int argc, char* argv[]){
|
|||
**** DEMANDE MISE A JOUR SIMPLE ****
|
||||
************************************************/
|
||||
if( 1 ){
|
||||
printf("DEMANDE D'UPDATE SIMPLE\n=======================\n\n");
|
||||
printf("\n\nDEMANDE D'UPDATE SIMPLE\n=======================\n");
|
||||
|
||||
if( trs.n < 1 ){
|
||||
printf("No plane to update.\n");
|
||||
|
@ -265,7 +272,7 @@ int main(int argc, char* argv[]){
|
|||
/* [1] Preparing request
|
||||
=========================================================*/
|
||||
tr.flags = TERMREQ_SPD;
|
||||
memcpy(&tr.update, &trs.data[0], sizeof(struct plane));
|
||||
memcpy(&tr.update, &tmp, sizeof(struct plane));
|
||||
tr.update.spd = 1000;
|
||||
|
||||
printf("Update req { flags: %d; plane: #%s { z=%d; cap=%d; speed=%d} }\n", tr.flags, tr.update.code, tr.update.z, tr.update.cap, tr.update.spd);
|
||||
|
@ -336,6 +343,90 @@ int main(int argc, char* argv[]){
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************************************
|
||||
**** DEMANDE MISE A JOUR SIMPLE + DATA ****
|
||||
************************************************/
|
||||
if( 1 ){
|
||||
printf("\n\nDEMANDE D'UPDATE SIMPLE + DATA\n==============================\n");
|
||||
|
||||
|
||||
|
||||
/* [1] Preparing request
|
||||
=========================================================*/
|
||||
tr.flags = TERMREQ_FBK|TERMREQ_ALT;
|
||||
memcpy(&tr.update, &tmp, sizeof(struct plane));
|
||||
tr.update.z = 500;
|
||||
|
||||
printf("Update req { flags: %d; plane: #%s { z=%d; cap=%d; speed=%d} }\n", tr.flags, tr.update.code, tr.update.z, tr.update.cap, tr.update.spd);
|
||||
tr.update.x = htonl(tr.update.x);
|
||||
tr.update.y = htonl(tr.update.y);
|
||||
tr.update.z = htonl(tr.update.z);
|
||||
tr.update.cap = htonl(tr.update.cap);
|
||||
tr.update.spd = htonl(tr.update.spd);
|
||||
|
||||
/* [2] Filling buffer
|
||||
=========================================================*/
|
||||
bzero(buffer, 512);
|
||||
memcpy(buffer+sizeof(char)*0+sizeof(int)*0, &tr.flags, sizeof(char));
|
||||
memcpy(buffer+sizeof(char)*1+sizeof(int)*0, &tr.update.code, sizeof(char)*6);
|
||||
memcpy(buffer+sizeof(char)*7+sizeof(int)*0, &tr.update.x, sizeof(int));
|
||||
memcpy(buffer+sizeof(char)*7+sizeof(int)*1, &tr.update.y, sizeof(int));
|
||||
memcpy(buffer+sizeof(char)*7+sizeof(int)*2, &tr.update.z, sizeof(int));
|
||||
memcpy(buffer+sizeof(char)*7+sizeof(int)*3, &tr.update.cap, sizeof(int));
|
||||
memcpy(buffer+sizeof(char)*7+sizeof(int)*4, &tr.update.spd, sizeof(int));
|
||||
|
||||
|
||||
/* [3] Sending request
|
||||
=========================================================*/
|
||||
if( sendto(csocket, buffer, 7+sizeof(int)*5+1, 0, (struct sockaddr*) &server, len) < 0 ){
|
||||
printf("Cannot ask for simple update.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* [4] Fetch & print data
|
||||
=========================================================*/
|
||||
/* 1. On récupère la réponse */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
nb = recvfrom(csocket, buffer, 512, 0, (struct sockaddr*) &server, &len);
|
||||
|
||||
printf("%d bytes received\n", nb);
|
||||
|
||||
if( nb < 1 ){
|
||||
printf("Error receiving simple update.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/* 2. On parse la réponse */
|
||||
count = 0; last = sizeof(char); memcpy(&trs.flags, buffer+count, last);
|
||||
count += last; last = sizeof(char); memcpy(&trs.n, buffer+count, last);
|
||||
printf("Flag received : %d\n", trs.flags);
|
||||
|
||||
trs.data = malloc( sizeof(struct plane) * trs.n );
|
||||
|
||||
|
||||
for( i = 0 ; i < trs.n ; i++ ){
|
||||
count += last; last = sizeof(char)*6; memcpy(&trs.data[i].code, buffer+count, last);
|
||||
count += last; last = sizeof(int); memcpy(&trs.data[i].x, buffer+count, last);
|
||||
count += last; last = sizeof(int); memcpy(&trs.data[i].y, buffer+count, last);
|
||||
count += last; last = sizeof(int); memcpy(&trs.data[i].z, buffer+count, last);
|
||||
count += last; last = sizeof(int); memcpy(&trs.data[i].cap, buffer+count, last);
|
||||
count += last; last = sizeof(int); memcpy(&trs.data[i].spd, buffer+count, last);
|
||||
|
||||
trs.data[i].x = ntohl(trs.data[i].x);
|
||||
trs.data[i].y = ntohl(trs.data[i].y);
|
||||
trs.data[i].z = ntohl(trs.data[i].z);
|
||||
trs.data[i].cap = ntohl(trs.data[i].cap);
|
||||
trs.data[i].spd = ntohl(trs.data[i].spd);
|
||||
|
||||
printf("Plane[%s@%d] { (%d,%d,%d), cap: %d, spd: %d}\n", trs.data[i].code, i, trs.data[i].x, trs.data[i].y, trs.data[i].z, trs.data[i].cap, trs.data[i].spd);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/************************************************
|
||||
**** DEMANDE MISE A JOUR COMBINEE ****
|
||||
************************************************/
|
||||
|
|
Loading…
Reference in New Issue