Délégation des middlewares [todo] middleware multicast pour avion
This commit is contained in:
parent
63436afc35
commit
f1fca736bd
|
@ -37,10 +37,10 @@ int main(int argc, char* argv[]){
|
|||
sgca.data = (struct plane*) malloc( sizeof(struct plane) );
|
||||
|
||||
/* 2. Variables locales */
|
||||
struct listn_thrd_arg tcp_listn_arg = { SERV_HOST, TCP_LIST, NULL, &managePlane };
|
||||
struct listn_thrd_arg udp_mcast_arg = { MCST_HOST, UDP_MCST, NULL, &dispatchPlanes };
|
||||
struct listn_thrd_arg udp_vterm_arg = { MCST_VTER, UDP_VTER, NULL, &manageViewTerm };
|
||||
struct listn_thrd_arg udp_cterm_arg = { MCST_CTER, UDP_CTER, NULL, &manageCtrlTerm };
|
||||
struct listen_arg tcp_listn_arg = { SERV_HOST, TCP_LIST, NULL, &managePlane };
|
||||
struct listen_arg udp_mcast_arg = { MCST_HOST, UDP_MCST, &multicastPlanes, NULL };
|
||||
struct listen_arg udp_vterm_arg = { MCST_VTER, UDP_VTER, &multicastTerminal, &manageViewTerm };
|
||||
struct listen_arg udp_cterm_arg = { MCST_CTER, UDP_CTER, &multicastTerminal, &manageCtrlTerm };
|
||||
|
||||
|
||||
/* [1] Lancement des THREADS d'écoute
|
||||
|
@ -95,7 +95,7 @@ void* LISTEN_TCP(void* THREADABLE_ARGS){
|
|||
struct sockaddr_in clientInfo; // contiendra les infos client
|
||||
socklen_t len; // taille de la socket
|
||||
int index, i; // compteurs
|
||||
struct listn_thrd_arg* arg = THREADABLE_ARGS; // Addr + Port serveur
|
||||
struct listen_arg* arg = THREADABLE_ARGS; // Addr + Port serveur
|
||||
|
||||
|
||||
// retour de @DROP_TCP_SERVER
|
||||
|
@ -149,7 +149,7 @@ void* LISTEN_TCP(void* THREADABLE_ARGS){
|
|||
if( index != -1 ){
|
||||
|
||||
// Construction arguments thread
|
||||
struct hndlr_thrd_arg thread_args = { TCPManagers, activeTCPManagers, CLIENT_SOCKET, &sgca };
|
||||
struct handler_arg thread_args = { TCPManagers, activeTCPManagers, CLIENT_SOCKET, &sgca };
|
||||
|
||||
/* 5. On lance un thread pour le traitement de ce client */
|
||||
pthread_create(&TCPManagers[index], NULL, arg->handler, (void*) &thread_args);
|
||||
|
@ -205,17 +205,17 @@ void* LISTEN_TCP(void* THREADABLE_ARGS){
|
|||
void* LISTEN_UDP(void* THREADABLE_ARGS){
|
||||
/* [0] Initialisation des variables
|
||||
==========================================================*/
|
||||
/* 1. On initialise les variables */
|
||||
int CLIENT_SOCKET; // contiendra la socket UDP à envoyer sur un THREAD
|
||||
struct sockaddr_in listenInfo; // contiendra les infos de la socket LISTEN
|
||||
struct sockaddr_in comInfo; // contiendra les infos de la socket COM
|
||||
struct sockaddr_in clientInfo; // contiendra les infos client
|
||||
socklen_t len; // taille de la socket
|
||||
int read; // compteurs
|
||||
char buffer[MAX_BUF_LEN]; // buffer requête
|
||||
struct bind_header request; // requête parsée
|
||||
int i, index; // compteurs
|
||||
struct listn_thrd_arg* arg = THREADABLE_ARGS; // Addr + Port serveur
|
||||
char entity[9+1];
|
||||
char entity[10]; // identifiant pour debug
|
||||
int returned; // Contrôle d'exécution middleware
|
||||
struct middleware_arg marg; // paramètres pour middleware
|
||||
|
||||
|
||||
/* 2. On parse les arguments */
|
||||
struct listen_arg* arg = THREADABLE_ARGS; // Addr + Port serveur
|
||||
|
||||
if( strcmp(arg->addr, MCST_VTER) == 0 && arg->port == UDP_VTER ) strcpy(entity, "udp_vterm");
|
||||
if( strcmp(arg->addr, MCST_CTER) == 0 && arg->port == UDP_CTER ) strcpy(entity, "udp_cterm");
|
||||
|
@ -246,94 +246,45 @@ void* LISTEN_UDP(void* THREADABLE_ARGS){
|
|||
============================================================================*/
|
||||
while( 1 ){
|
||||
|
||||
/* 0. On initialise les SOCKET en attendant la connexion d'un client */
|
||||
/* On initialise les SOCKET en attendant la connexion d'un client */
|
||||
CLIENT_SOCKET = -1;
|
||||
index = -1;
|
||||
|
||||
/* 1. On attends une connection UDP */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
read = recvfrom(SOCKET, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
||||
|
||||
/* 2. Si erreur reception ou taille incorrecte -> retour à l'écoute */
|
||||
if( read < BINDHDR_LEN ){
|
||||
if( DEBUGMOD&BUF ) printf("{%s} read('%s') = %d bytes (expected: %d)\n", entity, buffer, read, (int) (BINDHDR_LEN) );
|
||||
/* [2] Appel middleware si existe
|
||||
=========================================================*/
|
||||
if( arg->middleware != NULL ){
|
||||
|
||||
/* 1. Construction des arguments */
|
||||
marg.listenSock = SOCKET;
|
||||
marg.comSock = &CLIENT_SOCKET;
|
||||
strcpy(marg.entity, entity);
|
||||
|
||||
/* 2. Exécution middleware */
|
||||
returned = -1;
|
||||
returned = (*arg->middleware)( &marg );
|
||||
|
||||
/* 3. Gestion erreur FATALE */
|
||||
if( returned == -2 )
|
||||
break;
|
||||
|
||||
/* 4. Gestion erreur non FATALE */
|
||||
if( returned == -1 )
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [5] On démarre la tache sur un thread dédié -> si handler
|
||||
=========================================================*/
|
||||
if( arg->handler == NULL )
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 3. On récupère l'adresse IP du client */
|
||||
if( DEBUGMOD&SCK ) printf("{%s} %s:%d connecté\n", entity, inet_ntoa(clientInfo.sin_addr), ntohs(clientInfo.sin_port));
|
||||
|
||||
|
||||
|
||||
/* [3] Gestion de la requête
|
||||
=========================================================*/
|
||||
/* 1. On parse la requête */
|
||||
memcpy(&request.flags, buffer, sizeof(char));
|
||||
memcpy(&request.addr, buffer+sizeof(char), sizeof(char)*15);
|
||||
memcpy(&request.port, buffer+sizeof(char)*16, sizeof(unsigned short));
|
||||
printf("{%s} received: bind_header{flag = %d; addr = '%s'; port = %d}\n", entity, (int) request.flags, request.addr, request.port);
|
||||
|
||||
/* 2. Si on veut un port de communicatin */
|
||||
if( request.flags&BINDHEAD_SCK ){
|
||||
|
||||
/* 2.1 On bind une socket sur un port random */
|
||||
if( DROP_UDP_SERVER(SERV_HOST, 0, &CLIENT_SOCKET, &comInfo, 0) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de création de la socket COM\n", entity);
|
||||
|
||||
// On ferme la SOCKET CLIENT
|
||||
close(CLIENT_SOCKET);
|
||||
|
||||
// On retire le flags PORT pour dire qu'on a pas pu ouvrir une socket de comm.
|
||||
request.flags -= BINDHEAD_SCK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* 2.2 Si on veut on port de communication */
|
||||
if( request.flags&BINDHEAD_SCK ){
|
||||
|
||||
/* On récupère le port de la socket de communication */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( getsockname(CLIENT_SOCKET, (struct sockaddr*) &comInfo, &len) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de recherche du port COM ouvert\n", entity);
|
||||
|
||||
close(CLIENT_SOCKET);
|
||||
|
||||
// On retire le flags PORT pour dire qu'on a pas pu ouvrir une socket de comm.
|
||||
request.flags -= BINDHEAD_SCK;
|
||||
|
||||
// Si on a le port -> on le met dans la reponse
|
||||
}else{
|
||||
strcpy(request.addr, SERV_HOST);
|
||||
request.port = htons(comInfo.sin_port);
|
||||
if( DEBUGMOD&SCK ) printf("{%s}{udp_com} socket opened on %s:%d\n", entity, request.addr, request.port);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* [4] Envoi de la réponse
|
||||
=========================================================*/
|
||||
bzero(buffer, MAX_BUF_LEN);
|
||||
memcpy(buffer, &request.flags, sizeof(char));
|
||||
memcpy(buffer+sizeof(char), &request.addr, sizeof(char)*15);
|
||||
memcpy(buffer+sizeof(char)*16, &request.port, sizeof(unsigned short));
|
||||
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( sendto(SOCKET, buffer, BINDHDR_LEN/sizeof(char) + 1, 0, (struct sockaddr*) &clientInfo, len) < 0 ){
|
||||
printf("{%s} Impossible de répondre au client!\n", entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("{%s} sent: bind_header{flag = %d; addr = '%s'; port = %d}\n", entity, (int) request.flags, request.addr, request.port);
|
||||
|
||||
|
||||
|
||||
/* [5] On démarre la tache sur un thread dédié
|
||||
=========================================================*/
|
||||
/* 1. On cherche un "manager" libre (inactif) */
|
||||
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
||||
if( activeUDPManagers[i] == 0 ){ index = i; break; }
|
||||
|
@ -342,7 +293,7 @@ void* LISTEN_UDP(void* THREADABLE_ARGS){
|
|||
if( index != -1 ){
|
||||
|
||||
// Construction arguments thread
|
||||
struct hndlr_thrd_arg thread_args = { UDPManagers, activeUDPManagers, CLIENT_SOCKET, &sgca };
|
||||
struct handler_arg thread_args = { UDPManagers, activeUDPManagers, CLIENT_SOCKET, &sgca };
|
||||
|
||||
/* 2.1. On lance un thread pour le traitement de ce client */
|
||||
pthread_create(&UDPManagers[index], NULL, arg->handler, (void*) &thread_args);
|
||||
|
|
|
@ -60,22 +60,24 @@
|
|||
struct plane* data; // buffer tes données avion
|
||||
};
|
||||
|
||||
struct listn_thrd_arg{
|
||||
const char addr[16]; // socket address
|
||||
const unsigned short port; // socket port
|
||||
void* (*middleware)(); // Middleware (redirection etc)
|
||||
void* (*handler)(); // management function
|
||||
struct middleware_arg{
|
||||
int listenSock; // socket source
|
||||
int* comSock; // socket destination
|
||||
char entity[10]; // entity for log
|
||||
};
|
||||
|
||||
struct midwr_arg{
|
||||
int bla;
|
||||
};
|
||||
|
||||
struct hndlr_thrd_arg{
|
||||
struct handler_arg{
|
||||
pthread_t* managers;
|
||||
int* activeManagers;
|
||||
int socket;
|
||||
struct context* sgca;
|
||||
};
|
||||
|
||||
struct listen_arg{
|
||||
const char addr[16]; // socket address
|
||||
const unsigned short port; // socket port
|
||||
int (*middleware)(struct middleware_arg*); // middleware function
|
||||
void* (*handler)(void*); // management function (thread)
|
||||
};
|
||||
|
||||
#endif
|
|
@ -42,7 +42,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
|||
|
||||
|
||||
/* 2. On récupère les arguments */
|
||||
struct hndlr_thrd_arg* arg = THREADABLE_ARGS;
|
||||
struct handler_arg* arg = THREADABLE_ARGS;
|
||||
|
||||
/* 3. On récupère le rang du thread parmi les "managers" */
|
||||
index = -1;
|
||||
|
@ -142,13 +142,6 @@ void* managePlane(void* THREADABLE_ARGS){
|
|||
|
||||
|
||||
|
||||
void* dispatchPlanes(void* THREADABLE_ARGS){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Gestion d'une connexion TERMINAL
|
||||
*
|
||||
|
@ -179,7 +172,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
|||
// char response[MAX_BUF_LEN]; // Réponse
|
||||
|
||||
/* 2. On récupère les arguments */
|
||||
struct hndlr_thrd_arg* arg = THREADABLE_ARGS;
|
||||
struct handler_arg* arg = THREADABLE_ARGS;
|
||||
|
||||
|
||||
|
||||
|
@ -265,7 +258,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
|||
// char response[MAX_BUF_LEN]; // Réponse
|
||||
|
||||
/* 2. On récupère les arguments */
|
||||
struct hndlr_thrd_arg* arg = THREADABLE_ARGS;
|
||||
struct handler_arg* arg = THREADABLE_ARGS;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#include "../header.h"
|
||||
|
||||
void* managePlane(void* THREADABLE_ARGS);
|
||||
void* dispatchPlanes(void* THREADABLE_ARGS);
|
||||
|
||||
void* manageViewTerm(void* THREADABLE_ARGS);
|
||||
void* manageCtrlTerm(void* THREADABLE_ARGS);
|
||||
|
||||
|
|
|
@ -11,7 +11,105 @@
|
|||
|
||||
|
||||
|
||||
void* multicastPlanes(){ return 0; }
|
||||
int multicastPlanes(struct middleware_arg* arg){ return -2; }
|
||||
|
||||
|
||||
void* multicastTerminal(){ return 0; }
|
||||
int multicastTerminal(struct middleware_arg* arg){
|
||||
/* [0] Initialisation
|
||||
=========================================================*/
|
||||
struct sockaddr_in comInfo; // contiendra les infos de la socket COM
|
||||
struct sockaddr_in clientInfo; // contiendra les infos client
|
||||
socklen_t len; // taille de la socket
|
||||
int read; // compteurs
|
||||
char buffer[MAX_BUF_LEN+1]; // buffer requête
|
||||
struct bind_header request; // requête parsée
|
||||
|
||||
|
||||
|
||||
/* 1. On attends une connection UDP */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
read = recvfrom(arg->listenSock, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
||||
|
||||
/* 2. Si erreur reception ou taille incorrecte -> retour à l'écoute */
|
||||
if( read < BINDHDR_LEN ){
|
||||
if( DEBUGMOD&BUF ) printf("{%s} read('%s') = %d bytes (expected: %d)\n", arg->entity, buffer, read, (int) (BINDHDR_LEN) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 3. On récupère l'adresse IP du client */
|
||||
if( DEBUGMOD&SCK ) printf("{%s} %s:%d connecté\n", arg->entity, inet_ntoa(clientInfo.sin_addr), ntohs(clientInfo.sin_port));
|
||||
|
||||
|
||||
|
||||
/* [1] Gestion de la requête
|
||||
=========================================================*/
|
||||
/* 1. On parse la requête */
|
||||
memcpy(&request.flags, buffer, sizeof(char));
|
||||
memcpy(&request.addr, buffer+sizeof(char), sizeof(char)*15);
|
||||
memcpy(&request.port, buffer+sizeof(char)*16, sizeof(unsigned short));
|
||||
printf("{%s} received: bind_header{flag = %d; addr = '%s'; port = %d}\n", arg->entity, (int) request.flags, request.addr, request.port);
|
||||
|
||||
/* (1) Création socket de communication (si demandé)
|
||||
---------------------------------------------------------*/
|
||||
/* 1. Si on veut un port de communicatin */
|
||||
if( request.flags&BINDHEAD_SCK ){
|
||||
|
||||
/* 2. On bind une socket sur un port random */
|
||||
if( DROP_UDP_SERVER(SERV_HOST, 0, arg->comSock, &comInfo, 0) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de création de la socket COM\n", arg->entity);
|
||||
|
||||
/* 3. On ferme la socket et enleve le FLAG pour dire qu'on a pas pu ouvrir le port */
|
||||
close(*arg->comSock);
|
||||
request.flags -= BINDHEAD_SCK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* 2.2 Si on veut on port de communication */
|
||||
/* (2) Récupération port random
|
||||
---------------------------------------------------------*/
|
||||
if( request.flags&BINDHEAD_SCK ){
|
||||
|
||||
/* 1. On récupère le port de la socket de communication */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( getsockname(*arg->comSock, (struct sockaddr*) &comInfo, &len) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de recherche du port COM ouvert\n", arg->entity);
|
||||
|
||||
/* 2. On ferme la socket et enleve le FLAG pour dire qu'on a pas pu ouvrir le port */
|
||||
close(*arg->comSock);
|
||||
request.flags -= BINDHEAD_SCK;
|
||||
|
||||
/* 3. Si on a le port -> on le met dans la reponse */
|
||||
}else{
|
||||
strcpy(request.addr, SERV_HOST);
|
||||
request.port = htons(comInfo.sin_port);
|
||||
if( DEBUGMOD&SCK ) printf("{%s}{udp_com} socket opened on %s:%d\n", arg->entity, request.addr, request.port);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* [4] Envoi de la réponse
|
||||
=========================================================*/
|
||||
/* 1. On sérialise la réponse */
|
||||
bzero(buffer, MAX_BUF_LEN);
|
||||
memcpy(buffer, &request.flags, sizeof(char));
|
||||
memcpy(buffer+sizeof(char), &request.addr, sizeof(char)*15);
|
||||
memcpy(buffer+sizeof(char)*16, &request.port, sizeof(unsigned short));
|
||||
|
||||
/* 2. On envoie la réponse*/
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( sendto(arg->listenSock, buffer, BINDHDR_LEN/sizeof(char) + 1, 0, (struct sockaddr*) &clientInfo, len) < 0 ){
|
||||
printf("{%s} Impossible de répondre au client!\n", arg->entity);
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("{%s} sent: bind_header{flag = %d; addr = '%s'; port = %d}\n", arg->entity, (int) request.flags, request.addr, request.port);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
|
@ -13,8 +13,11 @@
|
|||
#define _LIB_LOCAL_MIDDLEWARE_H_
|
||||
|
||||
|
||||
void* multicastPlanes();
|
||||
void* multicastTerminal();
|
||||
#include "../header.h"
|
||||
#include "../network/udp/server.h"
|
||||
|
||||
int multicastPlanes(struct middleware_arg* ARGS);
|
||||
int multicastTerminal(struct middleware_arg* ARGS);
|
||||
|
||||
|
||||
#endif
|
|
@ -18,7 +18,6 @@ int DROP_UDP_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct
|
|||
/* [0] Initialisation des variables
|
||||
=========================================================*/
|
||||
int STATUS; // status
|
||||
uint yes = 1;
|
||||
struct ip_mreq mcastReq;
|
||||
*pListenSock = -1;
|
||||
struct timeval timeout;
|
||||
|
@ -43,18 +42,6 @@ int DROP_UDP_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* 4. MULTICAST -> Autorisation plusieurs sockets sur port */
|
||||
if( pMcast ){
|
||||
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) printf(" * [drop_udp_server] set port to be reused\n");
|
||||
|
||||
if( setsockopt(*pListenSock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(uint) ) < 0 ){
|
||||
close(*pListenSock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* [2] On définit les infos de la socket
|
||||
=========================================================*/
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
/**************************
|
||||
* Header Dependency *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#ifndef _LIB_HEADER_H_
|
||||
#define _LIB_HEADER_H_
|
||||
|
||||
|
@ -20,8 +29,8 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
/* vars */
|
||||
#define MCST_HOST "225.0.0.37" // adresse groupe multicast UDP
|
||||
#define MCST_PORT 0x504c // port multicast UDP
|
||||
#define MCST_HOST "224.0.0.1" // adresse groupe multicast UDP
|
||||
#define MCST_PORT 4444 // port multicast UDP
|
||||
|
||||
#define MAX_BUF_LEN 512
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
/**************************
|
||||
* TCP Client Dependency *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#include "client.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
/**************************
|
||||
* TCP Client Dependency *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#ifndef _LIB_NETWORK_TCP_CLIENT_H_
|
||||
#define _LIB_NETWORK_TCP_CLIENT_H_
|
||||
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
/**************************
|
||||
* UDP Client Dependency *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#ifndef _LIB_NETWORK_UDP_CLIENT_H_
|
||||
#define _LIB_NETWORK_UDP_CLIENT_H_
|
||||
|
||||
|
||||
/* Remarque:
|
||||
*
|
||||
* Il s'agit en réalité d'un serveur UDP, mais en multicast les membres du groupe pour qui sont copiées les requêtes
|
||||
* sont par habitude appelés clients
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "../../header.h"
|
||||
|
||||
|
@ -24,6 +41,7 @@
|
|||
* [2] On définit les infos de la socket
|
||||
* [3] On crée la socket
|
||||
*
|
||||
*
|
||||
*/
|
||||
int UDP_SOCKET(int* pSocket, const char* pAddr, const int pPort, struct sockaddr_in* pInfo);
|
||||
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
/**************************
|
||||
* Plane *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#include "plane.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// numéro de vol de l'plane : code sur 5 caractères
|
||||
char numero_vol[6];
|
||||
|
||||
|
@ -10,9 +22,8 @@ int mcast_socket = -1;
|
|||
int commu_socket = -1;
|
||||
char buffer[MAX_BUF_LEN] = {0};
|
||||
|
||||
/********************************
|
||||
*** 3 fonctions à implémenter
|
||||
********************************/
|
||||
|
||||
|
||||
|
||||
int open_communication(){
|
||||
/* 0. Initialisation des variables */
|
||||
|
@ -22,7 +33,6 @@ int open_communication(){
|
|||
char serverAddr[INET_ADDRSTRLEN+1]; // adresse TCP donné par requête multicast UDP
|
||||
int status;
|
||||
|
||||
|
||||
/* [1] Socket Multicast UDP
|
||||
=========================================================*/
|
||||
|
||||
|
@ -86,12 +96,12 @@ int open_communication(){
|
|||
|
||||
|
||||
|
||||
void fermer_communication(){
|
||||
void close_communication(){
|
||||
// fonction à implémenter qui permet de fermer la communication
|
||||
// avec le gestionnaire de vols
|
||||
}
|
||||
|
||||
void envoyer_caracteristiques(){
|
||||
void send_data(){
|
||||
|
||||
/* [0] Initialisation des variables
|
||||
=========================================================*/
|
||||
|
@ -147,8 +157,7 @@ void update_z(int alt){
|
|||
|
||||
// affiche les caractéristiques courantes de l'plane
|
||||
void display_data(){
|
||||
printf("Avion %6s -> localisation : (%d,%d), altitude : %d, vitesse : %d, cap : %d\n",
|
||||
numero_vol, crd.x, crd.y, crd.z, ctrl.speed, ctrl.cap);
|
||||
printf("Avion %6s -> localisation : (%d,%d), altitude : %d, vitesse : %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
|
||||
|
@ -156,11 +165,11 @@ void calc_ctrl(){
|
|||
float ctrl_x, ctrl_y;
|
||||
|
||||
if (ctrl.speed < VITMIN){
|
||||
fermer_communication();
|
||||
close_communication();
|
||||
exit(2);
|
||||
}
|
||||
if (crd.z == 0){
|
||||
fermer_communication();
|
||||
close_communication();
|
||||
exit(3);
|
||||
}
|
||||
|
||||
|
@ -189,7 +198,7 @@ void update(){
|
|||
|
||||
sleep(PAUSE);
|
||||
calc_ctrl();
|
||||
envoyer_caracteristiques();
|
||||
send_data();
|
||||
|
||||
}
|
||||
|
||||
|
@ -203,7 +212,6 @@ int main(){
|
|||
|
||||
// on quitte si on arrive à pas contacter le gestionnaire de vols
|
||||
if( !open_communication() ){
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
/**************************
|
||||
* Plane *
|
||||
***************************
|
||||
* Designed & Developed by *
|
||||
* Adrien Marquès *
|
||||
* <xdrm-brackets> *
|
||||
***************************
|
||||
* doowap31@gmail.com *
|
||||
**************************/
|
||||
#ifndef _PLANE_H_
|
||||
#define _PLANE_H_
|
||||
|
||||
|
|
Loading…
Reference in New Issue