| | |
| | | */ |
| | | |
| | | #include <string.h> |
| | | #include <math.h> |
| | | #include "dw_app.h" |
| | | #include "deca_device_api.h" |
| | | #include "deca_regs.h" |
| | |
| | | #define POLL_TX_TO_RESP_RX_DLY_UUS 150 |
| | | /* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the |
| | | * frame length of approximately 2.66 ms with above configuration. */ |
| | | #define RESP_RX_TO_FINAL_TX_DLY_UUS 400 |
| | | #define RESP_RX_TO_FINAL_TX_DLY_UUS 4100 |
| | | /* Receive response timeout. See NOTE 5 below. */ |
| | | #define RESP_RX_TIMEOUT_UUS 600 |
| | | #define RESP_RX_TIMEOUT_UUS 4700 |
| | | |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 420 |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 3600 |
| | | /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ |
| | | #define RESP_TX_TO_FINAL_RX_DLY_UUS 200 |
| | | #define RESP_TX_TO_FINAL_RX_DLY_UUS 500 |
| | | /* Receive final timeout. See NOTE 5 below. */ |
| | | #define FINAL_RX_TIMEOUT_UUS 4300 |
| | | |
| | | #define SPEED_OF_LIGHT 299702547 |
| | | |
| | | /* Indexes to access some of the fields in the frames defined above. */ |
| | |
| | | #define ANCTIMEMS 14 |
| | | #define ANCTIMEUS 16 |
| | | #define ANCSEND_INTERVAL 18 |
| | | #define SIGNALPOWER 20 |
| | | |
| | | #define POLL 0x01 |
| | | #define RESPONSE 0x02 |
| | |
| | | /*------------------------------------ Variables ------------------------------------------*/ |
| | | /* Default communication configuration. We use here EVK1000's default mode (mode 3). */ |
| | | static dwt_config_t config = { |
| | | 2, /* Channel number. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | 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. */ |
| | | (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | 2, /* Channel number. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | DWT_PLEN_1024, /* Preamble length. */ |
| | | DWT_PAC32, /* 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_110K, /* Data rate. */ |
| | | DWT_PHRMODE_STD, /* PHY header mode. */ |
| | | (1025 + 64 - 32) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | }; |
| | | |
| | | /* Frames used in the ranging process. See NOTE 2 below. */ |
| | |
| | | static uint8_t tx_final_msg[24] = {0}; |
| | | |
| | | //static uint8_t rx_poll_msg[] = {0x00, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x21, 0, 0}; |
| | | static uint8_t tx_resp_msg[22] = {0}; |
| | | static uint8_t tx_resp_msg[23] = {0}; |
| | | //static uint8_t rx_final_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| | | |
| | | /* Frame sequence number, incremented after each transmission. */ |
| | |
| | | dwt_writetxfctrl(sizeof(tx_sync_msg), 0);//设置è¶
宽带åéæ°æ®é¿åº¦ |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE); |
| | | } |
| | | double firstpath_power, rx_power,rec_firstpath_power; |
| | | double f1, f2, r1, r2; |
| | | uint16_t F1,F2,F3,N,C; |
| | | double B = 131072; |
| | | double A = 121.74; |
| | | double min_power; |
| | | dwt_rxdiag_t d1; |
| | | 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; |
| | | } |
| | | uint16_t g_Resttimer; |
| | | uint8_t result; |
| | | u8 tag_succ_times=0; |
| | |
| | | TIM3->CNT=tmp_time; |
| | | } |
| | | memcpy(&hex_dist2, &rx_buffer[DIST_IDX], 4); |
| | | rec_firstpath_power = rx_buffer[SIGNALPOWER]; |
| | | memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); |
| | | memcpy(&rec_com_interval,&rx_buffer[ANCSEND_INTERVAL], 2); |
| | | if(rec_com_interval>4&&rec_com_interval!=g_com_map[COM_INTERVAL]) |
| | |
| | | memcpy(&usart_send[9],&hex_dist2,4); |
| | | usart_send[13] = bat_percent; |
| | | usart_send[14] = button; |
| | | usart_send[15] = rec_firstpath_power; |
| | | checksum = Checksum_u16(&usart_send[2],17); |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |
| | |
| | | /* Execute a delay between ranging exchanges. */ |
| | | |
| | | } |
| | | |
| | | int8_t correction_time; |
| | | extern uint8_t sync_seq; |
| | | #define TDFILTER |
| | |
| | | /* Write and send the response message. See NOTE 9 below.*/ |
| | | if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) |
| | | memcpy(&tx_resp_msg[DIST_IDX], &g_Tagdist[tag_id_recv], 4); |
| | | |
| | | tx_resp_msg[SIGNALPOWER] = firstpath_power; |
| | | |
| | | dwt_writetxdata(sizeof(tx_resp_msg), tx_resp_msg, 0);//åå
¥åéæ°æ® |
| | | dwt_writetxfctrl(sizeof(tx_resp_msg), 0);//设å®åéé¿åº¦ |
| | | result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//å»¶è¿åéï¼çå¾
æ¥æ¶ |
| | |
| | | |
| | | dist_cm = dist_no_bias * 1000; //dis 为åä½ä¸ºcmçè·ç¦» |
| | | // dist[TAG_ID] = LP(dis, TAG_ID); //LP 为ä½é滤波å¨ï¼è®©æ°æ®æ´ç¨³å® |
| | | |
| | | dwt_readdiagnostics(&d1); |
| | | LOS(&d1); |
| | | /*--------------------------以ä¸ä¸ºéæµè·é»è¾------------------------*/ |
| | | #ifdef DEBUG_OUTPUT |
| | | printf("æ¶å°FINALå
ï¼æ ç¾ID: %d .\r\n",tag_id_recv); |
| | |
| | | memcpy(&usart_send[9],&anchor_dist_last_frm[tag_id_recv-TAG_ID_START],4); |
| | | usart_send[13] = battary; |
| | | usart_send[14] = button; |
| | | usart_send[15] = firstpath_power; |
| | | checksum = Checksum_u16(&usart_send[2],17); |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |