keil/uwb_app.c
@@ -270,6 +270,8 @@
uint16_t random_time;
//anchor
int32_t hist_dist;
int16_t temp_recdist_before_offset;
int16_t dist_temp;
void PushAnchorDataArray(uint16_t ancid,int16_t dist,uint8_t battary)
{
    uint8_t i;
@@ -290,8 +292,9 @@
    anchordata_dist[i] = dist;
    anchordata_bat[i] = battary;
    tagofflinetime[i]=0;//不断更新当前TAG对应离线时间
      dist_temp=dist;
//    if(dist>0)
      if(distance!=0x1ffff&&distance!=0)
      if(temp_recdist_before_offset!=0&&distance!=0x1ffff)
      {
    distance=dist*0.5+distance*0.5;
      }else{
@@ -372,6 +375,7 @@
uint32_t range_timeout_us = 5000;
uint16_t uwb_searchcount;
uint8_t flag_recsuccess;
uint8_t flag_temp2,flag_temp1;
extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag;
int UwbRange(void)
{
@@ -405,7 +409,8 @@
      flag_recsuccess = 0;
    temp_count3=phy_timer_count_get();
    gpio_pin_set(SCL_PIN);
    uwb_rx(0, 0, range_timeout_us);//开启接收
    flag_temp1=uwb_rx(0, 0, range_timeout_us);//开启接收
   // while(mac_is_busy());
  //  temp_count2=phy_timer_count_get();
      start_receive_count=phy_timer_count_get();
@@ -431,7 +436,7 @@
    {
        if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL&&!memcmp(&rx_buf[TAG_ID_IDX],&g_com_map[BIND_DEV_ID],2))//判断是否是和自己是同一组通讯的且为poll包
        {   flag_recsuccess = 1;
        {    flag_recsuccess = 1;
                sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
                 temp_count2=phy_timer_count_get();
            frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序
@@ -444,7 +449,7 @@
            for(i=0; i<rec_nearbase_num; i++)
            {
                if(rec_ancidlist[i] == dev_id)
                {
                {      temp_recdist_before_offset=rec_ancdistlist[i];
                    rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET];
                    PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary);
                }
@@ -464,15 +469,14 @@
            {
                seize_anchor=1;   //抢占anchor
                Anchor_RecNearPoll(i);
            }
                  recev_error_num=0;
              range_timeout_us=5000;//恢复为5000进入range后
            LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度:%d.\r\n",g_com_map[BIND_DEV_ID],distance,rssi);
        break;
            }
    } else {
         uwb_rx(0, 0, range_timeout_us);
         flag_temp1=uwb_rx(0, 0, range_timeout_us);
    }
   }
      delay_us(1);
@@ -528,7 +532,7 @@
    receive_flag = 0;
    temp_count3=phy_timer_count_get();
    gpio_pin_set(SCL_PIN);
    uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//开启接收
    flag_temp2=uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//开启接收
    start_receive_count=phy_timer_count_get();
    poll_timeout=US_TO_PHY_TIMER_COUNT(2000000);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
    end_receive_count=start_receive_count+poll_timeout;
@@ -554,7 +558,8 @@
        {
            if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL&&!memcmp(&rx_buf[TAG_ID_IDX],&g_com_map[BIND_DEV_ID],2))//判断是否是和自己是同一组通讯的且为poll包
            {   
                       sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-1));//测试
                       sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-13));//测试
                        range_timeout_us=20000;//将下次range开启后超时时间设为20ms之后再range里恢复
                        temp_count2=phy_timer_count_get();
                frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序
                battary = rx_buf[BATTARY_IDX];
@@ -567,6 +572,8 @@
                {
                    if(rec_ancidlist[i] == dev_id)
                    {
                                    temp_recdist_before_offset=rec_ancdistlist[i];
                                    rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET];
                        PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary);
                    }
                }
@@ -588,15 +595,15 @@
                }
                
                gpio_pin_clr(SCL_PIN);//测试
                        LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度:%d.\r\n",g_com_map[BIND_DEV_ID],distance,rssi);
                return 1;//返回发送成功标志
            }
        }
            temp_count3=phy_timer_count_get();
        uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收
        flag_temp2=uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收
    }
      delay_us(1);
      delay_us(2);
      uwb_rx_force_off(1);
    // LOG_INFO(TRACE_MODULE_APP,"超时定时器:%x,%x,%x\r\n",start_receive_count,end_receive_count,current_count);
    gpio_pin_clr(SCL_PIN);//测试