|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <strings.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",
|
|
0};
|
|
|
|
int trame_cmp(char* trame,char* type){
|
|
|
|
int i=0;
|
|
int verif = 1;
|
|
int j;
|
|
|
|
while(type[i]!=NULL){
|
|
i++;
|
|
}
|
|
|
|
for(j=0; j<i; j++){
|
|
if (trame[j+1] != type[j]){
|
|
verif = 0;
|
|
}
|
|
|
|
}
|
|
|
|
return verif;
|
|
}
|
|
|
|
|
|
|
|
int decode_int(char c){
|
|
int i;
|
|
if(c>='0' && c<='9')
|
|
{
|
|
i=c-48;
|
|
}
|
|
else
|
|
i=-1;
|
|
return i;
|
|
}
|
|
|
|
|
|
int decode_nombre(char * ch, int n) // fonction qui recupere les n premiers chiffres d'une chaine
|
|
{
|
|
int i;
|
|
int somme=0;
|
|
for (i=0;i<n;i++)
|
|
{
|
|
somme=(somme*10) + decode_int(ch[i]);
|
|
}
|
|
return somme;
|
|
|
|
|
|
}
|
|
|
|
float conversion_latitude(char * lat) // fonction qui convertie une latitude 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]=lat[2+i];
|
|
for (i=0;i<4; i++) min[i]=lat[5+i];
|
|
result_convers=decode_nombre(lat,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;
|
|
}
|
|
|
|
float conversion_longitude(char * lon) // fonction qui convertie une longitude en nombre flottant
|
|
{
|
|
float result_convers,val_deci;
|
|
int val_ent_dec,val_ent_minut;
|
|
result_convers=decode_nombre(lon,3);// recuperation de la partie entiere
|
|
val_ent_minut=decode_nombre(&lon[3],2);
|
|
val_ent_dec=decode_nombre(&lon[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;
|
|
}
|
|
|
|
/*Fonction ? modifier !!!!!*/
|
|
void traitement(char * trame)
|
|
{
|
|
static int cpt=0;
|
|
cpt++;
|
|
if(trame_cmp(trame,"GPGGA"))
|
|
{
|
|
printf ("> %s\n",trame);
|
|
}
|
|
|
|
}
|
|
|
|
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('2')!=2)
|
|
{
|
|
printf("Erreur test unitaire decode int\n");
|
|
exit(-1);
|
|
}
|
|
|
|
}
|
|
|
|
/*Ajouter vos tests unitaires dans cette fonction.*/
|
|
void tests_unitaires(void){
|
|
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);
|
|
}
|
|
if (trame_cmp("$GPRMC... ", "GPRMC" )!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
|
printf ("Erreur Test unitaire trame_cmp.\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_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);
|
|
}
|
|
}
|
|
|
|
/* Ne pas modifier cette fonction*/
|
|
int main(int argc,char ** argv)
|
|
{
|
|
|
|
/*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;
|
|
}
|