From 330bcfcfee023997495bf4e02ad0e8fe4308dfd9 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期四, 27 九月 2018 11:12:44 +0800 Subject: [PATCH] Revert "上海调试完成,可通讯,可设ID" --- 源码/核心板/Src/application/dw_app.c | 59 +++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 39 insertions(+), 20 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 6c4cdb1..bdd2e5a 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,6 +28,9 @@ #include "led.h" #include "serial_at_cmd_app.h" #include "Usart.h" +#include "global_param.h" +#include "filters.h" + /*------------------------------------ Marcos ------------------------------------------*/ @@ -67,8 +70,10 @@ #define FINAL_MSG_TS_LEN 4 #define GROUP_ID_IDX 0 -#define SOURCE_ID_IDX 1 -#define MESSAGE_TYPE_IDX 3 +#define ANCHOR_ID_IDX 1 +#define TAG_ID_IDX 3 +#define MESSAGE_TYPE_IDX 5 +#define DIST_IDX 6 #define POLL 0x01 #define RESPONSE 0x02 @@ -128,6 +133,10 @@ uint8_t random_delay_tim = 0; double distance, dist_no_bias, dist_cm; + +uint32_t g_UWB_com_interval = 0; +float dis_after_filter; //当前距离值 +LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 /*------------------------------------ Functions ------------------------------------------*/ @@ -234,23 +243,29 @@ dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); //设置接收超时时间 } -void Delayus(uint16_t time) +void Dw1000_App_Init(void) { - uint16_t i = 0; - while (time--) { - i = 10; - while (i--) - ; - - } + tx_poll_msg[MESSAGE_TYPE_IDX]=POLL; + tx_resp_msg[MESSAGE_TYPE_IDX]=RESPONSE; + tx_final_msg[MESSAGE_TYPE_IDX]=FINAL; + memcpy(&tx_poll_msg[TAG_ID_IDX], &g_com_map[DEV_ID], 2); + memcpy(&tx_final_msg[TAG_ID_IDX], &g_com_map[DEV_ID], 2); + memcpy(&tx_resp_msg[ANCHOR_ID_IDX], &g_com_map[DEV_ID], 2); + +} +void tag_sleep_configuraion(void) +{ + dwt_configuresleep(0x940, 0x7); + dwt_entersleep(); } + void Tag_App(void)//发送模式(TAG标签) { uint32_t frame_len; uint32_t final_tx_time; GPIO_ResetBits(SPIx_GPIO, SPIx_CS); - Delayus(2000); + delay_us(2000); GPIO_SetBits(SPIx_GPIO, SPIx_CS); /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */ @@ -283,14 +298,14 @@ /* Check that the frame is the expected response from the companion "DS TWR responder" example. * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */ rx_buffer[ALL_MSG_SN_IDX] = 0; - if (rx_buffer[9] == 0x10) //判断接收到的数据是否是response数据 + if (rx_buffer[MESSAGE_TYPE_IDX] == RESPONSE) //判断接收到的数据是否是response数据 { /* Retrieve poll transmission and response reception timestamp. */ poll_tx_ts = get_tx_timestamp_u64(); //获得POLL发送时间T1 resp_rx_ts = get_rx_timestamp_u64(); //获得RESPONSE接收时间T4 - - memcpy(&anchor_dist_last_frm[tag_id], &rx_buffer[11], 2); - + + memcpy(&anchor_dist_last_frm[tag_id], &rx_buffer[DIST_IDX], 2); + memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 2); /* Compute final message transmission time. See NOTE 9 below. */ final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8;//计算final包发送时间,T5=T4+Treply2 dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 @@ -371,11 +386,11 @@ rx_buffer[ALL_MSG_SN_IDX] = 0; //将收到的tag_id分别写入各次通讯的包中,为多标签通讯服务,防止一次通讯中接收到不同ID标签的数据 - tag_id_recv = rx_buffer[5]; - tx_resp_msg[5] = tag_id_recv; + tag_id_recv = rx_buffer[TAG_ID_IDX]; + tx_resp_msg[TAG_ID_IDX] = tag_id_recv; - if (rx_buffer[9] == 0x21) //判断是否是poll包数据 + if (rx_buffer[MESSAGE_TYPE_IDX] == POLL) //判断是否是poll包数据 { /* Retrieve poll reception timestamp. */ poll_rx_ts = get_rx_timestamp_u64();//获得Poll包接收时间T2 @@ -389,7 +404,7 @@ dwt_setrxtimeout(FINAL_RX_TIMEOUT_UUS);//接收超时时间 /* Write and send the response message. See NOTE 9 below.*/ - memcpy(&tx_resp_msg[11], &anchor_dist_last_frm[tag_id_recv], 2); + memcpy(&tx_resp_msg[DIST_IDX], &anchor_dist_last_frm[tag_id_recv], 2); tx_resp_msg[ALL_MSG_SN_IDX] = frame_seq_nb; dwt_writetxdata(sizeof(tx_resp_msg), tx_resp_msg, 0);//写入发送数据 dwt_writetxfctrl(sizeof(tx_resp_msg), 0);//设定发送长度 @@ -417,7 +432,7 @@ /* Check that the frame is a final message sent by "DS TWR initiator" example. * As the sequence number field of the frame is not used in this example, it can be zeroed to ease the validation of the frame. */ rx_buffer[ALL_MSG_SN_IDX] = 0; - if (rx_buffer[9] == 0x23) //判断是否为Final包 + if (rx_buffer[MESSAGE_TYPE_IDX] == FINAL&&rx_buffer[TAG_ID_IDX]==tag_id_recv&&rx_buffer[ANCHOR_ID_IDX]==g_com_map[DEV_ID]) //判断是否为Final包 { uint32_t poll_tx_ts, resp_rx_ts, final_tx_ts; uint32_t poll_rx_ts_32, resp_tx_ts_32, final_rx_ts_32; @@ -450,7 +465,11 @@ dist_cm = dist_no_bias * 100; //dis 为单位为cm的距离 // dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定 + /*--------------------------以下为非测距逻辑------------------------*/ LED0_BLINK; //每成功一次通讯则闪烁一次 + g_UWB_com_interval = 0; + dis_after_filter=dist_cm; + //dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); } } -- Gitblit v1.9.3