Révision 413
Ajouté par Clara SOULARD il y a presque 3 ans
branch/clara_soulard/sp4a12/main.c | ||
---|---|---|
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
#include <math.h>
|
||
|
||
typedef struct {
|
||
float latitude;
|
||
float longitude;
|
||
} Position ;
|
||
} Position ;
|
||
|
||
typedef struct {
|
||
Position rpos;
|
||
float vitmax;
|
||
} Zone ;
|
||
|
||
//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",
|
||
... | ... | |
return c;
|
||
}
|
||
|
||
/*float convertisseur_latitude (char *ch)
|
||
{
|
||
float lat;
|
||
|
||
float decimal=0.0;
|
||
float decimal1=0.0;
|
||
float decimal2=0.0;
|
||
float dec=0.0;
|
||
float a=0.0;
|
||
int b;
|
||
int i;
|
||
a=(float)(decode_nombre(ch, 4));
|
||
float degres=(float)(decode_nombre(*ch,2));
|
||
decimal1=(a-degres);
|
||
for(i=5; i<=8; i++)
|
||
{
|
||
b=decode_int(ch[i]);
|
||
decimal2=decimal2*10+b;
|
||
|
||
}
|
||
decimal=(float)((decimal1 + ((float)(decimal2)/10000))/60);
|
||
lat=degres+decimal;
|
||
return lat;
|
||
}*/
|
||
float convertisseur_latitude (char *ch)
|
||
{
|
||
|
||
... | ... | |
}
|
||
}
|
||
|
||
int decode_trame(char *trame, Position *p)
|
||
float calcul_distance(Position p_1, Position p_2)
|
||
{
|
||
char latit[10]; //chaine de caract?res qui vont servir ? copier les latitudes et les longitudes pour les convertir en flottants
|
||
char longit[15];
|
||
char *lat;
|
||
lat=&latit;
|
||
int k;
|
||
int i=0;
|
||
int j;
|
||
int ok;
|
||
float longitude=0.0;
|
||
float latitude=0.0;
|
||
float S;
|
||
float R=6371.00; //rayon de la Terre
|
||
float P=2*M_PI*R;
|
||
float c=P/360.00;
|
||
S=c*pow((pow((p_2.latitude-p_1.latitude),2)+pow((p_2.longitude-p_1.longitude),2)),0.5);
|
||
return S;
|
||
}
|
||
|
||
if (trame_cmp(trame, "GPGGA")!=1) //on utilise la fonction d?j? cr?e au tp1 pour comparer le debut de la trame et voir si elle est correcte
|
||
float calcul_vitesse(Position p_1, Position p_2)
|
||
{
|
||
float vitesse;
|
||
float h=36000;
|
||
vitesse=calcul_distance(p_1, p_2)*36000;
|
||
return vitesse;
|
||
}
|
||
|
||
|
||
int decode_trame(char* t, Position* p){
|
||
int ok,i;
|
||
char latitudecopie[9]; // chaine qui va contenir la latitude extraite de la trame
|
||
char longitudecopie[10]; //chaine qui va contenir la longitude extraite de la trame
|
||
|
||
ok=trame_cmp(t,"GPGGA"); // comparaison pour voir si la trame est valide
|
||
if(ok==1)
|
||
{
|
||
return 0;
|
||
}
|
||
else
|
||
{ ok=1;
|
||
int cptvir=0; //on compte les virgules dans la trame pour se reperer et savoir ou sont la latitude et la longitude
|
||
for(i=0;i<9;++i)
|
||
{
|
||
latitudecopie[i]=t[17+i]; //on a un tableau contenant la latitude en cha?ne de caract?res
|
||
}
|
||
(*p).latitude=convertisseur_latitude(latitudecopie);
|
||
|
||
while (trame[i]!='\0')
|
||
{
|
||
i=i+1;
|
||
for(i=0;i<10;++i)
|
||
{
|
||
longitudecopie[i]=t[29+i]; //on a un tableau contenant la longitude en cha?ne de caract?res
|
||
|
||
if (trame[i]==',') //on detecte les virgules
|
||
{
|
||
cptvir=cptvir+1;
|
||
if (cptvir==2) //la deuxi?me virgule marque le debut des coordonn?es de la latitude
|
||
{
|
||
for(k=i+1; k<i+10; k++)
|
||
{
|
||
latit[k-i]=trame[k]; //debugger ici ok fonctionne
|
||
}
|
||
(*p).longitude=convertisseur_longitude(longitudecopie);
|
||
|
||
}
|
||
printf("%f :", latitude=convertisseur_latitude(latit));
|
||
}else{
|
||
exit(-1);
|
||
} }
|
||
|
||
}
|
||
if (cptvir==4)
|
||
{
|
||
for(j=i+1; j<i+11; j++)
|
||
{
|
||
longit[j-i]=trame[j];
|
||
int distance_a_la_plus_proche_zone(Position p, Zone r[],int nb_zones, float *d)
|
||
{ int i;
|
||
float distance;
|
||
distance=calcul_distance(p, r[0].rpos); //initialise la premiere distance ? comparer
|
||
int index; //variable que l'on retourne ? la fin de la fonction
|
||
|
||
}
|
||
for (i=0; i<nb_zones; i++)
|
||
|
||
longitude=convertisseur_longitude(longit);
|
||
}
|
||
}
|
||
}
|
||
{
|
||
*d=calcul_distance(p, r[i].rpos);
|
||
if (*d<=distance) //si la distance entre la position p et celle du radar ? la i-?me position recens?e est inf?rieur ? la premi?re distance calcul?e, distance prends cette valeur. on retrouvera ainsi de suite la zone dangereuse la plus pr?s de la position de la voiture!
|
||
{
|
||
distance=*d;
|
||
index=i;
|
||
}
|
||
|
||
}
|
||
|
||
return ok;
|
||
|
||
return index;
|
||
}
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
... | ... | |
{
|
||
printf("Erreur sur le convertisseur longitude");
|
||
}
|
||
if (decode_trame("$GPGGA,141922.00,4545.1810,N,00306.6046,E,1,05,3.4,500.6,M,,M,,*74",p)!=1) {
|
||
if (decode_trame("$GPGGA,141922.00,4545.1810,N,00306.6046,E,1,05,3.4,500.6,M,,M,,*74",p)==1) {
|
||
printf("Erreur sur decode_trame");
|
||
}
|
||
|
||
printf("le resultat est : %i", decode_trame("$GPGGA,141922.00,4545.1810,N,00306.6046,E,1,05,3.4,500.6,M,,M,,*74", p));
|
||
//tests de certaines fonction
|
||
|
||
Position pos;
|
||
pos.latitude=1;
|
||
pos.longitude=1;
|
||
Position *posi;
|
||
posi=&pos;
|
||
|
||
|
||
decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", posi);
|
||
printf("position latitude: %f \n", (*posi).latitude);
|
||
printf("position longtitude: %f", (*posi).longitude);
|
||
|
||
Position position1, position2, position3, position4, position5,position6;
|
||
|
||
//paris
|
||
position2.latitude=48.85666666666667;
|
||
position2.longitude=2.3519444444444444;
|
||
|
||
//Rouen
|
||
position1.latitude=49.443888888888885;
|
||
position1.longitude=1.1033333333333335;
|
||
|
||
//lille
|
||
position3.latitude=50.63722222222222;
|
||
position3.longitude=3.063333333333333;
|
||
|
||
//chalons
|
||
position4.latitude=48.9575;
|
||
position4.longitude=4.364999999999999;
|
||
|
||
//nice
|
||
position5.latitude=43.7;
|
||
position5.longitude=7.35;
|
||
|
||
|
||
printf("fonction test distance\n");
|
||
printf("Distance Paris-Rouen=%f\n", calcul_distance(position2, position1)); //Paris-Rouen = 135 km
|
||
printf("Distance Paris-Lille=%f\n", calcul_distance(position2, position3)); //Paris-Lille
|
||
printf("D2=%f\n", calcul_distance(position2, position4));
|
||
printf("D2=%f\n", calcul_distance(position2, position5));
|
||
|
||
|
||
Zone zones[] = {{{44.7887762, -3.012}, 50},{{44.7891220, -3,013}, 70}};
|
||
float dist;
|
||
float *d;
|
||
d=&dist;
|
||
int c;
|
||
c=distance_a_la_plus_proche_zone(position1, zones, 2, d);
|
||
printf("zone dangereuse : %i \n", a);
|
||
|
||
|
||
}
|
||
|
||
... | ... | |
char *trame;
|
||
printf ("Trames de tests du fichier gps.log\n");
|
||
while ((trame = trame_suivante()))
|
||
traitement(trame);
|
||
traitement(trame);
|
||
|
||
return 0;
|
||
}
|
Formats disponibles : Unified diff
fonctions decodes trame, calcule_distance, calcule_vitesse et tests ok, manque commentaires et indentation à vérifier et les alarmes.