void showInfo1(char *buf) { char gps_str[1024];// ="$GPGGA,031105.000,4003.9196,N,11620.5765,E,1,05,3.4,109.0,M,-6.4,M,,0000*4A "; sprintf(gps_str,"%s",buf); nmeaINFO info; // nmea协议解析结果结构体 nmeaPARSER parser; // nmea协议解析载体 nmeaPOS dpos; nmea_zero_INFO(&info); // 填入默认的解析结果 nmea_parser_init(&parser); // 为解析载体分配内存空间 // 调用函数完成GPS信息解析,最终结果保留于info数组中 if( (nmea_parse(&parser, gps_str, (int)strlen(gps_str), &info)) > 0 ) { nmea_info2pos(&info, &dpos); printf("longitude %.5f ",info.lon); printf("latitude %.5f ",info.lat); printf("speed %.2f ",info.speed); printf(" "); printf("longitude %10.8f ",nmea_radian2degree(info.lon)); printf("latitude %10.8f ",nmea_radian2degree(info.lat)); printf("longitude %10.8f ",nmea_radian2degree(dpos.lon)); printf("latitude %10.8f ",nmea_radian2degree(dpos.lat)); } nmea_parser_destroy(&parser); // 释放解析载体的内存空间 } void showInfo_GPGGA(char *buf) { char gps_str[1024];// ="$GPGGA,031105.000,4003.9196,N,11620.5765,E,1,05,3.4,109.0,M,-6.4,M,,0000*4A "; sprintf(gps_str,"%s",buf); nmeaINFO info; // nmea协议解析结果结构体 nmeaGPGGA pack; nmeaPOS dpos; nmea_zero_INFO(&info); // 填入默认的解析结果 nmea_zero_GPGGA(&pack); // 调用函数完成GPS信息解析,最终结果保留于info数组中 if( (nmea_parse_GPGGA(gps_str, (int)strlen(gps_str), &pack)) > 0 ) { nmea_GPGGA2info(&pack,&info); nmea_info2pos(&info, &dpos); printf("GPGGA longitude %10.8f ",nmea_radian2degree(dpos.lon)); printf("GPGGA latitude %10.8f ",nmea_radian2degree(dpos.lat)); printf("GPGGA height_sea %10.8f ",pack.elv); printf("GPGGA height_ground %10.8f ",pack.diff); printf("GPGGA GPS_Num %2d ",pack.satinuse); } } void showInfo_GPRMC(char *buf) { char gps_str[1024];// ="$GPGGA,031105.000,4003.9196,N,11620.5765,E,1,05,3.4,109.0,M,-6.4,M,,0000*4A "; sprintf(gps_str,"%s",buf); nmeaINFO info; // nmea协议解析结果结构体 nmeaGPRMC pack; nmeaPOS dpos; nmea_zero_INFO(&info); // 填入默认的解析结果 nmea_zero_GPRMC(&pack); // 调用函数完成GPS信息解析,最终结果保留于info数组中 if( (nmea_parse_GPRMC(gps_str, (int)strlen(gps_str), &pack)) > 0 ) { nmea_GPRMC2info(&pack,&info); nmea_info2pos(&info, &dpos); // printf("GPRMC status %c ", pack.status); printf("DATE : %4d-%02d-%02d ",1900+pack.utc.year,pack.utc.mon+1,pack.utc.day); printf("TIME : %02d:%02d:%02d ",pack.utc.hour+8,pack.utc.min,pack.utc.sec); printf("GPRMC longitude %10.8f %c",nmea_radian2degree(dpos.lon),pack.ns); printf("GPRMC latitude %10.8f %c",nmea_radian2degree(dpos.lat),pack.ew); printf("Speed : %10.4f Km/h ",pack.speed); printf("direction : %10.4f ",pack.direction); } }