Révision 572
Ajouté par yoguer il y a presque 4 ans
branch/Guer/sp4a12/main.c | ||
---|---|---|
#include "trame.h"
|
||
#include <math.h>
|
||
|
||
|
||
typedef struct position
|
||
{
|
||
long latitude;
|
||
long longitude;
|
||
}position;
|
||
|
||
|
||
//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",
|
||
... | ... | |
0};
|
||
|
||
|
||
int decode_int(char c)
|
||
long decode_long(char c)
|
||
{
|
||
int a=0;
|
||
long a=0;
|
||
|
||
if(c>=48 && c<=57) //v?rifie que le caract?re est entre 0 et 9 compris
|
||
{
|
||
... | ... | |
}
|
||
|
||
|
||
int decode_nombre(char *ch,int n)
|
||
long decode_nombre(char *ch,long n)
|
||
{
|
||
int tab[n],i,retour=0,memoire=0;
|
||
long tab[n],i,retour=0,memoire=0;
|
||
|
||
for(i=0;i<n;i++)
|
||
{
|
||
tab[i]=decode_int(ch[i]);
|
||
tab[i]=decode_long(ch[i]);
|
||
|
||
if(tab[i]!= -1)
|
||
{
|
||
... | ... | |
}
|
||
|
||
|
||
int conversion_sexa(char *latitude_longitude)
|
||
long conversion_sexa(char *latitude_longitude)
|
||
{
|
||
float reste,resultat;
|
||
int resultVF=0;
|
||
//float resultat;
|
||
long resultVF=0,reste;
|
||
|
||
int tram=decode_nombre(latitude_longitude,12);
|
||
long tram=decode_nombre(latitude_longitude,12);
|
||
|
||
/* int degres=(tram/1000000); //on travailler en virgule flottante
|
||
/* long degres=(tram/1000000); //on travailler en virgule flottante
|
||
reste=(tram-(degres*1000000));
|
||
reste=(reste/10000);
|
||
resultat=(degres+(reste/60));*/
|
||
|
||
int degres=(tram/1000000);
|
||
long degres=(tram/1000000);
|
||
reste=(tram-(degres*1000000));
|
||
reste=(reste/10000);
|
||
resultVF=(degres*600000+reste*10000); //on travail en 1/10000('/?)
|
||
//On calcule un K pour passer en rad qui vaut 2.907718*10^-8
|
||
resultVF=(degres*600000+reste); //on travail en 1/10000('/?)
|
||
//On calcule un K pour passer en rad qui vaut 2.907718*10^-8
|
||
|
||
return resultVF;
|
||
}
|
||
|
||
|
||
int trame_cmp(char * trame, char * type)
|
||
long trame_cmp(char * trame, char * type)
|
||
{
|
||
int i=0, validation=0, j=0;
|
||
long i=0, validation=0, j=0;
|
||
|
||
while(type[i]!='\0') //permet de connaitre la taille de la chaine
|
||
{
|
||
... | ... | |
void traitement_trame(char *trame, position *p1)
|
||
{
|
||
char tab_latitude[13],tab_longitude[14];
|
||
int i,j;
|
||
long i,j;
|
||
|
||
for(i=0;i<11;i++)
|
||
{
|
||
... | ... | |
}
|
||
p1->longitude=conversion_sexa(tab_longitude);
|
||
|
||
printf ("> %s\n",trame);
|
||
printf("> %s\n",trame);
|
||
}
|
||
|
||
|
||
int calcul_vitesse(position *p1, position *p2)
|
||
long calcul_vitesse(position *p1, position *p2)
|
||
{
|
||
float distance, vitesse;
|
||
|
||
... | ... | |
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
static int cpt=0;
|
||
static long cpt=0;
|
||
cpt++ ;
|
||
|
||
position p1,p2;
|
||
... | ... | |
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
long main(long argc,char ** argv)
|
||
{
|
||
|
||
tests_unitaires();
|
||
... | ... | |
exit(-1);
|
||
}
|
||
|
||
test_decode_int(); //test la fonction decode_int
|
||
test_decode_long(); //test la fonction decode_long
|
||
test_decode_nombre(); //test la fonction decode_nombre
|
||
test_conversion_latitude_longitude(); //test la fonction conversion_char_latitude
|
||
}
|
||
|
||
|
||
void test_decode_int(void)
|
||
void test_decode_long(void)
|
||
{
|
||
char i;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if (decode_int('0'+i)==i);
|
||
if (decode_long('0'+i)==i);
|
||
{
|
||
printf("GOOD pour le caractere: %hd\n",i); //test si la fonction renvoie bien la bonne valeur d?cimal
|
||
}
|
||
}
|
||
|
||
if(decode_int('A')==-1)
|
||
if(decode_long('A')==-1)
|
||
{
|
||
printf("GOOD pour le caractere A\n\n"); //test si la fonction renvoie -1 pour le caract?re A
|
||
}
|
||
... | ... | |
void test_decode_nombre(void)
|
||
{
|
||
char *ch;
|
||
int n;
|
||
long n;
|
||
|
||
ch="246500";
|
||
n=3;
|
||
... | ... | |
{
|
||
char *trame_latitude_longitude;
|
||
trame_latitude_longitude="35723.2475,W";
|
||
int retour;
|
||
long retour;
|
||
|
||
retour=conversion_sexa(trame_latitude_longitude);
|
||
//printf("retour=%ld",retour);
|
Formats disponibles : Unified diff