From 2e872c0c712d5ea0cb9eccb84291fba9c39265a8 Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期二, 30 五月 2023 12:47:30 +0800 Subject: [PATCH] 1 --- Src/application/dw_app.c | 149 ++++++++++++++++++++++++++++++------------------- 1 files changed, 91 insertions(+), 58 deletions(-) diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c index 92e8358..9f0b150 100644 --- a/Src/application/dw_app.c +++ b/Src/application/dw_app.c @@ -29,7 +29,7 @@ #include <stdio.h> #include "beep.h" #include "modbus.h" - +#include "CRC.h" /*------------------------------------ Marcos ------------------------------------------*/ /* Inter-ranging delay period, in milliseconds. */ #define RNG_DELAY_MS 100 @@ -471,7 +471,7 @@ u8 nearbase_num=0,last_nearbase_num,next_nearbase_num,last_slotnum, para_update,para_len,stationary_flag=0; u32 rec_tagpos_binary; int16_t offset=4700,temptimer; -u8 motor_state,rec_remotepara_state,rec_remotepara[80]; +static u8 motor_state,rec_remotepara_state,rec_remotepara[80]; #define SINGLEPOLL_BASENUM 5 @@ -648,9 +648,9 @@ temptime = (slotpos_intoatl*SLOTTIME_MS+100)*100; if(anchor_time<temptime-5000) { - current_slotnum = pd_i; + current_slotnum = pd_i; delaytime = temptime-anchor_time+poll_offsettime+clockoffset; - expect_anctime = temptime; + expect_anctime = temptime; return ; } } @@ -668,14 +668,14 @@ NextPollDelay(anchor_time); current_count=HAL_LPTIM_ReadCounter(&hlptim1); lpcount = current_count+delaytime/LPTIMER_LSB+(10-nearbase_num)*8; - poll_startcount = lpcount+(waketopolltimeus)/LPTIMER_LSB; + poll_startcount = lpcount+(waketopolltimeus)/LPTIMER_LSB; if(poll_startcount>=32768) { - poll_startcount -=32768; + poll_startcount -=32768; } if(lpcount>=32768) { - lpcount -=32768; + lpcount -=32768; } __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); last_lpcount = lpcount; @@ -691,11 +691,11 @@ }else{ lpcount = last_lpcount+31457/tag_frequency+32.767*delayms;//(float)(200/tag_frequency*48+delayms*10)*3.3 ; } - if(lpcount>=32768) - { - lpcount -=32768; - } - poll_startcount = lpcount+(waketopolltimeus)/LPTIMER_LSB; + if(lpcount>=32768) + { + lpcount -=32768; + } + poll_startcount = lpcount+(waketopolltimeus)/LPTIMER_LSB; if(poll_startcount>=32768) { poll_startcount -=32768; @@ -763,6 +763,8 @@ tagpoll_sync_sec = current_slotpos/200; tagslotpos = current_slotpos%200; max_slotpos = rec_tagperiod*20; + tag_frequency = 10/rec_tagperiod; + bigslot_num = TOTAL_SLOTNUM/tag_frequency; tag_state=NEARPOLL; } }else{ @@ -800,7 +802,7 @@ uint16_t rec_ancpos; uint8_t dist_noutenough_count; uint8_t ancdist_hist[11]; - +uint16_t calCRC; void NearPoll(void) { @@ -825,13 +827,31 @@ recbase_num=0; // motor_state=0; - if(motor_state!=0&&motor_state!=3) - { - motor_flag = 1; - }else{ - motor_flag = 0; - } - + +// for(uint8_t i=0;i<nearbase_num+1;i++) +// { +// usart_send[0] = 0x55; +// usart_send[1] = 0xaa; +// usart_send[2] = 1;//正常模式 +// usart_send[3] = 17;//数据段长度 +// usart_send[4] = frame_seq_nb;//数据段长度 +// memcpy(&usart_send[5],&dev_id,2); +// if(i==0) +// { +// memcpy(&usart_send[7],&mainbase_id,2); +// }else{ +// memcpy(&usart_send[7],&nearbaseid_list[i-1],2); +// } +// memcpy(&usart_send[9],&nearbase_distlist[i],4); +// usart_send[13] = battary; +// usart_send[14] = button; +// usart_send[15] = rec_anc_signalpower[i]>>8; +// usart_send[16] = rec_anc_signalpower[i]; +// checksum = Checksum_u16(&usart_send[2],17); +// memcpy(&usart_send[19],&checksum,2); +// +// USART_puts(usart_send,21); +// } tx_near_msg[BATTARY_IDX] = bat_percent; tx_near_msg[BUTTON_IDX] = userkey_state|stationary_flag<<1|gotosleep_flag<<2|motor_flag<<5; tx_near_msg[SEQUENCE_IDX] = frame_seq_nb; @@ -841,7 +861,7 @@ memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*2],&nearbase_distlist,nearbase_num*4+4); memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*6+4],&rec_anc_signalpower,nearbase_num*2+2); - + userkey_state = 0; if(intheight!=0) intheight+=g_com_map[HEIGHTOFFEST_INDEX]; @@ -855,7 +875,7 @@ memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); dwt_writetxdata(29+8*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 dwt_writetxfctrl(29+8*nearbase_num, 0);//设置超宽带发送数据长度 - current_count=HAL_LPTIM_ReadCounter(&hlptim1); + current_count=HAL_LPTIM_ReadCounter(&hlptim1); while(current_count<poll_startcount||current_count>poll_startcount+16384) { @@ -958,7 +978,7 @@ dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度 dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 - userkey_state = !GET_USERKEY; + // userkey_state = !GET_USERKEY; memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); if(temp_dist!=nearbase_distlist[0]) @@ -968,8 +988,7 @@ mainbase_dist=temp_dist; nearbase_distlist[0] = temp_dist; base_mindist = temp_dist; - if((rx_buffer[MOTORSTATE_INDEX]&0xf)!=3) - motor_state=rx_buffer[MOTORSTATE_INDEX]&0xf; + if(frame_len==28) { memcpy(&rec_maxrangelen,&rx_buffer[MAXRANGE_DISTANCE],2); @@ -1090,37 +1109,41 @@ } if(mainbase_lost_count!=0) { -// if(mainbase_lost_count<=tag_frequency*1) -// {NextSlotDelayMs(0); -// }else{ -// NextSlotDelayMs(0); -// } + if(mainbase_lost_count<=tag_frequency*1) + {NextSlotDelayMs(0); + }else{ + NextSlotDelayMs(0); + } } if(para_update) - { - - pack_msgtype = rec_remotepara[0]; - pack_index = rec_remotepara[1]; - pack_length = rec_remotepara[2]; - if(pack_msgtype==2) - { - if( pack_index == MOTOR_ONTIME_INDEX) - { - // if(motor_keeptime==0) - motor_keeptime = rec_remotepara[3]; - }else{ - if(pack_index<200) + { + + calCRC = CRC_Compute(rec_remotepara,5); + if(memcmp(&calCRC,&rec_remotepara[5],2)==0) + { + pack_msgtype = rec_remotepara[0]; + pack_index = rec_remotepara[1]; + pack_length = rec_remotepara[2]; + if(pack_msgtype==2) + { + if( pack_index == MOTOR_ONTIME_INDEX) { - memcpy((uint8_t*)&g_com_map + pack_index, &rec_remotepara[3], pack_length); - //返回一个error状态 - //SendComMap(pack_datalen,pack_index); - save_com_map_to_flash(); - delay_ms(100); - NVIC_SystemReset(); + // if(motor_keeptime==0) + motor_keeptime = rec_remotepara[3]; + }else{ + if(pack_index<200) + { + memcpy((uint8_t*)&g_com_map + pack_index, &rec_remotepara[3], pack_length); + //返回一个error状态 + //SendComMap(pack_datalen,pack_index); + save_com_map_to_flash(); + delay_ms(100); + NVIC_SystemReset(); + } } - } - } + } + } } if(get_newdist>=2) { @@ -1146,6 +1169,7 @@ GetNearMsg(); } } + if(pos_nochange) { flag_tagnewpos = 0; @@ -1161,7 +1185,7 @@ { static u8 regpoll_count=0; mainbase_lost_count = 0; - tag_frequency = REGISTER_FREQUENCY; + //tag_frequency = REGISTER_FREQUENCY; bigslot_num = TOTAL_SLOTNUM/tag_frequency; regpoll_count++; if(regpoll_count%2) @@ -1229,17 +1253,17 @@ } } } +extern void FZNearPoll(void); u32 id,error_times=0; - +u8 ttt = 1; extern float Height; -void Tag_App(void)//发送模式(TAG标签) +void UWBWkWp(void) { - static uint8_t diccount = 0; - //LED0_ON; SPIx_CS_GPIO->BRR = SPIx_CS; delay_us(700); SPIx_CS_GPIO->BSRR = SPIx_CS; id = dwt_readdevid() ; + while (DWT_DEVICE_ID != id) { // Dw1000_Init(); @@ -1252,6 +1276,13 @@ } } error_times = 0; +} + +void Tag_App(void)//发送模式(TAG标签) +{ + static uint8_t diccount = 0,diccount2; + //LED0_ON; + UWBWkWp(); switch(tag_state) { case REGPOLL: @@ -1295,7 +1326,9 @@ case SINGLEPOLL: // Poll(); break; - } - userkey_state = !GET_USERKEY; + } + FZNearPoll(); + dwt_forcetrxoff(); +// userkey_state = !GET_USERKEY; dwt_entersleep(); } -- Gitblit v1.9.3