refact 3
This commit is contained in:
6
components/meter_orno/CMakeLists.txt
Executable file
6
components/meter_orno/CMakeLists.txt
Executable file
@@ -0,0 +1,6 @@
|
||||
set(srcs
|
||||
"src/orno_modbus.c"
|
||||
)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include")
|
||||
62
components/meter_orno/include/orno_modbus.h
Executable file
62
components/meter_orno/include/orno_modbus.h
Executable file
@@ -0,0 +1,62 @@
|
||||
#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, ///< 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
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ORNO_MODBUS_H_ */
|
||||
52
components/meter_orno/src/orno_modbus.c
Executable file
52
components/meter_orno/src/orno_modbus.c
Executable file
@@ -0,0 +1,52 @@
|
||||
#include "orno_modbus.h"
|
||||
#include <stdbool.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "orno_modbus";
|
||||
static bool meter_state = false;
|
||||
static bool meter_test = false;
|
||||
static bool model_enabled = false;
|
||||
|
||||
esp_err_t orno_modbus_init(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing ORNO Modbus driver");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t orno_modbus_read_current(orno_meter_type_t type, float *current)
|
||||
{
|
||||
if (!current) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
// Stub implementation - replace with real Modbus queries
|
||||
*current = 0.0f;
|
||||
ESP_LOGD(TAG, "Read current type %d -> %f", type, *current);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void orno_modbus_set_meter_test(bool state)
|
||||
{
|
||||
meter_test = state;
|
||||
}
|
||||
|
||||
void orno_modbus_set_model(bool enabled)
|
||||
{
|
||||
model_enabled = enabled;
|
||||
}
|
||||
|
||||
bool orno_modbus_get_meter_state(void)
|
||||
{
|
||||
return meter_state;
|
||||
}
|
||||
|
||||
void orno_modbus_start(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting ORNO Modbus driver");
|
||||
meter_state = true;
|
||||
}
|
||||
|
||||
void orno_modbus_stop(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Stopping ORNO Modbus driver");
|
||||
meter_state = false;
|
||||
}
|
||||
Reference in New Issue
Block a user