leiouyang / nmea0183-c Goto Github PK
View Code? Open in Web Editor NEWC代码解析NMEA0183协议数据(GPS)
C代码解析NMEA0183协议数据(GPS)
NMEA0183.h文件中
/* 数据解析状态结构体定义 /
typedef struct _gps_nmea
{
/ 数据解析状态 /
unsigned char parity; / 校验计算和 /
unsigned char is_checksum_term; / 当前字段域为校验字 /
char term[15]; / 当前字段域缓冲区,','为字段域分割符 /
unsigned char sentence_type; / 字段类别,见枚举 sentence_types*/
unsigned char term_number; /* 当前字段域序号 /
unsigned char term_offset; / 字段域数据偏移量 /
unsigned char gps_data_good; / GPS数据有效状态 */
/* 数据解析结果 */
// unsigned int new_time; /* UTC时间 /
// unsigned int new_date; / UTC日期 /
unsigned long new_time; / UTC时间 /
unsigned long new_date; / UTC日期 /
float new_latitude; / 纬度 /
float new_longitude; / 经度 /
int new_altitude; / 海拔高度 cm*/
float new_speed; /* 地速 km/h /
float new_course; / RMC、VTG字段磁偏角信息*/
float new_gps_yaw; /* HDT航向信息 /
unsigned short new_hdop; / 水平精度 *100 /
unsigned char new_satellite_count; / 当前使用卫星的颗数 /
unsigned char new_quality_indicator; / 定位状态 */
unsigned int last_RMC_ms; /* 最后更新字段时间 */
unsigned int last_GGA_ms;
unsigned int last_VTG_ms;
unsigned int last_HDT_ms;
}gps_nmea;
UTC时间 和 UTC日期使用unsigned int类型转换后结果不对,我改成unsigned long就可以了。
另外,NMEA0183.c文件中
// time and date
case GPS_SENTENCE_RMC + 1: // Time (RMC)
case GPS_SENTENCE_GGA + 1: // Time (GGA)
// pnmea->new_time = (unsigned int)(string_to_float((const char*)pnmea->term, (void*)0)1000); / ms /
pnmea->new_time =(unsigned long)(string_to_float((const char)pnmea->term, (void*)0)100); / ms /
break;
case GPS_SENTENCE_RMC + 9: // Date (GPRMC)
// pnmea->new_date = (unsigned int)sring_to_int((const char)pnmea->term, (void*)0);
pnmea->new_date =(unsigned long)string_to_float((const char*)pnmea->term, (void*)0);
break;
注释的语句是以前的,我把转换类型改成了unsigned long。
以上是我发现的问题。
基于你的库,我已经做好了一个GPS码表,4位数码管可以显示速度和时间,非常感谢你的开源!
/* 浮点数转换为字符串,包括整数转换为字符串
你的代码:
pnmea->new_latitude = (float)( ((unsigned int)pnmea->new_latitude) + (pnmea->new_latitude-((unsigned int)pnmea->new_latitude))/60.0 );
修改后的代码:
pnmea->new_latitude=(float)(((unsigned int)pnmea->new_latitude)+((pnmea->new_latitude-((unsigned int)pnmea->new_latitude))/60.0)*100
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.