Révision 579
Ajouté par abseck1 il y a presque 4 ans
main.c | ||
---|---|---|
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
#include <math.h>
|
||
|
||
typedef struct
|
||
{
|
||
... | ... | |
float vitmax;
|
||
} Zone;
|
||
|
||
Zone zones[] = {
|
||
{{44.7887762, -3.012}, 50}, /* Descripteur de la premi?re zone */
|
||
{{44.7891220, -3,013}, 70},
|
||
...
|
||
}
|
||
|
||
#define Rayon 6378.1370
|
||
//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",
|
||
... | ... | |
Zone zones[] = {
|
||
{{44.7887762, -3.012}, 50}, /* Descripteur de la premi?re zone */
|
||
{{44.7891220, -3,013}, 70},
|
||
...
|
||
};
|
||
{{46.7501,3.1101}, 50}
|
||
};
|
||
|
||
|
||
position test_position;
|
||
position pos1;
|
||
position pos2;
|
||
|
||
int trame_cmp(char* a,char* b){
|
||
if (!strncmp(trame+1,type,strlen(type)))
|
||
return 1;
|
||
int trame_cmp(char * trame, char * type) // declaration de la fonction de comparaison de deux chaines
|
||
{
|
||
if (!strncmp(trame+1,type,strlen(type)))
|
||
return 1;
|
||
return 0;
|
||
int i;
|
||
for (i=0; i<strlen(type); i++)https://forge.clermont-universite.fr/svn/polytech-ge-sp4abc-2021
|
||
|
||
|
||
int i;
|
||
for (i=0; i<strlen(type); i++) // parcours de la longueur du type
|
||
{
|
||
if (trame[i+1] != type[i])
|
||
return 0;
|
||
if (trame[i+1] != type[i]) // inegalit? entre les caracteres
|
||
return 0; // renvoie 0
|
||
}
|
||
return 1;
|
||
return 1; // renvoie 1
|
||
|
||
|
||
}
|
||
|
||
int decode_int(char c) // declaration de la fonction qui renvoie le nombre associ? au caractere
|
||
{
|
||
c=c-'0';
|
||
return c;
|
||
}
|
||
|
||
int decode_nombre(char * ch, int n)
|
||
{
|
||
... | ... | |
somme=(somme*10) + decode_int(ch[i]);
|
||
}
|
||
return somme;
|
||
https://forge.clermont-universite.fr/svn/polytech-ge-sp4abc-2021
|
||
}float conversion_longitude(char * longi)
|
||
/*https://forge.clermont-universite.fr/svn/polytech-ge-sp4abc-2021*/
|
||
|
||
}
|
||
|
||
float conversion_longitude(char * longi)
|
||
{
|
||
float result_convers,val_deci;
|
||
int val_ent_dec,val_ent_minut;
|
||
result_convers=decode_nombre(longi,3);// recuperation de la partie entiere
|
||
val_ent_minut=decode_nombre(&longi[3],2);
|
||
val_ent_dec=decode_nombre(&longi[6],4);
|
||
val_deci=(val_ent_minut+(0.0001*val_ent_dec))/60; // recuperation de la valeur decimale en degr?
|
||
result_convers=result_convers+val_deci;
|
||
return result_convers;
|
||
|
||
}
|
||
|
||
float conversion_latitude(char * lati) // fonction qui convertie une longitude en nombre flottant
|
||
{
|
||
// 3723.2475 equivalent a 37 degr? 23.2475 / 60 degr?
|
||
float result_convers,val_deci;
|
||
int val_ent_dec,val_ent_minut;
|
||
char minute[7];
|
||
char min[4];
|
||
int i;
|
||
for (i=0;i<7; i++) minute[i]=lati[2+i];
|
||
for (i=0;i<4; i++) min[i]=lati[5+i];
|
||
result_convers=decode_nombre(lati,2);// recuperation de la partie entiere 37
|
||
val_ent_minut=decode_nombre(minute,2); // 23
|
||
val_ent_dec=decode_nombre(min,4); // 2475
|
||
val_deci=(val_ent_minut+(val_ent_dec*0.0001))*0.0166667; // recuperation de la valeur decimale en degr?
|
||
result_convers+=val_deci;
|
||
return result_convers;
|
||
}
|
||
|
||
|
||
int decode_trame (char * trame, position * pos)
|
||
{
|
||
int i;
|
||
char ch[10]
|
||
if(trame_cmp(char * trame, position * pos))
|
||
char ch[10];
|
||
if (trame_cmp(trame,"GPGGA"))
|
||
{
|
||
for (i=0; i<10; i++) ch[i]=trame[]
|
||
pos->latitude= conversion_latitude(trame)
|
||
pos->longitude=conversion_longitude(ch)
|
||
for (i=0; i<10; i++) ch[i]=trame[29+i];
|
||
pos->latitude= conversion_latitude(trame);
|
||
pos->longitude=conversion_longitude(ch);
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
float conver_radian(float x) // fonction qui convertit un nombre flottant en flottaant
|
||
{
|
||
return (x*M_PI)/180;
|
||
}
|
||
|
||
float calcul_distance(position pos1,position pos2) // fonction qui calcule la distance entre deux positions
|
||
{
|
||
float result= (40000/360) * sqrt(((pos2.latitude - pos1.latitude)*(pos2.latitude - pos1.latitude))+((pos2.longitude - pos1.longitude)*(pos2.longitude - pos1.longitude))) ;
|
||
return result;
|
||
|
||
}
|
||
|
||
float calcul_vitesse(position pos1,position pos2) // fonction qui calcule la distance entre deux positions
|
||
{
|
||
float vitesse;
|
||
vitesse=3600*(calcul_distance(pos1,pos2)*Rayon);
|
||
return vitesse;
|
||
}
|
||
|
||
int distance_a_la_plus_proche_zone(position p,zone r[],int nb_zones,float *d) // fonction qui calcule la distance la plus proche
|
||
{
|
||
int index=0;
|
||
int i;
|
||
*d=fabs(calcul_distance(p,r[0].rpos)); // initialisation du minimum
|
||
float t;
|
||
if (nb_zones>0)
|
||
{
|
||
for (i=1;i<nb_zones;i++)
|
||
{
|
||
t=fabs(calcul_distance(p,r[i].rpos));
|
||
if (t<*d)
|
||
{
|
||
*d=t;
|
||
index=i;
|
||
}
|
||
}
|
||
return index;
|
||
}
|
||
return -1;
|
||
}
|
||
void test_distance_plus_proche(void) //
|
||
{
|
||
position p;
|
||
p.latitude =45.75;
|
||
p.longitude=3.110060;
|
||
int num_zone;
|
||
float d ;
|
||
num_zone=distance_a_la_plus_proche_zone(p,zones,sizeof(zones),&d);
|
||
|
||
if (num_zone!=2 & fabs(d-44.85)>0.5)
|
||
{
|
||
printf(("erreur test distance la plus proche "));
|
||
exit(-1);
|
||
}
|
||
}
|
||
float fonction_generique(char* ch) // fonction qui convertit la latitudes ou la longitude en flottant
|
||
{
|
||
float result_convers;
|
||
if(ch[4]=='.')
|
||
{
|
||
result_convers=conversion_latitude(ch);
|
||
}
|
||
else if(ch[5]=='.')
|
||
{
|
||
result_convers=conversion_longitude(ch);
|
||
}
|
||
|
||
return result_convers;
|
||
}
|
||
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
... | ... | |
static int cpt=0;
|
||
cpt++;
|
||
if(trame_cmp(trame,"GPGGA"))
|
||
printf ("> %s\n",trame);
|
||
}
|
||
printf ("> %s\n",trame);
|
||
position p;
|
||
position p_init;
|
||
p_init.latitude=45.750000;
|
||
p_init.longitude= 3.110060;
|
||
float distance;
|
||
float vitesse;
|
||
float seuil=1000;
|
||
int index;
|
||
if (decode_trame(trame,&p))
|
||
{
|
||
printf ("> %s\n",trame);
|
||
printf("la latitude est %f \n la longitude est %f \n ",p.latitude,p.longitude);
|
||
vitesse=calcul_vitesse(p_init,p);
|
||
index=distance_a_la_plus_proche_zone(p,zones,sizeof(zones),&distance);
|
||
if ((distance<seuil) && (vitesse>zones[index].vitmax))
|
||
{
|
||
printf(" alarme on \n");
|
||
printf(" zone numero %d \n ",index);
|
||
|
||
printf("la vitesse est %f\n ",vitesse);
|
||
printf("la distance est %f \n ",distance);
|
||
}
|
||
else
|
||
printf("Alarme off \n ");
|
||
p_init = p;
|
||
}
|
||
}
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
|
||
void test_decode_trame(void)
|
||
{
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&test_position)!=1)
|
||
{
|
||
printf("Erreur Test decode trame \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
void test_decode_int(void)
|
||
{
|
||
if (decode_int('0')!=0)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('1')!=1)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('2')!=2)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('3')!=3)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('4')!=4)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('5')!=5)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_decode_nombre(void)
|
||
{
|
||
if (decode_nombre("7541",1)!=7)
|
||
{
|
||
printf("Erreur test unitaire decode nombre\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("7541",2)!=75)
|
||
{
|
||
printf("Erreur test unitaire decode nombre\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("7541",3)!=754)
|
||
{
|
||
printf("Erreur test unitaire decode nombre\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
void test_fonction_generique(void)
|
||
{
|
||
if (fonction_generique("3223.2475") - 37.387459 > 0.0001 )
|
||
{
|
||
printf("Erreur test latitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
if (fonction_generique("00306.6036")-3.110060 > 0.0001)
|
||
{
|
||
printf("Erreur test longitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_latitude(void)
|
||
{
|
||
if (conversion_latitude("3223.2475,N") - 37.387459 > 0.0001 )
|
||
{
|
||
printf("Erreur test latitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_longitude(void)
|
||
{
|
||
if (conversion_longitude("00306.6036,E")-3.110060 > 0.0001)
|
||
{
|
||
printf("Erreur test longitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
... | ... | |
int main(int argc,char ** argv)
|
||
{
|
||
|
||
tests_unitaires();
|
||
tests_unitaires();
|
||
int trame_valide;
|
||
tests_unitaires();
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
test_latitude();
|
||
test_longitude();
|
||
test_fonction_generique();
|
||
test_decode_trame();
|
||
test_distance_plus_proche();
|
||
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
int i=0;
|
Formats disponibles : Unified diff
implantation des fonctions SPa12 suite