new release

This commit is contained in:
2026-05-15 12:20:47 +01:00
parent 286028b6a8
commit d0d431daf2
440 changed files with 2776 additions and 2462 deletions

View File

@@ -1,4 +1,5 @@
#include <inttypes.h>
#include <string.h>
#include "evse_session.h"
#include "evse_meter.h"
#include "freertos/FreeRTOS.h"
@@ -25,6 +26,8 @@ static uint64_t watt_microseconds = 0;
static evse_session_t last_session;
static bool last_session_valid = false;
static uint32_t session_counter = 0;
static char authorized_tag[AUTH_TAG_MAX_LEN];
static char current_session_tag[AUTH_TAG_MAX_LEN];
static portMUX_TYPE session_mux = portMUX_INITIALIZER_UNLOCKED;
@@ -52,9 +55,31 @@ void evse_session_init(void)
watt_microseconds = 0;
last_session_valid = false;
session_counter = 0;
authorized_tag[0] = '\0';
current_session_tag[0] = '\0';
portEXIT_CRITICAL(&session_mux);
}
void evse_session_set_authorized_tag(const char *tag)
{
portENTER_CRITICAL(&session_mux);
if (tag && tag[0] != '\0')
{
strncpy(authorized_tag, tag, AUTH_TAG_MAX_LEN - 1);
authorized_tag[AUTH_TAG_MAX_LEN - 1] = '\0';
}
else
{
authorized_tag[0] = '\0';
}
portEXIT_CRITICAL(&session_mux);
}
void evse_session_clear_authorized_tag(void)
{
evse_session_set_authorized_tag(NULL);
}
void evse_session_start(void)
{
TickType_t tick = xTaskGetTickCount();
@@ -67,12 +92,17 @@ void evse_session_start(void)
watt_microseconds = 0;
session_counter++;
uint32_t id = session_counter;
strncpy(current_session_tag, authorized_tag, AUTH_TAG_MAX_LEN - 1);
current_session_tag[AUTH_TAG_MAX_LEN - 1] = '\0';
char tag[AUTH_TAG_MAX_LEN];
strncpy(tag, current_session_tag, AUTH_TAG_MAX_LEN - 1);
tag[AUTH_TAG_MAX_LEN - 1] = '\0';
portEXIT_CRITICAL(&session_mux);
evse_set_limit_reached(false);
ESP_LOGI(TAG, "Session started (id=%" PRIu32 ") tick=%u us=%" PRId64,
id, (unsigned)tick, now_us);
ESP_LOGI(TAG, "Session started (id=%" PRIu32 ", tag=%s) tick=%u us=%" PRId64,
id, tag[0] ? tag : "-", (unsigned)tick, now_us);
evse_session_event_data_t evt = {
.type = EVSE_SESSION_EVENT_STARTED,
@@ -82,6 +112,8 @@ void evse_session_start(void)
.avg_power_w = 0,
.is_current = true,
};
strncpy(evt.tag, tag, AUTH_TAG_MAX_LEN - 1);
evt.tag[AUTH_TAG_MAX_LEN - 1] = '\0';
post_session_event(&evt);
}
@@ -91,6 +123,7 @@ void evse_session_end(void)
int64_t start_us;
uint64_t w_us;
uint32_t id;
char tag[AUTH_TAG_MAX_LEN];
int64_t end_us = esp_timer_get_time();
@@ -106,11 +139,14 @@ void evse_session_end(void)
start_us = session_start_us;
w_us = watt_microseconds;
id = session_counter;
strncpy(tag, current_session_tag, AUTH_TAG_MAX_LEN - 1);
tag[AUTH_TAG_MAX_LEN - 1] = '\0';
session_start_tick = 0;
session_start_us = 0;
last_tick_us = 0;
watt_microseconds = 0;
current_session_tag[0] = '\0';
portEXIT_CRITICAL(&session_mux);
uint32_t duration_s = (end_us > start_us) ? (uint32_t)((end_us - start_us) / 1000000LL) : 0;
@@ -120,6 +156,9 @@ void evse_session_end(void)
portENTER_CRITICAL(&session_mux);
last_session.start_tick = start_tick;
last_session.session_id = id;
strncpy(last_session.tag, tag, AUTH_TAG_MAX_LEN - 1);
last_session.tag[AUTH_TAG_MAX_LEN - 1] = '\0';
last_session.duration_s = duration_s;
last_session.energy_wh = energy_wh;
last_session.avg_power_w = avg_power;
@@ -129,8 +168,8 @@ void evse_session_end(void)
ESP_LOGI(TAG,
"Session ended (id=%" PRIu32 "): duration=%" PRIu32 " s, energy=%" PRIu32
" Wh, avg_power=%" PRIu32 " W",
id, duration_s, energy_wh, avg_power);
" Wh, avg_power=%" PRIu32 " W, tag=%s",
id, duration_s, energy_wh, avg_power, tag[0] ? tag : "-");
evse_session_event_data_t evt = {
.type = EVSE_SESSION_EVENT_FINISHED,
@@ -140,6 +179,8 @@ void evse_session_end(void)
.avg_power_w = avg_power,
.is_current = false,
};
strncpy(evt.tag, tag, AUTH_TAG_MAX_LEN - 1);
evt.tag[AUTH_TAG_MAX_LEN - 1] = '\0';
post_session_event(&evt);
}
@@ -185,6 +226,8 @@ bool evse_session_get(evse_session_t *out)
bool has_current;
evse_session_t last_copy;
bool last_valid;
uint32_t id;
char tag[AUTH_TAG_MAX_LEN];
int64_t now_us = esp_timer_get_time();
@@ -193,6 +236,9 @@ bool evse_session_get(evse_session_t *out)
start_us = session_start_us;
w_us = watt_microseconds;
has_current = (session_start_tick != 0);
id = session_counter;
strncpy(tag, current_session_tag, AUTH_TAG_MAX_LEN - 1);
tag[AUTH_TAG_MAX_LEN - 1] = '\0';
last_copy = last_session;
last_valid = last_session_valid;
portEXIT_CRITICAL(&session_mux);
@@ -205,6 +251,9 @@ bool evse_session_get(evse_session_t *out)
uint32_t avg_power = (duration_s > 0) ? (uint32_t)(watt_seconds / duration_s) : 0;
out->start_tick = start_tick;
out->session_id = id;
strncpy(out->tag, tag, AUTH_TAG_MAX_LEN - 1);
out->tag[AUTH_TAG_MAX_LEN - 1] = '\0';
out->duration_s = duration_s;
out->energy_wh = energy_wh;
out->avg_power_w = avg_power;