[update] Updated verbose plane info
This commit is contained in:
parent
4b23207f74
commit
685d18df8f
|
@ -39,8 +39,13 @@ int open_communication(){
|
|||
|
||||
/* (1) Création socket multicast client* (écoute)
|
||||
---------------------------------------------------------*/
|
||||
if( DROP_MULTICAST_SERVER(MCST_HOST, MCST_PORT, &mcast_socket, &udp) < 0 )
|
||||
if( DROP_MULTICAST_SERVER(MCST_HOST, MCST_PORT, &mcast_socket, &udp) < 0 ){
|
||||
printf("/!\\ Cannot drop multicast server\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
printf("* Multicast server bound to multicast group\n");
|
||||
|
||||
// *un client multicast est en fait un serveur UDP, mais le terme persiste car le service est délivré par le CLIENT UDP
|
||||
|
||||
|
@ -53,12 +58,14 @@ int open_communication(){
|
|||
/* 2. Gestion erreur */
|
||||
if( status < 0 ){
|
||||
close(mcast_socket);
|
||||
printf("/!\\ Cannot get TCP credentials (ip/port)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 3. Vérification taille */
|
||||
if( status < BINDHDR_LEN ){
|
||||
close(mcast_socket);
|
||||
printf("/!\\ Invalid TCP credentials (ip/port)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -77,12 +84,13 @@ int open_communication(){
|
|||
/* 5. On vérifie les flags */
|
||||
if( !(request.flags&BINDHEAD_TCP) || request.flags&BINDHEAD_UDP ){
|
||||
close(mcast_socket);
|
||||
printf("/!\\ Received incorrect TCP credentials (ip/port)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// printf("* hex("); for( int i = 0 ; i < BINDHDR_LEN/sizeof(char) ; i++ ) printf("\\x%02X", buffer[i]); printf(")\n");
|
||||
printf("* received bind_header{flags = %d; addr = %x/'%s'; port = %d;}\n\n", request.flags, request.addr, inet_ntoa(ip), request.port);
|
||||
printf("* Received TCP credentials (flags: %x, ip: %s:%d)\n", request.flags, inet_ntoa(ip), request.port);
|
||||
|
||||
|
||||
|
||||
|
@ -95,8 +103,12 @@ int open_communication(){
|
|||
/* (1) Création socket TCP + connection
|
||||
---------------------------------------------------------*/
|
||||
/* 1. Création socket TCP + connection serveur */
|
||||
if( TCP_CONNECT(&commu_socket, request.addr, request.port, PAUSE, &sgca) < 0 )
|
||||
if( TCP_CONNECT(&commu_socket, request.addr, request.port, PAUSE, &sgca) < 0 ){
|
||||
printf("/!\\ Can't connect to TCP socket\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("* Connected to TCP server\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -111,6 +123,10 @@ int open_communication(){
|
|||
void close_communication(){
|
||||
// fonction à implémenter qui permet de fermer la communication
|
||||
// avec le gestionnaire de vols
|
||||
if( commu_socket > -1 )
|
||||
close(commu_socket);
|
||||
|
||||
printf("=== PLANE CRASHED ===\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,7 +257,7 @@ int update_z(int alt){
|
|||
|
||||
|
||||
void display_data(){
|
||||
printf("| Plane %s |\n * position(%d,%d, %d)\n * speed: %d\n * cap: %d\n\n", numero_vol, crd.x, crd.y, crd.z, ctrl.speed, ctrl.cap);
|
||||
printf("| Plane %s | (%d,%d,%d) - speed: %d - cap: %d\n", numero_vol, crd.x, crd.y, crd.z, ctrl.speed, ctrl.cap);
|
||||
}
|
||||
|
||||
// recalcule la localisation de l'plane en fonction de sa speed et de son cap
|
||||
|
@ -353,11 +369,13 @@ int main(){
|
|||
display_data();
|
||||
|
||||
// on quitte si on arrive à pas contacter le gestionnaire de vols
|
||||
printf("\n=== CONNECTION PROTOCOL ===\n");
|
||||
if( !open_communication() ){
|
||||
printf("Cannot connect to SGCA.\n");
|
||||
printf("/!\\ Cannot connect to SGCA.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// on se déplace une fois toutes les initialisations faites
|
||||
printf("\n=== COMMUNICATION PROTOCOL ===\n");
|
||||
update();
|
||||
}
|
Loading…
Reference in New Issue