From 1ff43801a489ce8482dda3f7bf027082de33ccf2 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期一, 17 九月 2018 21:12:45 +0800 Subject: [PATCH] 增加多对多功能,尚未解决标签设ID问题(标签自动休眠,DMA无法收到串口数据) --- 源码/核心板/Src/application/global_param.c | 2 +- 源码/核心板/Src/main.c | 7 ++++--- 源码/核心板/Src/application/serial_at_cmd_app.c | 2 +- 源码/核心板/Src/application/dw_app.c | 39 ++++++++++++++++++++++++++------------- 4 files changed, 32 insertions(+), 18 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 84ee3d2..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" @@ -32,6 +32,7 @@ #include "filters.h" + /*------------------------------------ Marcos ------------------------------------------*/ /* Inter-ranging delay period, in milliseconds. */ #define RNG_DELAY_MS 100 @@ -69,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 @@ -240,7 +243,16 @@ dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); //设置接收超时时间 } - +void Dw1000_App_Init(void) +{ + 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); @@ -286,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 @@ -374,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 @@ -392,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);//设定发送长度 @@ -420,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; @@ -456,7 +468,8 @@ /*--------------------------以下为非测距逻辑------------------------*/ LED0_BLINK; //每成功一次通讯则闪烁一次 g_UWB_com_interval = 0; - dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); + dis_after_filter=dist_cm; + //dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); } } diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" index 30e9f55..e516ff6 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" @@ -25,7 +25,7 @@ if(g_com_map[0] != 0x55AA) { g_com_map[0] = 0x55AA; - g_com_map[ALARM_DISTANCE] = 200; //默认报警距离200cm + g_com_map[ALARM_DISTANCE] = 50; //默认报警距离200cm g_com_map[ALARM_DEV] = 0; g_com_map[DEV_ID] = DEFAULT_DEV_ID; //默认设备ID save_com_map_to_flash(); diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c" index e9f99cf..b3d7257 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c" @@ -8,7 +8,7 @@ void ParseFrame(void) { - if(!memcmp(m_frame_data, "SET", 3)) + if(!memcmp(m_frame_data, "DIS", 3)) { g_com_map[ALARM_DISTANCE] = (m_frame_data[3]-'0')*1000 + (m_frame_data[4]-'0')*100 + (m_frame_data[5]-'0')*10 + (m_frame_data[6]-'0'); printf("When distance < %d cm, alarm is on.\n", g_com_map[ALARM_DISTANCE]); diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" index ea6efee..673affa 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" @@ -10,8 +10,8 @@ #include "serial_at_cmd_app.h" #include "global_param.h" -//#define WORK_MODE_TAG -#define WORK_MODE_ANCHOR +#define WORK_MODE_TAG +//#define WORK_MODE_ANCHOR void Device_Init(void) { @@ -58,7 +58,7 @@ #ifdef WORK_MODE_TAG tag_sleep_configuraion(); #endif - + Dw1000_App_Init(); /* Loop forever initiating ranging exchanges. */ while(1) { @@ -68,6 +68,7 @@ g_start_send_flag = 0; Tag_App(); } +// UART_CheckReceive(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); #else -- Gitblit v1.9.3