Révision 377
Ajouté par rademagalh il y a presque 4 ans
branch/DEMAGALHAES/sp4a12/main.c | ||
---|---|---|
"$GPVTG,99.4,T,,M,0.4,N,0.7,K*57",
|
||
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
0};
|
||
typedef struct{
|
||
float latitude;
|
||
float longitude;
|
||
}Position;
|
||
typedef struct {
|
||
Position rpos;
|
||
float vitmax;
|
||
} Zone;
|
||
Zone zones[] = {
|
||
{{44.7887762, -3.012}, 50}, /* Descripteur de la premi?re zone */
|
||
{{44.7891220, -3.013}, 70},
|
||
};
|
||
|
||
int trame_cmp(char * trame, char * type)
|
||
{
|
||
... | ... | |
}
|
||
}
|
||
|
||
float CharVersRadians(char* ch)
|
||
float CharVersDegre(char* ch)
|
||
{
|
||
char * nombre=ch;
|
||
float dec;
|
||
... | ... | |
degre=decode_nombre(nombre,3);
|
||
dec=(dec-degre*100)/60;
|
||
}
|
||
return (degre+dec)*(3.14/180);
|
||
return (degre+dec);
|
||
}
|
||
|
||
typedef struct{
|
||
float latitude;
|
||
float longitude;
|
||
}Position;
|
||
|
||
Position decode_trame(char * ch)
|
||
{
|
||
Position pos;
|
||
... | ... | |
}
|
||
indice++;
|
||
} while (ch[indice]!='\0');
|
||
pos.latitude = CharVersRadians(latitude);
|
||
pos.longitude = CharVersRadians(longitude);
|
||
pos.latitude = CharVersDegre(latitude);
|
||
pos.longitude = CharVersDegre(longitude);
|
||
}
|
||
return pos;
|
||
}
|
||
|
||
float calcul_distance(Position p1,Position p2)
|
||
{
|
||
float R_terre=6378.137;
|
||
float distance = R_terre*(p1.latitude-p2.latitude)*(3.14/180);
|
||
return distance;
|
||
}
|
||
|
||
float calcul_vitesse(float distance)
|
||
{
|
||
return distance*3600;
|
||
}
|
||
|
||
float distance_a_la_plus_proche_zone(Position pos_voiture, Zone r[], int nb_zones)
|
||
{
|
||
Position t[nb_zones];
|
||
for (int i = 0; i < nb_zones; i++)
|
||
{
|
||
Position pos=r[i].rpos;
|
||
t[i]=pos;
|
||
}
|
||
float d_min=calcul_distance(pos_voiture,t[1]);
|
||
int indice_rechercher=0;
|
||
for (int i = 0; i < nb_zones; i++)
|
||
{
|
||
float d=calcul_distance(pos_voiture,t[i]);
|
||
if (d<d_min)
|
||
{
|
||
d_min=d;
|
||
indice_rechercher=i;
|
||
}
|
||
if (nb_zones==0)
|
||
{
|
||
return -1;
|
||
}
|
||
}
|
||
return d_min;
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
... | ... | |
printf ("Erreur Test decode_trame basique. n?1\n");
|
||
exit(-1);
|
||
}
|
||
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);
|
||
Position pos1=decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D");
|
||
Position pos2=decode_trame("$GPGGA,141925.00,4545.2410,N,00306.6046,E,1,05,3.4,501.4,M,,M,,*7D");
|
||
printf("pos.longitude : %f deg \n",pos1.longitude);
|
||
printf("pos.latitude : %f deg \n",pos1.latitude);
|
||
printf("pos.longitude : %f deg \n",pos2.longitude);
|
||
printf("pos.latitude : %f deg \n",pos2.latitude);
|
||
printf("distance entre pos1 et pos2 : %f km \n",calcul_distance(pos2,pos1));
|
||
printf("distance a la plus proche zone : %f km \n",distance_a_la_plus_proche_zone(pos1, zones, 2));
|
||
}
|
||
|
||
//Ne pas modifier cette fonction
|
Formats disponibles : Unified diff
Ajout fonction distance_a_la_plus_proche calcul_distance calcul_vitesse