给报警器报警加了多次触发判断

This commit is contained in:
小马_666 2025-01-25 14:43:42 +08:00
parent 39661d1d64
commit e55496541d
2 changed files with 40 additions and 24 deletions

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2025-01-24 08:40:39
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-25 13:35:20
* @LastEditTime: 2025-01-25 14:14:51
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\inc\bsp_h308.h
* @Description:
* @
@ -76,7 +76,7 @@ typedef struct __attribute__((packed))
rt_uint8_t checksum; // 校验
} TsH308Data;
typedef struct
typedef struct __attribute__((packed))
{
uint8_t end_of_life; // 寿命到期
uint8_t last_life; // 上次状态

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-11-14 10:21:04
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-25 14:04:15
* @LastEditTime: 2025-01-25 14:34:41
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_h308.c
* @Description:
*
@ -37,7 +37,7 @@ static rt_sem_t uart4_rx_ok_sem;
static struct rt_timer uart4_rx_timer;
uint8_t sensor_rx_flag = 0; // 接收缓冲区中已经收到的数据包数量static rt_uint8_t alarm_flag = 0, fault_flag = 0;
static rt_uint8_t alarm_flag = 0, fault_flag = 0;
rt_uint8_t alarm_flag = 0, fault_flag = 0;
TsH308 H308 = {0};
void _UART4_RxTimeout(void *parameter)
@ -166,50 +166,55 @@ static uint8_t H308_Count(const rt_uint8_t *buffer, uint8_t value, uint8_t size)
// }
// }
static void H308_HandleAlarm(uint8_t count, uint8_t *flag, uint8_t threshold)
static void H308_HandleAlarm(uint8_t count, uint8_t threshold)
{
if (count >= threshold && *flag == 0)
if (count >= threshold && alarm_flag == 0)
{
if (H308.Data.lel > H308.alarm_value)
{
*flag = 1;
alarm_flag = 1;
H308.detection_flag = kH308Alarm;
Send_Laser_Alarm_Event(kAlarmEvent);
}
}
else if (*flag == 1 && count == 0)
else if (alarm_flag == 1 && count == 0)
{
*flag = 0;
alarm_flag = 0;
H308.detection_flag = kH308Normal;
Send_Laser_Alarm_Event(kAlarmRcyEvent);
}
else if ((H308.Data.lel == 0) && (count == 0))
{
alarm_flag = 0;
H308.detection_flag = kH308Alarm;
}
}
static void H308_HandleFault(uint8_t count, uint8_t *flag, uint8_t threshold)
static void H308_HandleFault(uint8_t count, uint8_t threshold)
{
if (count >= threshold && *flag != 1)
if (count >= threshold && fault_flag != 1)
{
*flag = 1;
fault_flag = 1;
H308.detection_flag = kH308Fault;
rt_thread_mdelay(1);
Send_Laser_Alarm_Event(kFaultEvent);
}
else if (*flag == 1 && count == 0)
else if (fault_flag == 1 && count == 0)
{
*flag = 0;
fault_flag = 0;
H308.detection_flag = kH308Normal;
rt_thread_mdelay(1);
Send_Laser_Alarm_Event(kFaultRcyEvent);
}
else if (rt_pin_read(LED_Y_PIN) == PIN_HIGH && (count == 0))
{
*flag = 0;
fault_flag = 0;
H308.detection_flag = kH308Normal;
}
LOG_D(" *flag = [%d]; H308.detection_flag:[%d]", *flag, H308.detection_flag);
}
static uint8_t H308_CheckData(rt_uint8_t *alarm_flag, rt_uint8_t *fault_flag)
static uint8_t H308_CheckData(void)
{
static rt_uint8_t alarm_count = 0, fault_count = 0;
static rt_uint8_t index = 0;
static rt_uint8_t alarm_status_buffer[H308_SAMPLING_TIMS] = {0};
@ -222,11 +227,13 @@ static uint8_t H308_CheckData(rt_uint8_t *alarm_flag, rt_uint8_t *fault_flag)
{
index = 0;
}
alarm_count = H308_Count(alarm_status_buffer, kH308Alarm, H308_SAMPLING_TIMS);
rt_thread_mdelay(1);
fault_count = H308_Count(fault_buf, kH308Fault, H308_SAMPLING_TIMS);
H308_HandleAlarm(alarm_count, alarm_flag, H308_SAMPLING_TIMS);
H308_HandleFault(fault_count, fault_flag, H308_SAMPLING_TIMS);
rt_thread_mdelay(1);
H308_HandleAlarm(alarm_count, H308_SAMPLING_TIMS);
rt_thread_mdelay(1);
H308_HandleFault(fault_count, H308_SAMPLING_TIMS);
return RT_EOK;
}
@ -235,7 +242,7 @@ static uint8_t H308_CheckData(rt_uint8_t *alarm_flag, rt_uint8_t *fault_flag)
uint8_t IS_H308_EndOfLife(void)
{
RTC_GetTime();
if (RtcDateTime.year > 2035) // 至少大于2035年再检测
if (RtcDateTime.year >= 2035) // 至少大于2035年再检测
{
if (RTC_GetCounter() >= H308.expiration_seconds)
{
@ -244,11 +251,13 @@ uint8_t IS_H308_EndOfLife(void)
else
{
H308.end_of_life = 0;
return 0;
}
}
else
{
H308.end_of_life = 0;
return 0;
}
return H308.end_of_life;
}
@ -303,7 +312,13 @@ static void h308_thread_entry(void *param)
static uint8_t h308_rx_timout_cnt = 0;
static uint8_t h308_err_cnt = 0;
rt_thread_mdelay(1000);
H308.alarm_value = Flash_Get_SysCfg(kAlarmLValueId); // 获取系统报警阈值
rt_uint8_t alarm_value = Flash_Get_SysCfg(kAlarmLValueId); // 获取系统报警阈值;
if (alarm_value > 25)
{
alarm_value = 10;
}
H308.alarm_value = alarm_value;
LOG_D("报警阈值:%d%LEL", H308.alarm_value);
while (1)
@ -320,7 +335,7 @@ static void h308_thread_entry(void *param)
LOG_I("str:%s", str);
if (ret == 0)
{
H308_CheckData(&alarm_flag, &fault_flag);
H308_CheckData();
}
else
{
@ -330,6 +345,7 @@ static void h308_thread_entry(void *param)
else
{
h308_err_cnt++;
LOG_E("(len = %d) < 44, error data:[%s]", len, str);
if (h308_err_cnt >= 5)
{