| | |
| | | } |
| | | u8 test=0; |
| | | u8 anclost_times=0; |
| | | u8 exsistbase_list[MAX_NEARBASE_NUM],report_num,get_newbase=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) |
| | | void NearPoll(void) |
| | | { |
| | | static u8 mainbase_lost_count=0,flag_finalsend,flag_rxon; |
| | | uint32_t temp1,temp2,dw_systime; |
| | |
| | | u32 start_poll; |
| | | u8 i,j,getsync_flag=0,timeout; |
| | | // printf("%d",sync_timer); |
| | | dwt_forcetrxoff(); |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置åéåå¼å¯æ¥æ¶ï¼å¹¶è®¾å®å»¶è¿æ¶é´ |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | tag_succ_times = 0; |
| | |
| | | temp_sync_timer2=sync_timer; |
| | | memcpy(&temp_sync_timer1,&rx_buffer[ANCTIMEMS],2); |
| | | memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); |
| | | sync_timer=temp_sync_timer1; |
| | | exsistbase_list[0]=KEEP_TIMES; |
| | | |
| | | if(g_com_map[DEV_ROLE]!=0) |
| | | { |
| | | sync_timer=temp_sync_timer1; |
| | | //// memcpy(&tagslotpos,&rx_buffer[TAGSLOTPOS],2); |
| | | // |
| | | tmp_time=tmp_time+650; |
| | | |
| | | tmp_time=tmp_time+650; |
| | | if(tmp_time>999) |
| | | { |
| | | tmp_time-=999; |
| | |
| | | {sync_timer=0;} |
| | | } |
| | | TIM3->CNT=tmp_time; |
| | | |
| | | } |
| | | // if(tagslotpos>max_slotpos) |
| | | // tagslotpos=tagslotpos%(max_slotpos+1); |
| | | // tyncpoll_time=(tagslotpos-1)*slottime; |
| | | //////////////////////////// |
| | | rec_nearbasepos=0; |
| | | exsistbase_list[rec_nearbasepos]=10; |
| | | exsistbase_list[rec_nearbasepos]=KEEP_TIMES; |
| | | memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); |
| | | nearbase_distlist[rec_nearbasepos]=temp_dist; |
| | | |
| | |
| | | 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); |
| | | |
| | | if(temp_dist!=0x1ffff) |
| | | { |
| | | #ifndef USART_INTEGRATE_OUTPUT |
| | | 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],&rec_nearbaseid,2); |
| | | memcpy(&usart_send[9],&rx_buffer[DIST_IDX],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); |
| | | #endif |
| | | } |
| | | //result=dwt_starttx(DWT_START_TX_DELAYED);//设å®ä¸ºå»¶è¿åé |
| | | |
| | | |
| | | }else{ |
| | | rec_nearbasepos=FindNearBasePos(rec_nearbaseid); |
| | | if(rec_nearbasepos>=last_nearbase_num) //åç°æ°çåºç« |
| | |
| | | // temp_adc=Get_ADC_Value(); |
| | | // random_value=random_value|((temp_adc&0x01)<<i); |
| | | // } |
| | | tyncpoll_time = (tagslotpos%max_slotpos)*slottime; |
| | | tagslotpos=GetRandomSlotPos(rec_tagpos_binary); |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | } |
| | | // tyncpoll_time=0; |
| | | next_nearbase_num=0; |
| | |
| | | } |
| | | |
| | | // printf("%d,%d",temp_sync_timer2,temp_sync_timer1); |
| | | #ifdef USART_INTEGRATE_OUTPUT |
| | | usart_send[2] = 4;//æ£å¸¸æ¨¡å¼ |
| | | usart_send[3] = report_num*6+2;//æ£å¸¸æ¨¡å¼ |
| | | checksum = Checksum_u16(&usart_send[2],report_num*6+2); |
| | | memcpy(&usart_send[4+report_num*6],&checksum,2); |
| | | UART_PushFrame(usart_send,6+report_num*6); |
| | | #endif |
| | | // #ifdef USART_INTEGRATE_OUTPUT |
| | | // usart_send[2] = 4;//æ£å¸¸æ¨¡å¼ |
| | | // usart_send[3] = report_num*6+2;//æ£å¸¸æ¨¡å¼ |
| | | // checksum = Checksum_u16(&usart_send[2],report_num*6+2); |
| | | // memcpy(&usart_send[4+report_num*6],&checksum,2); |
| | | // UART_PushFrame(usart_send,6+report_num*6); |
| | | // #endif |
| | | // if(mainbase_lost_count>5) |
| | | // { |
| | | // //tag_state=DISCPOLL; |
| | |
| | | // anclost_times=0; |
| | | // } |
| | | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | |
| | | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR| SYS_STATUS_TXFRS |SYS_STATUS_RXFCG); |
| | | } |
| | | u8 nearmsg_mainbase=0,rec_tagpos_emptylist[32]; |
| | | void GetNearMsg(void) |
| | |
| | | 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; |
| | | } |
| | | }else{ |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | } |
| | | } |
| | | |
| | | void Tag_App(void)//å鿍¡å¼(TAGæ ç¾) |
| | | { |
| | | //LED0_ON; |
| | | dwt_forcetrxoff(); |
| | | g_Resttimer=0; |
| | | switch(tag_state) |
| | | { |
| | |
| | | misdist_num[taglist_pos]=0; |
| | | tagdist_list[taglist_pos] = hex_dist; |
| | | his_dist[taglist_pos]=hex_dist; |
| | | g_Tagdist[taglist_pos]=hex_dist; |
| | | #ifndef USART_INTEGRATE_OUTPUT |
| | | usart_send[2] = 1;//æ£å¸¸æ¨¡å¼ |
| | | usart_send[3] = 17;//æ°æ®æ®µé¿åº¦ |