| | |
| | | u8 exsistbase_list[MAX_NEARBASE_NUM],report_num,get_newbase=0; |
| | | u8 flag_finalsend,flag_getresponse,flag_rxon; |
| | | uint16_t current_count,start_count,end_count,lastsync_timer; |
| | | |
| | | extern u16 bigslot_num; |
| | | u8 nearbase_num=0,last_nearbase_num,next_nearbase_num,last_slotnum, para_update,para_len,stationary_flag=0; |
| | | u32 rec_tagpos_binary; |
| | | int16_t offset=2700; |
| | | int16_t offset=4700; |
| | | u8 motor_state,rec_remotepara_state,rec_remotepara[80]; |
| | | void Poll(void) |
| | | { |
| | |
| | | tag_succ_times++; |
| | | LED0_BLINK; |
| | | |
| | | tagslotpos=GetRandomSlotPos(rec_tagpos_binary); |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | SetNextPollTime(tyncpoll_time); |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | last_slotnum=current_slotnum; |
| | | current_slotnum=((float)sync_timer/(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(tyncpoll_time); |
| | | |
| | | if(temp_dist<mindist&&temp_dist!=0) |
| | | { |
| | |
| | | tyncpoll_time=(tagslotpos-1)*slottime; |
| | | } |
| | | mainbase_id=minid; |
| | | //mainbase_id = 2; |
| | | //mainbase_id = 0x2; |
| | | } |
| | | u8 nearmsg_mainbase=0,rec_tagpos_emptylist[32],mainbase_type;; |
| | | void GetNearMsg(void) |
| | |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | } |
| | | } |
| | | uint8_t changemainbase_count=0; |
| | | uint8_t changemainbase_count=0,gotosleep_flag; |
| | | uint32_t frame_len; |
| | | void NearPoll(void) |
| | | { |
| | | |
| | | uint32_t temp1,temp2,dw_systime; |
| | | uint32_t frame_len; |
| | | |
| | | uint32_t final_tx_time; |
| | | u32 start_poll; |
| | | u8 i,j,getsync_flag=0,timeout; |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | tag_succ_times = 0; |
| | | //GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_SET); |
| | | |
| | | if(next_nearbase_num>=MAX_NEARBASE_NUM) |
| | | { |
| | | next_nearbase_num = MAX_NEARBASE_NUM-1; |
| | |
| | | motor_state=0; |
| | | |
| | | tx_near_msg[BATTARY_IDX] = bat_percent; |
| | | tx_near_msg[BUTTON_IDX] = !GET_USERKEY|stationary_flag<<1; |
| | | tx_near_msg[BUTTON_IDX] = !GET_USERKEY|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); |
| | |
| | | //时间同步 |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | last_slotnum=current_slotnum; |
| | | current_slotnum=((float)sync_timer/g_com_map[COM_INTERVAL])+1; |
| | | current_slotnum=((float)sync_timer/(SLOTTIME_MS*bigslot_num))+1; |
| | | if(current_slotnum==last_slotnum-1) |
| | | {flag_getresponse=1;} |
| | | lastsync_timer=sync_timer; |
| | |
| | | HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET); |
| | | |
| | | } |
| | | extern uint8_t module_power; |
| | | uint16_t tag_slotpos; |
| | | void Registor_Poll(void) |
| | | { |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = REG_POLL; |
| | | tx_near_msg[REGP_FREQUENCY_INDEX] = tag_frequency; |
| | | tx_near_msg[REGP_POWER_INDEX] = module_power; |
| | | memcpy(&tx_near_msg[REGP_VERSION_INDEX],&g_com_map[VERSION],2); |
| | | memcpy(&tx_near_msg[REGP_IMUTHRES_INDEX],&g_com_map[IMU_THRES],2); |
| | | memcpy(&tx_near_msg[REGP_NOMOVESLEEPTIME_INDEX],&g_com_map[NOMOVESLEEP_TIME],2); |
| | | dwt_writetxdata(13+2*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | dwt_writetxfctrl(13+2*nearbase_num, 0);//设置超宽带发送数据长度 |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 |
| | | { |
| | | IdleTask(); |
| | | |
| | | }; |
| | | if(status_reg==0xffffffff) |
| | | { |
| | | NVIC_SystemReset(); |
| | | } |
| | | if (status_reg & SYS_STATUS_RXFCG)//如果成功接收 |
| | | { |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//清楚寄存器标志位 |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK; //获得接收到的数据长度 |
| | | dwt_readrxdata(rx_buffer, frame_len, 0); //读取接收数据 |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == REG_RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,2)) //判断接收到的数据是否是response数据 |
| | | { u16 rec_nearbaseid,rec_nearbasepos; |
| | | |
| | | memcpy(&rec_nearbaseid,&rx_buffer[ANCHOR_ID_IDX],2); |
| | | tag_frequency = rx_buffer[REGR_TAGFREQ_INDEX]; |
| | | bigslot_num = TOTAL_SLOTNUM/tag_frequency; |
| | | tag_slotpos = rx_buffer[REGR_TAGSLOTPOS_INDEX]; |
| | | //////////////////////////////////时间同步 |
| | | memcpy(&sync_timer,&rx_buffer[ANCTIMEMS],2); |
| | | memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // memcpy(&tagslotpos,&rx_buffer[TAGSLOTPOS],2); |
| | | tmp_time=tmp_time+450; |
| | | if(tmp_time>999) |
| | | { |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1010) |
| | | {sync_timer=0;} |
| | | } |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | last_slotnum=current_slotnum; |
| | | current_slotnum=((float)sync_timer/(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(tyncpoll_time); |
| | | |
| | | nearbase_num=rx_buffer[NEARBASENUM_INDEX]; |
| | | memcpy(nearbaseid_list,&rx_buffer[NEARBASEID_INDEX],nearbase_num*2); |
| | | } |
| | | } |
| | | } |
| | | u32 id; |
| | | void Tag_App(void)//发送模式(TAG标签) |
| | | { |
| | |
| | | switch(tag_state) |
| | | { |
| | | case DISCPOLL: |
| | | LED_LG_ON; |
| | | LED_LG_ON; |
| | | //Registor_Poll(); |
| | | Poll(); |
| | | LED_LG_OFF; |
| | | break; |