Révision 501
Ajouté par Orlani RIVERA il y a presque 3 ans
main.c | ||
---|---|---|
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
#include "trame.h"
|
||
#include <math.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",
|
||
... | ... | |
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
0};
|
||
|
||
|
||
typedef struct
|
||
{
|
||
float latitude;
|
||
float longitude;
|
||
}position
|
||
position p1;
|
||
position p2;
|
||
}position;
|
||
|
||
typedef struct {
|
||
Position rpos;
|
||
float vitmax;
|
||
typedef struct
|
||
{
|
||
position repos;
|
||
float vmax;
|
||
}Zone;
|
||
|
||
Zone zones[]={
|
||
... | ... | |
{{46.7350220, -3.023}, 90},
|
||
};
|
||
|
||
int trame_cmp(char* trame, char* type)
|
||
int trame_cmp(char* trame, char* type) /* fonction qui renvoie 1 si la trame commence par la cha?ne de caract?re type et z?ro sinon */
|
||
{
|
||
int i, ok = 1;
|
||
for(i = 0; i < 5; i++)
|
||
{
|
||
if(trame[i+1] != type[i])
|
||
if(trame[i+1] != type[i]) /* La trame commence ? partir du 2eme terme */
|
||
{
|
||
ok = 0;
|
||
}
|
||
|
||
if(ok = 1)
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
int decode_nombre(char *ch, int n)
|
||
int decode_nombre(char *ch, int n) /*fonction qui renvoie la valeur d?cimale des n premiers caract?res de la cha?ne ch */
|
||
{
|
||
int i, s=0;
|
||
for(i=0; i<n;i++)
|
||
int i, s = 0;
|
||
for(i = 0; i < n; i++)
|
||
{
|
||
s= (s*10) + decode_int(ch[i]);
|
||
s = (s*10) + decode_int(ch[i]);
|
||
}
|
||
return s;
|
||
}
|
||
|
||
|
||
int decode_int(char c)
|
||
int decode_int(char c) /* qui renvoie la valeur d?cimale associ?e ? un caract?re donn? en param?tre */
|
||
{
|
||
int decode;
|
||
if((c<'9')&&(c>='0'))
|
||
{
|
||
decode = c - 48;
|
||
decode = c - 48; /* Soustraction de 48 au code ascii */
|
||
}
|
||
else
|
||
{
|
||
decode = -1;
|
||
decode = -1; /* renvoie -1 si le caract?re rentr? n'est pas un chiffre*/
|
||
}
|
||
return decode;
|
||
}
|
||
... | ... | |
float resultat;
|
||
int degre, minute, dec_minute;
|
||
degre = decode_nombre (&ch[0], 2);
|
||
minute = decode_nombre (&ch[2], 2);
|
||
minute = decode_nombre (&ch[2], 2); /* Recuperation de la partie entiere correspondant aux degrees, minutes */
|
||
minute = minute/60;
|
||
dec_minute = decode_nombre (&ch[5], 4);
|
||
dec_minute = dec_minute/600000;
|
||
... | ... | |
}
|
||
}
|
||
return a;
|
||
}
|
||
}*/
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
static int cpt=0;
|
||
cpt = cpt++ ;
|
||
printf ("> %s\n",trame);
|
||
/* printf ("> %s\n",trame);*/
|
||
|
||
/* if trame_cmp(trame, "GPGGA") ==1)
|
||
/* if (trame_cmp(trame, "GPGGA") == 1)
|
||
{
|
||
printf ("> %s\n",trame);
|
||
}*/
|
||
... | ... | |
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
|
||
void tests_unitaires(void){
|
||
void tests_unitaires(void)
|
||
{
|
||
|
||
if (5!=5){
|
||
if (5!=5)
|
||
{
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
/* Tests trame */
|
||
/*
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=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){
|
||
if (trame_cmp("$GPRMC suite chaine", "GPGGA")!=0)
|
||
{
|
||
printf("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC...", "GPRMC")!=1){
|
||
if (trame_cmp("$GPRMC...", "GPRMC")!=1)
|
||
{
|
||
printf("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
||
if (trame_cmp("$APRMC...", "GPGGA")!=0)
|
||
{
|
||
printf("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
/* Test decode_int */
|
||
/*
|
||
if (decode_int('5')!=5){
|
||
|
||
/* Tests decode_int */
|
||
|
||
if (decode_int('5')!=5)
|
||
{
|
||
printf("Erreur Test unitaire decode_int.\n");
|
||
exit(-1);
|
||
if (decode_int('A') != -1){
|
||
}
|
||
if (decode_int('A') != -1)
|
||
{
|
||
printf("Erreur Test unitaire decode_int.\n");
|
||
exit(-1);
|
||
}
|
||
*/
|
||
/* Test decode_nombre */
|
||
/*
|
||
if (decode_nombre(7541,2) != 75){
|
||
/* Tests decode_nombre */
|
||
|
||
if (decode_nombre(7541,2) != 75)
|
||
{
|
||
printf("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre(987654321,2) != 98){
|
||
if (decode_nombre(987654321,2) != 98)
|
||
{
|
||
printf("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
... | ... | |
printf("Erreur Test unitaire conversion-longitude.\n");
|
||
exit(-1);
|
||
}
|
||
*/
|
||
if ((lat_long("4545.0242")-45.75)>0.01)
|
||
{
|
||
printf("Erreur Test unitaire 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",&p1)!=1)
|
||
{
|
||
printf("valeur de retour differente de 1 ");
|
||
if(decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&p1)!=0)
|
||
{
|
||
printf("Erreur test unitaire trame \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++]);
|
||
printf ("> %s\n",trame);
|
||
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;
|
||
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;
|
||
}
|
||
|
Formats disponibles : Unified diff
identation et ajout de commentaires.