2508 lines
72 KiB
C
2508 lines
72 KiB
C
.
|
||
|
||
// === Início de: components/meter_manager/driver/meter_ade7758/meter_ade7758.h ===
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor ADE7758 (SPI, mutex, registradores).
|
||
*/
|
||
esp_err_t meter_ade7758_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor ADE7758.
|
||
*/
|
||
esp_err_t meter_ade7758_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor ADE7758.
|
||
*/
|
||
void meter_ade7758_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_ade7758/meter_ade7758.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_ade7758/ade7758.h ===
|
||
#include "driver/spi_common.h"
|
||
#include "driver/spi_master.h"
|
||
|
||
|
||
|
||
#define WRITE 0x80 // WRITE bit BT7 to write to registers
|
||
#define CLKIN 10000000 // ADE7758 frec, 10.000000MHz
|
||
#define PERIODO 50 // Actually it is frequency, it is used to calculate the amount of Cycles that it accumulates for energy.
|
||
#define PHASE_A 1
|
||
#define PHASE_B 2
|
||
#define PHASE_C 3
|
||
|
||
|
||
//Register address
|
||
|
||
//------Name--------Address---------Lenght
|
||
#define AWATTHR 0x01 //---------16
|
||
#define BWATTHR 0x02 //---------16
|
||
#define CWATTHR 0x03 //---------16
|
||
|
||
#define AVARHR 0x04 //---------16
|
||
#define BVARHR 0x05 //---------16
|
||
#define CVARHR 0x06 //---------16
|
||
|
||
#define AVAHR 0x07 //---------16
|
||
#define BVAHR 0x08 //---------16
|
||
#define CVAHR 0x09 //---------16
|
||
|
||
#define AIRMS 0x0A //---------24
|
||
#define BIRMS 0x0B //---------24
|
||
#define CIRMS 0x0C //---------24
|
||
|
||
#define AVRMS 0x0D //---------24
|
||
#define BVRMS 0x0E //---------24
|
||
#define CVRMS 0x0F //---------24
|
||
|
||
#define FREQ 0x10 //---------12
|
||
#define TEMP 0x11 //---------8
|
||
#define WFORM 0x12 //---------24
|
||
#define OPMODE 0x13 //---------8
|
||
#define MMODE 0x14 //---------8
|
||
#define WAVMODE 0x15 //---------8
|
||
#define COMPMODE 0x16 //---------8
|
||
#define LCYCMODE 0x17 //---------8
|
||
#define MASK 0x18 //---------24
|
||
#define STATUS 0x19 //---------24
|
||
#define RSTATUS 0x1A //---------24
|
||
#define ZXTOUT 0x1B //---------16
|
||
#define LINECYC 0x1C //---------16
|
||
#define SAGCYC 0x1D //---------8
|
||
#define SAGLVL 0x1E //---------8
|
||
#define VPINTLVL 0x1F //---------8
|
||
#define IPINTLVL 0x20 //---------8
|
||
#define VPEAK 0x21 //---------8
|
||
#define IPEAK 0x22 //---------8
|
||
#define GAIN 0x23 //---------8
|
||
#define AVRMSGAIN 0x24 //---------12
|
||
#define BVRMSGAIN 0x25 //---------12
|
||
#define CVRMSGAIN 0x26 //---------12
|
||
#define AIGAIN 0x27 //---------12
|
||
#define BIGAIN 0x28 //---------12
|
||
#define CIGAIN 0x29 //---------12
|
||
#define AWG 0x2A //---------12
|
||
#define BWG 0x2B //---------12
|
||
#define CWG 0x2C //---------12
|
||
#define AVARG 0x2D //---------12
|
||
#define BVARG 0x2E //---------12
|
||
#define CVARG 0x2F //---------12
|
||
#define AVAG 0x30 //---------12
|
||
#define BVAG 0X31 //---------12
|
||
#define CVAG 0x32 //---------12
|
||
#define AVRMSOS 0x33 //---------12
|
||
#define BVRMSOS 0X34 //---------12
|
||
#define CVRMSOS 0X35 //---------12
|
||
#define AIRMSOS 0X36 //---------12
|
||
#define BIRMSOS 0X37 //---------12
|
||
#define CIRMSOS 0X38 //---------12
|
||
#define AWATTOS 0X39 //---------12
|
||
#define BWATTOS 0X3A //---------12
|
||
#define CWATTOS 0X3B //---------12
|
||
#define AVAROS 0X3C //---------12
|
||
#define BVAROS 0X3D //---------12
|
||
#define CVAROS 0X3E //---------12
|
||
#define APHCAL 0X3F //---------7
|
||
#define BPHCAL 0X40 //---------7
|
||
#define CPHCAL 0X41 //---------7
|
||
#define WDIV 0X42 //---------8
|
||
#define VARDIV 0X43 //---------8
|
||
#define VADIV 0X44 //---------8
|
||
#define APCFNUM 0X45 //---------16
|
||
#define APCFDEN 0X46 //---------12
|
||
#define VARCFNUM 0X47 //---------16
|
||
#define VARCFDEN 0X48 //---------12
|
||
|
||
#define CHKSUM 0X7E //---------8
|
||
#define VERSION 0x7f //---------8
|
||
#define DUMMY_BYTE 0xFF
|
||
|
||
|
||
//bits
|
||
|
||
/**
|
||
OPERATIONAL MODE REGISTER (0x13)
|
||
The general configuration of the ADE7758 is defined by writing to the OPMODE register.
|
||
Table 18 summarizes the functionality of each bit in the OPMODE register.
|
||
|
||
Bit Location Bit Mnemonic Default Value Description
|
||
0 DISHPF 0 The HPFs in all current channel inputs are disabled when this bit is set.
|
||
1 DISLPF 0 The LPFs after the watt and VAR multipliers are disabled when this bit is set.
|
||
2 DISCF 1 The frequency outputs APCF and VARCF are disabled when this bit is set.
|
||
3 to 5 DISMOD 0 By setting these bits, ADE7758<35>s ADCs can be turned off. In normal operation, these bits should be left at Logic 0.
|
||
DISMOD[2:0] Description
|
||
0 0 0 Normal operation.
|
||
1 0 0 Redirect the voltage inputs to the signal paths for the current channels and the current inputs to the signal paths for the voltage channels.
|
||
0 0 1 Switch off only the current channel ADCs.
|
||
1 0 1 Switch off current channel ADCs and redirect the current input signals to the voltage channel signal paths.
|
||
0 1 0 Switch off only the voltage channel ADCs.
|
||
1 1 0 Switch off voltage channel ADCs and redirect the voltage input signals to the current channel signal paths.
|
||
0 1 1 Put the ADE7758 in sleep mode.
|
||
1 1 1 Put the ADE7758 in power-down mode (reduces AIDD to 1 mA typ).
|
||
6 SWRST 0 Software Chip Reset. A data transfer to the ADE7758 should not take place for at least 18 <20>s after a software reset.
|
||
7 RESERVED 0 This should be left at 0.
|
||
|
||
*/
|
||
|
||
#define DISHPF 0x01
|
||
#define DISLPF 0x02
|
||
#define DISCF 0x04
|
||
#define SWRST 0x40
|
||
|
||
/**
|
||
MEASUREMENT MODE REGISTER (0x14)
|
||
The configuration of the PERIOD and peak measurements made by the ADE7758 is defined by writing to the MMODE register.
|
||
Table 19 summarizes the functionality of each bit in the MMODE register.
|
||
|
||
Bit Location Bit Mnemonic Default Value Description
|
||
0 to 1 FREQSEL 0 These bits are used to select the source of the measurement of the voltage line frequency.
|
||
FREQSEL1 FREQSEL0 Source
|
||
0 0 Phase A
|
||
0 1 Phase B
|
||
1 0 Phase C
|
||
1 1 Reserved
|
||
2 to 4 PEAKSEL 7 These bits select the phases used for the voltage and current peak registers.
|
||
Setting Bit 2 switches the IPEAK and VPEAK registers to hold the absolute values
|
||
of the largest current and voltage waveform (over a fixed number of half-line cycles)
|
||
from Phase A. The number of half-line cycles is determined by the content of the
|
||
LINECYC register. At the end of the LINECYC number of half-line cycles, the content
|
||
of the registers is replaced with the new peak values. Similarly, setting Bit 3 turns
|
||
on the peak detection for Phase B, and Bit 4 for Phase C. Note that if more than one
|
||
bit is set, the VPEAK and IPEAK registers can hold values from two different phases, that is,
|
||
the voltage and current peak are independently processed (see the Peak Current Detection section).
|
||
5 to 7 PKIRQSEL 7 These bits select the phases used for the peak interrupt detection.
|
||
Setting Bit 5 switches on the monitoring of the absolute current and voltage waveform to Phase A.
|
||
Similarly, setting Bit 6 turns on the waveform detection for Phase B, and Bit 7 for Phase C.
|
||
Note that more than one bit can be set for detection on multiple phases.
|
||
If the absolute values of the voltage or current waveform samples in the selected phases exceeds
|
||
the preset level specified in the VPINTLVL or IPINTLVL registers the corresponding bit(s) in the
|
||
STATUS registers are set (see the Peak Current Detection section).
|
||
|
||
*/
|
||
|
||
#define FREQSEL0 0x01
|
||
#define FREQSEL1 0x02
|
||
|
||
|
||
/**
|
||
WAVEFORM MODE REGISTER (0x15)
|
||
The waveform sampling mode of the ADE7758 is defined by writing to the WAVMODE register.
|
||
Table 20 summarizes the functionality of each bit in the WAVMODE register.
|
||
|
||
Bit Location Bit Mnemonic Default Value Description
|
||
0 to 1 PHSEL 0 These bits are used to select the phase of the waveform sample.
|
||
PHSEL[1:0] Source
|
||
0 0 Phase A
|
||
0 1 Phase B
|
||
1 0 Phase C
|
||
1 1 Reserved
|
||
2 to 4 WAVSEL 0 These bits are used to select the type of waveform.
|
||
WAVSEL[2:0] Source
|
||
0 0 0 Current
|
||
0 0 1 Voltage
|
||
0 1 0 Active Power Multiplier Output
|
||
0 1 1 Reactive Power Multiplier Output
|
||
1 0 0 VA Multiplier Output
|
||
-Others- Reserved
|
||
5 to 6 DTRT 0 These bits are used to select the data rate.
|
||
DTRT[1:0] Update Rate
|
||
0 0 26.04 kSPS (CLKIN/3/128)
|
||
0 1 13.02 kSPS (CLKIN/3/256)
|
||
1 0 6.51 kSPS (CLKIN/3/512)
|
||
1 1 3.25 kSPS (CLKIN/3/1024)
|
||
7 VACF 0 Setting this bit to Logic 1 switches the VARCF output pin to an output
|
||
frequency that is proportional to the total apparent power (VA).
|
||
In the default state, Logic 0, the VARCF pin outputs a frequency proportional
|
||
to the total reactive power (VAR).
|
||
*/
|
||
|
||
|
||
|
||
/**
|
||
COMPUTATIONAL MODE REGISTER (0x16)
|
||
The computational method of the ADE7758 is defined by writing to the COMPMODE register.
|
||
|
||
Bit Location Bit Mnemonic Default Value Description
|
||
0 to 1 CONSEL 0 These bits are used to select the input to the energy accumulation registers.
|
||
CONSEL[1:0] = 11 is reserved. IA, IB, and IC are IA, IB, and IC phase shifted by <20>90<39>, respectively.
|
||
Registers CONSEL[1, 0] = 00 CONSEL[1, 0] = 01 CONSEL[1, 0] = 10
|
||
AWATTHR VA <20> IA VA <20> (IA <20> IB) VA <20> (IA<49>IB)
|
||
BWATTHR VB <20> IB 0 0
|
||
CWATTHR VC <20> IC VC <20> (IC <20> IB) VC <20> IC
|
||
|
||
AVARHR VA <20> IA VA <20> (IA <20> IB) VA <20> (IA<49>IB)
|
||
BVARHR VB <20> IB 0 0
|
||
CVARHR VC <20> IC VC <20> (IC <20> IB) VC <20> IC
|
||
|
||
AVAHR VARMS <20> IARMS VARMS <20> IARMS VARMS <20> ARMS
|
||
BVAHR VBRMS <20> IBRMS (VARMS + VCRMS)/2 <20> IBRMS VARMS <20> IBRMS
|
||
CVAHR VCRMS <20> ICRMS VCRMS <20> ICRMS VCRMS <20> ICRMS
|
||
|
||
2 to 4 TERMSEL 7 These bits are used to select the phases to be included in the APCF and VARCF pulse outputs.
|
||
Setting Bit 2 selects Phase A (the inputs to AWATTHR and AVARHR registers) to be included.
|
||
Bit 3 and Bit 4 are for Phase B and Phase C, respectively.
|
||
Setting all three bits enables the sum of all three phases to be included in the frequency outputs
|
||
(see the Active Power Frequency Output and the Reactive Power Frequency Output sections).
|
||
|
||
5 ABS 0 Setting this bit places the APCF output pin in absolute only mode.
|
||
Namely, the APCF output frequency is proportional to the sum of the absolute values of the watt-hour
|
||
accumulation registers (AWATTHR, BWATTHR, and CWATTHR).
|
||
Note that this bit only affects the APCF pin and has no effect on the content of the corresponding
|
||
registers.
|
||
|
||
6 SAVAR 0 Setting this bit places the VARCF output pin in the signed adjusted mode.
|
||
Namely, the VARCF output frequency is proportional to the sign-adjusted sum of the VAR-hour accumulation
|
||
registers (AVARHR, BVARHR, and CVARHR).
|
||
The sign of the VAR is determined from the sign of the watt calculation from the corresponding phase,
|
||
that is, the sign of the VAR is flipped if the sign of the watt is negative, and if the watt is positive,
|
||
there is no change to the sign of the VAR.
|
||
Note that this bit only affects the VARCF pin and has no effect on the content of the corresponding
|
||
registers.
|
||
|
||
7 NOLOAD 0 Setting this bit activates the no-load threshold in the ADE7758.
|
||
*/
|
||
|
||
|
||
/**
|
||
LINE CYCLE ACCUMULATION MODE REGISTER (0x17)
|
||
The functionalities involved the line-cycle accumulation mode in the ADE7758 are defined by writing to the LCYCMODE register.
|
||
|
||
Bit Location Bit Mnemonic Default Value Description
|
||
|
||
0 LWATT 0 Setting this bit places the watt-hour accumulation registers
|
||
(AWATTHR, BWATTHR, and CWATTHR registers) into line-cycle accumulation mode.
|
||
1 LVAR 0 Setting this bit places the VAR-hour accumulation registers (AVARHR, BVARHR, and CVARHR registers)
|
||
into line-cycle accumulation mode.
|
||
2 LVA 0 Setting this bit places the VA-hour accumulation registers (AVAHR, BVAHR, and CVAHR registers)
|
||
into line-cycle accumulation mode.
|
||
3 to 5 ZXSEL 7 These bits select the phases used for counting the number of zero crossings in the line-cycle
|
||
accumulation mode. Bit 3, Bit 4, and Bit 5 select Phase A, Phase B, and Phase C, respectively.
|
||
More than one phase can be selected for the zero-crossing detection,
|
||
and the accumulation time is shortened accordingly.
|
||
6 RSTREAD 1 Setting this bit enables the read-with-reset for all the WATTHR, VARHR, and VAHR registers for all three
|
||
phases, that is, a read to those registers resets the registers to 0 after the content of the registers
|
||
have been read. This bit should be set to Logic 0 when the LWATT, LVAR, or LVA bits are set to Logic 1.
|
||
7 FREQSEL 0 Setting this bit causes the FREQ (0x10) register to display the period, instead of the frequency of the
|
||
line input.
|
||
*/
|
||
|
||
|
||
#define LWATT 0x01
|
||
#define LVAR 0x02
|
||
#define LVA 0x04
|
||
#define ZXSEL_A 0x08
|
||
#define ZXSEL_B 0x10
|
||
#define ZXSEL_C 0x20
|
||
#define RSTREAD 0x40
|
||
#define FREQSEL 0x80
|
||
|
||
|
||
|
||
/** INTERRUPT MASK REGISTER (0x18)
|
||
When an interrupt event occurs in the ADE7758, the IRQ logic output goes active low if the mask bit for this event is Logic 1 in the MASK register.
|
||
The IRQ logic output is reset to its default collector open state when the RSTATUS register is read.
|
||
describes the function of each bit in the interrupt mask register.
|
||
**/
|
||
|
||
// The next table summarizes the function of each bit for
|
||
// the Interrupt Enable Register
|
||
|
||
/* Bit Mask // Bit Location / Description
|
||
#define AEHF 0x0001 // bit 0 - Enables an interrupt when there is a change in Bit 14 of any one of the three WATTHR registers, that is, the WATTHR register is half full.
|
||
#define REHF 0x0002 // bit 1 - Enables an interrupt when there is a change in Bit 14 of any one of the three VARHR registers, that is, the VARHR register is half full.
|
||
#define VAEHF 0x0004 // bit 2 - Enables an interrupt when there is a 0 to 1 transition in the MSB of any one of the three VAHR registers, that is, the VAHR register is half full.
|
||
#define SAGA 0x0008 // bit 3 - Enables an interrupt when there is a SAG on the line voltage of the Phase A.
|
||
#define SAGB 0x0010 // bit 4 - Enables an interrupt when there is a SAG on the line voltage of the Phase B.
|
||
#define SAGC 0x0020 // bit 5 - Enables an interrupt when there is a SAG on the line voltage of the Phase C.
|
||
#define ZXTOA 0x0040 // bit 6 - Enables an interrupt when there is a zero-crossing timeout detection on Phase A.
|
||
#define ZXTOB 0x0080 // bit 7 - Enables an interrupt when there is a zero-crossing timeout detection on Phase B.
|
||
#define ZXTOC 0x0100 // bit 8 - Enables an interrupt when there is a zero-crossing timeout detection on Phase C.
|
||
#define ZXA 0x0200 // bit 9 - Enables an interrupt when there is a zero crossing in the voltage channel of Phase A
|
||
#define ZXB 0x0400 // bit 10 - Enables an interrupt when there is a zero crossing in the voltage channel of Phase B
|
||
#define ZXC 0x0800 // bit 11 - Enables an interrupt when there is a zero crossing in the voltage channel of Phase C
|
||
#define LENERGY 0x1000 // bit 12 - Enables an interrupt when the energy accumulations over LINECYC are finished.
|
||
//RESERVED 0x2000 // bit 13 - RESERVED
|
||
#define PKV 0x4000 // bit 14 - Enables an interrupt when the voltage input selected in the MMODE register is above the value in the VPINTLVL register.
|
||
#define PKI 0x8000 // bit 15 - Enables an interrupt when the current input selected in the MMODE register is above the value in the IPINTLVL register.
|
||
#define WFSM 0x010000 // bit 16 - Enables an interrupt when data is present in the WAVEMODE register.
|
||
#define REVPAP 0x020000 // bit 17 - Enables an interrupt when there is a sign change in the watt calculation among any one of the phases specified by the TERMSEL bits in the COMPMODE register.
|
||
#define REVPRP 0x040000 // bit 18 - Enables an interrupt when there is a sign change in the VAR calculation among any one of the phases specified by the TERMSEL bits in the COMPMODE register.
|
||
#define SEQERR 0x080000 // bit 19 - Enables an interrupt when the zero crossing from Phase A is followed not by the zero crossing of Phase C but with that of Phase B.
|
||
*/
|
||
/** INTERRUPT STATUS REGISTER (0x19)/RESET INTERRUPT STATUS REGISTER (0x1A)
|
||
The interrupt status register is used to determine the source of an interrupt event.
|
||
When an interrupt event occurs in the ADE7758, the corresponding flag in the interrupt status register is set.
|
||
The IRQ pin goes active low if the corresponding bit in the interrupt mask register is set.
|
||
When the MCU services the interrupt, it must first carry out a read from the interrupt status register to determine the source of the interrupt.
|
||
All the interrupts in the interrupt status register stay at their logic high state after an event occurs.
|
||
The state of the interrupt bit in the interrupt status register is reset to its default value once the reset interrupt status register is read.
|
||
**/
|
||
|
||
// The next table summarizes the function of each bit for
|
||
// the Interrupt Status Register, the Reset Interrupt Status Register.
|
||
|
||
// Bit Mask // Bit Location / Description
|
||
#define AEHF 0x0001 // bit 0 - Indicates that an interrupt was caused by a change in Bit 14 among any one of the three WATTHR registers, that is, the WATTHR register is half full.
|
||
#define REHF 0x0002 // bit 1 - Indicates that an interrupt was caused by a change in Bit 14 among any one of the three VARHR registers, that is, the VARHR register is half full.
|
||
#define VAEHF 0x0004 // bit 2 - Indicates that an interrupt was caused by a 0 to 1 transition in Bit 15 among any one of the three VAHR registers, that is, the VAHR register is half full.
|
||
#define SAGA 0x0008 // bit 3 - Indicates that an interrupt was caused by a SAG on the line voltage of the Phase A.
|
||
#define SAGB 0x0010 // bit 4 - Indicates that an interrupt was caused by a SAG on the line voltage of the Phase B.
|
||
#define SAGC 0x0020 // bit 5 - Indicates that an interrupt was caused by a SAG on the line voltage of the Phase C.
|
||
#define ZXTOA 0x0040 // bit 6 - Indicates that an interrupt was caused by a missing zero crossing on the line voltage of the Phase A.
|
||
#define ZXTOB 0x0080 // bit 7 - Indicates that an interrupt was caused by a missing zero crossing on the line voltage of the Phase B.
|
||
#define ZXTOC 0x0100 // bit 8 - Indicates that an interrupt was caused by a missing zero crossing on the line voltage of the Phase C
|
||
#define ZXA 0x0200 // bit 9 - Indicates a detection of a rising edge zero crossing in the voltage channel of Phase A.
|
||
#define ZXB 0x0400 // bit 10 - Indicates a detection of a rising edge zero crossing in the voltage channel of Phase B
|
||
#define ZXC 0x0800 // bit 11 - Indicates a detection of a rising edge zero crossing in the voltage channel of Phase C
|
||
#define LENERGY 0x1000 // bit 12 - In line energy accumulation, indicates the end of an integration over an integer number of half- line cycles (LINECYC). See the Calibration section.
|
||
#define RESET 0x2000 // bit 13 - Indicates that the 5 V power supply is below 4 V. Enables a software reset of the ADE7758 and sets the registers back to their default values. This bit in the STATUS or RSTATUS register is logic high for only one clock cycle after a reset event.
|
||
#define PKV 0x4000 // bit 14 - Indicates that an interrupt was caused when the selected voltage input is above the value in the VPINTLVL register.
|
||
#define PKI 0x8000 // bit 15 - Indicates that an interrupt was caused when the selected current input is above the value in the IPINTLVL register.
|
||
#define WFSM 0x010000 // bit 16 - Indicates that new data is present in the waveform register.
|
||
#define REVPAP 0x020000 // bit 17 - Indicates that an interrupt was caused by a sign change in the watt calculation among any one of the phases specified by the TERMSEL bits in the COMPMODE register.
|
||
#define REVPRP 0x040000 // bit 18 - Indicates that an interrupt was caused by a sign change in the VAR calculation among any one of the phases specified by the TERMSEL bits in the COMPMODE register.
|
||
#define SEQERR 0x080000 // bit 19 - Indicates that an interrupt was caused by a zero crossing from Phase A followed not by the zero crossing of Phase C but by that of Phase B.
|
||
|
||
|
||
//constants
|
||
#define GAIN_1 0x00
|
||
#define GAIN_2 0x01
|
||
#define GAIN_4 0x02
|
||
#define INTEGRATOR_ON 1
|
||
#define INTEGRATOR_OFF 0
|
||
#define FULLSCALESELECT_0_5V 0x00
|
||
#define FULLSCALESELECT_0_25V 0x01
|
||
#define FULLSCALESELECT_0_125V 0x02
|
||
|
||
esp_err_t transferByte(const uint8_t reg_addr, const uint8_t data, const uint8_t command);
|
||
esp_err_t transferMultiplesBytes(const uint8_t reg_addr, uint8_t *tx_buf, uint8_t *rx_buf, size_t data_length, const uint8_t command);
|
||
|
||
esp_err_t Init(const spi_host_device_t spi_peripheral, const int pin_miso, const int pin_mosi, const int pin_sclk);
|
||
esp_err_t InitSpi(const int ss);
|
||
|
||
esp_err_t RegisterDevice(const uint8_t mode, const int ss, const int addr_length, const int command_length, const int bus_speed);
|
||
uint8_t ReadRegister(const uint8_t reg_addr, const uint8_t command);
|
||
esp_err_t WriteRegister(const uint8_t reg_addr, const uint8_t reg_data, const uint8_t command);
|
||
esp_err_t WriteRegisterMultipleBytes(const uint8_t reg_addr, uint8_t *reg_data_buffer, const uint8_t byte_count, const uint8_t command);
|
||
esp_err_t ReadRegisterMultipleBytes(const uint8_t reg_addr, uint8_t *reg_data_buffer, const uint8_t byte_count, const uint8_t command);
|
||
spi_device_handle_t GetHandle();
|
||
|
||
|
||
//----------------------------------------------------------------------------
|
||
// Modes and configurations
|
||
//----------------------------------------------------------------------------
|
||
void setOpMode(uint8_t m);
|
||
uint8_t getOpMode();
|
||
void setMMode(uint8_t m);
|
||
uint8_t getMMode();
|
||
void setWavMode(uint8_t m);
|
||
uint8_t getWavMode();
|
||
void setCompMode(uint8_t m);
|
||
uint8_t getCompMode();
|
||
void setLcycMode(uint8_t m);
|
||
uint8_t getLcycMode();
|
||
void gainSetup(uint8_t integrator, uint8_t scale, uint8_t PGA2, uint8_t PGA1);
|
||
void setupDivs(uint8_t Watt_div,uint8_t VAR_div,uint8_t VA_div);
|
||
uint32_t getMaskInterrupts();
|
||
void setMaskInterrupts(uint32_t m);
|
||
uint32_t getStatus();
|
||
uint32_t resetStatus();
|
||
int32_t getAIRMS();
|
||
int32_t getBIRMS();
|
||
int32_t getCIRMS();
|
||
int32_t getAVRMS();
|
||
int32_t getBVRMS();
|
||
int32_t getCVRMS();
|
||
uint32_t avrms();
|
||
uint32_t bvrms();
|
||
uint32_t cvrms();
|
||
uint32_t airms();
|
||
uint32_t birms();
|
||
int32_t cirms();
|
||
int32_t getFreq();
|
||
void setLineCyc(uint32_t d);
|
||
int32_t getACurrentOffset();
|
||
int32_t getBCurrentOffset();
|
||
int32_t getCCurrentOffset();
|
||
void setACurrentOffset(int32_t o);
|
||
void setBCurrentOffset(int32_t o);
|
||
void setCCurrentOffset(int32_t o);
|
||
int32_t getAVoltageOffset();
|
||
int32_t getBVoltageOffset();
|
||
int32_t getCVoltageOffset();
|
||
void setAVoltageOffset(int32_t o);
|
||
void setBVoltageOffset(int32_t o);
|
||
void setCVoltageOffset(int32_t o);
|
||
void setAWattOffset(int32_t o);
|
||
void setBWattOffset(int32_t o);
|
||
void setCWattOffset(int32_t o);
|
||
void setZeroCrossingTimeout(int32_t d);
|
||
int32_t getZeroCrossingTimeout();
|
||
uint8_t setPotLine(uint8_t Phase, uint32_t Ciclos);
|
||
int32_t getWatt(uint8_t Phase);
|
||
int32_t getVar(uint8_t Phase);
|
||
int32_t getVa(uint8_t Phase);
|
||
uint8_t getVersion();
|
||
uint8_t read8(uint8_t reg);
|
||
uint32_t read16(uint8_t reg);
|
||
uint32_t read24(uint8_t reg);
|
||
|
||
esp_err_t write24(uint8_t reg, uint32_t data);
|
||
esp_err_t write16(uint8_t reg, uint32_t data);
|
||
esp_err_t write8(uint8_t reg, uint8_t data);
|
||
|
||
void enableADE7758Chip();
|
||
void disableADE7758Chip();
|
||
void setAPCFDEN(int32_t d);
|
||
int32_t getAPCFDEN();
|
||
void setAPCFNUM(int32_t d);
|
||
int32_t getAPCFNUM();
|
||
void setVARCFNUM(int32_t d);
|
||
int32_t getVARCFNUM();
|
||
void setVARCFDEN(int32_t d);
|
||
int32_t getVARCFDEN();
|
||
void setAWG(int32_t d);
|
||
int32_t getAWG();
|
||
void setBWG(int32_t d);
|
||
void setCWG(int32_t d);
|
||
void setAVARG(int32_t d);
|
||
int32_t getAVARG();
|
||
void setBVARG(int32_t d);
|
||
int32_t getBVARG();
|
||
void setCVARG(int32_t d);
|
||
int32_t getCVARG();
|
||
void setAVAG(int32_t d);
|
||
void setBVAG(int32_t d);
|
||
void setCVAG(int32_t d);
|
||
// === Fim de: components/meter_manager/driver/meter_ade7758/ade7758.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/modbus_params.h ===
|
||
/*
|
||
* SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
|
||
*
|
||
* SPDX-License-Identifier: Apache-2.0
|
||
*/
|
||
|
||
#ifndef _DEVICE_PARAMS
|
||
#define _DEVICE_PARAMS
|
||
|
||
#include <stdint.h>
|
||
|
||
#pragma pack(push, 1)
|
||
|
||
// Discrete Inputs
|
||
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;
|
||
|
||
// Coils
|
||
typedef struct {
|
||
uint8_t coils_port0;
|
||
uint8_t coils_port1;
|
||
uint8_t coils_port2;
|
||
} coil_reg_params_t;
|
||
|
||
// Input Registers (pode manter caso use em outro driver)
|
||
typedef struct {
|
||
float input_data0;
|
||
float input_data1;
|
||
float input_data2;
|
||
float input_data3;
|
||
uint16_t data[150];
|
||
float input_data4;
|
||
float input_data5;
|
||
float input_data6;
|
||
float input_data7;
|
||
uint16_t data_block1[150];
|
||
} input_reg_params_t;
|
||
|
||
|
||
// Holding Registers (ajustado para os campos usados no ORNO 516)
|
||
typedef struct {
|
||
float l1_current;
|
||
float l2_current;
|
||
float l3_current;
|
||
|
||
float l1_voltage;
|
||
float l2_voltage;
|
||
float l3_voltage;
|
||
|
||
float active_energy;
|
||
float reactive_energy;
|
||
|
||
float active_power;
|
||
float apparent_power;
|
||
float reactive_power;
|
||
|
||
float frequency;
|
||
float power_factor;
|
||
} holding_reg_params_t;
|
||
|
||
|
||
|
||
#pragma pack(pop)
|
||
|
||
// Instâncias globais das estruturas
|
||
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 // !_DEVICE_PARAMS
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/modbus_params.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_orno.h ===
|
||
#ifndef ORNO_MODBUS_H_
|
||
#define ORNO_MODBUS_H_
|
||
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
|
||
#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
|
||
|
||
#endif /* ORNO_MODBUS_H_ */
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_orno.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_ea777.h ===
|
||
#ifndef METER_DTS6619_H_
|
||
#define METER_DTS6619_H_
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor dts6619 (SPI, mutex, registradores).
|
||
*
|
||
* @return esp_err_t Retorna ESP_OK se a inicialização for bem-sucedida, caso contrário retorna um erro.
|
||
*/
|
||
esp_err_t meter_dts6619_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor DTS6619.
|
||
*
|
||
* @return esp_err_t Retorna ESP_OK se a tarefa for iniciada com sucesso, caso contrário retorna um erro.
|
||
*/
|
||
esp_err_t meter_dts6619_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor DTS6619.
|
||
*/
|
||
void meter_dts6619_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* METER_DTS6619_H_ */
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_ea777.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_orno513.h ===
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor ORNO 513 (SPI, mutex, registradores).
|
||
*/
|
||
esp_err_t meter_orno513_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor ORNO 513.
|
||
*/
|
||
esp_err_t meter_orno513_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor ORNO 513.
|
||
*/
|
||
void meter_orno513_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_orno513.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_orno516.h ===
|
||
#ifndef METER_ORNO516_H_
|
||
#define METER_ORNO516_H_
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor ORNO 516 (SPI, mutex, registradores).
|
||
*
|
||
* @return esp_err_t Retorna ESP_OK se a inicialização for bem-sucedida, caso contrário retorna um erro.
|
||
*/
|
||
esp_err_t meter_orno516_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor ORNO 516.
|
||
*
|
||
* @return esp_err_t Retorna ESP_OK se a tarefa for iniciada com sucesso, caso contrário retorna um erro.
|
||
*/
|
||
esp_err_t meter_orno516_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor ORNO 516.
|
||
*/
|
||
void meter_orno516_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* METER_ORNO516_H_ */
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_orno516.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_orno526.h ===
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor ORNO 526 (SPI, mutex, registradores).
|
||
*/
|
||
esp_err_t meter_orno526_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor ORNO 526.
|
||
*/
|
||
esp_err_t meter_orno526_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor ORNO 526.
|
||
*/
|
||
void meter_orno526_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_orno526.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_dds661.h ===
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor DDS 661 (SPI, mutex, registradores).
|
||
*/
|
||
esp_err_t meter_dds661_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor DDS 661.
|
||
*/
|
||
esp_err_t meter_dds661_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor DDS 661.
|
||
*/
|
||
void meter_dds661_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_dds661.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_orno/meter_dts6619.h ===
|
||
#ifndef METER_EA777_H_
|
||
#define METER_EA777_H_
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor EA777 (UART RS485, Modbus, registradores).
|
||
*
|
||
* @return esp_err_t Retorna ESP_OK se a inicialização for bem-sucedida, caso contrário retorna um erro.
|
||
*/
|
||
esp_err_t meter_ea777_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura de dados do medidor EA777.
|
||
*
|
||
* @return esp_err_t Retorna ESP_OK se a tarefa for iniciada com sucesso, caso contrário retorna um erro.
|
||
*/
|
||
esp_err_t meter_ea777_start(void);
|
||
|
||
/**
|
||
* @brief Para a tarefa de leitura e limpa os dados internos do medidor EA777.
|
||
*/
|
||
void meter_ea777_stop(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* METER_EA777_H_ */
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_orno/meter_dts6619.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/driver/meter_zigbee/meter_zigbee.h ===
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_err.h"
|
||
|
||
/**
|
||
* @brief Inicializa o driver do medidor Zigbee (UART, mutex, etc.).
|
||
*
|
||
* @return ESP_OK se a inicialização for bem-sucedida, erro caso contrário.
|
||
*/
|
||
esp_err_t meter_zigbee_init(void);
|
||
|
||
/**
|
||
* @brief Inicia a tarefa de leitura dos dados do medidor Zigbee.
|
||
*
|
||
* @return ESP_OK se a tarefa for iniciada com sucesso, erro caso contrário.
|
||
*/
|
||
esp_err_t meter_zigbee_start(void);
|
||
|
||
/**
|
||
* @brief Interrompe a tarefa e limpa recursos (UART, mutex, etc.).
|
||
*/
|
||
void meter_zigbee_stop(void);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/meter_manager/driver/meter_zigbee/meter_zigbee.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/include/meter_manager.h ===
|
||
#ifndef METER_MANAGER_H
|
||
#define METER_MANAGER_H
|
||
|
||
#include "esp_err.h"
|
||
#include <stdbool.h>
|
||
|
||
/**
|
||
* @brief Supported meter types for EVSE and Grid.
|
||
*/
|
||
typedef enum {
|
||
METER_TYPE_NONE, // No meter
|
||
METER_TYPE_ADE7758, // ADE7758 meter
|
||
METER_TYPE_ORNO513, // ORNO-513
|
||
METER_TYPE_ORNO516, // ORNO-516
|
||
METER_TYPE_ORNO526, // ORNO-516
|
||
METER_TYPE_DDS661, // DDS-661
|
||
METER_TYPE_DTS6619, // dts6619
|
||
METER_TYPE_MONO_ZIGBEE, // Zigbee single-phase
|
||
METER_TYPE_TRIF_ZIGBEE, // Zigbee three-phase
|
||
METER_TYPE_EA777 // EA777
|
||
} meter_type_t;
|
||
|
||
/**
|
||
* @brief Initializes the meter manager system.
|
||
*
|
||
* Registers network event handlers and initializes both EVSE and GRID meters.
|
||
*/
|
||
esp_err_t meter_manager_init(void);
|
||
|
||
|
||
/**
|
||
* @brief Starts all configured meters (EVSE and GRID).
|
||
*
|
||
* @return esp_err_t ESP_OK on success, or an error code from one of the start calls.
|
||
*/
|
||
esp_err_t meter_manager_start(void);
|
||
|
||
|
||
/**
|
||
* @brief Stops all meters and unregisters network event handlers.
|
||
*/
|
||
esp_err_t meter_manager_stop(void);
|
||
|
||
/**
|
||
* @brief EVSE Meter Management
|
||
*/
|
||
|
||
/**
|
||
* @brief Initializes the EVSE meter based on configured type.
|
||
*/
|
||
esp_err_t meter_manager_evse_init(void);
|
||
|
||
/**
|
||
* @brief Starts the EVSE meter.
|
||
*/
|
||
esp_err_t meter_manager_evse_start(void);
|
||
|
||
/**
|
||
* @brief Stops the EVSE meter.
|
||
*/
|
||
esp_err_t meter_manager_evse_stop(void);
|
||
|
||
/**
|
||
* @brief Returns true if an EVSE meter is configured (not NONE).
|
||
*/
|
||
bool meter_manager_evse_is_enabled(void);
|
||
|
||
/**
|
||
* @brief Sets the EVSE meter type and saves it to NVS.
|
||
*/
|
||
esp_err_t meter_manager_evse_set_model(meter_type_t meter_type);
|
||
|
||
/**
|
||
* @brief Gets the current EVSE meter type.
|
||
*/
|
||
meter_type_t meter_manager_evse_get_model(void);
|
||
|
||
/**
|
||
* @brief Grid Meter Management
|
||
*/
|
||
|
||
/**
|
||
* @brief Initializes the Grid meter based on configured type.
|
||
*/
|
||
esp_err_t meter_manager_grid_init(void);
|
||
|
||
/**
|
||
* @brief Starts the Grid meter.
|
||
*/
|
||
esp_err_t meter_manager_grid_start(void);
|
||
|
||
/**
|
||
* @brief Stops the Grid meter.
|
||
*/
|
||
esp_err_t meter_manager_grid_stop(void);
|
||
|
||
/**
|
||
* @brief Sets the Grid meter type and saves it to NVS.
|
||
*/
|
||
esp_err_t meter_manager_grid_set_model(meter_type_t meter_type);
|
||
|
||
/**
|
||
* @brief Gets the current Grid meter type.
|
||
*/
|
||
meter_type_t meter_manager_grid_get_model(void);
|
||
|
||
/**
|
||
* @brief Utility functions
|
||
*/
|
||
|
||
/**
|
||
* @brief Converts a meter_type_t to a human-readable string.
|
||
*/
|
||
const char* meter_type_to_str(meter_type_t type);
|
||
|
||
/**
|
||
* @brief Converts a string to a meter_type_t.
|
||
*/
|
||
meter_type_t string_to_meter_type(const char *str);
|
||
|
||
#endif // METER_MANAGER_H
|
||
|
||
// === Fim de: components/meter_manager/include/meter_manager.h ===
|
||
|
||
|
||
// === Início de: components/meter_manager/include/meter_events.h ===
|
||
#ifndef METER_EVENTS_H
|
||
#define METER_EVENTS_H
|
||
|
||
#include "esp_event.h"
|
||
#include "meter_manager.h" // Para meter_type_t
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
// Base de eventos dos medidores
|
||
ESP_EVENT_DECLARE_BASE(METER_EVENT);
|
||
|
||
// IDs de eventos emitidos por medidores
|
||
typedef enum {
|
||
METER_EVENT_DATA_READY = 0,
|
||
METER_EVENT_ERROR,
|
||
METER_EVENT_STARTED,
|
||
METER_EVENT_STOPPED
|
||
} meter_event_id_t;
|
||
|
||
// Estrutura de dados enviados com METER_EVENT_DATA_READY
|
||
typedef struct {
|
||
const char *source; // "GRID" ou "EVSE"
|
||
float vrms[3]; // Tensão por fase
|
||
float irms[3]; // Corrente por fase
|
||
int watt[3]; // Potência ativa por fase
|
||
float frequency; // Frequência da rede (Hz)
|
||
float power_factor; // Fator de potência
|
||
float total_energy; // Energia acumulada (kWh)
|
||
} meter_event_data_t;
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // METER_EVENTS_H
|
||
|
||
// === Fim de: components/meter_manager/include/meter_events.h ===
|
||
|
||
|
||
// === Início de: components/loadbalancer/include/loadbalancer_events.h ===
|
||
#pragma once
|
||
#include "esp_event.h"
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "esp_timer.h"
|
||
|
||
ESP_EVENT_DECLARE_BASE(LOADBALANCER_EVENTS);
|
||
|
||
typedef enum {
|
||
LOADBALANCER_EVENT_INIT,
|
||
LOADBALANCER_EVENT_STATE_CHANGED,
|
||
LOADBALANCER_EVENT_GLOBAL_CURRENT_LIMIT,
|
||
LOADBALANCER_EVENT_MASTER_CURRENT_LIMIT,
|
||
LOADBALANCER_EVENT_SLAVE_CURRENT_LIMIT,
|
||
LOADBALANCER_EVENT_SLAVE_STATUS
|
||
} loadbalancer_event_id_t;
|
||
|
||
typedef struct {
|
||
bool enabled;
|
||
int64_t timestamp_us;
|
||
} loadbalancer_state_event_t;
|
||
|
||
// (opcional)
|
||
typedef struct {
|
||
float limit;
|
||
int64_t timestamp_us;
|
||
} loadbalancer_global_limit_event_t;
|
||
|
||
typedef struct {
|
||
uint8_t slave_id;
|
||
uint16_t max_current;
|
||
int64_t timestamp_us;
|
||
} loadbalancer_master_limit_event_t;
|
||
|
||
typedef struct {
|
||
uint8_t slave_id;
|
||
uint16_t max_current;
|
||
int64_t timestamp_us;
|
||
} loadbalancer_slave_limit_event_t;
|
||
|
||
typedef struct {
|
||
uint8_t slave_id; // ID do slave que reportou
|
||
bool charging; // Status de carregamento
|
||
float hw_max_current; // Limite máximo de corrente do hardware informado
|
||
float runtime_current; // Corrente atual de carregamento (A)
|
||
int64_t timestamp_us; // Momento em que o status foi coletado
|
||
} loadbalancer_slave_status_event_t;
|
||
// === Fim de: components/loadbalancer/include/loadbalancer_events.h ===
|
||
|
||
|
||
// === Início de: components/loadbalancer/include/loadbalancer.h ===
|
||
#ifndef LOADBALANCER_H_
|
||
#define LOADBALANCER_H_
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
#include "esp_err.h"
|
||
|
||
|
||
/**
|
||
* @brief Inicializa o módulo de load balancer
|
||
*/
|
||
void loadbalancer_init(void);
|
||
|
||
/**
|
||
* @brief Task contínua do algoritmo de balanceamento
|
||
*/
|
||
void loadbalancer_task(void *param);
|
||
|
||
/**
|
||
* @brief Ativa ou desativa o load balancing
|
||
*/
|
||
void loadbalancer_set_enabled(bool value);
|
||
|
||
/**
|
||
* @brief Verifica se o load balancing está ativo
|
||
*/
|
||
bool loadbalancer_is_enabled(void);
|
||
|
||
/**
|
||
* @brief Define a corrente máxima do grid
|
||
*/
|
||
esp_err_t load_balancing_set_max_grid_current(uint8_t max_grid_current);
|
||
|
||
/**
|
||
* @brief Obtém a corrente máxima do grid
|
||
*/
|
||
uint8_t load_balancing_get_max_grid_current(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* LOADBALANCER_H_ */
|
||
|
||
// === Fim de: components/loadbalancer/include/loadbalancer.h ===
|
||
|
||
|
||
// === Início de: components/loadbalancer/include/input_filter.h ===
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
typedef struct {
|
||
float alpha; ///< Fator de suavização (0.0 a 1.0)
|
||
float value; ///< Último valor filtrado
|
||
int initialized; ///< Flag de inicialização
|
||
} input_filter_t;
|
||
|
||
/**
|
||
* @brief Inicializa o filtro com o fator alpha desejado.
|
||
* @param filter Ponteiro para a estrutura do filtro
|
||
* @param alpha Valor entre 0.0 (mais lento) e 1.0 (sem filtro)
|
||
*/
|
||
void input_filter_init(input_filter_t *filter, float alpha);
|
||
|
||
/**
|
||
* @brief Atualiza o valor filtrado com uma nova entrada.
|
||
* @param filter Ponteiro para o filtro
|
||
* @param input Valor bruto
|
||
* @return Valor suavizado
|
||
*/
|
||
float input_filter_update(input_filter_t *filter, float input);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/loadbalancer/include/input_filter.h ===
|
||
|
||
|
||
// === Início de: components/auth/include/auth.h ===
|
||
#pragma once
|
||
#include <stdbool.h>
|
||
#include "auth_types.h" // enum + MAX LEN para API
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/* Evento auxiliar legado/útil (resultado local) */
|
||
typedef struct {
|
||
char tag[AUTH_TAG_MAX_LEN];
|
||
bool authorized;
|
||
} auth_event_t;
|
||
|
||
void auth_init(void);
|
||
void auth_set_mode(auth_mode_t mode);
|
||
auth_mode_t auth_get_mode(void);
|
||
|
||
bool auth_add_tag(const char *tag);
|
||
bool auth_remove_tag(const char *tag);
|
||
bool auth_tag_exists(const char *tag);
|
||
void auth_list_tags(void);
|
||
|
||
void auth_process_tag(const char *tag);
|
||
void auth_wait_for_tag_registration(void);
|
||
|
||
int auth_get_tag_count(void);
|
||
const char *auth_get_tag_by_index(int index);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/auth/include/auth.h ===
|
||
|
||
|
||
// === Início de: components/auth/include/auth_events.h ===
|
||
#pragma once
|
||
#include "esp_event.h"
|
||
#include "auth_types.h" // só tipos comuns; evita incluir auth.h
|
||
|
||
ESP_EVENT_DECLARE_BASE(AUTH_EVENTS);
|
||
|
||
/* IDs de eventos */
|
||
typedef enum {
|
||
AUTH_EVENT_TAG_PROCESSED = 0, // resultado LOCAL -> auth_tag_event_data_t
|
||
AUTH_EVENT_TAG_VERIFY, // pedir validação OCPP -> auth_tag_verify_event_t
|
||
AUTH_EVENT_TAG_SAVED, // registada (modo registo) -> auth_tag_event_data_t
|
||
AUTH_EVENT_MODE_CHANGED, // modo alterado -> auth_mode_event_data_t
|
||
AUTH_EVENT_INIT, // estado inicial -> auth_mode_event_data_t
|
||
} auth_event_id_t;
|
||
|
||
/* Payloads */
|
||
typedef struct {
|
||
char tag[AUTH_TAG_MAX_LEN];
|
||
bool authorized;
|
||
} auth_tag_event_data_t;
|
||
|
||
typedef struct {
|
||
char tag[AUTH_TAG_MAX_LEN];
|
||
uint32_t req_id; // opcional p/ correlacionar
|
||
} auth_tag_verify_event_t;
|
||
|
||
typedef struct {
|
||
auth_mode_t mode;
|
||
} auth_mode_event_data_t;
|
||
|
||
// === Fim de: components/auth/include/auth_events.h ===
|
||
|
||
|
||
// === Início de: components/auth/include/wiegand.h ===
|
||
/*
|
||
* Copyright (c) 2021 Ruslan V. Uss <unclerus@gmail.com>
|
||
*
|
||
* Redistribution and use in source and binary forms, with or without
|
||
* modification, are permitted provided that the following conditions are met:
|
||
*
|
||
* 1. Redistributions of source code must retain the above copyright notice,
|
||
* this list of conditions and the following disclaimer.
|
||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||
* this list of conditions and the following disclaimer in the documentation
|
||
* and/or other materials provided with the distribution.
|
||
* 3. Neither the name of the copyright holder nor the names of itscontributors
|
||
* may be used to endorse or promote products derived from this software without
|
||
* specific prior written permission.
|
||
*
|
||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
*/
|
||
|
||
/**
|
||
* @file wiegand.h
|
||
* @defgroup wiegand wiegand
|
||
* @{
|
||
*
|
||
* ESP-IDF Wiegand protocol receiver
|
||
*
|
||
* Copyright (c) 2021 Ruslan V. Uss <unclerus@gmail.com>
|
||
*
|
||
* BSD Licensed as described in the file LICENSE
|
||
*/
|
||
#ifndef __WIEGAND_H__
|
||
#define __WIEGAND_H__
|
||
|
||
#include <driver/gpio.h>
|
||
#include <esp_err.h>
|
||
#include <esp_timer.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
typedef struct wiegand_reader wiegand_reader_t;
|
||
|
||
typedef void (*wiegand_callback_t)(wiegand_reader_t *reader);
|
||
|
||
/**
|
||
* Bit and byte order of data
|
||
*/
|
||
typedef enum {
|
||
WIEGAND_MSB_FIRST = 0,
|
||
WIEGAND_LSB_FIRST
|
||
} wiegand_order_t;
|
||
|
||
/**
|
||
* Wiegand reader descriptor
|
||
*/
|
||
struct wiegand_reader
|
||
{
|
||
gpio_num_t gpio_d0, gpio_d1;
|
||
wiegand_callback_t callback;
|
||
wiegand_order_t bit_order;
|
||
wiegand_order_t byte_order;
|
||
|
||
uint8_t *buf;
|
||
size_t size;
|
||
size_t bits;
|
||
esp_timer_handle_t timer;
|
||
bool start_parity;
|
||
bool enabled;
|
||
};
|
||
|
||
/**
|
||
* @brief Create and initialize reader instance.
|
||
*
|
||
* @param reader Reader descriptor
|
||
* @param gpio_d0 GPIO pin for D0
|
||
* @param gpio_d1 GPIO pin for D0
|
||
* @param internal_pullups Enable internal pull-up resistors for D0 and D1 GPIO
|
||
* @param buf_size Reader buffer size in bytes, must be large enough to
|
||
* contain entire Wiegand key
|
||
* @param callback Callback function for processing received codes
|
||
* @param bit_order Bit order of data
|
||
* @param byte_order Byte order of data
|
||
* @return `ESP_OK` on success
|
||
*/
|
||
esp_err_t wiegand_reader_init(wiegand_reader_t *reader, gpio_num_t gpio_d0, gpio_num_t gpio_d1,
|
||
bool internal_pullups, size_t buf_size, wiegand_callback_t callback, wiegand_order_t bit_order,
|
||
wiegand_order_t byte_order);
|
||
|
||
/**
|
||
* @brief Disable reader
|
||
*
|
||
* While reader is disabled, it will not receive new data
|
||
*
|
||
* @param reader Reader descriptor
|
||
* @return `ESP_OK` on success
|
||
*/
|
||
esp_err_t wiegand_reader_disable(wiegand_reader_t *reader);
|
||
|
||
/**
|
||
* @brief Enable reader
|
||
*
|
||
* @param reader Reader descriptor
|
||
* @return `ESP_OK` on success
|
||
*/
|
||
esp_err_t wiegand_reader_enable(wiegand_reader_t *reader);
|
||
|
||
/**
|
||
* @brief Delete reader instance.
|
||
*
|
||
* @param reader Reader descriptor
|
||
* @return `ESP_OK` on success
|
||
*/
|
||
esp_err_t wiegand_reader_done(wiegand_reader_t *reader);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
/**@}*/
|
||
|
||
#endif /* __WIEGAND_H__ */
|
||
|
||
// === Fim de: components/auth/include/wiegand.h ===
|
||
|
||
|
||
// === Início de: components/auth/include/auth_types.h ===
|
||
#pragma once
|
||
#include <stdbool.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/* Tamanho máx. da tag (inclui NUL) */
|
||
#define AUTH_TAG_MAX_LEN 30
|
||
|
||
/* Modos de autorização */
|
||
typedef enum {
|
||
AUTH_MODE_OPEN = 0, // Sem autenticação
|
||
AUTH_MODE_LOCAL_RFID, // Lista local (NVS)
|
||
AUTH_MODE_OCPP_RFID // Validação via OCPP/CSMS
|
||
} auth_mode_t;
|
||
|
||
/* Converte enum -> "open"|"local"|"ocpp" (nunca NULL) */
|
||
const char *auth_mode_to_str(auth_mode_t mode);
|
||
|
||
/* Converte "open"|"local"|"ocpp" (case-insensitive) -> enum */
|
||
bool auth_mode_from_str(const char *s, auth_mode_t *out);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/auth/include/auth_types.h ===
|
||
|
||
|
||
// === Início de: components/auth/include/wiegand_reader.h ===
|
||
#ifndef WIEGAND_READER_H
|
||
#define WIEGAND_READER_H
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
void initWiegand(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // WIEGAND_READER_H
|
||
|
||
// === Fim de: components/auth/include/wiegand_reader.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_pilot.h ===
|
||
#ifndef PILOT_H_
|
||
#define PILOT_H_
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
|
||
/**
|
||
* @brief Níveis categóricos de tensão no sinal CP (Control Pilot)
|
||
*/
|
||
typedef enum
|
||
{
|
||
PILOT_VOLTAGE_12, ///< Estado A: +12V
|
||
PILOT_VOLTAGE_9, ///< Estado B: +9V
|
||
PILOT_VOLTAGE_6, ///< Estado C: +6V
|
||
PILOT_VOLTAGE_3, ///< Estado D: +3V
|
||
PILOT_VOLTAGE_1 ///< Estado E/F: abaixo de 3V
|
||
} pilot_voltage_t;
|
||
|
||
/**
|
||
* @brief Inicializa o driver do sinal Pilot
|
||
*/
|
||
void pilot_init(void);
|
||
|
||
/**
|
||
* @brief Define o nível do Pilot: +12V ou -12V
|
||
*
|
||
* @param level true = +12V, false = -12V
|
||
*/
|
||
void pilot_set_level(bool level);
|
||
|
||
/**
|
||
* @brief Ativa o PWM do Pilot com corrente limitada
|
||
*
|
||
* @param amps Corrente em ampères (ex: 16 = 16A)
|
||
*/
|
||
void pilot_set_amps(uint16_t amps);
|
||
|
||
/**
|
||
* @brief Mede o nível de tensão do Pilot e detecta -12V
|
||
*
|
||
* @param up_voltage Valor categórico da tensão positiva
|
||
* @param down_voltage_n12 true se o nível negativo atingir -12V
|
||
*/
|
||
void pilot_measure(pilot_voltage_t *up_voltage, bool *down_voltage_n12);
|
||
|
||
/**
|
||
* @brief Retorna o estado lógico atual do Pilot (nível alto = +12V)
|
||
*
|
||
* @return true se nível atual for +12V, false se for -12V
|
||
*/
|
||
bool pilot_get_state(void);
|
||
|
||
/**
|
||
* @brief Cache interno opcional dos níveis de tensão reais do Pilot
|
||
*/
|
||
typedef struct {
|
||
uint16_t high_mv; ///< Pico positivo medido (mV)
|
||
uint16_t low_mv; ///< Pico negativo medido (mV)
|
||
} pilot_voltage_cache_t;
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* PILOT_H_ */
|
||
|
||
// === Fim de: components/evse/include/evse_pilot.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_manager.h ===
|
||
#ifndef EVSE_MANAGER_H
|
||
#define EVSE_MANAGER_H
|
||
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
#include <freertos/FreeRTOS.h>
|
||
#include <freertos/queue.h>
|
||
|
||
/**
|
||
* @brief Inicializa os módulos internos do EVSE (hardware, estado, erros, etc.)
|
||
* e inicia a tarefa de supervisão periódica (tick).
|
||
*/
|
||
void evse_manager_init(void);
|
||
|
||
/**
|
||
* @brief Executa uma iteração do ciclo de controle do EVSE.
|
||
*
|
||
* Esta função é chamada automaticamente pela task periódica,
|
||
* mas pode ser chamada manualmente em testes.
|
||
*/
|
||
void evse_manager_tick(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
|
||
#endif // EVSE_MANAGER_H
|
||
|
||
// === Fim de: components/evse/include/evse_manager.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_fsm.h ===
|
||
#ifndef EVSE_FSM_H
|
||
#define EVSE_FSM_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "evse_api.h"
|
||
#include "evse_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
|
||
|
||
// === Fim de: components/evse/include/evse_fsm.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_hardware.h ===
|
||
#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
|
||
|
||
// === Fim de: components/evse/include/evse_hardware.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_config.h ===
|
||
#ifndef EVSE_CONFIG_H
|
||
#define EVSE_CONFIG_H
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
#include "esp_err.h"
|
||
#include "freertos/FreeRTOS.h"
|
||
#include "evse_events.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 32 // 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);
|
||
|
||
// Configuração de socket outlet
|
||
bool evse_get_socket_outlet(void);
|
||
esp_err_t evse_set_socket_outlet(bool socket_outlet);
|
||
|
||
void evse_set_runtime_charging_current(uint16_t value);
|
||
uint16_t evse_get_runtime_charging_current(void);
|
||
|
||
|
||
// 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);
|
||
|
||
// 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
|
||
|
||
// === Fim de: components/evse/include/evse_config.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_state.h ===
|
||
#ifndef EVSE_STATE_H
|
||
#define EVSE_STATE_H
|
||
|
||
#include <stdbool.h>
|
||
#include "freertos/FreeRTOS.h"
|
||
#include "evse_events.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
// ============================
|
||
// EVSE Pilot Signal States
|
||
// ============================
|
||
|
||
typedef enum {
|
||
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
|
||
// ============================
|
||
|
||
/**
|
||
* @brief Initializes the EVSE state machine and default state.
|
||
*/
|
||
void evse_state_init(void);
|
||
|
||
/**
|
||
* @brief Periodic tick for state handling (optional hook).
|
||
*/
|
||
void evse_state_tick(void);
|
||
|
||
// ============================
|
||
// State Access & Control
|
||
// ============================
|
||
|
||
/**
|
||
* @brief Returns the current EVSE state.
|
||
*/
|
||
evse_state_t evse_get_state(void);
|
||
|
||
/**
|
||
* @brief Sets the current EVSE state and emits a change event if needed.
|
||
*/
|
||
void evse_set_state(evse_state_t state);
|
||
|
||
/**
|
||
* @brief Converts the state enum into a human-readable string.
|
||
*/
|
||
const char* evse_state_to_str(evse_state_t state);
|
||
|
||
// ============================
|
||
// State Evaluation Helpers
|
||
// ============================
|
||
|
||
/**
|
||
* @brief True if EV is in an active session (B2, C1, C2).
|
||
*/
|
||
bool evse_state_is_session(evse_state_t state);
|
||
|
||
/**
|
||
* @brief True if EV is actively charging (C1, C2).
|
||
*/
|
||
bool evse_state_is_charging(evse_state_t state);
|
||
|
||
/**
|
||
* @brief True if EV is physically plugged in (B1 and beyond).
|
||
*/
|
||
bool evse_state_is_plugged(evse_state_t state);
|
||
|
||
// ============================
|
||
// Authorization Control
|
||
// ============================
|
||
|
||
/**
|
||
* @brief Sets whether the EV is authorized to charge.
|
||
*/
|
||
void evse_state_set_authorized(bool authorized);
|
||
|
||
/**
|
||
* @brief Gets whether the EV is currently authorized.
|
||
*/
|
||
bool evse_state_get_authorized(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // EVSE_STATE_H
|
||
|
||
// === Fim de: components/evse/include/evse_state.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_error.h ===
|
||
// === Início de: components/evse/include/evse_error.h ===
|
||
#ifndef EVSE_ERROR_H
|
||
#define EVSE_ERROR_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "evse_pilot.h"
|
||
|
||
// Bits que auto-limpam passado um timeout
|
||
#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);
|
||
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);
|
||
|
||
// ----------------------------------------------------
|
||
// Semântica sticky: flag "todos erros limpos"
|
||
// ----------------------------------------------------
|
||
// Fica true quando TODOS os erros são limpos.
|
||
// Volta a false assim que qualquer erro novo aparece.
|
||
// Permanece true até o consumidor limpar explicitamente.
|
||
bool evse_error_cleared_flag(void);
|
||
void evse_error_reset_flag(void);
|
||
|
||
#endif // EVSE_ERROR_H
|
||
// === Fim de: components/evse/include/evse_error.h ===
|
||
|
||
// === Fim de: components/evse/include/evse_error.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_session.h ===
|
||
/*
|
||
* evse_session.h
|
||
* Module to track and retrieve charging session data (current or last completed),
|
||
* accumulating energy via periodic tick of instantaneous power.
|
||
*/
|
||
|
||
#ifndef EVSE_SESSION_H
|
||
#define EVSE_SESSION_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "freertos/FreeRTOS.h"
|
||
|
||
/**
|
||
* @brief Charging session statistics
|
||
*/
|
||
typedef struct {
|
||
TickType_t start_tick; ///< tick when session began
|
||
uint32_t duration_s; ///< total duration in seconds
|
||
uint32_t energy_wh; ///< total energy consumed in Wh
|
||
uint32_t avg_power_w; ///< average power in W
|
||
bool is_current; ///< true if session still in progress
|
||
} evse_session_t;
|
||
|
||
/**
|
||
* @brief Initialize the session module
|
||
*/
|
||
void evse_session_init(void);
|
||
|
||
/**
|
||
* @brief Mark the beginning of a charging session
|
||
*/
|
||
void evse_session_start(void);
|
||
|
||
/**
|
||
* @brief Mark the end of the charging session and store it as "last session"
|
||
*/
|
||
void evse_session_end(void);
|
||
|
||
/**
|
||
* @brief Periodic tick: must be called (e.g., each 1s) to accumulate energy from instant power
|
||
*/
|
||
void evse_session_tick(void);
|
||
|
||
/**
|
||
* @brief Retrieve statistics of either the current ongoing session (if any) or
|
||
* the last completed session.
|
||
* @param out pointer to evse_session_t to be filled
|
||
* @return true if there is a current or last session available, false otherwise
|
||
*/
|
||
bool evse_session_get(evse_session_t *out);
|
||
|
||
#endif // EVSE_SESSION_H
|
||
|
||
// === Fim de: components/evse/include/evse_session.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_meter.h ===
|
||
#ifndef EVSE_METER_H
|
||
#define EVSE_METER_H
|
||
|
||
#include <stdint.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#define EVSE_METER_PHASE_COUNT 3
|
||
|
||
/// Inicializa o módulo EVSE Meter e registra os tratadores de eventos
|
||
void evse_meter_init(void);
|
||
|
||
/// Retorna a potência instantânea (soma das 3 fases, em watts)
|
||
int evse_meter_get_instant_power(void);
|
||
|
||
/// Retorna a energia total acumulada (em Wh)
|
||
int evse_meter_get_total_energy(void);
|
||
|
||
/// Retorna as potências instantâneas nas fases L1, L2 e L3 (em watts)
|
||
void evse_meter_get_power(int power[EVSE_METER_PHASE_COUNT]);
|
||
|
||
/// Retorna as tensões medidas nas fases L1, L2 e L3 (em volts)
|
||
void evse_meter_get_voltage(float voltage[EVSE_METER_PHASE_COUNT]);
|
||
|
||
/// Retorna as correntes medidas nas fases L1, L2 e L3 (em amperes)
|
||
void evse_meter_get_current(float current[EVSE_METER_PHASE_COUNT]);
|
||
|
||
/// Handler interno para eventos do medidor (não chamar externamente)
|
||
void evse_meter_on_meter_event(void* arg, void* event_data);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // EVSE_METER_H
|
||
|
||
// === Fim de: components/evse/include/evse_meter.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_core.h ===
|
||
#ifndef EVSE_CORE_H
|
||
#define EVSE_CORE_H
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/**
|
||
* @brief Initializes the EVSE system and starts core task loop.
|
||
*/
|
||
void evse_init(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // EVSE_CORE_H
|
||
|
||
// === Fim de: components/evse/include/evse_core.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_limits.h ===
|
||
// === Início de: components/evse/include/evse_limits.h ===
|
||
#ifndef EVSE_LIMITS_H
|
||
#define EVSE_LIMITS_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "evse_state.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
// ============================
|
||
// Limit Status & Evaluation
|
||
// ============================
|
||
|
||
/**
|
||
* @brief Sets the internal 'limit reached' flag.
|
||
*/
|
||
void evse_set_limit_reached(bool value);
|
||
|
||
/**
|
||
* @brief Returns true if any runtime charging limit has been reached.
|
||
*/
|
||
bool evse_get_limit_reached(void);
|
||
|
||
/**
|
||
* @brief Convenience alias for evse_get_limit_reached().
|
||
*/
|
||
bool evse_is_limit_reached(void);
|
||
|
||
/**
|
||
* @brief Checks if any session limit has been exceeded (energy, time or power).
|
||
* Should be called periodically during charging.
|
||
*/
|
||
void evse_limits_check(void);
|
||
|
||
// ============================
|
||
// Runtime Limit Configuration
|
||
// ============================
|
||
|
||
/**
|
||
* @brief Get/set energy consumption limit (in Wh).
|
||
*/
|
||
uint32_t evse_get_consumption_limit(void);
|
||
void evse_set_consumption_limit(uint32_t value);
|
||
|
||
/**
|
||
* @brief Get/set maximum charging time (in seconds).
|
||
*/
|
||
uint32_t evse_get_charging_time_limit(void);
|
||
void evse_set_charging_time_limit(uint32_t value);
|
||
|
||
/**
|
||
* @brief Get/set minimum acceptable power level (in Watts).
|
||
*/
|
||
uint16_t evse_get_under_power_limit(void);
|
||
void evse_set_under_power_limit(uint16_t value);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // EVSE_LIMITS_H
|
||
// === Fim de: components/evse/include/evse_limits.h ===
|
||
|
||
// === Fim de: components/evse/include/evse_limits.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_events.h ===
|
||
#ifndef EVSE_EVENTS_H
|
||
#define EVSE_EVENTS_H
|
||
|
||
#pragma once
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
#include "esp_event.h"
|
||
|
||
ESP_EVENT_DECLARE_BASE(EVSE_EVENTS);
|
||
|
||
typedef enum {
|
||
EVSE_EVENT_INIT,
|
||
EVSE_EVENT_STATE_CHANGED,
|
||
EVSE_EVENT_CONFIG_UPDATED,
|
||
EVSE_EVENT_ENABLE_UPDATED,
|
||
EVSE_EVENT_AVAILABLE_UPDATED,
|
||
EVSE_EVENT_SESSION,
|
||
} evse_event_id_t;
|
||
|
||
// -----------------
|
||
// Eventos de STATE
|
||
// -----------------
|
||
typedef enum {
|
||
EVSE_STATE_EVENT_IDLE,
|
||
EVSE_STATE_EVENT_WAITING,
|
||
EVSE_STATE_EVENT_CHARGING,
|
||
EVSE_STATE_EVENT_FAULT
|
||
} evse_state_event_t;
|
||
|
||
typedef struct {
|
||
evse_state_event_t state;
|
||
} evse_state_event_data_t;
|
||
|
||
// -----------------
|
||
// Eventos de SESSÃO
|
||
// -----------------
|
||
typedef enum {
|
||
EVSE_SESSION_EVENT_STARTED = 0,
|
||
EVSE_SESSION_EVENT_FINISHED,
|
||
} evse_session_event_type_t;
|
||
|
||
typedef struct {
|
||
evse_session_event_type_t type; ///< STARTED / FINISHED
|
||
|
||
// campos básicos da sessão, em tipos simples:
|
||
uint32_t session_id; ///< opcional, se tiveres um ID
|
||
uint32_t duration_s; ///< duração em segundos (0 no STARTED)
|
||
uint32_t energy_wh; ///< energia em Wh (0 no STARTED)
|
||
uint32_t avg_power_w; ///< potência média em W (0 no STARTED)
|
||
|
||
bool is_current; ///< true se ainda estiver em curso
|
||
} evse_session_event_data_t;
|
||
|
||
|
||
// -----------------
|
||
// Eventos de CONFIG
|
||
// -----------------
|
||
typedef struct {
|
||
bool charging; // Estado de carregamento
|
||
float hw_max_current; // Corrente máxima suportada pelo hardware
|
||
float runtime_current; // Corrente de carregamento em uso
|
||
int64_t timestamp_us; // Momento da atualização
|
||
} evse_config_event_data_t;
|
||
|
||
// Eventos simples e específicos
|
||
typedef struct {
|
||
bool enabled; // novo estado de enabled
|
||
int64_t timestamp_us; // epoch micros
|
||
} evse_enable_event_data_t;
|
||
|
||
typedef struct {
|
||
bool available; // novo estado de available
|
||
int64_t timestamp_us; // epoch micros
|
||
} evse_available_event_data_t;
|
||
|
||
#endif // EVSE_EVENTS_H
|
||
|
||
// === Fim de: components/evse/include/evse_events.h ===
|
||
|
||
|
||
// === Início de: components/evse/include/evse_api.h ===
|
||
#ifndef EVSE_API_H
|
||
#define EVSE_API_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "evse_state.h"
|
||
#include "freertos/FreeRTOS.h"
|
||
#include "evse_session.h"
|
||
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
// ===============================
|
||
// Core EVSE State
|
||
// ===============================
|
||
|
||
/**
|
||
* @brief Get current EVSE state (e.g., A, B1, C2).
|
||
*/
|
||
evse_state_t evse_get_state(void);
|
||
|
||
/**
|
||
* @brief Set the EVSE state (e.g., called by FSM or hardware layer).
|
||
*/
|
||
void evse_set_state(evse_state_t state);
|
||
|
||
// ===============================
|
||
// Charging Session Info
|
||
// ===============================
|
||
|
||
/**
|
||
* @brief Retrieve statistics of either the current ongoing session (if any)
|
||
* or the last completed session.
|
||
* @param out pointer to evse_session_t to be filled
|
||
* @return true if there is a current or last session available
|
||
*/
|
||
bool evse_get_session(evse_session_t *out);
|
||
|
||
// ===============================
|
||
// Charging Session Info
|
||
// ===============================
|
||
|
||
/**
|
||
* @brief Returns true if the EV is charging (C1 or C2).
|
||
*/
|
||
bool evse_state_is_charging(evse_state_t state);
|
||
|
||
/**
|
||
* @brief Returns true if the EV is connected (plugged).
|
||
*/
|
||
bool evse_state_is_plugged(evse_state_t state);
|
||
|
||
/**
|
||
* @brief Returns true if a charging session is active (B2, C1, C2).
|
||
*/
|
||
bool evse_state_is_session(evse_state_t state);
|
||
|
||
// ===============================
|
||
// Authorization
|
||
// ===============================
|
||
|
||
/**
|
||
* @brief Set whether the vehicle is authorized to charge.
|
||
*/
|
||
void evse_state_set_authorized(bool authorized);
|
||
|
||
/**
|
||
* @brief Get current authorization status.
|
||
*/
|
||
bool evse_state_get_authorized(void);
|
||
|
||
// ===============================
|
||
// Configuration / Availability
|
||
// ===============================
|
||
|
||
/**
|
||
* @brief Enable or disable the EVSE (software flag, persisted in NVS).
|
||
*/
|
||
void evse_set_enabled(bool value);
|
||
|
||
/**
|
||
* @brief Returns true if the EVSE is currently available for use.
|
||
*/
|
||
bool evse_is_available(void);
|
||
|
||
/**
|
||
* @brief Set EVSE availability flag (may be persisted in NVS).
|
||
*/
|
||
void evse_set_available(bool value);
|
||
|
||
// ===============================
|
||
// Limit Status
|
||
// ===============================
|
||
|
||
/**
|
||
* @brief Returns true if any runtime charging limit has been reached.
|
||
*/
|
||
bool evse_is_limit_reached(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // EVSE_API_H
|
||
// === Fim de: components/evse/include/evse_api.h ===
|
||
|
||
|
||
// === Início de: components/scheduler/include/scheduler_types.h ===
|
||
// components/scheduler/include/scheduler_types.h
|
||
#pragma once
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
typedef enum {
|
||
SCHED_MODE_DISABLED = 0, // não faz gating
|
||
SCHED_MODE_SIMPLE, // por ex: janela diária única
|
||
SCHED_MODE_WEEKLY // por ex: janelas por dia da semana
|
||
} sched_mode_t;
|
||
|
||
typedef struct {
|
||
bool enabled; // gating ativo?
|
||
sched_mode_t mode;
|
||
|
||
// exemplo bem simples: uma janela diária [start_min..end_min[
|
||
// minutos desde meia-noite, 0..1439
|
||
uint16_t start_min;
|
||
uint16_t end_min;
|
||
} sched_config_t;
|
||
|
||
const char *sched_mode_to_str(sched_mode_t mode);
|
||
bool sched_mode_from_str(const char *s, sched_mode_t *out);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/scheduler/include/scheduler_types.h ===
|
||
|
||
|
||
// === Início de: components/scheduler/include/scheduler_events.h ===
|
||
// scheduler_events.h
|
||
#pragma once
|
||
#include "esp_event.h"
|
||
#include <stdbool.h>
|
||
|
||
ESP_EVENT_DECLARE_BASE(SCHED_EVENTS);
|
||
|
||
typedef enum
|
||
{
|
||
SCHED_EVENT_INIT = 0, // envia estado inicial
|
||
SCHED_EVENT_WINDOW_CHANGED, // allowed_now mudou
|
||
} sched_event_id_t;
|
||
|
||
typedef struct
|
||
{
|
||
bool allowed_now;
|
||
} sched_event_state_t;
|
||
|
||
// === Fim de: components/scheduler/include/scheduler_events.h ===
|
||
|
||
|
||
// === Início de: components/scheduler/include/scheduler.h ===
|
||
// components/scheduler/include/scheduler.h
|
||
#pragma once
|
||
|
||
#include <stdbool.h>
|
||
#include "scheduler_types.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
void scheduler_init(void);
|
||
void scheduler_set_config(const sched_config_t *cfg);
|
||
sched_config_t scheduler_get_config(void);
|
||
bool scheduler_is_allowed_now(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/scheduler/include/scheduler.h ===
|
||
|
||
|
||
// === Início de: components/ocpp/include/ocpp_events.h ===
|
||
#pragma once
|
||
#include "esp_event.h"
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/* Base de eventos do OCPP (igual ao padrão usado em auth_events.h) */
|
||
ESP_EVENT_DECLARE_BASE(OCPP_EVENTS);
|
||
|
||
/* IDs de eventos do OCPP */
|
||
typedef enum {
|
||
OCPP_EVENT_CONNECTED = 0, // payload: const char* (server URL) – opcional
|
||
OCPP_EVENT_DISCONNECTED, // payload: NULL
|
||
OCPP_EVENT_AUTHORIZED, // payload: ocpp_idtag_event_t (opcional)
|
||
OCPP_EVENT_AUTH_REJECTED, // payload: ocpp_idtag_event_t (opcional)
|
||
OCPP_EVENT_AUTH_TIMEOUT, // payload: NULL
|
||
OCPP_EVENT_REMOTE_START, // payload: ocpp_idtag_event_t (opcional)
|
||
OCPP_EVENT_REMOTE_STOP, // payload: NULL
|
||
OCPP_EVENT_START_TX, // payload: ocpp_tx_event_t (opcional)
|
||
OCPP_EVENT_STOP_TX, // payload: ocpp_reason_event_t (opcional)
|
||
OCPP_EVENT_RESET, // payload: NULL
|
||
OCPP_EVENT_OPERATIVE_UPDATED
|
||
} ocpp_event_id_t;
|
||
|
||
/* Limites de strings simples (evita dependência de auth.h) */
|
||
#define OCPP_IDTAG_MAX 32
|
||
#define OCPP_REASON_MAX 32
|
||
|
||
/* Payloads opcionais */
|
||
typedef struct {
|
||
char idTag[OCPP_IDTAG_MAX];
|
||
} ocpp_idtag_event_t;
|
||
|
||
typedef struct {
|
||
int tx_id; // se disponível
|
||
} ocpp_tx_event_t;
|
||
|
||
typedef struct {
|
||
char reason[OCPP_REASON_MAX];
|
||
} ocpp_reason_event_t;
|
||
|
||
// Payload do novo evento
|
||
typedef struct {
|
||
bool operative; // true = Operative, false = Inoperative
|
||
int64_t timestamp_us; // esp_timer_get_time()
|
||
} ocpp_operative_event_t;
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
// === Fim de: components/ocpp/include/ocpp_events.h ===
|
||
|
||
|
||
// === Início de: components/ocpp/include/ocpp.h ===
|
||
#ifndef OCPP_H_
|
||
#define OCPP_H_
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/**
|
||
* @brief Start OCPP
|
||
*/
|
||
void ocpp_start(void);
|
||
|
||
/**
|
||
* @brief Stop OCPP
|
||
*/
|
||
void ocpp_stop(void);
|
||
|
||
/* Config getters / setters */
|
||
bool ocpp_get_enabled(void);
|
||
void ocpp_set_enabled(bool value);
|
||
|
||
void ocpp_get_server(char *value); // buffer >= 64
|
||
void ocpp_set_server(char *value);
|
||
|
||
void ocpp_get_charge_id(char *value); // buffer >= 64
|
||
void ocpp_set_charge_id(char *value);
|
||
|
||
/* Estado de conexão */
|
||
bool ocpp_is_connected(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* OCPP_H_ */
|
||
|
||
// === Fim de: components/ocpp/include/ocpp.h ===
|