小学生
最后登录1970-1-1
在线时间 小时
注册时间2018-5-3
|
我在改了nmea_decode_test,如下。我想实现,服务端发一个指令就获取一次GPS信息。
然后这里,执行前三次是正常,后面第四次就卡住了。我找不出原因,其他部分没变,GSM是正常的。
我觉得是缓冲区的问题,缓冲区512字节,一个GPS信息是163字节,刚好三条是正常的,有点像是DMA出问题,
我不太清楚是什么原因。怎么改。还请大佬们指点一下。下面附源码
int nmea_decode_test(void)
{
double deg_lat;//转换成[degree].[degree]格式的纬度
double deg_lon;//转换成[degree].[degree]格式的经度
// memset(gps_rbuff,0,HALF_GPS_RBUFF_SIZE);
// GPS_HalfTransferEnd=0;
// GPS_TransferEnd=0;
nmeaINFO info; //GPS解码后得到的信息
nmeaPARSER parser; //解码时使用的数据结构
uint8_t new_parse=0; //是否有新的解码数据标志
nmeaTIME beiJingTime; //北京时间
char str_buff[100];
/*使用不透明前景层*/
LCD_SetLayer(LCD_FOREGROUND_LAYER);
LCD_SetTransparency(0xff);
LCD_Clear(LCD_COLOR_BLACK); /* 清屏,显示全黑 */
/*设置字体颜色及字体的背景颜色(此处的背景不是指LCD的背景层!注意区分)*/
LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLACK);
LCD_DisplayStringLine(LINE(1),(uint8_t *)"Inno-Pointer STM32-F429");
LCD_DisplayStringLine(LINE(2),(uint8_t *)"GPS test");
/* 设置用于输出调试信息的函数 */
nmea_property()->trace_func = &trace;
nmea_property()->error_func = &error;
nmea_property()->info_func = &gps_info;
/* 初始化GPS数据结构 */
nmea_zero_INFO(&info);
nmea_parser_init(&parser);
while(new_parse==0)
{
if(GPS_HalfTransferEnd) /* 接收到GPS_RBUFF_SIZE一半的数据 */
{
/* 进行nmea格式解码 */
nmea_parse(&parser, (const char*)&gps_rbuff[0], HALF_GPS_RBUFF_SIZE, &info);
GPS_HalfTransferEnd = 0; //清空标志位
new_parse = 1; //设置解码消息标志
}
else if(GPS_TransferEnd) /* 接收到另一半数据 */
{
nmea_parse(&parser, (const char*)&gps_rbuff[HALF_GPS_RBUFF_SIZE], HALF_GPS_RBUFF_SIZE, &info);
GPS_TransferEnd = 0;
new_parse =1;
}
}
if(new_parse) //有新的解码消息
{
/* 对解码后的时间进行转换,转换成北京时间 */
GMTconvert(&info.utc,&beiJingTime,8,1);
/* 输出解码得到的信息 */
printf("\r\n时间%d-%02d-%02d,%d:%d:%d\r\n", beiJingTime.year+1900, beiJingTime.mon,beiJingTime.day,beiJingTime.hour,beiJingTime.min,beiJingTime.sec);
//info.lat lon中的格式为[degree][min].[sec/60],使用以下函数转换成[degree].[degree]格式
deg_lat = nmea_ndeg2degree(info.lat);
deg_lon = nmea_ndeg2degree(info.lon);
printf("\r\n纬度:%f,经度%f\r\n",deg_lat,deg_lon);
printf("\r\n海拔高度:%f 米 ", info.elv);
printf("\r\n速度:%f km/h ", info.speed);
printf("\r\n航向:%f 度", info.direction);
printf("\r\n正在使用的GPS卫星:%d,可见GPS卫星:%d",info.satinfo.inuse,info.satinfo.inview);
printf("\r\n正在使用的北斗卫星:%d,可见北斗卫星:%d",info.BDsatinfo.inuse,info.BDsatinfo.inview);
printf("\r\nPDOP:%f,HDOP:%f,VDOP:%f",info.PDOP,info.HDOP,info.VDOP);
/* 液晶输出 */
/* 设置前景颜色(字体颜色)*/
LCD_SetTextColor(LCD_COLOR_BLUE);
LCD_DisplayStringLine(LINE(5),(uint8_t *)"GPS Info:");
/* 设置前景颜色(字体颜色)*/
LCD_SetTextColor(LCD_COLOR_WHITE);
/* 显示时间日期 */
sprintf(str_buff,"Date:%04d/%02d/%02d Time:%02d:%02d:%02d", beiJingTime.year+1900, beiJingTime.mon,beiJingTime.day,beiJingTime.hour,beiJingTime.min,beiJingTime.sec);
LCD_DisplayStringLine(LINE(6),(uint8_t *)str_buff);
/* 纬度 经度*/
sprintf(str_buff,"latitude :%.6f", deg_lat);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(7),(uint8_t *)str_buff);
sprintf(str_buff,"longitude :%.6f",deg_lon);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(8),(uint8_t *)str_buff);
/* 正在使用的卫星 可见的卫星*/
sprintf(str_buff,"GPS Satellite in use :%2d ", info.satinfo.inuse);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(9),(uint8_t *)str_buff);
sprintf(str_buff,"GPS Satellite in view :%2d", info.satinfo.inview);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(10),(uint8_t *)str_buff);
/* 正在使用的卫星 可见的卫星*/
sprintf(str_buff,"BDS Satellite in use :%2d ", info.BDsatinfo.inuse);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(11),(uint8_t *)str_buff);
sprintf(str_buff,"BDS Satellite in view :%2d", info.BDsatinfo.inview);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(12),(uint8_t *)str_buff);
/* 海拔高度 */
sprintf(str_buff,"Altitude:%4.2f m", info.elv);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(13),(uint8_t *)str_buff);
/* 速度 */
sprintf(str_buff,"speed:%4.2f km/h", info.speed);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(14),(uint8_t *)str_buff);
/* 航向 */
sprintf(str_buff,"Track angle:%3.2f deg", info.direction);
if(gsm_gprs_send(str_buff)!=GSM_TRUE)
{
printf("\r\nTCP发送数据失败,请检测正确设置各个模块\r\n");
GSM_DELAY(1000);
printf("\nIP链接断开\n");
GSM_DELAY(100);
gsm_gprs_link_close();
printf("\n关闭场景\n");
GSM_DELAY(100);
gsm_gprs_shut_close();
while(1);
}
LCD_DisplayStringLine(LINE(15),(uint8_t *)str_buff);
new_parse = 0;
}
/* 释放GPS数据结构 */
// nmea_parser_destroy(&parser);
return 0;
}
|
|