From bcd3024235d04c926f8a915500927232435137a7 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期日, 23 一月 2022 13:07:59 +0800 Subject: [PATCH] 增加modbus功能,待测试 --- 源码/核心板/Src/application/dw_app.c | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 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 7c3db08..bd9931b 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,5 +1,6 @@ #include "dw_app.h" #include "ADC.h" +#include "modbus.h" #define TDFILTER enum enumtagstate { @@ -842,6 +843,26 @@ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); } } + double firstpath_power, rx_power,rec_firstpath_power; + double f1, f2, r1, r2; +uint16_t F1,F2,F3,N,C; +double B = 131072; +double A = 121.74; +double min_power; + dwt_rxdiag_t d1; +double LOS(dwt_rxdiag_t *dia) { + F1 = dia->firstPathAmp1; + F2 = dia->firstPathAmp2; + F3 = dia->firstPathAmp3; + N = dia->rxPreamCount; + C = dia->maxGrowthCIR; + + firstpath_power=10* log10((F1*F1+F2*F2+F3*F3)/(N*N))-A; + rx_power=10*log10(C*B/(N*N))-A; + + // min_power = - 10 * log10((F1 *F1 + F2 * F2 + F3 * F3) / (C *B)); + return min_power; + } u16 smallcar_idlist[10]={0x4052,0x4032,0x4055,0x4034,0x4016,0x4010,0x4036,0x4027,0x4024,0x4047}; extern u16 dist_threshold; u8 misdist_num[TAG_NUM_IN_SYS],seize_anchor,getrange_success=0; @@ -940,7 +961,9 @@ tof = tof_dtu * DWT_TIME_UNITS; distance = tof * SPEED_OF_LIGHT;//距离=光速*飞行时间 dist_no_bias = distance - dwt_getrangebias(config.chan, (float)distance, config.prf); //距离减去矫正系数 - dist_cm = dist_no_bias * 1000; //dis 为单位为cm的距离 + dist_cm = dist_no_bias * 1000; //dis 为单位为cm的距离 + dwt_readdiagnostics(&d1); + LOS(&d1); /*--------------------------以下为非测距逻辑------------------------*/ //dist_cm=33000; getrange_success = 1; @@ -991,6 +1014,8 @@ memcpy(&usart_send[9],&tagdist_list[taglist_pos],4); usart_send[13] = battary; usart_send[14] = button; + usart_send[15] = firstpath_power; + usart_send[16] = rx_power; checksum = Checksum_u16(&usart_send[2],17); memcpy(&usart_send[19],&checksum,2); UART_PushFrame(usart_send,21); @@ -999,6 +1024,9 @@ memcpy(&usart_send_anc[6+6*anc_report_num],&tagdist_list[taglist_pos],4); anc_report_num++; #endif + Modbus_HoldReg[taglist_pos*4] = tag_id_recv; + Modbus_HoldReg[taglist_pos*4+1] = button<<8|battary; + memcpy(&Modbus_HoldReg[taglist_pos*4+2],&tagdist_list[taglist_pos],4); }else{ // printf("%d",hex_dist); misdist_num[taglist_pos]++; -- Gitblit v1.9.3