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 |   67 ++++++++++++++++++++++++++++++---
 1 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/keil/uwb_app.c b/keil/uwb_app.c
index 11b4535..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信息对应位置更新自己的交互信息
@@ -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;
@@ -370,13 +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;
+uint8_t secondtask_search_count,secondtask_search_flag;
 uint8_t flag_temp2,flag_temp1;
-extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag;
+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;
@@ -408,7 +417,9 @@
     receive_flag = 0;
 		flag_recsuccess = 0;
     temp_count3=phy_timer_count_get();
+		#ifdef BO_XING
     gpio_pin_set(SCL_PIN);
+		#endif
     flag_temp1=uwb_rx(0, 0, range_timeout_us);//开启接收
 	
    // while(mac_is_busy());
@@ -423,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&&current_count<end_receive_count+HALF_SECOND_TIME)
             {
@@ -473,7 +488,9 @@
 						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;
 				}
     } 
@@ -500,6 +517,34 @@
 			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)
@@ -530,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);
+		#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)
     {
@@ -545,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&&current_count<end_receive_count+HALF_SECOND_TIME)
             {
@@ -594,8 +645,9 @@
                     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;//返回发送成功标志
             }
@@ -607,7 +659,9 @@
 		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;//返回绑定失败标志
 }
 //}
@@ -634,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;

--
Gitblit v1.9.3