From 66246c4dca006a8736dbc8b4118981a53da55749 Mon Sep 17 00:00:00 2001 From: asterix Date: Tue, 13 Oct 2009 09:29:11 +0000 Subject: [PATCH] Some fix. Reformat. Check if read sentence return correct value. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3076 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/net/nmea_test.c | 97 +++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/bertos/net/nmea_test.c b/bertos/net/nmea_test.c index fdcc505d..8d287d96 100644 --- a/bertos/net/nmea_test.c +++ b/bertos/net/nmea_test.c @@ -58,38 +58,60 @@ static NmeaVtg vtg; static KFileMem mem; -static char nmea_test_vector[] = +static char nmea_test1[] = { -"$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" /* 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 = +static NmeaGga gga_test = { .latitude = 43851403, .longitude = 11147808, .altitude = 57, - .time = 2736328, + .time = 57928, .satellites = 5, .quality = 1, .hdop = 26, .geoid = 45, }; +static NmeaRmc rmc_test = +{ + .time = 1254758726, + .warn = 'A', + .latitude = 43851405, + .longitude = 11147812, + .speed = 0, + .course = 237, + .mag_var = 0 +}; + + +static NmeaVtg vtg_test = +{ + .track_good = 237, + .knot_speed = 0, + .km_speed = 0 +}; + +static NmeaGsv gsv_test = +{ + .tot_message = 3, + .message_num = 1, + .tot_svv = 9, + .info = + { + { 3, 78, 302, 37 }, + { 6, 87, 31, 0 }, + { 7, 5, 292, 37 }, + { 14, 5, 135, 0 } + } +}; + + #define TOT_GOOD_SENTENCE_NUM 12 #define MAX_SENTENCE_POLL 20 @@ -99,7 +121,7 @@ static int tot_sentence_parsed = 0; /** * do something with the GGA data */ -static void gpgga_callout(nmeap_context_t *context, void *data, void *user_data) +static void gpgga_callout_test(nmeap_context_t *context, void *data, void *user_data) { (void)context; (void)user_data; @@ -115,14 +137,13 @@ static void gpgga_callout(nmeap_context_t *context, void *data, void *user_data) gga->satellites, gga->quality, gga->hdop, - gga->geoid - ); + gga->geoid); } /** - * called when a gpgga message is received and parsed + * do something with the RMC data */ -static void gprmc_callout(nmeap_context_t *context, void *data, void *user_data) +static void gprmc_callout_test(nmeap_context_t *context, void *data, void *user_data) { (void)context; (void)user_data; @@ -137,14 +158,13 @@ static void gprmc_callout(nmeap_context_t *context, void *data, void *user_data) (long)rmc->longitude, rmc->speed, rmc->course, - rmc->mag_var - ); + rmc->mag_var); } /** - * do something with the GGA data + * do something with the GSV data */ -static void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data) +static void gpgsv_callout_test(nmeap_context_t *context, void *data, void *user_data) { (void)context; (void)user_data; @@ -164,7 +184,7 @@ static void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data) /** * do something with the VTG data */ -static void gpvtg_callout(nmeap_context_t *context, void *data, void *user_data) +static void gpvtg_callout_test(nmeap_context_t *context, void *data, void *user_data) { (void)context; (void)user_data; @@ -175,22 +195,21 @@ static void gpvtg_callout(nmeap_context_t *context, void *data, void *user_data) LOG_INFO("[%d]found GPVTG message %d %d %d\n",tot_sentence_parsed, vtg->track_good, vtg->knot_speed, - vtg->km_speed - ); + vtg->km_speed); } int nmea_testSetup(void) { kdbg_init(); - kfilemem_init(&mem, nmea_test_vector, sizeof(nmea_test_vector)); + kfilemem_init(&mem, nmea_test1, sizeof(nmea_test1)); LOG_INFO("Init test buffer..done.\n"); - nmeap_init(&nmea, NULL); - nmeap_addParser(&nmea, "GPGGA", nmea_gpgga, gpgga_callout, &gga); - nmeap_addParser(&nmea, "GPRMC", nmea_gprmc, gprmc_callout, &rmc); - nmeap_addParser(&nmea, "GPGSV", nmea_gpgsv, gpgsv_callout, &gsv); - nmeap_addParser(&nmea, "GPVTG", nmea_gpvtg, gpvtg_callout, &vtg); + nmeap_init(&nmea, NULL); + nmeap_addParser(&nmea, "GPGGA", nmea_gpgga, gpgga_callout_test, &gga); + nmeap_addParser(&nmea, "GPRMC", nmea_gprmc, gprmc_callout_test, &rmc); + nmeap_addParser(&nmea, "GPGSV", nmea_gpgsv, gpgsv_callout_test, &gsv); + nmeap_addParser(&nmea, "GPVTG", nmea_gpvtg, gpvtg_callout_test, &vtg); return 0; } @@ -207,17 +226,15 @@ int nmea_testRun(void) 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))) + if (memcmp(&gga_test, &gga, sizeof(gga_test)) && + memcmp(&rmc_test, &rmc, sizeof(rmc_test)) && + memcmp(&vtg_test, &vtg, sizeof(vtg_test)) && + memcmp(&gsv_test, &gsv, sizeof(gsv_test))) { LOG_ERR("Last gga test sentence had unexpected value\n"); return -1; } + return 0; } -- 2.25.1