fix imports
This commit is contained in:
0
components/ade7758/CMakeLists.txt
Normal file → Executable file
0
components/ade7758/CMakeLists.txt
Normal file → Executable file
0
components/ade7758/include/ade7758.h
Normal file → Executable file
0
components/ade7758/include/ade7758.h
Normal file → Executable file
0
components/ade7758/include/meter.h
Normal file → Executable file
0
components/ade7758/include/meter.h
Normal file → Executable file
0
components/ade7758/src/ade7758.c
Normal file → Executable file
0
components/ade7758/src/ade7758.c
Normal file → Executable file
0
components/ade7758/src/energy_meter.c
Normal file → Executable file
0
components/ade7758/src/energy_meter.c
Normal file → Executable file
0
components/ade7758/src/meter.c
Normal file → Executable file
0
components/ade7758/src/meter.c
Normal file → Executable file
@@ -1,9 +0,0 @@
|
||||
set(srcs
|
||||
"src/input_filter.c"
|
||||
"src/currentshaper.c"
|
||||
)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_REQUIRES nvs_flash
|
||||
REQUIRES config evse)
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef CURRENTSHAPER_H_
|
||||
#define CURRENTSHAPER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Inicia a tarefa do shaper de corrente dinâmica.
|
||||
*/
|
||||
void currentshaper_start(void);
|
||||
|
||||
/**
|
||||
* @brief Encerra a tarefa do shaper de corrente dinâmica.
|
||||
*/
|
||||
void currentshaper_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Executa a lógica de modelagem da corrente com base nos dados atuais.
|
||||
*/
|
||||
void shapeCurrent(void);
|
||||
|
||||
/**
|
||||
* @brief Define a corrente máxima disponível da rede elétrica (A*10).
|
||||
*
|
||||
* @param max_grid_current Corrente máxima da rede (em A*10)
|
||||
*/
|
||||
void setMaxGridCurrent(int max_grid_current);
|
||||
|
||||
/**
|
||||
* @brief Define a corrente medida em tempo real disponível na rede (A*10).
|
||||
*
|
||||
* @param live_grid_current Corrente de rede ao vivo (em A*10)
|
||||
*/
|
||||
void setLiveGridCurrent(int live_grid_current);
|
||||
|
||||
/**
|
||||
* @brief Define a tensão medida em tempo real da rede (V).
|
||||
*
|
||||
* @param live_volt Tensão da rede (em volts)
|
||||
*/
|
||||
void setLiveVolt(int live_volt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CURRENTSHAPER_H_ */
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef _INPUT_FILTER_H
|
||||
#define _INPUT_FILTER_H
|
||||
|
||||
#include <stdint.h> // Necessário para uint32_t
|
||||
#include <inttypes.h> // Para uso de PRIu32 se necessário em logs
|
||||
|
||||
// Constante mínima de tempo (tau), em milissegundos
|
||||
#ifndef INPUT_FILTER_MIN_TAU
|
||||
#define INPUT_FILTER_MIN_TAU 10 // ms
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Calcula o fator de suavização com base em delta e tau.
|
||||
*
|
||||
* @param delta Tempo desde a última atualização (ms)
|
||||
* @param tau Constante de tempo do filtro (ms)
|
||||
* @return double Fator de suavização (0.0 a 1.0)
|
||||
*/
|
||||
double getFactor(uint32_t delta, uint32_t tau);
|
||||
|
||||
/**
|
||||
* @brief Aplica filtro exponencial a uma entrada.
|
||||
*
|
||||
* @param input Valor atual medido
|
||||
* @param filtered Valor suavizado anterior
|
||||
* @param tau Constante de tempo (ms)
|
||||
* @return double Novo valor suavizado
|
||||
*/
|
||||
double filter(double input, double filtered, uint32_t tau);
|
||||
|
||||
#endif // _INPUT_FILTER_H
|
||||
@@ -1,136 +0,0 @@
|
||||
// currentshaper.c
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <sys/param.h>
|
||||
#include "evse_api.h"
|
||||
#include "input_filter.h"
|
||||
|
||||
static const char *TAG = "currentshaper";
|
||||
|
||||
#define EVSE_SHAPER_HYSTERESIS 50 // A*10
|
||||
#define CHARGING_CURRENT_MIN 60 // A*10
|
||||
|
||||
static TaskHandle_t currentshaper_task = NULL;
|
||||
|
||||
static uint32_t smoothing_time_ms = 1000;
|
||||
static uint32_t min_pause_time_ms = 300000;
|
||||
static uint32_t max_data_interval_ms = 120000;
|
||||
|
||||
static int max_grid_current = 300; // A*10
|
||||
static int live_grid_current = 0; // A*10
|
||||
static int live_voltage = 230;
|
||||
static double smoothed_current = 0;
|
||||
|
||||
static uint16_t max_current = 0;
|
||||
static TickType_t timer = 0;
|
||||
static TickType_t pause_timer = 0;
|
||||
|
||||
static bool updated = false;
|
||||
static bool changed = false;
|
||||
|
||||
static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
void shapeCurrent()
|
||||
{
|
||||
taskENTER_CRITICAL(&mux);
|
||||
updated = true;
|
||||
smoothed_current = filter(live_grid_current, smoothed_current, smoothing_time_ms);
|
||||
int diff = max_grid_current - (int)smoothed_current;
|
||||
int charge_current = evse_get_charging_current();
|
||||
int new_current = diff + charge_current;
|
||||
|
||||
new_current = MIN(new_current, evse_get_max_charging_current() * 10);
|
||||
new_current = MAX(new_current, CHARGING_CURRENT_MIN);
|
||||
|
||||
max_current = new_current;
|
||||
if (charge_current != max_current)
|
||||
{
|
||||
evse_set_charging_current(max_current);
|
||||
changed = true;
|
||||
}
|
||||
taskEXIT_CRITICAL(&mux);
|
||||
}
|
||||
|
||||
void setMaxGridCurrent(int value)
|
||||
{
|
||||
taskENTER_CRITICAL(&mux);
|
||||
max_grid_current = value;
|
||||
taskEXIT_CRITICAL(&mux);
|
||||
ESP_LOGI(TAG, "Max grid current: %d A*10", value);
|
||||
}
|
||||
|
||||
void setLiveGridCurrent(int value)
|
||||
{
|
||||
taskENTER_CRITICAL(&mux);
|
||||
live_grid_current = value;
|
||||
taskEXIT_CRITICAL(&mux);
|
||||
ESP_LOGI(TAG, "Live grid current: %d A*10", value);
|
||||
if (evse_state_is_charging(evse_get_state()))
|
||||
{
|
||||
shapeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
void setLiveVoltage(int value)
|
||||
{
|
||||
taskENTER_CRITICAL(&mux);
|
||||
live_voltage = value;
|
||||
taskEXIT_CRITICAL(&mux);
|
||||
ESP_LOGD(TAG, "Live voltage: %d V", value);
|
||||
}
|
||||
|
||||
static void currentshaper_task_func(void *param)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
TickType_t now = xTaskGetTickCount();
|
||||
if (evse_state_is_charging(evse_get_state()))
|
||||
{
|
||||
taskENTER_CRITICAL(&mux);
|
||||
if (changed)
|
||||
{
|
||||
if (max_current < CHARGING_CURRENT_MIN)
|
||||
{
|
||||
evse_set_charging_current(CHARGING_CURRENT_MIN);
|
||||
if (pause_timer == 0)
|
||||
pause_timer = now;
|
||||
}
|
||||
else if ((pause_timer != 0) && (now - pause_timer) * portTICK_PERIOD_MS >= min_pause_time_ms &&
|
||||
(max_current - CHARGING_CURRENT_MIN >= EVSE_SHAPER_HYSTERESIS))
|
||||
{
|
||||
pause_timer = 0;
|
||||
}
|
||||
timer = now;
|
||||
changed = false;
|
||||
}
|
||||
else if (!updated || (now - timer) * portTICK_PERIOD_MS > max_data_interval_ms)
|
||||
{
|
||||
if (updated)
|
||||
{
|
||||
pause_timer = now;
|
||||
updated = false;
|
||||
smoothed_current = live_grid_current;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL(&mux);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void currentshaper_start()
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting current shaper task");
|
||||
xTaskCreate(currentshaper_task_func, "currentshaper_task", 4096, NULL, 5, ¤tshaper_task);
|
||||
}
|
||||
|
||||
void currentshaper_stop()
|
||||
{
|
||||
ESP_LOGI(TAG, "Stopping current shaper task");
|
||||
if (currentshaper_task != NULL)
|
||||
{
|
||||
vTaskDelete(currentshaper_task);
|
||||
currentshaper_task = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// input_filter.c
|
||||
#include "input_filter.h"
|
||||
#include "esp_log.h"
|
||||
#include <math.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static const char *TAG = "inputfilter";
|
||||
static TickType_t last_data_time = 0;
|
||||
|
||||
#define MIN_TAU_MS 100 // Minimum time constant in ms
|
||||
|
||||
double getFactor(uint32_t delta_ms, uint32_t tau_ms)
|
||||
{
|
||||
if (tau_ms < MIN_TAU_MS)
|
||||
{
|
||||
tau_ms = MIN_TAU_MS;
|
||||
}
|
||||
double factor = 1.0 - exp(-((double)delta_ms / (double)tau_ms));
|
||||
ESP_LOGD(TAG, "delta_ms=%" PRIu32 ", tau_ms=%" PRIu32 ", factor=%f", delta_ms, tau_ms, factor);
|
||||
return factor;
|
||||
}
|
||||
|
||||
double filter(double input, double filtered, uint32_t tau_ms)
|
||||
{
|
||||
TickType_t now = xTaskGetTickCount();
|
||||
uint32_t delta_ms = (now - last_data_time) * portTICK_PERIOD_MS;
|
||||
last_data_time = now;
|
||||
|
||||
double factor = getFactor(delta_ms, tau_ms);
|
||||
filtered = input * factor + filtered * (1.0 - factor);
|
||||
|
||||
ESP_LOGD(TAG, "input=%f, filtered=%f", input, filtered);
|
||||
return filtered;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ void evse_set_require_auth(bool value) {
|
||||
require_auth = value;
|
||||
nvs_set_u8(nvs, "require_auth", value);
|
||||
nvs_commit(nvs);
|
||||
ESP_LOGI(TAG, "Require auth adjusted to: %d", require_auth);
|
||||
ESP_LOGD(TAG, "Require auth adjusted to: %d", require_auth);
|
||||
}
|
||||
|
||||
// Availability
|
||||
|
||||
@@ -6,4 +6,4 @@ set(srcs
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES meter_orno_modbus ade7758)
|
||||
REQUIRES esp_event meter_orno_modbus ade7758)
|
||||
|
||||
@@ -5,4 +5,4 @@ set(srcs
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES meter_orno_modbus)
|
||||
REQUIRES esp_event meter_orno_modbus)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(srcs
|
||||
"src/loadbalancer.c"
|
||||
"src/input_filter.c" "src/loadbalancer.c"
|
||||
)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES gridmeter evsemeter)
|
||||
REQUIRES esp_event gridmeter evsemeter)
|
||||
|
||||
0
components/loadbalancer/include/input_filter.h
Normal file → Executable file
0
components/loadbalancer/include/input_filter.h
Normal file → Executable file
0
components/loadbalancer/src/input_filter.c
Normal file → Executable file
0
components/loadbalancer/src/input_filter.c
Normal file → Executable file
@@ -79,7 +79,7 @@ void loadbalancer_task(void *param)
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting EVSE current limit: %.1f A", available);
|
||||
evse_set_current_limit((uint16_t)available);
|
||||
evse_set_charging_current((uint16_t)available);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
@@ -1,23 +1,58 @@
|
||||
#ifndef ORNO_MODBUS_H_
|
||||
#define ORNO_MODBUS_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Tipo do medidor ORNO usado na aplicação.
|
||||
*/
|
||||
typedef enum {
|
||||
ORNO_METER_GRID,
|
||||
ORNO_METER_EVSE
|
||||
ORNO_METER_GRID, ///< Medidor na entrada da rede elétrica
|
||||
ORNO_METER_EVSE ///< Medidor na saída da EVSE
|
||||
} orno_meter_type_t;
|
||||
|
||||
/**
|
||||
* @brief Inicializa o driver ORNO Modbus.
|
||||
*/
|
||||
esp_err_t orno_modbus_init(void);
|
||||
|
||||
/**
|
||||
* @brief Lê a corrente RMS do medidor especificado.
|
||||
*
|
||||
* @param type Tipo do medidor (GRID ou EVSE)
|
||||
* @param current Ponteiro para armazenar o valor da corrente (em amperes)
|
||||
* @return esp_err_t ESP_OK em caso de sucesso, erro caso contrário
|
||||
*/
|
||||
esp_err_t orno_modbus_read_current(orno_meter_type_t type, float *current);
|
||||
|
||||
/**
|
||||
* @brief Ativa ou desativa o modo de teste (simulação).
|
||||
*/
|
||||
void orno_modbus_set_meter_test(bool state);
|
||||
|
||||
/**
|
||||
* @brief Define o modelo usado do medidor (caso afete registros).
|
||||
*/
|
||||
void orno_modbus_set_model(bool enabled);
|
||||
|
||||
/**
|
||||
* @brief Retorna o estado atual do medidor (ligado/desligado).
|
||||
*/
|
||||
bool orno_modbus_get_meter_state(void);
|
||||
|
||||
/**
|
||||
* @brief Inicia a task interna de comunicação (se usada).
|
||||
*/
|
||||
void orno_modbus_start(void);
|
||||
|
||||
/**
|
||||
* @brief Para a task de comunicação (se usada).
|
||||
*/
|
||||
void orno_modbus_stop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user