| | |
| | | #include "HIDO_Timer.h" |
| | | #include "TCPClient.h" |
| | | |
| | | //#define DEBUG_MODE |
| | | #define DEBUG_MODE |
| | | extern int simple_main(void); |
| | | extern int temp_main(void); |
| | | #define TEST_UART_POLL_MODE 0 |
| | |
| | | uint8_t group_id; |
| | | uint16_t tag_frequency; |
| | | uint16_t disoffset; |
| | | uint16_t warning_distance,prewarning_distance; |
| | | |
| | | int16_t fVoltage_mv,first_search_flag; |
| | | uint8_t bat_percent,g_start_send_flag=1; |
| | | uint8_t link_success_flag,motor_count; |
| | |
| | | .int_tx = false, |
| | | #endif |
| | | }; |
| | | |
| | | struct UART_CFG_T test_uart_cfg_uart0 = |
| | | { |
| | | .parity = UART_PARITY_NONE, |
| | | .stop = UART_STOP_BITS_1, |
| | | .data = UART_DATA_BITS_8, |
| | | .flow = UART_FLOW_CONTROL_NONE, |
| | | .rx_level = UART_RXFIFO_CHAR_1, |
| | | .tx_level = UART_TXFIFO_EMPTY, |
| | | .baud = BAUD_9600, |
| | | #if (TEST_UART_MODE == TEST_UART_POLL_MODE) |
| | | .dma_en = false, |
| | | .int_rx = false, |
| | | .int_tx = false, |
| | | #elif (TEST_UART_MODE == TEST_UART_INTERUPT_MODE) |
| | | .dma_en = false, |
| | | .int_rx = true, |
| | | .int_tx = true, |
| | | #elif (TEST_UART_MODE == TEST_UART_DMA_MODE) |
| | | .dma_en = true, |
| | | .int_rx = false, |
| | | .int_tx = false, |
| | | #endif |
| | | }; |
| | | static void app_wdt_callback(void *dev, uint32_t status) |
| | | { |
| | | ASSERT(status, "WDT TIMEOUT,程序复位"); |
| | | //LOG_INFO(TRACE_MODULE_APP, "程序卡死,看门狗复位"); |
| | | } |
| | | struct WDT_CFG_T app_wdt_cfg = { |
| | | .timeout = 32768 * 30, |
| | | .rst_en = true, |
| | | .int_en = true, |
| | | .callback = app_wdt_callback, |
| | | }; |
| | | |
| | | int tt1,tt2; |
| | | void uart_receive_callback(void *dev, uint32_t err_code) |
| | | { |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | } |
| | | void uart0_receive_callback(void *dev, uint32_t err_code) |
| | | { |
| | | uart_receive(UART_ID0,m_EUART0_DMA_RXBuf,EUART_RX_BUF_SIZE,uart0_receive_callback); |
| | | } |
| | | void mcu_deep_sleep(void) |
| | | { |
| | |
| | | //UWB状态检测 |
| | | if(!power_low_flag)//低供电下不需要检测重连 |
| | | { |
| | | if(IfTCPConnected()) |
| | | { |
| | | TCP_reconnect_timer =0; |
| | | flag_TCP_reconnectting = 0; |
| | | } else { |
| | | if(TCP_reconnect_timer<30)//如果TCP没有连接,每隔10分钟尝试连接30秒 |
| | | { |
| | | flag_TCP_reconnectting = 1; |
| | | } else { |
| | | flag_TCP_reconnectting = 0; |
| | | } |
| | | if(TCP_reconnect_timer++>600) |
| | | { |
| | | TCP_reconnect_timer = 0; |
| | | } |
| | | // if(IfTCPConnected()) |
| | | // { |
| | | // TCP_reconnect_timer =0; |
| | | // flag_TCP_reconnectting = 0; |
| | | // } else { |
| | | // if(TCP_reconnect_timer<30)//如果TCP没有连接,每隔10分钟尝试连接30秒 |
| | | // { |
| | | // flag_TCP_reconnectting = 1; |
| | | // } else { |
| | | // flag_TCP_reconnectting = 0; |
| | | // } |
| | | // if(TCP_reconnect_timer++>600) |
| | | // { |
| | | // TCP_reconnect_timer = 0; |
| | | // } |
| | | |
| | | } |
| | | // } |
| | | } |
| | | HIDO_TimerTick(); |
| | | if(nomove_count<=g_com_map[NOMOVESLEEP_TIME])//防止溢出 |
| | |
| | | void Program_Init(void) |
| | | { |
| | | Usart1ParseDataCallback = UsartParseDataHandler;//需改为默认为gps处理,UsartParseDataHandler为升级处理当调试时候改为 |
| | | Usart0ParseDataCallback=Usart0ParseDataHandler; |
| | | parameter_init_anchor();//g_com_map表初始化角色默认为基站 |
| | | dev_id=g_com_map[DEV_ID];//这里不太对 |
| | | group_id=g_com_map[GROUP_ID];//组ID |
| | |
| | | memcpy(&disoffset,&g_com_map[DIST_OFFSET],2); |
| | | // g_com_map[ALARM_DISTANCE1] = 40; |
| | | // g_com_map[ALARM_DISTANCE2] = 40; |
| | | warning_distance=g_com_map[ALARM_DISTANCE1]; |
| | | prewarning_distance=g_com_map[ALARM_DISTANCE2]; |
| | | send_struct.warnDistence=warning_distance; |
| | | send_struct.alarmDistence=prewarning_distance;//更新报警距离 |
| | | memcpy(&send_struct.gunLableId,&g_com_map[BIND_DEV_ID],2);//更新绑定ID |
| | | send_struct.tagId=dev_id;//更新设备ID |
| | | // warning_distance=g_com_map[ALARM_DISTANCE1]; |
| | | // prewarning_distance=g_com_map[ALARM_DISTANCE2]; |
| | | // send_struct.warnDistence=warning_distance; |
| | | // send_struct.alarmDistence=prewarning_distance;//更新报警距离 |
| | | // memcpy(&send_struct.gunLableId,&g_com_map[BIND_DEV_ID],2);//更新绑定ID |
| | | // send_struct.tagId=dev_id;//更新设备ID |
| | | |
| | | if(g_com_map[BIND_DEV_ID]==0) |
| | | { |
| | |
| | | //UartDeinit(); |
| | | } |
| | | } |
| | | UART0_CheckReceive(); |
| | | UART_CheckReceive(); |
| | | } |
| | | int bind_check(void) |
| | |
| | | |
| | | // Disable watchdog timer |
| | | wdt_close(WDT_ID0); |
| | | wdt_open(WDT_ID0,&app_wdt_cfg);//30s最大上限检测喂狗 |
| | | LOG_INFO(TRACE_MODULE_APP, "UWB simple example\r\n"); |
| | | |
| | | // open system timer |
| | | //sys_timer_open(); |
| | | |
| | | // TODO 4G |
| | | // // TODO 4G |
| | | Uart_Register(UART_ID_4G, UART_ID0); |
| | | Internet_Init(); |
| | | TCPClient_Init(); |
| | | //TCPClient_Init(); |
| | | |
| | | |
| | | gpio_open(); |
| | | board_output_init(); |
| | | //uart_open(UART_ID0, &test_uart_cfg_uart0); |
| | | //board_led_init(); |
| | | //检测通过后改为正常adc采集模式 |
| | | adc_open(&usr_adc_cfg); |
| | |
| | | // uart1_change_from_gps_to_debug(); |
| | | //Uart1GpsRecDebugSend(); |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | |
| | | uart_receive(UART_ID0,m_EUART0_DMA_RXBuf,EUART_RX_BUF_SIZE,uart0_receive_callback); |
| | | // Initialize low power mode |
| | | power_init(); |
| | | //AIR780E_Reset(); //4G模块重启,耗时1.5秒,这个是无法同步的关键 |
| | |
| | | adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 |
| | | board_acceleration_detection_init(move_handler); |
| | | // LOG_INFO(TRACE_MODULE_APP, "测试进入app"); |
| | | board_4GUsart_detection_init(_4gUsart_handler); |
| | | //board_4GUsart_detection_init(_4gUsart_handler); |
| | | while (1) |
| | | { tt1=gpio_pin_get_val(ADC_GND_ENABLE); |
| | | wdt_ping(WDT_ID0);//喂狗 |
| | | //tt2 = gpio_pin_get_val(_4G_USART_RX_Pin); |
| | | if(!power_low_flag)//确认是否休眠下才开启功能 |
| | | { |
| | | if(flag_TCP_reconnectting||IfTCPConnected()) |
| | | { |
| | | // LOG_INFO(TRACE_MODULE_APP, "处理4G任务\r\n"); |
| | | |
| | | // if(flag_4guart_needinit) |
| | | // if(flag_TCP_reconnectting||IfTCPConnected()) |
| | | // { |
| | | // 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(); |
| | | } |
| | | // // 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(); |
| | | // } |
| | | } |
| | | if(flag_secondtask) |
| | | { |