|
我想问一下就是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[5]; //这条语句不是说明了他是一个字符就当做一个数组元素么?
status = buf[GetComma(2, buf)]; //GetComma函数作用是计算字符串中逗号的位置
if (ch == 'C') //如果第五个字符是C,($GPRMC)
{
if (status == 'A') //如果数据有效,则分析
{
GPS -> NS = buf[GetComma(4, 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)]); //角度
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);
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;
}
//====================================================================//
// 语法格式: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[i] == ',')
j++;
if(j == num)
return i + 1;
}
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|