Révision 196
Ajouté par Alexis FOURNIER il y a environ 3 ans
branch/Fournier_Alexis/sp4a12/main.c | ||
---|---|---|
#include <strings.h>
|
||
#include "trame.h"
|
||
|
||
typedef struct{
|
||
float latitude;
|
||
float longitude;
|
||
}position;
|
||
position p1;
|
||
|
||
//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",
|
||
... | ... | |
}
|
||
|
||
|
||
float conv_sexa_decimal(char chaine[]){
|
||
|
||
int i=0, degre=0, minutes=0, u=1, w=-1, n=0;
|
||
float min_sec=0, secondes=0, res=0, min=0;
|
||
|
||
do{
|
||
n++;
|
||
}while(chaine[n]!='.');
|
||
|
||
if(n==4){
|
||
degre=(chaine[0]-48)*10+(chaine[1]-48);
|
||
i=2;
|
||
}
|
||
else{
|
||
degre=(chaine[0]-48)*100+(chaine[1]-48)*10+(chaine[2]-48);
|
||
i=3;
|
||
}
|
||
|
||
do{
|
||
min=min+(chaine[i]-48)*pow(10, u);
|
||
u--;
|
||
i++;
|
||
}while(chaine[i]!='.');
|
||
i++;
|
||
do{
|
||
secondes=secondes+(chaine[i]-48)*pow(10, u);
|
||
u--;
|
||
i++;
|
||
}while(chaine[i]!='\0');
|
||
|
||
res=degre+(min+secondes)/60;
|
||
|
||
return res;
|
||
|
||
}
|
||
|
||
|
||
int trame_cmp(char *trame, char *type)
|
||
{
|
||
int i=0, res=1;
|
||
... | ... | |
|
||
int decode_nombre ( char *ch, int n){
|
||
int i;
|
||
int S =0;
|
||
int S=0;
|
||
for(i=0;i<n;i++){
|
||
S =(S*10)+decode_int(ch(i));
|
||
S =(S*10)+decode_int(ch[i]);
|
||
}
|
||
return S;
|
||
}
|
||
|
||
|
||
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=conv_sexa_decimal(trame);
|
||
p->longitude=conv_sexa_decimal(trame);
|
||
}
|
||
T=1;
|
||
}
|
||
else {
|
||
T=0;
|
||
}
|
||
return T;
|
||
|
||
|
||
}
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
/* if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
... | ... | |
exit(-1);
|
||
}
|
||
if (decode_int(0)!=(-1)){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
printf ("Erreur Test unitaire decode_int.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (decode_nombre("465",2)!=(46)){
|
||
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
|
||
}
|
||
if (decode_nombre("465",3)!=(46)){
|
||
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
|
||
}
|
||
*/
|
||
if (decode_trame("$GPGGA,141914.00,5445.0044,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", &p1)!=1){
|
||
printf ("Erreur Test unitaire decode_trame.\n");
|
||
}
|
||
if(decode_trame("$GPGGA,141914.00,5445.0044-00,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", &p1)!=0){
|
||
printf ("la trame est valide \n");
|
||
exit(-1);
|
||
}
|
||
|
||
|
||
if (decode_trame("$GPGGA,141914.00,4568.0044,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", &p1)!=1){
|
||
printf ("Erreur Test unitaire decode_trame.\n");
|
||
}
|
||
if(decode_trame("$GPGGA,141914.00,4568.0044-00,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", &p1)!=0){
|
||
printf ("la trame est valide \n");
|
||
exit(-1);
|
||
}
|
||
|
||
|
||
if (decode_trame("$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39", &p1)!=1){
|
||
printf ("Erreur Test unitaire decode_trame.\n");
|
||
}
|
||
if(decode_trame("$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39", &p1)!=0){
|
||
printf ("la trame est valide \n");
|
||
exit(-1);
|
||
}
|
||
if (decode_trame("$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C", &p1)!=1){
|
||
printf ("Erreur Test unitaire decode_trame.\n");
|
||
}
|
||
if(decode_trame("$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C", &p1)!=0){
|
||
printf ("la trame est valide \n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
Formats disponibles : Unified diff
question 3 TP2 fournier alexis