#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
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
(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,
(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
(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,
(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
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;
}
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;
}