| | |
| | | #include "modbus.h" |
| | | //#define DEBUG_OUTPUT |
| | | #define TDFILTER |
| | | #define CONSTANT_FILTER |
| | | //#define CONSTANT_FILTER |
| | | /*------------------------------------ Marcos ------------------------------------------*/ |
| | | /* Inter-ranging delay period, in milliseconds. */ |
| | | #define RNG_DELAY_MS 100 |
| | |
| | | u32 getdatatimer[TAGARRAY_LEN]; |
| | | #define DATALOSTTIME 2000 |
| | | extern float dw_vbat; |
| | | extern u8 supergroupid,modbusread_start; |
| | | extern u16 slottime,max_slotnum,current_slotpos,tyncpoll_time; |
| | | void Tag_App(void)//å鿍¡å¼(TAGæ ç¾) |
| | | { |
| | |
| | | /* Check that the frame is the expected response from the companion "DS TWR responder" example. |
| | | * 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]==0||rx_buffer[GROUP_ID_IDX] == group_id||group_id==0)&&rx_buffer[MESSAGE_TYPE_IDX] == RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,4)) //å¤ææ¥æ¶å°çæ°æ®æ¯å¦æ¯responseæ°æ® |
| | | if ((rx_buffer[GROUP_ID_IDX]==supergroupid||rx_buffer[GROUP_ID_IDX] == group_id||group_id==supergroupid)&&rx_buffer[MESSAGE_TYPE_IDX] == RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,4)) //å¤ææ¥æ¶å°çæ°æ®æ¯å¦æ¯responseæ°æ® |
| | | { u16 anc_id_recv,rec_com_interval; |
| | | /* Retrieve poll transmission and response reception timestamp. */ |
| | | poll_tx_ts = get_tx_timestamp_u64(); //è·å¾POLLåéæ¶é´T1 |
| | |
| | | TIM3->CNT=tmp_time; |
| | | } |
| | | memcpy(&hex_dist2, &rx_buffer[DIST_IDX], 4); |
| | | memcpy(&tag_distarray[i*4], &rx_buffer[DIST_IDX], 4); |
| | | memcpy(&tag_IDarray[i*2],&rx_buffer[ANCHOR_ID_IDX],2); |
| | | memcpy(&tag_distarray[i], &rx_buffer[DIST_IDX], 4); |
| | | memcpy(&tag_IDarray[i],&rx_buffer[ANCHOR_ID_IDX],2); |
| | | 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); |
| | |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |
| | | } |
| | | Modbus_HoldReg[anc_id_recv*2]=hex_dist2>>16; |
| | | Modbus_HoldReg[anc_id_recv*2+1]=hex_dist2; |
| | | } |
| | | // memcpy(&Modbus_HoldReg[anc_id_recv*2],&hex_dist,4); |
| | | /* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */ |
| | |
| | | } |
| | | |
| | | /* Execute a delay between ranging exchanges. */ |
| | | |
| | | if(modbusread_start) |
| | | { |
| | | Modbus_03_Solve(); |
| | | } |
| | | } |
| | | |
| | | int8_t correction_time; |
| | |
| | | // tag_recv_interval = tag_recv_timer + 65535 - tag_time_recv[tag_id_recv]; |
| | | // } |
| | | |
| | | if ((rx_buffer[GROUP_ID_IDX]==0||rx_buffer[GROUP_ID_IDX] == group_id||group_id==0)&&rx_buffer[MESSAGE_TYPE_IDX] == POLL&&(anchor_type == rx_buffer[ANC_TYPE_IDX])) //夿æ¯å¦æ¯pollå
æ°æ® |
| | | if ((rx_buffer[GROUP_ID_IDX]==supergroupid||rx_buffer[GROUP_ID_IDX] == group_id||group_id==supergroupid)&&rx_buffer[MESSAGE_TYPE_IDX] == POLL&&(anchor_type == rx_buffer[ANC_TYPE_IDX])) //夿æ¯å¦æ¯pollå
æ°æ® |
| | | { |
| | | tmp_time=TIM3->CNT; |
| | | memcpy(&tx_resp_msg[ANCTIMEMS],&sync_timer,2); |
| | |
| | | /* Check that the frame is a final message sent by "DS TWR initiator" example. |
| | | * As the sequence number field of the frame is not used in this example, it can be zeroed to ease the validation of the frame. */ |
| | | |
| | | if ((rx_buffer[GROUP_ID_IDX]==0||rx_buffer[GROUP_ID_IDX] == group_id||group_id==0)&&rx_buffer[MESSAGE_TYPE_IDX] == FINAL&&!memcmp(&rx_buffer[TAG_ID_IDX],&tag_id_recv,4)&&!memcmp(&rx_buffer[ANCHOR_ID_IDX],&dev_id,4)) //夿æ¯å¦ä¸ºFinalå
|
| | | if ((rx_buffer[GROUP_ID_IDX]==supergroupid||rx_buffer[GROUP_ID_IDX] == group_id||group_id==supergroupid)&&rx_buffer[MESSAGE_TYPE_IDX] == FINAL&&!memcmp(&rx_buffer[TAG_ID_IDX],&tag_id_recv,4)&&!memcmp(&rx_buffer[ANCHOR_ID_IDX],&dev_id,4)) //夿æ¯å¦ä¸ºFinalå
|
| | | { |
| | | uint32_t poll_tx_ts, resp_rx_ts, final_tx_ts; |
| | | uint32_t poll_rx_ts_32, resp_tx_ts_32, final_rx_ts_32; |
| | |
| | | memcpy(&usart_send[5],&tag_id_recv,2); |
| | | memcpy(&usart_send[7],&ancrec_IDarray[i],2); |
| | | |
| | | memcpy(&usart_send[9],&anchor_dist_last_frm[tag_id_recv-TAG_ID_START],4); |
| | | memcpy(&usart_send[9],&ancrec_distarray[i],4); |
| | | usart_send[13] = battary; |
| | | usart_send[14] = button; |
| | | usart_send[15] = firstpath_power; |