| | |
| | | #define BUTTON_IDX 16 |
| | | #define SEQUENCE_IDX 17 |
| | | //respose |
| | | #define TIMECORRE 14 |
| | | #define ANCTIMEMS 14 |
| | | #define ANCTIMEUS 16 |
| | | |
| | | #define POLL 0x01 |
| | | #define RESPONSE 0x02 |
| | |
| | | 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 rx_poll_msg[] = {0x00, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x21, 0, 0}; |
| | | static uint8_t tx_resp_msg[18] = {0}; |
| | | static uint8_t tx_resp_msg[20] = {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. */ |
| | |
| | | int32_t hex_dist; |
| | | u16 checksum; |
| | | int8_t tag_delaytime; |
| | | extern uint16_t sync_timer; |
| | | u16 tmp_time; |
| | | void Tag_App(void)//å鿍¡å¼(TAGæ ç¾) |
| | | { |
| | | uint32_t frame_len; |
| | | uint32_t final_tx_time; |
| | | u32 start_poll; |
| | | u8 i; |
| | | u8 i,getsync_flag=0; |
| | | //LED0_ON; |
| | | dwt_forcetrxoff(); |
| | | g_Resttimer=0; |
| | |
| | | tx_poll_msg[BATTARY_IDX] = Get_Battary(); |
| | | tx_poll_msg[BUTTON_IDX] = !READ_KEY0; |
| | | tx_poll_msg[SEQUENCE_IDX] = frame_seq_nb++; |
| | | |
| | | GPIO_WriteBit(GPIOA, GPIO_Pin_9, Bit_RESET); |
| | | for(i=0;i<g_com_map[MAX_REPORT_ANC_NUM];i++) |
| | | { |
| | | /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */ |
| | | tx_poll_msg[ANC_TYPE_IDX] = i; |
| | | tx_poll_msg[ANC_TYPE_IDX] = i-1; |
| | | |
| | | dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0);//å°Pollå
æ°æ®ä¼ ç»DW1000ï¼å°å¨å¼å¯åéæ¶ä¼ åºå» |
| | | dwt_writetxfctrl(sizeof(tx_poll_msg), 0);//设置è¶
宽带åéæ°æ®é¿åº¦ |
| | |
| | | poll_tx_ts = get_tx_timestamp_u64(); //è·å¾POLLåéæ¶é´T1 |
| | | resp_rx_ts = get_rx_timestamp_u64(); //è·å¾RESPONSEæ¥æ¶æ¶é´T4 |
| | | |
| | | if(i==0) |
| | | { |
| | | tag_delaytime=rx_buffer[TIMECORRE]; |
| | | if(tag_delaytime>g_com_map[COM_INTERVAL]/2) |
| | | { |
| | | tag_delaytime=tag_delaytime-g_com_map[COM_INTERVAL]; |
| | | } |
| | | } |
| | | |
| | | if(getsync_flag==0) |
| | | { |
| | | getsync_flag=1; |
| | | memcpy(&sync_timer,&rx_buffer[ANCTIMEMS],2); |
| | | memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); |
| | | tmp_time=tmp_time+450; |
| | | if(tmp_time>999) |
| | | { |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1010) |
| | | {sync_timer=0;} |
| | | } |
| | | TIM3->CNT=tmp_time; |
| | | } |
| | | memcpy(&anchor_dist_last_frm[0], &rx_buffer[DIST_IDX], 4); |
| | | memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); |
| | | /* Compute final message transmission time. See NOTE 9 below. */ |
| | |
| | | } |
| | | int8_t correction_time; |
| | | extern uint8_t sync_seq; |
| | | extern uint16_t sync_timer; |
| | | |
| | | void Anchor_App(void) |
| | | { |
| | | uint32_t frame_len; |
| | |
| | | |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == POLL&&(anchor_type == rx_buffer[ANC_TYPE_IDX])) //夿æ¯å¦æ¯pollå
æ°æ® |
| | | { |
| | | correction_time=tag_timer-tag_id_recv*3; |
| | | if(correction_time == g_com_map[COM_INTERVAL]) |
| | | correction_time = 0; |
| | | tx_resp_msg[TIMECORRE] = correction_time; |
| | | tmp_time=TIM3->CNT; |
| | | memcpy(&tx_resp_msg[ANCTIMEMS],&sync_timer,2); |
| | | memcpy(&tx_resp_msg[ANCTIMEUS],&tmp_time,2); |
| | | |
| | | // if(correction_time>10) |
| | | // {correction_time++;} |
| | | |
| | |
| | | }else if(rx_buffer[MESSAGE_TYPE_IDX] == SYNC) |
| | | { |
| | | if(rx_buffer[SYNC_SEQ_IDX]<sync_seq) |
| | | // if(rx_buffer[SYNC_SEQ_IDX]==2) |
| | | { |
| | | sync_seq=rx_buffer[SYNC_SEQ_IDX]+1; |
| | | SysTick->VAL =00; |
| | | sync_timer=0; |
| | | TIM3->CNT = sync_seq*325%1000+15; |
| | | sync_timer = sync_seq*325/1000; |
| | | SyncPoll(sync_seq); |
| | | } |
| | | } |