| | |
| | | #include "dw_app.h" |
| | | #include "ADC.h" |
| | | #define TDFILTER |
| | | #include "stm32f10x_it.h" |
| | | #include "serial_at_cmd_app.h" |
| | | #define STRX(x) #x |
| | | #define STR(x) STRX(x) |
| | | #define __debug_info__ __FILE__ ":" STR(__LINE__) |
| | | //#define TDFILTER |
| | | #define DBGMSG_OUTPUT |
| | | enum enumtagstate |
| | | { |
| | | DISCPOLL, |
| | |
| | | uint32_t tag_id = 0; |
| | | uint32_t tag_id_recv = 0; |
| | | uint32_t anc_id_recv = 0; |
| | | uint8_t random_delay_tim = 0; |
| | | uint8_t random_delay_tim = 0,dbgmsg_len; |
| | | double distance, dist_no_bias, dist_cm; |
| | | uint32_t g_UWB_com_interval = 0; |
| | | float dis_after_filter; //å½åè·ç¦»å¼ |
| | | LPFilter_Frac* p_Dis_Filter; //æµè·ç¨çä½éæ»¤æ³¢å¨ |
| | | int32_t g_Tagdist[TAG_NUM_IN_SYS]; |
| | | uint8_t g_flag_Taggetdist[256],flag_tag_distsmooth[TAG_NUM_IN_SYS]; |
| | | |
| | | char dbgmsg[100]; |
| | | static uint64_t get_tx_timestamp_u64(void) |
| | | { |
| | | uint8_t ts_tab[5]; |
| | |
| | | u8 exsistbase_list[MAX_NEARBASE_NUM],report_num,get_newbase=0,uwbrec_userdata[20],uwbrec_userdatalen; |
| | | u16 temp_sync_timer1,temp_sync_timer2; |
| | | extern u8 usartrec_userdatalen,heartbeat_timer; |
| | | void NearPoll(void) |
| | | void NearPoll(void) |
| | | { |
| | | static u8 mainbase_lost_count=0,flag_finalsend,flag_rxon; |
| | | uint32_t temp1,temp2,dw_systime; |
| | |
| | | flag_rxon=0; |
| | | dwt_forcetrxoff(); |
| | | dwt_setdelayedtrxtime(final_tx_time); |
| | | result=dwt_starttx(DWT_START_TX_DELAYED);//设å®ä¸ºå»¶è¿åé |
| | | result=dwt_starttx(DWT_START_TX_DELAYED);//设å®ä¸ºå»¶è¿åé |
| | | if(result!=DWT_SUCCESS) |
| | | { |
| | | #ifdef DBGMSG_OUTPUT |
| | | dbgmsg_len = sprintf(dbgmsg,"%s status_reg:%x",__debug_info__,status_reg); |
| | | SendDbgMsg(dbgmsg,dbgmsg_len); |
| | | #endif |
| | | } |
| | | break; |
| | | } |
| | | } |
| | |
| | | memcpy(&tmp_time,&rx_buffer[ANCTIMEUS],2); |
| | | |
| | | |
| | | if(g_com_map[DEV_ROLE]!=0) |
| | | { |
| | | sync_timer=temp_sync_timer1; |
| | | //// memcpy(&tagslotpos,&rx_buffer[TAGSLOTPOS],2); |
| | | // if(g_com_map[DEV_ROLE]!=0) |
| | | // { |
| | | // sync_timer=temp_sync_timer1; |
| | | ////// memcpy(&tagslotpos,&rx_buffer[TAGSLOTPOS],2); |
| | | //// |
| | | // |
| | | |
| | | tmp_time=tmp_time+650; |
| | | if(tmp_time>999) |
| | | { |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1000) |
| | | {sync_timer=0;} |
| | | } |
| | | TIM3->CNT=tmp_time; |
| | | } |
| | | // tmp_time=tmp_time+650; |
| | | // if(tmp_time>999) |
| | | // { |
| | | // tmp_time-=999; |
| | | // sync_timer++; |
| | | // if(sync_timer>=1000) |
| | | // {sync_timer=0;} |
| | | // } |
| | | // TIM3->CNT=tmp_time; |
| | | // } |
| | | current_slotnum=temp_sync_timer1/g_com_map[COM_INTERVAL]; |
| | | // if(tagslotpos>max_slotpos) |
| | | // tagslotpos=tagslotpos%(max_slotpos+1); |
| | |
| | | }else{ |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | if(flag_rxon) |
| | | {dwt_rxenable(0); |
| | | { |
| | | dwt_rxenable(0); |
| | | #ifdef DBGMSG_OUTPUT |
| | | dbgmsg_len = sprintf(dbgmsg,"%s status_reg:%x",__debug_info__,status_reg); |
| | | SendDbgMsg(dbgmsg,dbgmsg_len); |
| | | #endif |
| | | } |
| | | } |
| | | } |
| | |
| | | // temp_adc=Get_ADC_Value(); |
| | | // random_value=random_value|((temp_adc&0x01)<<i); |
| | | // } |
| | | pollsendtimer+=time32_incr%11; |
| | | tagslotpos=GetRandomSlotPos(rec_tagpos_binary|tagpos_binary); |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | tag_state=NEARPOLL; |
| | | tag_state=NEARPOLL; |
| | | } |
| | | // tyncpoll_time=0; |
| | | next_nearbase_num=0; |
| | |
| | | NearPoll(); |
| | | break; |
| | | } |
| | | |
| | | SetNextPollTime(tyncpoll_time); |
| | | g_start_send_flag = 0; |
| | | GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_RESET); |
| | |
| | | motorstate =0; |
| | | } |
| | | } |
| | | tx_nearresp_msg[GROUP_ID_IDX] = group_id; |
| | | tx_nearresp_msg[GROUP_ID_IDX] = group_id; |
| | | tx_nearresp_msg[MAINBASE_INDEX]=flag_syncbase; |
| | | tx_nearresp_msg[MESSAGE_TYPE_IDX]=NEAR_RESPONSE; |
| | | tx_nearresp_msg[MOTORSTATE_INDEX]=motorstate;//(remotesend_state<<4)|motorstate; |
| | |
| | | result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//å»¶è¿åéï¼çå¾
æ¥æ¶ |
| | | |
| | | |
| | | if(result==0) |
| | | if(result==DWT_SUCCESS) |
| | | { |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))&&!g_start_sync_flag)///䏿æ¥è¯¢è¯çç¶æç´å°æ¥æ¶æåæè
åºç°é误 |
| | | { }; |
| | | }else{ |
| | | result++; |
| | | #ifdef DBGMSG_OUTPUT |
| | | dbgmsg_len = sprintf(dbgmsg,"%s status_reg:%x",__debug_info__,status_reg); |
| | | SendDbgMsg(dbgmsg,dbgmsg_len); |
| | | #endif |
| | | } |
| | | |
| | | if (status_reg & SYS_STATUS_RXFCG)//æ¥æ¶æå |
| | |
| | | } |
| | | }else{ |
| | | //printf("%x/n",status_reg); |
| | | #ifdef DBGMSG_OUTPUT |
| | | dbgmsg_len = sprintf(dbgmsg,"%s status_reg:%x",__debug_info__,status_reg); |
| | | SendDbgMsg(dbgmsg,dbgmsg_len); |
| | | #endif |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | } |
| | |
| | | |
| | | break; |
| | | } |
| | | }else{ |
| | | } |
| | | }else{ |
| | | #ifdef DBGMSG_OUTPUT |
| | | if(status_reg&SYS_STATUS_ALL_RX_ERR) |
| | | { dbgmsg_len = sprintf(dbgmsg,"%s status_reg:%x",__debug_info__,status_reg); |
| | | SendDbgMsg(dbgmsg,dbgmsg_len); |
| | | } |
| | | #endif |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | } |
| | | } |
| | | |