| | |
| | | #define WARING_LIMIT_TIME 10 |
| | | #define UPDATE_TIME 10 |
| | | |
| | | |
| | | #define VIBRATION_TIME 1 //单位500ms |
| | | #define NO_VIBRATION_TIME 20 //15s |
| | | extern uint8_t mUsartReceivePack[100]; |
| | | extern uint8_t mUsart2ReceivePack[150]; |
| | | extern uint8_t state5V_prase_flag,gps_prase_flag; |
| | |
| | | uint8_t bat_percent,g_start_send_flag=1; |
| | | uint8_t link_success_flag,motor_count; |
| | | uint16_t gps_wait_count; |
| | | extern uint8_t gps_timeout_flag; |
| | | uint8_t state5v = 1; |
| | | uint8_t motor_power_state=1,uwb_state,air780_power_state,gps_success_state,red_charge_state,green_charge_state,air780_success_state,first_motor_in_flag; |
| | | float nomove_count=0; |
| | |
| | | //uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | //} |
| | | extern uint8_t gps_uwb_flag,gps_need_data_flag; |
| | | uint8_t TCP_reconnect_timer,flag_TCP_reconnectting = 1,flag_alam_state = 0; |
| | | static HIDO_UINT32 l_u32MotorPollTick = 0; |
| | | uint8_t TCP_reconnect_timer,flag_TCP_reconnectting = 1,flag_alam_state = 0,userkey_state; |
| | | uint32_t keystarttime,keystarttime2; |
| | | uint8_t motor_open_flag=1; |
| | | uint8_t gps_enable_flag,motor_open_air_flag,moter_open_uwb_flag,flag_fenli_alarm = 0,fenli_alarm_count,delaysleep_count,enbale_blink_flag; |
| | | int need_open_gps_count; |
| | | uint8_t change_vibration=2; |
| | | HIDO_UINT32 u32CurTick_Motor; |
| | | void MotorPoll(void) |
| | | { |
| | | if(!power_low_flag)//确认是否休眠下才开启功能 |
| | | { //马达震动逻辑 |
| | | if(g_com_map[MOTOR_ENABLE]) |
| | | { |
| | | if(motor_open_air_flag||moter_open_uwb_flag) |
| | | {motor_power_state=0; |
| | | if(motor_open_flag) |
| | | { |
| | | if (motor_count>=change_vibration) |
| | | { |
| | | change_vibration=VIBRATION_TIME; |
| | | motor_power_state = 1; |
| | | motor_count=0; |
| | | motor_open_flag=0; |
| | | update_led_power_state(); |
| | | } |
| | | motor_count++; |
| | | }else {//修改 |
| | | motor_power_state = 1; |
| | | if(motor_count>=NO_VIBRATION_TIME) |
| | | { |
| | | motor_power_state = 0; |
| | | motor_count=0; |
| | | motor_open_flag=1; |
| | | update_led_power_state(); |
| | | } |
| | | motor_count++; |
| | | } |
| | | |
| | | |
| | | } else { |
| | | motor_open_flag=1; |
| | | motor_count=0; |
| | | motor_power_state=1; |
| | | } |
| | | }else{ |
| | | motor_open_flag=1; |
| | | motor_count=0; |
| | | motor_power_state=1; |
| | | } |
| | | }else{ |
| | | motor_open_flag=1; |
| | | motor_count=0; |
| | | motor_power_state=1; |
| | | } |
| | | |
| | | } |
| | | |
| | | void MotorPollCheck(void) |
| | | { |
| | | if(!power_low_flag)//确认是否休眠下才开启功能 |
| | | { //马达震动逻辑 |
| | | if(g_com_map[MOTOR_ENABLE]) |
| | | { |
| | | if(motor_open_air_flag||moter_open_uwb_flag) |
| | | {motor_power_state=0; |
| | | if(motor_open_flag) |
| | | { |
| | | if (motor_count>=VIBRATION_TIME) |
| | | { |
| | | motor_power_state = 1; |
| | | motor_count=0; |
| | | motor_open_flag=0; |
| | | update_led_power_state(); |
| | | } |
| | | }else {//修改 |
| | | motor_power_state = 1; |
| | | if(motor_count>=NO_VIBRATION_TIME) |
| | | { |
| | | motor_power_state = 0; |
| | | motor_count=0; |
| | | motor_open_flag=1; |
| | | update_led_power_state(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } else { |
| | | motor_open_flag=1; |
| | | motor_count=0; |
| | | motor_power_state=1; |
| | | } |
| | | }else{ |
| | | motor_open_flag=1; |
| | | motor_count=0; |
| | | motor_power_state=1; |
| | | } |
| | | }else{ |
| | | motor_open_flag=1; |
| | | motor_count=0; |
| | | motor_power_state=1; |
| | | } |
| | | update_led_power_state(); |
| | | } |
| | | void StatusChange(void) |
| | | { |
| | | if(UWB_work_state==UN_BIND) { |
| | | gps_uwb_flag=0;//关闭GPS |
| | |
| | | mcu_deep_sleep(); |
| | | } |
| | | } |
| | | void UserKeyTask(void) |
| | | { |
| | | if(!GET_USERKEY) |
| | | { |
| | | if(HIDO_TimerGetTick() - keystarttime>3) |
| | | { |
| | | userkey_state = 1; |
| | | keystarttime = HIDO_TimerGetTick(); |
| | | TCPHeartBeatUpload();//立即上传该包 |
| | | } |
| | | if(HIDO_TimerGetTick() - keystarttime2>10) |
| | | { |
| | | g_com_map[CNT_RESTART] = 1; |
| | | } |
| | | }else |
| | | { |
| | | keystarttime = HIDO_TimerGetTick(); |
| | | keystarttime2 = HIDO_TimerGetTick(); |
| | | } |
| | | } |
| | | void MinuteTask(void) |
| | | { gpio_pin_clr(ADC_GND_ENABLE);//先拉低 |
| | | adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 |
| | |
| | | //初始化GPS计数数据 |
| | | gps_need_data_flag=1; |
| | | gps_wait_count=0; |
| | | gps_timeout_flag=0; |
| | | } |
| | | //gps_power_state=1;//测试gps长开 |
| | | //UWB状态检测 |
| | |
| | | uint8_t flag_sleeptimer,flag_secondtask,secondtask_count,log_4g_enable_flag; |
| | | uint8_t uwb_enable_flag=0; |
| | | uint8_t enable_system_function_flag; |
| | | |
| | | static void sleep_timer_callback(void *dev, uint32_t time) |
| | | { |
| | | // IO_control_init(); |
| | | |
| | | if(enbale_blink_flag) |
| | | { |
| | | green_charge_state=0; |
| | | charge_red_on(); |
| | | } |
| | | |
| | | if(tt) |
| | | UWBPoll(); |
| | | //车载poll |
| | | UWB_Tag_Poll(); |
| | | |
| | | MotorPoll(); |
| | | StatusChange(); |
| | | |
| | | MotorPoll(); |
| | | update_led_power_state(); |
| | | if(secondtask_count++%2==0) |
| | | { |
| | | flag_secondtask = 1; |
| | |
| | | |
| | | charge_state_change();//充电状态判断 |
| | | |
| | | if(!power_low_flag)//确认是否休眠下才开启功能 |
| | | { //马达震动逻辑 |
| | | if(g_com_map[MOTOR_ENABLE]) |
| | | { |
| | | if(motor_open_air_flag||moter_open_uwb_flag) |
| | | { |
| | | if (motor_count++%3!=0) |
| | | { |
| | | motor_power_state = 1; |
| | | }else {//修改 |
| | | motor_power_state = 0; |
| | | } |
| | | } else { |
| | | motor_power_state=1; |
| | | } |
| | | }else{ |
| | | motor_power_state=1; |
| | | } |
| | | } |
| | | if(enbale_blink_flag) |
| | | { |
| | | green_charge_state=0; |
| | |
| | | flag_4G_recdata = 1; |
| | | delaysleep_count = 3; |
| | | } |
| | | extern uint16_t ip0,ip1,ip2,ip3,port; |
| | | void Air780E_4G_POLL(void) |
| | | { |
| | | if(!power_low_flag)//确认是否休眠下才开启功能 |
| | | { |
| | | if(flag_TCP_reconnectting||IfTCPConnected()) |
| | | { |
| | | // LOG_INFO(TRACE_MODULE_APP, "处理4G任务\r\n"); |
| | | |
| | | // if(flag_4guart_needinit) |
| | | // { |
| | | // flag_4guart_needinit = 0; |
| | | // AIR780EUartInit(); |
| | | // }//yuan |
| | | if(flag_4G_recdata==1) |
| | | { |
| | | flag_4G_recdata = 2; |
| | | |
| | | //LOG_INFO(TRACE_MODULE_APP, "运行Socket_RecvAll tt2 %d\r\n",tt2); |
| | | Socket_RecvAll(); |
| | | } |
| | | air780_led_on(); |
| | | Internet_Poll(); |
| | | HIDO_ATLitePoll(); |
| | | HIDO_TimerPoll(); |
| | | TCPClient_Poll(); |
| | | air780_led_off(); |
| | | } |
| | | } |
| | | } |
| | | extern uint16_t ip0,ip1,ip2,ip3,port,air780e_send_second; |
| | | extern uint8_t gps_4g_flag; |
| | | extern uint8_t gps_need_data_flag; |
| | | void Program_Init(void) |
| | |
| | | }else{ |
| | | UWB_work_state = SEARCH_DEV; |
| | | } |
| | | if(g_com_map[SEND_4G_SECOND]<60) |
| | | g_com_map[SEND_4G_SECOND]=60; |
| | | // if(g_com_map[SEND_4G_SECOND]<60) |
| | | // g_com_map[SEND_4G_SECOND]=60; |
| | | if(g_com_map[SEND_4G_MINUTE]<1) |
| | | g_com_map[SEND_4G_MINUTE]=1; |
| | | air780e_send_second=g_com_map[SEND_4G_MINUTE]*60; |
| | | g_com_map[MODBUS_MODE] = 0; |
| | | log_4g_enable_flag=g_com_map[LOG_4G_ENABLE]; |
| | | ip0 = (g_com_map[TCP_IP_0]>>12&0xf)*1000+(g_com_map[TCP_IP_0]>>8&0xf)*100+(g_com_map[TCP_IP_0]>>4&0xf)*10+(g_com_map[TCP_IP_0]&0xf); |
| | |
| | | ip2 = (g_com_map[TCP_IP_2]>>12&0xf)*1000+(g_com_map[TCP_IP_2]>>8&0xf)*100+(g_com_map[TCP_IP_2]>>4&0xf)*10+(g_com_map[TCP_IP_2]&0xf); |
| | | ip3 = (g_com_map[TCP_IP_3]>>12&0xf)*1000+(g_com_map[TCP_IP_3]>>8&0xf)*100+(g_com_map[TCP_IP_3]>>4&0xf)*10+(g_com_map[TCP_IP_3]&0xf); |
| | | port = g_com_map[TCP_PORT]; |
| | | g_com_map[VERSION] = (1<<8)|11; |
| | | g_com_map[VERSION] = (1<<8)|12; |
| | | LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); |
| | | LOG_INFO(TRACE_MODULE_APP,"固件版本:UWB-4G车载手环 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); |
| | | LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port); |
| | |
| | | gpio_open(); |
| | | board_output_init(); |
| | | //board_led_init(); |
| | | //防止充电电流过低导致设备无法启动 |
| | | //检测通过后改为正常adc采集模式 |
| | | adc_open(&usr_adc_cfg); |
| | | |
| | | IIC2_Init(); |
| | | Accelerometer_Init(); |
| | | IO_control_init(); |
| | | #ifdef BO_XING |
| | | io_pin_mux_set(SCL_PIN, IO_FUNC0);//测试测距波形 |
| | | gpio_pin_set_dir(SCL_PIN , GPIO_DIR_OUT, 0); |
| | | io_pull_set(SCL_PIN , IO_PULL_DOWN, IO_PULL_UP_LEVEL4); |
| | | #endif |
| | | |
| | | gps_air780_power_change(0,1);//开启gps,4G |
| | | //加速度计初始化必须在IO_control_init之前因为复用SDA引脚 |
| | | Program_Init(); |
| | |
| | | |
| | | } |
| | | IdleTask(); |
| | | UserKeyTask(); |
| | | IMUTask(); |
| | | |
| | | #ifndef DEBUG_MODE |
| | | //if(flag_sleeptimer) |
| | | // if(!gps_need_data_flag&&!gpio_pin_get_val(INPUT_5V_Pin)&&((IfTCPConnected()&&Socket_IsSendQueueEmpty(0))||!flag_TCP_reconnectting&&!IfTCPConnected())) //进入休眠条件(与关系,全满足才进):1.没有5V输入 2 TCP已连接时发送队列为空||TCP无连接时不在重连状态。 |