From ed70b0682806d4659456fa28dd9bdd22fcb037ce Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期五, 06 十二月 2024 16:38:03 +0800 Subject: [PATCH] 功率测试最新代码 --- Src/radio/Lora.c | 96 +++++++++++------------------------------------ 1 files changed, 23 insertions(+), 73 deletions(-) diff --git a/Src/radio/Lora.c b/Src/radio/Lora.c index 50fe6ba..7a9751c 100644 --- a/Src/radio/Lora.c +++ b/Src/radio/Lora.c @@ -12,7 +12,6 @@ #include "main.h" #include <stdlib.h> #include "dw_mbx_tag.h" -#include "WS2812.h" static RadioEvents_t RadioEvents; #define USE_MODEM_LORA //#define USE_MODEM_FSK @@ -20,6 +19,7 @@ void Lora47xrx_Init(void); void Lora433_change(void); void Lora433rx_Init(void); +void SwitchLoraSettings(uint32_t freq,uint8_t sf,uint8_t power); uint32_t RxDutyCycle_RX_time =128; uint32_t RxDutyCycle_SLEEP_time=256; #define LORA_FREQUENCY0 470200000 @@ -32,21 +32,15 @@ #define LORA_TX_47X 2 #define LORA_RX_47X 3 uint8_t Lora_status=0; -extern uint32_t uwbled,gpsled,loraled,powerled; + #define RF_FREQUENCY 433000000 // Hz #define RF_FREQUENCY_R 500000000 // Hz #define RF_FREQUENCY_T 470200000 // Hz - #define TX_OUTPUT_POWER 22 // 22 dBm extern bool IrqFired; extern uint8_t lora_yingda_flag; uint16_t lora_yingda_num; - - -//bool EnableMaster=true;//主选择 -bool EnableMaster=false;//从选择 - uint16_t crc_value; /*! * Radio events function pointer @@ -101,8 +95,6 @@ #define RX_TIMEOUT_VALUE 0 #define BUFFER_SIZE 255 // Define the payload size here - - uint16_t BufferSize = BUFFER_SIZE; uint8_t TX_Buffer[BUFFER_SIZE]; uint8_t RX_Buffer[BUFFER_SIZE]; @@ -120,60 +112,9 @@ uint8_t lora_chongfuyingda_flag; uint8_t Lora_rx_open_flag; extern u32 Loratx_frequency; -void LedToggle(void) -{ -// HAL_GPIO_TogglePin(GPIOB, LED1_Pin); -} -//void Lora_tx_mode( void ) -//{ -//Lora_status=LORA_TX_47X; -// RadioEvents.TxDone = OnTxDone; -// RadioEvents.RxDone = OnRxDone; -// RadioEvents.TxTimeout = OnTxTimeout; -// RadioEvents.RxTimeout = OnRxTimeout; -// RadioEvents.RxError = OnRxError; - -// Radio.Init( &RadioEvents ); -// Radio.SetChannel( Loratx_frequency ); -// -// Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, 2, -// 7, LORA_CODINGRATE,LORA_PREAMBLE_LENGTH_T, LORA_FIX_LENGTH_PAYLOAD_ON, -// false, 0, 0, LORA_IQ_INVERSION_ON_T, 3000 ); - -//} -//void Lora_rx_open( void ) -//{ -// if(Lora_rx_open_flag==1) -// { -// Lora_Init(); -// Lora_rx_open_flag=0; -// } -// if(lora_yingda_flag&&lora_chongfuyingda_flag==0) -// { -// printf("Lora:%d %d\r\n",lora_yingda_flag,lora_chongfuyingda_flag); -// lora_chongfuyingda_flag=1; -// RadioEvents.TxDone = OnTxDone; -// RadioEvents.RxDone = OnRxDone; -// RadioEvents.TxTimeout = OnTxTimeout; -// RadioEvents.RxTimeout = OnRxTimeout; -// RadioEvents.RxError = OnRxError; - -// Radio.Init( &RadioEvents ); -// Radio.SetChannel( 500000000 ); -// Radio.SetRxConfig( MODEM_LORA, 0, 7, -// LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH_R, -// LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, -// 0, false, 0, 0, true, 1 ); - -// SX126xClearIrqStatus( IRQ_RADIO_ALL ); -//// Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time); -// Radio.Rx( RX_TIMEOUT_VALUE ); - -// -// } -//} -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; @@ -185,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; @@ -242,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; @@ -279,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); @@ -335,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 ) @@ -371,7 +316,7 @@ } - +extern u8 active_flag; void LoraInit(void) { RadioEvents.TxDone = OnTxDone; @@ -382,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