Add nmea module test.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 5 Oct 2009 09:16:47 +0000 (09:16 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 5 Oct 2009 09:16:47 +0000 (09:16 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3018 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/net/nmea_test.c [new file with mode: 0644]
test/run_tests.sh

diff --git a/bertos/net/nmea_test.c b/bertos/net/nmea_test.c
new file mode 100644 (file)
index 0000000..4f611ff
--- /dev/null
@@ -0,0 +1,181 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief NMEA parser test.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include "nmea.h"
+
+#include <struct/kfile_mem.h>
+
+#include <cfg/debug.h>
+#include <cfg/test.h>
+
+#include <string.h> //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);
index 0d8855eb4f47a04076df114c9e23750390a099d2..a4f8e11e03ac393f3d05c8f1379ebcb2b138e962 100755 (executable)
@@ -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'