Adicionar primeiro

This commit is contained in:
2025-06-06 21:17:25 +01:00
parent c188084ba4
commit 282e7f517b
841 changed files with 199592 additions and 1 deletions

View File

@@ -0,0 +1,70 @@
#ifndef EVSE_API_H
#define EVSE_API_H
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "evse_state.h" // Define evse_state_t
// Inicialização
void evse_init(void);
void evse_process(void);
// Estado
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);
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);
void evse_authorize(void);
bool evse_is_pending_auth(void);
void evse_set_authorized(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);
// Grid
uint8_t grid_get_max_current(void);
esp_err_t grid_set_max_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(uint8_t value);
// 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);
#endif // EVSE_API_H

View File

@@ -0,0 +1,78 @@
#ifndef EVSE_CONFIG_H
#define EVSE_CONFIG_H
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
// ========================
// Limites Globais (Defines)
// ========================
// Corrente máxima de carregamento (configurável pelo usuário)
#define MIN_CHARGING_CURRENT_LIMIT 6 // A
#define MAX_CHARGING_CURRENT_LIMIT 16 // A
// Corrente máxima da rede elétrica (grid)
#define MIN_GRID_CURRENT_LIMIT 6 // A
#define MAX_GRID_CURRENT_LIMIT 100 // A
// Corrente via cabo (proximity) — se configurável
#define MIN_CABLE_CURRENT_LIMIT 6 // A
#define MAX_CABLE_CURRENT_LIMIT 63 // A
// ========================
// Funções de Configuração
// ========================
// Inicialização
esp_err_t evse_config_init(void);
void evse_check_defaults(void);
// Corrente de carregamento
uint8_t evse_get_max_charging_current(void);
esp_err_t evse_set_max_charging_current(uint8_t value);
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);
// Corrente da rede elétrica
uint8_t grid_get_max_current(void);
esp_err_t grid_set_max_current(uint8_t value);
// Configuração de socket outlet
bool evse_get_socket_outlet(void);
esp_err_t evse_set_socket_outlet(bool socket_outlet);
// RCM
bool evse_is_rcm(void);
esp_err_t evse_set_rcm(bool rcm);
// Temperatura
uint8_t evse_get_temp_threshold(void);
esp_err_t evse_set_temp_threshold(uint8_t threshold);
// Autenticação
bool evse_is_require_auth(void);
void evse_set_require_auth(bool require);
// Disponibilidade
bool evse_config_is_available(void);
void evse_config_set_available(bool available);
// Ativação/desativação do EVSE
bool evse_config_is_enabled(void);
void evse_config_set_enabled(bool enabled);
#ifdef __cplusplus
}
#endif
#endif // EVSE_CONFIG_H

View File

@@ -0,0 +1,45 @@
#ifndef EVSE_ERROR_H
#define EVSE_ERROR_H
#include <stdint.h>
#include <stdbool.h>
#include "pilot.h"
#define EVSE_ERR_AUTO_CLEAR_BITS ( \
EVSE_ERR_DIODE_SHORT_BIT | \
EVSE_ERR_TEMPERATURE_HIGH_BIT | \
EVSE_ERR_RCM_TRIGGERED_BIT )
// Error bits
#define EVSE_ERR_DIODE_SHORT_BIT (1 << 0)
#define EVSE_ERR_LOCK_FAULT_BIT (1 << 1)
#define EVSE_ERR_UNLOCK_FAULT_BIT (1 << 2)
#define EVSE_ERR_RCM_SELFTEST_FAULT_BIT (1 << 3)
#define EVSE_ERR_RCM_TRIGGERED_BIT (1 << 4)
#define EVSE_ERR_TEMPERATURE_HIGH_BIT (1 << 5)
#define EVSE_ERR_PILOT_FAULT_BIT (1 << 6)
#define EVSE_ERR_TEMPERATURE_FAULT_BIT (1 << 7)
// Inicialização do módulo de erros
void evse_error_init(void);
// Verificações e monitoramento
void evse_error_check(pilot_voltage_t pilot_voltage, bool is_n12v);
void evse_temperature_check(void);
void evse_error_tick(void);
// Leitura e controle de erros
uint32_t evse_get_error(void);
bool evse_is_error_cleared(void);
void evse_mark_error_cleared(void);
void evse_error_set(uint32_t bitmask);
void evse_error_clear(uint32_t bitmask);
bool evse_error_is_active(void);
uint32_t evse_error_get_bits(void);
void evse_error_reset_flag(void);
bool evse_error_cleared_flag(void);
#endif // EVSE_ERROR_H

View File

@@ -0,0 +1,33 @@
#ifndef EVSE_EVENTS_H
#define EVSE_EVENTS_H
#include "evse_api.h"
#include "esp_event_base.h"
// Certifique-se de que ESP_EVENT_DECLARE_BASE seja corretamente reconhecido
#ifdef __cplusplus
extern "C" {
#endif
// Declaração da base de eventos EVSE (será definida em evse_events.c)
ESP_EVENT_DECLARE_BASE(EVSE_EVENT);
typedef enum {
EVSE_EVENT_STATE_CHANGED,
EVSE_EVENT_ERROR,
EVSE_EVENT_ERROR_CLEARED,
EVSE_EVENT_LIMIT_REACHED,
EVSE_EVENT_AUTH_GRANTED
} evse_event_id_t;
// Estrutura do evento de mudança de estado
typedef struct {
evse_state_t previous;
evse_state_t current;
} evse_event_state_changed_t;
#ifdef __cplusplus
}
#endif
#endif // EVSE_EVENTS_H

View File

