yincheng.zhong
2024-03-08 d67d922c6345042cb3dfaedd621a2120fe808b70
Src/radio/Lora.c
@@ -10,63 +10,37 @@
#include "stdio.h"
#include "delay.h"
#include "main.h"
#include <stdlib.h>
#include "dw_mbx_tag.h"
static RadioEvents_t RadioEvents;
#define USE_MODEM_LORA
//#define USE_MODEM_FSK
#define REGION_CN779
#define REGION_CN779
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;
#if defined( REGION_AS923 )
#define RF_FREQUENCY                                923000000 // Hz
#elif defined( REGION_AU915 )
#define RF_FREQUENCY                                915000000 // Hz
#elif defined( REGION_CN779 )
#define LORA_FREQUENCY0 470200000
#define LORA_FREQUENCY1 471200000
#define LORA_FREQUENCY2 472200000
#define LORA_FREQUENCY3 473200000
#define LORA_FREQUENCY4 474200000
uint16_t Lora_rece_error;
#define LORA_RX_433 1
#define LORA_TX_47X 2
#define LORA_RX_47X 3
uint8_t Lora_status=0;
#define RF_FREQUENCY                              433000000 // Hz
#define RF_FREQUENCY_R                              500000000 // Hz
#define RF_FREQUENCY_T                              470200000 // Hz
#elif defined( REGION_EU868 )
#define RF_FREQUENCY                                868000000 // Hz
#elif defined( REGION_KR920 )
#define RF_FREQUENCY                                920000000 // Hz
#elif defined( REGION_IN865 )
#define RF_FREQUENCY                                865000000 // Hz
#elif defined( REGION_US915 )
#define RF_FREQUENCY                                915000000 // Hz
#elif defined( REGION_US915_HYBRID )
#define RF_FREQUENCY                                915000000 // Hz
#else
    #error "Please define a frequency band in the compiler 'options."
#endif
#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
@@ -85,8 +59,8 @@
                                                              //  2: 4/6,
                                                              //  3: 4/7,
                                                              //  4: 4/8]
