From 95f736655c46ec4974e89c7f0ca6a542cdbf3532 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期二, 26 四月 2022 17:15:25 +0800 Subject: [PATCH] V1.73 --- 源码/核心板/Src/application/dw_app.c | 104 +++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 74 insertions(+), 30 deletions(-) diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" index 3245d47..5f50042 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" @@ -1,6 +1,12 @@ #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, @@ -43,14 +49,14 @@ 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]; @@ -318,7 +324,7 @@ 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; @@ -384,7 +390,14 @@ 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; } } @@ -393,15 +406,17 @@ }; 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; @@ -424,22 +439,22 @@ 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); @@ -533,6 +548,7 @@ if(temp_dist!=0x1ffff ) { #ifdef USART_SINGLE_OUTPUT + usart_send[2] = 1;//正常模式 usart_send[3] = 29;//数据段长度 usart_send[4] = frame_seq_nb;//数据段长度 @@ -560,7 +576,15 @@ }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 + } } } } @@ -584,9 +608,10 @@ // 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; @@ -742,7 +767,6 @@ NearPoll(); break; } - SetNextPollTime(tyncpoll_time); g_start_send_flag = 0; GPIO_WriteBit(GPIOA, GPIO_Pin_10, Bit_RESET); @@ -923,7 +947,7 @@ 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; @@ -944,12 +968,18 @@ 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)//接收成功 @@ -1035,6 +1065,7 @@ g_Tagdist[taglist_pos]= 0x2ffff; } #ifdef USART_SINGLE_OUTPUT + usart_send[2] = 1;//正常模式 usart_send[3] = 29;//数据段长度 usart_send[4] = frame_seq_nb2;//数据段长度 @@ -1066,6 +1097,13 @@ } }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); } } @@ -1096,7 +1134,7 @@ { 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; @@ -1222,9 +1260,15 @@ 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); } -} } -- Gitblit v1.9.3