Révision 363
Ajouté par beclement2 il y a presque 4 ans
branch/CLEMENT/sp4a12/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};
|
||
0};
|
||
|
||
// On D?finit la structure position
|
||
|
||
struct position{
|
||
float latitude;
|
||
float longitude;
|
||
};
|
||
|
||
int trame_cmp(char* trame,char* type){
|
||
|
||
int i=0; //Initialisation des variables
|
||
... | ... | |
|
||
}
|
||
|
||
int test_decode_int(void){
|
||
|
||
char testchar = '2';
|
||
|
||
int test = decode_int(testchar);
|
||
|
||
return test;
|
||
|
||
}
|
||
|
||
int decode_nombre(char * ch, int n){
|
||
|
||
int i;
|
||
... | ... | |
|
||
}
|
||
|
||
int test_decode_nombre(){
|
||
|
||
float conv_lat(char * latitude){
|
||
|
||
char testchar[] = "9876";
|
||
int test = decode_nombre(testchar, 3);
|
||
return test;
|
||
|
||
}
|
||
|
||
float conv_lat(char * latitude){
|
||
float val = decode_nombre(latitude,4);
|
||
float res = 0;
|
||
for (int i = 5; i < 9;i++){
|
||
... | ... | |
return res;}
|
||
|
||
float conv_long(char * longitude){
|
||
|
||
float val = decode_nombre(longitude,5);
|
||
float res = 0;
|
||
for (int i = 6; i < 10;i++){
|
||
... | ... | |
return res;}
|
||
|
||
float conversion(char * chaine){
|
||
|
||
int cpt = 0;
|
||
while (chaine[cpt]!='\0'){
|
||
cpt++;
|
||
... | ... | |
}
|
||
}
|
||
|
||
|
||
struct position decode_tram(char * trame){
|
||
|
||
|
||
if (trame_cmp(trame, "GPGGA")!= 1){
|
||
printf("Cette trame n'est pas au bon format.");
|
||
}
|
||
|
||
else{
|
||
//On d?finit notre structure
|
||
|
||
struct position position_trame;
|
||
char latitude[10];
|
||
char longitude[11];
|
||
int n = 0;
|
||
int i = 0;
|
||
int j = 0;
|
||
int k = 0;
|
||
|
||
while (trame[i] != '\0' && n <= 4){
|
||
if (trame[i] == ','){ //On rep?re les virgules
|
||
n = n + 1;
|
||
i = i + 1;
|
||
}
|
||
if (n == 2) { //Apr?s virgule 2 on a la latitude
|
||
latitude[j] = trame[i]; //On r?cup?re la latitude
|
||
j = j + 1;
|
||
}
|
||
if (n == 4) { //Apr?s virgule 4 on a la longitude
|
||
longitude[k] = trame[i]; //On stocke caract?re par caract?re pour isoler la longitude afin de la convertir.
|
||
k = k + 1;
|
||
}
|
||
i ++;
|
||
}
|
||
latitude[j] = '\0';
|
||
longitude[k] = '\0';
|
||
position_trame.latitude = conversion(latitude);
|
||
position_trame.longitude = conversion(longitude); //On stocke la latitude et la longitude convertie dans structure position.
|
||
|
||
return position_trame;
|
||
}
|
||
}
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
... | ... | |
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if(test_decode_int() != 2){
|
||
printf ("Erreur Test unitaire test_decode_int.\n");
|
||
if(decode_int('2') != 2){
|
||
printf ("Erreur Test unitaire decode_int.\n");
|
||
exit(-1);
|
||
}
|
||
if(decode_nombre("9876", 2) != 98){
|
||
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (fabs(conv_lat("3723.2475")-37.387458)>= pow(10,-6)){ // On s'arrange pour avoir le m?me arrondis que code blocks.
|
||
printf ("Erreur Test unitaire conv_lat.\n");
|
||
exit(-1);
|
||
... | ... | |
exit(-1);
|
||
}
|
||
|
||
// On va passer au test unitaire de notre fonction decode_tram :
|
||
char test1[] = "$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D";
|
||
char test2[] = "$GPGGA,141915.00,4545.0242,N,00306.6039,E,1,05,3.4,499.5,M,,M,,*72";
|
||
struct position test1_1;
|
||
struct position test2_1;
|
||
test1_1 = decode_tram(test1);
|
||
test2_1 = decode_tram(test2);
|
||
|
||
if ((fabs(test1_1.latitude - 45.75) >= pow(10,-6)) && fabs(test1_1.longitude - 003.11006) >= pow(10,-6)){
|
||
printf("Erreur Test unitaire decode_tram1.\n");
|
||
}
|
||
|
||
if ((fabs(test2_1.latitude - 45.750401) >= pow(10,-6)) && fabs(test2_1.longitude - 003.110065) >= pow(10,-6)){
|
||
printf("Erreur Test unitaire decode_tram2.\n");
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
|
||
tests_unitaires();
|
||
|
Formats disponibles : Unified diff
Séance numéro 2, décode tram et test unitaire décode tram implanté