From ee0d5aab5ecbbd265660cba45c8a1946005b8f8c Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期三, 18 九月 2024 13:49:17 +0800
Subject: [PATCH] v1.30,把gcom表1搬到表2的时候往后挪,防止保存出错一直重启。

---
 Src/radio/Lora.c |   76 +++++++++++++++++++++++++++++--------
 1 files changed, 59 insertions(+), 17 deletions(-)

diff --git a/Src/radio/Lora.c b/Src/radio/Lora.c
index 078cfaf..da6839b 100644
--- a/Src/radio/Lora.c
+++ b/Src/radio/Lora.c
@@ -14,6 +14,7 @@
 #include "dw_mbx_tag.h"
 #include "Flash.h"
 #include "dw_driver.h"
+#include "WS2812.h"
 static RadioEvents_t RadioEvents;
 #define USE_MODEM_LORA
 //#define USE_MODEM_FSK
@@ -169,6 +170,7 @@
 uint32_t lora_zhuangtai;
 uint16_t current_count;
 extern wg_state_enum wg_state;
+extern u8 uwb_rxflag;
 void OnTxDone( void )
 {  
     if(flag_writepara_needreset) //配置写入完成设备需要重启
@@ -184,7 +186,16 @@
     }
     else
     {
-    Radio.Rx( 100 ); 
+        if(uwb_rxflag)
+        {
+        uwb_rxflag=0;
+        UWB_RXOFF();   
+        Radio.Rx( 50 ); 
+        }
+        else
+        {
+        Radio.Rx( 50 ); 
+        }
     } 
 }
 extern LPTIM_HandleTypeDef hlptim1;
@@ -241,11 +252,12 @@
 extern uint8_t report_ancnum;
 static uint16_t delaytime = 1200;
 static uint16_t source_id;
-uint8_t rec_index;
+uint8_t rec_index,rec_secdelay;
 uint16_t rec_value,rec_delaytime,rx_count;
 uint16_t rec_value,rec_delaytime,rx_count,datalen_offset;
-int16_t target_count;
-uint8_t shengji_flag;
+int32_t target_count;
+uint8_t shengji_flag,time=5;
+extern uint32_t uwbled,gpsled,loraled,powerled;
 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
 {    uint16_t checksum1;
         BufferSize = size;
@@ -257,9 +269,8 @@
     lora_up_rec_flag=1;
     if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL)
     {
-            UWB_Wkup();
-            MbxTagUwbRec();       
-            HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效
+        UWB_RXStart(10);
+        delay_ms(time);
     }
     if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG)
     {
@@ -276,13 +287,19 @@
             if(!memcmp(&wg_report_id,&RX_Buffer[SOURCE_ID_IDX],2))
             {
                 wg_lost_count = 0;
+                loraled=GREEN;
                 switch(RX_Buffer[PWTAG_RW_FLAG_IDX])
                 {
                     case WGRSP_RWTAG_NONE:
                         current_count = HAL_LPTIM_ReadCounter(&hlptim1);
                         wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400;
                         memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2);
-                   
+                    rec_secdelay = RX_Buffer[PWTAG_SECDELAY_IDX];
+                    if(BufferSize!=13||rec_secdelay>20)
+                    {
+                        rec_secdelay = 0;
+                    }
+                    
                     if(report_ancnum<2)
                     {
                         datalen_offset = report_ancnum*85;
@@ -303,6 +320,8 @@
                         break;
                     case WGRSP_RWTAG_WRITE:
                         rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX];
+                        if(rec_index<=DEV_ID)
+                            return;
                         if(rec_index==0xDD)
                         {
                              if(usart5_state==1)
@@ -312,7 +331,7 @@
                              }
                             HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);
                             HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);    
-                            memcpy(&xiafayuyin_data,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],BufferSize-PWTAG_WRITE_VALUE_IDX);
+                            memcpy(&xiafayuyin_data,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],BufferSize-PWTAG_WRITE_VALUE_IDX-2);
                             yuyin_sendflag=1;           
                             yuyinzidongguan_time=0;             
                             yuyin_no_sleep_flag=1;  
@@ -352,6 +371,7 @@
     } 
     if(!no_rx_flag&&LoraUp_flag==0)
     {
+        if(RX_Buffer[MSG_TYPE_IDX]!=LORA_MSGTYPE_RANGEPOLL)
         SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
         Radio.Rx(0);
     }
@@ -420,16 +440,35 @@
 
     Radio.Init( &RadioEvents );
     SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],5,0); //切换lora接收频点  
-    if(active_flag)
-    {
+//    if(active_flag)
+//    {
     Radio.Rx( 0 ); 
-    }else{
-        Radio.Sleep();
-    }        
+//    }else{
+//        Radio.Sleep();
+//    }        
 //        Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
+    RadioGetStatus();
                                    
 }
+uint32_t IAP_JumpTo(uint32_t ApplicationAddress)
+{
+	uint32_t JumpAddress;
+	
+	if (((*(uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
+	{ 
+//HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
+//        __disable_irq();
+		JumpAddress = *(uint32_t*) (ApplicationAddress + 4);
+		
+		__set_MSP(*(uint32_t*) ApplicationAddress);         //Set MSP
+		
+		(*((void(*)(void))JumpAddress))();
+		 
+		return 1;
+	}	
 
+	return 0;
+}
 uint8_t send_lora_data[250];
 //extern uint8_t lora_recbuffer[255];
 uint8_t muqiandeshengjibao;
@@ -454,10 +493,11 @@
     memcpy(&send_lora_data[6],&crc16,2);
     huifushengjibao_flag=0;
     LoraUp_flag=1;
+//    SwitchLoraSettings(LORA_UPCHANNEL_FRQ,LORA_UPCHANNEL_SF,22); //切换lora升级频点      
     Radio.Send(send_lora_data,8);//基站发送升级确认回复
     Delay_Ms(1000); 
     SwitchLoraSettings(LORA_UPCHANNEL_FRQ,LORA_UPCHANNEL_SF,22); //切换lora升级频点  
-    delay_ms(200);   
+    delay_ms(200);    
     __disable_irq();
 //    FLASH_Read(APP_1OR2_ADRESS,(uint8_t*)&app1_or_app2,2);        
     final_bag_num=(rec_wenjian_daxiao/220)+1;//计算一共要请求多少包   
@@ -472,6 +512,7 @@
     __enable_irq();             
     while(1)
     {
+//        huifushengjibao_flag=1;
         if(huifushengjibao_flag==1)
         {lora_up_rec_flag=1;
             while(1)
@@ -538,10 +579,11 @@
                 if(muqiandeshengjibao==final_bag_num)
                 {
                 uint16_t tmp11 ,result11;
-                    tmp11=0XBB;
+                    tmp11=0XCC;
                 result11 = FLASH_Prepare(APP_1OR2_ADRESS, PAGE_SIZE);
                 if(result11)
-                result11 = FLASH_Write(APP_1OR2_ADRESS, (const uint8_t*)&tmp11, 2); 
+                result11 = FLASH_Write(APP_1OR2_ADRESS, (const uint8_t*)&tmp11, 2);
+                __disable_irq();                
                 Delay_Ms(1500);
                 HAL_NVIC_SystemReset();
                 }

--
Gitblit v1.9.3