24小时热门版块排行榜    

查看: 2106  |  回复: 0

疯鸟嘛

新虫 (初入文坛)

[求助] 帮忙看看这个GPS的数据解析程序

请教那些弄过GPS的大神,        我想问一下那些解析出来的数据在buf数组里面是怎么存储的,
// 例:$GPRMC,080655.00,A,4546.40891,N,12639.65641,E,1.045,328.42,170809,,,A*60  这就是解析出来后的数据存在buf
int GPS_RMC_Parse(char *line,GPS_INFO *GPS)                        //解析GPRMC的数据
{
        uchar ch, status, tmp;
        float lati_cent_tmp, lati_second_tmp;
        float long_cent_tmp, long_second_tmp;
        float speed_tmp;
        char *buf = line;                         //一个字符当做一个数组元素??                        //line是串口接收的一行数据                
        ch = buf[5];                                       
        status = buf[GetComma(2, buf)];         //GetComma函数作用是计算字符串中逗号的位置
                                        //           status = buf[GetComma(2, buf)];等价于status = buf[];
        if (ch == 'C')  //如果第五个字符是C,($GPRMC)      
        {
                if (status == 'A')  //如果数据有效,则分析      
                {
                        GPS -> NS       = buf[GetComma(4, buf)];        //从Get_Double_Number这个函数似乎又不是直接将一个字符当做一个数组元素
                                                                               //这些数字都是那个协议里面固定的。          。。。这个又是buf几。。
                        GPS -> EW       = buf[GetComma(6, buf)];                         //buf里面的数组元素是怎么排布的。

                        GPS->latitude   = Get_Double_Number(&buf[GetComma(3, buf)]); //Get_Double_Number函数作用是把给定字符串第一个逗号之前的字符转化为双精度型
                        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)]); //角度                          
                          //因为前面六位是固定的,例:GPRMC, 就像是这样。时间可以不用调用        GetComma函数 去算出他在字符串的位置
                        GPS->D.hour    = (buf[7] - '0') * 10 + (buf[8] - '0');                //时间           减‘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);           //GetComma函数作用是一行数据中        逗号的位置
                        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);          //UTC2BTC函数就是讲世界时间转化为北京时间(相差8小时)
                       
                        return 1;
                }               
        }
       
        return 0;
}
回复此楼

» 猜你喜欢

生活永远不是一个人在战斗
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

找到一些相关的精华帖子,希望有用哦~

科研从小木虫开始,人人为我,我为人人
相关版块跳转 我要订阅楼主 疯鸟嘛 的主题更新
信息提示
请填处理意见