Révision 436
Ajouté par Lilian MEMBRE il y a presque 3 ans
branch/MEMBRE/sp4a12/main.c | ||
---|---|---|
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include <math.h>
|
||
#include "trame.h"
|
||
|
||
//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",
|
||
"$GPGSV,3,3,10,22,39,053,50,28,15,320,*7E",
|
||
"$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C",
|
||
"$GPGLL,4545.6424,N,00306.6036,E,141914.00,A*0E",
|
||
"$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",
|
||
"$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39",
|
||
"$GPVTG,99.4,T,,M,0.4,N,0.7,K*57",
|
||
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
#include <math.h>
|
||
#include "trame.h"
|
||
#define PI 3.14159
|
||
|
||
//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",
|
||
"$GPGSV,3,3,10,22,39,053,50,28,15,320,*7E",
|
||
"$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C",
|
||
"$GPGLL,4545.6424,N,00306.6036,E,141914.00,A*0E",
|
||
"$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",
|
||
"$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39",
|
||
"$GPVTG,99.4,T,,M,0.4,N,0.7,K*57",
|
||
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
0};
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//Fontion trame_cmp
|
||
int trame_cmp(char * trame, char * type)
|
||
{
|
||
int i;
|
||
int egalite = 1;
|
||
|
||
for (i=0;i<5;i++)
|
||
{
|
||
if (trame[i+1]!= type[i])
|
||
{
|
||
egalite=0;
|
||
}
|
||
}
|
||
return egalite;
|
||
int trame_cmp(char * trame, char * type)
|
||
{
|
||
int i;
|
||
int egalite = 1;
|
||
|
||
for (i=0;i<5;i++)
|
||
{
|
||
if (trame[i+1]!= type[i])
|
||
{
|
||
egalite=0;
|
||
}
|
||
}
|
||
return egalite;
|
||
}
|
||
|
||
|
||
... | ... | |
|
||
//Fonction decode_int
|
||
|
||
int decode_int(char c)
|
||
{
|
||
if ((c<'A') && (c>='0'))
|
||
{
|
||
c =c-48;
|
||
}
|
||
else
|
||
{
|
||
c=-1;
|
||
int decode_int(char c)
|
||
{
|
||
if ((c<'A') && (c>='0'))
|
||
{
|
||
c =c-48;
|
||
}
|
||
return c;
|
||
else
|
||
{
|
||
c=-1;
|
||
}
|
||
return c;
|
||
}
|
||
|
||
|
||
... | ... | |
if (decode_int('0')!=0){
|
||
printf("Erreur test unitaire");
|
||
exit(-1);
|
||
}
|
||
}
|
||
if (decode_int('1')!=1){
|
||
printf("Erreur test unitaire");
|
||
exit(-1);
|
||
... | ... | |
if (decode_int('A')!=-1){
|
||
printf("Erreur test unitaire");
|
||
exit(-1);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
... | ... | |
|
||
|
||
//Fonction decode_nombre
|
||
int decode_nombre(char * ch, int n)
|
||
{
|
||
int p=0;
|
||
int i;
|
||
for(i=0;i<n;i++)
|
||
{
|
||
p= decode_int(ch[i]) + p*10;
|
||
}
|
||
return p;
|
||
int decode_nombre(char * ch, int n)
|
||
{
|
||
int p=0;
|
||
int i;
|
||
for(i=0;i<n;i++)
|
||
{
|
||
p= decode_int(ch[i]) + p*10;
|
||
}
|
||
return p;
|
||
}
|
||
|
||
|
||
... | ... | |
}
|
||
|
||
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
static int cpt=0;
|
||
cpt++;
|
||
position p;
|
||
|
||
if (trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
printf ("> %s\n",trame);
|
||
}
|
||
}
|
||
{
|
||
printf ("%s\n",trame);
|
||
decode_trame(trame,&p);
|
||
printf("latitude= %f , longitude= %f \n",p.latitude,p.longitude);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
... | ... | |
|
||
position p,p1,p2;
|
||
|
||
typedef struct {
|
||
position pos;
|
||
float vitesse;
|
||
}zone;
|
||
|
||
zone zones[]= {
|
||
{{44.788776, -3.01200}, 50},
|
||
{{44.789122, -3.01300}, 70},
|
||
{{45.896654, 3.224569}, 60},
|
||
{{46.251478, 4.000000}, 80},
|
||
{{47.353711, 5.199235}, 90},
|
||
};
|
||
|
||
//Fonction decode_tram v1 pas s?r
|
||
|
||
/*int decode_trame_v1(char *trame, position p)
|
||
{
|
||
int i;
|
||
if (trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
p.latitude=latitude(trame);
|
||
p.longitude=longitude(trame);
|
||
i=1;
|
||
}
|
||
else
|
||
{
|
||
i=0;
|
||
}
|
||
return i;
|
||
}*/
|
||
|
||
//Fonction decode_tram v2
|
||
|
||
int decode_trame_v2(char *l, position *p)
|
||
{
|
||
float degree_latitue=0,minutes_latitude,res_latitude,degree_longitude=0,minutes_longitute=0,res_longitude=0;
|
||
int degree_latitude,minutes_latitude=0,degree_longitude,minutes_longitude=0;
|
||
double res_latitude=0,res_longitude=0;
|
||
|
||
|
||
degree_longitude=decode_int(l[29])*100+decode_int(l[30])*10+decode_int(l[31]);
|
||
minutes_longitute=(decode_int(l[32])*10+decode_int(l[33])+decode_int(l[35])*0.1+decode_int(l[36])*0.01+decode_int(l[37])*0.001+decode_int(l[38])*0.0001)/60;
|
||
res_longitude=degree_longitude+minutes_longitute;
|
||
minutes_longitude=(decode_int(l[32])*10+decode_int(l[33])+decode_int(l[35])*0.1+decode_int(l[36])*0.01+decode_int(l[37])*0.001+decode_int(l[38])*0.0001)/60;
|
||
res_longitude=degree_longitude+minutes_longitude;
|
||
|
||
degree_latitue=decode_int(l[17])*10+decode_int(l[18]);
|
||
if(l[27]=='S') //identifier si la latitude est nord ou sud
|
||
{
|
||
res_latitude = -res_latitude;
|
||
}
|
||
degree_latitude=decode_int(l[17])*10+decode_int(l[18]);
|
||
minutes_latitude=(decode_int(l[19])*10+decode_int(l[20])+decode_int(l[22])*0.1+decode_int(l[23])*0.01+decode_int(l[24])*0.001+decode_int(l[25])*0.0001)/60;
|
||
res_latitude=degree_latitue+minutes_latitude;
|
||
|
||
res_latitude=degree_latitude+minutes_latitude;
|
||
if(l[40]=='W')
|
||
{
|
||
res_longitude= -res_longitude;
|
||
}
|
||
p ->longitude=res_longitude;
|
||
p ->latitude=res_latitude;
|
||
}
|
||
... | ... | |
|
||
/*void test_decode_tram (void)
|
||
{
|
||
decode_trame_v2("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p1);
|
||
if (p1.longitude-3.11006 < 0.000001 && 3.11006-p1.longitude< 0.000001)
|
||
decode_trame_v2("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p);
|
||
if(fabs(fabs(p.latitude)-46.759373 >10-6))
|
||
{
|
||
printf("Erreur test longitude");
|
||
printf ("Erreur test latitude decode_trame_v2");
|
||
exit(-1);
|
||
}
|
||
if(fabs(fabs(p.longitude)-101.202358 >10-6))
|
||
{
|
||
printf ("Erreur test longitude decode_trame_v2");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
*/
|
||
|
||
//Fonction calcul_distance
|
||
|
||
/*float clacul_distance(position *p1, position *p2)
|
||
float clacul_distance(position *p1, position *p2)
|
||
{
|
||
float distance;
|
||
distance=(2*3.14*6370/360)*(((p2.latitude-p1.latitude)*(p2.latitude-p1.latitude)+(p2.longitude-p1.longitude)*(p2.longitude-p1*longitude))**(1/2));
|
||
return distance;
|
||
distance=acos(sin(PI * p1 ->latitude/180.0)*sin(PI * p2 ->latitude/180.0)+cos(PI* p1 ->latitude/180.0)*cos(PI* p2 ->latitude/180.0)*cos(PI*(fabs(p1 ->longitude - p2 ->longitude))/180.0))*6371;
|
||
return (float) distance;
|
||
}
|
||
|
||
//Fonction calcul_vitesse
|
||
... | ... | |
{
|
||
float vitesse;
|
||
|
||
vitesse=calcul_distance(p1,p2);
|
||
vitesse=vitesse/3600;
|
||
vitesse=calcul_distance(&p1,&p2);
|
||
vitesse=vitesse*3600;
|
||
|
||
return vitesse;
|
||
}
|
||
|
||
//Test calcul_vitesse
|
||
/*Test calcul_vitesse
|
||
|
||
float test_calcul_vitesse()
|
||
{
|
||
... | ... | |
}*/
|
||
|
||
|
||
/* distance ? la proche zone */
|
||
|
||
int distance_a_la_proche_zone(position p, zone r[],int nb_zones, float *d)
|
||
{
|
||
int i=0,dist_zone,res;
|
||
dist_zone=calcul_distance(&p,&r[0].pos);
|
||
for(i=0;i<nb_zones;i++)
|
||
{
|
||
*d=calcul_distance(&p,&r[i].pos);
|
||
printf("\n%f\n",*d);
|
||
if(-*d<dist_zone<*d)
|
||
{
|
||
dist_zone=*d;
|
||
res=i;
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
|
||
position p2,p1,p;
|
||
position p,p1,p2;
|
||
p1.latitude=35.968723;
|
||
p1.longitude=170.652056;
|
||
p2.longitude=156.831330;
|
||
p2.latitude=55.806160;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
|
||
position p2;
|
||
|
||
|
||
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");
|
||
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);
|
||
... | ... | |
exit(-1);
|
||
}
|
||
|
||
/* test longitude */
|
||
|
||
if (longitude("13558.8889")-135,981481<0.000001 && 135,981481-longitude("13558.8889")<0.000001)
|
||
{
|
||
printf("Erreur test longitude1");
|
||
exit(-1);
|
||
}
|
||
|
||
if (longitude("10112.1415")-101,202358<0.000001 && 101,202358-longitude("10112.1415")<0.000001)
|
||
{
|
||
printf ("Erreur test longitude2");
|
||
exit(-1);
|
||
}
|
||
/* test latitude */
|
||
|
||
if (latitude("3723.2475")-37.387458<0.000001 && 37.387458-latitude("3723.2475")<0.000001)
|
||
if (latitude("3558.8889")-35,981481>0.000001 && 35,981481-latitude("3558.8889")<0.000001)
|
||
{
|
||
printf("Erreur test latitude");
|
||
printf ("Erreur test latitude1");
|
||
exit(-1);
|
||
}
|
||
/* test longitude */
|
||
if (longitude("00306.6036")-37.387458<0.000001 && 37.387458-latitude("00306.6036")<0.000001)
|
||
if (latitude("0112.1415")-01,202358>0.000001 && 01,202358-latitude("0112.1415")<0.000001)
|
||
{
|
||
printf("Erreur test latitude");
|
||
printf ("Erreur test latitude2");
|
||
exit(-1);
|
||
}
|
||
|
||
... | ... | |
exit(-1);
|
||
}
|
||
|
||
/*Test decode tram latitude */
|
||
|
||
decode_trame_v2("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p);
|
||
if(fabs(fabs(p.latitude)-46.759373 >10-6))
|
||
{
|
||
printf ("Erreur test latitude decode_trame_v2");
|
||
exit(-1);
|
||
}
|
||
|
||
|
||
|
||
/*Test decode tram longitude */
|
||
|
||
/*decode_trame_v2("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p1);
|
||
if (p1.longitude-3.11006 < 0.000001 && 3.11006-p1.longitude< 0.000001)
|
||
|
||
decode_trame("$GPGGA,141914.00,4645.5624,N,10112.1415,E,1,05,3.4,499.3,M,,M,,*7D",&p);
|
||
if(fabs(fabs(p.longitude)-101.202358 >10-6))
|
||
{
|
||
printf("Erreur test longitude");
|
||
printf ("Erreur test longitude decode_trame_v2");
|
||
exit(-1);
|
||
}*/
|
||
decode_trame_v2("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p2);
|
||
/*if (p2.latitude-45.75 < 0.000001 && 45.75 -p2.latitude< 0.000001)
|
||
}
|
||
|
||
|
||
/* test calcul_distance */
|
||
|
||
|
||
if(calcul_distance(&p1,&p2)<2441 && calcul_distance(&p1,&p2)>2442)
|
||
{
|
||
printf("Erreur test latitude");
|
||
printf (" Erreur test calcul distance");
|
||
exit(-1);
|
||
}*/
|
||
printf("%f",p2.latitude);
|
||
}
|
||
}
|
||
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
tests_unitaires();
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
int i=0;
|
||
while (trames[i])
|
||
traitement(trames[i++]);
|
||
|
||
if (!trame_init())
|
||
exit(-1);
|
||
// Affichage des trames du fichier gps.log
|
||
char *trame;
|
||
printf ("Trames de tests du fichier gps.log\n");
|
||
while ((trame = trame_suivante()))
|
||
traitement(trame);
|
||
|
||
return 0;
|
||
}
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
tests_unitaires();
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
int i=0;
|
||
while (trames[i])
|
||
traitement(trames[i++]);
|
||
|
||
if (!trame_init())
|
||
exit(-1);
|
||
// Affichage des trames du fichier gps.log
|
||
char *trame;
|
||
printf ("Trames de tests du fichier gps.log\n");
|
||
while ((trame = trame_suivante()))
|
||
traitement(trame);
|
||
|
||
return 0;
|
||
}
|
Formats disponibles : Unified diff
erreurs precedente corriges + test ok
fonction distance proche zone ok