将气压传感器(HP203B)的温度作为备用温度,添加了温度与气压传感器错误日志

This commit is contained in:
95384 2024-11-23 12:05:21 +08:00
parent 9d53c5dae7
commit e96230cbd3
9 changed files with 2847 additions and 35 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
EWARM/micro_climate/
EWARM/REMOTE_UPDATE/
EWARM/settings/
frt_protocol.c
软件框架图.vsdx
软件流程图.vsdx
赛联-微气象传感器软件设计说明书.docx

View File

@ -125,8 +125,8 @@ extern mcs_para g_stMcs_Para;
typedef struct _error_log{
uint16_t tof_error_NS:1; /* 接受南北信号tofytofx<0很小 */
uint16_t tof_error_WE:1; /* 接受东西信号tofytofx<0很小 */
uint16_t error_2:1; /* 保留 */
uint16_t error_3:1; /* 保留 */
uint16_t temp_error_SHT30:1; /* SHT30错误日志温湿度 */
uint16_t temp_error_HP203B:1; /* HP203B错误日志大气压 */
uint16_t error_4:1; /* 保留 */
uint16_t error_5:1; /* 保留 */
uint16_t error_6:1; /* 保留 */

View File

@ -858,26 +858,50 @@ void tem_hum_update_task(void const * argument)
int time_s_temp_humi = 0;
uint32_t time_s_1Day = 0;
float backupTemperature;
get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity);//开机先采集一次
while(1)
{
osDelay(1000);
time_s_temp_humi ++;
time_s_1Day ++;
if (time_s_temp_humi >= g_stConfigInfo.temp_hum_update_time)
// 温湿度大气压更新
if (time_s_temp_humi >= 1/*g_stConfigInfo.temp_hum_update_time*/)
{
get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity);
// 采集HP203B传感器数据大气压
if(get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure) == FALSE)
{
g_error_log.temp_error_HP203B = 1;
/// 错误处理
}
else
{
// 没出问题清除错误日志
g_error_log.temp_error_HP203B = 0;
}
// 采集SHT30传感器数据温湿度
if(get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity) == FALSE)
{
g_error_log.temp_error_SHT30 = 1;
/// 错误处理
g_stMcs_Para.temperature = backupTemperature;
}
else
{
// 没出问题清除错误日志
g_error_log.temp_error_SHT30 = 0;
}
// 计时重置
time_s_temp_humi = 0;
}
// 一天重启
if (time_s_1Day >= 86400)
{
__iar_builtin_set_FAULTMASK(1);
NVIC_SystemReset();
}
// 风速风向更新
my_update_mcs_param(av_speed, av_angle);
//采集HP203B数据(大气压)
get_press_data();
}
}

View File

@ -3,7 +3,6 @@
#include "filter.h"
#include "anemometer_dev.h"
/****************************
*set_mode
*
@ -22,10 +21,10 @@ void hp203_set_mode()
/****************************
*Hp203bReadPressure
*
*Press--
*
*
*
*
*
*****************************/
float Hp203bReadPressure(void)
{
@ -48,36 +47,95 @@ float Hp203bReadPressure(void)
return ret;
}
/****************************
*Hp203bReadTempture
*
*
*
*
*
*****************************/
float Hp203bReadTempture(void)
{
float ret = 0.0;
long Hp203b_tempture = 0;
uint8_t Hp203bPressure_Temp[3] = {0};
uint8_t read_command[1] = {0x32};
HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff);
HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff);
Hp203b_tempture = Hp203bPressure_Temp[0];
Hp203b_tempture <<= 8;
Hp203b_tempture |= Hp203bPressure_Temp[1];
Hp203b_tempture <<= 8;
Hp203b_tempture |= Hp203bPressure_Temp[2];
Hp203b_tempture = Hp203b_tempture / 100;
ret = Hp203b_tempture;
return ret;
}
/****************************
*get_press_data
*
*
*Press--
*
*
*
*****************************/
#define COLLECT_PRESS_DATA_NUM 10
BOOL get_press_data(void)
#define COLLECT_HB203_DATA_NUM 10
BOOL get_HP203_data(float* tempdata, float* press)
{
U_DataType collect_pressure[30]={0x00};
// 压强
U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00};
for(int i=0; i<COLLECT_PRESS_DATA_NUM; i++){
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
collect_pressure[i].fValue = Hp203bReadPressure();
osDelay(1);
}
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_PRESS_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
if(tmp_press.fValue < 300)
{
tmp_press.fValue = 300;
return FALSE;
// return FALSE;
goto error_return;
}
if(tmp_press.fValue > 1200)
{
tmp_press.fValue = 1200;
return FALSE;
// return FALSE;
goto error_return;
}
// 温度
U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00};
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
collect_tempture[i].fValue = Hp203bReadTempture();
osDelay(1);
}
g_stMcs_Para.pressure = tmp_press.fValue;
U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
if(tmp_tempture.fValue < -40)
{
tmp_tempture.fValue = -40;
// return FALSE;
goto error_return;
}
if(tmp_tempture.fValue > 85)
{
tmp_tempture.fValue = 85;
// return FALSE;
goto error_return;
}
*tempdata = tmp_tempture.fValue;
*press = tmp_press.fValue;
return TRUE;
error_return:
*tempdata = 0;
*press = 0;
return FALSE;
}

