From 1ee47e9f40e3a7c1681d61a89a9367c80a561a0f Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期四, 04 三月 2021 10:35:31 +0800 Subject: [PATCH] V1.41 修改到ch3,preamble 改成64 --- 源码/核心板/Src/application/dw_app.c | 39 +++++++++++++++++++++++++++++++-------- 1 files changed, 31 insertions(+), 8 deletions(-) diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" index 52f2990..28fa6e4 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" @@ -28,7 +28,7 @@ #include <stdio.h> #include "beep.h" #include "modbus.h" - +//#define DEBUG_OUTPUT /*------------------------------------ Marcos ------------------------------------------*/ /* Inter-ranging delay period, in milliseconds. */ #define RNG_DELAY_MS 100 @@ -90,16 +90,16 @@ /*------------------------------------ Variables ------------------------------------------*/ /* Default communication configuration. We use here EVK1000's default mode (mode 3). */ static dwt_config_t config = { - 2, /* Channel number. */ + 3, /* Channel number. */ DWT_PRF_64M, /* Pulse repetition frequency. */ - DWT_PLEN_128, /* Preamble length. */ + DWT_PLEN_64, /* 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_6M8, /* Data rate. */ DWT_PHRMODE_STD, /* PHY header mode. */ - (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ + (65 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ }; /* Frames used in the ranging process. See NOTE 2 below. */ @@ -361,6 +361,9 @@ * set by dwt_setrxaftertxdelay() has elapsed. */ dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 start_poll = time32_incr; + #ifdef DEBUG_OUTPUT + printf("P包发送,基站ID: %d .\r\n",i); + #endif /* We assume that the transmission is achieved correctly, poll for reception of a frame or error/timeout. See NOTE 8 below. */ while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 { if(time32_incr - start_poll>20) @@ -439,16 +442,20 @@ dwt_writetxfctrl(sizeof(tx_final_msg), 0);//设定发送数据长度 result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 + #ifdef DEBUG_OUTPUT + printf("F包发送,基站ID: %d .\r\n",i); + #endif + tag_succ_times++; LED0_BLINK; - + g_Resttimer=0; memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2); if(hex_dist2!=0xffff) { g_Tagdist[anc_id_recv]= hex_dist2; g_flag_Taggetdist[anc_id_recv]=0; -// g_Resttimer=0; + if(!g_com_map[MODBUS_MODE]) { hex_dist2 = hex_dist2; @@ -488,6 +495,9 @@ } else { + #ifdef DEBUG_OUTPUT + printf("R包失败错误信息: %x .\r\n",status_reg); + #endif /* Clear RX error events in the DW1000 status register. */ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); random_delay_tim = DFT_RAND_DLY_TIM_MS; @@ -508,6 +518,7 @@ #define TDFILTER //#define CHECK_UID extern uint8_t UID_ERROR; +extern u16 dist_threshold; u8 misdist_num[TAG_NUM_IN_SYS]; void Anchor_App(void) { @@ -584,6 +595,9 @@ frame_seq_nb2 = rx_buffer[SEQUENCE_IDX]; /* We assume that the transmission is achieved correctly, now poll for reception of expected "final" frame or error/timeout. * See NOTE 7 below. */ + #ifdef DEBUG_OUTPUT + printf("收到POLL包,标签ID: %d .\r\n",tag_id_recv); + #endif if(result==0) { while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))///不断查询芯片状态直到接收成功或者出现错误 @@ -643,13 +657,16 @@ // dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定 /*--------------------------以下为非测距逻辑------------------------*/ + #ifdef DEBUG_OUTPUT + printf("收到FINAL包,标签ID: %d .\r\n",tag_id_recv); + #endif LED0_BLINK; //每成功一次通讯则闪烁一次 g_UWB_com_interval = 0; -// g_Resttimer=0; + g_Resttimer=0; hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]*10; if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) { - if(abs(hex_dist-his_dist[tag_id_recv-TAG_ID_START])<15000||misdist_num[tag_id_recv-TAG_ID_START]>4) + if(abs(hex_dist-his_dist[tag_id_recv-TAG_ID_START])<dist_threshold||misdist_num[tag_id_recv-TAG_ID_START]>4) { int32_t filter_dist; misdist_num[tag_id_recv-TAG_ID_START]=0; @@ -695,6 +712,9 @@ } }else{ /* Clear RX error events in the DW1000 status register. */ + #ifdef DEBUG_OUTPUT + printf("F包失败错误信息: %x .\r\n",status_reg); + #endif dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); } }else if(rx_buffer[MESSAGE_TYPE_IDX] == SYNC) @@ -710,6 +730,9 @@ } else { + #ifdef DEBUG_OUTPUT + printf("P包失败错误信息: %x .\r\n",status_reg); + #endif /* Clear RX error events in the DW1000 status register. */ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); } -- Gitblit v1.9.3