root/branch/MORSY/sp4a12/main.c @ 391
1 | jalaffon | #include <stdio.h>
|
|
#include <stdlib.h>
|
|||
351 | yomorsy | #include <strings.h>
|
|
#include<math.h>
|
|||
361 | yomorsy | #include "trame.h"
|
|
374 | yomorsy | #define PI 3.14159
|
|
361 | yomorsy | ||
374 | yomorsy | ||
361 | yomorsy | typedef struct {
|
|
float latitude;
|
|||
float longtitude;
|
|||
}position;
|
|||
374 | yomorsy | ||
1 | jalaffon | //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",
|
|||
"$GPGSV,3,3,10,22,39,053,50,28,15,320,*7E",
|
|||
"$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C",
|
|||
"$GPGLL,4545.6424,N,00306.6036,E,141914.00,A*0E",
|
|||
"$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",
|
|||
"$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};
|
|||
//Fonction ? modifier !!!!!
|
|||
361 | yomorsy | void traitement(char * trame)
|
|
239 | yomorsy | {
|
|
static int cpt=0;
|
|||
246 | yomorsy | cpt++;
|
|
361 | yomorsy | position p;
|
|
246 | yomorsy | ||
if (trame_cmp(trame, "GPGGA")==1){
|
|||
printf("%s\n",trame);
|
|||
361 | yomorsy | decode_trame(trame,&p);
|
|
printf("latitude= %f , longtude= %f \n",p.latitude,p.longtitude);
|
|||
246 | yomorsy | }
|
|
361 | yomorsy | ||
246 | yomorsy | }
|
|
250 | yomorsy | int decode_int(char c){
|
|
int y;
|
|||
int x=c;
|
|||
if (x>=48 && x<=58){
|
|||
y=x-48;
|
|||
}
|
|||
else{
|
|||
y =-1;
|
|||
}
|
|||
return y;
|
|||
}
|
|||
246 | yomorsy | int trame_cmp(char*trame , char*type){
|
|
int i=0,s=0,y;
|
|||
while(trame[i+1]==type[i] && type[i]!="/0"){
|
|||
i=i+1;
|
|||
s=s+1;
|
|||
}
|
|||
int x=strlen(type);
|
|||
if(s==x){
|
|||
y=1;
|
|||
}
|
|||
else{
|
|||
y=0;
|
|||
}
|
|||
return y;
|
|||
}
|
|||
351 | yomorsy | int decode_nombre(char *ch,int n){
|
|
int i,j,p;
|
|||
int s=0;
|
|||
for (i=0;i<n;i++){
|
|||
p=1;
|
|||
for(j=0;j<n-1-i;j++){
|
|||
p=p*10;
|
|||
}
|
|||
int a=decode_int(ch[i]);
|
|||
s=s+a*p;
|
|||
}
|
|||
return s;
|
|||
}
|
|||
361 | yomorsy | /*float latitude (char*c){
|
|
351 | yomorsy | int i=0,degre;
|
|
float secondes=0,sommes,minute=0;
|
|||
361 | yomorsy | degre=decode_int(c[0])*10+decode_int(c[1]) ;
|
|
secondes=(decode_int(c[5])*1000+decode_int(c[6])*100+decode_int(c[7])*10+decode_int(c[5]))/10000;
|
|||
minute=(decode_int(c[2])*10+decode_int(c[3])+secondes)/60;
|
|||
351 | yomorsy | sommes=degre+minute;
|
|
return sommes;
|
|||
361 | yomorsy | }*/
|
|
351 | yomorsy | ||
361 | yomorsy | /*float longtitude (char*c){
|
|
351 | yomorsy | int i=0,degre;
|
|
float secondes=0,sommes,minute=0;
|
|||
361 | yomorsy | degre=decode_int(c[0])*100+decode_int(c[1])*10+decode_int(c[2]) ;
|
|
secondes=secondes+(decode_int(c[6])*1000+decode_int(c[7])*100+decode_int(c[8])*10+decode_int(c[9]))/10000;
|
|||
minute=minute+(decode_int(c[3])*10+decode_int(c[4])+secondes)/60;
|
|||
sommes=sommes+degre+minute;
|
|||
return sommes;
|
|||
}*/
|
|||
351 | yomorsy | ||
361 | yomorsy | float lat_long (char c[]) {
|
|
int n=0, degre=0,i=1,b;
|
|||
float min=0, secondes=0, res=0,p;
|
|||
351 | yomorsy | ||
361 | yomorsy | ||
do{
|
|||
n++;
|
|||
} while (c[n]!='.');
|
|||
if (n==4) {
|
|||
degre = (c[0]-48)*10+(c[1]-48);
|
|||
min = (c[2]-48)*10+(c[3]-48);
|
|||
} else {
|
|||
degre = (c[0]-48)*100+(c[1]-48)*10+(c[2]-48);
|
|||
min = (c[3]-48)*10+(c[4]-48);
|
|||
351 | yomorsy | }
|
|
361 | yomorsy | n++;
|
|
do {
|
|||
p=1;
|
|||
for (b=0;b<i;b++) {
|
|||
p=p*0.1;
|
|||
}
|
|||
secondes= secondes + (c[n]-48)*p;
|
|||
i++;
|
|||
n++;
|
|||
} while (c[n]!='\0');
|
|||
351 | yomorsy | ||
361 | yomorsy | res = degre + (min+secondes)/60;
|
|
return res;
|
|||
351 | yomorsy | }
|
|
361 | yomorsy | void decode_trame(char*c,position *p){
|
|
int i=0,degre_long,degre_lat;
|
|||
float secondes_long=0,secondes_lat=0,sommes_lat=0,sommes_long=0,minute_lat=0,minute_long=0;
|
|||
degre_long=decode_int(c[29])*100+decode_int(c[30])*10+decode_int(c[31]) ;
|
|||
secondes_long=decode_int(c[35])*0.1+decode_int(c[36])*0.01+decode_int(c[37])*0.001+decode_int(c[38])*0.0001;
|
|||
minute_long=(decode_int(c[32])*10+decode_int(c[33])+secondes_long)/60;
|
|||
sommes_long=degre_long+minute_long;
|
|||
degre_lat=decode_int(c[17])*10+decode_int(c[18]) ;
|
|||
secondes_lat=(decode_int(c[21])*1000+decode_int(c[22])*100+decode_int(c[23])*10+decode_int(c[24]))/10000;
|
|||
minute_lat=(decode_int(c[19])*10+decode_int(c[20])+secondes_lat)/60;
|
|||
sommes_lat=degre_lat+minute_lat;
|
|||
p ->latitude=sommes_lat;
|
|||
p ->longtitude=sommes_long;
|
|||
}
|
|||
374 | yomorsy | float calcul_distance(position*p1,position*p2){
|
|
float distance;
|
|||
distance=acos(sin(PI * p1 ->latitude/180)*sin(PI * p2 ->latitude/180)+cos(PI* p1 ->latitude/180)*cos(PI* p2 ->latitude/180)*cos(PI*(fabs(p1 ->longtitude - p2 ->longtitude))/180))*6371;
|
|||
return distance;
|
|||
}
|
|||
361 | yomorsy | ||
351 | yomorsy | //Ajouter vos tests unitaires dans cette fonction.
|
|
246 | yomorsy | void tests_unitaires(void){
|
|
374 | yomorsy | position p,p1,p2;
|
|
p1.latitude=35.968723;
|
|||
p1.longtitude=256.652056;
|
|||
p2.longtitude=156.831330;
|
|||
p2.latitude=55.806160;
|
|||
246 | yomorsy | if (5!=5){
|
|
printf ("Erreur Test unitaire basique.\n");
|
|||
exit(-1);
|
|||
}
|
|||
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=1){
|
|||
printf ("Erreur Test unitaire trame_cmp.\n");
|
|||
exit(-1);
|
|||
}
|
|||
if (trame_cmp("$GPRMC suite chaine","GPGGA")!=0){
|
|||
printf ("Erreur Test unitaire trame_cmp.\n");
|
|||
exit(-1);
|
|||
}
|
|||
if (trame_cmp("$GPRMC... ", "GPRMC" )!=1){
|
|||
printf ("Erreur Test unitaire trame_cmp.\n");
|
|||
exit(-1);
|
|||
}
|
|||
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
|||
printf ("Erreur Test unitaire trame_cmp.\n");
|
|||
exit(-1);
|
|||
}
|
|||
351 | yomorsy | //****************************
|
|
250 | yomorsy | ||
351 | yomorsy | if (5!=5){
|
|
250 | yomorsy | printf ("Erreur Test unitaire basique.\n");
|
|
exit(-1);
|
|||
}
|
|||
if(decode_int('5')!= 5){
|
|||
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp50.\n");
|
|
250 | yomorsy | exit(-1);
|
|
}
|
|||
271 | yomorsy | ||
250 | yomorsy | if(decode_int('a')!= -1){
|
|
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp3.\n");
|
|
250 | yomorsy | exit(-1);
|
|
}
|
|||
351 | yomorsy | ||
//**********************
|
|||
255 | yomorsy | if (5!=5){
|
|
271 | yomorsy | printf ("Erreur Test unitaire basique.\n");
|
|
exit(-1);
|
|||
255 | yomorsy | }
|
|
if (decode_nombre("35789",3)!=357){
|
|||
361 | yomorsy | printf ("Erreur Test unitaire trame_cmp16.\n");
|
|
271 | yomorsy | exit(-1);
|
|
255 | yomorsy | }
|
|
271 | yomorsy | ||
255 | yomorsy | if (decode_nombre("25986452235",7)!=2598645){
|
|
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp2.\n");
|
|
exit(-1);
|
|||
255 | yomorsy | }
|
|
if (decode_nombre("2",1)!=2){
|
|||
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp3.\n");
|
|
exit(-1);
|
|||
255 | yomorsy | }
|
|
if (decode_nombre("25986452235",7)==2578963){
|
|||
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp4.\n");
|
|
exit(-1);
|
|||
255 | yomorsy | }
|
|
351 | yomorsy | //********************************
|
|
361 | yomorsy | /* if (5!=5){
|
|
271 | yomorsy | printf ("Erreur Test unitaire basique.\n");
|
|
exit(-1);
|
|||
361 | yomorsy | }
|
|
if (longtitude("13558.8889")-135,981481<0.000001 && 135,981481-longtitude("13558.8889")<0.000001){
|
|||
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp1.\n");
|
|
exit(-1);
|
|||
}
|
|||
361 | yomorsy | if (longtitude("10112.1415")-101,202358<0.000001 && 101,202358-longtitude("10112.1415")<0.000001){
|
|
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp2.\n");
|
|
exit(-1);
|
|||
361 | yomorsy | }*/
|
|
//***********************************
|
|||
/* if (5!=5){
|
|||
printf ("Erreur Test unitaire basique.\n");
|
|||
exit(-1);
|
|||
271 | yomorsy | }
|
|
361 | yomorsy | if (latitude("3558.8889")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
|
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp1.\n");
|
|
exit(-1);
|
|||
}
|
|||
361 | yomorsy | if (latitude("0112.1415")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
|
271 | yomorsy | printf ("Erreur Test unitaire trame_cmp2.\n");
|
|
exit(-1);
|
|||
361 | yomorsy | }*/
|
|
351 | yomorsy | //*****************************
|
|
361 | yomorsy | if (5!=5){
|
|
271 | yomorsy | printf ("Erreur Test unitaire basique.\n");
|
|
exit(-1);
|
|||
}
|
|||
361 | yomorsy | if (lat_long("13558.8889")-135.981481>0.000001 && 135.981481-lat_long("13358.8889")<0.000001){
|
|
printf ("Erreur Test unitaire trame_cmp18.\n");
|
|||
exit(-1);
|
|||
}
|
|||
/* if (lat_long("10112.1415")-101.2023583>0.000001 && 101.2023583-lat_long("10112.1415")<0.000001){
|
|||
printf ("Erreur Test unitaire trame_cmp21.\n");
|
|||
exit(-1);
|
|||
}*/
|
|||
/* if (lat_long("3558.8889")-35.981481>0.000001 && 35.981481-lat_long("3558.8889")<0.000001){
|
|||
printf ("Erreur Test unitaire trame_cmp12.\n");
|
|||
exit(-1);
|
|||
}*/
|
|||
if (lat_long("0112.1415")-01.202358>0.000001 && 01.202358-lat_long("0112.1415")<0.000001){
|
|||
printf ("Erreur Test unitaire trame_cmp22.\n");
|
|||
exit(-1);
|
|||
}
|
|||
/////////////////////////////////////////
|
|||
decode_trame("$GPGGA,141914.00,3558.8889,N,10112.1415,E,1,05,3.4,499.3,M,,M,,*7D",&p);
|
|||
if(fabs(fabs(p.latitude)-46.759373 >10-6)){
|
|||
printf ("Erreur Test unitaire trame_cmp21\n");
|
|||
271 | yomorsy | exit(-1);
|
|
361 | yomorsy | }
|
|
decode_trame("$GPGGA,141914.00,4645.5624,N,10112.1415,E,1,05,3.4,499.3,M,,M,,*7D",&p);
|
|||
if(fabs(fabs(p.longtitude)-101.202358 >10-6)){
|
|||
printf ("Erreur Test unitaire trame_cmp25\n");
|
|||
351 | yomorsy | exit(-1);
|
|
361 | yomorsy | }
|
|
374 | yomorsy | //////////
|
|
351 | yomorsy | ||
374 | yomorsy | if(fabs(calcul_distance(&p1,&p2)-7328.429126) >0.000001){
|
|
printf ("Erreur Test unitaire trame_cmp30\n");
|
|||
printf("a");
|
|||
exit(-1);
|
|||
}
|
|||
float a= calcul_distance(&p1,&p2);
|
|||
printf("%f",a);
|
|||
351 | yomorsy | }
|
|
1 | jalaffon | // Ne pas modifier cette fonction
|
|
int main(int argc,char ** argv)
|
|||
{
|
|||
271 | yomorsy | tests_unitaires();
|
|
1 | jalaffon | ||
// Affichage des trames definies dans la table trames.
|
|||
printf ("Trames de tests tableau trames:\n");
|
|||
int i=0;
|
|||
while (trames[i])
|
|||
traitement(trames[i++]);
|
|||
374 | yomorsy | if (!trame_init())
|
|
exit(-1);
|
|||
1 | jalaffon | // Affichage des trames du fichier gps.log
|
|
char *trame;
|
|||
printf ("Trames de tests du fichier gps.log\n");
|
|||
while ((trame = trame_suivante()))
|
|||
traitement(trame);
|
|||
return 0;
|
|||
}
|