yincheng.zhong
2025-03-05 ece0fe2ba0ed5a2cfa719076ec2a56cba85ba413
Src/radio/Lora.c
@@ -248,6 +248,7 @@
int32_t target_count;
extern uint16_t motor_keeptime;
uint8_t shengji_flag;
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{   uint16_t checksum1;
        BufferSize = size;
@@ -259,9 +260,13 @@
    lora_up_rec_flag=1;
    if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL)
    {
       // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
            UWB_Wkup();
            MbxTagUwbRec();
            HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效
      //  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
            MbxTagUwbRec();
      //  HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效
          //  Radio.Rx(0);
    }
    if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG)
    {
@@ -301,7 +306,7 @@
                        while(target_count>=32768)
                            target_count-=32768;
                        __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
                        rx_count = HAL_LPTIM_ReadCounter(&hlptim1);
                       // 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:
@@ -338,10 +343,10 @@
                        {}//文件过大,超出范围
                        else
                        {
                        memcpy(&wangguan_up_id,&RX_Buffer[SOURCE_ID_IDX],2);//网关ID 占用2个字节
                        shengji_flag=1;
                        LoraUp_flag=1;
                        imu_enable=0;
                            memcpy(&wangguan_up_id,&RX_Buffer[SOURCE_ID_IDX],2);//网关ID 占用2个字节
                            shengji_flag=1;
                            LoraUp_flag=1;
                            imu_enable=0;
                        }
//                      LoraUp_Poll();
                            break;                        
@@ -350,39 +355,46 @@
                }
            }
        }
    }
}
    if(!no_rx_flag)
    {
        if(lora_jianting_flag&&LoraUp_flag==0)
        {
            SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
            SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0);
            Radio.Rx(0);
        }
    }
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
}
void OnTxTimeout( void )
{
    Radio.Standby();
    if(lora_jianting_flag)
    SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
    {
        SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0);
        Radio.Rx(0);
    }
}
    uint8_t tm;
uint16_t Lora_rece_error;
void OnRxTimeout( void )
{
    Radio.Standby();
    if(wg_state==WG_Lost)
    {
        current_count = HAL_LPTIM_ReadCounter(&hlptim1);
        target_count-=current_count%3276;
//        current_count = HAL_LPTIM_ReadCounter(&hlptim1);
//        target_count-=current_count%3276;
        target_count-=66;//提前2ms发lora
        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);
        SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0);
        Radio.Rx(0);
    }
}
@@ -392,7 +404,10 @@
    Radio.Standby();
    if(lora_jianting_flag)
    SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0);
    {
        SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0);
        Radio.Rx(0);
    }
}
uint16_t freq_test;
@@ -431,7 +446,7 @@
    RadioEvents.RxError = OnRxError;
    Radio.Init( &RadioEvents );
    SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],5,0); //切换lora接收频点
    SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); //切换lora接收频点
    if(active_flag)
    {
    Radio.Rx( 0 ); 
@@ -458,7 +473,7 @@
    if(shengji_flag)
    {
//    memcpy(&wangguan_up_id,&RX_Buffer[SOURCE_ID_IDX],2);//网关ID 占用2个字节
    send_lora_data[MSG_TYPE_IDX]=LORA_MSGTYPE_UPDATE_CONFIRM;
    send_lora_data[MSG_TYPE_IDX]=LORA_MSGTYPE_UPDATE_CONFIRM2;
    memcpy(&send_lora_data[SOURCE_ID_IDX],&dev_id,2);//网关ID 占用2个字节
    memcpy(&send_lora_data[DEST_ID_IDX],&wangguan_up_id,2);//标签或者基站的设备ID 2个字节
//    send_lora_data[MUQIAN_BAG]=0xFF;