WXK
7 天以前 2ee355706fb52cd610000dfa89ad244656428d72
keil/include/main/main.c
@@ -342,7 +342,7 @@
uint8_t Get_anchor_appdata_flag;
uint8_t Get_anchor_appdata_num;
extern uint8_t update_tag_time;
uint8_t sleep_limit_time=1;
uint8_t sleep_limit_time=10;
uint8_t enable_sleep_count,sleep_flag;
static void sleep_timer_callback(void *dev, uint32_t time)
{
@@ -420,11 +420,11 @@
    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)|0;
    g_com_map[VERSION] = (1<<8)|4;
    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);
}
}
extern uint8_t motor_state;
extern  float motor_keeptime;
uint8_t test1;
@@ -449,7 +449,7 @@
//                }
//                pwm_ch_enable(PWM_ID0, &usr_pwm_ch0_cfg);
//                        delay_ms(10000);
                pwm_ch_disable(PWM_ID0);
                pwm_ch_disable(PWM_ID3);
                break;
            case 1:
//                if(current_time<MOTOR_ONTIME)
@@ -477,7 +477,7 @@
//                    {
//                    HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
//                    }   
                pwm_ch_enable(PWM_ID0, &usr_pwm_ch0_cfg);
                pwm_ch_enable(PWM_ID3, &usr_pwm_ch0_cfg);
                break;
            case 3:
//                if(hardware_type==NSH1)
@@ -504,7 +504,7 @@
        if(state5v==1)
        {
        state5v=0;
        sleep_limit_time=1;//新增插入串口后30s不休眠
        sleep_limit_time=10;//新增插入串口后30s不休眠
        enable_sleep_count=0;//重新插拔可以重置时间
        }
@@ -605,43 +605,6 @@
    uint32_t tx_en_start_u32;
    uint32_t tx_en_start_u321;
