Compare commits

..

No commits in common. "7091edb970774a7107fd9fe05510803cb90a0ae8" and "04d3a7085c572b90a1be9327f2ddd46a4c7ef684" have entirely different histories.

5 changed files with 43 additions and 68 deletions

View File

@ -977,22 +977,21 @@ void tem_hum_update_task(void const * argument)
float backupTemperature; float backupTemperature;
// 开机先采集一次大气压温湿度 // 开机先采集一次大气压温湿度
uint8_t hp203_ret = get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure); {
uint8_t sht30_ret = get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity);
// 采集HP203B传感器数据大气压 // 采集HP203B传感器数据大气压
if(hp203_ret == FALSE) if(get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure) == FALSE)
{ {
g_error_log.temp_error_HP203B = 1; g_error_log.temp_error_HP203B = 1;
/// 错误处理 /// 错误处理
} }
// 采集SHT30传感器数据温湿度 // 采集SHT30传感器数据温湿度
if(sht30_ret == FALSE) if(get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity) == FALSE)
{ {
g_error_log.temp_error_SHT30 = 1; g_error_log.temp_error_SHT30 = 1;
/// 错误处理 /// 错误处理
g_stMcs_Para.temperature = backupTemperature; g_stMcs_Para.temperature = backupTemperature;
} }
}
while(1) while(1)
{ {
@ -1002,10 +1001,8 @@ void tem_hum_update_task(void const * argument)
// 温湿度大气压更新 // 温湿度大气压更新
if (time_s_temp_humi >= g_usrConfigInfo.temp_hum_update_time) if (time_s_temp_humi >= g_usrConfigInfo.temp_hum_update_time)
{ {
hp203_ret = get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure);
sht30_ret = get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity);
// 采集HP203B传感器数据大气压 // 采集HP203B传感器数据大气压
if(hp203_ret == FALSE) if(get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure) == FALSE)
{ {
g_error_log.temp_error_HP203B = 1; g_error_log.temp_error_HP203B = 1;
/// 错误处理 /// 错误处理
@ -1016,7 +1013,7 @@ void tem_hum_update_task(void const * argument)
g_error_log.temp_error_HP203B = 0; g_error_log.temp_error_HP203B = 0;
} }
// 采集SHT30传感器数据温湿度 // 采集SHT30传感器数据温湿度
if(sht30_ret == FALSE) if(get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity) == FALSE)
{ {
g_error_log.temp_error_SHT30 = 1; g_error_log.temp_error_SHT30 = 1;
/// 错误处理 /// 错误处理

View File

@ -462,10 +462,6 @@ static u_int16_t FRT_WriteRegDeviceAddr(void *pMsg)
{ {
uint16_t *pMsgAddr = (uint16_t *)pMsg; uint16_t *pMsgAddr = (uint16_t *)pMsg;
uint16_t data = *pMsgAddr; uint16_t data = *pMsgAddr;
if(data > 0xFF || data < 0x00)
{
return 0;
}
g_usrConfigInfo.addr = data; g_usrConfigInfo.addr = data;
save_usr_config_info(g_usrConfigInfo); save_usr_config_info(g_usrConfigInfo);
@ -481,15 +477,9 @@ static u_int16_t FRT_WriteRegCommuBaudRate(void *pMsg)
{ {
uint16_t *pMsgAddr = (uint16_t *)pMsg; uint16_t *pMsgAddr = (uint16_t *)pMsg;
uint16_t data = *pMsgAddr; uint16_t data = *pMsgAddr;
if(data != 2400 && data != 4800 && data != 9600 && data != 19200 && data != 38400)
{
return 0;
}
//存
g_usrConfigInfo.uart_baud = data; g_usrConfigInfo.uart_baud = data;
save_usr_config_info(g_usrConfigInfo); save_usr_config_info(g_usrConfigInfo);
//改
MX_USART3_UART_Init(g_usrConfigInfo.uart_baud); MX_USART3_UART_Init(g_usrConfigInfo.uart_baud);
MX_USART1_UART_Init(g_usrConfigInfo.uart_baud); MX_USART1_UART_Init(g_usrConfigInfo.uart_baud);
@ -505,10 +495,6 @@ static u_int16_t FRT_WriteRegSpeedAverageTime(void *pMsg)
{ {
uint16_t *pMsgAddr = (uint16_t *)pMsg; uint16_t *pMsgAddr = (uint16_t *)pMsg;
uint16_t data = *pMsgAddr; uint16_t data = *pMsgAddr;
if(data > 600 || data < 1)
{
return 0;
}
g_usrConfigInfo.speed_average_time = data; g_usrConfigInfo.speed_average_time = data;
save_usr_config_info(g_usrConfigInfo); save_usr_config_info(g_usrConfigInfo);
@ -525,10 +511,6 @@ static u_int16_t FRT_WriteRegTempHumUpdateTime(void *pMsg)
{ {
uint16_t *pMsgAddr = (uint16_t *)pMsg; uint16_t *pMsgAddr = (uint16_t *)pMsg;
uint16_t data = *pMsgAddr; uint16_t data = *pMsgAddr;
if(data > 600 || data < 1)
{
return 0;
}
g_usrConfigInfo.temp_hum_update_time = data; g_usrConfigInfo.temp_hum_update_time = data;
save_usr_config_info(g_usrConfigInfo); save_usr_config_info(g_usrConfigInfo);
@ -1289,18 +1271,16 @@ void FRT_MsgProc_WriteRegister(device_handle device, void *pMsg)
// } // }
// 发回数据 // 发回数据
uint8_t Trans_data[8]; uint8_t Trans_data[6];
Trans_data[0] = g_usrConfigInfo.addr; Trans_data[0] = g_usrConfigInfo.addr;
Trans_data[1] = data[1]; Trans_data[1] = data[1];
Trans_data[2] = start_reg_addr >> 8; Trans_data[2] = start_reg_addr;
Trans_data[3] = start_reg_addr; Trans_data[3] = reg_num;
Trans_data[4] = reg_num >> 8;
Trans_data[5] = reg_num;
return_crc_value = CRC16(Trans_data, 6); return_crc_value = CRC16(Trans_data, 4);
Trans_data[6] = return_crc_value; Trans_data[4] = return_crc_value;
Trans_data[7] = return_crc_value >> 8; Trans_data[5] = return_crc_value >> 8;
uart_dev_write(device, Trans_data, 8); uart_dev_write(device, Trans_data, 6);
for(u_int16_t pos=0; pos <reg_num; pos++) for(u_int16_t pos=0; pos <reg_num; pos++)
{ {

View File

@ -171,6 +171,7 @@ void Flash_EnableReadProtection(void)
term_printf("Version 1.0.0 Build: %s %s\r\n",__DATE__,__TIME__); term_printf("Version 1.0.0 Build: %s %s\r\n",__DATE__,__TIME__);
HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED); HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED);
sht30_init(); sht30_init();
hp203_set_mode();
/* USER CODE END 2 */ /* USER CODE END 2 */

View File

@ -41,12 +41,10 @@ BOOL Hp203bReadPressure(float *press)
Hp203b_Pressure <<= 8; Hp203b_Pressure <<= 8;
Hp203b_Pressure |= Hp203bPressure_Temp[2]; Hp203b_Pressure |= Hp203bPressure_Temp[2];
*press = (float)Hp203b_Pressure / 100.0f; Hp203b_Pressure = Hp203b_Pressure / 100;
if(*press < 300 || *press > 1200) if(Hp203b_Pressure<300||Hp203b_Pressure>1200)
{
*press = 0;
return FALSE; return FALSE;
} *press = Hp203b_Pressure;
return TRUE; return TRUE;
} }
@ -60,27 +58,21 @@ BOOL Hp203bReadPressure(float *press)
*****************************/ *****************************/
BOOL Hp203bReadTempture(float *press) BOOL Hp203bReadTempture(float *press)
{ {
uint32_t Hp203b_tempture = 0; long Hp203b_tempture = 0;
uint8_t Hp203bPressure_Temp[3] = {0}; uint8_t Hp203bPressure_Temp[3] = {0};
uint8_t read_command[1] = {0x32}; uint8_t read_command[1] = {0x32};
HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff); HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff);
HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff); HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff);
Hp203b_tempture = (Hp203bPressure_Temp[0] & 0x0F)<<16;
Hp203b_tempture |= Hp203bPressure_Temp[1]<<8; Hp203b_tempture = Hp203bPressure_Temp[0];
Hp203b_tempture <<= 8;
Hp203b_tempture |= Hp203bPressure_Temp[1];
Hp203b_tempture <<= 8;
Hp203b_tempture |= Hp203bPressure_Temp[2]; Hp203b_tempture |= Hp203bPressure_Temp[2];
if((Hp203b_tempture>>19) & 1){ Hp203b_tempture = Hp203b_tempture / 100;
Hp203b_tempture = (((~Hp203b_tempture) + 1) & 0xFFFFF); *press = Hp203b_tempture;
*press = -(float)Hp203b_tempture / 100.0f;
}
else{
*press = (float)Hp203b_tempture / 100.0f;
}
if(*press<-50||*press>95){
*press = 0;
return FALSE;
}
return TRUE; return TRUE;
} }
@ -96,20 +88,23 @@ BOOL Hp203bReadTempture(float *press)
BOOL get_HP203_data(float* tempdata, float* press) BOOL get_HP203_data(float* tempdata, float* press)
{ {
int ret; int ret;
uint8_t temp_error_time, press_error_time = 0;
// ѹǿ // ѹǿ
U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00}; U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00};
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){ for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
hp203_set_mode();
ret = Hp203bReadPressure(&collect_pressure[i].fValue); ret = Hp203bReadPressure(&collect_pressure[i].fValue);
if(ret == FALSE) if(ret == FALSE)
{ {
goto error_return; press_error_time++;
} }
osDelay(1); osDelay(1);
} }
if(press_error_time >= COLLECT_HB203_DATA_NUM)
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT); {
goto error_return;
}
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM - press_error_time, FILTER_DATA_TYPE_FLOAT);
if(tmp_press.fValue < 300) if(tmp_press.fValue < 300)
{ {
// return FALSE; // return FALSE;
@ -124,22 +119,24 @@ BOOL get_HP203_data(float* tempdata, float* press)
U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00}; U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00};
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){ for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
hp203_set_mode();
ret = Hp203bReadTempture(&collect_tempture[i].fValue); ret = Hp203bReadTempture(&collect_tempture[i].fValue);
if(ret == FALSE) if(ret == FALSE)
{ {
goto error_return; temp_error_time++;
} }
osDelay(1); osDelay(1);
} }
if(temp_error_time >= COLLECT_HB203_DATA_NUM)
U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT); {
if(tmp_tempture.fValue < -50) goto error_return;
}
U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM - temp_error_time, FILTER_DATA_TYPE_FLOAT);
if(tmp_tempture.fValue < -40)
{ {
// return FALSE; // return FALSE;
goto error_return; goto error_return;
} }
if(tmp_tempture.fValue > 95) if(tmp_tempture.fValue > 85)
{ {
// return FALSE; // return FALSE;
goto error_return; goto error_return;

View File

@ -146,7 +146,7 @@ BOOL get_temp_humi_data(float* temdata, float* humidata)
// 断言有问题 // 断言有问题
// AssertError((tmp_temdata.fValue >= -40) && (tmp_temdata.fValue <= 85), return FALSE, "sht30温度值校验失败"); // AssertError((tmp_temdata.fValue >= -40) && (tmp_temdata.fValue <= 85), return FALSE, "sht30温度值校验失败");
// AssertError((tmp_humidata.fValue >= 0) && (tmp_humidata.fValue <= 100), return FALSE, "sht30湿度值校验失败"); // AssertError((tmp_humidata.fValue >= 0) && (tmp_humidata.fValue <= 100), return FALSE, "sht30湿度值校验失败");
if(tmp_temdata.fValue < -50) if(tmp_temdata.fValue < -40)
{ {
// tmp_temdata.fValue = -40; // tmp_temdata.fValue = -40;
// term_printf("sht30温度值校验失败"); // term_printf("sht30温度值校验失败");