#define LORA_PREAMBLE_LENGTH_T                      10         // Same for Tx
#define LORA_PREAMBLE_LENGTH_R                      64        // Same for Rx
#define LORA_PREAMBLE_LENGTH_T                      8         // Same for Tx
#define LORA_PREAMBLE_LENGTH_R                      8        // Same for Rx
//#define LORA_PREAMBLE_LENGTH                      990         // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT                         0         // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
@@ -118,11 +92,8 @@
}States_t;
//#define RX_TIMEOUT_VALUE                            1000
#define RX_TIMEOUT_VALUE                            64000
#define BUFFER_SIZE                                 64 // Define the payload size here
const uint8_t PingMsg[] = "PING";
const uint8_t PongMsg[] = "PONG";
#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];
@@ -140,30 +111,220 @@
void OnRxError( void );
uint8_t  lora_chongfuyingda_flag;
uint8_t Lora_rx_open_flag;
void LedToggle(void)
extern u32 Loratx_frequency;
{
//   HAL_GPIO_TogglePin(GPIOB, LED1_Pin);
}
void Lora_tx_mode( void )
{
            Radio.SetChannel( 470200000 );
            Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, 0,
            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)
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;
void OnTxDone( void )
{
    if(flag_writepara_needreset) //配置写入完成设备需要重启
    {
    Lora_Init();
    Lora_rx_open_flag=0;
        printf("网关下发配置写入完成,重启");
        SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader
    }
    if(lora_yingda_flag&&lora_chongfuyingda_flag==0)
    Radio.Standby();
    Radio.Rx( 50 );
    LED_TB_OFF;
}
extern LPTIM_HandleTypeDef hlptim1;
uint16_t current_time,start_time,end_time;
uint8_t power_and_key=0;
extern u8 battary,button;
u8 lora_seq_nb2;
extern uint8_t stationary_flag;
extern uint8_t anjian_flag;
extern uint8_t lora_tx_flag;
extern uint16_t wg_report_id,wg_report_freq;
extern uint8_t no_yingdaflag;
uint16_t Beepchixutime;
uint8_t xiafayuyin_data[200];
uint8_t yuyin_sendflag;
uint8_t yuyinzidongguan_time;
uint8_t  yuyin_no_sleep_flag,no_rx_flag;
extern uint8_t usart5_state;
extern uint8_t lora_sendbuffer[200];
void LoraSendComMap(uint8_t cmd)
{
   uint8_t data_length = 0x28;
   uint16_t checksum = 0;
   lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_READPARARESP;
   lora_sendbuffer[MSG_LENGTH] = data_length+9;
    memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2);
    memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2);
   lora_sendbuffer[RP_CMD_IDX] = cmd;
   lora_sendbuffer[RP_INDEX_IDX] = 2;
   lora_sendbuffer[RP_LEN_IDX] = data_length;
   memcpy(&lora_sendbuffer[7], &g_com_map[1], data_length);
   checksum = Checksum_u16(lora_sendbuffer,9+data_length);
   memcpy(&lora_sendbuffer[9+data_length],&checksum,2);
    Radio.Send(lora_sendbuffer,data_length+11);
  //  Delay_Ms(100);
}
void LoraRspWriteCommap(uint8_t index)
{
   uint8_t data_length = 2;
   uint16_t checksum = 0;
   lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_READPARARESP;
   lora_sendbuffer[MSG_LENGTH] = data_length+9;
    memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2);
    memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2);
   lora_sendbuffer[RP_CMD_IDX] = WGRSP_RWTAG_WRITE;
   lora_sendbuffer[RP_INDEX_IDX] = index;
   lora_sendbuffer[RP_LEN_IDX] = data_length;
   memcpy(&lora_sendbuffer[7], &g_com_map[index/2], data_length);
   checksum = Checksum_u16(lora_sendbuffer,9+data_length);
   memcpy(&lora_sendbuffer[9+data_length],&checksum,2);
    Radio.Send(lora_sendbuffer,data_length+11);
  //  Delay_Ms(100);
}
extern u8 lora_jianting_flag;
static uint16_t delaytime = 1050;
static uint16_t source_id;
uint8_t rec_index;
uint16_t rec_value,rec_delaytime,rx_count;
int32_t target_count;
extern uint16_t motor_keeptime;
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
        BufferSize = size;
        memcpy( RX_Buffer, payload, BufferSize );
        RssiValue = rssi;
        SnrValue = snr;
        Radio.Standby();
        no_rx_flag = 0;
    if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL)
    {
        printf("Lora:%d  %d\r\n",lora_yingda_flag,lora_chongfuyingda_flag);
    lora_chongfuyingda_flag=1;
            UWB_Wkup();
            MbxTagUwbRec();
            HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效
    }
    if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG)
    {
        if(!memcmp(&dev_id,&RX_Buffer[DEST_ID_IDX],2))
        {
           memcpy(&source_id,&RX_Buffer[SOURCE_ID_IDX],2);
            if(wg_state==WG_Lost)
            {
                wg_state = WG_Connected;
                wg_report_id = source_id;
            }
            if(!memcmp(&wg_report_id,&RX_Buffer[SOURCE_ID_IDX],2))
            {
                wg_lost_count = 0;
                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);
                        target_count = current_count + rec_delaytime*3.2768 - delaytime;
                        while(target_count>=32768)
                            target_count-=32768;
                        __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
                        rx_count = HAL_LPTIM_ReadCounter(&hlptim1);
                     //   printf("tx %d,rx %d,delay %d",current_count>>5,rx_count>>5,rec_delaytime);
                        break;
                    case WGRSP_RWTAG_READ:
                        no_rx_flag = 1;
                        LoraSendComMap(WGRSP_RWTAG_READ);
                        break;
                    case WGRSP_RWTAG_WRITE:
                        rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX];
                    switch(rec_index)
                    {
                        case 0xdd:  //语音下发
                            break;
                        case 0x20:  //蜂鸣
                            memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2);
                            motor_keeptime = rec_value;
                            break;
                        default :
                            memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2);
                            g_com_map[rec_index/2] = rec_value;
                            save_com_map_to_flash();
                            LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA);
                            flag_writepara_needreset = 1;
                            no_rx_flag = 1;
                    }
                        break;
                }
            }
        }
    }
    if(!no_rx_flag)
    {
        if(lora_jianting_flag)
        {
            SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
            Radio.Rx(0);
        }
    }
}
void OnTxTimeout( void )
{
    Radio.Standby();
    if(lora_jianting_flag)
    SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
}
    uint8_t tm;
