Révision 656
Ajouté par mukis il y a presque 4 ans
branch/KIS/sp4a12/main.c | ||
---|---|---|
#include "trame.h"
|
||
|
||
typedef struct {
|
||
float longitude;
|
||
float latitude;
|
||
float longitude;
|
||
} Position ;
|
||
|
||
|
||
... | ... | |
}
|
||
if (a==0)
|
||
{
|
||
printf("Trame commencant par GPGGA :\n");
|
||
printf("%s\n",trame);
|
||
return 1;
|
||
}
|
||
else
|
||
... | ... | |
|
||
if (i<=4)
|
||
{
|
||
conversion_latitude (c);
|
||
return conversion_latitude (c);
|
||
}
|
||
if (i>=5)
|
||
{
|
||
conversion_longitude (c);
|
||
return conversion_longitude (c);
|
||
}
|
||
}
|
||
|
||
int decode_trame(char *trame, Position *p)
|
||
int decode_trame(char *trame, Position p)
|
||
{
|
||
int i=0, j=0, k=0;
|
||
char lat_c[10], long_c[11];
|
||
char lat_c[10]={NULL}, long_c[11]={NULL};
|
||
|
||
if(trame_cmp(trame,"GPGGA"))
|
||
{
|
||
for (i=0; i< '\0'; i++)
|
||
printf("Trame commencant par GPGGA :\n");
|
||
printf("%s\n",trame);
|
||
for (i=0; i<66; i++)
|
||
{
|
||
if (i>=17 && i<=25)
|
||
{
|
||
lat_c[j] = trame[i];
|
||
j++;
|
||
//printf("lat : %s\n",lat_c);
|
||
}
|
||
|
||
if (i>=29 && i<=38)
|
||
if (i>=29 )// 29<= i <=38
|
||
{
|
||
if(i==39)
|
||
{
|
||
break;
|
||
}
|
||
long_c[k] = trame[i];
|
||
k++;
|
||
//printf("long : %s\n",long_c);
|
||
}
|
||
}
|
||
|
||
Position p;
|
||
printf("lat_c : %s,long_c %s\n",lat_c,long_c);
|
||
p.latitude = conversion_lat_long(lat_c);
|
||
p.longitude = conversion_lat_long(long_c);
|
||
}
|
||
printf("lat : %f,long : %f\n\n",p.latitude,p.longitude);
|
||
return trame_cmp(trame,"GPGGA");
|
||
}
|
||
|
||
float calcule_distance(Position p_1, Position p_2)
|
||
{
|
||
float d=0, a1, a2, b1, b2;
|
||
|
||
return trame_cmp(trame,"GPGGA");
|
||
a1 = p_1.latitude;
|
||
a2 = p_2.latitude;
|
||
b1 = p_1.longitude;
|
||
b2 = p_2.longitude;
|
||
|
||
d = 6371 * acosf( sin(a1)*sin(a2) + cos(a1)*cos(a2)*cos(b2-b1) ); //distance en km
|
||
|
||
return d;
|
||
}
|
||
|
||
float calcule_vitesse(Position p_1, Position p_2)
|
||
{
|
||
float v = 0;
|
||
|
||
v = calcule_distance(p_1, p_2)*3,6; // vitesse en km/h
|
||
|
||
return v;
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
... | ... | |
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void)
|
||
{
|
||
Position p;
|
||
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
... | ... | |
printf ("Erreur Test unitaire conversion longitude.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_trame("$GPVTG,99.4,T,,M,0.4,N,0.7,K*57", "GPGGA")!=0){
|
||
if (decode_trame("$GPVTG,99.4,T,,M,0.4,N,0.7,K*57", p)!=0){
|
||
printf ("Erreur Test unitaire decode_trame.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", "GPGGA")!=1){
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", p)!=1){
|
||
printf ("Erreur Test unitaire decode_trame.\n");
|
||
exit(-1);
|
||
}
|
||
... | ... | |
tests_unitaires();
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
printf ("\nTrames de tests tableau trames:\n");
|
||
int i=0;
|
||
while (trames[i])
|
||
traitement(trames[i++]);
|
Formats disponibles : Unified diff
fonction distance et vitesse FAIT
reste a les tester