24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 2118  |  回复: 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)

我们都爱小木虫

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

科研从小木虫开始,人人为我,我为人人
相关版块跳转 我要订阅楼主 疯鸟嘛 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿华中农业071010,总分320求调剂 +5 困困困困坤坤 2026-04-02 5/250 2026-04-02 15:51 by wangjagri
[考研] 材料求调剂 一志愿哈工大总分298分,前三科223分 +12 dongfang59 2026-03-27 12/600 2026-04-02 12:26 by ms629
[考研] 一志愿厦门大学材料工程专硕354找调剂!!! +7 贝呗钡钡 2026-03-30 7/350 2026-04-02 12:19 by 1753564080
[考研] 337求调剂 +11 《树》 2026-03-29 11/550 2026-04-02 10:20 by 不吃魚的貓
[考研] 一志愿安徽大学计算机科学与技术学硕,331分求调剂 +5 蒋昌鹏qtj 2026-04-01 5/250 2026-04-02 08:10 by fxue1114
[考研] 302求调剂一志愿北航070300,本科郑大化学 +8 圣日耳曼条 2026-04-01 11/550 2026-04-02 07:40 by chemdavid
[考研] 化学工程专硕324分,一志愿中国矿业大学求调剂 +7 耿耿1314 2026-04-01 7/350 2026-04-02 07:40 by 尚水阁主
[考研] 350求调剂 +7 阿佳~ 2026-03-31 7/350 2026-04-01 16:12 by yanflower7133
[考研] 材料与化工调剂一志愿大连海事085600,349 +9 吃的不少 2026-03-30 9/450 2026-04-01 11:24 by wangjy2002
[考研] 070300求调剂306分 +5 26要上岸 2026-03-27 5/250 2026-04-01 11:09 by oooqiao
[考研] 318一志愿吉林大学生物与医药 求调剂 +6 笃行致远. 2026-03-28 6/300 2026-04-01 09:28 by oooqiao
[考研] 求调剂:085600材料与化工,考材科基,总分319 +17 678lucky 2026-03-31 21/1050 2026-04-01 01:40 by 1018329917
[考研] 材料科学与工程求调剂 +13 深V宿舍吧 2026-03-29 13/650 2026-03-31 19:50 by Dyhoer
[考研] 340求调剂 +4 希望如此i 2026-03-31 4/200 2026-03-31 16:40 by 690616278
[考研] 262求调剂 +7 ZZ..000 2026-03-30 8/400 2026-03-31 10:05 by cal0306
[考研] 293分求调剂,外语为俄语 +5 加一一九 2026-03-31 5/250 2026-03-31 09:39 by zhshch
[有机交流] 考研调剂 +8 watb 2026-03-26 8/400 2026-03-30 18:40 by 544594351
[考研] 328求调剂 +8 嗯滴的基本都 2026-03-27 8/400 2026-03-30 17:20 by Wang200018
[考研] 一志愿南京航空航天大学材料学硕求调剂 +3 @taotao 2026-03-28 3/150 2026-03-28 10:26 by JourneyLucky
[考研] 265求调剂 +8 小木虫085600 2026-03-27 8/400 2026-03-27 22:16 by 无际的草原
信息提示
请填处理意见