#ifndef UART_CMD_H #define UART_CMD_H #include "cmd_handler.h" #include "esp_err.h" #include "pb.h" #include "uart_messages.pb.h" /** Decode framed UART body (protobuf UartMessage without the leading type byte). */ esp_err_t uart_cmd_decode(const uint8_t *data, size_t len, alox_UartMessage *out); /** Set type + oneof tag on an outbound UartMessage. */ void uart_cmd_init_response(alox_UartMessage *msg, alox_MessageType type, pb_size_t which_payload); /** Encode and send; logs on failure when log_tag is non-NULL. */ esp_err_t uart_cmd_send(const alox_UartMessage *msg, const char *log_tag); esp_err_t uart_cmd_register(alox_MessageType type, msg_callback_t cb); /** Nanopb encode callback for a NUL-terminated C string. */ bool uart_cmd_encode_string(pb_ostream_t *stream, const pb_field_t *field, void *const *arg); typedef struct { const uint8_t *data; size_t len; } uart_cmd_bytes_t; /** Nanopb encode callback; arg is uart_cmd_bytes_t *. */ bool uart_cmd_encode_bytes(pb_ostream_t *stream, const pb_field_t *field, void *const *arg); #define UART_CMD_REQ(msg, tag, field) \ ((msg)->which_payload == (tag) ? &(msg)->payload.field : NULL) #endif