From 39499467e80152cc7e4a2de4f6628b158ccd98fd Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期一, 04 三月 2024 15:52:58 +0800
Subject: [PATCH] V1.6,修复uwb会被lptime打断进行lora发送的bug,会造成uwb不接收,读不到id等问题。

---
 Src/radio/Lora.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/Src/radio/Lora.c b/Src/radio/Lora.c
index 11a6036..c38f80b 100644
--- a/Src/radio/Lora.c
+++ b/Src/radio/Lora.c
@@ -113,7 +113,8 @@
 uint8_t Lora_rx_open_flag;
 extern u32 Loratx_frequency;
 
-uint8_t flag_writepara_needreset = 0,wg_lost_count;
+uint8_t flag_writepara_needreset = 0;
+uint32_t wg_lost_count = 10;
 uint32_t lora_zhuangtai;
 uint16_t current_count;
 extern wg_state_enum wg_state;
@@ -125,11 +126,8 @@
         SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
     }
     Radio.Standby();
-    Radio.Rx( 10 );
-    if(wg_lost_count++>3)
-    {
-        wg_state = WG_Lost;
-    }
+    Radio.Rx( 50 );
+    LED_TB_OFF;   
 }
 extern LPTIM_HandleTypeDef hlptim1;
 uint16_t current_time,start_time,end_time;
@@ -182,10 +180,11 @@
     Radio.Send(lora_sendbuffer,data_length+11);
   //  Delay_Ms(100);
 }
-static uint16_t delaytime = 1125;
+static uint16_t delaytime = 1050;
 static uint16_t source_id;
 uint8_t rec_index;
-uint16_t rec_value,rec_delaytime,target_count,rx_count;
+uint16_t rec_value,rec_delaytime,rx_count;
+int16_t target_count;
 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
 {   
         BufferSize = size;
@@ -219,7 +218,7 @@
                         current_count = HAL_LPTIM_ReadCounter(&hlptim1);
                         wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400;
                         memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2);                  
-                        target_count = current_count + rec_delaytime*32.8 - delaytime;
+                        target_count = current_count + rec_delaytime*3.2768 - delaytime;
                         if(target_count>=32768)
                             target_count-=32768;
                         __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
@@ -275,7 +274,13 @@
 void OnRxTimeout( void )
 {
     Radio.Standby();
+    current_count = HAL_LPTIM_ReadCounter(&hlptim1);
+    target_count-=current_count%3276;
+    if(target_count<0)
+        target_count+=32768;
+    __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
     SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
+    Radio.Rx(0);
 }
 
 void OnRxError( void )
@@ -311,7 +316,7 @@
 
     
 }
-
+extern u8 active_flag;
 void LoraInit(void)
 {
     RadioEvents.TxDone = OnTxDone;
@@ -322,7 +327,12 @@
 
     Radio.Init( &RadioEvents );
     SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],5,0); //切换lora接收频点  
-    Radio.Rx( 0 );                                   
+    if(active_flag)
+    {
+    Radio.Rx( 0 ); 
+    }else{
+        Radio.Sleep();
+    }        
 //        Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
                                    
 }

--
Gitblit v1.9.3