打印
[应用方案]

单片机GPS定位

[复制链接]
272|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
primojones|  楼主 | 2023-11-20 08:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
int GPS_RMC_Parse(char *line,GPS_INFO *GPS)
{
    uchar ch, status, tmp;
    float lati_cent_tmp, lati_second_tmp;
    float long_cent_tmp, long_second_tmp;
    float speed_tmp;
    char *buf = line;
    ch = buf[5];
    status = buf[GetComma(2, buf)];

    if (ch == 'C')  //如果第五个字符是C,($GPRMC)
    {
        if (status == 'A')  //如果数据有效,则分析
        {
            GPS -> NS       = buf[GetComma(4, buf)];
            GPS -> EW       = buf[GetComma(6, buf)];

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

               GPS->latitude_Degree  = (int)GPS->latitude / 100;       //分离纬度
            lati_cent_tmp         = (GPS->latitude - GPS->latitude_Degree * 100);
            GPS->latitude_Cent    = (int)lati_cent_tmp;
            lati_second_tmp       = (lati_cent_tmp - GPS->latitude_Cent) * 60;
            GPS->latitude_Second  = (int)lati_second_tmp;

            GPS->longitude_Degree = (int)GPS->longitude / 100;    //分离经度
            long_cent_tmp         = (GPS->longitude - GPS->longitude_Degree * 100);
            GPS->longitude_Cent   = (int)long_cent_tmp;   
            long_second_tmp       = (long_cent_tmp - GPS->longitude_Cent) * 60;
            GPS->longitude_Second = (int)long_second_tmp;

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

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

            UTC2BTC(&GPS->D);
            
            return 1;
        }        
    }
   
    return 0;
}
原文链接:https://blog.csdn.net/m0_74295839/article/details/128139872


使用特权

评论回复
沙发
hjl2832| | 2023-11-20 09:07 | 只看该作者
有没有推荐的GPS模块?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

28

主题

1086

帖子

0

粉丝