|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.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};
|
|
|
|
typedef struct // declaration du type position compos? de la latitude et la longitude
|
|
{
|
|
float latitude;
|
|
float longitude;
|
|
|
|
} position;
|
|
|
|
position test_pos;
|
|
//Fonction ? modifier !!!!!
|
|
void traitement(char * trame)
|
|
{
|
|
static int cpt=0;
|
|
cpt++;
|
|
if (trame_cmp(trame,"$GPGGA"))
|
|
printf ("> %s\n",trames);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int trame_cmp(char*trame, char*type)
|
|
{
|
|
int i=1;
|
|
int verif=1;// variable booleen pour tester l'arriv?e ? la fin du type
|
|
while((verif==1) && (type[i-1] != '\0')) // test tant qu'on est pas arriv?e au bout du type
|
|
{
|
|
if (trame[i]!=type[i-1]) // comparaison de chaque caract?re du trame avec chaque carat?re du type
|
|
{
|
|
verif=0; // si trame est diff?rent du type la variable booleenne passe ? 0
|
|
}
|
|
i++;
|
|
}
|
|
return verif;
|
|
}
|
|
|
|
int decode_int(char c) // declaration de la fonction qui renvoie le nombre associ? au caractere
|
|
{
|
|
int i=0;
|
|
i=c-'0'; // calcule du nombre
|
|
return i;
|
|
}
|
|
|
|
|
|
int decode_nombre(char * ch, int n) // fonction qui recupere les n premiers chiffres d'une chaine
|
|
{
|
|
int i; // pour parcourir les caract?res
|
|
int somme=0 ;// contient char* chain et le nombre d?cod?
|
|
for (i=0;i<n;i++)
|
|
{
|
|
somme=(somme*10) + decode_int(ch[i]);
|
|
}
|
|
return somme;
|
|
|
|
}
|
|
|
|
|
|
float convers_latitude( char *lat )/* fonction qui convertie une longitude en nombre flottant */
|
|
|
|
{
|
|
/*3723.2475,N signifie 37?23,2475' de
|
|
latitude Nord (c.-?-d. 37? et 23,2475 minutes or il ya 60 minutes dans 1?), ou
|
|
encore +37,387458?), en d?cimal*/
|
|
float res_convers=0; // variable contenant le resultat de la conversion
|
|
int i;
|
|
float val_sexa= decode_nombre(lat,4);// on d?code les 4 premiers caract?res en chiffres
|
|
for (i=5;i<9;i++)
|
|
{
|
|
val_sexa+= (decode_int(lat[i]))*pow(10,-i+4);// d?codage de la partie d?cimale
|
|
}
|
|
res_convers=(int)(val_sexa/100);// on recueille les degr?s (exemple 37)
|
|
res_convers= res_convers + (val_sexa - res_convers*100)/60;// conversion des minutes en degr? et ajout ? la somme
|
|
return res_convers;
|
|
|
|
}
|
|
|
|
|
|
|
|
float convers_longitude( char* longi )
|
|
{
|
|
|
|
float res_convers=0; // variable contenant le resultat de la conversion
|
|
int i;
|
|
float val_sexa= decode_nombre(longi,5);// on d?code les 5 premiers caract?res en chiffres
|
|
for (i=6;i<10;i++)
|
|
{
|
|
val_sexa+= (decode_int(longi[i]))*pow(10,-i+4);// d?codage de la partie d?cimale
|
|
}
|
|
res_convers=(int)(val_sexa/1000);// on recueille les degr?s
|
|
res_convers= res_convers + (val_sexa - res_convers*100)/60;// conversion des minutes en degr? et ajout ? la somme
|
|
return res_convers;
|
|
|
|
|
|
|
|
|
|
|
|
float fonction_generique(char* ch) // fonction qui convertit la latitude ou la longitude en nombre flottant
|
|
{
|
|
float res_convers;
|
|
if(ch[4]=='.')
|
|
{
|
|
res_convers=convers_latitude(ch); // conversion en latitude
|
|
}
|
|
else if(ch[5]=='.')
|
|
{
|
|
res_convers=convers_longitude(ch); // conversion en longitude
|
|
}
|
|
|
|
return res_convers;
|
|
|
|
}
|
|
|
|
|
|
|
|
int decode_trame(char* trame,position *pos)// fonction qui valide le bon format de la trame "GPGGA" et extrait la position (la latitude et la longitude en float)
|
|
|
|
{
|
|
char longi[10]; // tableau pour la longitude
|
|
char lati[9]; // tableau pour la latitude
|
|
int cpt = 0; // compteur pour les virgules de la tram
|
|
int i=0;
|
|
int j=0;
|
|
int k=0;
|
|
if( trame_cmp(trame,"GPGGA")==1){
|
|
while( trame[i] != '\0'){ // test du bout de la trame
|
|
if(trame[i] == ','){
|
|
cpt+=1; // comptage du nombre de virgules
|
|
i++;
|
|
}
|
|
if (cpt== 2){
|
|
lati[j] = trame[i];// on extrait la latitude
|
|
j++;
|
|
}
|
|
if (cpt==4){
|
|
longi[k]=trame[i];// on extrait la longitude
|
|
k++;
|
|
}
|
|
i++;
|
|
}
|
|
pos->latitude = convers_latitude(lati); // conversion dans la structure position
|
|
pos->longitude = convers_longitude(longi);
|
|
return 1;
|
|
|
|
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
//Ajouter vos tests unitaires dans cette fonction.
|
|
void tests_unitaires(void) {
|
|
|
|
if (decode_trame("$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C" ,&test_pos)!=0)
|
|
{
|
|
printf("Erreur Test unitaire decode trame \n");
|
|
exit(-1);
|
|
}
|
|
|
|
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&test_pos)!=1)
|
|
{
|
|
printf("Erreur Test unitaire decode trame \n");
|
|
exit(-1);
|
|
}
|
|
|
|
|
|
if (convers_longitude("00306.6036,E")- 3.110060 > 0.0001)
|
|
{
|
|
printf("Erreur test unitaire longitude !!! \n");
|
|
exit(-1);
|
|
}
|
|
|
|
if (convers_latitude("3723.2475,N") - 37.387459 > 0.0001 )
|
|
{
|
|
printf("Erreur test latitude !!! \n");
|
|
exit(-1);
|
|
}
|
|
|
|
/*if (fonction_generique("00306.6036,E")- 3.110060 != 0.000000)
|
|
{
|
|
printf("Erreur test generique !!! \n");
|
|
exit(-1);
|
|
}
|
|
|
|
if (fonction_generique("3723.2475,N") - 37.387459 > 0.0001 )
|
|
{
|
|
printf("Erreur test generique !!! \n");
|
|
exit(-1);
|
|
} */
|
|
|
|
|
|
if ( decode_nombre("3103", 2)!= 31){
|
|
printf("Erreur Test unitaire decode_nombre.\n");
|
|
exit(-1);
|
|
}
|
|
|
|
if ( decode_int('1')!= 1){
|
|
printf("Erreur Test unitaire decode_int.\n");
|
|
exit(-1);
|
|
}
|
|
if (5!=5){
|
|
printf ("Erreur Test unitaire basique.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPGSV suite chaine","GPGSV")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPRMC suite chaine","GPRMC")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPGLL suite chaine","GPGLL")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPGSA suite chaine","GPGSA")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPVTG suite chaine","GPVTG")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
if (trame_cmp("$GPZDA suite chaine","GPZDA")!=1){
|
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
|
exit(-1);
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
}
|