From: asterix Date: Mon, 5 Oct 2009 09:16:47 +0000 (+0000) Subject: Add nmea module test. X-Git-Tag: 2.3.0~63 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=b7b925c33aeb1536d65d9f5a2c6b66c3b191e4e4;p=bertos.git Add nmea module test. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3018 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/net/nmea_test.c b/bertos/net/nmea_test.c new file mode 100644 index 00000000..4f611ff8 --- /dev/null +++ b/bertos/net/nmea_test.c @@ -0,0 +1,181 @@ +/** + * \file + * + * + * \brief NMEA parser test. + * + * \author Daniele Basile + */ + +#include "nmea.h" + +#include + +#include +#include + +#include //strncmp + +static nmeap_context_t nmea; /* parser context */ +static NmeaRmc rmc; +static NmeaGga gga; +static NmeaGsv gsv; +static NmeaVtg vtg; + +static KFileMem mem; + +static char nmea_test_vector[] = +{ +"$GPGGA,123519,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.12,W,000.5,054.7,191194,020.3,E*68\r\n" /* good */ +"$GPRMC,225446,A,4916.45,N,12311.12,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 */ +}; + + +/** + * do something with the GGA data + */ +static void gpgga_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaGga *gga = (NmeaGga *)data; + + kprintf("found GPGGA message %d %d %d %d %d %d %d %d\n", + gga->latitude, + gga->longitude, + gga->altitude, + gga->time, + gga->satellites, + gga->quality, + gga->hdop, + gga->geoid + ); +} + +/** + * called when a gpgga message is received and parsed + */ +static void gprmc_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaRmc *rmc = (NmeaRmc *)data; + + kprintf("found GPRMC Message %d %c %d %d %d %d %d %d\n", + rmc->time, + rmc->warn, + rmc->latitude, + rmc->longitude, + rmc->speed, + rmc->course, + rmc->date, + rmc->mag_var + ); +} + +/** + * do something with the GGA data + */ +static void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaGsv *gsv = (NmeaGsv *)data; + + kprintf("found GPGSV message %d %d %d %d %d %d %d\n", + gsv->tot_message, + gsv->message_num, + gsv->tot_svv, + gsv->sv_prn, + gsv->elevation, + gsv->azimut, + gsv->snr + ); +} + +/** + * do something with the VTG data + */ +static void gpvtg_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaVtg *vtg = (NmeaVtg *)data; + + kprintf("found GPVTG message %d %d %d\n", + vtg->track_good, + vtg->knot_speed, + vtg->km_speed + ); +} + +int nmea_testSetup(void) +{ + kdbg_init(); + + kfilemem_init(&mem, nmea_test_vector, sizeof(nmea_test_vector)); + kprintf("Init test buffer..done.\n"); + + nmeap_init(&nmea, NULL); + kprintf("Init NMEA context..done.\n"); + nmeap_addParser(&nmea, "GPGGA", nmea_gpgga, gpgga_callout, &gga); + kprintf("Init NMEA GPGGA parser..done.\n"); + nmeap_addParser(&nmea, "GPRMC", nmea_gprmc, gprmc_callout, &rmc); + kprintf("Init NMEA GPRMC parser..done.\n"); + nmeap_addParser(&nmea, "GPGSV", nmea_gpgsv, gpgsv_callout, &gsv); + kprintf("Init NMEA GPGSV parser..done.\n"); + nmeap_addParser(&nmea, "GPVTG", nmea_gpvtg, gpvtg_callout, &vtg); + kprintf("Init NMEA GPVTG parser..done.\n"); + + return 0; +} + +int nmea_testTearDown(void) +{ + return 0; +} + +int nmea_testRun(void) +{ + nmea_poll(&nmea, &mem.fd); + return 0; +} + +TEST_MAIN(nmea); diff --git a/test/run_tests.sh b/test/run_tests.sh index 0d8855eb..a4f8e11e 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -28,7 +28,7 @@ TESTS=${TESTS:-`find . \ -o -name "*_test.c" -print` } TESTOUT="testout" -SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c bertos/emul/switch_ctx_emul.S bertos/mware/ini_reader.c bertos/emul/kfile_posix.c bertos/algo/crc_ccitt.c bertos/algo/crc.c bertos/struct/kfile_mem.c bertos/net/ax25.c bertos/net/afsk.c" +SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c bertos/emul/switch_ctx_emul.S bertos/mware/ini_reader.c bertos/emul/kfile_posix.c bertos/algo/crc_ccitt.c bertos/algo/crc.c bertos/struct/kfile_mem.c bertos/net/ax25.c bertos/net/afsk.c bertos/net/nmeap/src/nmeap01.c bertos/net/nmea.c" buildout='/dev/null' runout='/dev/null'