From 91c225bf44680a93147c33715bf16eb5adfb0818 Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期三, 25 十二月 2024 18:20:04 +0800 Subject: [PATCH] 目前成功的是基站端原代码rx写法帧间隔500,延时550,标签那边帧间隔500 基站default为600,成功一对多低功耗测试版本 --- keil/uwb_tag_.c | 44 +++++++++++++++++++++++++++++--------------- 1 files changed, 29 insertions(+), 15 deletions(-) diff --git a/keil/uwb_tag_.c b/keil/uwb_tag_.c index e6cf3dd..7a0a6ff 100644 --- a/keil/uwb_tag_.c +++ b/keil/uwb_tag_.c @@ -14,10 +14,10 @@ extern int TagRange(void); void Tag_uwb_init(void); /* Ranging period: 1s */ -#define RANGING_PERIOD_MS (1000) +#define RANGING_PERIOD_MS (10000) /* This is the delay from the end of the poll frame transmission to the enable of the receiver */ -#define POLL_TX_TO_RESP_RX_DLY_US 300U //yuan700 +#define POLL_TX_TO_RESP_RX_DLY_US 550U //yuan700 #define RESP_RX_TO_FINAL_TX_DLY_US 550U @@ -25,15 +25,15 @@ #define POLL_DELAY 100U //yuan100U /* Receive response timeout */ -#define RESP_RX_TIMEOUT_US 1200U //Yuan500 10mssuccess 300jixian - +#define RESP_RX_TIMEOUT_US_DEFAULT 600U //Yuan500 10mssuccess 300jixian +#define RESP_RX_TIMEOUT_US 2000000 /* Field index in frame */ #define MSG_SEQ_NUM_IDX 2 #define FINAL_MSG_POLL_TX_TS_IDX 10 #define FINAL_MSG_RESP_RX_TS_IDX 14 #define FINAL_MSG_FINAL_TX_TS_IDX 18 #define DELAY_DEFAULT 50000 -#define DELAY_BETWEEN_TWO_FRAME_UUS 600 //yuan1400 +#define DELAY_BETWEEN_TWO_FRAME_UUS 450 //yuan1400 #define HALF_SECOND_TIME 62400000 uint16_t CmpTagInList(uint16_t tagid); @@ -245,13 +245,14 @@ return rx_timestamp; } - +uint32_t temp_rx_first_stamp,temp_rx_second_stamp; +uint16_t temp_rx_first_id,temp_rx_second_id; /* RX done process handler. */ static void rx_int_callback(struct MAC_HW_REPORT_T *rx_report) { // Power off radio power_off_radio(); - + //tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US); rx_state = rx_report->err_code; /** UWB RX success */ @@ -262,6 +263,14 @@ memcpy(rx_buf, rx_report->pkt_data, rx_length); /* Calculate rx timestamp */ resp_rx_ts_i64 = ranging_rx_time_correct(rx_report); + if(temp_rx_first_stamp==0) + { + temp_rx_first_stamp=(uint32_t)resp_rx_ts_i64; + memcpy(&temp_rx_first_id,&rx_buf[1],2); + }else{ + memcpy(&temp_rx_second_id,&rx_buf[1],2); + temp_rx_second_stamp=(uint32_t)resp_rx_ts_i64; + } temp_count1=phy_timer_count_get(); //获取发射端时钟偏差 resp_rx_num++; @@ -288,7 +297,7 @@ temp_count2=phy_timer_count_get(); } - + //tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 } /* TX done process handler. */ @@ -380,7 +389,7 @@ uint32_t temp_dist,temp_id,temp_exsis; temp_dist=true_nearbase_distlist[j]; temp_id = true_nearbase_idlist[j]; - temp_exsis=true_exsistbase_list[j]; + temp_exsis=true_exsistbase_list[i]; true_nearbase_distlist[j]=true_nearbase_distlist[j+1]; true_nearbase_idlist[j]=true_nearbase_idlist[j+1]; true_exsistbase_list[j]=true_exsistbase_list[j+1]; @@ -415,6 +424,7 @@ } uint32_t count_index; int tt=1; +float freqlost_count; void Tag_uwb_init(void) { // The following peripherals will be initialized in the uwb_open function @@ -427,6 +437,7 @@ // Set calibration parameters uwb_calibration_params_set(config.phy_cfg.ch_num); #ifdef STS_MODE + // set advanced parameters struct PHY_ADV_CONFIG_T adv_config = { .thres_fap_detect = 40, @@ -480,12 +491,12 @@ resp_rx_en_start_u32 = poll_tx_en_start_u32+ US_TO_PHY_TIMER_COUNT(POLL_TX_TO_RESP_RX_DLY_US);//设置发送多少s后接收按target独立时间起点算+ US_TO_PHY_TIMER_COUNT(POLL_TX_TO_RESP_RX_DLY_US为发送后要多久开启接收时间 temp_resp=resp_rx_en_start_u32; //tempflag=uwb_rx(1, resp_rx_en_start_u32, RESP_RX_TIMEOUT_US);//开启接受并设置接收超时 - tempflag=uwb_rx(0,resp_rx_en_start_u32, RESP_RX_TIMEOUT_US); + tempflag=uwb_rx(1,resp_rx_en_start_u32, RESP_RX_TIMEOUT_US); start_receive_count=phy_timer_count_get(); //poll_timeout=nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS)+US_TO_PHY_TIMER_COUNT(RESP_RX_TIMEOUT_US);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss - poll_timeout=US_TO_PHY_TIMER_COUNT(RESP_RX_TIMEOUT_US); + poll_timeout=US_TO_PHY_TIMER_COUNT(RESP_RX_TIMEOUT_US_DEFAULT)+nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS); end_receive_count=start_receive_count+poll_timeout; if(end_receive_count>=UINT32_MAX) @@ -507,16 +518,18 @@ break; } } + temp_count3=phy_timer_count_get(); if(receive_flag==1)//成功接收数据 { receive_flag=0; - tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 + //tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 //接收成功则判断是否为同一组 if (rx_buf[MESSAGE_TYPE_IDX] == MBX_RESPONSE&&!memcmp(&rx_buf[TAG_ID_IDX],&dev_id,2)&&rx_buf[GROUP_ID_IDX]==group_id) //判断接收到的数据是否是response数据 { memcpy(&rec_nearbaseid,&rx_buf[ANCHOR_ID_IDX],2); rec_nearbasepos=FindNearBasePos(rec_nearbaseid); + freqlost_count = 0; SetANCTimestap(rec_nearbasepos,&rx_buf[RESP_MSG_POLL_RX_TS_IDX],&rx_buf[RESP_MSG_RESP_TX_TS_IDX],(uint32_t)resp_rx_ts_i64,&rx_buf[RESP_MSG_ANC_DISTOFFSET],test2,(uint32_t)poll_tx_ts_i64); if(rec_nearbasepos>=nearbase_num) //发现新的基站 { @@ -528,7 +541,7 @@ memset(rx_buf, 0, sizeof(rx_buf));//清空接收到的用完的数组 rx_length=0;//清0长度 -// uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 + uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 // while(mac_is_busy()); //break;//成功接收就退出 } @@ -538,9 +551,10 @@ // #endif }else if(receive_flag==2){//接收出错 receive_flag=0; + tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 // sleep_timer_start(__MS_TO_32K_CNT(SLEEP_COUNT-phy_timer_count_get()%30));//测试 // sleep_time_step=SLEEP_COUNT-phy_timer_count_get()%10; - tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 + //tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 temp_count3=phy_timer_count_get(); // while(mac_is_busy()); temp_count1=phy_timer_count_get(); @@ -559,6 +573,6 @@ //dwt_forecetrxoff(); CalculateDists(poll_tx_ts_i64); //计算距离并更新距离表 AnchorListUpdate();//更新存活基站列表 - // Rank_ANchor_list_by_dis();//冒泡排序重新按距离重新排列基站列表最小距离存货基站放到最前面 + Rank_ANchor_list_by_dis();//冒泡排序重新按距离重新排列基站列表最小距离存货基站放到最前面 } #endif \ No newline at end of file -- Gitblit v1.9.3