- int nmea_decode_test(void)
- {
- double deg_lat;//转换成[degree].[degree]格式的纬度
- double deg_lon;//转换成[degree].[degree]格式的经度
- nmeaINFO info; //GPS解码后得到的信息
- nmeaPARSER parser; //解码时使用的数据结构
- uint8_t new_parse=0; //是否有新的解码数据标志
-
- nmeaTIME beiJingTime; //北京时间
-
- uint8_t ucStatus;
- char cStr [ 1000 ] ;
- char str_buff[100];
-
- LCD_SetFont(&Font8x16);
- LCD_SetColors(RED,BLACK);
-
- ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH); /* 清屏,显示全黑 */
- /*设置字体颜色及字体的背景颜色*/
- LCD_SetColors(RED,BLACK);
-
- ILI9341_DispStringLine_EN(LINE(1)," Wildfire STM32-F103");
- ILI9341_DispStringLine_EN(LINE(2)," GPS module");
-
- /* 设置用于输出调试信息的函数 */
- 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(1)
- {
-
- 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(BLUE);
-
- ILI9341_DispStringLine_EN(LINE(5)," GPS Info:");
- /* 设置前景颜色(字体颜色)*/
- LCD_SetTextColor(WHITE);
-
- /* 显示时间日期 */
- sprintf(str_buff," Date:%4d/%02d/%02d ", beiJingTime.year+1900, beiJingTime.mon,beiJingTime.day);
- ILI9341_DispStringLine_EN(LINE(6),str_buff);
-
- sprintf(str_buff," Time:%02d:%02d:%02d", beiJingTime.hour,beiJingTime.min,beiJingTime.sec);
- ILI9341_DispStringLine_EN(LINE(7),str_buff);
- /* 纬度 经度*/
- sprintf(str_buff," latitude :%.6f ", deg_lat);
- ILI9341_DispStringLine_EN(LINE(8),str_buff);
-
- sprintf(str_buff," longitude :%.6f",deg_lon);
- ILI9341_DispStringLine_EN(LINE(9),str_buff);
-
- /* 正在使用的卫星 可见的卫星*/
- sprintf(str_buff," GPS Satellite in use :%2d ", info.satinfo.inuse);
- ILI9341_DispStringLine_EN(LINE(10),str_buff);
-
- sprintf(str_buff," GPS Satellite in view :%2d", info.satinfo.inview);
- ILI9341_DispStringLine_EN(LINE(11),str_buff);
- // /* 正在使用的卫星 可见的卫星*/
- // sprintf(str_buff," BDS Satellite in use :%2d ", info.BDsatinfo.inuse);
- // ILI9341_DispStringLine_EN(LINE(12),str_buff);
- //
- // sprintf(str_buff," BDS Satellite in view :%2d", info.BDsatinfo.inview);
- // ILI9341_DispStringLine_EN(LINE(13),str_buff);
-
- /* 海拔高度 */
- sprintf(str_buff," Altitude:%4.2f m", info.elv);
- ILI9341_DispStringLine_EN(LINE(12),str_buff);
-
- /* 速度 */
- sprintf(str_buff," speed:%4.2f km/h", info.speed);
- ILI9341_DispStringLine_EN(LINE(13),str_buff);
-
- /* 航向 */
- // sprintf(str_buff," Track angle:%3.2f deg", info.direction);
- // ILI9341_DispStringLine_EN(LINE(14),str_buff);
- DHT11_Data_TypeDef DHT11_Data;//声明
- DHT11_Read_TempAndHumidity ( & DHT11_Data );
- a1=DHT11_Data.humi_int;
- b1=DHT11_Data.humi_deci;
- c1=DHT11_Data.temp_int;
- d1=DHT11_Data.temp_deci;
- LCD_SetFont(&Font8x16);
- LCD_SetColors(WHITE ,BLACK);
- sprintf(dispBuff," humi:%d.%dRH temp:%d.%dC",a1,b1,c1,d1);
- LCD_ClearLine(LINE(14));
- ILI9341_DispStringLine_EN(LINE(14),dispBuff); //14行显示英文字符串
-
-
- printf ( "\r\n正在配置 ESP8266 ......\r\n" );
- macESP8266_CH_ENABLE();
-
- ESP8266_AT_Test ();
-
- ESP8266_Net_Mode_Choose ( STA );
- while ( ! ESP8266_JoinAP ( macUser_ESP8266_ApSsid, macUser_ESP8266_ApPwd ) );
-
- ESP8266_Enable_MultipleId ( DISABLE );
-
- while ( ! ESP8266_Link_Server ( enumTCP, macUser_ESP8266_TcpServer_IP, macUser_ESP8266_TcpServer_Port, Single_ID_0 ) );
-
- while ( ! ESP8266_UnvarnishSend () );
-
- printf ( "\r\n配置 ESP8266 完毕\r\n" );
-
- if ( DHT11_Read_TempAndHumidity ( & DHT11_Data ) == SUCCESS ) //读取 DHT11 温湿度信息
- {
- sprintf ( cStr, "\r\n检测成功!\r\n\r\n湿度为%d.%d %RH ,温度为 %d.%d℃ \r\n经度是%f ,纬度是%f\r\n",
- DHT11_Data .humi_int, DHT11_Data .humi_deci, DHT11_Data .temp_int, DHT11_Data.temp_deci, deg_lat,deg_lon);
- }
- printf ( "%s", cStr ); //打印读取 DHT11 温湿度信息
-
- ESP8266_SendString ( ENABLE, cStr, 0, Single_ID_0 ); //发送 DHT11 温湿度信息和GPS信息到网络调试助手
-
- if ( ucTcpClosedFlag ) //检测是否失去连接
- {
- ESP8266_ExitUnvarnishSend (); //退出透传模式
-
- do ucStatus = ESP8266_Get_LinkStatus (); //获取连接状态
- while ( ! ucStatus );
-
- if ( ucStatus == 4 ) //确认失去连接后重连
- {
- printf ( "\r\n正在重连热点和服务器 ......\r\n" );
-
- while ( ! ESP8266_JoinAP ( macUser_ESP8266_ApSsid, macUser_ESP8266_ApPwd ) );
-
- while ( ! ESP8266_Link_Server ( enumTCP, macUser_ESP8266_TcpServer_IP, macUser_ESP8266_TcpServer_Port, Single_ID_0 ) );
-
- printf ( "\r\n重连热点和服务器成功\r\n" );
- }
-
- while ( ! ESP8266_UnvarnishSend () );
-
- }
- }
-
- new_parse = 0;
- }
- }
- 这是GPS解析数据、LCD显示GPS和温度、WiFi传输GPS和温度的程序。有了WiFi传输函数LCD更新显示GPS和温度信息的频率变慢了。
复制代码 |