Révision 341
Ajouté par Khalid YAZID il y a presque 3 ans
main.c | ||
---|---|---|
"$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};
|
||
//Fonction ? modifier !!!!!
|
||
0};
|
||
zones[] = {
|
||
{{44.7887762, -3.012}, 50}, /* Descripteur de la premi?re zone */
|
||
{{44.7891220, -3,013}, 70}};
|
||
|
||
typedef struct {
|
||
float latitude;
|
||
float longitude;
|
||
}Position;
|
||
|
||
typedef struct {
|
||
Position rpos;
|
||
float vitmax;
|
||
}Zone;
|
||
int trame_cmp(char *trame , char *type){
|
||
int i;
|
||
int test=1;
|
||
... | ... | |
x=x-48;
|
||
return x;
|
||
}
|
||
void test_decode_int(void){
|
||
/*void test_decode_int(void){
|
||
int i,j,s;
|
||
char *C[]= {"0","1","2","3","4","5","6","7","8","9"};
|
||
int T[]= {0,1,2,3,4,5,6,7,9,8};
|
||
for(i=0;i<10;i++){
|
||
s=0;
|
||
if (decode_int(C[i])!=-1 ){
|
||
if (decode_int(C[i])!=-1 ){int decode_trame(char* trame, position p )}
|
||
{ int i;
|
||
if (trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
p.latitude=latitude(trame);
|
||
p.longitude=longitude(trame);
|
||
i=1;
|
||
}
|
||
else
|
||
{ i=0;
|
||
}
|
||
return i;
|
||
}
|
||
|
||
for(j=0;j<10;j++){
|
||
if (decode_int(*C[i])==T[j]){
|
||
s=1;
|
||
... | ... | |
}}
|
||
|
||
}
|
||
}*/
|
||
int trame_latitude(char* trame){ //selection la latitude
|
||
char latitude[7];
|
||
int b=trame_cmp(trame,"GPGGA");
|
||
int i,k,v,j;
|
||
if (b==1){
|
||
for(k=0;k=strlen(trame);k++){
|
||
for(i=k;i=strlen(trame[k]);i++){
|
||
if (trame[i]==','){
|
||
v+=1;
|
||
if(v==2){
|
||
for (j=0;j=7;j++){
|
||
latitude[j]=trame[i+1];
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
int trame_longtitude(char* trame){ //selection la longtitude
|
||
char longtitude[7];
|
||
int b=trame_cmp(trame,"GPGGA");
|
||
int i,k,v,j;
|
||
if (b==1){
|
||
for(k=0;k=strlen(trame);k++){
|
||
for(i=k;i=strlen(trame[k]);i++){
|
||
if (trame[i]==','){
|
||
v+=1;
|
||
if(v==4){
|
||
for (j=0;j=7;j++){
|
||
longtitude[j]=trame[i+2];
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
int decode_nombre(char *ch,int n){
|
||
int i=0,x=strlen(ch);
|
||
char s;
|
||
int i,j,p;
|
||
int s=0;
|
||
for (i=0;i<n;i++){
|
||
int a=decode_int(ch[x-1-n-i]);
|
||
s=s+a*pow(10,i);
|
||
p=1;
|
||
for(j=0;j<n-1-i;j++){
|
||
p=p*10;
|
||
}
|
||
int a=decode_int(ch[i]);
|
||
s=s+a*p;
|
||
}
|
||
return s;
|
||
}
|
||
}
|
||
void test_decode_nombre(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("35789",3)!=357){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (decode_nombre("25986452235",7)!=2598645){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("2",1)!=2){
|
||
printf ("Erreur Test unitaire trame_cmp3.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("25986452235",7)==2578963){
|
||
printf ("Erreur Test unitaire trame_cmp4.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
|
||
float latitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[0])*10+decode_int(c[1]) ;
|
||
secondes=(decode_int(c[5])*1000+decode_int(c[6])*100+decode_int(c[7])*10+decode_int(c[5]))/10000;
|
||
minute=(decode_int(c[2])*10+decode_int(c[3])+secondes)/60;
|
||
sommes=degre+minute;
|
||
return sommes;
|
||
}
|
||
void test_latitude(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("3558.8889")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("0112.1415")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
float longtitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[0])*100+decode_int(c[1])*10+decode_int(c[2]) ;
|
||
secondes=(decode_int(c[6])*1000+decode_int(c[7])*100+decode_int(c[8])*10+decode_int(c[9])*1)%1000;
|
||
minute=(decode_int(c[3])*10+decode_int(c[4])+secondes)/60;
|
||
sommes=degre+minute;
|
||
}
|
||
void test_longtitude(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("13558.8889")-135,981481<0.000001 && 135,981481-latitude("13558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("10112.1415")-101,202358<0.000001 && 101,202358-latitude("10112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
float deux_fonctions(char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
while(c[i] != '.'){
|
||
i=i+1;
|
||
}
|
||
if(i==4){
|
||
|
||
degre=decode_int(c[0])*10+decode_int(c[1]) ;
|
||
secondes=(decode_int(c[5])*1000+decode_int(c[6])*100+decode_int(c[7])*10+decode_int(c[5]))/10000;
|
||
minute=(decode_int(c[2])*10+decode_int(c[3])+secondes)/60;
|
||
sommes=degre+minute;}
|
||
else{
|
||
degre=decode_int(c[0])*100+decode_int(c[1])*10+decode_int(c[2]) ;
|
||
secondes=(decode_int(c[6])*1000+decode_int(c[7])*100+decode_int(c[8])*10+decode_int(c[9])*1)%1000;
|
||
minute=(decode_int(c[3])*10+decode_int(c[4])+secondes)/60;
|
||
sommes=degre+minute;
|
||
}
|
||
return sommes;
|
||
|
||
|
||
}
|
||
|
||
void test_deux_fonctions(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("13558.8889")-135,981481<0.000001 && 135,981481-deux_fonctions("13558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("10112.1415")-101,202358<0.000001 && 101,202358-deux_fonctions("10112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
int decode_trame(char* trame, Position *p )
|
||
{
|
||
int i;
|
||
if (trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
p.latitude=latitude('4545.0000');
|
||
p.longitude=longitude('0306.6036');
|
||
i=1;
|
||
}
|
||
else
|
||
{
|
||
i=0;
|
||
}
|
||
return i;
|
||
}
|
||
|
||
float calcul_distance(Position p1, Position p2)
|
||
{
|
||
float distance;
|
||
distance=(2*3.14*6370/360)*sqrt((p2.latitude-p1.latitude)*(p2.latitude-p1.latitude)+(p2.longitudep1.longitude)*(p2.longitude-p1.longitude));
|
||
return distance;
|
||
}
|
||
float calcul_vitesse(position p1, Position p2)
|
||
{
|
||
float vitesse;
|
||
vitesse=calcul_distance(p1, p2);
|
||
vitesse=vitesse/3600;
|
||
return vitesse;
|
||
}
|
||
|
||
//Fonction ? modifier !!!!
|
||
void traitement(char * trame)
|
||
{
|
||
|
||
static int cpt=0 ;
|
||
static int cpt=0;
|
||
cpt++ ;
|
||
/*int decode_trame(char *trame, Position *p);*/
|
||
int b=trame_cmp(trame,"GPGGA");
|
||
if (b==1){
|
||
printf ("> %s\n",trame);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
test_decode_int();
|
||
int y=decode_nombre("7541",2);
|
||
/* test_decode_int()*/
|
||
/* int y=decode_nombre("7541",2);
|
||
printf("la valeur de dedcod_nombre est%d",y);
|
||
|
||
/* 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("$APRMC...", "GPGGA")!=0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}*/
|
||
}*/
|
||
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
tests_unitaires();
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
test_latitude();
|
||
test_longtitude();
|
||
test_deux_fonctions();
|
||
|
||
|
||
|
||
// 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;
|
||
}
|
||
|
||
// 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;
|
||
}
|
Formats disponibles : Unified diff
TP 2 implantation de la question 1 jusqu'à la question 6