| | |
| | | uint32_t g_UWB_com_interval = 0; |
| | | float dis_after_filter; //当前距离值 |
| | | LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 |
| | | |
| | | float range_lost_time = 0; |
| | | |
| | | |
| | | static uint64_t get_tx_timestamp_u64(void) |
| | |
| | | /* Apply default antenna delay value. See NOTE 1 below. */ |
| | | dwt_setrxantennadelay(RX_ANT_DLY); //设置接收天线延迟 |
| | | dwt_settxantennadelay(TX_ANT_DLY); //设置发射天线延迟 |
| | | // dwt_configcontinuousframemode(12480); |
| | | // dwt_writetxdata(13, usart_send, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | // dwt_writetxfctrl(13, 0);//设置超宽带发送数据长度 |
| | | // dwt_starttx(DWT_START_TX_IMMEDIATE);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 |
| | | |
| | | //while(1) |
| | | //{} |
| | | /* 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. */ |
| | | //设置接收超时时间 |
| | |
| | | #else |
| | | clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ; |
| | | #endif |
| | | rtd_init = tag_resprx[i] - poll_tx_ts; |
| | | rtd_init = tag_resprx[i] - poll_tx_ts&0xffffffff; |
| | | rtd_resp = anc_resptx[i] - anc_pollrx[i]; |
| | | tof = ((rtd_init - rtd_resp * (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS; |
| | | distance = tof * SPEED_OF_LIGHT; |
| | | if(distance>-10&&distance<1000) |
| | | nearbase_distlist[i] = distance*100+anc_distoffset[i]; |
| | | range_lost_time=0; |
| | | }else{ |
| | | // nearbase_distlist[i] = 0x1ffff; |
| | | } |
| | |
| | | }; |
| | | |
| | | } |
| | | float range_lost_time = 0; |
| | | u16 numceshi; |
| | | u16 rec_nearbaseid,rec_nearbasepos; |
| | | extern u16 poll_startcount; |
| | | 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,flag_ancreadpara=0; |
| | | u32 start_poll,timeout; |
| | | u8 i,j,getsync_flag=0,flag_ancreadpara=0; |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 |
| | | dwt_setrxtimeout(0); |
| | | tag_succ_times = 0; |
| | |
| | | memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); |
| | | dwt_writetxdata(13+4*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | dwt_writetxfctrl(13+4*nearbase_num, 0);//设置超宽带发送数据长度 |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while(current_count<poll_startcount||current_count>poll_startcount+16384) |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count<poll_startcount-300) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 |
| | | |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); |
| | | numceshi++; |
| | | tx_near_msg[TAGCONFIGSUCCESS_INDEX] =0; |
| | | para_update = 0; |
| | | get_newbase = 0; |
| | |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=nearbase_num*SLOT_SCALE+50; |
| | | timeout=nearbase_num*SLOT_SCALE+100; //单位0.1ms |
| | | end_count=start_count+(timeout<<2); |
| | | if(end_count>=32768) |
| | | {end_count-=32768;} |
| | |
| | | mainbase_lost_count++; |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while(current_count<end_count||current_count>end_count+15000) |
| | | // while(1) |
| | | // while(1) |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 |
| | | { |
| | | if(flag_finalsend&&flag_ancreadpara) |
| | | { |
| | | dw_systime=dwt_readsystimestamphi32(); |
| | | if(dw_systime>temp1&&dw_systime<temp2) |
| | | { |
| | | |
| | | dwt_forcetrxoff(); |
| | | flag_rxon=0; |
| | | if(flag_ancreadpara) //只有在读取参数的时候需要回复 |
| | | { |
| | | u16 calCRC; |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = MBX_PRAAREPLY; |
| | | memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX],g_com_map,SENDANCPARA_LEN); |
| | | calCRC = CRC_Compute((uint8_t*)g_com_map,SENDANCPARA_LEN); |
| | | memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX+SENDANCPARA_LEN],&calCRC,2); |
| | | dwt_writetxdata(14+SENDANCPARA_LEN, tx_near_msg, 0);//将发送数据写入DW1000 |
| | | dwt_writetxfctrl(14+SENDANCPARA_LEN, 0);//设定发送数据长度 |
| | | |
| | | dwt_setdelayedtrxtime(final_tx_time); |
| | | result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | } |
| | | flag_finalsend=0; |
| | | break; |
| | | } |
| | | } |
| | | // if(flag_finalsend&&flag_ancreadpara) |
| | | // { |
| | | // dw_systime=dwt_readsystimestamphi32(); |
| | | // if(dw_systime>temp1&&dw_systime<temp2) |
| | | // { |
| | | // |
| | | // dwt_forcetrxoff(); |
| | | // flag_rxon=0; |
| | | // if(flag_ancreadpara) //只有在读取参数的时候需要回复 |
| | | // { |
| | | // u16 calCRC; |
| | | // tx_near_msg[MESSAGE_TYPE_IDX] = MBX_PRAAREPLY; |
| | | // memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX],g_com_map,SENDANCPARA_LEN); |
| | | // calCRC = CRC_Compute((uint8_t*)g_com_map,SENDANCPARA_LEN); |
| | | // memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX+SENDANCPARA_LEN],&calCRC,2); |
| | | // dwt_writetxdata(14+SENDANCPARA_LEN, tx_near_msg, 0);//将发送数据写入DW1000 |
| | | // dwt_writetxfctrl(14+SENDANCPARA_LEN, 0);//设定发送数据长度 |
| | | // |
| | | // dwt_setdelayedtrxtime(final_tx_time); |
| | | // result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | // } |
| | | // flag_finalsend=0; |
| | | // break; |
| | | // } |
| | | // } |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count>=end_count&¤t_count<end_count+15000) |
| | | break; |
| | |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK; //获得接收到的数据长度 |
| | | dwt_readrxdata(rx_buffer, frame_len, 0); //读取接收数据 |
| | | test2 = dwt_readcarrierintegrator(); |
| | | poll_tx_ts = get_tx_timestamp_u64(); //获得POLL发送时间T1 |
| | | resp_rx_ts = get_rx_timestamp_u64(); |
| | | dwt_setrxtimeout(0);//DELAY_BETWEEN_TWO_FRAME_UUS*(nearbase_num+1-recbase_num)+10);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == MBX_RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,2)&&rx_buffer[GROUP_ID_IDX]==group_id) //判断接收到的数据是否是response数据 |
| | | { |
| | | poll_tx_ts = get_tx_timestamp_u64(); //获得POLL发送时间T1 |
| | | resp_rx_ts = get_rx_timestamp_u64(); //获得RESPONSE接收时间T4 |
| | | // poll_tx_ts = get_tx_timestamp_u64(); //获得POLL发送时间T1 |
| | | // resp_rx_ts = get_rx_timestamp_u64(); //获得RESPONSE接收时间T4 |
| | | recbase_num++; |
| | | memcpy(&rec_nearbaseid,&rx_buffer[ANCHOR_ID_IDX],2); |
| | | rec_remotepara_state = rx_buffer[MOTORSTATE_INDEX]>>4; |
| | | TagFreqProcess(rx_buffer[TAGFREQ_IDX]); |
| | | // TagFreqProcess(rx_buffer[TAGFREQ_IDX]); |
| | | // if(rec_nearbaseid==0x9002) |
| | | // {rec_remotepara_state = rx_buffer[MOTORSTATE_INDEX]>>4;} |
| | | if(rec_remotepara_state != 0) |
| | | { |
| | | para_update = rec_remotepara_state; |
| | |
| | | } |
| | | } |
| | | nearbase_num = next_nearbase_num; |
| | | if(mainbase_lost_count>1&&exsistbase_list[0] != 0) |
| | | if(mainbase_lost_count>1)//&&exsistbase_list[0] != 0) |
| | | { |
| | | last_lpcount+= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16); |
| | | last_lpcount-= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16); |
| | | } |
| | | last_nearbase_num = next_nearbase_num; |
| | | for(i=0;i<last_nearbase_num-1;i++) |
| | |
| | | } |
| | | delay_us(100); |
| | | g_Resttimer=0; |
| | | if(freqlost_count>FREQ_LOST_TIME) |
| | | { |
| | | if(regpoll_count++>11) //待机状态1分钟上传一次基站状态 |
| | | { |
| | | regpoll_count = 0; |
| | | Registor_Poll(); |
| | | } |
| | | }else{ |
| | | if(regpoll_count++>59)//测距状态1分钟上传一次基站状态 |
| | | { |
| | | regpoll_count = 0; |
| | | Registor_Poll(); |
| | | } |
| | | } |
| | | // if(freqlost_count>FREQ_LOST_TIME) |
| | | // { |
| | | // if(regpoll_count++>11) //待机状态1分钟上传一次基站状态 |
| | | // { |
| | | // regpoll_count = 0; |
| | | // Registor_Poll(); |
| | | // } |
| | | // }else{ |
| | | // if(regpoll_count++>59)//测距状态1分钟上传一次基站状态 |
| | | // { |
| | | // regpoll_count = 0; |
| | | // Registor_Poll(); |
| | | // } |
| | | // } |
| | | NearPoll(); |
| | | dwt_entersleep(); |
| | | bat_percent=Get_VDDVlotage(); |