uint16_t Lora_rece_error;
void OnRxTimeout( void )
{
    Radio.Standby();
    current_count = HAL_LPTIM_ReadCounter(&hlptim1);
    target_count-=current_count%3276;
    while(target_count<0)
        target_count+=32768;
    __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
    if(lora_jianting_flag)
    {
        SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
        Radio.Rx(0);
    }
}
void OnRxError( void )
{
    Radio.Standby();
    if(lora_jianting_flag)
    SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
}
uint16_t freq_test;
void SwitchLoraSettings(uint32_t freq,uint8_t sf,uint8_t power)
{
//    RadioEvents.TxDone = OnTxDone;
//    RadioEvents.RxDone = OnRxDone;
//    RadioEvents.TxTimeout = OnTxTimeout;
//    RadioEvents.RxTimeout = OnRxTimeout;
//    RadioEvents.RxError = OnRxError;
    //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
//    Radio.Init( &RadioEvents );
    Radio.Standby();
  //  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
    Radio.SetChannel( freq*1000000 );
    freq_test = freq;
    Radio.SetTxConfig( MODEM_LORA, power, 0, 2,
    sf, LORA_CODINGRATE,LORA_PREAMBLE_LENGTH_T, LORA_FIX_LENGTH_PAYLOAD_ON,
    false, 0, 0, LORA_IQ_INVERSION_ON_T, 3000 );
    Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH,
    sf,LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH_R,
    LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
    0, false, 0, 0, LORA_IQ_INVERSION_ON_R, 0 );
}
extern u8 active_flag;
void LoraInit(void)
{
    RadioEvents.TxDone = OnTxDone;
    RadioEvents.RxDone = OnRxDone;
    RadioEvents.TxTimeout = OnTxTimeout;
@@ -171,244 +332,13 @@
    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 );
    }
}
void OnTxDone( void )
{
    LED_TB_OFF;
    if(lora_yingda_num>1000)
    SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],5,0); //切换lora接收频点
    if(active_flag)
    {
    lora_yingda_num=0;
    lora_yingda_flag=1;
    }
    if(lora_yingda_flag==0)
    Lora_rx_open_flag=1;
    else
    {}
}
extern uint32_t lp_time;
uint32_t lora_txtime_old;
extern uint8_t frame_seq_nb2,rec_nearbase_num,ancidlist_num;
uint16_t RX_TIMEOUTs;
extern LPTIM_HandleTypeDef hlptim1;
uint16_t current_time,start_time,end_time;
    uint16_t lora_recv_devid=0;
u32 id;
extern uint8_t Lora_tx_ancnum;
extern uint16_t Lora_tx_ancid[50];
extern uint16_t Lora_tx_ancdist[50];
uint8_t power_and_key=0;
extern u8 battary,button;
u8 lora_seq_nb2;
extern uint8_t stationary_flag;
extern uint8_t anjian_flag;
void Lora_tx_zubao( void )
{
    uint16_t checksum;
                    usart_send[2] = 0x22;//正常模式
               usart_send[3] = 9+Lora_tx_ancnum*4;//数据段长度
                    memcpy(&usart_send[4],&dev_id,2);
               usart_send[6] = lora_seq_nb2;//包序
                    power_and_key=stationary_flag<<1;//把按键跟静止2合1,发出去
                    power_and_key=power_and_key+anjian_flag;;
                    memcpy(usart_send+7,&bat_percent,1);
                    memcpy(usart_send+8,&power_and_key,1);
                    usart_send[9] = lora_yingda_flag;//lora等待应答位
                    usart_send[10] = Lora_tx_ancnum;
//                    usart_send[9] = lora_yingda_flag;
               memcpy(&usart_send[11],&Lora_tx_ancid,2*Lora_tx_ancnum);
               memcpy(&usart_send[11+Lora_tx_ancnum*2],&Lora_tx_ancdist,2*Lora_tx_ancnum);
               checksum = Checksum_u16(&usart_send[2],8+4*Lora_tx_ancnum);
               memcpy(&usart_send[11+4*Lora_tx_ancnum],&checksum,2);
}
uint16_t current_count;
u16 Lora_recevcount;
extern uint8_t no_data_chongqi_num;
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
    Lora_recevcount=HAL_LPTIM_ReadCounter(&hlptim1);
    Lora_recevcount=Lora_recevcount+197;//197代表6ms
    if(Lora_recevcount>=32768)
    {
    Lora_recevcount -=32768;
    }
