1
WXK
2023-12-12 04f8fa58e5106157c2b2608fe97917f91d347200
Src/main.c
@@ -193,11 +193,11 @@
u16 total_slotnum,current_slotnum;
extern int32_t offsettimeus;
u16 last_lpcount = 0;
//u16 last_lpcount = 0;
void SetNextPollTime(u16 time)
{
  int32_t lpcount,lptime,target_time;
  int32_t lpcount1,lptime1,target_time1;
int32_t last_lpcount1;
//   if(current_slotnum>=total_slotnum)
//      current_slotnum-=total_slotnum;
//   
@@ -212,14 +212,14 @@
//   {
//   lpcount+=LPTIMER_1S_COUNT;
//   }
    last_lpcount=HAL_LPTIM_ReadCounter(&hlptim1);
    lpcount = last_lpcount+32768+32.768*time;
    while(lpcount>LPTIMER_1S_COUNT)
    last_lpcount1=HAL_LPTIM_ReadCounter(&hlptim1);
    lpcount1 = last_lpcount1+32.768*time;
    while(lpcount1>LPTIMER_1S_COUNT)
    {
        lpcount-=LPTIMER_1S_COUNT;
        lpcount1-=LPTIMER_1S_COUNT;
    }
//    last_lpcount = lpcount;
   __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
   __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount1+32768);
}
@@ -305,6 +305,7 @@
//{Loratx_frequency=490000000;}
srand(HAL_LPTIM_ReadCounter(&hlptim1));
        Loratx_frequency=((rand()%5)+470)*1000000; 
//Loratx_frequency=474000000;
}
void Program_Init(void)
{   float temp;
@@ -485,12 +486,16 @@
{
    if(lora_tx_flag)
    {
//        Lora47X_change();
//        Delay_Ms(50);
//         SX126xReset();
//    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
            Lora47X_Init();
    lora_tx_flag=0;
    LED_TB_ON;    
    lora_seq_nb2++;
    Lora_tx_zubao();
    Lora_tx_mode();
//    Lora_tx_mode();
    Radio.Send( usart_send, 13+Lora_tx_ancnum*4);
    Lora_tx_ancnum=0;    
    memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist));
@@ -499,6 +504,10 @@
    }
   if(lora_txanchor_power_flag)
    {
//         SX126xReset();
//        Lora47X_change();
//        Delay_Ms(50);
            Lora47X_Init();
       LED_TB_ON;
       lora_seq_nb1++;
   lora_txanchor_power_flag=0;
@@ -512,7 +521,7 @@
               memcpy(&usart_send[8+Lora_tx_ancnum*2],&Lora_tx_anc_electricity,Lora_tx_ancnum);
               checksum = Checksum_u16(&usart_send[2],8+3*Lora_tx_ancnum);
               memcpy(&usart_send[8+3*Lora_tx_ancnum],&checksum,2);
           Lora_tx_mode();
//           Lora_tx_mode();
           Radio.Send( usart_send, 10+Lora_tx_ancnum*3);
           Lora_tx_ancnum=0; 
       
@@ -574,7 +583,7 @@
  MX_SPI1_Init();
  MX_ADC_Init();
  
  MX_IWDG_Init();
//  MX_IWDG_Init();
  /* USER CODE BEGIN 2 */
//    LED_LG_ON;
    Program_Init();
@@ -595,7 +604,8 @@
//    Uwb_Lora_Switch(0,1);
//    Lora433rx_Init();
//    Lora47xrx_Init();
    Lora_Init();
//    Lora_Init();
//    Lora47xrx_Init();
//    Radio.Sleep( );
    Delay_Ms(10);
//    Uwb_Lora_Switch(0,0);
@@ -604,11 +614,14 @@
    usart_send[1]=0xaa;
    bat_percent=Get_VDDVlotage();
      GetLoratx_frequency();
//    Lora47X_Init();
//   mcu_sleep();
   //LED0_BLINK;      
//   SystemPower_Config();
//HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);   
//    HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_SET); //片选lora无效
//    lora_tx_flag=1;
//     Lora_Tx_Poll();
  /* USER CODE END 2 */
  /* Infinite loop */
@@ -619,9 +632,9 @@
    /* USER CODE BEGIN 3 */
//Lora_rx_open();
//      Lora_Tx_Poll();
      Lora_Tx_Poll();
    HAL_IWDG_Refresh(&hiwdg);
//    HAL_IWDG_Refresh(&hiwdg);
    IdleTask();   
//   Radio.IrqProcess( ); // Process Radio IRQ
//     Anchor_App();
@@ -1070,6 +1083,8 @@
//    }
//    else
//    {
    lora_tx_flag=1;
    lora_txanchor_power_flag=0;
//    }
@@ -1079,6 +1094,8 @@
        lora_tx_flag=0;
        bat_percent=Get_VDDVlotage();
    }
    if(stationary_num>=10)
    {stationary_num=0;
    stationary_flag=1;