bugfix/static-code-analysis (#28)
The claude.ai LLM performed a static code analysis. Reviewed-on: #28 Co-authored-by: localhorst <localhorst@mosad.xyz> Co-committed-by: localhorst <localhorst@mosad.xyz>
This commit is contained in:
@ -2,10 +2,12 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "safety.h"
|
||||
|
||||
#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
|
||||
#define FLOAT_EPSILON 0.0001f
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system-safety";
|
||||
static SemaphoreHandle_t xMutexAccessSafety = NULL;
|
||||
@ -91,7 +93,7 @@ void checkSensorSanity(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sCurrentMeasurement.fCurrentValue == sanityChecks[i].fSensorTemperatureLast)
|
||||
if (fabsf(sCurrentMeasurement.fCurrentValue - sanityChecks[i].fSensorTemperatureLast) < FLOAT_EPSILON)
|
||||
{
|
||||
sanityChecks[i].uUnchangedCounter++;
|
||||
if (sanityChecks[i].uUnchangedCounter >= (SENSOR_GRACE_PERIOD / PERIODIC_INTERVAL))
|
||||
@ -103,6 +105,7 @@ void checkSensorSanity(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
sanityChecks[i].uUnchangedCounter = 0U;
|
||||
sanityChecks[i].fSensorTemperatureLast = sCurrentMeasurement.fCurrentValue;
|
||||
|
||||
if (sCurrentMeasurement.fCurrentValue > sanityChecks[i].sSensorLimit.max)
|
||||
@ -119,12 +122,10 @@ void checkSensorSanity(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
sanityChecks[i].uUnchangedCounter = 0U;
|
||||
sanityChecks[i].state = SENSOR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
// printf(" state: %u\n", sanityChecks[i].state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ void getSensorSanityStates(sSensorSanityCheck *pSensorSanityChecks)
|
||||
{
|
||||
// Copy only the needed attributes
|
||||
pSensorSanityChecks[i].state = sanityChecks[i].state;
|
||||
strcpy(pSensorSanityChecks[i].name, sanityChecks[i].name);
|
||||
strncpy(pSensorSanityChecks[i].name, sanityChecks[i].name, MAX_ERROR_STRING_SIZE);
|
||||
}
|
||||
xSemaphoreGiveRecursive(xMutexAccessSafety);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user