Révision 112
Ajouté par mamoisan il y a environ 4 ans
branch/moisan/sp4a12/main.c | ||
---|---|---|
"$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;
|
||
int result = 1;
|
||
while (type[i]!='\0')
|
||
{
|
||
if(trame[i+1]!=type[i])
|
||
{
|
||
result = 0;
|
||
}
|
||
i++;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC suite chaine","GPGGA")!=0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC... ", "GPRMC" )!=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);
|
||
}
|
||
}
|
||
|
||
int decode_int(char a)
|
||
{
|
||
if((a>'0') && (a<'9'))
|
||
{
|
||
return (a-48);
|
||
} else
|
||
{
|
||
return -1;
|
||
}
|
||
}
|
||
|
||
void test_decode_int(void)
|
||
{
|
||
if (decode_int('0')!=0){
|
||
printf ("Erreur Test decode_int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('5')!=5){
|
||
printf ("Erreur Test decode_int.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('A')!=-1){
|
||
printf ("Erreur Test decode_int.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
int decode_nombre(char * ch,int n)
|
||
{
|
||
int i;
|
||
int res=0;
|
||
for (i=0;i<=n;i++)
|
||
{
|
||
res += pow(10,(n-i-1))*decode_int(ch[i]);
|
||
}
|
||
return res;
|
||
}
|
||
|
||
void test_decode_nombre(void)
|
||
{
|
||
if (decode_nombre("7541",2)!=75){
|
||
printf ("Erreur Test decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("7541",3)!=754){
|
||
printf ("Erreur Test decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("123",3)!=123){
|
||
printf ("Erreur Test decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("987654321",2)!=98){
|
||
printf ("Erreur Test decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
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);
|
||
{
|
||
if(trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
printf ("> %s\n",trame);
|
||
}
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC suite chaine","GPGGA")!=0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC... ", "GPRMC" )!=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
|
Formats disponibles : Unified diff
Questions 4,5,6,7,8