| | |
| | | //respose |
| | | #define ANCTIMEMS 14 |
| | | #define ANCTIMEUS 16 |
| | | #define TAGSLOTPOS 18 |
| | | |
| | | #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[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. */ |
| | |
| | | extern uint16_t sync_timer; |
| | | u16 tmp_time; |
| | | int32_t temp_dist; |
| | | u16 tagslotpos; |
| | | void Tag_App(void)//å鿍¡å¼(TAGæ ç¾) |
| | | { |
| | | uint32_t frame_len; |
| | |
| | | getsync_flag=1; |
| | | memcpy(&sync_timer,&rx_buffer[ANCTIMEMS],2); |
| | | memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); |
| | | memcpy(&tagslotpos,&rx_buffer[TAGSLOTPOS],2); |
| | | tmp_time=tmp_time+450; |
| | | if(tmp_time>999) |
| | | { |
| | |
| | | {sync_timer=0;} |
| | | } |
| | | TIM3->CNT=tmp_time; |
| | | if(tagslotpos>max_slotpos) |
| | | tagslotpos=tagslotpos%(max_slotpos+1); |
| | | tyncpoll_time=(tagslotpos-1)*slottime; |
| | | } |
| | | memcpy(&anchor_dist_last_frm[0], &rx_buffer[DIST_IDX], 4); |
| | | memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); |
| | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | random_delay_tim = DFT_RAND_DLY_TIM_MS; |
| | | } |
| | | // deca_sleep(10); |
| | | } |
| | | // dwt_entersleep(); |
| | | if(tag_succ_times<g_com_map[MIN_REPORT_ANC_NUM]) |
| | | |
| | | if(getsync_flag==0) |
| | | { |
| | | //poll_timer +=time32_incr&0x7+3; |
| | | tagslotpos--; |
| | | if(tagslotpos==0||tagslotpos>max_slotpos) |
| | | { |
| | | tagslotpos=max_slotpos; |
| | | } |
| | | tyncpoll_time=(tagslotpos-1)*slottime; |
| | | } |
| | | |
| | | /* Execute a delay between ranging exchanges. */ |
| | | |
| | | } |
| | | |
| | | int8_t correction_time; |
| | | extern uint8_t sync_seq; |
| | | u16 taglist_num=0,taglist_pos; |
| | | u16 tagid_list[TAG_NUM_IN_SYS]; |
| | | u8 tagofflinetime[TAG_NUM_IN_SYS]; |
| | | void TagListUpdate(void) |
| | | { |
| | | u16 i,j=0,temp[TAG_NUM_IN_SYS]; |
| | | for(i=0;i<taglist_num;i++) |
| | | { |
| | | if(tagofflinetime[i]++<QUIT_SLOT_TIME) |
| | | { |
| | | tagid_list[j]=tagid_list[i]; |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | | taglist_num=j; |
| | | } |
| | | u16 CmpTagInList(u16 tagid) |
| | | {u16 i; |
| | | for(i=0;i<taglist_num;i++) |
| | | { |
| | | if(memcmp(&tagid,&tagid_list[i],2)==0) |
| | | return i+1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | void Anchor_App(void) |
| | | { |
| | |
| | | //tag_id_recv = rx_buffer[TAG_ID_IDX]; |
| | | memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],4); |
| | | memcpy(&tx_resp_msg[TAG_ID_IDX],&tag_id_recv,4); |
| | | //tx_resp_msg[TAG_ID_IDX] = tag_id_recv; |
| | | // if(tag_recv_timer>tag_time_recv[tag_id_recv-TAG_ID_START]) |
| | | // { tag_recv_interval = tag_recv_timer - tag_time_recv[tag_id_recv]; |
| | | // }else{ |
| | | // tag_recv_interval = tag_recv_timer + 65535 - tag_time_recv[tag_id_recv]; |
| | | // } |
| | | |
| | | taglist_pos=CmpTagInList(tag_id_recv); |
| | | if(taglist_pos==0) |
| | | { |
| | | tagid_list[taglist_num++]=tag_id_recv; |
| | | taglist_pos=taglist_num; |
| | | } |
| | | tagofflinetime[taglist_pos-1]=0; |
| | | if (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); |
| | | memcpy(&tx_resp_msg[ANCTIMEUS],&tmp_time,2); |
| | | |
| | | memcpy(&tx_resp_msg[TAGSLOTPOS],&taglist_pos,2); |
| | | // if(correction_time>10) |
| | | // {correction_time++;} |
| | | |
| | |
| | | //dist_cm=33000; |
| | | |
| | | LED0_BLINK; //æ¯æå䏿¬¡é讯åéªç䏿¬¡ |
| | | g_UWB_com_interval = 0; |
| | | dis_after_filter=dist_cm; |
| | | hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]; |
| | | if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) |
| | |
| | | checksum = Checksum_u16(&usart_send[2],17); |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |
| | | |
| | | |
| | | //dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); |
| | | |
| | | } |
| | | }else{ |
| | | /* Clear RX error events in the DW1000 status register. */ |