| | |
| | | #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 |
| | |
| | | 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 |
| | |
| | | #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 |
| | |
| | | #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]; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX]; |
| | | if(rec_index==0xDD) |
| | | { |
| | | if(usart5_state==1) |
| | | { |
| | | Usart5Init(); |
| | | usart5_state=0; |
| | | } |
| | | 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[9],RX_Buffer[8]); |
| | | yuyin_sendflag=1; |
| | | yuyinzidongguan_time=0; |
| | | yuyin_no_sleep_flag=1; |
| | | // if(usart5_state==1) |
| | | // { |
| | | // Usart5Init(); |
| | | // usart5_state=0; |
| | | // } |
| | | // 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[9],RX_Buffer[8]); |
| | | // yuyin_sendflag=1; |
| | | // yuyinzidongguan_time=0; |
| | | // yuyin_no_sleep_flag=1; |
| | | }else{ |
| | | memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2); |
| | | g_com_map[rec_index/2] = rec_value; |
| | |
| | | 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 ) |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | extern u8 active_flag; |
| | | void LoraInit(void) |
| | | { |
| | | RadioEvents.TxDone = OnTxDone; |
| | |
| | | |
| | | 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); |
| | | |
| | | } |