From 48672f1db1e15655c83ff8590334df47225577d0 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期三, 24 一月 2024 10:30:54 +0800
Subject: [PATCH] 修改同步部分代码

---
 Src/application/dw_app.c |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c
index 99a5aea..a2d6bac 100644
--- a/Src/application/dw_app.c
+++ b/Src/application/dw_app.c
@@ -253,7 +253,7 @@
   {
     current_count=HAL_LPTIM_ReadCounter(&hlptim1);
     target_count = GetUwbPollCount();
-    SwitchLoraToSyncRec(UWB_CHANNEL_FRQ,5); //切换lora接收频点  
+    SwitchLoraSettings(UWB_CHANNEL_FRQ,5); //切换lora接收频点  
     while(current_count<target_count||current_count>target_count+16384)
     {
         current_count=HAL_LPTIM_ReadCounter(&hlptim1);
@@ -271,23 +271,26 @@
     bat_percent=Get_VDDVlotage();
     next_poll_state = Next_Poll_LORASYNC;
   }else{
-    current_count=HAL_LPTIM_ReadCounter(&hlptim1);
-    target_count = GetWGRecSyncCount()-2000/LPTIMER_LSB; //提前2ms进入接收状态
-    while(current_count<target_count||current_count>target_count+16384)
-    {
-        current_count=HAL_LPTIM_ReadCounter(&hlptim1);
-        if(current_count<target_count-300)
-        {
-            break;
-        }
-    }
-      LoraSyncRecPoll();
-      if(GetRangeState())
+     LoraSyncRecPoll();
+      if(GetRangeState())  //获取当前测距状态,是否开启。如果开启下次为测距,否为同步
       {
         next_poll_state = Next_Poll_RANGE;
       }else{
         next_poll_state = Next_Poll_LORASYNC;
-      }
-      
+      }      
+  }
+  if(next_poll_state == Next_Poll_LORASYNC)  
+  {
+   target_count = GetUwbPollCount()-4000/LPTIMER_LSB;  //同步则提前4ms唤醒,如果在同步间隔内,则会快速进入休眠。
+      if(target_count<0)
+      target_count+=32768;
+    __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
+  }else{
+
+        target_count = GetUwbPollCount()-2000/LPTIMER_LSB; //测距提前4ms唤醒
+     
+      if(target_count<0)
+      target_count+=32768;
+    __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
   }
 }

--
Gitblit v1.9.3