Révision 370
Ajouté par lefraisse il y a presque 4 ans
branch/FRAISSE/sp4a12/main.c | ||
---|---|---|
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include <math.h>
|
||
#include "trame.h"
|
||
#include "trame.h"
|
||
#define pi 3.141592
|
||
|
||
//Trames de tests ? modifier si n?cessaire.
|
||
char * trames[]= {"$GPGSV,3,2,10,15,03,077,,18,04,041,42,19,85,271,,20,08,214,*7C",
|
||
... | ... | |
"$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39",
|
||
"$GPVTG,99.4,T,,M,0.4,N,0.7,K*57",
|
||
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
0};
|
||
0};
|
||
|
||
int trame_cmp(char* trame,char* type){
|
||
int n=1,i;
|
||
... | ... | |
return n;
|
||
}
|
||
|
||
float decode_latitude(char* c){
|
||
int i=0;
|
||
float j, res;
|
||
while (c[i]!= '.')
|
||
i++;
|
||
|
||
|
||
}
|
||
|
||
//renvoie la valeur d?cimale des n premiers caract?res de la cha?ne ch
|
||
int decode_nombre(char * ch, int n){
|
||
|
||
... | ... | |
cpt++;
|
||
if (trame_cmp(trame,"GPGGA"))
|
||
printf ("> %s\n",trame);
|
||
}
|
||
}
|
||
|
||
typedef struct {
|
||
float latitude;
|
||
float longitude;
|
||
} Position ;
|
||
|
||
|
||
int decode_trame (char *trame,Position *P){
|
||
char *type="GPGGA";
|
||
int i,j,compteur_virgule=0,compteur_element=0,valide,virgule=0;
|
||
char memorisation_tps[11]={'0','0','0','0','0','0','0','0','0','0','\0'};
|
||
char memorisation_latitude[10]={'0','0','0','0','0','0','0','0','0','\0'};
|
||
char memorisation_indic_latitude[2]={'0','\0'};
|
||
char memorisation_longitude[11]={'0','0','0','0','0','0','0','0','0','0','\0'};
|
||
char memorisation_indic_longitude[2]={'0','\0'};
|
||
|
||
if (trame_cmp(trame,"GPGGA")){
|
||
valide=1;
|
||
for (i=6;compteur_virgule<6;i++){
|
||
if (trame[i]==','){
|
||
compteur_element=0;
|
||
compteur_virgule++;
|
||
}
|
||
else{
|
||
switch(compteur_virgule){
|
||
case 1: memorisation_tps[compteur_element]=trame[i];
|
||
compteur_element++;
|
||
break;
|
||
case 2: if (trame[i]!='.'){
|
||
memorisation_latitude[compteur_element]=trame[i];
|
||
}
|
||
compteur_element++;
|
||
break;
|
||
case 3: memorisation_indic_latitude[compteur_element]=trame[i];
|
||
compteur_element++;
|
||
break;
|
||
case 4: if (trame[i]!='.'){
|
||
memorisation_longitude[compteur_element]=trame[i];
|
||
}
|
||
compteur_element++;
|
||
break;
|
||
case 5: memorisation_indic_longitude[compteur_element]=trame[i];
|
||
compteur_element++;
|
||
default:break;
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
else
|
||
valide=0;
|
||
|
||
//On d?code les degr?s entiers
|
||
P->latitude=decode_nombre(memorisation_latitude,2);
|
||
P->longitude=decode_nombre(memorisation_longitude,3);
|
||
//On d?code les d?gr?s flottants
|
||
for (i=2;i<9;i++){
|
||
P->longitude+=memorisation_longitude[i+1]*1/6*pow(10,-i+2);
|
||
P->latitude+=(memorisation_latitude[i]-'0')*1/6*pow(10,-i+2);
|
||
}
|
||
|
||
//On transforme les notations S/N/E/O
|
||
if(memorisation_indic_latitude[0]=='S')
|
||
P->latitude = -P->latitude;
|
||
|
||
if(memorisation_indic_longitude[0]=='O')
|
||
P->longitude = -P->longitude;
|
||
|
||
return valide;
|
||
}
|
||
|
||
float calcul_distance(Position p_1,Position p_2){
|
||
float r=6378.137;
|
||
return 2*r*asin(sqrt(pow(sin(pi/180*(p_1.latitude-p_2.latitude)/2),2)+cos(pi/180*p_1.latitude)*cos(pi/180*p_2.latitude)*pow(sin(pi/180*(p_1.longitude-p_2.longitude)/2),2)));
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
Formats disponibles : Unified diff
Mise en place de la fonction decode_trame et calcul_distance