49 lines
1.4 KiB
C
49 lines
1.4 KiB
C
#ifndef EVSE_LINK_FRAMING_H_
|
|
#define EVSE_LINK_FRAMING_H_
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "driver/uart.h"
|
|
|
|
// UART instance and configuration
|
|
#define UART_PORT UART_NUM_2
|
|
#define UART_BAUDRATE 9600
|
|
#define UART_RX_BUF_SIZE 256
|
|
|
|
// GPIO pin assignments for RS-485 UART
|
|
// Ajuste conforme seu hardware
|
|
#define MB_UART_TXD 17
|
|
#define MB_UART_RXD 16
|
|
#define MB_UART_RTS 2 // pino DE/RE do transceiver RS-485
|
|
|
|
#define TX_PIN MB_UART_TXD
|
|
#define RX_PIN MB_UART_RXD
|
|
#define RTS_PIN MB_UART_RTS
|
|
|
|
// 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_
|