4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
33 * \brief NMEA parser test.
35 * \author Daniele Basile <asterix@develer.com>
42 #include <struct/kfile_mem.h>
44 #include <cfg/debug.h>
45 #define LOG_LEVEL NMEA_LOG_LEVEL
46 #define LOG_FORMAT NMEA_LOG_FORMAT
51 #include <string.h> //strncmp
53 static nmeap_context_t nmea; /* parser context */
61 static char nmea_test1[] =
63 "$GPRMC,170525.949,A,4351.0843,N,01108.8687,E,0.00,237.67,051009,,,A*61\r\n" /* acquired */
64 "$GPVTG,237.67,T,,,0.00,N,0.00,K,A*77\r\n" /* acquired */
65 "$GPGSV,3,1,09,3,78,302,37,6,87,031,,7,05,292,37,14,05,135,*48\r\n" /* acquired */
66 "$GPGGA,170527.949,4351.0842,N,01108.8685,E,1,05,02.6,57.4,M,45.2,M,,*5C\r\n" /* acquired */
69 static NmeaGga gga_test =
72 .longitude = 11147808,
81 static NmeaRmc rmc_test =
86 .longitude = 11147812,
93 static NmeaVtg vtg_test =
100 static NmeaGsv gsv_test =
115 #define TOT_GOOD_SENTENCE_NUM 12
117 #define MAX_SENTENCE_POLL 20
119 static int tot_sentence_parsed = 0;
122 * do something with the GGA data
124 static void gpgga_callout_test(nmeap_context_t *context, void *data, void *user_data)
128 NmeaGga *gga = (NmeaGga *)data;
130 tot_sentence_parsed++;
132 LOG_INFO("[%d]found GPGGA message %ld %ld %d %lu %d %d %d %d\n",tot_sentence_parsed,
134 (long)gga->longitude,
144 * do something with the RMC data
146 static void gprmc_callout_test(nmeap_context_t *context, void *data, void *user_data)
150 NmeaRmc *rmc = (NmeaRmc *)data;
152 tot_sentence_parsed++;
154 LOG_INFO("[%d]found GPRMC Message %lu %c %ld %ld %d %d %d\n",tot_sentence_parsed,
158 (long)rmc->longitude,
165 * do something with the GSV data
167 static void gpgsv_callout_test(nmeap_context_t *context, void *data, void *user_data)
171 NmeaGsv *gsv = (NmeaGsv *)data;
173 tot_sentence_parsed++;
175 LOG_INFO("[%d]found GPGSV message %d %d %d\n",tot_sentence_parsed,
180 for (int i = 0; i < 4; i++)
181 LOG_INFO("[%d]%d %d %d %d\n", i, gsv->info[i].sv_prn, gsv->info[i].elevation, gsv->info[i].azimut, gsv->info[i].snr);
185 * do something with the VTG data
187 static void gpvtg_callout_test(nmeap_context_t *context, void *data, void *user_data)
191 NmeaVtg *vtg = (NmeaVtg *)data;
193 tot_sentence_parsed++;
195 LOG_INFO("[%d]found GPVTG message %d %d %d\n",tot_sentence_parsed,
201 int nmea_testSetup(void)
205 kfilemem_init(&mem, nmea_test1, sizeof(nmea_test1));
206 LOG_INFO("Init test buffer..done.\n");
208 nmeap_init(&nmea, NULL);
209 nmeap_addParser(&nmea, "GPGGA", nmea_gpgga, gpgga_callout_test, &gga);
210 nmeap_addParser(&nmea, "GPRMC", nmea_gprmc, gprmc_callout_test, &rmc);
211 nmeap_addParser(&nmea, "GPGSV", nmea_gpgsv, gpgsv_callout_test, &gsv);
212 nmeap_addParser(&nmea, "GPVTG", nmea_gpvtg, gpvtg_callout_test, &vtg);
217 int nmea_testTearDown(void)
222 int nmea_testRun(void)
224 for (int i = 0; i < MAX_SENTENCE_POLL; i++)
226 nmea_poll(&nmea, &mem.fd);
229 if (memcmp(&gga_test, &gga, sizeof(gga_test)) &&
230 memcmp(&rmc_test, &rmc, sizeof(rmc_test)) &&
231 memcmp(&vtg_test, &vtg, sizeof(vtg_test)) &&
232 memcmp(&gsv_test, &gsv, sizeof(gsv_test)))
234 LOG_ERR("Last gga test sentence had unexpected value\n");