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 | 71 +++++++++++++++++++++++++---------- 1 files changed, 50 insertions(+), 21 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 58345cd..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. */ @@ -319,6 +320,7 @@ extern uint16_t sync_timer; u16 tmp_time; int32_t temp_dist; +u16 tagslotpos; void Tag_App(void)//发送模式(TAG标签) { uint32_t frame_len; @@ -386,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) { @@ -395,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); @@ -464,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) { @@ -515,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++;} @@ -613,7 +647,6 @@ //dist_cm=33000; LED0_BLINK; //每成功一次通讯则闪烁一次 - g_UWB_com_interval = 0; dis_after_filter=dist_cm; hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]; if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) @@ -636,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