Refactor ESP-NOW air protocol to nanopb protobuf.
Add esp_now_messages.proto with EspNowMessage types, encode/decode helpers, and Makefile targets to regenerate firmware and UART schemas together. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/* Automatically generated nanopb constant definitions */
|
||||
/* Generated by nanopb-1.0.0-dev */
|
||||
|
||||
#include "esp_now_messages.pb.h"
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
PB_BIND(alox_EspNowDiscover, alox_EspNowDiscover, AUTO)
|
||||
|
||||
|
||||
PB_BIND(alox_EspNowSlavePresence, alox_EspNowSlavePresence, AUTO)
|
||||
|
||||
|
||||
PB_BIND(alox_EspNowMessage, alox_EspNowMessage, AUTO)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/* Automatically generated nanopb header */
|
||||
/* Generated by nanopb-1.0.0-dev */
|
||||
|
||||
#ifndef PB_ALOX_MAIN_PROTO_ESP_NOW_MESSAGES_PB_H_INCLUDED
|
||||
#define PB_ALOX_MAIN_PROTO_ESP_NOW_MESSAGES_PB_H_INCLUDED
|
||||
#include <pb.h>
|
||||
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
/* Enum definitions */
|
||||
typedef enum _alox_EspNowMessageType {
|
||||
alox_EspNowMessageType_ESPNOW_UNKNOWN = 0,
|
||||
alox_EspNowMessageType_ESPNOW_DISCOVER = 1,
|
||||
alox_EspNowMessageType_ESPNOW_SLAVE_INFO = 2,
|
||||
alox_EspNowMessageType_ESPNOW_HEARTBEAT = 3
|
||||
} alox_EspNowMessageType;
|
||||
|
||||
/* Struct definitions */
|
||||
typedef struct _alox_EspNowDiscover {
|
||||
uint32_t network;
|
||||
} alox_EspNowDiscover;
|
||||
|
||||
typedef struct _alox_EspNowSlavePresence {
|
||||
uint32_t network;
|
||||
pb_callback_t mac;
|
||||
uint32_t version;
|
||||
uint32_t slave_id;
|
||||
bool available;
|
||||
bool used;
|
||||
} alox_EspNowSlavePresence;
|
||||
|
||||
typedef struct _alox_EspNowMessage {
|
||||
alox_EspNowMessageType type;
|
||||
pb_size_t which_payload;
|
||||
union _alox_EspNowMessage_payload {
|
||||
alox_EspNowDiscover discover;
|
||||
alox_EspNowSlavePresence slave_info;
|
||||
alox_EspNowSlavePresence heartbeat;
|
||||
} payload;
|
||||
} alox_EspNowMessage;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Helper constants for enums */
|
||||
#define _alox_EspNowMessageType_MIN alox_EspNowMessageType_ESPNOW_UNKNOWN
|
||||
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_HEARTBEAT
|
||||
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_HEARTBEAT+1))
|
||||
|
||||
|
||||
|
||||
#define alox_EspNowMessage_type_ENUMTYPE alox_EspNowMessageType
|
||||
|
||||
|
||||
/* Initializer values for message structs */
|
||||
#define alox_EspNowDiscover_init_default {0}
|
||||
#define alox_EspNowSlavePresence_init_default {0, {{NULL}, NULL}, 0, 0, 0, 0}
|
||||
#define alox_EspNowMessage_init_default {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_default}}
|
||||
#define alox_EspNowDiscover_init_zero {0}
|
||||
#define alox_EspNowSlavePresence_init_zero {0, {{NULL}, NULL}, 0, 0, 0, 0}
|
||||
#define alox_EspNowMessage_init_zero {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_zero}}
|
||||
|
||||
/* Field tags (for use in manual encoding/decoding) */
|
||||
#define alox_EspNowDiscover_network_tag 1
|
||||
#define alox_EspNowSlavePresence_network_tag 1
|
||||
#define alox_EspNowSlavePresence_mac_tag 2
|
||||
#define alox_EspNowSlavePresence_version_tag 3
|
||||
#define alox_EspNowSlavePresence_slave_id_tag 4
|
||||
#define alox_EspNowSlavePresence_available_tag 5
|
||||
#define alox_EspNowSlavePresence_used_tag 6
|
||||
#define alox_EspNowMessage_type_tag 1
|
||||
#define alox_EspNowMessage_discover_tag 2
|
||||
#define alox_EspNowMessage_slave_info_tag 3
|
||||
#define alox_EspNowMessage_heartbeat_tag 4
|
||||
|
||||
/* Struct field encoding specification for nanopb */
|
||||
#define alox_EspNowDiscover_FIELDLIST(X, a) \
|
||||
X(a, STATIC, SINGULAR, UINT32, network, 1)
|
||||
#define alox_EspNowDiscover_CALLBACK NULL
|
||||
#define alox_EspNowDiscover_DEFAULT NULL
|
||||
|
||||
#define alox_EspNowSlavePresence_FIELDLIST(X, a) \
|
||||
X(a, STATIC, SINGULAR, UINT32, network, 1) \
|
||||
X(a, CALLBACK, SINGULAR, BYTES, mac, 2) \
|
||||
X(a, STATIC, SINGULAR, UINT32, version, 3) \
|
||||
X(a, STATIC, SINGULAR, UINT32, slave_id, 4) \
|
||||
X(a, STATIC, SINGULAR, BOOL, available, 5) \
|
||||
X(a, STATIC, SINGULAR, BOOL, used, 6)
|
||||
#define alox_EspNowSlavePresence_CALLBACK pb_default_field_callback
|
||||
#define alox_EspNowSlavePresence_DEFAULT NULL
|
||||
|
||||
#define alox_EspNowMessage_FIELDLIST(X, a) \
|
||||
X(a, STATIC, SINGULAR, UENUM, type, 1) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (payload,discover,payload.discover), 2) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (payload,slave_info,payload.slave_info), 3) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (payload,heartbeat,payload.heartbeat), 4)
|
||||
#define alox_EspNowMessage_CALLBACK NULL
|
||||
#define alox_EspNowMessage_DEFAULT NULL
|
||||
#define alox_EspNowMessage_payload_discover_MSGTYPE alox_EspNowDiscover
|
||||
#define alox_EspNowMessage_payload_slave_info_MSGTYPE alox_EspNowSlavePresence
|
||||
#define alox_EspNowMessage_payload_heartbeat_MSGTYPE alox_EspNowSlavePresence
|
||||
|
||||
extern const pb_msgdesc_t alox_EspNowDiscover_msg;
|
||||
extern const pb_msgdesc_t alox_EspNowSlavePresence_msg;
|
||||
extern const pb_msgdesc_t alox_EspNowMessage_msg;
|
||||
|
||||
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
|
||||
#define alox_EspNowDiscover_fields &alox_EspNowDiscover_msg
|
||||
#define alox_EspNowSlavePresence_fields &alox_EspNowSlavePresence_msg
|
||||
#define alox_EspNowMessage_fields &alox_EspNowMessage_msg
|
||||
|
||||
/* Maximum encoded size of messages (where known) */
|
||||
/* alox_EspNowSlavePresence_size depends on runtime parameters */
|
||||
/* alox_EspNowMessage_size depends on runtime parameters */
|
||||
#define ALOX_MAIN_PROTO_ESP_NOW_MESSAGES_PB_H_MAX_SIZE alox_EspNowDiscover_size
|
||||
#define alox_EspNowDiscover_size 6
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package alox;
|
||||
|
||||
enum EspNowMessageType {
|
||||
ESPNOW_UNKNOWN = 0;
|
||||
ESPNOW_DISCOVER = 1;
|
||||
ESPNOW_SLAVE_INFO = 2;
|
||||
ESPNOW_HEARTBEAT = 3;
|
||||
}
|
||||
|
||||
message EspNowDiscover {
|
||||
uint32 network = 1;
|
||||
}
|
||||
|
||||
message EspNowSlavePresence {
|
||||
uint32 network = 1;
|
||||
bytes mac = 2;
|
||||
uint32 version = 3;
|
||||
uint32 slave_id = 4;
|
||||
bool available = 5;
|
||||
bool used = 6;
|
||||
}
|
||||
|
||||
message EspNowMessage {
|
||||
EspNowMessageType type = 1;
|
||||
oneof payload {
|
||||
EspNowDiscover discover = 2;
|
||||
EspNowSlavePresence slave_info = 3;
|
||||
EspNowSlavePresence heartbeat = 4;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user