Révision 361
Ajouté par Youssef MORSY il y a presque 3 ans
branch/MORSY/sp4a12/main.c | ||
---|---|---|
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include<math.h>
|
||
#include "trame.h"
|
||
|
||
#include "trame.h"
|
||
|
||
|
||
|
||
typedef struct {
|
||
float latitude;
|
||
float longtitude;
|
||
}position;
|
||
|
||
position p;
|
||
//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",
|
||
... | ... | |
0};
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
void traitement(char * trame)
|
||
{
|
||
static int cpt=0;
|
||
cpt++;
|
||
position p;
|
||
|
||
if (trame_cmp(trame, "GPGGA")==1){
|
||
printf("%s\n",trame);
|
||
decode_trame(trame,&p);
|
||
printf("latitude= %f , longtude= %f \n",p.latitude,p.longtitude);
|
||
}
|
||
|
||
|
||
}
|
||
int decode_int(char c){
|
||
int y;
|
||
... | ... | |
return s;
|
||
}
|
||
|
||
float latitude (char*c){
|
||
/*float latitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[17])*10+decode_int(c[18]) ;
|
||
secondes=(decode_int(c[21])*1000+decode_int(c[22])*100+decode_int(c[23])*10+decode_int(c[24]))/10000;
|
||
minute=(decode_int(c[19])*10+decode_int(c[20])+secondes)/60;
|
||
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;
|
||
sommes=degre+minute;
|
||
return sommes;
|
||
}
|
||
}*/
|
||
|
||
|
||
|
||
float longtitude (char*c){
|
||
/*float longtitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[29])*100+decode_int(c[30])*10+decode_int(c[31]) ;
|
||
secondes=(decode_int(c[35])*1000+decode_int(c[36])*100+decode_int(c[37])*10+decode_int(c[38])*1)%1000;
|
||
minute=(decode_int(c[32])*10+decode_int(c[33])+secondes)/60;
|
||
sommes=degre+minute;
|
||
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;
|
||
}*/
|
||
|
||
return sommes;
|
||
}
|
||
|
||
float deux_fonctions(char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
while(c[i] != '.'){
|
||
i=i+1;
|
||
}
|
||
if(i==4){
|
||
float lat_long (char c[]) {
|
||
int n=0, degre=0,i=1,b;
|
||
float min=0, secondes=0, res=0,p;
|
||
|
||
degre=decode_int(c[17])*10+decode_int(c[18]) ;
|
||
secondes=(decode_int(c[21])*1000+decode_int(c[22])*100+decode_int(c[23])*10+decode_int(c[24]))/10000;
|
||
minute=(decode_int(c[19])*10+decode_int(c[20])+secondes)/60;
|
||
sommes=degre+minute;}
|
||
else{
|
||
degre=decode_int(c[29])*100+decode_int(c[30])*10+decode_int(c[31]) ;
|
||
secondes=(decode_int(c[35])*1000+decode_int(c[36])*100+decode_int(c[37])*10+decode_int(c[38])*1)/1000;
|
||
minute=(decode_int(c[32])*10+decode_int(c[33])+secondes)/60;
|
||
sommes=degre+minute;
|
||
|
||
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);
|
||
}
|
||
return sommes;
|
||
|
||
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');
|
||
|
||
res = degre + (min+secondes)/60;
|
||
|
||
return res;
|
||
|
||
}
|
||
|
||
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;
|
||
|
||
|
||
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
|
||
void tests_unitaires(void){
|
||
... | ... | |
exit(-1);
|
||
}
|
||
if (decode_nombre("35789",3)!=357){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
printf ("Erreur Test unitaire trame_cmp16.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
... | ... | |
exit(-1);
|
||
}
|
||
//********************************
|
||
if (5!=5){
|
||
/* if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("$GPGGA,141914.00,3558.8889,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
}
|
||
if (longtitude("13558.8889")-135,981481<0.000001 && 135,981481-longtitude("13558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("$GPGGA,141914.00,0112.1415,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
if (longtitude("10112.1415")-101,202358<0.000001 && 101,202358-longtitude("10112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}*/
|
||
//***********************************
|
||
/* if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
//***********************************
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("$GPGGA,141914.00,0112.1415,N,13558.8889,E,1,05,3.4,499.3,M,,M,,*7D")-135,981481<0.000001 && 135,981481-latitude("13558.8889")<0.000001){
|
||
if (latitude("3558.8889")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("$GPGGA,141914.00,0112.1415,N,10112.1415,E,1,05,3.4,499.3,M,,M,,*7D")-101,202358<0.000001 && 101,202358-latitude("10112.1415")<0.000001){
|
||
if (latitude("0112.1415")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
}*/
|
||
//*****************************
|
||
if (5!=5){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("$GPGGA,141914.00,0112.1415,N,13558.8889,E,1,05,3.4,499.3,M,,M,,*7D")-135,981481<0.000001 && 135,981481-deux_fonctions("13558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("$GPGGA,141914.00,0112.1415,N,10112.1415.1415,E,1,05,3.4,499.3,M,,M,,*7D10112.1415")-101,202358<0.000001 && 101,202358-deux_fonctions("10112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
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");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("$GPGGA,141914.00,3558.8889,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
}
|
||
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");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("$GPGGA,141914.00,0112.1415,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
}
|
||
// Ne pas modifier cette fonction
|
||
... | ... | |
while (trames[i])
|
||
traitement(trames[i++]);
|
||
|
||
if (!trame_init())
|
||
exit(-1);
|
||
// if (!trame_init())
|
||
// exit(-1);
|
||
// Affichage des trames du fichier gps.log
|
||
char *trame;
|
||
printf ("Trames de tests du fichier gps.log\n");
|
Formats disponibles : Unified diff
question 3 tp2