new meter

This commit is contained in:
2025-06-14 11:46:10 +01:00
parent 6f95c7ba59
commit a0b2e048d4
20 changed files with 17741 additions and 74 deletions

View File

@@ -50,7 +50,13 @@ 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(uint8_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);
@@ -60,4 +66,10 @@ 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);
#endif // EVSE_API_H

View File

@@ -9,24 +9,47 @@
extern "C" {
#endif
/// Estado dos limites
void evse_set_limit_reached(uint8_t value);
bool evse_is_limit_reached(void);
// ========================
// Limit state control
// ========================
/// Verifica e aplica lógica de limites com base no estado atual do EVSE
void evse_limits_check(evse_state_t state);
/**
* @brief Sets the 'limit reached' flag. Used internally when a session exceeds defined thresholds.
*/
void evse_set_limit_reached(bool value);
/**
* @brief Returns whether any session limit has been reached (energy, time or power).
*/
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.
*/
void evse_limits_check(void);
// ========================
// Runtime limit configuration
// ========================
/// Limites ativos (runtime)
uint32_t evse_get_consumption_limit(void);
void evse_set_consumption_limit(uint32_t value);
void evse_set_consumption_limit(uint32_t value); // in Wh
uint32_t evse_get_charging_time_limit(void);
void evse_set_charging_time_limit(uint32_t value);
void evse_set_charging_time_limit(uint32_t value); // in seconds
uint16_t evse_get_under_power_limit(void);
void evse_set_under_power_limit(uint16_t value);
void evse_set_under_power_limit(uint16_t value); // in Watts
// ========================
// Default (persistent) limits
// ========================
/// Limites padrão (persistentes)
uint32_t evse_get_default_consumption_limit(void);
void evse_set_default_consumption_limit(uint32_t value);

View File

@@ -1,49 +1,95 @@
#ifndef EVSE_STATE_H
#define EVSE_STATE_H
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "evse_events.h"
// ============================
// EVSE Pilot Signal States
// ============================
#include <stdbool.h>
// Estado do EVSE (pilot signal)
typedef enum {
EVSE_STATE_A,
EVSE_STATE_B1,
EVSE_STATE_B2,
EVSE_STATE_C1,
EVSE_STATE_C2,
EVSE_STATE_D1,
EVSE_STATE_D2,
EVSE_STATE_E,
EVSE_STATE_F
EVSE_STATE_A, // EV Not Connected (12V)
EVSE_STATE_B1, // EV Connected (9V, Not Authorized)
EVSE_STATE_B2, // EV Connected (9V, Authorized and Ready)
EVSE_STATE_C1, // Charging Requested (6V, Relay Off)
EVSE_STATE_C2, // Charging Active (6V, Relay On)
EVSE_STATE_D1, // Ventilation Required (3V, Relay Off)
EVSE_STATE_D2, // Ventilation Active (3V, Relay On)
EVSE_STATE_E, // Error: Pilot Short to Ground (0V)
EVSE_STATE_F // Fault: No Pilot or EVSE Unavailable
} evse_state_t;
// ============================
// Initialization & Core Control
// ============================
// Funções públicas necessárias
/**
* @brief Initializes the EVSE state machine.
*/
void evse_state_init(void);
/**
* @brief Periodic tick function for the state machine.
*/
void evse_state_tick(void);
void evse_state_set_authorized(bool authorized);
bool evse_state_get_authorized(void);
// ============================
// State Access
// ============================
/**
* @brief Returns the current EVSE state.
*/
evse_state_t evse_get_state(void);
/**
* @brief Updates the current EVSE state and triggers events.
*/
void evse_set_state(evse_state_t state);
// Converte o estado para string
/**
* @brief Returns the tick count when charging session started.
*/
TickType_t evse_get_session_start(void);
/**
* @brief Converts the state enum to a human-readable string.
*/
const char* evse_state_to_str(evse_state_t state);
// Retorna true se o estado representa sessão ativa
// ============================
// State Evaluators
// ============================
/**
* @brief Returns true if the state represents an active session (B2, C1, C2).
*/
bool evse_state_is_session(evse_state_t state);
// Retorna true se o estado representa carregamento ativo
/**
* @brief Returns true if the state represents active charging (C1, C2).
*/
bool evse_state_is_charging(evse_state_t state);
// Retorna true se o estado representa veículo conectado
/**
* @brief Returns true if the vehicle is plugged in.
*/
bool evse_state_is_plugged(evse_state_t state);
//evse_state_event_t map_state_to_event(evse_state_t state);
// ============================
// Authorization
// ============================
/**
* @brief Sets the vehicle authorization state.
*/
void evse_state_set_authorized(bool authorized);
/**
* @brief Returns the current vehicle authorization state.
*/
bool evse_state_get_authorized(void);
#endif // EVSE_STATE_H