小小工大 发表于 2014-6-17 05:59:39

新手求助,关于GPS解析出来数据怎么在数组里面存储

我想问一下就是GPS接收回来的数据包解析之后是怎么存储在buf数组里面。因为我想让数据显示在5110上面,所以就是需要知道数据在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;                        //这条语句不是说明了他是一个字符就当做一个数组元素么?                               
        status = buf;       //GetComma函数作用是计算字符串中逗号的位置          
        if (ch == 'C')                        //如果第五个字符是C,($GPRMC)      
        {
                if (status == 'A')//如果数据有效,则分析      
                {
                        GPS -> NS       = buf;       
                                                                       //这条语句好像是又说明了两个逗号之间的数据是当做一个数组元素。                                 
                        GPS -> EW       = buf;                       //buf里面的数组元素是怎么排布的。

                        GPS->latitude   = Get_Double_Number(&buf); //Get_Double_Number函数作用是把给定字符串第一个逗号之前的字符转化为双精度型
                        GPS->longitude= Get_Double_Number(&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);    //速度(单位:海里/时)   
                        GPS->speed   = speed_tmp * 1.85;                           //1海里=1.85公里   
                        GPS->direction = Get_Float_Number(&buf); //角度                          
                        GPS->D.hour    = (buf - '0') * 10 + (buf - '0');                //时间           减‘0’是        转化为十进制。
                        GPS->D.minute= (buf - '0') * 10 + (buf - '0');               
                        GPS->D.second= (buf - '0') * 10 + (buf - '0');
                        tmp = GetComma(9, buf);          
                        GPS->D.day   = (buf - '0') * 10 + (buf - '0'); //日期   
                        GPS->D.month   = (buf - '0') * 10 + (buf - '0');
                        GPS->D.year    = (buf - '0') * 10 + (buf - '0')+2000;

                        UTC2BTC(&GPS->D);          //UTC2BTC函数就是讲世界时间转化为北京时间(相差8小时)
                       
                        return 1;
                }               
        }
       
        return 0;
}
//====================================================================//
// 语法格式:static uchar GetComma(uchar num,char *str)
// 实现功能:计算字符串中各个逗号的位置
// 参    数:查找的逗号是第几个的个数,需要查找的字符串
// 返 回 值:0
//====================================================================//

static uchar GetComma(uchar num,char *str)
{
        uchar i,j = 0;
        int len=strlen(str);

        for(i = 0;i < len;i ++)
        {
                if(str == ',')
                        j++;
                if(j == num)
                        return i + 1;       
        }

        return 0;       
}

wye11083 发表于 2014-6-17 08:08:51

只保留坐标,用一个全局数组存。

小小工大 发表于 2014-6-17 12:26:07

wye11083 发表于 2014-6-17 08:08
只保留坐标,用一个全局数组存。

$GPRMC,080655.00,A,4546.40891,N,12639.65641,E,1.045,328.42,170809,,,A*60
您能不能说的明白一点啊?不太懂啊。
就拿080655.00来说,他是存在buf几里面呀?
是0,8,0,6,5,5各是buf数组的一个数组元素,还是其他的什么?
如果是将080655.00当做一个数组元素的话,那这个函数static uchar GetComma(uchar num,char *str)的意思不都变了吗?
求详解~~~

wye11083 发表于 2014-6-17 19:15:02

小小工大 发表于 2014-6-17 12:26
$GPRMC,080655.00,A,4546.40891,N,12639.65641,E,1.045,328.42,170809,,,A*60
您能不能说的明白一点啊? ...

这是GPRMC信令,给你一个网上找的文档:

如果没有太多要求,你只要存经纬度就可以了,所以两个数组搞定。

y_square 发表于 2014-6-17 19:36:40

数据在buf里面就是一个个ascii字符,每一个数组元素是ascii字符
页: [1]
查看完整版本: 新手求助,关于GPS解析出来数据怎么在数组里面存储