| | |
| | | #define FINAL_MSG_TS_LEN 4 |
| | | |
| | | #define SYNC_SEQ_IDX 5 |
| | | |
| | | //common |
| | | #define GROUP_ID_IDX 0 |
| | | #define ANCHOR_ID_IDX 1 |
| | | #define TAG_ID_IDX 5 |
| | | #define MESSAGE_TYPE_IDX 9 |
| | | #define DIST_IDX 10 |
| | | |
| | | //Poll |
| | | #define ANC_TYPE_IDX 14 |
| | | #define BATTARY_IDX 15 |
| | | #define BUTTON_IDX 16 |
| | | #define SEQUENCE_IDX 17 |
| | | //respose |
| | | #define DIST_IDX 10 |
| | | #define ANCTIMEMS 14 |
| | | #define ANCTIMEUS 16 |
| | | #define ANCSEND_INTERVAL 18 |
| | | |
| | | #define POLL 0x01 |
| | | #define RESPONSE 0x02 |
| | |
| | | static uint8_t tx_poll_msg[20] = {0}; |
| | | static uint8_t tx_sync_msg[14] = {0}; |
| | | //static uint8_t rx_resp_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'V', 'E', 'W', 'A', 0x10, 0x02, 0, 0, 0, 0}; |
| | | static uint8_t tx_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}; |
| | | 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[20] = {0}; |
| | | static uint8_t tx_resp_msg[22] = {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. */ |
| | |
| | | for(i=0;i<255;i++) |
| | | { |
| | | g_flag_Taggetdist[i]++; |
| | | if(g_flag_Taggetdist[i]>=20) |
| | | if(g_flag_Taggetdist[i]>=2) |
| | | { |
| | | g_Tagdist[i]=0xffff; |
| | | } |
| | |
| | | memcpy(&tx_final_msg[TAG_ID_IDX], &dev_id, 4); |
| | | memcpy(&tx_resp_msg[ANCHOR_ID_IDX], &dev_id, 4); |
| | | memcpy(&tx_sync_msg[ANCHOR_ID_IDX], &dev_id, 4); |
| | | |
| | | memcpy(&tx_resp_msg[ANCSEND_INTERVAL], &g_com_map[COM_INTERVAL], 2); |
| | | } |
| | | uint16_t Checksum_u16(uint8_t* pdata, uint32_t len) |
| | | { |
| | |
| | | * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */ |
| | | |
| | | if (rx_buffer[GROUP_ID_IDX] == group_id&&rx_buffer[MESSAGE_TYPE_IDX] == RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,4)) //å¤ææ¥æ¶å°çæ°æ®æ¯å¦æ¯responseæ°æ® |
| | | { u16 anc_id_recv; |
| | | { u16 anc_id_recv,rec_com_interval; |
| | | /* Retrieve poll transmission and response reception timestamp. */ |
| | | poll_tx_ts = get_tx_timestamp_u64(); //è·å¾POLLåéæ¶é´T1 |
| | | resp_rx_ts = get_rx_timestamp_u64(); //è·å¾RESPONSEæ¥æ¶æ¶é´T4 |
| | |
| | | } |
| | | memcpy(&hex_dist2, &rx_buffer[DIST_IDX], 4); |
| | | 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]) |
| | | { |
| | | g_com_map[COM_INTERVAL]=rec_com_interval; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软å¤ä½åå°bootloader |
| | | } |
| | | |
| | | /* Compute final message transmission time. See NOTE 9 below. */ |
| | | final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8;//计ç®finalå
åéæ¶é´ï¼T5=T4+Treply2 |
| | | dwt_setdelayedtrxtime(final_tx_time);//设置finalå
åéæ¶é´T5 |
| | |
| | | LED0_BLINK; |
| | | |
| | | memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2); |
| | | // g_Tagdist[anc_id_recv]= hex_dist; |
| | | // g_flag_Taggetdist[anc_id_recv]=0; |
| | | if(hex_dist2!=0xffff) |
| | | { |
| | | g_Tagdist[anc_id_recv]= hex_dist2; |
| | | g_flag_Taggetdist[anc_id_recv]=0; |
| | | |
| | | if(!g_com_map[MODBUS_MODE]&&hex_dist2!=0xffff) |
| | | if(!g_com_map[MODBUS_MODE]) |
| | | { |
| | | hex_dist2 = hex_dist2+(int16_t)g_com_map[DIST_OFFSET]; |
| | | hex_dist2 = hex_dist2; |
| | | usart_send[2] = 1;//æ£å¸¸æ¨¡å¼ |
| | | usart_send[3] = 17;//æ°æ®æ®µé¿åº¦ |
| | | usart_send[4] = frame_seq_nb;//æ°æ®æ®µé¿åº¦ |
| | |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |
| | | } |
| | | } |
| | | // memcpy(&Modbus_HoldReg[anc_id_recv*2],&hex_dist,4); |
| | | /* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */ |
| | | if(result==0) |
| | |
| | | } |
| | | }else if(rx_buffer[MESSAGE_TYPE_IDX] == SYNC) |
| | | { |
| | | if(rx_buffer[SYNC_SEQ_IDX]<sync_seq) |
| | | // if(rx_buffer[SYNC_SEQ_IDX]==2) |
| | | if(rx_buffer[SYNC_SEQ_IDX]<sync_seq&&sync_mainbase==0) |
| | | { |
| | | sync_seq=rx_buffer[SYNC_SEQ_IDX]+1; |
| | | TIM3->CNT = sync_seq*325%1000+15; |