From 13cd19475cb91e0eebdc79743e32e77a2a212f0e Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期一, 22 一月 2024 22:20:38 +0800
Subject: [PATCH] 修改部分代码

---
 Src/radio/Lora.c |  148 +++++++++++--------------------------------------
 1 files changed, 34 insertions(+), 114 deletions(-)

diff --git a/Src/radio/Lora.c b/Src/radio/Lora.c
index e2860ad..a3c10f7 100644
--- a/Src/radio/Lora.c
+++ b/Src/radio/Lora.c
@@ -9,6 +9,7 @@
 #include "string.h"
 #include "stdio.h"
 #include "delay.h"
+#include "dw_mbx_anc.h"
 static RadioEvents_t RadioEvents;
 #define USE_MODEM_LORA
 //#define USE_MODEM_FSK
@@ -83,7 +84,7 @@
                                                               //  2: 4/6,
                                                               //  3: 4/7,
                                                               //  4: 4/8]
-#define LORA_PREAMBLE_LENGTH_T                      96         // Same for Tx 
+#define LORA_PREAMBLE_LENGTH_T                      8         // 96         // Same for Tx 
 #define LORA_PREAMBLE_LENGTH_R                      64        // Same for Rx
 //#define LORA_PREAMBLE_LENGTH                      990         // Same for Tx and Rx
 #define LORA_SYMBOL_TIMEOUT                         0         // Symbols
@@ -114,6 +115,8 @@
     TX,
     TX_TIMEOUT,
 }States_t;
+
+static uint8_t flag_lora_wait_sync = 0;
 
 #define RX_TIMEOUT_VALUE                            1000
 #define BUFFER_SIZE                                 64 // Define the payload size here
@@ -154,82 +157,27 @@
     Radio.Sleep( );
 //printf("TX SUCCESS2\r\n");
 }
+static uint8_t rxbuffer[255],rxbuff_len;
+static uint16_t rec_lp_count;
+uint8_t GetLoraBufferAndLen(uint8_t* buffer,uint16_t* lp_count)
+{
+    memcpy(buffer,rxbuffer,rxbuff_len);
+    memcpy(lp_count,&rec_lp_count,2);
+    return rxbuff_len;
+}
 extern uint16_t tx_num;
 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
 {
-    BufferSize = size;
-    memcpy( RX_Buffer, payload, BufferSize );
+    rec_lp_count = HAL_LPTIM_ReadCounter(&hlptim1);
+    rxbuff_len = size;
+    memcpy( rxbuffer, payload, BufferSize );
     RssiValue = rssi;
     SnrValue = snr;
     
     Radio.Standby();
     
-    if(EnableMaster)
-    {
-      if(memcmp(RX_Buffer,PongMsg,4)==0)
-      {
-        LedToggle();//LED闪烁
-				printf("Master RXD PONG!\r\n");
-        
-      }
-
-			
-//			HAL_Delay_nMS(1000);
-//     
-//        TX_Buffer[0] = 'P';
-//        TX_Buffer[1] = 'I';
-//        TX_Buffer[2] = 'N';
-//        TX_Buffer[3] = 'G'; 
-//        
-////        crc_value=RadioComputeCRC(TX_Buffer,4,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
-////        TX_Buffer[4]=crc_value>>8;
-////        TX_Buffer[5]=crc_value;
-////        //Radio.Send( TX_Buffer, 6);
-//			  Radio.Send( TX_Buffer, 4);
-			
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_SET);
-//		    printf("Master TXD PING!\r\n");
-//			  HAL_Delay_nMS( 1 );
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_RESET);	  			
-			
-			  //printf("Master TXD PING!\r\n");
-    }
-    else
-    {
-      if(memcmp(RX_Buffer,PingMsg,4)==0)
-      {
-				
-//				HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_SET);
-				printf("Slave  RXD PING!\r\n");
-//			  HAL_Delay_nMS( 1 );
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_RESET);	
-				
-//        LedToggle();//LED闪烁
-				//printf("Slave  RXD PING!\r\n");
-				
-//				T_R_Init(1);	
-        
-//        TX_Buffer[0] = 'P';
-//        TX_Buffer[1] = 'O';
-//        TX_Buffer[2] = 'N';
-//        TX_Buffer[3] = 'G'; 
-				
-        
-//        crc_value=RadioComputeCRC(TX_Buffer,4,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
-//        TX_Buffer[4]=crc_value>>8;
-//        TX_Buffer[5]=crc_value;
-//        //Radio.Send( TX_Buffer, 6);
-				
-			
-				Radio.Send( TX_Buffer, 4);
-				printf("Slave TXD PONG!\r\n");
-      }
-      else
-      {
-        Radio.Rx( RX_TIMEOUT_VALUE ); 
-				printf("Slave TXD XXXX\r\n");
-      }   
-    }
+    flag_lora_wait_sync = 0;
+    SetFlagSyncSuccess(1);
 }
 
 void OnTxTimeout( void )
@@ -240,56 +188,13 @@
 void OnRxTimeout( void )
 {
     Radio.Standby();
-    if(EnableMaster)
-    {
-        TX_Buffer[0] = 'P';
-        TX_Buffer[1] = 'I';
-        TX_Buffer[2] = 'N';
-        TX_Buffer[3] = 'G'; 
-        
-//        crc_value=RadioComputeCRC(TX_Buffer,4,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
-//        TX_Buffer[4]=crc_value>>8;
-//        TX_Buffer[5]=crc_value;
-        //Radio.Send( TX_Buffer, 6);
-			  Radio.Send( TX_Buffer, 4);
-			
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_SET);
-//			  HAL_Delay_nMS( 1 );
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_RESET);	  		
-			  printf("Master TXD PING!\r\n");
-    }
-    else
-    {
-      Radio.Rx( RX_TIMEOUT_VALUE ); 
-    }
+    flag_lora_wait_sync = 0;
 }
 
 void OnRxError( void )
 {
-
+    flag_lora_wait_sync = 0;
     Radio.Standby();
-    if(EnableMaster)
-    {
-        TX_Buffer[0] = 'P';
-        TX_Buffer[1] = 'I';
-        TX_Buffer[2] = 'N';
-        TX_Buffer[3] = 'G'; 
-        
-//        crc_value=RadioComputeCRC(TX_Buffer,4,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
-//        TX_Buffer[4]=crc_value>>8;
-//        TX_Buffer[5]=crc_value;
-        //Radio.Send( TX_Buffer, 6);
-			  Radio.Send( TX_Buffer, 4);
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_SET);
-//			  HAL_Delay_nMS( 1 );
-//			  HAL_GPIO_WritePin( OUT1_GPIO_Port, OUT1_Pin,GPIO_PIN_RESET);	  		
-			  printf("Master TXD PING!\r\n");
-    }
-    else
-    {
-      Radio.Rx( RX_TIMEOUT_VALUE ); 
-    }
-  
 }
 
 
@@ -378,3 +283,18 @@
 //          TX_Buffer[5]=crc_value;
 
 }
+#define SYNC_CHANNEL_FRQ 48000000
+uint8_t GetFlagLoraWaitSync(void)
+{
+    return flag_lora_wait_sync;
+}
+void SwitchLoraToSyncRec()
+{
+    RadioEvents.RxDone = OnRxDone;
+    RadioEvents.RxTimeout = OnRxTimeout;
+    RadioEvents.RxError = OnRxError;
+    Radio.Init( &RadioEvents );
+    Radio.SetChannel( SYNC_CHANNEL_FRQ );	
+    flag_lora_wait_sync = 1;  
+}
+

--
Gitblit v1.9.3