按NMEA-0813协议解析GPS数据

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.typedef data struct{

2. double latitude;//经度

3. double longitude;//纬度

4.int latitude_Degree;//度

5.int latitude_Cent;//分

6.int latitude_Second;//秒

7.int longitude_Degree;//度

8.int longitude_Cent;//分

9.int longitude_Second;//秒

10. float speed;//速度

11. float direction;//航向

12. float height;//海拔高度

13.int satellite;

14. U8 NS;

15. U8 EW;

16. DATE_TIME D;

17.}GPS_INFO;

时间结构体:

1.typedef struct{

2.int year;

3.int month;

4.int day;

5.int hour;

6.int minute;

7.int second;

8.}DATE_TIME;

核心算法就是解析GPRMC数据,得到经纬度,日期时间,速度,航向:

1.int GPS_RMC_Parse(char *line, GPS_INFO *GPS)

2.{

3. U8 ch, status, tmp;

4. float lati_cent_tmp, lati_second_tmp;

5. float long_cent_tmp, long_second_tmp;

6. float speed_tmp;

7. char *buf = line;

8. ch = buf[5];

9. status = buf[GetComma(2, buf)];

10.

11.if(ch =='C')//如果第五个字符是C,($GPRMC)

12.{

13.if(status =='A')//如果数据有效,则分析

14.{

15. GPS->NS = buf[GetComma(4, buf)];

16. GPS->EW = buf[GetComma(6, buf)];

17.

18. GPS->latitude = Get_Double_Number(&buf[GetComma(3, buf)]);

19. GPS->longitude = Get_Double_Number(&buf[GetComma(5, buf)]);

20.

21. GPS->latitude_Degree =(int)GPS->latitude / 100;//分离纬度

22. lati_cent_tmp =(GPS->latitude - GPS->latitude_Degree * 100);

23. GPS->latitude_Cent =(int)lati_cent_tmp;

24. lati_second_tmp =(lati_cent_tmp - GPS->latitude_Cent)* 60;

25. GPS->latitude_Second =(int)lati_second_tmp;

26.

27. GPS->longitude_Degree =(int)GPS->longitude / 100;//分离经度

28. long_cent_tmp =(GPS->longitude - GPS->longitude_Degree * 100);

29. GPS->longitude_Cent =(int)long_cent_tmp;

30. long_second_tmp =(long_cent_tmp - GPS->longitude_Cent)* 60;

31. GPS->longitude_Second =(int)long_second_tmp;

32.

33. speed_tmp = Get_Float_Number(&buf[GetComma(7, buf)]);//速度(单位:

海里/时)

34. GPS->speed = speed_tmp * 1.85;//1海里=1.85公里

35. GPS->direction = Get_Float_Number(&buf[GetComma(8, buf)]);//角

36.

37. GPS->D.hour=(buf[7]-'0')* 10 +(buf[8]-'0');//时间

38. GPS->D.minute=(buf[9]-'0')* 10 +(buf[10]-'0');

39. GPS->D.second=(buf[11]-'0')* 10 +(buf[12]-'0');

40. tmp = GetComma(9, buf);

41. GPS->D.day=(buf[tmp + 0]-'0')* 10 +(buf[tmp + 1]-'0');//日期

42. GPS->D.month=(buf[tmp + 2]-'0')* 10 +(buf[tmp + 3]-'0');

43. GPS->D.year=(buf[tmp + 4]-'0')* 10 +(buf[tmp + 5]-'0')+ 2000;

44.

45. UTC2BTC(&GPS->D);

46.

47. return 1;

48.}

49.}

50.

51. return 0;

52.}

相关文档
最新文档