yincheng.zhong
2024-03-03 cae9d270866f095318e8c31ea7c4a8fe741f465d
Src/main.c
@@ -247,7 +247,7 @@
    hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2);
    hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4);
    //deca_sleep(1000);
    g_com_map[VERSION] = (1<<8)|3;
    g_com_map[VERSION] = (1<<8)|5;
//    g_com_map[DEV_ID]=1158;
    g_com_map[GROUP_ID]=0;
//    g_com_map[COM_INTERVAL] = 1000;
@@ -255,9 +255,10 @@
    {
        g_com_map[COM_INTERVAL] = 1000;
    }
    g_com_map[STATIONARY_TIME] = 10;
    active_flag = g_com_map[ACTIVE_INDEX];
    module_power = g_com_map[POWER];
    g_com_map[IMU_ENABLE] = 0;
//    g_com_map[IMU_ENABLE] = 0;
    imu_enable=g_com_map[IMU_ENABLE];
    motor_enable=g_com_map[MOTOR_ENABLE];
@@ -507,7 +508,9 @@
    HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1);
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET); //开GPS电源
    LoraInit();
#ifdef _USE_BAR
    BarInit();
#endif
//    Delay_Ms(1000);
//    HAL_UART_Transmit(&hlpuart1,Close_RMC,22,1000);
//    HAL_UART_Transmit(&hlpuart1,Close_GSA,22,1000);
@@ -1027,30 +1030,42 @@
    /*Enter the Standby mode*/
    HAL_PWR_EnterSTANDBYMode();
}
extern uint8_t tx_near_msg[80];
float key_keeptime;
extern float freqlost_count,range_lost_time;
extern uint8_t lora_yingda_flag;
extern uint32_t wg_lost_count;
uint8_t lora_yingdatime;
uint8_t lora_yingdatime,gotosleep_flag,sleep_flag;
extern uint8_t lora_chongfuyingda_flag,report_ancnum;
uint16_t no_data_chongqi_num;
uint16_t anchor_send_num;
uint8_t no_yingdatime;
uint8_t no_yingdatime,tflag1,tflag2;
extern uint16_t tagdist_list[ANC_MAX_NUM];
void LedTask(void)
{
    if(report_ancnum>0)
    {
        LED2_TB_ON;
#ifdef _SMT_TEST
        tflag1 = 1;
        printf("测距值%d\r\n",tagdist_list[0]);
#endif
    }
   // if(wg_lost_count<=1)
    if(wg_lost_count<=1)
    {
#ifdef _SMT_TEST
        tflag2 = 1;
        printf("网关通讯正常\r\n");
#endif
        LED_TB_ON;
    }
    if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
        if(bat_percent<15)
        {
            LED_TR_ON;
        } else {
            LED2_TB_ON;
        }
    
}
@@ -1058,12 +1073,86 @@
{
//    uint8_t pinlv;
    SystemClock_Config();
    HAL_IWDG_Refresh(&hiwdg);
    if(active_flag==0)  //未激活状态
    {
        if(!GET_USERKEY)
        {
            LED_TB_ON;
            key_keeptime+=1;
            if(key_keeptime>3)
            {
                u8 i=250,keystate=1;
                while(i--)
                {
                    if(i%10==0)
                    {
                        LED_TB_BLINK;
                    }
                    if(GET_USERKEY)
                    {
                        keystate = 0;
                    }
                    if(keystate==0&&!GET_USERKEY)
                    {
                        parameter_init();
                        g_com_map[ACTIVE_INDEX] = 1;
                        save_com_map_to_flash();
                        delay_ms(100);
                        SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader
                    }
                    delay_ms(10);
                }
            }
        } else {
            //   LED_LG_OFF;
            key_keeptime=0;
        }
    } else {
        if(!sleep_flag)
        {
    LedTask();
    LoraReportPoll();
    flag_onesecond = 1;
       if(!GET_USERKEY)
        if(nomove_count++>g_com_map[STATIONARY_TIME])
   {
      key_keeptime+=1/(float)tag_frequency;
            stationary_flag = 1;
        } else {
            stationary_flag = 0;
        }
        if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
        {
            gotosleep_flag=1;
        } else {
            gotosleep_flag=0;
        }
    }
#ifndef DEBUG_MODE
        if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
        {
            if(sleep_flag==0)
            {
                Radio.Standby();
                Radio.Sleep();
                sleep_flag = 1;
            }
        } else {
            if(sleep_flag)
            {
                SCB->AIRCR = 0X05FA0000|(unsigned int)0x04;
            }
        }
#endif
    }
    if(!GET_USERKEY)    //长按重启逻辑
    {
        key_keeptime+=1;
      if(key_keeptime>=KEY_KEEPRESET_TIME)
      {
         SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; 
@@ -1071,6 +1160,7 @@
   }else{
      key_keeptime=0;
   }
    LED_TB_OFF;
    LED_TR_OFF;
    LED2_TB_OFF;