add orno driver
This commit is contained in:
70
components/meter_orno/include/meter_orno.h
Executable file
70
components/meter_orno/include/meter_orno.h
Executable file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
/**
|
||||
* @brief Inicializa o driver do medidor (SPI, mutex, registradores ADE7758).
|
||||
*/
|
||||
esp_err_t meter_init(void);
|
||||
|
||||
/**
|
||||
* @brief Inicia a tarefa de leitura de dados do medidor.
|
||||
*/
|
||||
esp_err_t meter_start(void);
|
||||
|
||||
/**
|
||||
* @brief Para a tarefa de leitura e limpa os dados internos.
|
||||
*/
|
||||
void meter_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Verifica se o medidor está em execução.
|
||||
*
|
||||
* @return true se a tarefa estiver ativa, false caso contrário.
|
||||
*/
|
||||
bool meter_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Limpa os dados armazenados no medidor (zera todos os valores).
|
||||
*/
|
||||
void meter_clear_data(void);
|
||||
|
||||
// ----- Leituras por fase (L1, L2, L3) -----
|
||||
|
||||
// Tensão RMS (em volts)
|
||||
float meter_get_vrms_l1(void);
|
||||
float meter_get_vrms_l2(void);
|
||||
float meter_get_vrms_l3(void);
|
||||
|
||||
// Corrente RMS (em amperes)
|
||||
float meter_get_irms_l1(void);
|
||||
float meter_get_irms_l2(void);
|
||||
float meter_get_irms_l3(void);
|
||||
|
||||
// Potência ativa (W)
|
||||
int meter_get_watt_l1(void);
|
||||
int meter_get_watt_l2(void);
|
||||
int meter_get_watt_l3(void);
|
||||
|
||||
// Potência reativa (VAR)
|
||||
int meter_get_var_l1(void);
|
||||
int meter_get_var_l2(void);
|
||||
int meter_get_var_l3(void);
|
||||
|
||||
// Potência aparente (VA)
|
||||
int meter_get_va_l1(void);
|
||||
int meter_get_va_l2(void);
|
||||
int meter_get_va_l3(void);
|
||||
|
||||
// (Opcional) contador de watchdog para diagnóstico
|
||||
uint32_t meter_get_watchdog_counter(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
80
components/meter_orno/include/modbus_params.h
Normal file
80
components/meter_orno/include/modbus_params.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*=====================================================================================
|
||||
* Description:
|
||||
* The Modbus parameter structures used to define Modbus instances that
|
||||
* can be addressed by Modbus protocol. Define these structures per your needs in
|
||||
* your application. Below is just an example of possible parameters.
|
||||
*====================================================================================*/
|
||||
#ifndef _DEVICE_PARAMS
|
||||
#define _DEVICE_PARAMS
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// This file defines structure of modbus parameters which reflect correspond modbus address space
|
||||
// for each modbus register type (coils, discreet inputs, holding registers, input registers)
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t discrete_input0:1;
|
||||
uint8_t discrete_input1:1;
|
||||
uint8_t discrete_input2:1;
|
||||
uint8_t discrete_input3:1;
|
||||
uint8_t discrete_input4:1;
|
||||
uint8_t discrete_input5:1;
|
||||
uint8_t discrete_input6:1;
|
||||
uint8_t discrete_input7:1;
|
||||
uint8_t discrete_input_port1;
|
||||
uint8_t discrete_input_port2;
|
||||
} discrete_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t coils_port0;
|
||||
uint8_t coils_port1;
|
||||
uint8_t coils_port2;
|
||||
} coil_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
float input_data0; // 0
|
||||
float input_data1; // 2
|
||||
float input_data2; // 4
|
||||
float input_data3; // 6
|
||||
uint16_t data[150]; // 8 + 150 = 158
|
||||
float input_data4; // 158
|
||||
float input_data5;
|
||||
float input_data6;
|
||||
float input_data7;
|
||||
uint16_t data_block1[150];
|
||||
} input_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t holding_data0;
|
||||
uint32_t holding_data1;
|
||||
uint32_t holding_data2;
|
||||
uint32_t holding_data3;
|
||||
uint32_t holding_data4;
|
||||
uint32_t holding_data5;
|
||||
uint32_t holding_data6;
|
||||
uint32_t holding_data7;
|
||||
} holding_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern holding_reg_params_t holding_reg_params;
|
||||
extern input_reg_params_t input_reg_params;
|
||||
extern coil_reg_params_t coil_reg_params;
|
||||
extern discrete_reg_params_t discrete_reg_params;
|
||||
|
||||
#endif // !defined(_DEVICE_PARAMS)
|
||||
@@ -1,62 +0,0 @@
|
||||
#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_ */
|
||||
Reference in New Issue
Block a user