[应用方案] 单片机GPS定位

[复制链接]
 楼主| primojones 发表于 2023-11-20 08:52 | 显示全部楼层 |阅读模式
  1. int GPS_RMC_Parse(char *line,GPS_INFO *GPS)
  2. {
  3.     uchar 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.     if (ch == 'C')  //如果第五个字符是C,($GPRMC)
  11.     {
  12.         if (status == 'A')  //如果数据有效,则分析
  13.         {
  14.             GPS -> NS       = buf[GetComma(4, buf)];
  15.             GPS -> EW       = buf[GetComma(6, buf)];

  16.             GPS->latitude   = Get_Double_Number(&buf[GetComma(3, buf)]);
  17.             GPS->longitude  = Get_Double_Number(&buf[GetComma( 5, buf)]);

  18.                GPS->latitude_Degree  = (int)GPS->latitude / 100;       //分离纬度
  19.             lati_cent_tmp         = (GPS->latitude - GPS->latitude_Degree * 100);
  20.             GPS->latitude_Cent    = (int)lati_cent_tmp;
  21.             lati_second_tmp       = (lati_cent_tmp - GPS->latitude_Cent) * 60;
  22.             GPS->latitude_Second  = (int)lati_second_tmp;

  23.             GPS->longitude_Degree = (int)GPS->longitude / 100;    //分离经度
  24.             long_cent_tmp         = (GPS->longitude - GPS->longitude_Degree * 100);
  25.             GPS->longitude_Cent   = (int)long_cent_tmp;   
  26.             long_second_tmp       = (long_cent_tmp - GPS->longitude_Cent) * 60;
  27.             GPS->longitude_Second = (int)long_second_tmp;

  28.             speed_tmp      = Get_Float_Number(&buf[GetComma(7, buf)]);    //速度(单位:海里/时)
  29.             GPS->speed     = speed_tmp * 1.85;                           //1海里=1.85公里
  30.             GPS->direction = Get_Float_Number(&buf[GetComma(8, buf)]); //角度            

  31.             GPS->D.hour    = (buf[7] - '0') * 10 + (buf[8] - '0');        //时间
  32.             GPS->D.minute  = (buf[9] - '0') * 10 + (buf[10] - '0');
  33.             GPS->D.second  = (buf[11] - '0') * 10 + (buf[12] - '0');
  34.             tmp = GetComma(9, buf);
  35.             GPS->D.day     = (buf[tmp + 0] - '0') * 10 + (buf[tmp + 1] - '0'); //日期
  36.             GPS->D.month   = (buf[tmp + 2] - '0') * 10 + (buf[tmp + 3] - '0');
  37.             GPS->D.year    = (buf[tmp + 4] - '0') * 10 + (buf[tmp + 5] - '0')+2000;

  38.             UTC2BTC(&GPS->D);
  39.             
  40.             return 1;
  41.         }        
  42.     }
  43.    
  44.     return 0;
  45. }
  46. 原文链接:https://blog.csdn.net/m0_74295839/article/details/128139872


hjl2832 发表于 2023-11-20 09:07 | 显示全部楼层
有没有推荐的GPS模块?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

41

主题

1530

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

41

主题

1530

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部