Révision 522
Ajouté par jcguifodjo il y a presque 4 ans
main.c | ||
---|---|---|
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
#include "math.h"
|
||
#define k 0.017453292519943
|
||
#define N 200
|
||
|
||
... | ... | |
float latitude;
|
||
float longitude;
|
||
} Position ;
|
||
//Comparaison des trames pour savoir si la trame est du bon type
|
||
int trame_cmp(char* trame,char* type)
|
||
{
|
||
int i=0,d=1;
|
||
... | ... | |
return d;
|
||
|
||
}
|
||
//Conversion d'un caract?re en decimal
|
||
int decode_int(char c)
|
||
{
|
||
int d;
|
||
... | ... | |
}
|
||
return d;
|
||
}
|
||
float decode_angle_lat(float lat )
|
||
//Renvoi la valeur decimal des n premiers caract?res entr?e en param?tre
|
||
int decode_nombre(char *c, int n)
|
||
{
|
||
int entier=lat/100;
|
||
float min=lat%100;
|
||
float deg= entier+(min/60);
|
||
return deg;
|
||
int i,valeur=0;
|
||
for(i=0;i<n;i++){
|
||
valeur+=decode_int(c[i])*pow(10,n-1-i);
|
||
}
|
||
|
||
}
|
||
float decode_angle_lon(float lon )
|
||
//Conversion de la latitude et longitude en degree floatant
|
||
float conversion(char *c)
|
||
{
|
||
int entier=lon/100;
|
||
float min=lon%100;
|
||
float deg= entier+(min/60);
|
||
return deg;
|
||
}
|
||
int decode_trame(char *trame, Position *p)
|
||
{
|
||
int i,j,d=trame_cmp(char* trame,char* type);
|
||
float lat[N],lon[N];
|
||
for (i=0; i<8; i++){
|
||
lat[i]=trame[i+17]-48;
|
||
int i=0,j;
|
||
float deg_lat,deg_long;
|
||
while(c[i]!='\0'){
|
||
|
||
i++;
|
||
}
|
||
for (j=0; j<9;j++){
|
||
lon[i]=trame[i+29]-48;
|
||
if(i==9){
|
||
deg_lat=decode_nombre(c,2);
|
||
deg_lat+=(c[2]-'0')*1/6;
|
||
deg_lat+=(c[3]-'0')*1/60;
|
||
for(i=5;i<9;i++){
|
||
deg_lat+=((c[i]-'0')*pow(10,3-i))/6;
|
||
}
|
||
return deg_lat;
|
||
}
|
||
if(i==10){
|
||
|
||
if(d==1 && p.latitude<=180 && p.longitude>==-180){
|
||
deg_long=decode_nombre(c,3);
|
||
deg_long+=(c[3]-'0')*1/6;
|
||
deg_long+=(c[4]-'0')*1/60;
|
||
for(i=6;i<10;i++){
|
||
deg_long+=((c[i]-'0')*pow(10,4-i))/6;
|
||
}
|
||
return deg_long;
|
||
}
|
||
|
||
printf("Trame et position valide");
|
||
}
|
||
|
||
}
|
||
|
||
//Decodage d'une trame
|
||
int decode_trame(char *trame, Position p)
|
||
{
|
||
int i,j,d;
|
||
char lat[N],lon[N],indx_lat[]={'0','\0'},indx_lon[]={'0','\0'};
|
||
|
||
|
||
if(trame_cmp(trame,"GPGGA")==1){
|
||
d=1;
|
||
for (i=0; i<8; i++){
|
||
lat[i]=trame[i+17];
|
||
}
|
||
for (j=0; j<9;j++){
|
||
lon[i]=trame[i+29];
|
||
}
|
||
indx_lat[0]=trame[27];
|
||
indx_lon[0]=trame[40];
|
||
p.latitude= conversion(lat);
|
||
p.longitude=conversion(lon);
|
||
|
||
if(indx_lat[0]=='S'){
|
||
p.latitude=-p.latitude;
|
||
}
|
||
|
||
if(indx_lat[0]=='W'){
|
||
p.longitude=-p.longitude;
|
||
}
|
||
}
|
||
else{
|
||
printf("Trame incomplete");
|
||
d=0;
|
||
}
|
||
return 0;
|
||
|
||
}
|
||
return d;
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
... | ... | |
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
//test unitaire decode_int
|
||
void test_decode_int(void){
|
||
if (decode_int('0')!=0){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('1')!=1){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('2')!=2){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('3')!=3){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('4')!=4){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('5')!=5){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('A')!=-1){
|
||
printf ("Erreur Test unitaire basique decode int.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
//Test unitaire decode_nombre
|
||
void test_decode_nombre(void){
|
||
|
||
if (decode_nombre("632",2)!=63){
|
||
printf ("Erreur Test unitaire basique decode nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("632",2)!=63){
|
||
printf ("Erreur Test unitaire basique decode nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("1204",3)!=120){
|
||
printf ("Erreur Test unitaire basique decode nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("10",1)!=1){
|
||
printf ("Erreur Test unitaire basique decode nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("7865",3)!=786){
|
||
printf ("Erreur Test unitaire basique decode nombre.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
|
||
}
|
||
void tests_unitaires(void){
|
||
|
||
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
... | ... | |
}
|
||
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
exit(-1);//Fin
|
||
}
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
}
|
||
|
||
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
Formats disponibles : Unified diff
Test unitaire decode trame GPGGA