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 |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/keil/uwb_app.c b/keil/uwb_app.c
index 0010dbf..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);
 
@@ -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;
@@ -377,7 +382,9 @@
 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 HIDO_UINT32 u32CurTick;
 extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag,flag_secondtask;
 int UwbRange(void)
 {
@@ -427,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)
             {
@@ -506,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)
@@ -536,6 +575,7 @@
 
     // 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
@@ -543,7 +583,8 @@
 		#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)
     {
@@ -553,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)
             {
@@ -645,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