| | |
| | | static dwt_config_t config = { |
| | | 2, /* Channel number. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | DWT_PLEN_128, /* Preamble length. */ |
| | | DWT_PLEN_64, /* 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. */ |
| | | 0, /* Use non-standard SFD (Boolean) */ |
| | | 1, /* Use non-standard SFD (Boolean) */ |
| | | DWT_BR_6M8, /* Data rate. */ |
| | | DWT_PHRMODE_STD, /* PHY header mode. */ |
| | | (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | |
| | | static uint64_t resp_tx_ts; |
| | | static uint64_t final_rx_ts; |
| | | static double tof; |
| | | int32_t anchor_dist_last_frm[TAG_NUM_IN_SYS],his_dist[TAG_NUM_IN_SYS]; ; |
| | | int32_t anchor_dist_last_frm[TAG_NUM_IN_SYS],his_dist[TAG_NUM_IN_SYS]; |
| | | uint32_t tag_id = 0; |
| | | uint32_t tag_id_recv = 0; |
| | | uint32_t anc_id_recv = 0; |
| | |
| | | } |
| | | return max_slotpos-1; |
| | | } |
| | | dwt_rxdiag_t d1; |
| | | u8 test=0; |
| | | u8 anclost_times=0; |
| | | u8 exsistbase_list[MAX_NEARBASE_NUM],report_num,get_newbase=0; |
| | | u16 temp_sync_timer1,temp_sync_timer2; |
| | | double firstpath_power, rx_power; |
| | | double f1, f2, r1, r2; |
| | | uint16_t F1,F2,F3,N,C; |
| | | double B = 131072; |
| | | double A = 121.74; |
| | | double min_power; |
| | | double LOS(dwt_rxdiag_t *dia) { |
| | | F1 = dia->firstPathAmp1; |
| | | F2 = dia->firstPathAmp2; |
| | | F3 = dia->firstPathAmp3; |
| | | N = dia->rxPreamCount; |
| | | C = dia->maxGrowthCIR; |
| | | |
| | | firstpath_power=10* log10((F1*F1+F2*F2+F3*F3)/(N*N))-A; |
| | | rx_power=10*log10(C*B/(N*N))-A; |
| | | |
| | | // min_power = - 10 * log10((F1 *F1 + F2 * F2 + F3 * F3) / (C *B)); |
| | | return min_power; |
| | | } |
| | | void Poll(void) |
| | | { |
| | | uint32_t frame_len; |
| | |
| | | flag_rxon=1; |
| | | neartimout_timer=0; |
| | | get_newbase=0; |
| | | timeout=ceil((float)nearbase_num*SLOT_SCALE)+3; |
| | | timeout=ceil((float)nearbase_num*SLOT_SCALE)+2; |
| | | //timeout=5; |
| | | mainbase_dist=100000; |
| | | mainbase_lost_count++; |
| | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | } |
| | | uint32_t time_monitor[10]; |
| | | extern uint16_t configremotetagID; |
| | | extern u8 remotetag_paralen; |
| | | u8 misdist_num[TAG_NUM_IN_SYS],seize_anchor,waittagconfig_reponse; |
| | | u8 Anchor_RecNearPoll(u8 ancrec_nearbasepos) //0 mainbase 1 first near_base |
| | | { |
| | | u8 motorstate; |
| | | time_monitor[0] = sync_timer*1000+TIM3->CNT; |
| | | tmp_time=TIM3->CNT; |
| | | memcpy(&tx_nearresp_msg[ANCTIMEMS],&sync_timer,2); |
| | | memcpy(&tx_nearresp_msg[ANCTIMEUS],&tmp_time,2); |
| | |
| | | memcpy(&tx_nearresp_msg[TAG_ID_IDX],&tag_id_recv,2); |
| | | poll_rx_ts = get_rx_timestamp_u64();//è·å¾Pollå
æ¥æ¶æ¶é´T2 |
| | | |
| | | resp_tx_time = (poll_rx_ts + ((POLL_RX_TO_RESP_TX_DLY_UUS+ancrec_nearbasepos*DELAY_BETWEEN_TWO_FRAME_UUS) * UUS_TO_DWT_TIME)) >> 8;//计ç®Responseåéæ¶é´T3ã |
| | | resp_tx_time = (poll_rx_ts + ((POLL_RX_TO_RESP_TX_DLY_UUS+(ancrec_nearbasepos)*DELAY_BETWEEN_TWO_FRAME_UUS) * UUS_TO_DWT_TIME)) >> 8;//计ç®Responseåéæ¶é´T3ã |
| | | dwt_setdelayedtrxtime(resp_tx_time);//设置Responseåéæ¶é´T3 |
| | | dwt_setrxaftertxdelay(RESP_TX_TO_FINAL_RX_DLY_UUS+(rec_nearbase_num+1-ancrec_nearbasepos)*DELAY_BETWEEN_TWO_FRAME_UUS);//设置åé宿åå¼å¯æ¥æ¶å»¶è¿æ¶é´ |
| | | dwt_setrxtimeout(FINAL_RX_TIMEOUT_UUS);//æ¥æ¶è¶
æ¶æ¶é´ |
| | | |
| | | dwt_readdiagnostics(&d1); |
| | | if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE1]) |
| | | { |
| | | motorstate =0; |
| | |
| | | int64_t tof_dtu; |
| | | resp_tx_ts = get_tx_timestamp_u64();//è·å¾responseåéæ¶é´T3 |
| | | final_rx_ts = get_rx_timestamp_u64();//è·å¾finalæ¥æ¶æ¶é´T6 |
| | | |
| | | dwt_setrxtimeout(0);//è®¾å®æ¥æ¶è¶
æ¶æ¶é´ï¼0使²¡æè¶
æ¶æ¶é´ |
| | | dwt_rxenable(0);//æå¼æ¥æ¶ |
| | | |
| | | final_msg_get_ts(&rx_buffer[FINAL_MSG_POLL_TX_TS_IDX], &poll_tx_ts);//仿¥æ¶æ°æ®ä¸è¯»åT1ï¼T4ï¼T5 |
| | | final_msg_get_ts(&rx_buffer[FINAL_MSG_RESP_RX_NEARBASE_IDX+ancrec_nearbasepos*4], &resp_rx_ts); |
| | | final_msg_get_ts(&rx_buffer[FINAL_MSG_FINAL_TX_TS_IDX], &final_tx_ts); |
| | |
| | | poll_rx_ts_32 = (uint32_t)poll_rx_ts;//使ç¨32使°æ®è®¡ç® |
| | | resp_tx_ts_32 = (uint32_t)resp_tx_ts; |
| | | final_rx_ts_32 = (uint32_t)final_rx_ts; |
| | | time_monitor[1] = sync_timer*1000+TIM3->CNT; |
| | | Ra = (double)(resp_rx_ts - poll_tx_ts);//Tround1 = T4 - T1 |
| | | Rb = (double)(final_rx_ts_32 - resp_tx_ts_32);//Tround2 = T6 - T3 |
| | | Da = (double)(final_tx_ts - resp_rx_ts);//Treply2 = T5 - T4 |
| | |
| | | tof = tof_dtu * DWT_TIME_UNITS; |
| | | distance = tof * SPEED_OF_LIGHT;//è·ç¦»=å
é*é£è¡æ¶é´ |
| | | dist_no_bias = distance - dwt_getrangebias(config.chan, (float)distance, config.prf); //è·ç¦»åå»ç«æ£ç³»æ° |
| | | dist_cm = dist_no_bias * 100; //dis 为åä½ä¸ºcmçè·ç¦» |
| | | dist_cm = dist_no_bias * 100; //dis 为åä½ä¸ºcmçè·ç¦» |
| | | // dwt_readdiagnostics(&d1); |
| | | // time_monitor[2] = sync_timer*1000+TIM3->CNT; |
| | | // LOS(&d1); |
| | | // time_monitor[3] = sync_timer*1000+TIM3->CNT; |
| | | /*--------------------------以ä¸ä¸ºéæµè·é»è¾------------------------*/ |
| | | //dist_cm=33000; |
| | | |