完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在添加了lwgps后,测试用例使用不了,有同学弄过这一块吗?我的怎么就是不行呢…. 我用的是和芯星通的GPS芯片。 //***************************************************************************** // 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); #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; } 测试打印如图所示
|
|
相关推荐
3个回答
|
|
lwgps_process(&h_lwgps, &ch, 1); 一个字节字符就想解析出来信息?
|
|
|
|
我也看到了,他是一个字节,具体的程序解析源码我没有去看,我现在修改好了。
|
|
|
|
对lwgps2rtt.c文件做了如下修改,大家可以对照,可以正确的解析GPS数据了。
//***************************************************************************** // 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. //! @} // //***************************************************************************** |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1109 浏览 0 评论
867 浏览 0 评论
7812 浏览 0 评论
如何使用python调起UDE STK5.2进行下载自动化下载呢?
3056 浏览 0 评论
开启全新AI时代 智能嵌入式系统快速发展——“第六届国产嵌入式操作系统技术与产业发展论坛”圆满结束
3121 浏览 0 评论
74145 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-12 01:51 , Processed in 0.719412 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号