Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
lwgps
5
添加lwgps包之后不能正确解析出经纬度、时间信息
发布于 2022-08-05 14:45:15 浏览:632
订阅该版
在添加了lwgps后,测试用例使用不了,有同学弄过这一块吗?我的怎么就是不行呢.... 我用的是和芯星通的GPS芯片。 ```c //***************************************************************************** // file : lwgps2rtt.c // porting lwgps to rt-thread // // Change Logs: // Date Author Note // 2020/09/05 Cheney First draft version // 2020/09/13 Cheney 1. Update the comments. // 2. Support gps info query interface. // 2020/10/10 Cheney Support macros LWGPS_CFG_STATUS // 2020/12/15 Cheney Configure the uart before using it. // //***************************************************************************** //***************************************************************************** // //! \addtogroup lwgps //! @{ // //***************************************************************************** #include
#include
#include
#include "lwgps.h" #ifndef GPS_MODULE_BAUD_RATE #define GPS_MODULE_BAUD_RATE BAUD_RATE_9600 #endif static lwgps_t h_lwgps; static rt_device_t serial = RT_NULL; static struct rt_semaphore rx_sem; static rt_thread_t lwgps_tid = RT_NULL; static rt_mutex_t lwgps_mutex = RT_NULL; /** * \brief gps uart date received callback * * \param dev: uart device * \param size: data size * \return rt_err_t: operation result. */ static rt_err_t uart_input(rt_device_t dev, rt_size_t size) { rt_sem_release(&rx_sem); return RT_EOK; } #if LWGPS_CFG_STATUS == 1 void lwgps_process_cbk(lwgps_statement_t res) { // TODO: give the interface to user. } #endif /** * \brief lwgps process thread * * \param parameter: input parameters. */ static void lwgps_thread_entry(void *parameter) { rt_uint8_t ch; while (RT_TRUE) { rt_sem_take(&rx_sem, RT_TICK_PER_SECOND); while (rt_device_read(serial, -1, &ch, 1) == 1) { rt_mutex_take(lwgps_mutex, RT_WAITING_FOREVER); rt_kprintf("%c",ch); #if LWGPS_CFG_STATUS == 1 lwgps_process(&h_lwgps, &ch, 1, lwgps_process_cbk); #else lwgps_process(&h_lwgps, &ch, 1); // rt_kprintf("Valid status: %d\r\n", h_lwgps.is_valid); // rt_kprintf("Latitude: %f degrees\r\n", h_lwgps.latitude); // rt_kprintf("Longitude: %f degrees\r\n", h_lwgps.longitude); // rt_kprintf("Altitude: %f meters\r\n", h_lwgps.altitude); #endif rt_mutex_release(lwgps_mutex); } } } /** * \brief get gps information * * \param gps_info: gps information. */ void lwgps2rtt_get_gps_info(lwgps_t *gps_info) { rt_mutex_take(lwgps_mutex, RT_WAITING_FOREVER); rt_memcpy(gps_info, &h_lwgps, (sizeof(h_lwgps) - sizeof(h_lwgps.p))); //rt_kprintf("latitude is %f\n",gps_info) rt_mutex_release(lwgps_mutex); } /** * \brief module init * * \param uart_dev_name: uart device name */ void lwgps2rtt_init(void) { serial = rt_device_find("uart3"); if (!serial) { rt_kprintf("uart find %s failed!\n", "uart3"); return; } struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; config.baud_rate = GPS_MODULE_BAUD_RATE; config.data_bits = DATA_BITS_8; config.stop_bits = STOP_BITS_1; config.parity = PARITY_NONE; rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config); lwgps_mutex = rt_mutex_create("lwgps_mutex", RT_IPC_FLAG_FIFO); rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO); rt_device_open(serial, RT_DEVICE_FLAG_INT_RX); rt_device_set_rx_indicate(serial, uart_input); lwgps_init(&h_lwgps); lwgps_tid = rt_thread_create("lwgps", lwgps_thread_entry, RT_NULL, 2048, 20, 4); if (lwgps_tid != RT_NULL) rt_thread_startup(lwgps_tid); } /** * \brief module deinit * */ void lwgps2rtt_deinit(void) { if (serial != RT_NULL) { rt_device_close(serial); rt_device_set_rx_indicate(serial, RT_NULL); } if (lwgps_tid != RT_NULL) { rt_thread_delete(lwgps_tid); } if (lwgps_mutex != RT_NULL) { rt_mutex_delete(lwgps_mutex); } serial = RT_NULL; lwgps_tid = RT_NULL; lwgps_mutex = RT_NULL; } INIT_APP_EXPORT(lwgps2rtt_init); ``` ```C #include
#define DBG_TAG "main" #define DBG_LVL DBG_LOG #include
#include "lwgps/lwgps.h" lwgps_t gps_info; int main(void) { int count = 1; while (1) { //LOG_D("Hello RT-Thread!"); //rt_thread_mdelay(1000); lwgps2rtt_get_gps_info(&gps_info); rt_kprintf("hour: %d\r\n", gps_info.hours); rt_kprintf("minute: %d\r\n", gps_info.minutes); rt_kprintf("seconds: %d\r\n", gps_info.seconds); rt_kprintf("Latitude: %f degrees\r\n", gps_info.latitude); rt_kprintf("Longitude: %f degrees\r\n", gps_info.longitude); rt_kprintf("Altitude: %f meters\r\n", gps_info.altitude); } return RT_EOK; } ``` 测试打印如图所示 ![xgy_20220805144247.jpg](https://oss-club.rt-thread.org/uploads/20220805/fe9e752f7fcdd2d31f888eac9591a6b0.jpg "xgy_20220805144247.jpg")
查看更多
3
个回答
默认排序
按发布时间排序
OGES_7242
2023-03-19
这家伙很懒,什么也没写!
![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230319/338561535b19e2b3080a5c7d1fa55341.png) 你好请问一下你的主函数是这样写的吗,我照着你的例程然后这样写了主函数,然后他在这给我报错了 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230319/2aef6555518393494faad2621ae9c482.png)
出出啊
2022-08-05
恃人不如自恃,人之为己者不如己之自为也
`lwgps_process(&h_lwgps, &ch, 1);` 一个字节字符就想解析出来信息?
xinggaoyong
2022-08-07
这家伙很懒,什么也没写!
对lwgps2rtt.c文件做了如下修改,大家可以对照,可以正确的解析GPS数据了。 ```c //***************************************************************************** // file : lwgps2rtt.c // porting lwgps to rt-thread // // Change Logs: // Date Author Note // 2020/09/05 Cheney First draft version // 2020/09/13 Cheney 1. Update the comments. // 2. Support gps info query interface. // 2020/10/10 Cheney Support macros LWGPS_CFG_STATUS // 2020/12/15 Cheney Configure the uart before using it. // //***************************************************************************** //***************************************************************************** // //! \addtogroup lwgps //! @{ // //***************************************************************************** #include
#include
#include
#include "lwgps.h" #ifndef GPS_MODULE_BAUD_RATE #define GPS_MODULE_BAUD_RATE BAUD_RATE_9600 #endif static lwgps_t h_lwgps; struct rt_ringbuffer rb ; static rt_uint8_t gpspool[200]; static rt_device_t serial = RT_NULL; static struct rt_semaphore rx_sem; static rt_thread_t lwgps_tid = RT_NULL; static rt_mutex_t lwgps_mutex = RT_NULL; static rt_mutex_t uart_mutex = RT_NULL; /** * \brief gps uart date received callback * * \param dev: uart device * \param size: data size * \return rt_err_t: operation result. */ static rt_err_t uart_input(rt_device_t dev, rt_size_t size) { rt_sem_release(&rx_sem); return RT_EOK; } #if LWGPS_CFG_STATUS == 1 void lwgps_process_cbk(lwgps_statement_t res) { // TODO: give the interface to user. } #endif /** * \brief lwgps process thread * * \param parameter: input parameters. */ static void lwgps_thread_entry(void *parameter) { rt_uint8_t ch[100]; rt_uint8_t arr[150]; rt_uint8_t count = 0,result; while (RT_TRUE) { rt_sem_take(&rx_sem, RT_WAITING_FOREVER); /*add by xinggaoyong */ result = rt_device_read(serial, -1, ch, 100); rt_ringbuffer_put(&rb, ch, result); count = count + result; if (count >= 100) { rt_mutex_take(lwgps_mutex, RT_WAITING_FOREVER); rt_ringbuffer_get(&rb, arr, count); #if LWGPS_CFG_STATUS == 1 lwgps_process(&h_lwgps, arr, count, lwgps_process_cbk); #else lwgps_process(&h_lwgps, arr, count); /*处理结束后,清零count*/ count = 0; #endif rt_mutex_release(lwgps_mutex); } } } /** * \brief get gps information * * \param gps_info: gps information. */ void lwgps2rtt_get_gps_info(lwgps_t *gps_info) { rt_mutex_take(lwgps_mutex, RT_WAITING_FOREVER); rt_memcpy(gps_info, &h_lwgps, (sizeof(h_lwgps) - sizeof(h_lwgps.p))); //rt_kprintf("latitude is %f\n",gps_info) rt_mutex_release(lwgps_mutex); } /** * \brief module init * * \param uart_dev_name: uart device name */ void lwgps2rtt_init(void) { rt_ringbuffer_init(&rb,gpspool,150); serial = rt_device_find("uart3"); if (!serial) { rt_kprintf("uart find %s failed!\n", "uart3"); return; } struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; config.baud_rate = GPS_MODULE_BAUD_RATE; config.data_bits = DATA_BITS_8; config.stop_bits = STOP_BITS_1; config.parity = PARITY_NONE; rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config); lwgps_mutex = rt_mutex_create("lwgps_mutex", RT_IPC_FLAG_FIFO); uart_mutex = rt_mutex_create("uart_mutex", RT_IPC_FLAG_FIFO); rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO); rt_device_open(serial, RT_DEVICE_FLAG_INT_RX); //rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); rt_device_set_rx_indicate(serial, uart_input); lwgps_init(&h_lwgps); lwgps_tid = rt_thread_create("lwgps", lwgps_thread_entry, RT_NULL, 2048, 20, 4); if (lwgps_tid != RT_NULL) rt_thread_startup(lwgps_tid); } /** * \brief module deinit * */ void lwgps2rtt_deinit(void) { if (serial != RT_NULL) { rt_device_close(serial); rt_device_set_rx_indicate(serial, RT_NULL); } if (lwgps_tid != RT_NULL) { rt_thread_delete(lwgps_tid); } if (lwgps_mutex != RT_NULL) { rt_mutex_delete(lwgps_mutex); } serial = RT_NULL; lwgps_tid = RT_NULL; lwgps_mutex = RT_NULL; } /*add by xinggaoyong*/ INIT_APP_EXPORT(lwgps2rtt_init); //***************************************************************************** // // Close the Doxygen group. //! @} // //***************************************************************************** ```
撰写答案
登录
注册新账号
关注者
0
被浏览
632
关于作者
xinggaoyong
这家伙很懒,什么也没写!
提问
4
回答
6
被采纳
0
关注TA
发私信
相关问题
1
使用Studio,选中lwgps 包后,studio中显式为灰色
2
lwgps获取时间不对的问题
3
移植lwgps,直接下载无法运行,debug模式可运行
4
使用lwgps如何获得gps数据
5
大家调试过的GPS模块有哪些?
6
在使用lwgps软件包时系统报错,报错信息如下
7
添加lwgps软件包后,程序运行出错
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
ota在线升级
UART
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
7
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部