| | |
| | | 9, /* RX preamble code. Used in RX only. */ |
| | | 1, /* Use non-standard SFD (Boolean) */ |
| | | DWT_BR_6M8, /* Data rate. */ |
| | | DWT_PHRMODE_STD, /* PHY header mode. */ |
| | | DWT_PHRMODE_EXT, /* PHY header mode. */ |
| | | (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | }; |
| | | static uint8_t tx_poll_msg[20] = {0}; |
| | |
| | | LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 |
| | | |
| | | |
| | | |
| | | void GetNearMsg(void); |
| | | static uint64_t get_tx_timestamp_u64(void) |
| | | { |
| | | uint8_t ts_tab[5]; |
| | |
| | | /* Apply default antenna delay value. See NOTE 1 below. */ |
| | | dwt_setrxantennadelay(RX_ANT_DLY); //设置接收天线延迟 |
| | | dwt_settxantennadelay(TX_ANT_DLY); //设置发射天线延迟 |
| | | |
| | | /* Set expected response's delay and timeout. See NOTE 4 and 5 below. |
| | | * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */ |
| | | //设置接收超时时间 |
| | |
| | | if(minddist!=0x1ffff&&minddist!=0) |
| | | { |
| | | trygetnearmsg_times = 0; |
| | | tag_state = GETNEARMSG; |
| | | tag_state = GETNEARMSG; |
| | | mainbase_id = mindist_ancid; |
| | | GetNearMsg(); |
| | | } |
| | | |
| | | if(getsync_flag==0) |
| | |
| | | |
| | | } |
| | | } |
| | | extern uint16_t tagid_list[TAG_NUM_IN_SYS]; |
| | | extern uint16_t taglist_num; |
| | | extern int32_t tagdist_list[TAG_NUM_IN_SYS]; |
| | | uint16_t nearbase_taglist_num; |
| | | extern uint8_t uwb_tx[300]; |
| | | void NearPoll(void) |
| | | { |
| | | |
| | |
| | | tx_near_msg[BUTTON_IDX] = userkey_state|stationary_flag<<1|gotosleep_flag<<2|motor_flag<<5; |
| | | tx_near_msg[SEQUENCE_IDX] = frame_seq_nb; |
| | | tx_near_msg[SEQUENCEH_IDX] = (frame_seq_nb++)>>8; |
| | | tx_near_msg[NEARBASENUM_INDEX] = nearbase_num; |
| | | if(taglist_num>10) |
| | | {taglist_num=10;} |
| | | nearbase_taglist_num=nearbase_num+taglist_num; |
| | | tx_near_msg[NEARBASENUM_INDEX] = nearbase_taglist_num; |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX],&nearbaseid_list,nearbase_num*2); |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*2],&nearbase_distlist,nearbase_num*4+4); |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*6+4],&rec_anc_signalpower,nearbase_num*2+2); |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*2],&tagid_list,taglist_num*2); |
| | | |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*2+taglist_num*2],&nearbase_distlist,nearbase_num*4+4); |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*2+taglist_num*2+nearbase_num*4+4],&tagdist_list,taglist_num*4); |
| | | |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_taglist_num*12+4],&rec_anc_signalpower,nearbase_taglist_num*2+2); |
| | | |
| | | |
| | | if(intheight!=0) |
| | | intheight+=g_com_map[HEIGHTOFFEST_INDEX]; |
| | | |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*8+6],&intheight,2); |
| | | // memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*8+6],&intheight,2); |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = POS_POLL; |
| | | |
| | | tx_near_msg[NEARP_TAGFREQ_INDEX] = tag_frequency; |
| | | tx_near_msg[NEARP_TAGSLOTPOS_INDEX] = tagslotpos; |
| | | |
| | | memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); |
| | | dwt_writetxdata(29+8*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | dwt_writetxfctrl(29+8*nearbase_num, 0);//设置超宽带发送数据长度 |
| | | dwt_writetxdata(29+8*nearbase_taglist_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | dwt_writetxfctrl(29+8*nearbase_taglist_num, 0);//设置超宽带发送数据长度 |
| | | |
| | | // dwt_writetxdata(280, uwb_tx, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | // dwt_writetxfctrl(282, 0);//设置超宽带发送数据长度 |
| | | |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | |
| | | while(current_count<poll_startcount||current_count>poll_startcount+16384) |
| | |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=ceil((float)nearbase_num*SLOT_SCALE)+3; |
| | | timeout=ceil((float)nearbase_taglist_num*SLOT_SCALE)+3; |
| | | end_count=start_count+(timeout<<5); |
| | | if(end_count>=32768) |
| | | {end_count-=32768;} |
| | |
| | | } |
| | | nearbase_distlist[rec_nearbasepos+1]=temp_dist; // nearbase_distlist[1]对应 rec_nearbaseid[0]的距离 |
| | | final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos)*4], resp_rx_ts); |
| | | if(temp_dist<salvebase_mindist&&nearbase_switchdistlist[rec_nearbasepos]!=0&&(nearbase_switchdistlist[rec_nearbasepos]==1||temp_dist<nearbase_switchdistlist[rec_nearbasepos])) |
| | | if(temp_dist<salvebase_mindist&&nearbase_switchdistlist[rec_nearbasepos]!=0&&(nearbase_switchdistlist[rec_nearbasepos]==1||temp_dist<nearbase_switchdistlist[rec_nearbasepos])) |
| | | { |
| | | salvebase_mindist = temp_dist; |
| | | mindist_slavebaseid = rec_nearbaseid; |
| | |
| | | changemainbase_count++; |
| | | if(changemainbase_count>2) |
| | | { |
| | | changemainbase_count = 0; |
| | | mainbase_id = mindist_slavebaseid; |
| | | tag_state = GETNEARMSG; |
| | | trygetnearmsg_times = 0; |
| | | changemainbase_count = 0; |
| | | mainbase_id = mindist_slavebaseid; |
| | | tag_state = GETNEARMSG; |
| | | trygetnearmsg_times = 0; |
| | | GetNearMsg(); |
| | | } |
| | | }else{ |
| | | changemainbase_count = 0; |
| | |
| | | { |
| | | mainbase_lost_count = 0; |
| | | tag_state = DISCPOLL; |
| | | DiscPoll(); |
| | | } |
| | | if(mainbase_lost_count!=0) |
| | | { |
| | |
| | | if(nearbaseid_list[i]!=nearbaseid_list2[i]) |
| | | { |
| | | tag_state = GETNEARMSG; |
| | | GetNearMsg(); |
| | | trygetnearmsg_times = 0; |
| | | nearbaseid_list0[i]=1; |
| | | } |
| | |
| | | } |
| | | } |
| | | u32 id,error_times=0; |
| | | |
| | | extern float Height; |
| | | void Tag_App(void)//发送模式(TAG标签) |
| | | { |
| | |
| | | } |
| | | userkey_state = !GET_USERKEY; |
| | | dwt_forcetrxoff(); |
| | | // Dw1000_Init(); |
| | | dwt_setinterrupt( DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 1); |
| | | dwt_setrxtimeout(0);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0); |