evse_link feature
This commit is contained in:
45
components/evse_link/include/evse_link.h
Executable file
45
components/evse_link/include/evse_link.h
Executable file
@@ -0,0 +1,45 @@
|
||||
#ifndef EVSE_LINK_H_
|
||||
#define EVSE_LINK_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Operation mode: slave or master
|
||||
typedef enum {
|
||||
EVSE_LINK_MODE_SLAVE = 0,
|
||||
EVSE_LINK_MODE_MASTER = 1
|
||||
} evse_link_mode_t;
|
||||
|
||||
// Callback invoked when a complete frame is received:
|
||||
// src: device address of sender (0–255)
|
||||
// dest: device address of receiver (0–255 or 0xFF broadcast)
|
||||
// payload: pointer to received data buffer (command + data)
|
||||
// len: length of payload (0–255)
|
||||
typedef void (*evse_link_rx_cb_t)(uint8_t src, uint8_t dest,
|
||||
const uint8_t *payload, uint8_t len);
|
||||
|
||||
// Initializes the EVSE-Link component
|
||||
void evse_link_init(void);
|
||||
|
||||
// Sends a framed payload to `dest` with length `len`.
|
||||
// The source address is automatically set from configuration.
|
||||
// Returns true on successful enqueue/transmit.
|
||||
bool evse_link_send(uint8_t dest, const uint8_t *payload, uint8_t len);
|
||||
|
||||
// Feeds a received byte into the framing parser.
|
||||
void evse_link_recv_byte(uint8_t byte);
|
||||
|
||||
// Registers a callback to receive complete frames.
|
||||
void evse_link_register_rx_cb(evse_link_rx_cb_t cb);
|
||||
|
||||
// Runtime configuration getters/setters
|
||||
void evse_link_set_mode(evse_link_mode_t mode);
|
||||
evse_link_mode_t evse_link_get_mode(void);
|
||||
|
||||
void evse_link_set_self_id(uint8_t id);
|
||||
uint8_t evse_link_get_self_id(void);
|
||||
|
||||
void evse_link_set_enabled(bool enabled);
|
||||
bool evse_link_is_enabled(void);
|
||||
|
||||
#endif // EVSE_LINK_H_
|
||||
16
components/evse_link/include/evse_link_events.h
Normal file
16
components/evse_link/include/evse_link_events.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef EVSE_LINK_EVENTS_H_
|
||||
#define EVSE_LINK_EVENTS_H_
|
||||
|
||||
#include "esp_event.h"
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(EVSE_LINK_EVENTS);
|
||||
|
||||
typedef enum {
|
||||
LINK_EVENT_FRAME_RECEIVED, // qualquer frame válido
|
||||
LINK_EVENT_SLAVE_ONLINE, // heartbeat recebido primeira vez
|
||||
LINK_EVENT_SLAVE_OFFLINE, // sem heartbeat no timeout
|
||||
LINK_EVENT_MASTER_POLL_SENT, // opcional: poll enviado pelo master
|
||||
LINK_EVENT_CURRENT_LIMIT_APPLIED,
|
||||
LINK_EVENT_SLAVE_CONFIG_UPDATED // <- NOVO evento
|
||||
} evse_link_event_t;
|
||||
#endif // EVSE_LINK_EVENTS_H_
|
||||
42
components/evse_link/include/evse_link_framing.h
Normal file
42
components/evse_link/include/evse_link_framing.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef EVSE_LINK_FRAMING_H_
|
||||
#define EVSE_LINK_FRAMING_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "driver/uart.h"
|
||||
|
||||
// UART configuration
|
||||
#define UART_PORT UART_NUM_2
|
||||
#define UART_BAUDRATE 115200
|
||||
#define UART_RX_BUF_SIZE 256
|
||||
|
||||
// GPIO pin assignments for UART
|
||||
#define TX_PIN 21 // GPIO21 -> RX on other board
|
||||
#define RX_PIN 22 // GPIO22 -> TX on other board
|
||||
|
||||
// Frame delimiters
|
||||
#define MAGIC_START 0x7E
|
||||
#define MAGIC_END 0x7F
|
||||
|
||||
// Maximum payload (excluding sequence byte)
|
||||
#define EVSE_LINK_MAX_PAYLOAD 254
|
||||
|
||||
// Callback type for when a full frame is received
|
||||
typedef void (*evse_link_frame_cb_t)(uint8_t src, uint8_t dest,
|
||||
const uint8_t *payload, uint8_t len);
|
||||
|
||||
// Initialize framing module (mutex, UART driver, etc.)
|
||||
void evse_link_framing_init(void);
|
||||
|
||||
// Send a framed payload to `dest` with length `len`
|
||||
// Includes source address in the header
|
||||
bool evse_link_framing_send(uint8_t dest, uint8_t src,
|
||||
const uint8_t *payload, uint8_t len);
|
||||
|
||||
// Feed a received byte into the framing parser
|
||||
void evse_link_framing_recv_byte(uint8_t byte);
|
||||
|
||||
// Register a callback for complete frames
|
||||
void evse_link_framing_register_cb(evse_link_frame_cb_t cb);
|
||||
|
||||
#endif // EVSE_LINK_FRAMING_H_
|
||||
Reference in New Issue
Block a user