Révision 14
Ajouté par nipelloux il y a plus de 4 ans
| branch/pelloux/sp4a12/main.c | ||
|---|---|---|
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <strings.h>
|
||
|
#include <strings.h>
|
||
|
#include <math.h>
|
||
|
#include "trame.h"
|
||
|
|
||
|
//Trames de tests ? modifier si n?cessaire.
|
||
| ... | ... | |
|
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
|
0};
|
||
|
|
||
|
int trame_cmp(char* a,char* b){
|
||
|
return 0;
|
||
|
int trame_cmp(char* trame,char* type){
|
||
|
int i=0;
|
||
|
while (type[i]!='\0'){
|
||
|
if (trame[i+1] != type[i]){
|
||
|
return 0;
|
||
|
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
|
||
|
int decode_int(char c){
|
||
|
int val=c-48;
|
||
|
if(val>=9 || val<0){
|
||
|
return -1;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int decode_nbr(char *ch,int n){
|
||
|
int res=0;
|
||
|
int i;
|
||
|
for(i=0;i<n;i++){
|
||
|
res += (decode_int(ch[i]))*pow(10,n-1-i);
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
//float conv_latitude(char * latitude){
|
||
|
// int i=0
|
||
|
// float v=0;
|
||
|
//while(latitude[i]!=''){
|
||
|
// v+=decode_int()
|
||
|
// }
|
||
|
|
||
|
//}
|
||
|
//Fonction ? modifier !!!!!
|
||
|
void traitement(char * trame)
|
||
|
{
|
||
|
printf ("> %s\n",trame);
|
||
|
{
|
||
|
if (trame_cmp(trame,"GPGGA")==1){
|
||
|
printf ("> %s\n",trame);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//Ajouter vos tests unitaires dans cette fonction.
|
||
| ... | ... | |
|
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
||
|
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
if (decode_int('5')!=5){
|
||
|
printf ("Erreur Test unitaire decode_int.\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
if (decode_int('A')!=-1){
|
||
|
printf ("Erreur Test unitaire decode_nbr.\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
if (decode_nbr("987654321",2)!=98){
|
||
|
printf ("Erreur Test unitaire decode_nbr.\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
if (decode_nbr("123",3)!=123){
|
||
|
printf ("Erreur Test unitaire decode_nbr.\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
// if (conv_latitude("987654321",2)!=98){
|
||
|
// printf ("Erreur Test unitaire decode_nbr.\n");
|
||
|
// exit(-1);
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
// Ne pas modifier cette fonction
|
||
|
int main(int argc,char ** argv)
|
||
|
{
|
||
|
|
||
|
tests_unitaires();
|
||
|
//tests_unitaires();
|
||
|
|
||
|
// Affichage des trames definies dans la table trames.
|
||
|
printf ("Trames de tests tableau trames:\n");
|
||
Formats disponibles : Unified diff
main+fonction traitement+decode int+decode nbr