From 5739481744a7d26671190f6f327726e23843dd6d Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期一, 02 十一月 2020 15:34:13 +0800 Subject: [PATCH] Merge branch '定位-临近' into 定位临近_工卡 --- Src/application/dw_app.c | 72 +++++++++++++++++++++-------------- 1 files changed, 43 insertions(+), 29 deletions(-) diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c index 3e5b5dc..c1e0ea2 100644 --- a/Src/application/dw_app.c +++ b/Src/application/dw_app.c @@ -50,7 +50,7 @@ #define RESP_RX_TO_FINAL_TX_DLY_UUS 510 /* Receive response timeout. See NOTE 5 below. */ -#define RESP_RX_TIMEOUT_UUS 0 +#define RESP_RX_TIMEOUT_UUS 1000 #define DELAY_BETWEEN_TWO_FRAME_UUS 240 @@ -72,6 +72,7 @@ enum enumtagstate { + REGPOLL, DISCPOLL, GETNEARMSG, NEARPOLL, @@ -465,7 +466,7 @@ extern u16 bigslot_num; u8 nearbase_num=0,last_nearbase_num,next_nearbase_num,last_slotnum, para_update,para_len,stationary_flag=0; u32 rec_tagpos_binary; -int16_t offset=4700; +int16_t offset=4700,temptimer; u8 motor_state,rec_remotepara_state,rec_remotepara[80]; void Poll(void) { @@ -537,12 +538,15 @@ ancsync_time=((sync_timer)*1000+tmp_time); last_slotnum=current_slotnum; - current_slotnum=((float)sync_timer/(SLOTTIME_MS*bigslot_num))+1; + temptimer = sync_timer-10; + if(temptimer<0) + {temptimer+=1000;} + current_slotnum=((float)temptimer/(SLOTTIME_MS*bigslot_num))+1; if(current_slotnum==last_slotnum-1) {flag_getresponse=1;} lastsync_timer=sync_timer; offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; - SetNextPollTime(tyncpoll_time); + SetNextPollTime(tagslotpos); if(temp_dist<mindist&&temp_dist!=0) { @@ -657,8 +661,8 @@ memcpy(&tx_near_msg[NEARBASEID_INDEX],&nearbaseid_list,nearbase_num*2); tx_near_msg[MESSAGE_TYPE_IDX] = NEAR_POLL; memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); - dwt_writetxdata(13+2*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 - dwt_writetxfctrl(13+2*nearbase_num, 0);//设置超宽带发送数据长度 + dwt_writetxdata(21+2*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 + dwt_writetxfctrl(21+2*nearbase_num, 0);//设置超宽带发送数据长度 dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 tx_near_msg[TAGCONFIGSUCCESS_INDEX] =0; @@ -747,12 +751,12 @@ //时间同步 ancsync_time=((sync_timer)*1000+tmp_time); last_slotnum=current_slotnum; - current_slotnum=((float)sync_timer/(SLOTTIME_MS*bigslot_num))+1; + // current_slotnum=((float)sync_timer/(SLOTTIME_MS*bigslot_num))+1; if(current_slotnum==last_slotnum-1) {flag_getresponse=1;} lastsync_timer=sync_timer; offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; - SetNextPollTime(tyncpoll_time); +// SetNextPollTime(tagslotpos); }else{ @@ -797,16 +801,7 @@ j=0; if(exsistbase_list[0]==0) { -// u8 temp_adc,random_value; -// random_value=0; -// for(i=0;i<8;i++) -// { -// temp_adc=Get_ADC_Value(); -// random_value=random_value|((temp_adc&0x01)<<i); -// } -// tagslotpos=GetRandomSlotPos(rec_tagpos_binary); -// tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; - SetNextPollTime(tyncpoll_time); +// SetNextPollTime(tagslotpos); } // tyncpoll_time=0; next_nearbase_num=0; @@ -905,21 +900,32 @@ HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET); } -extern uint8_t module_power; -uint16_t tag_slotpos; +extern uint8_t module_power,imu_enable,motor_enable; + void Registor_Poll(void) { + static u8 regpoll_count=0; + tag_frequency = REGISTER_FREQUENCY; + bigslot_num = TOTAL_SLOTNUM/tag_frequency; + regpoll_count++; + if(regpoll_count%2) + { + if(tagslotpos--<2) + tagslotpos=TOTAL_SLOTNUM; + } + SetNextPollTime(tagslotpos); dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); + tx_near_msg[REGP_TAGSTATE_INDEX] = !GET_USERKEY<<2|imu_enable<<1|motor_enable; tx_near_msg[MESSAGE_TYPE_IDX] = REG_POLL; - tx_near_msg[REGP_FREQUENCY_INDEX] = tag_frequency; + tx_near_msg[REGP_FREQUENCY_INDEX] = 1000/g_com_map[COM_INTERVAL]; tx_near_msg[REGP_POWER_INDEX] = module_power; memcpy(&tx_near_msg[REGP_VERSION_INDEX],&g_com_map[VERSION],2); memcpy(&tx_near_msg[REGP_IMUTHRES_INDEX],&g_com_map[IMU_THRES],2); memcpy(&tx_near_msg[REGP_NOMOVESLEEPTIME_INDEX],&g_com_map[NOMOVESLEEP_TIME],2); - dwt_writetxdata(13+2*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 - dwt_writetxfctrl(13+2*nearbase_num, 0);//设置超宽带发送数据长度 + dwt_writetxdata(21, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 + dwt_writetxfctrl(21, 0);//设置超宽带发送数据长度 dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 { @@ -941,7 +947,7 @@ memcpy(&rec_nearbaseid,&rx_buffer[ANCHOR_ID_IDX],2); tag_frequency = rx_buffer[REGR_TAGFREQ_INDEX]; bigslot_num = TOTAL_SLOTNUM/tag_frequency; - tag_slotpos = rx_buffer[REGR_TAGSLOTPOS_INDEX]; + tagslotpos = rx_buffer[REGR_TAGSLOTPOS_INDEX]; //////////////////////////////////时间同步 memcpy(&sync_timer,&rx_buffer[ANCTIMEMS],2); memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); @@ -955,17 +961,21 @@ if(sync_timer>=1010) {sync_timer=0;} } - ancsync_time=((sync_timer)*1000+tmp_time); + ancsync_time=((sync_timer)*1000+tmp_time); last_slotnum=current_slotnum; - current_slotnum=((float)sync_timer/(SLOTTIME_MS*bigslot_num))+1; + temptimer = sync_timer-10; + if(temptimer<0) + {temptimer+=1000;} + current_slotnum=((float)temptimer/(SLOTTIME_MS*bigslot_num))+1; if(current_slotnum==last_slotnum-1) {flag_getresponse=1;} lastsync_timer=sync_timer; offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; - SetNextPollTime(tyncpoll_time); - + SetNextPollTime(tagslotpos); + mainbase_id=rec_nearbaseid; nearbase_num=rx_buffer[NEARBASENUM_INDEX]; memcpy(nearbaseid_list,&rx_buffer[NEARBASEID_INDEX],nearbase_num*2); + tag_state = NEARPOLL; } } } @@ -981,9 +991,13 @@ } switch(tag_state) { + case REGPOLL: + LED_LG_ON; + Registor_Poll(); + LED_LG_OFF; + break; case DISCPOLL: LED_LG_ON; - //Registor_Poll(); Poll(); LED_LG_OFF; break; -- Gitblit v1.9.3