From ce9ff1ded137cb9915e4d8619b7bee5dc0e05138 Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期四, 25 四月 2024 15:21:50 +0800 Subject: [PATCH] V2.1 调试完成 1V4没有问题 --- Src/application/dw_app.c | 95 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 84 insertions(+), 11 deletions(-) diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c index ef8207f..f9c6e82 100644 --- a/Src/application/dw_app.c +++ b/Src/application/dw_app.c @@ -70,17 +70,36 @@ #define FINAL_MSG_RESP_RX_TS_IDX 14 #define FINAL_MSG_FINAL_TX_TS_IDX 18 #define FINAL_MSG_TS_LEN 4 -static dwt_config_t config = { + +//#define _UWB_4G + +//static dwt_config_t config = { +//#ifdef _UWB_4G +// 2, /* Channel number. */ +//#else +// 5, +//#endif +// DWT_PRF_64M, /* Pulse repetition frequency. */ +// DWT_PLEN_1024, /* Preamble length. */ +// DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ +// 9, /* TX preamble code. Used in TX only. */ +// 9, /* RX preamble code. Used in RX only. */ +// 1, /* Use non-standard SFD (Boolean) */ +// DWT_BR_110K, /* Data rate. */ +// DWT_PHRMODE_STD, /* PHY header mode. */ +// (1025 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ +//}; +dwt_config_t config = { 5, /* Channel number. */ DWT_PRF_64M, /* Pulse repetition frequency. */ - DWT_PLEN_64, /* Preamble length. */ - DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ + DWT_PLEN_1024, /* Preamble length. */ + DWT_PAC32, /* Preamble acquisition chunk size. Used in RX only. */ 9, /* TX preamble code. Used in TX only. */ 9, /* RX preamble code. Used in RX only. */ 1, /* Use non-standard SFD (Boolean) */ - DWT_BR_6M8, /* Data rate. */ + DWT_BR_110K, /* Data rate. */ DWT_PHRMODE_STD, /* PHY header mode. */ - (65 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ + (1025 + 64 - 32) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ }; static uint8_t tx_poll_msg[20] = {0}; static uint8_t tx_sync_msg[14] = {0}; @@ -156,7 +175,14 @@ *ts += ts_field[i] << (i * 8); } } - +void SetNLOSNTMSettings(void) +{ + uint8_t temp; + temp = 7; + dwt_writetodevice(LDE_IF_ID,LDE_CFG1_OFFSET,1,&temp); + dwt_write16bitoffsetreg(LDE_IF_ID,LDE_CFG2_OFFSET,3); + // NTM = dwt_read32bitoffsetreg(LDE_IF_ID,LDE_CFG1_OFFSET) & LDE_CFG1_NSTDEV_MASK; +} void Dw1000_Init(void) { /* Reset and initialise DW1000. @@ -169,7 +195,7 @@ /* Configure DW1000. See NOTE 6 below. */ dwt_configure(&config);//配置DW1000 - +// SetNLOSNTMSettings(); /* Apply default antenna delay value. See NOTE 1 below. */ @@ -338,7 +364,11 @@ { // exsistbase_list[i]--; - clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ; +#ifdef _UWB_4G + clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER_110KB * HERTZ_TO_PPM_MULTIPLIER_CHAN_2 / 1.0e6) ; +#else + clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER_110KB * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ; +#endif rtd_init = tag_resprx[i] - poll_tx_ts; rtd_resp = anc_resptx[i] - anc_pollrx[i]; tof = ((rtd_init - rtd_resp * (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS; @@ -346,10 +376,39 @@ if(distance>-10&&distance<1000) nearbase_distlist[i] = distance*100+anc_distoffset[i]; }else{ - // nearbase_distlist[i] = 0x1ffff; + nearbase_distlist[i] = 0x1ffff; } } +} +extern uint8_t module_power,imu_enable,motor_enable; +void Registor_Poll(void) +{ + static u8 regpoll_count=0; + u8 timeout; + + tx_near_msg[MESSAGE_TYPE_IDX] = MBX_REG; + tx_near_msg[REGP_TAGSTATE_INDEX] = !GET_USERKEY<<2|imu_enable<<1|motor_enable; + tx_near_msg[REGP_FREQUENCY_INDEX] = bat_percent; + 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[GROUP_ID],2); + memcpy(&tx_near_msg[REGP_NOMOVESLEEPTIME_INDEX],&g_com_map[DIST_OFFSET],2); + memcpy(&tx_near_msg[REGP_HEIGHTOFFSET_INDEX],&g_com_map[MAX_REPORT_ANC_NUM],2); + dwt_writetxdata(23, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 + dwt_writetxfctrl(23, 0);//设置超宽带发送数据长度 + dwt_starttx(DWT_START_TX_IMMEDIATE);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 + start_count=HAL_LPTIM_ReadCounter(&hlptim1); + timeout=50; + end_count=start_count+(timeout<<2); + while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_TXFRS)))//不断查询芯片状态直到成功接收或者发生错误 + { + current_count=HAL_LPTIM_ReadCounter(&hlptim1); + if(current_count>=end_count&¤t_count<end_count+15000) + break; + + }; + } float range_lost_time = 0; u16 rec_nearbaseid,rec_nearbasepos; @@ -395,7 +454,7 @@ flag_getresponse=0; start_count=HAL_LPTIM_ReadCounter(&hlptim1); recbase_num=0; - timeout=nearbase_num*SLOT_SCALE+10; + timeout=nearbase_num*SLOT_SCALE+500; end_count=start_count+(timeout<<2); if(end_count>=32768) {end_count-=32768;} @@ -640,7 +699,7 @@ } } } - +u8 regpoll_count; u32 id; void Tag_App(void)//发送模式(TAG标签) { @@ -659,6 +718,20 @@ } delay_us(100); g_Resttimer=0; + if(freqlost_count>FREQ_LOST_TIME) + { + if(regpoll_count++>11) //待机状态1分钟上传一次基站状态 + { + regpoll_count = 0; + Registor_Poll(); + } + }else{ + if(regpoll_count++>59)//测距状态1分钟上传一次基站状态 + { + regpoll_count = 0; + Registor_Poll(); + } + } NearPoll(); dwt_entersleep(); bat_percent=Get_VDDVlotage(); -- Gitblit v1.9.3