@@ -0,0 +1,37 @@
#ifndef EVSE_FSM_H
#define EVSE_FSM_H
#include <stdint.h>
#include <stdbool.h>
#include "evse_api.h"
#include "pilot.h"
#include "freertos/FreeRTOS.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Reinicia a máquina de estados do EVSE para o estado inicial (A).
*/
void evse_fsm_reset(void);
/**
* @brief Processa uma leitura do sinal de piloto e atualiza a máquina de estados do EVSE.
*
* Esta função deve ser chamada periodicamente pelo núcleo de controle para
* avaliar mudanças no estado do conector, disponibilidade do carregador e
* autorização do usuário.
*
* @param pilot_voltage Leitura atual da tensão do sinal piloto.
* @param authorized Indica se o carregamento foi autorizado.
* @param available Indica se o carregador está disponível (ex: sem falhas).
* @param enabled Indica se o carregador está habilitado via software.
*/
void evse_fsm_process(pilot_voltage_t pilot_voltage, bool authorized, bool available, bool enabled);
#ifdef __cplusplus
}
#endif
#endif // EVSE_FSM_H

View File

@@ -0,0 +1,71 @@
#ifndef EVSE_HARDWARE_H
#define EVSE_HARDWARE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
/**
* @brief Inicializa todos os periféricos de hardware do EVSE (pilot, relé, trava, etc.)
*/
void evse_hardware_init(void);
/**
* @brief Executa atualizações periódicas no hardware (tick)
*/
void evse_hardware_tick(void);
/**
* @brief Verifica se o sinal piloto está em nível alto (12V)
*/
bool evse_hardware_is_pilot_high(void);
/**
* @brief Verifica se o veículo está fisicamente conectado via Proximity
*/
bool evse_hardware_is_vehicle_connected(void);
/**
* @brief Verifica se há consumo de energia (corrente detectada)
*/
bool evse_hardware_is_energy_detected(void);
/**
* @brief Liga o relé de fornecimento de energia
*/
void evse_hardware_relay_on(void);
/**
* @brief Desliga o relé de fornecimento de energia
*/
void evse_hardware_relay_off(void);
/**
* @brief Consulta o estado atual do relé
* @return true se ligado, false se desligado
*/
bool evse_hardware_relay_status(void);
/**
* @brief Aciona a trava física do conector
*/
void evse_hardware_lock(void);
/**
* @brief Libera a trava física do conector
*/
void evse_hardware_unlock(void);
/**
* @brief Verifica se o conector está travado
*/
bool evse_hardware_is_locked(void);
#ifdef __cplusplus
}
#endif
#endif // EVSE_HARDWARE_H

View File

@@ -0,0 +1,43 @@
#ifndef EVSE_LIMITS_H
#define EVSE_LIMITS_H
#include <stdint.h>
#include <stdbool.h>
#include "evse_state.h"
#ifdef __cplusplus
extern "C" {
#endif
/// Estado dos limites
void evse_set_limit_reached(uint8_t value);
bool evse_is_limit_reached(void);
/// Verifica e aplica lógica de limites com base no estado atual do EVSE
void evse_limits_check(evse_state_t state);
/// Limites ativos (runtime)
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);
/// Limites padrão (persistentes)
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);
#ifdef __cplusplus
}
#endif
#endif // EVSE_LIMITS_H

View File

@@ -0,0 +1,63 @@
#ifndef EVSE_MANAGER_H
#define EVSE_MANAGER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include "evse_state.h"
#include "evse_error.h"
#include "evse_config.h"
/**
* @brief Inicializa todos os módulos do EVSE e inicia a tarefa de supervisão periódica.
*/
void evse_manager_init(void);
/**
* @brief Executa uma iteração do ciclo de controle do EVSE (chamada automaticamente pela task).
*
* Você normalmente não precisa chamar isso manualmente.
*/
void evse_manager_tick(void);
/**
* @brief Verifica se o EVSE está disponível para conexão (não bloqueado, sem falha crítica, etc).
*/
bool evse_manager_is_available(void);
/**
* @brief Define se o EVSE deve estar disponível.
*
* Pode ser usado, por exemplo, para bloquear carregamento via comando remoto.
*/
void evse_manager_set_available(bool available);
/**
* @brief Define se o EVSE está autorizado a iniciar carregamento (ex: após autenticação).
*/
void evse_manager_set_authorized(bool authorized);
/**
* @brief Verifica se o EVSE está em estado de carregamento ativo.
*/
bool evse_manager_is_charging(void);
/**
* @brief Ativa ou desativa o EVSE (liga/desliga logicamente o carregamento).
*/
void evse_manager_set_enabled(bool enabled);
/**
* @brief Verifica se o EVSE está ativado logicamente.
*/
bool evse_manager_is_enabled(void);
void evse_manager_task(void *arg);
#ifdef __cplusplus
}
#endif
#endif // EVSE_MANAGER_H

View File

@@ -0,0 +1,42 @@
#ifndef EVSE_STATE_H
#define EVSE_STATE_H
#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_t;
// Funções públicas necessárias
void evse_state_init(void);
void evse_state_tick(void);
void evse_state_set_authorized(bool authorized);
evse_state_t evse_get_state(void);
void evse_set_state(evse_state_t state);
// Converte o estado para string
const char* evse_state_to_str(evse_state_t state);
// Retorna true se o estado representa sessão ativa
bool evse_state_is_session(evse_state_t state);
// Retorna true se o estado representa carregamento ativo
bool evse_state_is_charging(evse_state_t state);
// Retorna true se o estado representa veículo conectado
bool evse_state_is_plugged(evse_state_t state);
#endif // EVSE_STATE_H