92 lines
2.5 KiB
C++
92 lines
2.5 KiB
C++
//
|
|
// GPS Daemon
|
|
// Neal Probert
|
|
//
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <signal.h>
|
|
#include <time.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/wait.h>
|
|
#include <arpa/inet.h>
|
|
|
|
#include "NmeaParser.h"
|
|
|
|
#include "netlib.h"
|
|
|
|
extern int optind, opterr, optopt;
|
|
|
|
//
|
|
// Written because gpsd (http://gpsd.berlios.de/) is too fat
|
|
//
|
|
|
|
static const char *msg[] = {
|
|
// from web examples
|
|
"$GPGLL,3751.65,S,14507.36,E*77\r\n",
|
|
"$GPGLL,4916.45,N,12311.12,W,225444,A\n",
|
|
"$GPGSA,A,3,,,,,,16,18,,22,24,,,3.6,2.1,2.2*3C\n",
|
|
"$GPGSA,A,3,19,28,14,18,27,22,31,39,,,,,1.7,1.0,1.3*34\n",
|
|
"$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58\n",
|
|
"$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74\n",
|
|
"$GPGSV,1,1,13,02,02,213,,03,-3,000,,11,00,121,,14,13,172,05*62\n",
|
|
"$GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62\n",
|
|
"$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68\n",
|
|
"$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70\n",
|
|
"$GPVTG,360.0,T,348.7,M,000.0,N,000.0,K*43\n",
|
|
"$GPZDA,024611.08,25,03,2002,00,00*6A\n",
|
|
|
|
// real examples (u-Blox)
|
|
"$GPRMC,195042.00,A,4227.99355,N,08323.70161,W,0.000,-69.23,270307,,,E*6A\n",
|
|
"$GPVTG,-69.23,T,,M,0.000,N,0.000,K,E*2A\n",
|
|
"$GPGGA,195042.00,4227.99355,N,08323.70161,W,6,6,1.43,262.3,M,-34.1,M,,*57\n",
|
|
"$GPGSA,A,E,24,29,26,18,09,10,,,,,,,2.58,1.43,2.15*73\n",
|
|
"$GPGSV,3,1,12,24,56,138,39,29,39,048,41,26,51,051,45,21,78,286,28*7A\n",
|
|
"$GPGSV,3,2,12,18,50,288,33,09,26,144,37,07,22,212,,22,19,274,*72\n",
|
|
"$GPGSV,3,3,12,10,07,082,37,06,15,198,,03,10,319,,33,08,105,34*72\n",
|
|
"$GPGLL,4227.99355,N,08323.70161,W,195042.00,A,E*7F\n",
|
|
"$GPGST,195042.00,1.9,,,,50,50,3.5*7C\n",
|
|
"$GPZDA,195042.00,27,",
|
|
"03,2007,00,00*6E\n",
|
|
|
|
NULL
|
|
};
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
NmeaParser Nmea;
|
|
int failed = 0;
|
|
|
|
printf( "Starting NMEA Parser tests:\n" );
|
|
|
|
for ( int i=0 ; msg[i] ; i++ )
|
|
{
|
|
printf( "%s", msg[i] );
|
|
|
|
int flag = Nmea.NmeaParse( msg[i], strlen(msg[i]) );
|
|
|
|
if ( flag < 0 )
|
|
failed++;
|
|
|
|
if ( flag > 0 )
|
|
printf( "\tpassed\n" );
|
|
else if ( flag < 0 )
|
|
printf( "\tfailed\n" );
|
|
}
|
|
|
|
if ( failed )
|
|
printf( "FAILED: %d tests failed!\n", failed );
|
|
else
|
|
printf( "SUCCESS: All tests passed!\n" );
|
|
|
|
return 0;
|
|
}
|