yincheng.zhong
2023-04-24 5c6608fc16627430bcdbaf4917c608e61b7db77c
Src/main.c
@@ -187,7 +187,7 @@
}
   if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
   {
      nomove_count = 0;
      //nomove_count = 0;
        bat_percent=Get_Battary();
      if(state5v==0)
      {
@@ -197,9 +197,9 @@
      if(bat_percent>99)
      {
         LED_LR_OFF;
         LED_LG_ON;
         //LED_LG_ON;
      }else{
         LED_LR_ON;
      //   LED_LR_ON;
         LED_LG_OFF;      
      }      
   }else{
@@ -250,19 +250,20 @@
u16 total_slotnum,current_slotnum;
extern int32_t offsettimeus;
  int32_t lpcount,lptime,target_time;
void SetNextPollTime(u16 time)
{
  int32_t lpcount,lptime,target_time;
   if(current_slotnum>=total_slotnum)
      current_slotnum-=total_slotnum;
   target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000;
   //if(target_time<90000)
   {
      lptime=target_time-offsettimeus;
      lpcount = lptime/LPTIMER_LSB;
//   if(current_slotnum>=total_slotnum)
//      current_slotnum-=total_slotnum;
//
//   target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000;
//   //if(target_time<90000)
//   {
//      lptime=target_time-offsettimeus;
//      lpcount = lptime/LPTIMER_LSB;
    lpcount+=g_com_map[COM_INTERVAL]*LPTIMER_LSB;
   if(lpcount>LPTIMER_1S_COUNT)
      lpcount-=LPTIMER_1S_COUNT;
   if(lpcount<0)
@@ -270,7 +271,6 @@
   lpcount+=LPTIMER_1S_COUNT;
   }
   __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
}
}
void HardWareTypeDiffConfig(void)
@@ -314,6 +314,7 @@
   imu_enable=g_com_map[IMU_ENABLE];
   motor_enable=g_com_map[MOTOR_ENABLE];
   
    g_com_map[GROUP_ID] = 98;
   group_id=g_com_map[GROUP_ID];
   dev_id = g_com_map[DEV_ID];
   slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3;
@@ -336,7 +337,9 @@
//   g_com_map[MAX_REPORT_ANC_NUM]=1;
   g_com_map[NOMOVESLEEP_TIME]=10;
#endif
      if(g_com_map[COM_INTERVAL]==0)
    g_com_map[COM_INTERVAL]=100;
    if(g_com_map[COM_INTERVAL]==0)
   {
     g_com_map[COM_INTERVAL]=100;
   }
@@ -356,9 +359,32 @@
    Error_Handler();
  }
//g_com_map[NOMOVESLEEP_TIME]=5;
   printf("标签ID: %d .\r\n",dev_id);
   printf("通讯间隔: %d ms.\r\n",g_com_map[COM_INTERVAL]);
   printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]);
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t0.bco=63488");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t0.txt=\"等待串口通讯\"");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t1.bco=63488");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t1.txt=\"等待测距\"");
//          USART_putc(0xff);
//        USART_putc(0xff);
//        USART_putc(0xff);
//        printf("t2.bco=2024");
//        USART_putc(0xff);
//        USART_putc(0xff);
//        USART_putc(0xff);
//        printf("t2.txt=\"无测距\"");
   
//   printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
@@ -389,6 +415,7 @@
{
      //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
}
u8 flag_entersleep1=0,flag_entersleep2=0;
/* USER CODE END 0 */
/**
@@ -455,7 +482,7 @@
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
      if(g_start_send_flag&&active_flag)
      if(g_start_send_flag)
   { static uint16_t blink_count=0;
      SystemClock_Config();
      g_start_send_flag = 0;   
@@ -487,7 +514,7 @@
         if(m_bEUARTTxEn==0&&waitusart_timer==0&&(motor_state==0||motor_state==3))
         {   
#ifndef DEBUG_MODE   
if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
if(flag_entersleep1*flag_entersleep2==1)
            HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
#endif
         }
@@ -929,8 +956,67 @@
  /*Enter the Standby mode*/
  HAL_PWR_EnterSTANDBYMode();   
}
extern u8 flag_usartrecok,flag_uwbrange_ok;
extern int32_t uwb_dist;
void LCDPROCESS(void)
{
    if(flag_usartrecok)
    {
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t0.bco=2024");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t0.txt=\"串口通讯成功\"");
        flag_entersleep1 = 1;
    }else{
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t0.bco=63488");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t0.txt=\"等待串口通讯\"");
    }
    if(flag_uwbrange_ok)
    {
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t1.bco=2024");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t1.txt=\"测距成功\"");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t2.bco=2024");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t2.txt=\"距离:%d\"",uwb_dist);
        flag_entersleep2 = 1;
    }else{
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t1.bco=63488");
        USART_putc(0xff);
        USART_putc(0xff);
        USART_putc(0xff);
        printf("t1.txt=\"等待测距\"");
    }
}
float lcd_count=0;
extern uint8_t tx_near_msg[80],stationary_flag;
float key_keeptime;
float key_keeptime,lcdtimer;
void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
   static uint8_t i=0;
@@ -939,6 +1025,12 @@
   current_slotnum++;
   SetNextPollTime(tyncpoll_time);
   nomove_count+=(float)g_com_map[COM_INTERVAL]/1000;
    lcdtimer+=(float)g_com_map[COM_INTERVAL]/1000;
    if(lcdtimer-lcd_count>0.5)
    {
        lcd_count = lcdtimer;
        LCDPROCESS();
    }
    if(motor_keeptime>0)
   {   
   motor_keeptime-=(float)g_com_map[COM_INTERVAL]/1000;