| | |
| | | /* |
| | | * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and |
| | | * its subsidiaries and affiliates (collectly called MKSEMI). |
| | | * |
| | | * All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * 1. Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * |
| | | * 2. Redistributions in binary form, except as embedded into an MKSEMI |
| | | * integrated circuit in a product or a software update for such product, |
| | | * must reproduce the above copyright notice, this list of conditions and |
| | | * the following disclaimer in the documentation and/or other materials |
| | | * provided with the distribution. |
| | | * |
| | | * 3. Neither the name of MKSEMI nor the names of its contributors may be used |
| | | * to endorse or promote products derived from this software without |
| | | * specific prior written permission. |
| | | * |
| | | * 4. This software, with or without modification, must only be used with a |
| | | * MKSEMI integrated circuit. |
| | | * |
| | | * 5. Any software provided in binary form under this license must not be |
| | | * reverse engineered, decompiled, modified and/or disassembled. |
| | | * |
| | | * THIS SOFTWARE IS PROVIDED BY MKSEMI "AS IS" AND ANY EXPRESS OR IMPLIED |
| | | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| | | * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| | | * DISCLAIMED. IN NO EVENT SHALL MKSEMI OR CONTRIBUTORS BE LIABLE FOR ANY |
| | | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| | | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| | | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| | | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| | | */ |
| | | |
| | | #include "mk_trace.h" |
| | | #include "mk_wdt.h" |
| | | #include "mk_calib.h" |
| | |
| | | #include "TCPClient.h" |
| | | #include "PCA9555.h" |
| | | #include "WS2812.h" |
| | | #include "DBG.h" |
| | | typedef enum |
| | | { |
| | | RTCMMODE_NONE, |
| | | RTCMMODE_TCP, |
| | | RTCMMODE_NTRIP, |
| | | }RTCMMode; |
| | | |
| | | //#define DEBUG_MODE |
| | | extern int simple_main(void); |
| | |
| | | extern uint8_t state5V_prase_flag,gps_prase_flag; |
| | | extern int distance; |
| | | extern uint8_t anchordata_num; |
| | | uint32_t dev_id; |
| | | uint16_t dev_id; |
| | | uint8_t group_id; |
| | | uint16_t tag_frequency; |
| | | uint16_t disoffset; |
| | |
| | | .flow = UART_FLOW_CONTROL_NONE, |
| | | .rx_level = UART_RXFIFO_CHAR_1, |
| | | .tx_level = UART_TXFIFO_EMPTY, |
| | | .baud = BAUD_9600, |
| | | .baud = BAUD_115200, |
| | | #if (TEST_UART_MODE == TEST_UART_POLL_MODE) |
| | | .dma_en = false, |
| | | .int_rx = false, |
| | |
| | | LOG_INFO(TRACE_MODULE_APP, "电池电压正常,4G,GPS,正常工作\r\n"); |
| | | } |
| | | PCA9555_Set_One_Value_Output(ADC_MINIUS,1);//拉高 |
| | | // LOG_INFO(TRACE_MODULE_APP, "The voltage is %%%d \r\n",bat_percent); |
| | | } |
| | | extern uint8_t gps_uwb_flag,gps_need_data_flag; |
| | | uint8_t TCP_reconnect_timer,flag_TCP_reconnectting = 1,flag_alam_state = 0,userkey_state; |
| | |
| | | { |
| | | PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低 |
| | | adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 |
| | | } |
| | | void Air780eTask(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(); |
| | | } |
| | | Internet_Poll(); |
| | | HIDO_ATLitePoll(); |
| | | HIDO_TimerPoll(); |
| | | TCPClient_Poll(); |
| | | |
| | | } |
| | | // } |
| | | |
| | | } |
| | | void SecondTask(void) |
| | | {static uint8_t second_count; |
| | |
| | | Usart1ParseDataCallback = UsartParseDataHandler;//需改为默认为gps处理,UsartParseDataHandler为升级处理当调试时候改为 |
| | | parameter_init_anchor();//g_com_map表初始化角色默认为基站 |
| | | dev_id=g_com_map[DEV_ID];//这里不太对 |
| | | g_com_map[GROUP_ID]=9; |
| | | group_id=g_com_map[GROUP_ID];//组ID |
| | | // tag_frequency = 1000/g_com_map[COM_INTERVAL];//测距频率这个存的是测距时间 |
| | | 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 |
| | | |
| | | g_com_map[IP_0]=111; |
| | | g_com_map[IP_1]=198; |
| | | g_com_map[IP_2]=60; |
| | | g_com_map[IP_3]=6; |
| | | g_com_map[PORT]=6666; |
| | | g_com_map[RTCMMODE_INDEX] = RTCMMODE_NTRIP; |
| | | snprintf((char *)&g_com_map[NTRIP_HOST_INDEX], 32, "140.143.212.42"); |
| | | g_com_map[NTRIP_PORT_INDEX] = HIDO_UtilStrToInt("8005"); |
| | | // snprintf((char *)&g_com_map[NTRIP_PORT_INDEX], 32, "8005"); |
| | | snprintf((char *)&g_com_map[NTRIP_USERNANME_INDEX], 32, "test005"); |
| | | snprintf((char *)&g_com_map[NTRIP_PASSWORD_INDEX], 32, "Hxzk0228"); |
| | | snprintf((char *)&g_com_map[NTRIP_SOURCENAME_INDEX], 32, "RTCM32_GNSS2"); |
| | | |
| | | |
| | | if(g_com_map[BIND_DEV_ID]==0) |
| | | { |
| | |
| | | } |
| | | 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); |
| | | ip1 = (g_com_map[TCP_IP_1]>>12&0xf)*1000+(g_com_map[TCP_IP_1]>>8&0xf)*100+(g_com_map[TCP_IP_1]>>4&0xf)*10+(g_com_map[TCP_IP_1]&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)|1; |
| | | g_com_map[VERSION] = (1<<8)|3; |
| | | |
| | | |
| | | LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); |
| | | LOG_INFO(TRACE_MODULE_APP,"固件版本:4G-GPS定位手环 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); |
| | | LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",g_com_map[IP_0],g_com_map[IP_1],g_com_map[IP_2],g_com_map[IP_3],g_com_map[PORT]); |
| | | if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_TCP) |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP,"TCP_RTCM模式,服务器地址: %d.%d.%d.%d:%d.\r\n",g_com_map[TCP_IP_0],g_com_map[TCP_IP_1],g_com_map[TCP_IP_2],g_com_map[TCP_IP_3],g_com_map[TCP_PORT]); |
| | | } |
| | | else if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_NTRIP) |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP,"NtripHost:%s.\r\n",(char *)&g_com_map[NTRIP_HOST_INDEX]); |
| | | LOG_INFO(TRACE_MODULE_APP,"NtripPort:%d.\r\n",g_com_map[NTRIP_PORT_INDEX]); |
| | | LOG_INFO(TRACE_MODULE_APP,"NtripUsername:%s.\r\n",(char *)&g_com_map[NTRIP_USERNANME_INDEX]); |
| | | LOG_INFO(TRACE_MODULE_APP,"NtripPassword:%s.\r\n",(char *)&g_com_map[NTRIP_PASSWORD_INDEX]); |
| | | LOG_INFO(TRACE_MODULE_APP,"NtripSourcename:%s.\r\n",(char *)&g_com_map[NTRIP_SOURCENAME_INDEX]); |
| | | } |
| | | else if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_NONE) |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP,"单点定位模式模式. \r\n"); |
| | | } |
| | | } |
| | | uint32_t adctick = 0; |
| | | uint8_t only_one_flag; |
| | | uint16_t chongman_time; |
| | | uint8_t bat_percent_old=100; |
| | | uint8_t input5vflag; |
| | | uint8_t kai_4g_flag; |
| | | void IdleTask(void) |
| | | { |
| | | if(read_5v_input_pca()) |
| | |
| | | }else{ |
| | | powerled = RED; |
| | | } |
| | | UART_CheckReceive(); |
| | | if(DBG_GetMode() == DBG_MODE_SHELL) |
| | | { |
| | | if(kai_4g_flag==0) |
| | | { |
| | | kai_4g_flag=1; |
| | | // PCA9555_Set_One_Value_Output(AIR780E_ENBALE,1); |
| | | Shell_Init(); |
| | | } |
| | | HIDO_InputPoll(); |
| | | Internet_Poll(); |
| | | HIDO_TimerPoll(); |
| | | HIDO_ATLitePoll(); |
| | | TCPClient_Poll(); |
| | | } |
| | | UART_CheckReceive(); |
| | | if(flag_secondtask) |
| | | { |
| | | flag_secondtask = 0; |
| | |
| | | state5V_prase_flag=state5v; |
| | | gps_prase_flag=1;//恢复gps解析 |
| | | uart1_change_from_debug_to_gps();//测试 |
| | | PCA9555_Set_One_Value_Output(MCU_A,0);//输出低电平切换为GPS |
| | | PCA9555_Set_One_Value_Output(MCU_A,0);//输出低电平切换为GPS |
| | | } |
| | | // input5vflag=0; |
| | | } |
| | | UART_CheckReceive(); |
| | | if(g_com_map[CNT_RESTART]==1) |
| | | { |
| | | g_com_map[CNT_RESTART]=0; |
| | | // printf("%s URTRestart",__debug_info__); |
| | | // URTRestart(); |
| | | NVIC_SystemReset(); |
| | | |
| | | } |
| | | if(g_com_map[MAP_SIGN_INDEX]!=0x55AA||g_com_map[COM_INTERVAL]==0) |
| | | { |
| | | // printf("%s URTRestart",__debug_info__); |
| | | // URTRestart(); |
| | | // // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | NVIC_SystemReset(); |
| | | } |
| | | HIDO_TimerPoll(); |
| | |
| | | int tt2; |
| | | int test1,test3; |
| | | uint32_t test4; |
| | | |
| | | extern uint8_t receive_flag; |
| | | int main(void) |
| | | { |
| | | board_clock_run(); |
| | | boot_deinit(); |
| | | board_pins_config(); |
| | | board_debug_console_open_baud(TRACE_PORT_UART1,BAUD_115200); |
| | | board_debug_console_open_baud(TRACE_PORT_UART1,BAUD_115200); |
| | | // Reset reason |
| | | reset_cause_get(); |
| | | reset_cause_clear(); |
| | | //注意串口一波特率改为9600了为了能和GPS通信上 |
| | | // Load calibration parameters from NVM |
| | | uint32_t internal_flash = (REG_READ(0x40000018) >> 17) & 0x1; |
| | | uint32_t external_flash = (REG_READ(0x40010030) >> 28) & 0x3; |
| | | if (internal_flash || external_flash == 1) |
| | |
| | | { |
| | | board_calibration_params_default(); |
| | | } |
| | | |
| | | // Chip calibration |
| | | calib_chip(); |
| | | |
| | | // Disable watchdog timer |
| | | wdt_close(WDT_ID0); |
| | | LOG_INFO(TRACE_MODULE_APP, "UWB simple example\r\n"); |
| | | |
| | | // open system timer |
| | | //sys_timer_open(); |
| | | // TODO 4G |
| | | Uart_Register(UART_ID_4G, UART_ID0); |
| | | // Uart_Register(UART_ID_DBG, UART_ID1); |
| | | Program_Init(); |
| | | Internet_Init(); |
| | | TCPClient_Init(); |
| | | if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_NTRIP) |
| | | { |
| | | NTRIPClient_Init(); |
| | | NTRIPApp_Init(); |
| | | } |
| | | gpio_open(); |
| | | LED_output_init();//配置彩色灯引脚 |
| | | IIC2_Init(); |
| | | Accelerometer_Init(); |
| | | PCA9555_init(); |
| | | |
| | | |
| | | //AIR780E_Reset(); |
| | | |
| | | adc_open(&usr_adc_cfg); |
| | | |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | power_init(); |
| | | sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback); |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 |
| | | PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低 |
| | | adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 |
| | | pca_input_detection_init(pca_handler);//pca检测输入 |
| | | Uwb_init(); |
| | | OpenUWB(); |
| | | DBG_Init(); |
| | | // Shell_Init(); |
| | | |
| | | if(!read_5v_input_pca()) |
| | | { |
| | | Set4LEDColor(BLUE,GREEN,WHITE,RED); |
| | |
| | | delay_ms(500); |
| | | Set4LEDColor(LEDOFF,LEDOFF,LEDOFF,LEDOFF); |
| | | } |
| | | // io_pin_mux_set(SCL_PIN, IO_FUNC0);//测试测距波形 |
| | | // gpio_pin_set_dir(SCL_PIN , GPIO_DIR_IN, 0); |
| | | // io_pull_set(SCL_PIN , IO_PULL_UP, IO_PULL_UP_LEVEL4); |
| | | Program_Init(); |
| | | //uart_open(UART_ID1, &test_uart_cfg); |
| | | // uart1_change_from_gps_to_debug(); |
| | | //Uart1GpsRecDebugSend(); |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | |
| | | // Initialize low power mode |
| | | power_init(); |
| | | //AIR780E_Reset(); //4G模块重启,耗时1.5秒,这个是无法同步的关键 |
| | | sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback); |
| | | //sleep_timer_start(__MS_TO_32K_CNT(g_com_map[COM_INTERVAL]));//测试 |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 |
| | | PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低 |
| | | adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 |
| | | //board_acceleration_detection_init(move_handler); |
| | | pca_input_detection_init(pca_handler);//pca检测输入 |
| | | //board_4GUsart_detection_init(_4gUsart_handler); |
| | | Uwb_init(); |
| | | OpenUWB(); |
| | | // state5v=1; |
| | | // state5V_prase_flag=state5v; |
| | | // gps_prase_flag=0;//解除gps解析 |
| | | // uart1_change_from_gps_to_debug();//测试 |
| | | // PCA9555_Set_One_Value_Output(MCU_A,1);//输出高电平切换为5V输入 |
| | | while (1) |
| | | { |
| | | uwb_app_poll(); |
| | |
| | | IMUTask(); |
| | | UserKeyTask(); |
| | | IdleTask(); |
| | | #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无连接时不在重连状态。 |
| | | //// { |
| | | //// if(!flag_4guart_needinit) |
| | | //// { |
| | | //// LOG_INFO(TRACE_MODULE_APP, "4G RX 中断打开\r\n"); |
| | | //// board_4GUsart_detection_init(_4gUsart_handler); |
| | | |
| | | //// } |
| | | //// flag_sleeptimer =0; |
| | | // //LOG_INFO(TRACE_MODULE_APP, "进入休眠\r\n"); |
| | | //// flag_4guart_needinit = 1; |
| | | |
| | | //// trace_flush(); |
| | | //// uint32_t lock = int_lock(); |
| | | //// //LOG_INFO(TRACE_MODULE_APP, "进入低功耗"); |
| | | //// power_enter_power_down_mode(0); |
| | | //// int_unlock(lock); |
| | | //// }//yuan |
| | | |
| | | // if(delaysleep_count==0) |
| | | // if(!gps_power_state&&!gpio_pin_get_val(INPUT_5V_Pin)&&((IfTCPConnected()&&AIR780E_IsIPIdle()&&Socket_IsSendQueueEmpty(0))||((!flag_TCP_reconnectting)&&!IfTCPConnected())||power_low_flag)) |
| | | // { |
| | | //// test1=gpio_pin_get_val(_4G_USART_RX_Pin); |
| | | // uint32_t lock; |
| | | // //flag_4guart_needinit = 1; |
| | | //// Internet_Poll(); |
| | | //// HIDO_ATLitePoll(); |
| | | //// HIDO_TimerPoll(); |
| | | //// TCPClient_Poll(); |
| | | // |
| | | // // delay_us(300000); |
| | | // trace_flush(); |
| | | // lock = int_lock(); |
| | | // power_enter_power_down_mode(0); |
| | | // uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | //// test3=gpio_pin_get_val(_4G_USART_RX_Pin); |
| | | // //LOG_INFO(TRACE_MODULE_APP, "进入休眠\r\n"); |
| | | // int_unlock(lock); |
| | | // } |
| | | |
| | | #endif |
| | | } |
| | | } |