Révision 372
Ajouté par beclement2 il y a presque 4 ans
branch/CLEMENT/sp4a12/main.c | ||
---|---|---|
|
||
// On D?finit la structure position
|
||
|
||
struct position{
|
||
typedef struct{
|
||
float latitude;
|
||
float longitude;
|
||
};
|
||
}position;
|
||
|
||
typedef struct{
|
||
position rpos;
|
||
float vitmax;
|
||
}zone;
|
||
|
||
int trame_cmp(char* trame,char* type){
|
||
|
||
int i=0; //Initialisation des variables
|
||
... | ... | |
|
||
return verif; //On retourne, 1 c'est valid?, 0 c'est pas valid?.
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
static int cpt=0 ;
|
||
|
||
if ((trame_cmp(trame, "GPGGA")) == 1){
|
||
printf("> %s\n",trame);
|
||
}
|
||
cpt++ ;
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
int decode_int(char c){ /* Fonction permettant de transformer un code ASCII en d?cimale */
|
||
... | ... | |
}
|
||
|
||
|
||
struct position decode_tram(char * trame){
|
||
position decode_trame(char * trame){
|
||
|
||
|
||
if (trame_cmp(trame, "GPGGA")!= 1){
|
||
... | ... | |
else{
|
||
//On d?finit notre structure
|
||
|
||
struct position position_trame;
|
||
position position_trame;
|
||
char latitude[10];
|
||
char longitude[11];
|
||
int n = 0;
|
||
... | ... | |
int j = 0;
|
||
int k = 0;
|
||
|
||
while (trame[i] != '\0' && n <= 4){
|
||
while (trame[i] != '\0'){
|
||
if (trame[i] == ','){ //On rep?re les virgules
|
||
n = n + 1;
|
||
i = i + 1;
|
||
... | ... | |
}
|
||
}
|
||
|
||
float calcule_distance(position position_trame1, position position_trame2){
|
||
|
||
//On doit d'abord calcule la distance :
|
||
|
||
float x = (position_trame2.longitude - position_trame1.longitude) * cos( (position_trame1.latitude + position_trame2.latitude) / 2);
|
||
float y = position_trame2.latitude - position_trame1.latitude;
|
||
float z = sqrt(x*x + y*y);
|
||
float k = 1.852 * 60;
|
||
float d = k * z;
|
||
return d;
|
||
}
|
||
|
||
float calcule_vitesse(position position_trame1, position position_trame2){
|
||
|
||
// On doit calculer la distance :
|
||
float d;
|
||
d = calcule_distance(position_trame1, position_trame2);
|
||
//On a la distance, on calcule la vitesse;
|
||
float v = d * 3600;
|
||
return v;
|
||
}
|
||
|
||
float p;
|
||
float * d = &p;
|
||
|
||
|
||
|
||
int distance_a_la_plus_proche_zone(position p, zone r[], int nb_zones, float *d){
|
||
|
||
int i = 1;
|
||
*d = calcule_distance(p, r[0].rpos); //On initialise par d?faut que la premi?re zone est la plus proche
|
||
float temp_d;
|
||
while (i < nb_zones){
|
||
temp_d = calcule_distance(p, r[i].rpos);
|
||
if (temp_d < *d){
|
||
*d = temp_d;
|
||
}
|
||
i++;
|
||
}
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
position affichage;
|
||
static int cpt=0 ;
|
||
|
||
if ((trame_cmp(trame, "GPGGA")) == 1){
|
||
printf("> %s\n",trame);
|
||
affichage = decode_trame(trame);
|
||
printf("Latitude : %f \nLongitude %f\n\n", affichage.latitude, affichage.longitude);
|
||
|
||
}
|
||
cpt++ ;
|
||
|
||
|
||
}
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
... | ... | |
exit(-1);
|
||
}
|
||
|
||
if (fabs(conv_lat("3723.2475")-37.387458)>= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
if ((conv_lat("3723.2475")-37.387458)>= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
printf ("Erreur Test unitaire conv_lat.\n");
|
||
exit(-1);
|
||
}
|
||
if (fabs(conversion("00306.6036")-3.11006)>= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
if ((conversion("00306.6036")-3.11006)>= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
printf ("Erreur Test unitaire conversion.\n");
|
||
exit(-1);
|
||
}
|
||
if (fabs(conversion("3723.2475")-37.387458)>= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
if ((conversion("3723.2475")-37.387458) >= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
printf ("Erreur Test unitaire conversion.\n");
|
||
exit(-1);
|
||
}
|
||
... | ... | |
// On va passer au test unitaire de notre fonction decode_tram :
|
||
char test1[] = "$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D";
|
||
char test2[] = "$GPGGA,141915.00,4545.0242,N,00306.6039,E,1,05,3.4,499.5,M,,M,,*72";
|
||
struct position test1_1;
|
||
struct position test2_1;
|
||
test1_1 = decode_tram(test1);
|
||
test2_1 = decode_tram(test2);
|
||
position test1_1;
|
||
position test2_1;
|
||
float dtest;
|
||
test1_1 = decode_trame(test1);
|
||
test2_1 = decode_trame(test2);
|
||
|
||
if ((fabs(test1_1.latitude - 45.75) >= pow(10,-6)) && fabs(test1_1.longitude - 003.11006) >= pow(10,-6)){
|
||
|
||
if (((test1_1.latitude - 45.75) >= pow(10,-6)) && (test1_1.longitude - 003.11006) >= pow(10,-6)){
|
||
printf("Erreur Test unitaire decode_tram1.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if ((fabs(test2_1.latitude - 45.750401) >= pow(10,-6)) && fabs(test2_1.longitude - 003.110065) >= pow(10,-6)){
|
||
if (((test2_1.latitude - 45.750401) >= pow(10,-6)) && ((test2_1.longitude - 003.110065) >= pow(10,-6))){
|
||
printf("Erreur Test unitaire decode_tram2.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if ((calcule_distance(test1_1, test2_1) - 0.044508) >= pow(10,-6)){
|
||
printf("Erreur test unitaire distance.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if ((calcule_vitesse(test1_1, test2_1) - 160.2304) >= pow(10,-4)){
|
||
printf("Erreur test unitaire calcul_vitesse\n");
|
||
exit(-1);
|
||
}
|
||
|
||
//On d?finit la zone pour faire un test unitaire
|
||
|
||
zone zones[] = {
|
||
{{44.7887762, -3.012}, 50}, /* Descripteur de la premi?re zone */
|
||
{{44.7891220, -3,013}, 70},
|
||
};
|
||
|
||
distance_a_la_plus_proche_zone(test1_1, zones, 2, d);
|
||
|
||
if ((*d - 217.8 >= pow(10,-1))){
|
||
printf("Erreur test unitaire distance_a_la_plus_proche_zone\n");
|
||
exit(-1);
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
|
||
tests_unitaires();
|
||
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
int i=0;
|
||
while (trames[i])
|
Formats disponibles : Unified diff
fin de distance_a_la_plus_proche_zone