| | |
| | | #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&&g_com_map[MODBUS_ID1]==1) |
| | | { |
| | | #ifdef DBGMSG_OUTPUT |
| | | dbgmsg_len = sprintf(dbgmsg,"%s status_reg:%x",__debug_info__,status_reg); |
| | | SendDbgMsg(dbgmsg,dbgmsg_len); |
| | | #endif |
| | | } |
| | | break; |
| | | } |
| | | } |
| | |
| | | }; |
| | | if(status_reg==0xffffffff) |
| | | { |
| | | NVIC_SystemReset(); |
| | | //NVIC_SystemReset(); |
| | | } |
| | | if (status_reg & SYS_STATUS_RXFCG)//妿æåæ¥æ¶ |
| | | { |
| | | rflosttimer = 0; |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//æ¸
æ¥å¯å卿 å¿ä½ |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK; //è·å¾æ¥æ¶å°çæ°æ®é¿åº¦ |
| | | dwt_readrxdata(rx_buffer, frame_len, 0); //è¯»åæ¥æ¶æ°æ® |
| | | dwt_setrxtimeout(0);//DELAY_BETWEEN_TWO_FRAME_UUS*(nearbase_num+1-recbase_num)+10);//è®¾å®æ¥æ¶è¶
æ¶æ¶é´ï¼0使²¡æè¶
æ¶æ¶é´ |
| | | dwt_rxenable(0);//æå¼æ¥æ¶ |
| | | rflosttimer = 0; |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == NEAR_RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,2)&&rx_buffer[GROUP_ID_IDX] == group_id) //å¤ææ¥æ¶å°çæ°æ®æ¯å¦æ¯responseæ°æ® |
| | | { u16 rec_nearbaseid,rec_nearbasepos; |
| | | int32_t temp_dist; |
| | |
| | | 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); |
| | |
| | | if(temp_dist!=0x1ffff ) |
| | | { |
| | | #ifdef USART_SINGLE_OUTPUT |
| | | |
| | | usart_send[2] = 1;//æ£å¸¸æ¨¡å¼ |
| | | usart_send[3] = 29;//æ°æ®æ®µé¿åº¦ |
| | | usart_send[4] = frame_seq_nb;//æ°æ®æ®µé¿åº¦ |
| | |
| | | }else{ |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | if(flag_rxon) |
| | | {dwt_rxenable(0); |
| | | { |
| | | dwt_rxenable(0); |
| | | if(g_com_map[MODBUS_ID1]==1) |
| | | { |
| | | #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++; |
| | | if(g_com_map[MODBUS_ID1]==1) |
| | | { |
| | | #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)//æ¥æ¶æå |
| | |
| | | g_Tagdist[taglist_pos]= 0x2ffff; |
| | | } |
| | | #ifdef USART_SINGLE_OUTPUT |
| | | |
| | | usart_send[2] = 1;//æ£å¸¸æ¨¡å¼ |
| | | usart_send[3] = 29;//æ°æ®æ®µé¿åº¦ |
| | | usart_send[4] = frame_seq_nb2;//æ°æ®æ®µé¿åº¦ |
| | |
| | | } |
| | | }else{ |
| | | //printf("%x/n",status_reg); |
| | | if(g_com_map[MODBUS_ID1]==1) |
| | | { |
| | | #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); |
| | | } |
| | | } |
| | |
| | | { u16 tag_recv_interval; |
| | | float temp_tagpos; |
| | | |
| | | |
| | | rflosttimer = 0; |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);//æ¸
餿 å¿ä½ |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;//è·å¾æ¥æ¶æ°æ®é¿åº¦ |
| | | recpoll_len = frame_len; |
| | |
| | | |
| | | break; |
| | | } |
| | | }else{ |
| | | } |
| | | }else{ |
| | | #ifdef DBGMSG_OUTPUT |
| | | if((status_reg&SYS_STATUS_ALL_RX_ERR)&&g_com_map[MODBUS_ID1]==1) |
| | | { 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); |
| | | } |
| | | } |
| | | } |
| | | |