From d0ecbb6b662da93cf85096bd628d41729cd47b24 Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期一, 11 十一月 2024 18:16:49 +0800 Subject: [PATCH] 手环加入上位机配置4G和GPS更新频率设置,加入供电过低保护,减少搜索为1s,震动逻辑变为10s停,500ms震,搜索模式加入校准时间函数,满足功耗稳定测距版本,加入SOS报警上传,初步加入查询伪代码,加入休眠唤醒逻辑 --- keil/uwb_app.c | 114 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 91 insertions(+), 23 deletions(-) diff --git a/keil/uwb_app.c b/keil/uwb_app.c index e61a15f..4c4ca1d 100644 --- a/keil/uwb_app.c +++ b/keil/uwb_app.c @@ -8,11 +8,14 @@ #include "dw_app_anchor.h" #include "global_param.h" #include "board.h" +#include "HIDO_TypeDef.h" extern int simple_main(void); extern int temp_main(void); +extern void Air780E_4G_POLL(void); void TagListUpdate(void); +void Calibration_Time(void); extern void IO_LED_control_change(uint8_t data); extern void IO_control_init(void); @@ -35,7 +38,7 @@ extern uint16_t tag_frequency; extern uint16_t disoffset; static uint8_t frame_len,recpoll_len,current_syncid,new_tagid,seize_anchor,result,g_start_sync_flag; -extern uint8_t gps_power_state,motor_power_state,uwb_state,air780_power_state,gps_success_state,chaging_state,changed_state,air780_success_state; +extern uint8_t gps_power_state,motor_power_state,uwb_state,air780_power_state,gps_success_state,red_charge_state,green_charge_state,air780_success_state; int poll_rx_num,resp_tx_num; //resp函数 void PushAnchorDataArray(uint16_t ancid,int16_t dist,uint8_t battary);//找到自己的id信息对应位置更新自己的交互信息 @@ -79,7 +82,7 @@ /* RX window open in advance */ #define RX_WIN_IN_ADVANCE_US (150) -#define DELAY_BETWEEN_TWO_FRAME_UUS 1400 +#define DELAY_BETWEEN_TWO_FRAME_UUS 600 //yuan1400 /* Field index in frame */ #define MSG_SEQ_NUM_IDX 2 @@ -263,6 +266,8 @@ } } uint32_t start_receive_count,end_receive_count,poll_timeout,current_count,temp_resp; +uint32_t start_receive_count_calibration; +uint32_t current_count_calibration; static uint16_t anchordata_id[TAG_NUM_IN_SYS],anchordata_dist[TAG_NUM_IN_SYS]; static uint8_t anchordata_bat[TAG_NUM_IN_SYS]; uint8_t anchordata_num = 0; @@ -270,6 +275,8 @@ uint16_t random_time; //anchor int32_t hist_dist; +int16_t temp_recdist_before_offset; +int16_t dist_temp; void PushAnchorDataArray(uint16_t ancid,int16_t dist,uint8_t battary) { uint8_t i; @@ -290,8 +297,14 @@ anchordata_dist[i] = dist; anchordata_bat[i] = battary; tagofflinetime[i]=0;//不断更新当前TAG对应离线时间 + dist_temp=dist; // if(dist>0) + if(temp_recdist_before_offset!=0&&distance!=0x1ffff) + { distance=dist*0.5+distance*0.5; + }else{ + distance=dist; + } } uint16_t CmpTagInList(uint16_t tagid) { uint16_t i; @@ -362,12 +375,17 @@ uwb_tx(send_buffer, 40,1 ,resp_tx_en_start_u32);//立即发送测试size大小 temp_count1=phy_timer_count_get(); while(mac_is_busy()); + #ifdef BO_XING gpio_pin_clr(SCL_PIN); + #endif } uint32_t range_timeout_us = 5000; uint16_t uwb_searchcount; uint8_t flag_recsuccess; -extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag; +uint8_t secondtask_search_count,secondtask_search_flag; +uint8_t flag_temp2,flag_temp1; +extern HIDO_UINT32 u32CurTick; +extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag,flag_secondtask; int UwbRange(void) { uint8_t i; @@ -399,8 +417,11 @@ receive_flag = 0; flag_recsuccess = 0; temp_count3=phy_timer_count_get(); + #ifdef BO_XING gpio_pin_set(SCL_PIN); - uwb_rx(0, 0, range_timeout_us);//开启接收 + #endif + flag_temp1=uwb_rx(0, 0, range_timeout_us);//开启接收 + // while(mac_is_busy()); // temp_count2=phy_timer_count_get(); start_receive_count=phy_timer_count_get(); @@ -413,8 +434,12 @@ { current_count=phy_timer_count_get(); while(mac_is_busy()) - { + { + +// MotorPoll(); IdleTask(); + UserKeyTask(); + IMUTask(); current_count=phy_timer_count_get(); if(current_count>end_receive_count&¤t_count<end_receive_count+HALF_SECOND_TIME) { @@ -426,8 +451,8 @@ { if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL&&!memcmp(&rx_buf[TAG_ID_IDX],&g_com_map[BIND_DEV_ID],2))//判断是否是和自己是同一组通讯的且为poll包 - { flag_recsuccess = 1; - sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试 + { flag_recsuccess = 1; + sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试 temp_count2=phy_timer_count_get(); frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序 battary = rx_buf[BATTARY_IDX]; @@ -439,7 +464,7 @@ for(i=0; i<rec_nearbase_num; i++) { if(rec_ancidlist[i] == dev_id) - { + { temp_recdist_before_offset=rec_ancdistlist[i]; rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET]; PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary); } @@ -459,16 +484,18 @@ { seize_anchor=1; //抢占anchor Anchor_RecNearPoll(i); - } recev_error_num=0; - + range_timeout_us=5000;//恢复为5000进入range后 LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度:%d.\r\n",g_com_map[BIND_DEV_ID],distance,rssi); + #ifdef BO_XING + gpio_pin_clr(SCL_PIN); + #endif break; } - } else { - uwb_rx(0, 0, range_timeout_us); - } + } + //失败或者接受被高发射机打断都会再次开启接收 + flag_temp1=uwb_rx(0, 0, range_timeout_us); } delay_us(1); uwb_rx_force_off(1); @@ -485,11 +512,39 @@ } } - gpio_pin_clr(SCL_PIN); + return 0; } +void Calibration_Time(void) +{ + current_count_calibration=phy_timer_count_get(); + if((current_count_calibration-start_receive_count_calibration>=MS_TO_PHY_TIMER_COUNT(500)||current_count_calibration+(UINT32_MAX-start_receive_count_calibration)>=MS_TO_PHY_TIMER_COUNT(500)) + &&!((end_receive_count-current_count_calibration<=MS_TO_PHY_TIMER_COUNT(200))||(end_receive_count+(UINT32_MAX-current_count_calibration)<=MS_TO_PHY_TIMER_COUNT(200)))) + { + start_receive_count_calibration=current_count_calibration;//更新开始时间 + MotorPoll(); + + if(secondtask_search_count++%2==0) + { + secondtask_search_flag = 1; + }else{ + secondtask_search_flag = 0; + } + if(secondtask_search_flag)//更新S时间TICK + { + HIDO_TimerTick(); + TagListUpdate(); + GPS_Poll(); + } + update_led_power_state();//更新等状态防止震动卡死在搜索 + } +// if(current_count_calibration-start_receive_count_calibration>=MS_TO_PHY_TIMER_COUNT(1000)||current_count_calibration+(UINT32_MAX-start_receive_count_calibration)>=MS_TO_PHY_TIMER_COUNT(1000)) +// { +// HIDO_TimerTick(); +// } +} //主函数绑定接受逻辑 int UwbSearch(void) @@ -520,12 +575,16 @@ // Register rx interrupt callback function mac_register_process_handler(tx_int_callback, rx_int_callback); + receive_flag = 0; temp_count3=phy_timer_count_get(); + #ifdef BO_XING gpio_pin_set(SCL_PIN); - uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//开启接收 + #endif + flag_temp2=uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//开启接收 start_receive_count=phy_timer_count_get(); - poll_timeout=US_TO_PHY_TIMER_COUNT(2000000);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss + start_receive_count_calibration=start_receive_count; + poll_timeout=US_TO_PHY_TIMER_COUNT(1000000);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss end_receive_count=start_receive_count+poll_timeout; if(end_receive_count>=UINT32_MAX) { @@ -535,8 +594,10 @@ while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000 { while(mac_is_busy()) - { + { Calibration_Time(); IdleTask(); + UserKeyTask(); + IMUTask(); current_count=phy_timer_count_get(); if(current_count>end_receive_count&¤t_count<end_receive_count+HALF_SECOND_TIME) { @@ -549,7 +610,8 @@ { if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL&&!memcmp(&rx_buf[TAG_ID_IDX],&g_com_map[BIND_DEV_ID],2))//判断是否是和自己是同一组通讯的且为poll包 { - sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-1));//测试 + sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-13));//测试 + range_timeout_us=20000;//将下次range开启后超时时间设为20ms之后再range里恢复 temp_count2=phy_timer_count_get(); frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序 battary = rx_buf[BATTARY_IDX]; @@ -562,6 +624,8 @@ { if(rec_ancidlist[i] == dev_id) { + temp_recdist_before_offset=rec_ancdistlist[i]; + rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET]; PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary); } } @@ -581,20 +645,23 @@ seize_anchor=1; //抢占anchor Anchor_RecNearPoll(i); } - + #ifdef BO_XING gpio_pin_clr(SCL_PIN);//测试 + #endif + LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度:%d.\r\n",g_com_map[BIND_DEV_ID],distance,rssi); return 1;//返回发送成功标志 } } temp_count3=phy_timer_count_get(); - uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收 - + flag_temp2=uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收 } - delay_us(1); + delay_us(2); uwb_rx_force_off(1); // LOG_INFO(TRACE_MODULE_APP,"超时定时器:%x,%x,%x\r\n",start_receive_count,end_receive_count,current_count); + #ifdef BO_XING gpio_pin_clr(SCL_PIN);//测试 + #endif return 0;//返回绑定失败标志 } //} @@ -621,6 +688,7 @@ search_open_flag=0; uwb_led_on(); link_success_flag=UwbSearch();//第一次开启接收2s绑定失败后则进行下面1分钟后重新开启2s绑定流程 + Calibration_Time(); uwb_led_off(); if(link_success_flag) UWB_work_state=LINK_SUCCESS; @@ -653,7 +721,7 @@ //link_error_count+=g_com_map[COM_INTERVAL]; //if(link_error_count>=g_com_map[4G_INTERNAL]) //link_error_count=0; - update_led_power_state();//更新灯状态 + // update_led_power_state();//更新灯状态 } LOG_INFO(TRACE_MODULE_APP,"UWB状态:%d\r\n",UWB_work_state); } -- Gitblit v1.9.3