chore: snapshot before shared RS485 bus integration
This commit is contained in:
72
components/evse/evse_manager.c
Executable file → Normal file
72
components/evse/evse_manager.c
Executable file → Normal file
@@ -22,6 +22,8 @@
|
||||
#include "loadbalancer_events.h"
|
||||
#include "ocpp_events.h"
|
||||
#include "scheduler_events.h"
|
||||
#include "evse_link_events.h"
|
||||
|
||||
|
||||
static const char *TAG = "EVSE_Manager";
|
||||
|
||||
@@ -61,6 +63,72 @@ bool evse_sched_is_allowed(void)
|
||||
return v;
|
||||
}
|
||||
|
||||
static void on_evse_link_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
if (base != EVSE_LINK_EVENTS || id != LINK_EVENT_CURRENT_LIMIT_APPLIED || data == NULL)
|
||||
return;
|
||||
|
||||
uint16_t current = *(const uint16_t *)data;
|
||||
|
||||
ESP_LOGI(TAG, "[EVSE-LINK] current limit applied: %uA", current);
|
||||
|
||||
if (current == 0)
|
||||
{
|
||||
bool prev_auth = evse_state_get_authorized();
|
||||
|
||||
portENTER_CRITICAL(&s_mgr_mux);
|
||||
lb_paused = true;
|
||||
lb_prev_authorized = prev_auth;
|
||||
portEXIT_CRITICAL(&s_mgr_mux);
|
||||
|
||||
if (prev_auth)
|
||||
{
|
||||
ESP_LOGI(TAG, "[EVSE-LINK] limit=0A → paused by master");
|
||||
evse_state_set_authorized(false);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
evse_set_runtime_charging_current(current);
|
||||
|
||||
bool was_paused;
|
||||
bool prev_auth;
|
||||
bool local_auth_enabled;
|
||||
|
||||
portENTER_CRITICAL(&s_mgr_mux);
|
||||
was_paused = lb_paused;
|
||||
prev_auth = lb_prev_authorized;
|
||||
local_auth_enabled = auth_enabled;
|
||||
lb_paused = false;
|
||||
lb_prev_authorized = false;
|
||||
portEXIT_CRITICAL(&s_mgr_mux);
|
||||
|
||||
if (was_paused)
|
||||
{
|
||||
bool can_resume =
|
||||
(evse_get_error() == 0) &&
|
||||
evse_config_is_available() &&
|
||||
evse_config_is_enabled() &&
|
||||
evse_sched_is_allowed() &&
|
||||
!evse_is_limit_reached();
|
||||
|
||||
if (!can_resume)
|
||||
{
|
||||
ESP_LOGW(TAG, "[EVSE-LINK] limit=%uA → cannot resume", current);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!local_auth_enabled || prev_auth)
|
||||
{
|
||||
ESP_LOGI(TAG, "[EVSE-LINK] limit=%uA → resuming after master pause", current);
|
||||
evse_state_set_authorized(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void evse_manager_handle_auth_on_tick(void)
|
||||
{
|
||||
bool sched_allowed = evse_sched_is_allowed();
|
||||
@@ -423,6 +491,10 @@ void evse_manager_init(void)
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(LOADBALANCER_EVENTS, ESP_EVENT_ANY_ID, &on_loadbalancer_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(OCPP_EVENTS, ESP_EVENT_ANY_ID, &on_ocpp_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(SCHED_EVENTS, ESP_EVENT_ANY_ID, &on_sched_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(EVSE_LINK_EVENTS,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&on_evse_link_event,
|
||||
NULL));
|
||||
|
||||
ESP_LOGI(TAG, "EVSE Manager inicializado.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user