From bdad051416564607f0b31df44732e3ea97b7174a Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期日, 25 八月 2019 17:56:12 +0800 Subject: [PATCH] 华星火车项目测试完成 --- 源码/核心板/Src/application/dw_app.c | 131 +++++++++++++++++++++++-------------------- 1 files changed, 69 insertions(+), 62 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 2a1e753..643eb8b 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" @@ -69,9 +69,13 @@ #define TAG_ID_IDX 5 #define MESSAGE_TYPE_IDX 9 #define DIST_IDX 10 +//Poll #define ANC_TYPE_IDX 14 #define BATTARY_IDX 15 #define BUTTON_IDX 16 + +//respose +#define TIMECORRE 14 #define POLL 0x01 #define RESPONSE 0x02 @@ -98,7 +102,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[16] = {0}; +static uint8_t tx_resp_msg[18] = {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. */ @@ -125,7 +129,7 @@ static double tof; -uint32_t anchor_dist_last_frm[TAG_NUM_IN_SYS]; +uint32_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; @@ -136,7 +140,7 @@ float dis_after_filter; //当前距离值 LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 -uint16_t g_Tagdist[TOTAL_TAG_NUM]; +uint16_t g_Tagdist[TAG_NUM_IN_SYS]; uint8_t g_flag_Taggetdist[256]; /*------------------------------------ Functions ------------------------------------------*/ @@ -279,7 +283,7 @@ return sum; } -u16 tag_time_recv[TOTAL_TAG_NUM]; +u16 tag_time_recv[TAG_NUM_IN_SYS]; u8 usart_send[25]; u8 battary,button; extern uint8_t g_pairstart; @@ -293,6 +297,7 @@ u8 tag_succ_times=0; u32 hex_dist; u16 checksum; +int8_t tag_delaytime; void Tag_App(void)//发送模式(TAG标签) { uint32_t frame_len; @@ -308,7 +313,7 @@ tx_poll_msg[BATTARY_IDX] = Get_Battary(); tx_poll_msg[BUTTON_IDX] = !READ_KEY0; - for(i=0;i<REPOET_ANC_NUM;i++) + 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; @@ -354,6 +359,15 @@ poll_tx_ts = get_tx_timestamp_u64(); //获得POLL发送时间T1 resp_rx_ts = get_rx_timestamp_u64(); //获得RESPONSE接收时间T4 + if(i==0) + { + tag_delaytime=rx_buffer[TIMECORRE]; + if(tag_delaytime>g_com_map[COM_INTERVAL]/2) + { + tag_delaytime=tag_delaytime-g_com_map[COM_INTERVAL]; + } + } + memcpy(&anchor_dist_last_frm[0], &rx_buffer[DIST_IDX], 4); memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); /* Compute final message transmission time. See NOTE 9 below. */ @@ -375,25 +389,23 @@ result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 tag_succ_times++; - #ifdef WORK_MODE_TAG + LED0_BLINK; - #endif - #ifdef HEX_OUTPUT - usart_send[2] = frame_seq_nb++; - //usart_send[6] = tag_id_recv; - //usart_send[8] = g_com_map[DEV_ID]; - memcpy(&usart_send[3],&dev_id,4); - memcpy(&usart_send[7],&rx_buffer[ANCHOR_ID_IDX],4); - hex_dist = anchor_dist_last_frm[0]; - memcpy(&usart_send[11],&hex_dist,4); - usart_send[15] = battary; - usart_send[16] = button; - checksum = Checksum_u16(&usart_send[2],19); - memcpy(&usart_send[21],&checksum,2); - UART_PushFrame(usart_send,23); - #else - printf("Anchor ID: %d, Tag ID: %d, Dist = %d cm\n", g_com_map[DEV_ID_L]|g_com_map[DEV_ID_L]<<8, tag_id_recv, (uint16_t)dist_cm); - #endif + + + 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];; + memcpy(&usart_send[9],&hex_dist,4); + usart_send[13] = battary; + usart_send[14] = button; + checksum = Checksum_u16(&usart_send[2],17); + memcpy(&usart_send[19],&checksum,2); + UART_PushFrame(usart_send,21); + /* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */ if(result==0) {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成 @@ -420,16 +432,15 @@ // deca_sleep(10); } // dwt_entersleep(); - if(tag_succ_times<REPOET_ANC_NUM_MIN) + if(tag_succ_times<g_com_map[MIN_REPORT_ANC_NUM]) { - random_delay_tim =time32_incr&0x8f+7; - deca_sleep(random_delay_tim); + //poll_timer +=time32_incr&0x7+3; } - //LED0_BLINK; - RTC_SET_ALARM(1); + /* Execute a delay between ranging exchanges. */ } +int8_t correction_time; extern uint8_t g_start_send_flag; void Anchor_App(void) { @@ -445,8 +456,7 @@ /* Poll for reception of a frame or error/timeout. See NOTE 7 below. */ while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))&&!g_start_send_flag)//不断查询芯片状态直到接收成功或者出现错误 { - UART_CheckReceive(); - UART_CheckSend(); + IdleTask(); g_Resttimer=0; }; @@ -478,6 +488,13 @@ if (rx_buffer[MESSAGE_TYPE_IDX] == POLL&&(anchor_type == rx_buffer[ANC_TYPE_IDX])) //判断是否是poll包数据 { + correction_time=tag_timer-(tag_id_recv%GROUP_TAG_NUM)*3; + if(correction_time == g_com_map[COM_INTERVAL]) + correction_time = 0; + tx_resp_msg[TIMECORRE] = correction_time; +// if(correction_time>10) +// {correction_time++;} + /* Retrieve poll reception timestamp. */ poll_rx_ts = get_rx_timestamp_u64();//获得Poll包接收时间T2 @@ -490,7 +507,7 @@ dwt_setrxtimeout(FINAL_RX_TIMEOUT_UUS);//接收超时时间 /* Write and send the response message. See NOTE 9 below.*/ - if(tag_id_recv-TAG_ID_START<=TOTAL_TAG_NUM) + if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) memcpy(&tx_resp_msg[DIST_IDX], &anchor_dist_last_frm[tag_id_recv-TAG_ID_START], 4); dwt_writetxdata(sizeof(tx_resp_msg), tx_resp_msg, 0);//写入发送数据 @@ -559,38 +576,28 @@ LED0_BLINK; //每成功一次通讯则闪烁一次 g_UWB_com_interval = 0; dis_after_filter=dist_cm; - // g_Tagdist[tag_id_recv-TAG_ID_START]=dist_cm; -// if(g_pairstart==1&&dist_cm<20) -// { -// g_pairstart=0; -// g_com_map[PAIR_ID]=tag_id_recv; -// save_com_map_to_flash(); -// BEEP2_ON; -// delay_ms(1000); -// printf("Pair Finish PairID: %d. \r\n",g_com_map[PAIR_ID]); -// } - // tag_time_recv[tag_id_recv] = tag_recv_timer; - if(tag_id_recv-TAG_ID_START<=TOTAL_TAG_NUM) - { - g_flag_Taggetdist[tag_id_recv-TAG_ID_START]=0; - anchor_dist_last_frm[tag_id_recv-TAG_ID_START] = dist_cm; - } - #ifdef HEX_OUTPUT - usart_send[2] = frame_seq_nb++; - //usart_send[6] = tag_id_recv; - //usart_send[8] = g_com_map[DEV_ID]; - memcpy(&usart_send[3],&tag_id_recv,4); - memcpy(&usart_send[7],&dev_id,4); + hex_dist = (int16_t)(dist_cm+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) + { + g_Tagdist[tag_id_recv-TAG_ID_START] = hex_dist; + anchor_dist_last_frm[tag_id_recv-TAG_ID_START] = hex_dist; + } + his_dist[tag_id_recv-TAG_ID_START]=hex_dist; + + usart_send[2] = 1;//正常模式 + usart_send[3] = 17;//数据段长度 + usart_send[4] = frame_seq_nb++;//数据段长度 + memcpy(&usart_send[5],&tag_id_recv,2); + memcpy(&usart_send[7],&dev_id,2); hex_dist = dist_cm; - memcpy(&usart_send[11],&hex_dist,4); - usart_send[15] = battary; - usart_send[16] = button; - checksum = Checksum_u16(&usart_send[2],19); - memcpy(&usart_send[21],&checksum,2); - UART_PushFrame(usart_send,23); - #else - printf("Anchor ID: %d, Tag ID: %d, Dist = %d cm\n", g_com_map[DEV_ID_L]|g_com_map[DEV_ID_L]<<8, tag_id_recv, (uint16_t)dist_cm); - #endif + memcpy(&usart_send[9],&hex_dist,4); + usart_send[13] = battary; + usart_send[14] = button; + 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); -- Gitblit v1.9.3