From 4cdc4b3d488e15b1d6572bdcd61a2ce92d0c8c9b Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期五, 16 五月 2025 18:13:14 +0800 Subject: [PATCH] 成功分离2个测距功能 --- keil/include/main/main.c | 152 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 111 insertions(+), 41 deletions(-) diff --git a/keil/include/main/main.c b/keil/include/main/main.c index f98589e..6c9ab6b 100644 --- a/keil/include/main/main.c +++ b/keil/include/main/main.c @@ -50,6 +50,9 @@ #include "mk_uart.h" #include "mk_spi.h" #include "mk_flash.h" +#include "Usart.h" +#include <serial_at_cmd_app.h> +#include <global_param.h> #include "board.h" @@ -109,7 +112,12 @@ // //***************************************************************************** #define WSF_BUF_POOLS 5 -void Fira_Ranging_Task(void); +void Fira_Change_Task(void); +extern uint8_t normal_flag,log_4g_enable_flag; +extern uint16_t ip0,ip1,ip2,ip3,port; +uint8_t group_id,enable_sleep_count; +uint32_t dev_id; +uint16_t disoffset; // Default pool descriptor. static wsfBufPoolDesc_t poolDescriptors[WSF_BUF_POOLS] = { {32, 26}, {64, 24}, {128, 4}, {256 + 32, 4}, {1024 + 32, 2}, @@ -119,6 +127,37 @@ { // LOG_INFO(TRACE_MODULE_APP, "Wake up by sleep timer %d\r\n", time); } +void Program_Init(void) +{ + Usart1ParseDataCallback = UsartParseDataHandler;//需改为默认为gps处理,UsartParseDataHandler为升级处理当调试时候改为 + parameter_init_anchor();//g_com_map表初始化角色默认为基站 + dev_id=g_com_map[DEV_ID];//这里不太对 + group_id=(uint8_t)g_com_map[GROUP_ID];//组ID +// tag_frequency = 1000/g_com_map[COM_INTERVAL];//测距频率这个存的是测距时间 + memcpy(&disoffset,&g_com_map[DIST_OFFSET],2); +// g_com_map[ALARM_DISTANCE1] = 40; +// g_com_map[ALARM_DISTANCE2] = 40; +// warning_distance=g_com_map[ALARM_DISTANCE1]; +// prewarning_distance=g_com_map[ALARM_DISTANCE2]; + //g_com_map[SEND_4G_SECOND] +// if(g_com_map[SEND_4G_SECOND]<30) +// { +// gps_open_flag=0; +// }else{ +// gps_open_flag=1; +// } + g_com_map[MODBUS_MODE] = 0; + log_4g_enable_flag=g_com_map[LOG_4G_ENABLE]; + ip0 = (g_com_map[TCP_IP_0]>>12&0xf)*1000+(g_com_map[TCP_IP_0]>>8&0xf)*100+(g_com_map[TCP_IP_0]>>4&0xf)*10+(g_com_map[TCP_IP_0]&0xf); + ip1 = (g_com_map[TCP_IP_1]>>12&0xf)*1000+(g_com_map[TCP_IP_1]>>8&0xf)*100+(g_com_map[TCP_IP_1]>>4&0xf)*10+(g_com_map[TCP_IP_1]&0xf); + ip2 = (g_com_map[TCP_IP_2]>>12&0xf)*1000+(g_com_map[TCP_IP_2]>>8&0xf)*100+(g_com_map[TCP_IP_2]>>4&0xf)*10+(g_com_map[TCP_IP_2]&0xf); + ip3 = (g_com_map[TCP_IP_3]>>12&0xf)*1000+(g_com_map[TCP_IP_3]>>8&0xf)*100+(g_com_map[TCP_IP_3]>>4&0xf)*10+(g_com_map[TCP_IP_3]&0xf); + port = g_com_map[TCP_PORT]; + g_com_map[VERSION] = (1<<8)|0; + LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); + LOG_INFO(TRACE_MODULE_APP,"固件版本:4G-GPS定位手环 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); + LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port); +} static void board_init(void) { @@ -127,6 +166,7 @@ // Clock configuration board_clock_run(); + boot_deinit();//新加的 // Pin configuration board_pins_config(); // Trace configuration @@ -163,6 +203,7 @@ // Configure IO_04 for RF Switch gpio_pin_set_dir(IO_PIN_4, GPIO_DIR_OUT, 0); #else + Program_Init(); // led board_led_init(); // board_led_on(BOARD_LED_1); @@ -191,13 +232,52 @@ break; } } -wsfHandlerId_t handlerId; -void Fira_Ranging_Task(void) + +void Fira_Change_Task(void) { - // +} + +static void uart_receive_callback(void *dev, uint32_t err_code) +{ + uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); +} + +int main(void) +{ + // Initialize MCU system + board_init(); + // Disable watchdog timer + wdt_close(WDT_ID0); + LOG_INFO(TRACE_MODULE_APP, "UCI FiRa example\r\n"); + if(gpio_pin_get_val(MODE_CHANGE_PIN)) + { + + + // Platform init for WSF + PalSysInit(); + + // Initialize os + + // + // Set up timers for the WSF scheduler. + // + WsfOsInit(); + WsfTimerInit(); + sys_tick_callback_set(WsfTimerUpdateTicks); + + // + // Initialize a buffer pool for WSF dynamic memory needs. + // + uint32_t wsfBufMemLen = WsfBufInit(WSF_BUF_POOLS, poolDescriptors); + + if (wsfBufMemLen > FREE_MEM_SIZE) + { + LOG_INFO(TRACE_MODULE_APP, "Memory pool is not enough %d\r\n", wsfBufMemLen - FREE_MEM_SIZE); + } +// // Create app task // - handlerId = WsfOsSetNextHandler(app_handler); + wsfHandlerId_t handlerId = WsfOsSetNextHandler(app_handler); app_init(handlerId); // @@ -212,6 +292,7 @@ uwb_test_init(handlerId); #endif +#ifndef MY_MODE uwb_open(); // set advanced parameters @@ -239,40 +320,12 @@ uwb_app_config.filter_en = (uint8_t)(FILTER_EN); uwb_app_config.session_param.tx_power_level = board_param.tx_power_fcc[CALIB_CH(uwb_app_config.ppdu_params.ch_num)]; uwb_app_config.ppdu_params.rx_ant_id = (uint8_t)(RX_MAIN_ANT_PORT); -} -int main(void) -{ - // Initialize MCU system - board_init(); - - // Disable watchdog timer - wdt_close(WDT_ID0); - LOG_INFO(TRACE_MODULE_APP, "UCI FiRa example\r\n"); - - // Platform init for WSF - PalSysInit(); - - // Initialize os - - // - // Set up timers for the WSF scheduler. - // - WsfOsInit(); - WsfTimerInit(); - sys_tick_callback_set(WsfTimerUpdateTicks); - - // - // Initialize a buffer pool for WSF dynamic memory needs. - // - uint32_t wsfBufMemLen = WsfBufInit(WSF_BUF_POOLS, poolDescriptors); - - if (wsfBufMemLen > FREE_MEM_SIZE) - { - LOG_INFO(TRACE_MODULE_APP, "Memory pool is not enough %d\r\n", wsfBufMemLen - FREE_MEM_SIZE); - } - - - + +#elif defined MY_MODE + Uwb_init();//默认为我们测距配置 + OpenUWB(); + uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); +#endif // // Create UCI transmission layer task // @@ -291,13 +344,30 @@ // Enable sleep timer sleep_timer_open(true, SLEEP_TIMER_MODE_ONESHOT, sleep_timer_callback); - + while (1) { wsfOsDispatcher(); +#ifdef MY_MODE + if(normal_flag) + { + IdleTask(); + } +#endif power_manage(); } - + }else{ +// adc_open(&usr_adc_cfg); + Uwb_init();//默认为我们测距配置 + OpenUWB(); + uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); + while (1) + { + uwb_app_poll();//我们的测距逻辑 + IdleTask(); + } + } + } void app_restore_from_power_down(void) -- Gitblit v1.9.3