Révision 376
Ajouté par rademagalh il y a presque 4 ans
branch/DEMAGALHAES/sp4a12/main.c | ||
---|---|---|
}
|
||
}
|
||
|
||
double conversionChaineFlottante(char* ch)
|
||
float CharVersRadians(char* ch)
|
||
{
|
||
double res = 0, fact = 1;
|
||
if (*ch == '-')
|
||
{
|
||
ch++;
|
||
fact = -1;
|
||
}
|
||
for (int virguleVu = 0; *ch; ch++)
|
||
{
|
||
if (*ch == '.')
|
||
{
|
||
virguleVu = 1;
|
||
continue;
|
||
}
|
||
int d = *ch - '0';
|
||
if (d >= 0 && d <= 9)
|
||
{
|
||
if (virguleVu) fact /= 10.0;
|
||
res = res * 10.0 + (double)d;
|
||
}
|
||
if (*ch == ',')
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
return res * fact;
|
||
char * nombre=ch;
|
||
float dec;
|
||
int compte=0,n,degre;
|
||
float res = 0, fact = 1;
|
||
if (*ch == '-')
|
||
{
|
||
ch++;
|
||
fact = -1;
|
||
}
|
||
for (int virguleVu = 0; *ch; ch++)
|
||
{
|
||
compte++;
|
||
if (*ch == '.')
|
||
{
|
||
virguleVu = 1;
|
||
n=compte-1;
|
||
continue;
|
||
}
|
||
int d = *ch - '0';
|
||
if (d >= 0 && d <= 9)
|
||
{
|
||
if (virguleVu) fact /= 10.0;
|
||
res = res * 10.0 + (float)d;
|
||
}
|
||
if (*ch == ',')
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
dec=(res * fact);
|
||
if (n==4)
|
||
{
|
||
degre=decode_nombre(nombre,2);
|
||
dec=(dec-degre*100)/60;
|
||
}
|
||
else if (n==5)
|
||
{
|
||
degre=decode_nombre(nombre,3);
|
||
dec=(dec-degre*100)/60;
|
||
}
|
||
return (degre+dec)*(3.14/180);
|
||
}
|
||
|
||
typedef struct{
|
||
... | ... | |
}
|
||
indice++;
|
||
} while (ch[indice]!='\0');
|
||
pos.latitude = conversionChaineFlottante(latitude);
|
||
pos.longitude = conversionChaineFlottante(longitude);
|
||
pos.latitude = CharVersRadians(latitude);
|
||
pos.longitude = CharVersRadians(longitude);
|
||
}
|
||
return pos;
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
|
||
//Fonction de tests unitaires pour conversionChaineFlottante
|
||
void test_conversionChaineFlottante()
|
||
{
|
||
printf("Test de la fonction test_conversionChaineFlottante \n");
|
||
if (5!=5){
|
||
printf ("Erreur Test conversionChaineFlottante basique. n?1\n");
|
||
exit(-1);
|
||
}
|
||
if ((conversionChaineFlottante("3723.2475,N")/723.247500)<1)
|
||
{
|
||
printf ("Erreur Test conversionChaineFlottante. n?2\n");
|
||
exit(-1);
|
||
}
|
||
if ((conversionChaineFlottante("00306.6036,E")/00306.603600)<1)
|
||
{
|
||
printf ("Erreur Test conversionChaineFlottante. n?3\n");
|
||
exit(-1);
|
||
}
|
||
if ((conversionChaineFlottante("4545.0000,N")/4545.000000)<1)
|
||
{
|
||
printf ("Erreur Test conversionChaineFlottante. n?4\n");
|
||
exit(-1);
|
||
}
|
||
if ((conversionChaineFlottante("00752.726,E")/00752.726000)<1)
|
||
{
|
||
printf ("Erreur Test conversionChaineFlottante. n?5\n");
|
||
exit(-1);
|
||
}
|
||
else
|
||
{
|
||
printf("Pas d'erreur fonction potentiellement valide ! \n");
|
||
}
|
||
}
|
||
|
||
|
||
void test_decode_trame(){
|
||
printf("Test de la fonction test_decode_trame \n");
|
||
if (5!=5){
|
||
... | ... | |
Position pos=(decode_trame(("$GPGGA,141925.00,4545.2410,N,00306.6046,E,1,05,3.4,501.4,M,,M,,*7D")));
|
||
printf("latitude en flottant = %.4f \n ",pos.latitude);
|
||
printf("longitude en flottant = %.4f \n ",pos.longitude);
|
||
if ((4545.2410/pos.latitude)>1.0)
|
||
{
|
||
printf ("Erreur Test decode_trame. n?2\n");
|
||
exit(-1);
|
||
}
|
||
if ((00306.6046/pos.longitude)<1.0)
|
||
{
|
||
printf ("Erreur Test decode_trame. n?3\n");
|
||
exit(-1);
|
||
}
|
||
else
|
||
{
|
||
printf("Pas d'erreur fonction potentiellement valide ! \n");
|
||
}
|
||
|
||
}
|
||
|
||
//Ne pas modifier cette fonction
|
||
... | ... | |
tests_unitaires();
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
test_conversionChaineFlottante();
|
||
test_decode_trame();
|
||
|
||
// Affichage des trames definies dans la table trames.
|
Formats disponibles : Unified diff
Modification et rectification de la fonction caractVersFlottant pour obtenir CharVersRadians.