add grade period for temp sensors
This commit is contained in:
parent
6e6d2965f7
commit
a7f6973efd
@ -179,7 +179,7 @@ void taskInput(void *pvParameters)
|
||||
for (int j = 0; j < sSensorCount; j++)
|
||||
{
|
||||
float temp_c = fDS18B20Temps[j];
|
||||
ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %.3f°C", (uint64_t)uOneWireAddresses[j], temp_c);
|
||||
ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %lf°C", (uint64_t)uOneWireAddresses[j], temp_c);
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
switch ((uint64_t)uOneWireAddresses[j])
|
||||
|
@ -3,15 +3,16 @@
|
||||
#include "esp_log.h"
|
||||
#include "safety.h"
|
||||
|
||||
#define PERIODIC_INTERVAL 1U // run safety checks every 1sec
|
||||
#define PERIODIC_INTERVAL 1U // run safety checks every 1sec
|
||||
#define SENSOR_GRACE_PERIOD (60U * 30U) // period that a sensor can report the same reading in seconds
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system-safety";
|
||||
static SemaphoreHandle_t xMutexAccessSafety = NULL;
|
||||
sSensorSanityCheck sanityChecks[NUMBER_OF_SENSOR_SANITY_CHECKS] = {
|
||||
{0, "chamber_temperature", {95.0f, -10.0f}, 0.0f, getChamberTemperature},
|
||||
{0, "outdoor_temperature", {45.0f, -20.0f}, 0.0f, getOutdoorTemperature},
|
||||
{0, "inlet_flow_temperature", {95.0f, -10.0f}, 0.0f, getInletFlowTemperature},
|
||||
{0, "return_flow_temperature", {95.0f, -10.0f}, 0.0f, getReturnFlowTemperature}};
|
||||
{0U, "chamber_temperature", {95.0f, -10.0f}, 0.0f, 0U, getChamberTemperature},
|
||||
{0U, "outdoor_temperature", {45.0f, -20.0f}, 0.0f, 0U, getOutdoorTemperature},
|
||||
{0U, "inlet_flow_temperature", {95.0f, -10.0f}, 0.0f, 0U, getInletFlowTemperature},
|
||||
{0U, "return_flow_temperature", {95.0f, -10.0f}, 0.0f, 0U, getReturnFlowTemperature}};
|
||||
|
||||
void taskSafety(void *pvParameters);
|
||||
void checkSensorSanity(void);
|
||||
@ -60,16 +61,20 @@ void checkSensorSanity(void)
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_SENSOR_SANITY_CHECKS; i++)
|
||||
{
|
||||
//printf("Check sanity of sensor %s:\n", sanityChecks[i].name);
|
||||
//printf(" Status: %u\n", sanityChecks[i].status);
|
||||
//printf(" Sensor Limits: Max = %.2f, Min = %.2f\n", sanityChecks[i].sSensorLimit.max, sanityChecks[i].sSensorLimit.min);
|
||||
//printf(" Last Sensor Temperature: %.2f\n", sanityChecks[i].fSensorTemperatureLast);
|
||||
// printf("Check sanity of sensor %s:\n", sanityChecks[i].name);
|
||||
// printf(" Status: %u\n", sanityChecks[i].status);
|
||||
// printf(" Sensor Limits: Max = %.2f, Min = %.2f\n", sanityChecks[i].sSensorLimit.max, sanityChecks[i].sSensorLimit.min);
|
||||
// printf(" Last Sensor Temperature: %.2f\n", sanityChecks[i].fSensorTemperatureLast);
|
||||
|
||||
const float fSensorTemperatureCurrent = sanityChecks[i].getSensor(CURRENT);
|
||||
if (fSensorTemperatureCurrent == sanityChecks[i].fSensorTemperatureLast)
|
||||
{
|
||||
ESP_LOGE(TAG, "%s Sensor reported unchanged value! %lf == %lf",sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].fSensorTemperatureLast);
|
||||
sanityChecks[i].status = 1;
|
||||
sanityChecks[i].uUnchangedCounter++;
|
||||
if (sanityChecks[i].uUnchangedCounter >= (SENSOR_GRACE_PERIOD / PERIODIC_INTERVAL))
|
||||
{
|
||||
ESP_LOGE(TAG, "%s Sensor reported unchanged value! %lf == %lf", sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].fSensorTemperatureLast);
|
||||
sanityChecks[i].status = 1U;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -78,19 +83,20 @@ void checkSensorSanity(void)
|
||||
if (fSensorTemperatureCurrent > sanityChecks[i].sSensorLimit.max)
|
||||
{
|
||||
ESP_LOGE(TAG, "%s Sensor reported too high value! %lf > %lf", sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].sSensorLimit.max);
|
||||
sanityChecks[i].status = 1;
|
||||
sanityChecks[i].status = 1U;
|
||||
}
|
||||
else if (fSensorTemperatureCurrent < sanityChecks[i].sSensorLimit.min)
|
||||
{
|
||||
ESP_LOGE(TAG, "%s Sensor reported too low value! %lf < %lf", sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].sSensorLimit.min);
|
||||
sanityChecks[i].status = 1;
|
||||
sanityChecks[i].status = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
sanityChecks[i].status = 0;
|
||||
sanityChecks[i].uUnchangedCounter = 0U;
|
||||
sanityChecks[i].status = 0U;
|
||||
}
|
||||
}
|
||||
//printf(" Status: %u\n", sanityChecks[i].status);
|
||||
// printf(" Status: %u\n", sanityChecks[i].status);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,11 @@ typedef struct _TemperatureSensorLimit
|
||||
} sTemperatureSensorLimit;
|
||||
typedef struct _SensorSanityCheck
|
||||
{
|
||||
unsigned int status;
|
||||
uint8_t status;
|
||||
char name[MAX_ERROR_STRING_SIZE];
|
||||
sTemperatureSensorLimit sSensorLimit;
|
||||
float fSensorTemperatureLast;
|
||||
uint32_t uUnchangedCounter;
|
||||
GetSensorValue getSensor;
|
||||
} sSensorSanityCheck;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user