Révision 377
Ajouté par Lilian MEMBRE il y a presque 3 ans
main.c | ||
---|---|---|
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include <strings.h>
|
||
#include <math.h>
|
||
#include "trame.h"
|
||
|
||
//Trames de tests ? modifier si n?cessaire.
|
||
... | ... | |
printf ("> %s\n",trame);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/* TP SP4A N?2 */
|
||
|
||
typedef struct{
|
||
|
||
float latitude;
|
||
float longitude;
|
||
} position;
|
||
|
||
|
||
position p,p1,p2;
|
||
|
||
|
||
|
||
//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;
|
||
|
||
|
||
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;
|
||
|
||
degree_latitue=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;
|
||
|
||
p ->longitude=res_longitude;
|
||
p ->latitude=res_latitude;
|
||
}
|
||
|
||
//Test decode_trame
|
||
|
||
/*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)
|
||
{
|
||
printf("Erreur test longitude");
|
||
exit(-1);
|
||
}
|
||
}
|
||
*/
|
||
|
||
//Fonction calcul_distance
|
||
|
||
/*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;
|
||
}
|
||
|
||
//Fonction calcul_vitesse
|
||
|
||
float clacul_vitesse(position *p1, position *p2)
|
||
{
|
||
float vitesse;
|
||
|
||
vitesse=calcul_distance(p1,p2);
|
||
vitesse=vitesse/3600;
|
||
|
||
return vitesse;
|
||
}
|
||
|
||
//Test calcul_vitesse
|
||
|
||
float test_calcul_vitesse()
|
||
{
|
||
position p1,p2;
|
||
float v;
|
||
decode_tram_v1("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D", &p1);
|
||
decode_tram_v1("$GPGGA,141915.00,4545.0242,N,00306.6039,E,1,05,3.4,499.5,M,,M,,*72", &p2);
|
||
|
||
v=calcul_vitesse(p1,p2);
|
||
}*/
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
void tests_unitaires(void){
|
||
|
||
position p2;
|
||
|
||
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
... | ... | |
if (e*e > 0.000001){
|
||
printf("erreur2");
|
||
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)
|
||
{
|
||
printf("Erreur test longitude");
|
||
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)
|
||
{
|
||
printf("Erreur test latitude");
|
||
exit(-1);
|
||
}*/
|
||
printf("%f",p2.latitude);
|
||
}
|
||
|
||
|
Formats disponibles : Unified diff
decode tram ok, encore des bugs dans les test. calcul vitesse et distance fait à tester