Atomate nmea check. Some fix.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 6 Oct 2009 10:50:24 +0000 (10:50 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 6 Oct 2009 10:50:24 +0000 (10:50 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3036 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/net/nmea_test.c

index f95125d051c997f3cb71551bac24a3d0a94e1b05..acc7cd487961ec6178be6546cb7b3f052cefbc28 100644 (file)
 #include <struct/kfile_mem.h>
 
 #include <cfg/debug.h>
+#define LOG_LEVEL  NMEA_LOG_LEVEL
+#define LOG_FORMAT NMEA_LOG_FORMAT
+#include <cfg/log.h>
+
 #include <cfg/test.h>
 
 #include <string.h> //strncmp
@@ -57,23 +61,40 @@ static KFileMem mem;
 static char nmea_test_vector[] =
 {
 "$GPGGA,123519.021,3929.946667,N,11946.086667,E,1,08,0.9,545.4,M,46.9,M,,*4A\r\n" /* good */
-"$xyz,1234,asdfadfasdfasdfljsadfkjasdfk\r\n"                                  /* junk */
-"$GPRMC,225446,A,4916.45,N,12311.120,W,000.5,054.7,191194,020.3,E*68\r\n"      /* good */
-"$GPRMC,225446,A,4916.45,N,12311.120,W,000.5,054.7,191194,020.3,E*48\r\n"      /* checksum error */
-"$GPGGA,091144.698,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*5C\r\n"   /* acquired */
-"$GPRMC,091144.698,V,0000.0000,S,00000.0000,W,0.00,0.00,051009,,,A*75\r\n"    /* acquired */
-"$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70\r\n"                                      /* acquired */
-"$GPGGA,091145.698,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*5D\r\n"   /* acquired */
-"$GPGSV,1,1,02,1,,,41,12,,,35,,,,,,,,*4A\r\n"                                 /* acquired */
-"$GPRMC,091145.698,V,0000.0000,S,00000.0000,W,0.00,0.00,051009,,,A*74\r\n"    /* acquired */
-"$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70\r\n"                                      /* acquired */
-"$GPGGA,170529.948,4351.0841,N,01108.8685,E,1,05,02.6,57.4,M,45.2,M,,*50\r\n"
-"$GPRMC,170525.949,A,4351.0843,N,01108.8687,E,0.00,237.67,051009,,,A*61\r\n"
-"$GPVTG,237.67,T,,,0.00,N,0.00,K,A*77\r\n"
-"$GPGSV,3,1,09,3,78,302,37,6,87,031,,7,05,292,37,14,05,135,*48\r\n"
-"$GPGGA,170527.949,4351.0842,N,01108.8685,E,1,05,02.6,57.4,M,45.2,M,,*5C\r\n"
+"$xyz,1234,asdfadfasdfasdfljsadfkjasdfk\r\n"                                      /* junk */
+"$GPRMC,225446,A,4916.45,N,12311.120,W,000.5,054.7,191194,020.3,E*68\r\n"         /* good */
+"$GPRMC,225446,A,4916.45,N,12311.120,W,000.5,054.7,191194,020.3,E*48\r\n"         /* checksum error */
+"$GPGGA,091144.698,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*5C\r\n"       /* acquired */
+"$GPRMC,091144.698,V,0000.0000,S,00000.0000,W,0.00,0.00,051009,,,A*75\r\n"        /* acquired */
+"$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70\r\n"                                          /* acquired */
+"$GPGGA,091145.698,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*5D\r\n"       /* acquired */
+"$GPGSV,1,1,02,1,,,41,12,,,35,,,,,,,,*4A\r\n"                                     /* acquired */
+"$GPRMC,091145.698,V,0000.0000,S,00000.0000,W,0.00,0.00,051009,,,A*74\r\n"        /* acquired */
+"$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70\r\n"                                          /* acquired */
+"$GPGGA,170529.948,4351.0841,N,01108.8685,E,1,05,02.6,57.4,M,45.2,M,,*50\r\n"     /* acquired */
+"$GPRMC,170525.949,A,4351.0843,N,01108.8687,E,0.00,237.67,051009,,,A*61\r\n"      /* acquired */
+"$GPVTG,237.67,T,,,0.00,N,0.00,K,A*77\r\n"                                        /* acquired */
+"$GPGSV,3,1,09,3,78,302,37,6,87,031,,7,05,292,37,14,05,135,*48\r\n"               /* acquired */
+"$GPGGA,170527.949,4351.0842,N,01108.8685,E,1,05,02.6,57.4,M,45.2,M,,*5C\r\n"     /* acquired */
 };
 
+NmeaGga gga_test =
+{
+       .latitude = 43851403,
+    .longitude = 11147808,
+    .altitude = 574,
+    .time = 2736328,
+    .satellites = 5,
+    .quality = 1,
+    .hdop = 26,
+    .geoid = 452,
+};
+
+#define TOT_GOOD_SENTENCE_NUM    12
+
+#define MAX_SENTENCE_POLL  20
+
+static int tot_sentence_parsed = 0;
 
 /**
  * do something with the GGA data
@@ -84,9 +105,11 @@ static void gpgga_callout(nmeap_context_t *context, void *data, void *user_data)
        (void)user_data;
        NmeaGga *gga = (NmeaGga *)data;
 
-    kprintf("found GPGGA message %ld %ld %d %lu %d %d %d %d\n",
-            gga->latitude,
-            gga->longitude,
+       tot_sentence_parsed++;
+
+    LOG_INFO("[%d]found GPGGA message %ld %ld %d %lu %d %d %d %d\n",tot_sentence_parsed,
+            (long)gga->latitude,
+            (long)gga->longitude,
             gga->altitude,
             gga->time,
             gga->satellites,
@@ -105,11 +128,13 @@ static void gprmc_callout(nmeap_context_t *context, void *data, void *user_data)
        (void)user_data;
     NmeaRmc *rmc = (NmeaRmc *)data;
 
-       kprintf("found GPRMC Message %lu %c %d %ld %ld %d %d\n",
+       tot_sentence_parsed++;
+
+       LOG_INFO("[%d]found GPRMC Message %lu %c %ld %ld %d %d %d\n",tot_sentence_parsed,
             rmc->time,
             rmc->warn,
-            rmc->latitude,
-            rmc->longitude,
+            (long)rmc->latitude,
+            (long)rmc->longitude,
             rmc->speed,
             rmc->course,
             rmc->mag_var
@@ -125,7 +150,9 @@ static void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data)
        (void)user_data;
        NmeaGsv *gsv = (NmeaGsv *)data;
 
-    kprintf("found GPGSV message %d %d %d %d %d %d %d\n",
+       tot_sentence_parsed++;
+
+    LOG_INFO("[%d]found GPGSV message %d %d %d %d %d %d %d\n",tot_sentence_parsed,
                        gsv->tot_message,
                        gsv->message_num,
                        gsv->tot_svv,
@@ -145,7 +172,9 @@ static void gpvtg_callout(nmeap_context_t *context, void *data, void *user_data)
        (void)user_data;
        NmeaVtg *vtg = (NmeaVtg *)data;
 
-    kprintf("found GPVTG message %d %d %d\n",
+       tot_sentence_parsed++;
+
+    LOG_INFO("[%d]found GPVTG message %d %d %d\n",tot_sentence_parsed,
                        vtg->track_good,
                        vtg->knot_speed,
                        vtg->km_speed
@@ -157,18 +186,18 @@ int nmea_testSetup(void)
        kdbg_init();
 
        kfilemem_init(&mem, nmea_test_vector, sizeof(nmea_test_vector));
-       kprintf("Init test buffer..done.\n");
+       LOG_INFO("Init test buffer..done.\n");
 
     nmeap_init(&nmea, NULL);
-       kprintf("Init NMEA context..done.\n");
+       LOG_INFO("Init NMEA context..done.\n");
     nmeap_addParser(&nmea, "GPGGA", nmea_gpgga, gpgga_callout, &gga);
-       kprintf("Init NMEA GPGGA parser..done.\n");
+       LOG_INFO("Init NMEA GPGGA parser..done.\n");
     nmeap_addParser(&nmea, "GPRMC", nmea_gprmc, gprmc_callout, &rmc);
-       kprintf("Init NMEA GPRMC parser..done.\n");
+       LOG_INFO("Init NMEA GPRMC parser..done.\n");
        nmeap_addParser(&nmea, "GPGSV", nmea_gpgsv, gpgsv_callout, &gsv);
-       kprintf("Init NMEA GPGSV parser..done.\n");
+       LOG_INFO("Init NMEA GPGSV parser..done.\n");
        nmeap_addParser(&nmea, "GPVTG", nmea_gpvtg, gpvtg_callout, &vtg);
-       kprintf("Init NMEA GPVTG parser..done.\n");
+       LOG_INFO("Init NMEA GPVTG parser..done.\n");
 
        return 0;
 }
@@ -180,7 +209,22 @@ int nmea_testTearDown(void)
 
 int nmea_testRun(void)
 {
-       nmea_poll(&nmea, &mem.fd);
+       for (int i = 0; i < MAX_SENTENCE_POLL; i++)
+       {
+               nmea_poll(&nmea, &mem.fd);
+       }
+
+       if (tot_sentence_parsed != TOT_GOOD_SENTENCE_NUM)
+       {
+               LOG_ERR("No all test sentence have been parser.\n");
+               return -1;
+       }
+
+       if (memcmp(&gga_test, &gga, sizeof(gga_test)))
+       {
+               LOG_ERR("Last gga test sentence had unexpected value\n");
+               return -1;
+       }
        return  0;
 }