chen
2024-09-03 11163a8d87777cd4d47f6bc477fd7b75eccdf8a1
keil/uwb_app.c
@@ -102,7 +102,7 @@
/* Default communication configuration. */
static struct mk_uwb_configure config = {
    .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX),
    .phy_cfg.ch_num = 9,                      /* Channel number.                           */
    .phy_cfg.ch_num = 5,                      /* Channel number.                           */
    .phy_cfg.code_index = 9,                  /* TX preamble code.                         */
    .phy_cfg.mean_prf = MEAN_PRF_64M,         /* Data rate 6.8M                            */
    .phy_cfg.data_bit_rate = DATA_BR_6M8,     /* data rate 6.8M.                           */
@@ -226,6 +226,7 @@
        /* UWB_BD_ERR      Preamble detection error  */
        /* UWB_TO_ERR      Receive timeout           */
        /* UWB_STS_ERR     STS error                 */
                 temp_count= phy_timer_count_get();
        memcpy(&rx_rpt, rx_report, sizeof(struct MAC_HW_REPORT_T));
        rx_length = 0;
@@ -254,6 +255,7 @@
static int32_t tagdist_list[TAG_NUM_IN_SYS];
uint16_t random_time;
//anchor
int32_t hist_dist;
void PushAnchorDataArray(uint16_t ancid,int16_t dist,uint8_t battary)
{
    uint8_t i;
@@ -274,8 +276,8 @@
    anchordata_dist[i] = dist;
    anchordata_bat[i] = battary;
    tagofflinetime[i]=0;//不断更新当前TAG对应离线时间
    //if(dist>0)
    distance=dist;
    if(dist>0)
    distance=dist*0.5+distance*0.5;
}
uint16_t CmpTagInList(uint16_t tagid)
{   uint16_t i;
@@ -426,10 +428,12 @@
                Anchor_RecNearPoll(i);
            }
            sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
            LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度:%d.\r\n",g_com_map[BIND_DEV_ID],distance,rssi);
        }
    } else {
        LOG_INFO(TRACE_MODULE_APP,"测距失败\r\n");
        sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
        LOG_INFO(TRACE_MODULE_APP,"测距失败,计数:%d\r\n",recev_error_num);
        if(recev_error_num++>5)
        {
            recev_error_num=0;
@@ -438,7 +442,7 @@
            search_open_flag = 1;
        }
    }
    sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
    gpio_pin_clr(SCL_PIN);
}
@@ -483,11 +487,12 @@
    {
        end_receive_count-=UINT32_MAX;
    }
    current_count=phy_timer_count_get();
    while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000
    {
        while(mac_is_busy())
        {
            IdleTask();
            current_count=phy_timer_count_get();
            if(current_count>end_receive_count&&current_count<end_receive_count+HALF_SECOND_TIME)
            {
@@ -536,19 +541,19 @@
            }
        }
            temp_count3=phy_timer_count_get();
        uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收
    }
    // LOG_INFO(TRACE_MODULE_APP,"超时定时器:%x,%x,%x\r\n",start_receive_count,end_receive_count,current_count);
    gpio_pin_clr(SCL_PIN);//测试
    return 0;//返回绑定失败标志
}
//}
#define SEARCH_TIMESTEMP 120
#define SEARCH_TIMESTEMP 20
void UWBPoll(void)
{
    LOG_INFO(TRACE_MODULE_APP,"UWB状态:%d\r\n",UWB_work_state);
    switch(UWB_work_state)
    {
    case LINK_SUCCESS:
@@ -571,6 +576,8 @@
            uwb_led_off();
            if(link_success_flag)
                UWB_work_state=LINK_SUCCESS;
        }else{
            LOG_INFO(TRACE_MODULE_APP,"等待进入搜索模式:%d\r\n",SEARCH_TIMESTEMP-uwb_searchcount);
        }
    }
@@ -600,6 +607,7 @@
        //link_error_count=0;
        update_led_power_state();//更新灯状态
    }
     LOG_INFO(TRACE_MODULE_APP,"UWB状态:%d\r\n",UWB_work_state);
}
uint8_t GetUWBBindState(void)