From 8a64dd03a6565f25a4920171fb18d41f49aa8d11 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期日, 05 七月 2020 23:46:50 +0800 Subject: [PATCH] 防撞9对5测试完成,发给华星 --- 源码/核心板/Src/application/dw_app.c | 74 +++++++++++++++++++++++++++--------- 1 files changed, 55 insertions(+), 19 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 acdbb09..e672903 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" @@ -208,17 +208,24 @@ u16 nearbaseid_list[MAX_NEARBASE_NUM],mainbase_id,true_nearbase_idlist[MAX_NEARBASE_NUM]; int32_t mainbase_dist,nearbase_distlist[MAX_NEARBASE_NUM],true_nearbase_distlist[MAX_NEARBASE_NUM],true_exsistbase_list[MAX_NEARBASE_NUM]; uint8_t trygetnearmsg_times; -u16 current_slotnum,total_slotnum,target_time; +u16 current_slotnum,total_slotnum,target_time,last_time; +u32 rec_tagpos_binary; +extern uint32_t tagpos_binary; void SetNextPollTime(u16 time) { - if(current_slotnum>=total_slotnum) + current_slotnum++; + if(current_slotnum==total_slotnum) current_slotnum-=total_slotnum; //time=5; target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time); - if(target_time>=990&&target_time<1000) + + last_time=target_time; + if(target_time>=990&&target_time<992) { current_slotnum++; target_time+=g_com_map[COM_INTERVAL]; + tagslotpos=GetRandomSlotPos(rec_tagpos_binary|tagpos_binary); + tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; } if(target_time>=1000) {target_time-=1000;} @@ -303,8 +310,7 @@ u8 anclost_times=0; u8 exsistbase_list[MAX_NEARBASE_NUM],report_num,get_newbase=0; u16 temp_sync_timer1,temp_sync_timer2; -u32 rec_tagpos_binary; -extern uint32_t tagpos_binary; + void NearPoll(void) { static u8 mainbase_lost_count=0,flag_finalsend,flag_rxon; @@ -341,7 +347,7 @@ flag_rxon=1; neartimout_timer=0; get_newbase=0; - timeout=ceil((float)nearbase_num/4)+2; + timeout=ceil((float)nearbase_num*0.4)+3; //timeout=5; mainbase_dist=100000; mainbase_lost_count++; @@ -396,7 +402,7 @@ temp_sync_timer2=sync_timer; memcpy(&temp_sync_timer1,&rx_buffer[ANCTIMEMS],2); memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); - exsistbase_list[0]=KEEP_TIMES; + if(g_com_map[DEV_ROLE]!=0) { @@ -414,15 +420,18 @@ } TIM3->CNT=tmp_time; } + current_slotnum=temp_sync_timer1/g_com_map[COM_INTERVAL]; // if(tagslotpos>max_slotpos) // tagslotpos=tagslotpos%(max_slotpos+1); // tyncpoll_time=(tagslotpos-1)*slottime; //////////////////////////// rec_nearbasepos=0; - exsistbase_list[rec_nearbasepos]=KEEP_TIMES; + memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); nearbase_distlist[rec_nearbasepos]=temp_dist; - + if(temp_dist!=0x1ffff) + exsistbase_list[rec_nearbasepos]=KEEP_TIMES; + mainbase_lost_count=0; flag_finalsend=1; final_tx_time = (resp_rx_ts + ((RESP_RX_TO_FINAL_TX_DLY_UUS+DELAY_BETWEEN_TWO_FRAME_UUS*nearbase_num+500) * UUS_TO_DWT_TIME)) >> 8; @@ -450,9 +459,11 @@ memcpy(&tx_nearfinal_msg[ANCHOR_ID_IDX],&rec_nearbaseid,2); } - exsistbase_list[rec_nearbasepos]=KEEP_TIMES; memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); nearbase_distlist[rec_nearbasepos]=temp_dist; + + if(temp_dist!=0x1ffff) + exsistbase_list[rec_nearbasepos]=KEEP_TIMES; final_msg_set_ts(&tx_nearfinal_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos)*4], resp_rx_ts); dwt_writetxdata(28+nearbase_num*4, tx_nearfinal_msg, 0);//将发送数据写入DW1000 @@ -510,7 +521,8 @@ // random_value=random_value|((temp_adc&0x01)<<i); // } tagslotpos=GetRandomSlotPos(rec_tagpos_binary|tagpos_binary); - tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; + tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; + tag_state=GETNEARMSG; } // tyncpoll_time=0; next_nearbase_num=0; @@ -555,7 +567,7 @@ { nearbaseid_list[i]=true_nearbase_idlist[i]; nearbase_distlist[i]=true_nearbase_distlist[i]; - if(nearbase_distlist[i]!=0x1ffff&&true_exsistbase_list[i]==0xa) + if(nearbase_distlist[i]!=0x1ffff&&true_exsistbase_list[i]==KEEP_TIMES) { memcpy(&usart_send[4+6*report_num],&nearbaseid_list[i],2); memcpy(&usart_send[6+6*report_num],&nearbase_distlist[i],4); @@ -633,9 +645,11 @@ tagslotpos=GetRandomSlotPos(rec_tagpos_binary); //tagslotpos=rx_buffer[TAGSLOTPOS]; memcpy(nearbaseid_list,&rx_buffer[NEARBASEID_INDEX],next_nearbase_num*2); - slottime=ceil((nearbase_num+2)*0.3)+1; + //slottime=ceil((nearbase_num+2)*0.4)+2; tyncpoll_time=tagslotpos*slottime; tag_state=NEARPOLL; + }else{ + tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; } }else{ tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; @@ -661,8 +675,9 @@ NearPoll(); break; } - current_slotnum++; + SetNextPollTime(tyncpoll_time); + g_start_send_flag = 0; GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_RESET); } @@ -773,6 +788,7 @@ u8 misdist_num[TAG_NUM_IN_SYS],seize_anchor; u8 Anchor_RecNearPoll(u8 ancrec_nearbasepos) //0 mainbase 1 first near_base { + u8 motorstate; tmp_time=TIM3->CNT; memcpy(&tx_nearresp_msg[ANCTIMEMS],&sync_timer,2); memcpy(&tx_nearresp_msg[ANCTIMEUS],&tmp_time,2); @@ -784,7 +800,20 @@ dwt_setdelayedtrxtime(resp_tx_time);//设置Response发送时间T3 dwt_setrxaftertxdelay(RESP_TX_TO_FINAL_RX_DLY_UUS+(rec_nearbase_num+1-ancrec_nearbasepos)*DELAY_BETWEEN_TWO_FRAME_UUS);//设置发送完成后开启接收延迟时间 dwt_setrxtimeout(FINAL_RX_TIMEOUT_UUS);//接收超时时间 - + + if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE1]) + { + motorstate =0; + }else if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE2]) + { + motorstate =2; + }else if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE3]) + { + motorstate =1; + }else{ + motorstate =0; + } + if(new_tagid) { tagdist_list[taglist_pos]=0x1ffff; @@ -794,9 +823,16 @@ } tx_nearresp_msg[MAINBASE_INDEX]=flag_syncbase; tx_nearresp_msg[MESSAGE_TYPE_IDX]=NEAR_RESPONSE; - - dwt_writetxdata(21, tx_nearresp_msg, 0);//写入发送数据 - dwt_writetxfctrl(21, 0);//设定发送长度 + tx_nearresp_msg[MOTORSTATE_INDEX]=(remotesend_state<<4)|motorstate; + if(remotesend_state) + { + memcpy(&tx_nearresp_msg[REMOTEPARA_INDEX],remotetag_para,REMOTEPARA_LEN); + dwt_writetxdata(22+REMOTEPARA_LEN, tx_nearresp_msg, 0);//写入发送数据 + dwt_writetxfctrl(22+REMOTEPARA_LEN, 0);//设定发送长度 + }else{ + dwt_writetxdata(22, tx_nearresp_msg, 0);//写入发送数据 + dwt_writetxfctrl(22, 0);//设定发送长度 + } result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//延迟发送,等待接收 battary = rx_buffer[BATTARY_IDX]; @@ -860,7 +896,7 @@ his_dist[taglist_pos]=hex_dist; g_Tagdist[taglist_pos]=hex_dist; #ifndef USART_INTEGRATE_OUTPUT - usart_send[2] = 1;//正常模式 + usart_send[2] = 1;//正常模式 usart_send[3] = 17;//数据段长度 usart_send[4] = frame_seq_nb;//数据段长度 memcpy(&usart_send[5],&tag_id_recv,2); -- Gitblit v1.9.3