| | |
| | | static dwt_config_t config = { |
| | | 5, /* Channel number. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | DWT_PLEN_64, /* Preamble length. */ |
| | | DWT_PLEN_128, /* Preamble length. */ |
| | | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ |
| | | 9, /* TX preamble code. Used in TX only. */ |
| | | 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. */ |
| | | (65 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | }; |
| | | static uint8_t tx_poll_msg[20] = {0}; |
| | | static uint8_t tx_sync_msg[14] = {0}; |
| | |
| | | } |
| | | void CalculateDists(void) |
| | | { |
| | | for(int i=0;i<11;i++) |
| | | for(int i=0;i<MAX_NEARBASE_NUM;i++) |
| | | { |
| | | //rec_anc_signalpower[i] = exsistbase_list[i]; |
| | | if(exsistbase_list[i]>0) |
| | | if(exsistbase_list[i]==KEEP_TIMES) |
| | | { |
| | | |
| | | // exsistbase_list[i]--; |
| | |
| | | if(distance>-10&&distance<1000) |
| | | nearbase_distlist[i] = distance*100+anc_distoffset[i]; |
| | | }else{ |
| | | nearbase_distlist[i] = 0x1ffff; |
| | | // nearbase_distlist[i] = 0x1ffff; |
| | | } |
| | | |
| | | } |
| | |
| | | u32 start_poll; |
| | | u8 i,j,getsync_flag=0,timeout,flag_ancreadpara=0; |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 |
| | | dwt_setrxtimeout(10000); |
| | | dwt_setrxtimeout(0); |
| | | tag_succ_times = 0; |
| | | //GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_SET); |
| | | if(next_nearbase_num>=MAX_NEARBASE_NUM) |
| | | if(nearbase_num>=MAX_NEARBASE_NUM) |
| | | { |
| | | next_nearbase_num = MAX_NEARBASE_NUM-1; |
| | | nearbase_num = MAX_NEARBASE_NUM-1; |
| | | } |
| | | HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET); |
| | | last_nearbase_num=next_nearbase_num; |
| | | nearbase_num=next_nearbase_num; |
| | | // HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET); |
| | | // last_nearbase_num=next_nearbase_num; |
| | | // nearbase_num=next_nearbase_num; |
| | | recbase_num=0; |
| | | // motor_state=0; |
| | | for(uint8_t i=0;i<nearbase_num;i++) |
| | |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=nearbase_num*SLOT_SCALE+4; |
| | | end_count=start_count+(timeout<<5); |
| | | timeout=nearbase_num*SLOT_SCALE+10; |
| | | end_count=start_count+(timeout<<2); |
| | | if(end_count>=32768) |
| | | {end_count-=32768;} |
| | | mainbase_dist=100000; |
| | |
| | | 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) |
| | | if(flag_finalsend&&flag_ancreadpara) |
| | | { |
| | | dw_systime=dwt_readsystimestamphi32(); |
| | | if(dw_systime>temp1&&dw_systime<temp2) |
| | |
| | | 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);//设定为延迟发送 |
| | | } |
| | | // dwt_setdelayedtrxtime(final_tx_time); |
| | | // result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | flag_finalsend=0; |
| | | break; |
| | | } |
| | |
| | | //////////////////////////// |
| | | rec_nearbasepos=0; |
| | | exsistbase_list[rec_nearbasepos]=KEEP_TIMES; |
| | | memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); |
| | | nearbase_distlist[rec_nearbasepos]=temp_dist; |
| | | |
| | | if((rx_buffer[MOTORSTATE_INDEX]&0xf)!=3) |
| | | motor_state=rx_buffer[MOTORSTATE_INDEX]&0xf; |
| | | |
| | |
| | | |
| | | |
| | | //时间同步 |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | last_slotnum=current_slotnum; |
| | | current_slotnum=((float)sync_timer/g_com_map[COM_INTERVAL])+1; |
| | | if(current_slotnum==last_slotnum-1) |
| | | {flag_getresponse=1;} |
| | | lastsync_timer=sync_timer; |
| | | offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; |
| | | // ancsync_time=((sync_timer)*1000+tmp_time); |
| | | // last_slotnum=current_slotnum; |
| | | // current_slotnum=((float)sync_timer/g_com_map[COM_INTERVAL])+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(rec_remotepara_state==1) |
| | | // { |
| | |
| | | rec_nearbasepos=FindNearBasePos(rec_nearbaseid); |
| | | SetANCTimestap(rec_nearbasepos,&rx_buffer[RESP_MSG_POLL_RX_TS_IDX],&rx_buffer[RESP_MSG_RESP_TX_TS_IDX],resp_rx_ts,&rx_buffer[RESP_MSG_ANC_DISTOFFSET]); |
| | | |
| | | if(rec_nearbasepos>=last_nearbase_num) //发现新的基站 |
| | | if(rec_nearbasepos>=last_nearbase_num) //发现新的基站 |
| | | { |
| | | get_newbase=1; |
| | | nearbase_num++; |
| | |
| | | } |
| | | |
| | | exsistbase_list[rec_nearbasepos]=KEEP_TIMES; |
| | | memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); |
| | | nearbase_distlist[rec_nearbasepos]=temp_dist; |
| | | |
| | | |
| | | if(motor_state<(rx_buffer[MOTORSTATE_INDEX]&0xf)&&(rx_buffer[MOTORSTATE_INDEX]&0xf)!=3) |
| | | { |
| | |
| | | } |
| | | // dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | if(mainbase_lost_count>tag_frequency*BASELOST_STOPMOTOR_TIME) |
| | | {motor_state=0; } |
| | | dwt_forcetrxoff(); |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | nearbase_num=recbase_num; |
| | | // tyncpoll_time=0; |
| | | next_nearbase_num=0; |
| | | CalculateDists(); |
| | | j = 0; |
| | | for(i=0;i<last_nearbase_num+get_newbase;i++) |
| | | next_nearbase_num = 0; |
| | | for(i=0;i<nearbase_num;i++) |
| | | { |
| | | if(exsistbase_list[i]>0) |
| | | { |
| | | { |
| | | exsistbase_list[i]--; |
| | | next_nearbase_num++; |
| | | true_exsistbase_list[j]=exsistbase_list[i]; |
| | | true_nearbase_idlist[j]=nearbaseid_list[i]; |
| | | true_nearbase_distlist[j++]=nearbase_distlist[i]; |
| | | exsistbase_list[i]--; |
| | | |
| | | } |
| | | } |
| | | nearbase_num = next_nearbase_num; |
| | | if(mainbase_lost_count>1&&exsistbase_list[0] != 0) |
| | | { |
| | | last_lpcount+= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16); |
| | |
| | | { |
| | | nearbaseid_list[i]=true_nearbase_idlist[i]; |
| | | nearbase_distlist[i]=true_nearbase_distlist[i]; |
| | | exsistbase_list[i] = true_exsistbase_list[i]; |
| | | } |
| | | // #ifdef USART_INTEGRATE_OUTPUT |
| | | // usart_send[0] = 0x55; |
| | |
| | | // USART_puts(usart_send,6+report_num*6); |
| | | // #endif |
| | | |
| | | for(i=0;i<MAX_NEARBASE_NUM;i++) |
| | | { |
| | | nearbase_distlist[i]=0x1ffff; |
| | | } |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR| SYS_STATUS_TXFRS |SYS_STATUS_RXFCG); |
| | | //HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET); |
| | | CalculateDists(); |
| | | |
| | | if(para_update==1) |
| | | { |
| | | uint16_t calCRC; |