From 61445f53207dce2dce3ae11450297aa33908b1e6 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期四, 21 十月 2021 11:51:03 +0800 Subject: [PATCH] 1 --- Src/application/dw_app.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c index e38a85a..f3d87f1 100644 --- a/Src/application/dw_app.c +++ b/Src/application/dw_app.c @@ -70,7 +70,7 @@ #define FINAL_MSG_TS_LEN 4 #define STARTPOLL REGPOLL//#define SWITCHBASE_DIST -//#define SWITCHBASE_ZHUANDIAN +#define SWITCHBASE_ZHUANDIAN #define SWITCHBASE_DIST enum enumtagstate { @@ -628,12 +628,17 @@ void GetNearMsg(void) { u32 start_poll,frame_len; - + u8 nearmsg_i=0; + for(nearmsg_i=0;nearmsg_i<20;nearmsg_i++) + { + nearbase_distlist[nearmsg_i] = 0x1ffff; + } //mainbase_id = 0x9724; memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); memcpy(&tx_near_msg[TAG_ID_IDX],&dev_id,2); tx_near_msg[MESSAGE_TYPE_IDX] = NEAR_MSG; + dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); dwt_writetxdata(12, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 @@ -670,7 +675,38 @@ // tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; } } +extern u32 synctimer; +u32 target_time=100; +u8 pd_i; +u32 temptime,delaytime; +u16 delaycount; +extern u16 slotpos_intoatl, slotpos; +void NextPollDelay(u32 anchor_time) +{ + for(pd_i=0;pd_i<=tag_frequency;pd_i++) + { + slotpos_intoatl = pd_i*bigslot_num+tagslotpos; + temptime = (slotpos_intoatl*SLOTTIME_MS+100)*100; + if(anchor_time<temptime-10000) + { + delaytime = temptime-anchor_time; + + return ; + } + } + temptime = (tagslotpos*SLOTTIME_MS+100+10000)*100; + delaytime = temptime-anchor_time; + return ; +} +u16 lpcount; +void SetLPTimer(u32 anchor_time) +{ + NextPollDelay(anchor_time); + current_count=HAL_LPTIM_ReadCounter(&hlptim1); + lpcount = current_count+delaytime/LPTIMER_LSB; + __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); +} void NearPoll(void) { @@ -818,7 +854,7 @@ {flag_getresponse=1;} lastsync_timer=sync_timer; offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; - SetNextPollTime(tagslotpos); + SetLPTimer(ancsync_time); if(result==0) {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成 { };} @@ -831,14 +867,14 @@ memcpy(&nearbase_switchdistlist[rec_nearbasepos],&rx_buffer[NR_NEARSWITCH_DISTANCE],2); nearbase_distlist[rec_nearbasepos+1]=temp_dist; // nearbase_distlist[1]对应 rec_nearbaseid[0]的距离 final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos)*4], resp_rx_ts); - if(temp_dist<salvebase_mindist) + if(temp_dist<salvebase_mindist&&nearbase_switchdistlist[rec_nearbasepos]==1) { salvebase_mindist = temp_dist; mindist_slavebaseid = rec_nearbaseid; } #ifdef SWITCHBASE_ZHUANDIAN - if(temp_dist<nearbase_switchdistlist[rec_nearbasepos]&&nearbase_switchdistlist[rec_nearbasepos]!=0&&temp_dist>0) - { + if(temp_dist<nearbase_switchdistlist[rec_nearbasepos]&&nearbase_switchdistlist[rec_nearbasepos]>1&&temp_dist>0) + { mainbase_id = rec_nearbaseid; tag_state = GETNEARMSG; } @@ -877,7 +913,7 @@ changemainbase_count = 0; } #endif - }else if(mainbase_lost_count>10*tag_frequency) + }else if(mainbase_lost_count>5*tag_frequency) { tag_state = STARTPOLL; } -- Gitblit v1.9.3