fix ade7758
This commit is contained in:
@@ -3,73 +3,77 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "evse_state.h" // Define evse_state_t
|
||||
#include "evse_state.h" // Tipos e estados
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
// Inicialização
|
||||
void evse_init(void);
|
||||
void evse_process(void);
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Estado
|
||||
// ===============================
|
||||
// Core EVSE State
|
||||
// ===============================
|
||||
|
||||
/**
|
||||
* @brief Get current EVSE state (e.g., A, B1, C2).
|
||||
*/
|
||||
evse_state_t evse_get_state(void);
|
||||
const char* evse_state_to_str(evse_state_t state);
|
||||
bool evse_is_connector_plugged(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Set the EVSE state (e.g., called by FSM or hardware layer).
|
||||
*/
|
||||
void evse_set_state(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Get timestamp when the current session started (for timing limits).
|
||||
*/
|
||||
TickType_t evse_get_session_start(void);
|
||||
|
||||
// ===============================
|
||||
// Charging Session Info
|
||||
// ===============================
|
||||
|
||||
/**
|
||||
* @brief Returns true if the EV is charging (C1 or C2).
|
||||
*/
|
||||
bool evse_state_is_charging(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the EV is connected (plugged).
|
||||
*/
|
||||
bool evse_state_is_plugged(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Returns true if a charging session is active (B2, C1, C2).
|
||||
*/
|
||||
bool evse_state_is_session(evse_state_t state);
|
||||
|
||||
// ===============================
|
||||
// Authorization
|
||||
// ===============================
|
||||
|
||||
/**
|
||||
* @brief Set whether the vehicle is authorized to charge.
|
||||
*/
|
||||
void evse_state_set_authorized(bool authorized);
|
||||
|
||||
/**
|
||||
* @brief Get current authorization status.
|
||||
*/
|
||||
bool evse_state_get_authorized(void);
|
||||
|
||||
|
||||
// ===============================
|
||||
// Limit Status
|
||||
// ===============================
|
||||
|
||||
/**
|
||||
* @brief Returns true if any runtime charging limit has been reached.
|
||||
*/
|
||||
bool evse_is_limit_reached(void);
|
||||
|
||||
// Autorização e disponibilidade
|
||||
bool evse_is_enabled(void);
|
||||
void evse_set_enabled(bool value);
|
||||
bool evse_is_available(void);
|
||||
void evse_set_available(bool value);
|
||||
bool evse_is_require_auth(void);
|
||||
void evse_set_require_auth(bool value);
|
||||
|
||||
// Corrente
|
||||
uint16_t evse_get_charging_current(void);
|
||||
esp_err_t evse_set_charging_current(uint16_t value);
|
||||
uint16_t evse_get_default_charging_current(void);
|
||||
esp_err_t evse_set_default_charging_current(uint16_t value);
|
||||
uint8_t evse_get_max_charging_current(void);
|
||||
esp_err_t evse_set_max_charging_current(uint8_t value);
|
||||
|
||||
// Temperatura
|
||||
uint8_t evse_get_temp_threshold(void);
|
||||
esp_err_t evse_set_temp_threshold(uint8_t value);
|
||||
|
||||
// RCM / Socket
|
||||
bool evse_get_socket_outlet(void);
|
||||
esp_err_t evse_set_socket_outlet(bool value);
|
||||
bool evse_is_rcm(void);
|
||||
esp_err_t evse_set_rcm(bool value);
|
||||
|
||||
// Limites
|
||||
uint32_t evse_get_consumption_limit(void);
|
||||
void evse_set_consumption_limit(uint32_t value);
|
||||
uint32_t evse_get_charging_time_limit(void);
|
||||
void evse_set_charging_time_limit(uint32_t value);
|
||||
uint16_t evse_get_under_power_limit(void);
|
||||
void evse_set_under_power_limit(uint16_t value);
|
||||
|
||||
void evse_set_limit_reached(bool value);
|
||||
|
||||
// Energia total acumulada da sessão (em Wh)
|
||||
uint32_t evse_get_total_energy(void);
|
||||
|
||||
// Potência instantânea medida (em W)
|
||||
uint32_t evse_get_instant_power(void);
|
||||
|
||||
// Limites default
|
||||
uint32_t evse_get_default_consumption_limit(void);
|
||||
void evse_set_default_consumption_limit(uint32_t value);
|
||||
uint32_t evse_get_default_charging_time_limit(void);
|
||||
void evse_set_default_charging_time_limit(uint32_t value);
|
||||
uint16_t evse_get_default_under_power_limit(void);
|
||||
void evse_set_default_under_power_limit(uint16_t value);
|
||||
|
||||
|
||||
uint32_t evse_get_total_energy(void);
|
||||
uint32_t evse_get_instant_power(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // EVSE_API_H
|
||||
|
||||
17
components/evse/include/evse_core.h
Normal file
17
components/evse/include/evse_core.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef EVSE_CORE_H
|
||||
#define EVSE_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initializes the EVSE system and starts core task loop.
|
||||
*/
|
||||
void evse_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // EVSE_CORE_H
|
||||
@@ -9,47 +9,58 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ========================
|
||||
// Limit state control
|
||||
// ========================
|
||||
// ============================
|
||||
// Limit Status & Evaluation
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* @brief Sets the 'limit reached' flag. Used internally when a session exceeds defined thresholds.
|
||||
* @brief Sets the internal 'limit reached' flag.
|
||||
* Called internally when a limit condition is triggered.
|
||||
*/
|
||||
void evse_set_limit_reached(bool value);
|
||||
|
||||
/**
|
||||
* @brief Returns whether any session limit has been reached (energy, time or power).
|
||||
* @brief Returns true if any runtime charging limit has been reached.
|
||||
*/
|
||||
bool evse_get_limit_reached(void);
|
||||
|
||||
// ========================
|
||||
// Limit checking
|
||||
// ========================
|
||||
|
||||
/**
|
||||
* @brief Evaluates if the session has exceeded any configured limits.
|
||||
* Should be called periodically while in charging state.
|
||||
* @brief Checks if any session limit has been exceeded (energy, time or power).
|
||||
* Should be called periodically during charging.
|
||||
*/
|
||||
void evse_limits_check(void);
|
||||
|
||||
// ========================
|
||||
// Runtime limit configuration
|
||||
// ========================
|
||||
// ============================
|
||||
// Runtime Limit Configuration
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* @brief Get/set energy consumption limit (in Wh).
|
||||
*/
|
||||
uint32_t evse_get_consumption_limit(void);
|
||||
void evse_set_consumption_limit(uint32_t value); // in Wh
|
||||
void evse_set_consumption_limit(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Get/set maximum charging time (in seconds).
|
||||
*/
|
||||
uint32_t evse_get_charging_time_limit(void);
|
||||
void evse_set_charging_time_limit(uint32_t value); // in seconds
|
||||
void evse_set_charging_time_limit(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Get/set minimum acceptable power level (in Watts).
|
||||
* If the power remains below this for a long time, the session may be interrupted.
|
||||
*/
|
||||
uint16_t evse_get_under_power_limit(void);
|
||||
void evse_set_under_power_limit(uint16_t value); // in Watts
|
||||
void evse_set_under_power_limit(uint16_t value);
|
||||
|
||||
// ========================
|
||||
// Default (persistent) limits
|
||||
// ========================
|
||||
// ============================
|
||||
// Default (Persistent) Limits
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* @brief Default values used after system boot or reset.
|
||||
* These can be restored from NVS or fallback values.
|
||||
*/
|
||||
uint32_t evse_get_default_consumption_limit(void);
|
||||
void evse_set_default_consumption_limit(uint32_t value);
|
||||
|
||||
|
||||
@@ -26,38 +26,6 @@ void evse_manager_init(void);
|
||||
*/
|
||||
void evse_manager_tick(void);
|
||||
|
||||
/**
|
||||
* @brief Verifica se o EVSE está disponível para uso.
|
||||
*
|
||||
* Isso considera falhas críticas, disponibilidade configurada, etc.
|
||||
*/
|
||||
bool evse_manager_is_available(void);
|
||||
|
||||
/**
|
||||
* @brief Define se o EVSE deve estar disponível (ex: via controle remoto).
|
||||
*/
|
||||
void evse_manager_set_available(bool available);
|
||||
|
||||
/**
|
||||
* @brief Define se o EVSE está autorizado a carregar (ex: após autenticação).
|
||||
*/
|
||||
void evse_manager_set_authorized(bool authorized);
|
||||
|
||||
/**
|
||||
* @brief Verifica se o EVSE está atualmente carregando.
|
||||
*/
|
||||
bool evse_manager_is_charging(void);
|
||||
|
||||
/**
|
||||
* @brief Ativa ou desativa logicamente o EVSE (controla habilitação geral).
|
||||
*/
|
||||
void evse_manager_set_enabled(bool enabled);
|
||||
|
||||
/**
|
||||
* @brief Verifica se o EVSE está ativado logicamente.
|
||||
*/
|
||||
bool evse_manager_is_enabled(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
37
components/evse/include/evse_meter.h
Normal file
37
components/evse/include/evse_meter.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef EVSE_METER_H
|
||||
#define EVSE_METER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EVSE_METER_PHASE_COUNT 3
|
||||
|
||||
/// Inicializa o módulo EVSE Meter e registra os tratadores de eventos
|
||||
void evse_meter_init(void);
|
||||
|
||||
/// Retorna a potência instantânea (soma das 3 fases, em watts)
|
||||
uint32_t evse_meter_get_instant_power(void);
|
||||
|
||||
/// Retorna a energia total acumulada (em Wh)
|
||||
uint32_t evse_meter_get_total_energy(void);
|
||||
|
||||
/// Retorna as potências instantâneas nas fases L1, L2 e L3 (em watts)
|
||||
void evse_meter_get_power(uint32_t power[EVSE_METER_PHASE_COUNT]);
|
||||
|
||||
/// Retorna as tensões medidas nas fases L1, L2 e L3 (em volts)
|
||||
void evse_meter_get_voltage(float voltage[EVSE_METER_PHASE_COUNT]);
|
||||
|
||||
/// Retorna as correntes medidas nas fases L1, L2 e L3 (em amperes)
|
||||
void evse_meter_get_current(float current[EVSE_METER_PHASE_COUNT]);
|
||||
|
||||
/// Handler interno para eventos do medidor (não chamar externamente)
|
||||
void evse_meter_on_meter_event(void* arg, void* event_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // EVSE_METER_H
|
||||
@@ -5,6 +5,10 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "evse_events.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ============================
|
||||
// EVSE Pilot Signal States
|
||||
// ============================
|
||||
@@ -22,21 +26,21 @@ typedef enum {
|
||||
} evse_state_t;
|
||||
|
||||
// ============================
|
||||
// Initialization & Core Control
|
||||
// Initialization
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* @brief Initializes the EVSE state machine.
|
||||
* @brief Initializes the EVSE state machine and default state.
|
||||
*/
|
||||
void evse_state_init(void);
|
||||
|
||||
/**
|
||||
* @brief Periodic tick function for the state machine.
|
||||
* @brief Periodic tick for state handling (optional hook).
|
||||
*/
|
||||
void evse_state_tick(void);
|
||||
|
||||
// ============================
|
||||
// State Access
|
||||
// State Access & Control
|
||||
// ============================
|
||||
|
||||
/**
|
||||
@@ -45,51 +49,55 @@ void evse_state_tick(void);
|
||||
evse_state_t evse_get_state(void);
|
||||
|
||||
/**
|
||||
* @brief Updates the current EVSE state and triggers events.
|
||||
* @brief Sets the current EVSE state and emits a change event if needed.
|
||||
*/
|
||||
void evse_set_state(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Returns the tick count when charging session started.
|
||||
* @brief Returns the tick count when the current charging session began.
|
||||
*/
|
||||
TickType_t evse_get_session_start(void);
|
||||
|
||||
/**
|
||||
* @brief Converts the state enum to a human-readable string.
|
||||
* @brief Converts the state enum into a human-readable string.
|
||||
*/
|
||||
const char* evse_state_to_str(evse_state_t state);
|
||||
|
||||
// ============================
|
||||
// State Evaluators
|
||||
// State Evaluation Helpers
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* @brief Returns true if the state represents an active session (B2, C1, C2).
|
||||
* @brief True if EV is in an active session (B2, C1, C2).
|
||||
*/
|
||||
bool evse_state_is_session(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the state represents active charging (C1, C2).
|
||||
* @brief True if EV is actively charging (C1, C2).
|
||||
*/
|
||||
bool evse_state_is_charging(evse_state_t state);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the vehicle is plugged in.
|
||||
* @brief True if EV is physically plugged in (B1 and beyond).
|
||||
*/
|
||||
bool evse_state_is_plugged(evse_state_t state);
|
||||
|
||||
// ============================
|
||||
// Authorization
|
||||
// Authorization Control
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* @brief Sets the vehicle authorization state.
|
||||
* @brief Sets whether the EV is authorized to charge.
|
||||
*/
|
||||
void evse_state_set_authorized(bool authorized);
|
||||
|
||||
/**
|
||||
* @brief Returns the current vehicle authorization state.
|
||||
* @brief Gets whether the EV is currently authorized.
|
||||
*/
|
||||
bool evse_state_get_authorized(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // EVSE_STATE_H
|
||||
|
||||
Reference in New Issue
Block a user