diff --git a/main/control.c b/main/control.c index 42eb184..4ff2ffa 100644 --- a/main/control.c +++ b/main/control.c @@ -22,9 +22,8 @@ static const char *TAG = "smart-oil-heater-control-system-control"; static eControlState sControlState = CONTROL_STARTING; - // Control table for daily schedules -static sControlDay aControlTable[] = { +static const sControlDay aControlTable[] = { {MONDAY, 2U, {{{4, 45}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY, CHAMBER_TEMPERATURE_TARGET}, {{22, 0}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT, CHAMBER_TEMPERATURE_TARGET}}}, {TUESDAY, 2U, {{{4, 45}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY, CHAMBER_TEMPERATURE_TARGET}, {{22, 0}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT, CHAMBER_TEMPERATURE_TARGET}}}, {WEDNESDAY, 2U, {{{4, 45}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY, CHAMBER_TEMPERATURE_TARGET}, {{22, 0}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT, CHAMBER_TEMPERATURE_TARGET}}}, @@ -33,11 +32,11 @@ static sControlDay aControlTable[] = { {SATURDAY, 2U, {{{6, 45}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY, CHAMBER_TEMPERATURE_TARGET}, {{23, 30}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT, CHAMBER_TEMPERATURE_TARGET}}}, {SUNDAY, 2U, {{{6, 45}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY, CHAMBER_TEMPERATURE_TARGET}, {{22, 30}, RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT, CHAMBER_TEMPERATURE_TARGET}}}, }; +static sControlTemperatureEntry currentControlEntry = aControlTable[0].aTemperatureEntries[0]; // Function prototypes void taskControl(void *pvParameters); -eControlWeekday getCurrentWeekday(void); -sControlTemperatureEntry getCurrentTemperatureEntry(void); +void findControlCurrentTemperatureEntry(void); void initControl(void) { @@ -101,7 +100,7 @@ void taskControl(void *pvParameters) continue; } - sControlTemperatureEntry currentControlEntry = getCurrentTemperatureEntry(); + sControlTemperatureEntry currentControlEntry = getControlCurrentTemperatureEntry(); if (getOutdoorTemperature().average60s.fValue >= SUMMER_MODE_TEMPERATURE_THRESHOLD_HIGH) { @@ -192,7 +191,7 @@ eControlState getControlState(void) return sControlState; } -eControlWeekday getCurrentWeekday(void) +eControlWeekday getControlCurrentWeekday(void) { time_t now; struct tm *timeinfo; @@ -204,10 +203,9 @@ eControlWeekday getCurrentWeekday(void) return (eControlWeekday)((day == 0) ? 6 : day - 1); } -sControlTemperatureEntry getCurrentTemperatureEntry(void) +void findControlCurrentTemperatureEntry(void) { - sControlTemperatureEntry result = aControlTable[0].aTemperatureEntries[0]; - eControlWeekday currentDay = getCurrentWeekday(); + eControlWeekday currentDay = getControlCurrentWeekday(); time_t now; struct tm timeinfo; @@ -225,10 +223,14 @@ sControlTemperatureEntry getCurrentTemperatureEntry(void) (aControlTable[i].day == currentDay && aControlTable[i].aTemperatureEntries[j].timestamp.hour > hour) || (aControlTable[i].day == currentDay && aControlTable[i].aTemperatureEntries[j].timestamp.hour == hour && aControlTable[i].aTemperatureEntries[j].timestamp.minute >= minute)) { - return aControlTable[i].aTemperatureEntries[j]; + currentControlEntry = aControlTable[i].aTemperatureEntries[j]; } - result = aControlTable[i].aTemperatureEntries[j]; + currentControlEntry = aControlTable[i].aTemperatureEntries[j]; } } - return result; +} + +sControlTemperatureEntry getControlCurrentTemperatureEntry(void) +{ + return currentControlEntry; } diff --git a/main/control.h b/main/control.h index fe7f3ad..7690bd1 100644 --- a/main/control.h +++ b/main/control.h @@ -54,3 +54,5 @@ typedef struct _ControlDay void initControl(void); eControlState getControlState(void); +eControlWeekday getControlCurrentWeekday(void); +sControlTemperatureEntry getControlCurrentTemperatureEntry(void); diff --git a/main/metrics.c b/main/metrics.c index ca430b9..6f1b2db 100644 --- a/main/metrics.c +++ b/main/metrics.c @@ -254,6 +254,31 @@ void taskMetrics(void *pvParameters) aMetrics[u16MetricCounter].u8MetricValue = getControlState(); u16MetricCounter++; + // Control Current Weekday + strcpy(aMetrics[u16MetricCounter].caMetricName, "control_current_weekday"); + aMetrics[u16MetricCounter].type = INTEGER_U8; + aMetrics[u16MetricCounter].u8MetricValue = getControlCurrentWeekday(); + u16MetricCounter++; + + // Control Current Entry Time + strcpy(aMetrics[u16MetricCounter].caMetricName, "control_current_entry_time"); + aMetrics[u16MetricCounter].type = INTEGER_64; + int64_t i64SecondsSinceMidnight = (getControlCurrentTemperatureEntry().timestamp.hour * 60U * 60U) + (getControlCurrentTemperatureEntry().timestamp.minute * 60U); + aMetrics[u16MetricCounter].i64MetricValue = i64SecondsSinceMidnight; + u16MetricCounter++; + + // Control Current Entry Chamber Temperature + strcpy(aMetrics[u16MetricCounter].caMetricName, "control_current_entry_chamber_temperature"); + aMetrics[u16MetricCounter].type = FLOAT; + aMetrics[u16MetricCounter].fMetricValue = getControlCurrentTemperatureEntry().fChamberTemperature; + u16MetricCounter++; + + // Control Current Entry Return Flow Temperature + strcpy(aMetrics[u16MetricCounter].caMetricName, "control_current_entry_return_flow_temperature"); + aMetrics[u16MetricCounter].type = FLOAT; + aMetrics[u16MetricCounter].fMetricValue = getControlCurrentTemperatureEntry().fReturnFlowTemperature; + u16MetricCounter++; + // SNTP State strcpy(aMetrics[u16MetricCounter].caMetricName, "sntp_state"); aMetrics[u16MetricCounter].type = INTEGER_U8; diff --git a/main/metrics.h b/main/metrics.h index 230d711..e8eafed 100644 --- a/main/metrics.h +++ b/main/metrics.h @@ -4,7 +4,7 @@ #define HTML_RESPONSE_SIZE 4096U #define METRIC_NAME_MAX_SIZE 64U -#define METRIC_MAX_COUNT 34U +#define METRIC_MAX_COUNT 38U typedef enum _MetricValueType {