From 66596268c0f602ecc7ccbb34ea2b649108179eea Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期一, 08 六月 2020 08:50:29 +0800 Subject: [PATCH] V1.15 --- 源码/核心板/Src/application/dw_app.c | 90 ++++++++++++++++++++++++++------------------- 1 files changed, 52 insertions(+), 38 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 1b499a2..c3f95e8 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" @@ -251,10 +251,31 @@ // change_base_count=0; // } //} +u8 GetRandomSlotPos(uint32_t emptyslot) +{ + u8 i; + for(i=dev_id%32;i<max_slotpos;i++) + { + if(((emptyslot>>i)&0x1)==0) + { + return i; + } + } + + for(i=1;i<max_slotpos;i++) + { + if(((emptyslot>>i)&0x1)==0) + { + return i; + } + } +return max_slotpos-1; +} u8 test=0; 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; void NearPoll(void) { static u8 mainbase_lost_count=0,flag_finalsend,flag_rxon; @@ -383,6 +404,9 @@ tx_nearfinal_msg[MESSAGE_TYPE_IDX]=NEAR_FINAL; dwt_writetxdata(28+nearbase_num*4, tx_nearfinal_msg, 0);//将发送数据写入DW1000 dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度 + memcpy(&rec_tagpos_binary,&rx_buffer[NEARMSG_EMPTYSLOTPOS_INDEX],4); + tagslotpos=GetRandomSlotPos(rec_tagpos_binary); + if(temp_dist!=0x1ffff) { #ifndef USART_INTEGRATE_OUTPUT @@ -460,22 +484,21 @@ j=0; if(exsistbase_list[0]==0) { - u8 temp_adc,random_value; - random_value=0; - for(i=0;i<8;i++) - { - temp_adc=Get_ADC_Value(); - random_value=random_value|((temp_adc&0x01)<<i); - } - tyncpoll_time=(random_value%max_slotpos)*slottime; +// u8 temp_adc,random_value; +// random_value=0; +// for(i=0;i<8;i++) +// { +// temp_adc=Get_ADC_Value(); +// random_value=random_value|((temp_adc&0x01)<<i); +// } + tyncpoll_time = (tagslotpos%max_slotpos)*slottime; } // tyncpoll_time=0; next_nearbase_num=0; for(i=0;i<last_nearbase_num+get_newbase;i++) { if(exsistbase_list[i]>0) - { - + { next_nearbase_num++; true_exsistbase_list[j]=exsistbase_list[i]; true_nearbase_idlist[j]=nearbaseid_list[i]; @@ -553,8 +576,7 @@ } -u8 nearmsg_mainbase=0; -u32 rec_tagpos_binary; +u8 nearmsg_mainbase=0,rec_tagpos_emptylist[32]; void GetNearMsg(void) { u32 start_poll,frame_len; @@ -591,9 +613,9 @@ { next_nearbase_num=rx_buffer[NEARBASENUM_INDEX]; memcpy(&rec_tagpos_binary,&rx_buffer[NEARMSG_EMPTYSLOTPOS_INDEX],4); - tagslotpos=rx_buffer[TAGSLOTPOS]; + 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; tyncpoll_time=tagslotpos*slottime; tag_state=NEARPOLL; } @@ -610,13 +632,11 @@ break; case GETNEARMSG: - GetNearMsg(); + GetNearMsg(); break; case NEARPOLL: NearPoll(); break; - - } } @@ -836,12 +856,10 @@ } } } - }else{ //printf("%x/n",status_reg); dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); } - } uint32_t current_syncid=0xffffffff,synclost_timer; extern u8 flag_syncbase; @@ -871,16 +889,16 @@ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);//清除标志位 frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;//获得接收数据长度 dwt_readrxdata(rx_buffer, frame_len, 0);//读取接收数据 + memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2); //将收到的tag_id分别写入各次通讯的包中,为多标签通讯服务,防止一次通讯中接收到不同ID标签的数据 - //tag_id_recv = rx_buffer[TAG_ID_IDX]; + tag_id_recv = rx_buffer[TAG_ID_IDX]; switch(rx_buffer[MESSAGE_TYPE_IDX]) { // case POLL: // if (anchor_type == rx_buffer[ANC_TYPE_IDX]) // Anchor_RecPoll(); // break; - case SYNC: - + case SYNC: memcpy(&rec_syncid,&rx_buffer[ANCHOR_ID_IDX],4); if(rec_syncid<current_syncid) { @@ -921,10 +939,8 @@ } break; - case NEAR_POLL: - + case NEAR_POLL: memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],2); - memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2); taglist_pos=CmpTagInList(tag_id_recv); if(taglist_pos==taglist_num) { @@ -936,10 +952,16 @@ new_tagid=0; } tagofflinetime[taglist_pos]=0; - temp_tagpos=round((float)(sync_timer%g_com_map[COM_INTERVAL])/slottime); + temp_tagpos=round((float)(sync_timer%g_com_map[COM_INTERVAL])/slottime); tagpos_rec[(u8)temp_tagpos]=1; rec_nearbase_num=rx_buffer[NEARBASENUM_INDEX]; + if(rec_nearbase_num>ancidlist_num) + { + ancidlist_num=rec_nearbase_num; + memcpy(ancidlist_rec,&rx_buffer[NEARBASEID_INDEX],rec_nearbase_num*2); + } + for(i=0;i<rec_nearbase_num;i++) { memcpy(&tempid,&rx_buffer[NEARBASEID_INDEX+i*2],2); @@ -955,19 +977,11 @@ seize_anchor=1; //抢占anchor Anchor_RecNearPoll(i); } - if(rec_nearbase_num>ancidlist_num) - { - ancidlist_num=rec_nearbase_num; - memcpy(ancidlist_rec,&rx_buffer[NEARBASEID_INDEX],rec_nearbase_num*2); - } + - break; - - } - - } - else - { + break; + } + }else{ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); } } -- Gitblit v1.9.3