diff --git a/App/Inc/anemometer_dev.h b/App/Inc/anemometer_dev.h
index 35d9ae3..7039dec 100644
--- a/App/Inc/anemometer_dev.h
+++ b/App/Inc/anemometer_dev.h
@@ -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)
// 切换通道
diff --git a/App/Inc/frt_protocol.h b/App/Inc/frt_protocol.h
index 3edeef9..160fbce 100644
--- a/App/Inc/frt_protocol.h
+++ b/App/Inc/frt_protocol.h
@@ -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)
diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c
index 18416ea..b8b4d87 100644
--- a/App/Src/anemometer_dev.c
+++ b/App/Src/anemometer_dev.c
@@ -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 ++;
// 放弃本次采样,可以有效筛选雨滴等导致的异常大的风速数据
// 但是持续的遮挡会导致风速数据保持不变。
-
- continue;
-
-
+ // 连续10次采样有问题判定为有遮挡,置错误标志位,将声速与风速分量置0
+ if(tof_error_log_WE >= COVER_TINE)
+ {
+ g_error_log.tof_error_WE = 1;
+
+ 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));
diff --git a/App/Src/frt_protocol.c b/App/Src/frt_protocol.c
index a2aecc3..a416689 100644
--- a/App/Src/frt_protocol.c
+++ b/App/Src/frt_protocol.c
@@ -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)
{
diff --git a/Core/Src/main.c b/Core/Src/main.c
index d2d439e..0773111 100644
--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -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);
diff --git a/Core/Src/system_stm32l4xx.c b/Core/Src/system_stm32l4xx.c
index 5162ccc..d067755 100644
--- a/Core/Src/system_stm32l4xx.c
+++ b/Core/Src/system_stm32l4xx.c
@@ -1,4 +1,4 @@
-#define REMOTE_UPDATE // ǷԶ
+//#define REMOTE_UPDATE // ǷԶ
#ifdef REMOTE_UPDATE
/**
diff --git a/EWARM/micro_climate.ewp b/EWARM/micro_climate.ewp
index f1f9fa8..0fff44f 100644
--- a/EWARM/micro_climate.ewp
+++ b/EWARM/micro_climate.ewp
@@ -701,7 +701,7 @@
- 32
+ 1
inputOutputBased
@@ -786,7 +786,7 @@