//    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
    BufferSize = size;
    memcpy( RX_Buffer, payload, BufferSize );
    RssiValue = rssi;
    SnrValue = snr;
    no_data_chongqi_num=0;
    Radio.Standby();
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
    if(lora_yingda_flag)
    {
    memcpy(&lora_recv_devid,&RX_Buffer[4],2);
        if(lora_recv_devid==dev_id)
        {
        }
    }
    if(lora_yingda_flag==0)
    {
        lora_chongfuyingda_flag=0;
//        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET);
//       Delay_Ms(10);
//        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET);
        uint16_t i=0;
//        for(i=0;i<BufferSize;i++)
        {printf("R %d:\r\n",RX_Buffer[3]);}
        RX_TIMEOUTs++;
//        printf("RX_num :%d\r\n",RX_TIMEOUTs);
//        start_time=HAL_LPTIM_ReadCounter(&hlptim1);
//        end_time=start_time+((32768/1000)*20);
//        if(end_time>=32768)
//       {end_time-=32768;}
//        current_time=HAL_LPTIM_ReadCounter(&hlptim1);
        HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_SET); //片选lora无效
           id =  dwt_readdevid() ;
   while (0xDECA0130!=id)
    {
        u8 iderror_count = 0;
        id =  dwt_readdevid() ;
        if(iderror_count++>100)
        {
////////            printf("UWB芯片ID错误");
            break;
        }
    }
////////            printf("Anchor_App\r\n");
        current_count=HAL_LPTIM_ReadCounter(&hlptim1);
      while(current_count<Lora_recevcount||current_count>Lora_recevcount+16384)
      {
         current_count=HAL_LPTIM_ReadCounter(&hlptim1);
         if(current_count<Lora_recevcount-300)
         {
            break;
         }
      }
//    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
            Anchor_App();
//    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
            HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效
            delay_ms(1);
//            if(lp_time-lora_txtime_old>=1)
//            {
//            LED_TB_ON;
//            lora_txtime_old=lp_time;
//            lora_seq_nb2++;
//            lora_yingda_num++;
//            Lora_tx_zubao();
//            Lora_tx_mode();
//            Radio.Send( usart_send, 12+Lora_tx_ancnum*4);
//            Lora_tx_ancnum=0;
//            }
//            else
//            {
            Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
//            }
    }
}
void OnTxTimeout( void )
{
       Radio.Standby();
        Lora_Init();
    Lora_rx_open_flag=0;
    Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
}
void OnRxTimeout( void )
{
    Radio.Standby();
        Lora_Init();
    Lora_rx_open_flag=0;
    Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
//    printf("slave OnRxTimeout\r\n");
}
void OnRxError( void )
{
    Radio.Standby();
        Lora_Init();
    Lora_rx_open_flag=0;
    Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
}
void Lora_Init(void)
{
    RadioEvents.TxDone = OnTxDone;
    RadioEvents.RxDone = OnRxDone;
    RadioEvents.TxTimeout = OnTxTimeout;
    RadioEvents.RxTimeout = OnRxTimeout;
    RadioEvents.RxError = OnRxError;
//    printf("Lora_Init3\r\n");
        Radio.Init( &RadioEvents );
        Radio.SetChannel( RF_FREQUENCY );
//        Radio.SetStandby( STDBY_RC );
//    Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
//                                   LORA_SPREADING_FACTOR, LORA_CODINGRATE,
//                                   LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
//                                   true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
//      Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
//                                   LORA_SPREADING_FACTOR, LORA_CODINGRATE,
//                                   LORA_PREAMBLE_LENGTH_T, LORA_FIX_LENGTH_PAYLOAD_ON,
//                                   false, 0, 0, LORA_IQ_INVERSION_ON_T, 1000 );
//    Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
//                                   LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
//                                   LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
//                                   0, true, 0, 0, LORA_IQ_INVERSION_ON, false );
//               printf("Lora_Init1\r\n");
      Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                                   LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH_R,
                                   LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   0, false, 0, 0, LORA_IQ_INVERSION_ON_R, 1 );
    Radio.Rx( 0 );
    }else{
        Radio.Sleep();
    }
//        Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
                                   
//      Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
//                                   LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
//                                   LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
//                                   0, false, 0, 0, LORA_IQ_INVERSION_ON, true );
    {
       SX126xClearIrqStatus( IRQ_RADIO_ALL );
//        SX126xSetDioIrqParams( IRQ_RX_DONE | IRQ_CRC_ERROR,
// IRQ_RX_DONE | IRQ_CRC_ERROR,
// IRQ_RADIO_NONE, IRQ_RADIO_NONE
// );
//            SX126xSetDioIrqParams( IRQ_RADIO_ALL, //IRQ_RX_DONE | IRQ_RX_TX_TIMEOUT,
//       IRQ_RADIO_ALL, //IRQ_RX_DONE | IRQ_RX_TX_TIMEOUT,
//       IRQ_RADIO_NONE,
//       IRQ_RADIO_NONE );
       Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time);
//        Radio.Rx( RX_TIMEOUT_VALUE );
//       printf("I am Slave!\r\n");
    }
}