From 503efc0a0d2ea34213ec87aea5bf63c52c2eb93a Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期二, 12 十一月 2019 19:29:18 +0800 Subject: [PATCH] 实现标签时间隙动态更新 --- 源码/核心板/Src/application/dw_app.c | 91 ++++++++++++++++++++++++++++++++------------- 1 files changed, 65 insertions(+), 26 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 83dcf89..82c7da6 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" @@ -79,6 +79,7 @@ //respose #define ANCTIMEMS 14 #define ANCTIMEUS 16 +#define TAGSLOTPOS 18 #define POLL 0x01 #define RESPONSE 0x02 @@ -107,7 +108,7 @@ static uint8_t tx_final_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //static uint8_t rx_poll_msg[] = {0x00, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x21, 0, 0}; -static uint8_t tx_resp_msg[20] = {0}; +static uint8_t tx_resp_msg[22] = {0}; //static uint8_t rx_final_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* Frame sequence number, incremented after each transmission. */ @@ -134,7 +135,7 @@ static double tof; -uint32_t anchor_dist_last_frm[TAG_NUM_IN_SYS],his_dist[TAG_NUM_IN_SYS]; ; +int32_t anchor_dist_last_frm[TAG_NUM_IN_SYS],his_dist[TAG_NUM_IN_SYS]; ; uint32_t tag_id = 0; uint32_t tag_id_recv = 0; uint8_t random_delay_tim = 0; @@ -318,6 +319,8 @@ int8_t tag_delaytime; extern uint16_t sync_timer; u16 tmp_time; +int32_t temp_dist; +u16 tagslotpos; void Tag_App(void)//发送模式(TAG标签) { uint32_t frame_len; @@ -337,7 +340,7 @@ for(i=0;i<g_com_map[MAX_REPORT_ANC_NUM];i++) { /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */ - tx_poll_msg[ANC_TYPE_IDX] = i-1; + tx_poll_msg[ANC_TYPE_IDX] = i; dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 dwt_writetxfctrl(sizeof(tx_poll_msg), 0);//设置超宽带发送数据长度 @@ -385,6 +388,7 @@ getsync_flag=1; memcpy(&sync_timer,&rx_buffer[ANCTIMEMS],2); memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); + memcpy(&tagslotpos,&rx_buffer[TAGSLOTPOS],2); tmp_time=tmp_time+450; if(tmp_time>999) { @@ -394,6 +398,9 @@ {sync_timer=0;} } TIM3->CNT=tmp_time; + if(tagslotpos>max_slotpos) + tagslotpos=tagslotpos%(max_slotpos+1); + tyncpoll_time=(tagslotpos-1)*slottime; } memcpy(&anchor_dist_last_frm[0], &rx_buffer[DIST_IDX], 4); memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); @@ -418,14 +425,21 @@ tag_succ_times++; LED0_BLINK; - +// temp_dist=anchor_dist_last_frm[0]; +// if(anchor_dist_last_frm[0]>1000000) +// { +// temp_dist=anchor_dist_last_frm[0]-0xffffffff; +// temp_dist+=0xffff; +// anchor_dist_last_frm[0]=temp_dist; +// } + usart_send[2] = 1;//正常模式 usart_send[3] = 17;//数据段长度 usart_send[4] = frame_seq_nb;//数据段长度 memcpy(&usart_send[5],&dev_id,2); memcpy(&usart_send[7],&rx_buffer[ANCHOR_ID_IDX],2); - hex_dist = anchor_dist_last_frm[0];; + hex_dist = anchor_dist_last_frm[0]+(int16_t)g_com_map[DIST_OFFSET]; memcpy(&usart_send[9],&hex_dist,4); usart_send[13] = battary; usart_send[14] = button; @@ -456,19 +470,47 @@ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); random_delay_tim = DFT_RAND_DLY_TIM_MS; } -// deca_sleep(10); } -// dwt_entersleep(); - if(tag_succ_times<g_com_map[MIN_REPORT_ANC_NUM]) - { - //poll_timer +=time32_incr&0x7+3; - } - /* Execute a delay between ranging exchanges. */ +if(getsync_flag==0) +{ +tagslotpos--; + if(tagslotpos==0||tagslotpos>max_slotpos) + { + tagslotpos=max_slotpos; + } + tyncpoll_time=(tagslotpos-1)*slottime; +} } + int8_t correction_time; extern uint8_t sync_seq; +u16 taglist_num=0,taglist_pos; +u16 tagid_list[TAG_NUM_IN_SYS]; +u8 tagofflinetime[TAG_NUM_IN_SYS]; +void TagListUpdate(void) +{ + u16 i,j=0,temp[TAG_NUM_IN_SYS]; + for(i=0;i<taglist_num;i++) + { + if(tagofflinetime[i]++<QUIT_SLOT_TIME) + { + tagid_list[j]=tagid_list[i]; + tagofflinetime[j++]=tagofflinetime[i]; + } + } + taglist_num=j; +} +u16 CmpTagInList(u16 tagid) +{u16 i; + for(i=0;i<taglist_num;i++) + { + if(memcmp(&tagid,&tagid_list[i],2)==0) + return i+1; + } + return 0; +} void Anchor_App(void) { @@ -507,19 +549,19 @@ //tag_id_recv = rx_buffer[TAG_ID_IDX]; memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],4); memcpy(&tx_resp_msg[TAG_ID_IDX],&tag_id_recv,4); - //tx_resp_msg[TAG_ID_IDX] = tag_id_recv; -// if(tag_recv_timer>tag_time_recv[tag_id_recv-TAG_ID_START]) -// { tag_recv_interval = tag_recv_timer - tag_time_recv[tag_id_recv]; -// }else{ -// tag_recv_interval = tag_recv_timer + 65535 - tag_time_recv[tag_id_recv]; -// } - + taglist_pos=CmpTagInList(tag_id_recv); + if(taglist_pos==0) + { + tagid_list[taglist_num++]=tag_id_recv; + taglist_pos=taglist_num; + } + tagofflinetime[taglist_pos-1]=0; if (rx_buffer[MESSAGE_TYPE_IDX] == POLL&&(anchor_type == rx_buffer[ANC_TYPE_IDX])) //判断是否是poll包数据 { tmp_time=TIM3->CNT; memcpy(&tx_resp_msg[ANCTIMEMS],&sync_timer,2); memcpy(&tx_resp_msg[ANCTIMEUS],&tmp_time,2); - + memcpy(&tx_resp_msg[TAGSLOTPOS],&taglist_pos,2); // if(correction_time>10) // {correction_time++;} @@ -602,10 +644,11 @@ // dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定 /*--------------------------以下为非测距逻辑------------------------*/ + //dist_cm=33000; + LED0_BLINK; //每成功一次通讯则闪烁一次 - g_UWB_com_interval = 0; dis_after_filter=dist_cm; - hex_dist = (int16_t)(dist_cm+g_com_map[DIST_OFFSET]); + hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]; if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) if(abs(hex_dist-his_dist[tag_id_recv-TAG_ID_START])<1000) { @@ -626,10 +669,6 @@ checksum = Checksum_u16(&usart_send[2],17); memcpy(&usart_send[19],&checksum,2); UART_PushFrame(usart_send,21); - - - //dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); - } }else{ /* Clear RX error events in the DW1000 status register. */ -- Gitblit v1.9.3