Révision 380
Ajouté par Mourougen MARIMOUTOU-POUGARY il y a presque 3 ans
branch/MARIMOUTOU_Mourougen/main.c | ||
---|---|---|
float Latitude;
|
||
float Longitude;
|
||
}Position;
|
||
|
||
Position P,P1,P2,P3,P4;
|
||
typedef struct
|
||
{
|
||
Position rpos;
|
||
... | ... | |
flottant=decode_nombre(trame,i+10,i+5);
|
||
|
||
res=degres+((reste+(flottant/10000))/60);
|
||
|
||
if(trame[40]=='W')
|
||
{
|
||
res=-res;
|
||
}
|
||
return res;
|
||
|
||
}
|
||
... | ... | |
flottant=decode_nombre(trame,i+10,i+5);
|
||
|
||
res=degres+((reste+(flottant/10000))/60);
|
||
|
||
if(trame[40]=='S')
|
||
{
|
||
res=-res;
|
||
}
|
||
return res;
|
||
|
||
}
|
||
|
||
/*
|
||
Position decode_position(char *trame,Position* P)//Fonction qui stocke la latitude dans la structure Position
|
||
{
|
||
P->Latitude=decode_latitude(trame);
|
||
P->Longitude=decode_latitude(trame);
|
||
//return (*P).Latitude;
|
||
P->Latitude=decode_latitude(&trame);
|
||
P->Longitude=decode_latitude(&trame);
|
||
}
|
||
*/
|
||
|
||
|
||
float decode_trame(char *trame,Position P)//Fonction qui extrait la position(latitude,longitude) pour les trame trame valide
|
||
float decode_trame(char *trame,Position *P)//Fonction qui extrait la position(latitude,longitude) pour les trame trame valide
|
||
{
|
||
if(trame_cmp(trame,"GPPGA")==1)
|
||
{
|
||
decode_position(trame,&P);
|
||
P->Latitude=decode_latitude(trame);
|
||
P->Longitude=decode_longitude(trame);
|
||
}
|
||
}
|
||
|
||
float calcul_distance(Position p_1,Position p_2)
|
||
float calcul_distance(Position *p_1,Position *p_2)
|
||
{
|
||
float D;
|
||
int R_terre=6371;
|
||
D=sqrt(pow((p_2.Longitude-p_1.Longitude)*R_terre,2)+pow((p_2.Latitude-p_1.Latitude)*R_terre,2));
|
||
float R_terre=6371.0;
|
||
D=((6.28*R_terre)/360.0)*sqrt(((p_2->Longitude-p_1->Longitude),2)+pow((p_2->Latitude-p_1->Latitude),2));
|
||
|
||
return D;
|
||
}
|
||
... | ... | |
float calcul_vitesse(Position p_1,Position p_2)
|
||
{
|
||
int R_terre=6371;
|
||
float Vitesse=(calcul_distance(p_1,p_2)*R_terre)/3600;
|
||
float Vitesse=(calcul_distance(&p_1,&p_2))*3600;
|
||
return Vitesse;
|
||
}
|
||
|
||
int distance_a_la_plus_proche_zone(Position p,Zone r[],int nb_zones,float*d)//fONCTION QUI RETOURNE
|
||
int distance_a_la_plus_proche_zone(Position p,Zone r[],int nb_zones,float*d)//fonction qui retourne l'indice de la position de la plus proche zone
|
||
{
|
||
int i;
|
||
while(r[i])
|
||
{
|
||
if(r.Latitude-p.Latitude && r.Longitude==p.Longitude)
|
||
int i,j;
|
||
float pos_init=calcul_distance(&p,&r[0].rpos);//Initialisation d'une position initial de reference
|
||
if(nb_zones>0){
|
||
for(i=1;i<nb_zones;i++)
|
||
{
|
||
|
||
*d=calcul_distance(&p,&r[i].rpos);
|
||
if(*d<=pos_init)
|
||
{
|
||
j=i;
|
||
pos_init=*d;
|
||
}
|
||
}
|
||
return j;
|
||
|
||
}exit(-1);
|
||
}else{return -1;}
|
||
|
||
|
||
|
||
}
|
||
|
||
int test_distance_de_la_plus_proche_zone()
|
||
{
|
||
float distance;
|
||
P.Latitude=decode_latitude("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73");
|
||
P.Longitude=decode_longitude("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73");
|
||
|
||
int indice=distance_a_la_plus_proche_zone(P,zones,strlen(zones),&distance);
|
||
|
||
return indice;
|
||
|
||
}
|
||
//
|
||
|
||
//Fonction ? modifier !!!!!
|
||
... | ... | |
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
//Test fonction trame_cmp
|
||
/*if (trame_cmp("$GPRGA","GPGGA")!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}*/
|
||
//test fonction decode_int
|
||
/*if (test_decode_int()!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
... | ... | |
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}*/
|
||
//Test fonction
|
||
/*if (test_decode_latitude()!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
... | ... | |
printf("%f\n",decode_latitude("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D"));
|
||
printf("%f\n",decode_longitude("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D"));*/
|
||
//Position pos;
|
||
/*printf("Latitude: %f Longitude: %f\n",decode_position("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&pos));*/
|
||
//printf("Latitude: %f Longitude: %f\n",decode_position("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&pos));
|
||
|
||
//Test de la fonction decode_trame
|
||
|
||
/*if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",pos)!=1){
|
||
/*
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",pos)!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
... | ... | |
if (decode_trame("$GPRMC,141916.00,A,4545.6422,N,00306.6037,E,0.1,211.1,010206,,*3B",pos)!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}*/
|
||
//Test calcul distance et vitesse
|
||
/*Position P1,P2;
|
||
Position p_2=decode_position("$GPGGA,141917.00,4545.0242,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73",&P2);
|
||
Position p_1=decode_position("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&P1);
|
||
printf("distance: %f\n",calcul_distance(p_1,p_2));
|
||
printf("vitesse: %f\n",calcul_vitesse(p_1,p_2));*/
|
||
}
|
||
*/
|
||
|
||
|
||
//Test calcul distance et vitesse pour un intervalle de 1s
|
||
/*
|
||
P2.Latitude=decode_latitude("$GPGGA,141915.00,4545.0242,N,00306.6039,E,1,05,3.4,499.5,M,,M,,*75");
|
||
P2.Longitude=decode_longitude("$GPGGA,141915.00,4545.0242,N,00306.6039,E,1,05,3.4,499.5,M,,M,,*75");
|
||
P1.Latitude=decode_latitude("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73");
|
||
P1.Longitude=decode_longitude("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73");
|
||
|
||
printf("distance: %f\n",calcul_distance(P1,P2));
|
||
printf("vitesse: %f\n",calcul_vitesse(P1,P2));
|
||
*/
|
||
|
||
//Test calcul distance entre 2 villes
|
||
/*
|
||
//Paris
|
||
P1.Latitude = 48.8588897;
|
||
P1.Longitude = 2.320041;
|
||
//Lyon
|
||
P2.Latitude = 45.7578137;
|
||
P2.Longitude = 4.8320114;
|
||
//Toulouse
|
||
P3.Latitude = 43.7520597;
|
||
P3.Longitude = 1.2877314;
|
||
|
||
printf("distance Paris-Lyon : %f\n",calcul_distance(&P1,&P2));
|
||
printf("distance Paris-Toulouse : %f\n",calcul_distance(&P1,&P3));
|
||
*/
|
||
//Test de la fonction distance la plus proche
|
||
printf("%f\n",decode_latitude("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73"));
|
||
printf("%f\n",decode_longitude("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*73"));
|
||
|
||
|
||
|
||
P1.Latitude = 44.788762;
|
||
P1.Longitude = -3.012;
|
||
|
||
P2.Latitude = 44.788762;
|
||
P2.Longitude = -3.013;
|
||
|
||
printf("distance 1 : %f\n",calcul_distance(&P,&P1));
|
||
printf("distance 2 : %f\n",calcul_distance(&P,&P2));
|
||
printf("%d\n",strlen(zones));
|
||
printf("%d\n",test_distance_de_la_plus_proche_zone());
|
||
|
||
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
Formats disponibles : Unified diff
Revision et Test de la fonction calcul_distance