WXK
2024-09-27 309c1a9532dd4978720eeff3aa51e7184f35bb96
keil/uwb_app.c
@@ -216,7 +216,7 @@
        poll_rx_num++;
        rssi = rx_report->rssi;
        receive_flag=1;
        recev_error_num=0;
    }
    else
    {
@@ -276,7 +276,7 @@
    anchordata_dist[i] = dist;
    anchordata_bat[i] = battary;
    tagofflinetime[i]=0;//不断更新当前TAG对应离线时间
    if(dist>0)
//    if(dist>0)
    distance=dist*0.5+distance*0.5;
}
uint16_t CmpTagInList(uint16_t tagid)
@@ -347,7 +347,8 @@
    while(mac_is_busy());
    gpio_pin_clr(SCL_PIN);
}
uint16_t uwb_searchcount;
uint16_t uwb_searchcount,range_timeout_us = 5000;
uint8_t flag_recsuccess;
extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag;
int UwbRange(void)
{
@@ -378,24 +379,36 @@
    mac_register_process_handler(tx_int_callback, rx_int_callback);
    receive_flag = 0;
      flag_recsuccess = 0;
    temp_count3=phy_timer_count_get();
    gpio_pin_set(SCL_PIN);
    uwb_rx(0, 0, RX_SYNC_WIN_US);//开启接收
    while(mac_is_busy());
    temp_count2=phy_timer_count_get();
//      start_receive_count=phy_timer_count_get();
//   poll_timeout=rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS)+US_TO_PHY_TIMER_COUNT(DELAY_DEFAULT);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
//   end_receive_count=start_receive_count+poll_timeout;
//   if(end_receive_count>=UINT32_MAX)
//   {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
//      {
    uwb_rx(0, 0, range_timeout_us);//开启接收
  //  while(mac_is_busy());
  //  temp_count2=phy_timer_count_get();
      start_receive_count=phy_timer_count_get();
   poll_timeout=US_TO_PHY_TIMER_COUNT(range_timeout_us);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
   end_receive_count=start_receive_count+poll_timeout;
   if(end_receive_count>=UINT32_MAX)
   {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
      {
         current_count=phy_timer_count_get();
         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)
            {
                    break;
            }
        }
    if(receive_flag==1)//成功接收
    {
        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包
        {   temp_count2=phy_timer_count_get();
        {   flag_recsuccess = 1;
                 temp_count2=phy_timer_count_get();
            frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序
            battary = rx_buf[BATTARY_IDX];
            rec_nearbase_num=rx_buf[FZ_NEARBASENUM_INDEX];  //标签传过来的他与基站交互的基站id数目
@@ -428,11 +441,18 @@
                Anchor_RecNearPoll(i);
            }
                  recev_error_num=0;
            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);
        }
        break;
            }
    } else {
        sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
         uwb_rx(0, 0, range_timeout_us);
    }
   }
      if(!flag_recsuccess)
      {
         sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-3));//测试
        LOG_INFO(TRACE_MODULE_APP,"测距失败,计数:%d\r\n",recev_error_num);
        if(recev_error_num++>5)
        {
@@ -441,8 +461,7 @@
            uwb_searchcount = 0;
            search_open_flag = 1;
        }
    }
         }
    gpio_pin_clr(SCL_PIN);
}