Révision 193
Ajouté par Stephen LOPEZ il y a environ 3 ans
branch/LOPEZ_Stephen/tp_sp4_2022_LOPEZ_Stephen/sp4a12/main.c | ||
---|---|---|
printf ("> %s\n",trame);
|
||
}
|
||
}
|
||
|
||
typedef struct {
|
||
float latitude;
|
||
float longitude;
|
||
} position ;
|
||
position p1;
|
||
|
||
int trame_cmp(char *trame,char*type)
|
||
{
|
||
int i;
|
||
... | ... | |
return S;
|
||
}
|
||
|
||
float latitude (char *ch)
|
||
float latitude (char * ch)
|
||
{
|
||
float deg;
|
||
deg = decode_nombre(&ch[17],2)+(decode_nombre(&ch[17+2],2)/60)+(decode_nombre(&ch[17+5],4)/600000);
|
||
return deg;
|
||
float minute;
|
||
float diminute;
|
||
float resultat;
|
||
|
||
deg=(float)decode_nombre(&ch[0],2);
|
||
minute=(float)decode_nombre(&ch[0+2],2);
|
||
minute=minute/60;
|
||
diminute=(float)decode_nombre(&ch[0+5],4);
|
||
diminute=diminute/600000;
|
||
resultat=deg+minute+diminute;
|
||
|
||
return resultat;
|
||
}
|
||
float longitude (char *ch)
|
||
|
||
float longitude (char * ch)
|
||
{
|
||
float degr;
|
||
degr = decode_nombre(&ch[29],3)+(decode_nombre(&ch[29+3],2)/60)+(decode_nombre(&ch[29+6],4)/600000);
|
||
return degr;
|
||
float deg;
|
||
float minute;
|
||
float diminute;
|
||
float resultat;
|
||
|
||
deg=(float)decode_nombre(&ch[0],3);
|
||
minute=(float)decode_nombre(&ch[0+3],2);
|
||
minute=minute/60;
|
||
diminute=(float)decode_nombre(&ch[0+6],4);
|
||
diminute=diminute/600000;
|
||
resultat=(float)
|
||
deg+minute+diminute;
|
||
|
||
return resultat;
|
||
}
|
||
float lat_long(char* ch)
|
||
{
|
||
float res;
|
||
if (ch[4]==46)
|
||
{
|
||
res=latitude(ch);
|
||
}
|
||
else
|
||
{
|
||
res=longitude(ch);
|
||
}
|
||
return res;
|
||
}
|
||
|
||
int decode_trame(char* trame, position *p )
|
||
{
|
||
int T;
|
||
if (trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
if ((trame[16]!=trame[17])&&(trame[28]!=trame[29]))
|
||
{
|
||
p->latitude=latitude(trame);
|
||
p->longitude=longitude(trame);
|
||
T=1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
T=0;
|
||
}
|
||
return T;
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
/*
|
||
|
||
/*
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
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);
|
||
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");3723.2475
|
||
printf ("Erreur Test unitaire trame_cmp.\n");3723.2475;
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
||
... | ... | |
if (decode_int('5')!=5){
|
||
printf ("Erreur Test unitaire decode_int.\n");
|
||
exit(-1);
|
||
}45
|
||
}
|
||
if (decode_int('9')!=9){
|
||
printf ("Erreur Test unitaire decode_int.\n");
|
||
exit(-1);
|
||
... | ... | |
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (latitude("3723.2475")-37.387458>0.0001){
|
||
printf ("Erreur Test unitaire latitude.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("$GPGGA,141921.00,4545.1610,N,00306.6043,E,1,05,3.4,499.8,M,,M,,*7C")-45.75268333>0.01){
|
||
|
||
if (latitude("4545.1610")-45.75268333>0.01){
|
||
printf ("Erreur Test unitaire latitude.\n");
|
||
exit(-1);
|
||
}
|
||
if (longitude("$GPGGA,141921.00,4545.1610,N,00306.6043,E,1,05,3.4,499.8,M,,M,,*7C")-3.110071667>0.01){
|
||
printf ("Erreur Test unitaire latitude.\n");
|
||
if (longitude("00306.6043")-3.110071667>0.01){
|
||
printf ("Erreur Test unitaire longitude.\n");
|
||
exit(-1);
|
||
}
|
||
*/
|
||
|
||
if ((lat_long("00306.6036")-003.11006)>0.1){
|
||
printf("Erreur Test unitaire trameLONG\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if ((lat_long("4545.0242")-45.7504)>0.1){
|
||
printf("Erreur Test unitaire trameLAT\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p1)!=1){
|
||
printf("La position et la trame sont invalide ");
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p1)!=0){
|
||
printf("Erreur Test unitaire decode_trame \n");}
|
||
exit(-1);
|
||
}
|
||
|
||
if (decode_trame("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*72",&p1)!=1){
|
||
printf("La position et la trame sont invalide ");
|
||
if (decode_trame("$GPGGA,141917.00,4545.0726,N,00306.6039,E,1,05,3.4,499.6,M,,M,,*72",&p1)!=0){
|
||
printf("Erreur Test unitaire decode_trame \n");}
|
||
exit(-1);
|
||
}
|
||
|
||
if (decode_trame("$GPGGA,141918.00,4545.0968,N,00306.6034,E,1,05,3.4,498.8,M,,M,,*7C",&p1)!=1){
|
||
printf("La position et la trame sont invalide ");
|
||
if (decode_trame("$GPGGA,141918.00,4545.0968,N,00306.6034,E,1,05,3.4,498.8,M,,M,,*7C",&p1)!=0){
|
||
printf("Erreur Test unitaire decode_trame \n");}
|
||
exit(-1);
|
||
}
|
||
if (decode_trame("$GPGGA,141919.00,4545.1210,N,00306.6040,E,1,05,3.4,500.2,M,,M,,*75",&p1)!=1){
|
||
printf("La position et la trame sont invalide ");
|
||
if (decode_trame("$GPGGA,141919.00,4545.1210,N,00306.6040,E,1,05,3.4,500.2,M,,M,,*75",&p1)!=0){
|
||
printf("Erreur Test unitaire decode_trame \n");}
|
||
exit(-1);
|
||
}
|
||
*/
|
||
}
|
||
|
||
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
Formats disponibles : Unified diff
Séance 1 terminée
Question 1 et 2 de la séance 2 sont validées