uint8_t baifenbi=5;
void Lora_upanc_ing_Poll( void )
{   uint16_t crc16;
//    if(Lora_upanc_flag==1)
//    {
//        Lora_deinit_Poll();
        if(Lora_qingqiu_flag==1)
        {
            CloseUWB();
//            mubiao_anchor_ID=0x1872;
            final_bag_num=(g_com_map[YAOGEIANC_UPWENJIAN_DAXIAO]/ONE_BAG_DAXIAO)+1;//计算一共要发都是包
//            final_bag_num=651;
            Lora_qingqiu_flag=0;
            send_lora_data[MSG_TYPE_IDX]=LORA_MSGTYPE_UPDATEFILE_RESP;//LORA MSG TYPE 定义
            memcpy(&send_lora_data[SOURCE_ID_IDX],&dev_id,2);//自己ID 占用2个字节
            memcpy(&send_lora_data[DEST_ID_IDX],&mubiao_anchor_ID,2);//标签或者基站的设备ID 2个字节
            memcpy(&send_lora_data[MUQIAN_BAG],&Lora_qingqiu_bao,2);
            memcpy(&send_lora_data[DATA_IDX], (HIDO_VOID *)(APP_CONFIG_APPLICATION_ADDRESS+Lora_qingqiu_bao*ONE_BAG_DAXIAO), ONE_BAG_DAXIAO);
            crc16=Cal_CRC16(send_lora_data,DATA_IDX+ONE_BAG_DAXIAO);
            memcpy(&send_lora_data[DATA_IDX+ONE_BAG_DAXIAO],&crc16,2);
//            Lora_status=1;
            jindu=(Lora_qingqiu_bao*100)/final_bag_num;
//            LOG_INFO(TRACE_MODULE_APP, "升级进度%d\r\n",jindu);
            Dtu_shengji_jindu[4]=jindu;
            memcpy(&Dtu_shengji_jindu[5],&mubiao_anchor_ID,2);
            if(jindu>baifenbi)
            {
            uart_send(UART_ID0, Dtu_shengji_jindu,9, NULL);
                baifenbi=baifenbi+10;
            }
            tx_en_start_u32 = phy_timer_count_get()+US_TO_PHY_TIMER_COUNT(100U);//发送必须要延时发送才可以用于测距否则立即发送会获取时间戳不对,需要计算程序运行时间,避免设置过去时间
            tempflag=uwb_tx(send_lora_data,DATA_IDX+ONE_BAG_DAXIAO+2+2,1,tx_en_start_u32);//立即发送
            tx_en_start_u321= phy_timer_count_get();
//            while(mac_is_busy());//等待发送完成
        }
//    }
}
static void pwm_callback(void *dev, uint32_t status)
{
//    uint8_t id = *(uint8_t *)dev;
@@ -659,16 +622,11 @@
    board_clock_run();
    boot_deinit();
    board_pins_config();
   board_debug_console_open_baud(TRACE_PORT_UART0,BAUD_115200);
    board_debug_console_open_baud(TRACE_PORT_UART0,BAUD_115200);
    // Reset reason
    reset_cause_get();
    reset_cause_clear();
    Program_Init();
//    sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback);
//    sleep_timer_start(__MS_TO_32K_CNT(500));//测试
//    Chuanshuwenjian_Poll();
//注意串口一波特率改为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)
@@ -681,10 +639,8 @@
    {
        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");
@@ -697,56 +653,27 @@
    pwm_open(&usr_pwm_cfg);
//    pwm_ch_enable(PWM_ID0, &usr_pwm_ch0_cfg);
    gpio_open();
      LED_output_init();//配置adcGND引脚
//      battery_monitor_open();
//      Voltage_input=battery_monitor_get();
//      battery_monitor_close();
    LED_output_init();//配置adcGND引脚
    adc_open(&usr_adc_cfg);
      
    IIC2_Init();
    SC7A22H_Motion_Detection_Init();
//      PCA9555_init();
//      if(!read_5v_input_pca())
//      {
//     Set4LEDColor(BLUE,GREEN,WHITE,GREEN);
//     delay_ms(500);
//     Set4LEDColor(RED,WHITE,RED,WHITE);
//     delay_ms(500);
//     //Set4LEDColor(LEDOFF,LEDOFF,LEDOFF,LEDOFF);
//    }
         //IO_control_init();
//    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);
    //gps_air780_power_change(0,1);//开启gps,4G
//加速度计初始化必须在IO_control_init之前因为复用SDA引脚
      gpio_pin_clr(ADC_GND_ENABLE);
         Program_Init();
    //uart_open(UART_ID1, &test_uart_cfg);
   // uart1_change_from_gps_to_debug();
    //Uart1GpsRecDebugSend();
    gpio_pin_clr(ADC_GND_ENABLE);
    Program_Init();
    uart_receive(UART_ID0,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);
    #ifdef _UWB_1HZ
    sleep_timer_start(__MS_TO_32K_CNT(1000));//测试
    #else
    sleep_timer_start(__MS_TO_32K_CNT(5000));//测试
    //sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试
   board_5V_input_init(voltage_input_handler);
//         PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低
       adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样
    #endif
    board_5V_input_init(voltage_input_handler);
    adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样
    board_acceleration_detection_init(move_handler);
//      pca_input_detection_init(pca_handler);//pca检测输入
      Uwb_init();
//      OpenUWB();
//        LOG_INFO(TRACE_MODULE_APP,"初始化_uwb_rx打开\r\n");
      Dw1000_App_Init();
      //board_4GUsart_detection_init(_4gUsart_handler);
//pwm_ch_enable(PWM_ID0, &usr_pwm_ch0_cfg);
//        delay_ms(10000);
//pwm_ch_disable(PWM_ID0);
    Uwb_init();
    Dw1000_App_Init();
    while (1)
    { 
        if(flag_secondtask)
@@ -757,12 +684,15 @@
        if(g_start_send_flag)
        {
            g_start_send_flag = 0;
            gpio_pin_set(IO_PIN_7);//亮
          SwitchTagState();   
            gpio_pin_clr(IO_PIN_7);//灭
        }
//            PowerTask();
            IMUTask();
//            UserKeyTask();
        IdleTask();
        LoraUp_Poll();
#ifndef DEBUG_MODE
        
         if(sleep_flag&&state5v==0){//开始一段时间无休眠