View File

@ -25,9 +25,7 @@ extern "C" {
#define HP20X_CONVERT_OSR1024 0x48
void hp203_set_mode();
float Hp203bReadPressure(void);
BOOL get_press_data(void);
BOOL get_HP203_data(float* tempdata, float* press);
#ifdef __cplusplus
}

View File

@ -127,15 +127,16 @@ u_int8_t sht30_collect_data(stTempHumiSensor stSensorDev, float *temp, float *hu
#define COLLECT_DATA_NUM 10
BOOL get_temp_humi_data(float* temdata, float* humidata)
{
U_DataType collect_temdata[30]={0x00};
U_DataType collect_humidata[30]={0x00};
U_DataType collect_temdata[COLLECT_DATA_NUM]={0x00};
U_DataType collect_humidata[COLLECT_DATA_NUM]={0x00};
U_DataType tmp_temdata,tmp_humidata;
for(int i=0; i<COLLECT_DATA_NUM; i++){
int ret = sht30_collect_data(g_stTempHumiSensor,&collect_temdata[i].fValue, &collect_humidata[i].fValue);
// AssertError(ret == HAL_OK, return FALSE, "sht30²ÉÑùʧ°Ü");
if(ret == HAL_ERROR)
return FALSE;
// return FALSE;
goto error_return;
osDelay(1);
}
@ -149,25 +150,29 @@ BOOL get_temp_humi_data(float* temdata, float* humidata)
{
tmp_temdata.fValue = -40;
// term_printf("sht30ζÈֵУÑéʧ°Ü");
return FALSE;
// return FALSE;
goto error_return;
}
if(tmp_temdata.fValue > 125)
{
tmp_temdata.fValue = 125;
// term_printf("sht30ζÈֵУÑéʧ°Ü");
return FALSE;
// return FALSE;
goto error_return;
}
if(tmp_humidata.fValue < 0)
{
tmp_humidata.fValue = 0;
// term_printf("sht30ʪ¶ÈֵУÑéʧ°Ü");
return FALSE;
// return FALSE;
goto error_return;
}
if(tmp_humidata.fValue > 100)
{
tmp_humidata.fValue = 100;
// term_printf("sht3ʪ¶ÈֵУÑéʧ°Ü");
return FALSE;
// return FALSE;
goto error_return;
}
*temdata = tmp_temdata.fValue;
@ -176,6 +181,11 @@ BOOL get_temp_humi_data(float* temdata, float* humidata)
//g_stTempHumiData.temp = tmp_temdata.fValue;
//g_stTempHumiData.humi = tmp_humidata.fValue;
return TRUE;
error_return:
*temdata = 0;
*humidata = 0;
return FALSE;
}
#if 0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -49,8 +49,8 @@
| :-: | :------------------: |
| 0 | 南北方向探头遮挡 |
| 1 | 东西方向探头遮挡 |
| 1 | |
| 3 | |
| 1 | SHT30报错温湿度传感器 |
| 3 | HP203B报错大气压传感器 |
| 4 | |
| 5 | |
| 6 | |