添加了探头有遮挡时的数据处理,协议中添加了错误日志,优化了协议解析时处理收到的错误数据的逻辑
This commit is contained in:
parent
7148a72c16
commit
ca14efe43d
|
@ -115,6 +115,26 @@ typedef struct _mcs_para{
|
|||
float32_t precipitation_intensity;/* 光辐射 */
|
||||
}mcs_para;
|
||||
extern mcs_para g_stMcs_Para;
|
||||
|
||||
typedef struct _error_log{
|
||||
uint16_t tof_error_NS:1; /* 接受南北信号(tofy,tofx<0)很小 */
|
||||
uint16_t tof_error_WE:1; /* 接受东西信号(tofy,tofx<0)很小 */
|
||||
uint16_t error_2:1; /* 保留 */
|
||||
uint16_t error_3:1; /* 保留 */
|
||||
uint16_t error_4:1; /* 保留 */
|
||||
uint16_t error_5:1; /* 保留 */
|
||||
uint16_t error_6:1; /* 保留 */
|
||||
uint16_t error_7:1; /* 保留 */
|
||||
uint16_t error_8:1; /* 保留 */
|
||||
uint16_t error_9:1; /* 保留 */
|
||||
uint16_t error_10:1; /* 保留 */
|
||||
uint16_t error_11:1; /* 保留 */
|
||||
uint16_t error_12:1; /* 保留 */
|
||||
uint16_t error_13:1; /* 保留 */
|
||||
uint16_t error_14:1; /* 保留 */
|
||||
uint16_t error_15:1; /* 保留 */
|
||||
}error_log;
|
||||
extern error_log g_error_log;
|
||||
#pragma pack(pop)
|
||||
|
||||
// 切换通道
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef enum
|
|||
FRT_REGISTER_TRANSDUCER_CFG_8R0 = 32, /* 换能器参数 */
|
||||
FRT_REGISTER_RSSI_RANGE = 33, /* RSSI有效范围 */
|
||||
FRT_REGISTER_WAVE_DATA = 34, /* 波形数据 */
|
||||
FRT_REGISTER_ERROR_LOG = 35, /* 错误日志 */
|
||||
}FRT_MsgRegister;
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "FIR.h"
|
||||
|
||||
#define AVE_TIME 600 //滑动平均时间,秒,最大600
|
||||
#define COVER_TINE 10 //探头遮挡后导致的接收次数过小的报错临界次数
|
||||
|
||||
uint32_t run_time_us;
|
||||
|
||||
|
@ -40,7 +41,7 @@ float32_t av_speedy=0;
|
|||
|
||||
Weather_param weather_info={0x00};
|
||||
mcs_para g_stMcs_Para={0x00};
|
||||
|
||||
error_log g_error_log={0x00};
|
||||
|
||||
|
||||
|
||||
|
@ -363,8 +364,10 @@ char str[100];
|
|||
|
||||
void wind_task(void const * argument)
|
||||
{
|
||||
|
||||
int flag_init_msc_value = 1;
|
||||
//错误次数统计,南北,东西分开(接受信号很小)
|
||||
uint8_t tof_error_log_NS = 0;
|
||||
uint8_t tof_error_log_WE = 0;
|
||||
// int flag_init_msc_value = 1;
|
||||
|
||||
arm_rfft_fast_init_f32(&s,FFT_DATA_LEN);
|
||||
firFilterInit();
|
||||
|
@ -403,26 +406,38 @@ void wind_task(void const * argument)
|
|||
// 接受信号很小
|
||||
if(tofx<0||tofy<0)
|
||||
{
|
||||
tof_error_log_NS ++;
|
||||
// 放弃本次采样,可以有效筛选雨滴等导致的异常大的风速数据
|
||||
// 但是持续的遮挡会导致风速数据保持不变。
|
||||
continue;
|
||||
|
||||
// 连续10次采样有问题判定为有遮挡,置错误标志位,将声速与风速分量置0
|
||||
if(tof_error_log_NS >= COVER_TINE)
|
||||
{
|
||||
g_error_log.tof_error_NS = 1;
|
||||
|
||||
weather_info.wind_c = 0;
|
||||
weather_info.wind_velocity_x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// 手动设置渡越时间差为0,会在探头受遮挡的时候输出0,持续遮挡的时候也输出0,但是计算出声速将变得很大
|
||||
// tofx = tofx/ADC_SAMP_RATE_MHz+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.0001f;
|
||||
// tofy = tofy/ADC_SAMP_RATE_MHz+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.0001f;
|
||||
// dtof = 0;
|
||||
}else{
|
||||
// 遮挡没有之后数据正常,将标志位取消,错误计数置零
|
||||
tof_error_log_NS = 0;
|
||||
g_error_log.tof_error_NS = 0;
|
||||
// 计算成us
|
||||
tofx = ((tofx-FIR_PHASE_DELAY)/ADC_SAMP_RATE_MHz)+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.0001f;
|
||||
tofy = ((tofy-FIR_PHASE_DELAY)/ADC_SAMP_RATE_MHz)+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.0001f;
|
||||
|
||||
// 通过各通道渡越时间求时间差
|
||||
dtof = tofx-tofy;
|
||||
|
||||
weather_info.wind_c = DISTANCE/2.0f*(1.0f/tofx+1.0f/tofy);
|
||||
weather_info.wind_velocity_x = 0-DISTANCE*dtof/1.41422f/tofx/tofx;
|
||||
}
|
||||
weather_info.wind_c = DISTANCE/2.0f*(1.0f/tofx+1.0f/tofy);
|
||||
weather_info.wind_velocity_x = 0-DISTANCE*dtof/1.41422f/tofx/tofx;
|
||||
|
||||
// 通道3 通道4 测试东西风速
|
||||
// 通道3发送 通道4接收
|
||||
|
@ -447,12 +462,21 @@ void wind_task(void const * argument)
|
|||
// 如果测量的信号幅值过小。
|
||||
if(tofx<0||tofy<0)
|
||||
{
|
||||
tof_error_log_WE ++;
|
||||
// 放弃本次采样,可以有效筛选雨滴等导致的异常大的风速数据
|
||||
// 但是持续的遮挡会导致风速数据保持不变。
|
||||
// 连续10次采样有问题判定为有遮挡,置错误标志位,将声速与风速分量置0
|
||||
if(tof_error_log_WE >= COVER_TINE)
|
||||
{
|
||||
g_error_log.tof_error_WE = 1;
|
||||
|
||||
continue;
|
||||
|
||||
|
||||
weather_info.wind_c = 0;
|
||||
weather_info.wind_velocity_y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// 手动设置渡越时间差为0,会在探头受遮挡的时候输出0,持续遮挡的时候也输出0,但是计算出声速将变得很大
|
||||
// tofx = tofx/ADC_SAMP_RATE_MHz+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.0001f;
|
||||
// tofy = tofy/ADC_SAMP_RATE_MHz+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.0001f;
|
||||
|
@ -460,17 +484,19 @@ void wind_task(void const * argument)
|
|||
// dtof = 0;
|
||||
|
||||
}else{
|
||||
// 遮挡没有之后数据正常,将标志位取消,错误计数置零
|
||||
tof_error_log_WE = 0;
|
||||
g_error_log.tof_error_WE = 0;
|
||||
// 计算成us
|
||||
tofx = ((tofx-FIR_PHASE_DELAY)/ADC_SAMP_RATE_MHz)+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.000001f;
|
||||
tofy = ((tofy-FIR_PHASE_DELAY)/ADC_SAMP_RATE_MHz)+REV_MUTE_DELAY_US-1.0f/DRIVE_FREQ_MHz+0.000001f;
|
||||
// 通过各通道渡越时间求时间差
|
||||
dtof = tofx-tofy;
|
||||
|
||||
weather_info.wind_c = DISTANCE/2.0f*(1.0f/tofx+1.0f/tofy);
|
||||
weather_info.wind_velocity_y = DISTANCE*dtof/1.41422f/tofx/tofx;
|
||||
}
|
||||
|
||||
|
||||
weather_info.wind_c = DISTANCE/2.0f*(1.0f/tofx+1.0f/tofy);
|
||||
weather_info.wind_velocity_y = DISTANCE*dtof/1.41422f/tofx/tofx;
|
||||
|
||||
weather_info.wind_velocity = sqrtf(weather_info.wind_velocity_x*weather_info.wind_velocity_x + weather_info.wind_velocity_y*weather_info.wind_velocity_y);
|
||||
// 分母加0.0001 保证分母不为0
|
||||
weather_info.wind_angle = acosf(weather_info.wind_velocity_x/(weather_info.wind_velocity+0.000001f));
|
||||
|
|
|
@ -14,6 +14,7 @@ static void send_uart_pack(device_handle device,FRT_MsgFunctionCode_e cmd_type,
|
|||
static void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg);
|
||||
static void FRT_MsgProc_WriteRegister(device_handle device, void *pMsg);
|
||||
static u_int16_t FRT_ReadReg(unsigned char regId);
|
||||
/* 读 */
|
||||
static u_int16_t FRT_ReadRegMinWindDiretion(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegAverageWindDirection(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegMaxWindDirection(void *pMsg);
|
||||
|
@ -24,27 +25,28 @@ static u_int16_t FRT_ReadRegTemperature(void *pMsg);
|
|||
static u_int16_t FRT_ReadRegHumidity(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegPressure(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegRain(void *pMsg);
|
||||
|
||||
/* 读 */
|
||||
static u_int16_t FRT_ReadRegPrecipitationIntensity(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegDeviceAddr(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegCommuBaudRate(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegSpeedAverageTime(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegTempHumUpdateTime(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegRainPowerCtl(void *pMsg);
|
||||
|
||||
/* 写 */
|
||||
static u_int16_t FRT_WriteRegDeviceAddr(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegCommuBaudRate(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegSpeedAverageTime(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegTempHumUpdateTime(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegSoftReset(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegResetDefault(void *pMsg);
|
||||
|
||||
/* 读配置 */
|
||||
static u_int16_t FRT_ReadRegTransducerCFG1R5(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegTransducerCFG4R5(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegTransducerCFG8R0(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegRSSIRange(void *pMsg);
|
||||
static u_int16_t FRT_ReadRegWaveData(void *pMsg);
|
||||
|
||||
static u_int16_t FRT_ReadRegErrorData(void *pMsg);
|
||||
/* 写配置 */
|
||||
static u_int16_t FRT_WriteRegTransducerCFG1R5(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegTransducerCFG4R5(void *pMsg);
|
||||
static u_int16_t FRT_WriteRegTransducerCFG8R0(void *pMsg);
|
||||
|
@ -82,6 +84,7 @@ FRT_RegProcTable_s g_RegTbl[] =
|
|||
{ FRT_REGISTER_TRANSDUCER_CFG_4R5, FRT_ReadRegTransducerCFG4R5 }, /* 读换能器参数寄存器值4R5 */
|
||||
{ FRT_REGISTER_TRANSDUCER_CFG_8R0, FRT_ReadRegTransducerCFG8R0 }, /* 读换能器参数寄存器值8R0 */
|
||||
{ FRT_REGISTER_RSSI_RANGE, FRT_ReadRegRSSIRange }, /* 读RSSI有效范围 */
|
||||
{ FRT_REGISTER_ERROR_LOG, FRT_ReadRegErrorData }, /* 读错误日志 */
|
||||
};
|
||||
|
||||
/* 写寄存器处理表 */
|
||||
|
@ -466,6 +469,16 @@ static u_int16_t FRT_ReadRegRSSIRange(void *pMsg)
|
|||
return FRT_swap_endian_16(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读错误日志
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static u_int16_t FRT_ReadRegErrorData(void *pMsg)
|
||||
{
|
||||
u_int16_t value=*((u_int16_t*)&g_error_log);
|
||||
return FRT_swap_endian_16(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 写换能器参数寄存器值1R5
|
||||
|
@ -612,7 +625,7 @@ void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg)
|
|||
start_reg_addr < 0x00 ||\
|
||||
(start_reg_addr > 0x08 && start_reg_addr < 0x14) ||\
|
||||
(start_reg_addr > 0x17 && start_reg_addr < 0x1E) ||\
|
||||
start_reg_addr > 0x22 \
|
||||
start_reg_addr > 0x23 \
|
||||
)
|
||||
|
||||
{
|
||||
|
@ -624,7 +637,7 @@ void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg)
|
|||
reg_num < 0x01 ||\
|
||||
(((reg_num + start_reg_addr - 1) > 0x08) && ((reg_num + start_reg_addr - 1) < 0x14)) ||\
|
||||
(((reg_num + start_reg_addr -1) > 0x17) && ((reg_num + start_reg_addr -1) < 0x1E)) ||\
|
||||
((reg_num + start_reg_addr -1) > 0x22) \
|
||||
((reg_num + start_reg_addr -1) > 0x23) \
|
||||
)
|
||||
|
||||
{
|
||||
|
@ -759,13 +772,20 @@ static int uart_read_frt_climate_pack(device_handle uart_handle,u_int8_t *buff,
|
|||
// 判断首字符是否是地址,是地址再开始读取,不是则将索引退一步
|
||||
if(offset == sizeof(unsigned char))
|
||||
{
|
||||
if(buff[0] != g_stConfigInfo.addr)
|
||||
if(buff[0] != g_stConfigInfo.addr && buff[0] != 0xFF)
|
||||
{
|
||||
memcpy(buff, buff + 1, offset - 1);
|
||||
offset--;
|
||||
buff_size--;
|
||||
}
|
||||
}
|
||||
// 判断地址对不对,不对缩一位
|
||||
else if(buff[1] != FRT_FUNCTION_CODE_READ_REGISTER && buff[1] != FRT_FUNCTION_CODE_WRITE_REGISTER)
|
||||
{
|
||||
memcpy(buff, buff + 1, offset - 1);
|
||||
offset--;
|
||||
buff_size--;
|
||||
}
|
||||
// 读寄存器
|
||||
else if (buff[1] == FRT_FUNCTION_CODE_READ_REGISTER & offset == 8)
|
||||
{
|
||||
|
|
|
@ -166,7 +166,7 @@ void Flash_EnableReadProtection(void)
|
|||
/* USER CODE BEGIN 2 */
|
||||
init_term_uart();
|
||||
init_rs485_uart();
|
||||
init_ec801_uart();
|
||||
// init_ec801_uart();
|
||||
term_printf("Micro Climate Station Sensor.\r\n");
|
||||
term_printf("Version 1.0.0 Build: %s %s\r\n",__DATE__,__TIME__);
|
||||
HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#define REMOTE_UPDATE // 控制是否远程升级
|
||||
//#define REMOTE_UPDATE // 控制是否远程升级
|
||||
|
||||
#ifdef REMOTE_UPDATE
|
||||
/**
|
||||
|
|
|
@ -701,7 +701,7 @@
|
|||
<data>
|
||||
<extensions></extensions>
|
||||
<cmdline></cmdline>
|
||||
<hasPrio>32</hasPrio>
|
||||
<hasPrio>1</hasPrio>
|
||||
<buildSequence>inputOutputBased</buildSequence>
|
||||
</data>
|
||||
</settings>
|
||||
|
@ -786,7 +786,7 @@
|
|||
</option>
|
||||
<option>
|
||||
<name>IlinkIcfFile</name>
|
||||
<state>$PROJ_DIR$\stm32l496xx_flash_app-1109.icf</state>
|
||||
<state>$PROJ_DIR$\stm32l496xx_flash.icf</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>IlinkIcfFileSlave</name>
|
||||
|
|
25
README.md
25
README.md
|
@ -39,5 +39,28 @@
|
|||
| 30 | 换能器参数1R5 | 2 Byte | 读写:无符号整数; 0-100 |
|
||||
| 31 | 换能器参数4R5 | 2 Byte | 读写:无符号整数; 0-100 |
|
||||
| 32 | 换能器参数8R0 | 2 Byte | 读写:无符号整数; 0-100 |
|
||||
| 33 | RSSI有效范围 | 2 Byte | 读写:无符号整数; 0-100 |
|
||||
| 33 | RSSI有效范围 | 2 Byte | 读:无符号整数; 0-100 |
|
||||
| 34 | | | |
|
||||
| 35 | 错误日志 | 2Byte | 读 |
|
||||
|
||||
错误日志解析:
|
||||
|
||||
| 位 | 备注 |
|
||||
| :-: | :------------------: |
|
||||
| 0 | 南北方向探头遮挡 |
|
||||
| 1 | 东西方向探头遮挡 |
|
||||
| 1 | |
|
||||
| 3 | |
|
||||
| 4 | |
|
||||
| 5 | |
|
||||
| 6 | |
|
||||
| 7 | |
|
||||
| 8 | |
|
||||
| 9 | |
|
||||
| 10 | |
|
||||
| 11 | |
|
||||
| 12 | |
|
||||
| 13 | |
|
||||
| 14 | |
|
||||
| 15 | |
|
||||
|
||||
|
|
Loading…
Reference in New Issue