| | |
| | | #define FINAL_MSG_FINAL_TX_TS_IDX 18 |
| | | #define FINAL_MSG_TS_LEN 4 |
| | | |
| | | |
| | | #define STARTPOLL DISCPOLL |
| | | enum enumtagstate |
| | | { |
| | | REGPOLL, |
| | | DISCPOLL, |
| | | GETNEARMSG, |
| | | NEARPOLL, |
| | | }tag_state=DISCPOLL; |
| | | }tag_state=STARTPOLL; |
| | | static dwt_config_t config = { |
| | | 2, /* Channel number. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | |
| | | tyncpoll_time=(tagslotpos-1)*slottime; |
| | | } |
| | | mainbase_id=minid; |
| | | //mainbase_id = 0x2; |
| | | //mainbase_id = 0x1; |
| | | } |
| | | u8 nearmsg_mainbase=0,rec_tagpos_emptylist[32],mainbase_type;; |
| | | void GetNearMsg(void) |
| | |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | } |
| | | } |
| | | extern u8 userkey_state; |
| | | uint8_t changemainbase_count=0,gotosleep_flag; |
| | | uint32_t frame_len; |
| | | void NearPoll(void) |
| | |
| | | HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET); |
| | | |
| | | recbase_num=0; |
| | | motor_state=0; |
| | | // motor_state=0; |
| | | |
| | | tx_near_msg[BATTARY_IDX] = bat_percent; |
| | | tx_near_msg[BUTTON_IDX] = !GET_USERKEY|stationary_flag<<1|gotosleep_flag<<2; |
| | | tx_near_msg[BUTTON_IDX] = userkey_state|stationary_flag<<1|gotosleep_flag<<2; |
| | | tx_near_msg[SEQUENCE_IDX] = frame_seq_nb++; |
| | | tx_near_msg[NEARBASENUM_INDEX] = nearbase_num; |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX],&nearbaseid_list,nearbase_num*2); |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = NEAR_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(21+2*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | dwt_writetxfctrl(21+2*nearbase_num, 0);//设置超宽带发送数据长度 |
| | |
| | | //时间同步 |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | last_slotnum=current_slotnum; |
| | | // current_slotnum=((float)sync_timer/(SLOTTIME_MS*bigslot_num))+1; |
| | | current_slotnum=((float)(sync_timer*10)/(SLOTTIME_MS*bigslot_num))+1; |
| | | if(current_slotnum==last_slotnum-1) |
| | | {flag_getresponse=1;} |
| | | lastsync_timer=sync_timer; |
| | | offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; |
| | | // SetNextPollTime(tagslotpos); |
| | | SetNextPollTime(tagslotpos); |
| | | |
| | | }else{ |
| | | |
| | |
| | | dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度 |
| | | dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 |
| | | result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | userkey_state = !GET_USERKEY; |
| | | if(result==0) |
| | | {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成 |
| | | { };} |
| | |
| | | } |
| | | }else{ |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | if(recbase_num!=nearbase_num) |
| | | if(recbase_num!=nearbase_num+1) |
| | | {dwt_rxenable(0); } |
| | | // if(flag_rxon) |
| | | // { |
| | |
| | | } |
| | | // dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | dwt_forcetrxoff(); |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | j=0; |
| | | if(exsistbase_list[0]==0) |
| | |
| | | {flag_getresponse=1;} |
| | | lastsync_timer=sync_timer; |
| | | offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; |
| | | SetNextPollTime(tagslotpos); |
| | | // SetNextPollTime(tagslotpos); |
| | | mainbase_id=rec_nearbaseid; |
| | | nearbase_num=rx_buffer[NEARBASENUM_INDEX]; |
| | | memcpy(nearbaseid_list,&rx_buffer[NEARBASEID_INDEX],nearbase_num*2); |