概述
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _STR(x)
#x
#define STR(x)
_STR(x)
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
#define NMEA_UNIT_LEN 20
#define NMEA_INFO_LEN 16
#if 0
"$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69rn",
"$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70rn",
"$GPGSV,2,1,08,01,05,005,80,02,05,050,80,03,05,095,80,04,05,140,80*7frn",
"$GPGSV,2,2,08,05,05,185,80,06,05,230,80,07,05,275,80,08,05,320,80*71rn",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,00,00,00,00,0.0,0.0,0.0*3arn",
"$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50rn",
"$GPVTG,217.5,T,208.8,M,000.00,N,000.01,K*4Crn"
#endif
char nmea_info[NMEA_UNIT_LEN][NMEA_INFO_LEN] = {0};
void nmea_init(char *info);
void nmea_parse(char *str, char *info);
void nmea_decode(char *info);
void showInfo(char *info);
int main(int argc, char *argv[])
{
char *gps_str[]= {
"$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70rn",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,00,00,00,00,0.0,0.0,0.0*3arn",
"$GPGSV,2,1,08,01,05,005,80,02,05,050,80,03,05,095,80,04,05,140,80*7frn",
"$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50rn",
"$GPVTG,217.5,T,208.8,M,000.00,N,000.01,K*4Crn",
"$GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2Drn",
};
for (int i = 0; i < 6; i ++)
{
nmea_init((char *)nmea_info);
nmea_parse(gps_str[i], (char *)nmea_info);
#if 0
showInfo((char *)nmea_info);
#endif
nmea_decode((char *)nmea_info);
}
return 0;
}
void nmea_init(char *info)
{
for (int i = 0; i < NMEA_UNIT_LEN; i ++)
{
for (int j = 0; j < NMEA_INFO_LEN; j ++)
{
info[i * NMEA_INFO_LEN + j] = '