Révision 290
Ajouté par Florentin GAMEL il y a presque 3 ans
branch/gamel/sp4a12/main.c | ||
---|---|---|
}
|
||
|
||
|
||
int decode_nombre(char*ch,int n){
|
||
int temp=0;
|
||
|
||
/*
|
||
int main2(){
|
||
int result;
|
||
float position;
|
||
result=decode_trame(p);
|
||
|
||
return(0);
|
||
}
|
||
|
||
|
||
float decode_trame(char*trame,position p)
|
||
{
|
||
int i;
|
||
if (trame_cmp(trame[i],"GPGGA")==1)
|
||
{
|
||
decode_position(trame[i],p)
|
||
}
|
||
}
|
||
*/
|
||
|
||
|
||
|
||
|
||
int decode_nombre(char *ch,int n){
|
||
int r=0;
|
||
int i;
|
||
|
||
for(i=0;i<n;i++){
|
||
temp=(temp*10)+decode_int(ch[i]);
|
||
r=10*r+decode_int(ch[i]);
|
||
}
|
||
return temp;
|
||
return r;
|
||
}
|
||
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
float decode_latitude(char *trame){
|
||
int i;
|
||
char minute[5];
|
||
float degreLat;
|
||
float minLat;
|
||
float resDecodeLat;
|
||
|
||
for(i=0;i<4;i++){
|
||
minute[i]=trame[i+22];
|
||
}
|
||
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
degreLat=10*decode_int(trame[17])+decode_int(trame[18]);
|
||
minLat=10*decode_int(trame[19])+decode_int(trame[20])+0.0001*decode_nombre(minute,4);
|
||
|
||
resDecodeLat=degreLat+minLat/60;
|
||
|
||
return resDecodeLat;
|
||
}
|
||
|
||
|
||
float decode_longitude(char *trame){
|
||
int i;
|
||
char minute[5];
|
||
float degreLong;
|
||
float minLong;
|
||
float resDecodeLong;
|
||
|
||
for(i=0;i<4;i++){
|
||
minute[i]=trame[i+35];
|
||
}
|
||
}
|
||
|
||
degreLong=100*decode_int(trame[29])+10*decode_int(trame[30])+decode_int(trame[31]);
|
||
minLong=10*decode_int(trame[32])+decode_int(trame[33])+0.0001*decode_nombre(minute,4);
|
||
|
||
resDecodeLong=degreLong+minLong/60;
|
||
|
||
return resDecodeLong;
|
||
}
|
||
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
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 suite chaine","GPRMC")!=1){
|
||
printf("Erreur test unitaire trame_cmp\n");
|
||
exit(-1);
|
||
}
|
||
if(trame_cmp("$APRMC suite chaine","GPGGA")!=0){
|
||
printf("Erreur test unitaire trame_cmp\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
|
||
void test_decode_nombre(void){
|
||
char t[5];
|
||
t[0]='1';t[1]='2';t[2]='3';t[3]='4';
|
||
|
||
if(decode_nombre(t,1)!=1){
|
||
printf("Erreur test unitaire decode-nombre1\n");
|
||
exit(-1);
|
||
}
|
||
if(decode_nombre(t,4)!=1234){
|
||
printf("Erreur test unitaire decode-nombre2\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void tests_decode_int(void){
|
||
if (decode_int('0')!=0){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
... | ... | |
}
|
||
}
|
||
|
||
|
||
void test_decode_latitude(void){
|
||
if(decode_latitude("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")!=45.75){
|
||
printf("Erreur test unitaire decode_latitude\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_decode_longitude(void){
|
||
if(decode_longitude("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")!=3.1100599765777588){
|
||
printf("Erreur test unitaire decode_longitude\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
Formats disponibles : Unified diff
Question 8 et 9 avec les fonctions de longitude et latitude et les tests unitaires