Add LiPo battery monitoring with ESP-NOW cache and dashboard API.

Slaves report pack voltages every 30s; the master caches them for fast
BATTERY_STATUS reads. goTool exposes REST/WebSocket and shows values in
the dashboard, with a nanopb fix so optional lipo submessages encode.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-29 20:14:28 +02:00
co-authored by Cursor
parent eb67a46158
commit 3cb0b5bbe9
30 changed files with 1618 additions and 150 deletions
+1
View File
@@ -25,6 +25,7 @@ idf_component_register(
"cmd/cmd_restart.c"
"pod_reboot.c"
"cmd/cmd_led_ring.c"
"cmd/cmd_battery.c"
"cmd/cmd_ota.c"
"cmd/cmd_ota_slave_progress.c"
"ota_uart.c"
+14
View File
@@ -116,6 +116,7 @@ Schema: `proto/esp_now_messages.proto`. Encode/decode: `esp_now_proto.c`. The ES
| `ESPNOW_FIND_ME` | Master → slave | `EspNowFindMe` (`client_id` filter) — LED locate sequence |
| `ESPNOW_RESTART` | Master → slave | `EspNowRestart` (`client_id` filter) — reboot slave |
| `ESPNOW_ACCEL_SAMPLE` | Slave → master | `EspNowAccelSample` (`slave_id`, `x`, `y`, `z` raw LSB) — ~every 16 ms |
| `ESPNOW_BATTERY_REPORT` | Slave → master | `EspNowBatteryReport` (`client_id`, `lipo1/2` mV) — ~every 30 s; cached in `client_registry` |
| `ESPNOW_OTA_START` | Master → slave (unicast) | `EspNowOtaStart` (`total_size`) |
| `ESPNOW_OTA_PAYLOAD` | Master → slave | `EspNowOtaPayload` (`seq`, up to 200 B `data`) |
| `ESPNOW_OTA_END` | Master → slave | `EspNowOtaEnd` |
@@ -210,6 +211,7 @@ Host and master speak nanopb-encoded `UartMessage` inside UART frames (byte 0 =
| 6 | `ACCEL_DEADZONE` | Implemented (`cmd/cmd_accel_deadzone.c`) — get/set accel filter LSB |
| 7 | `ESPNOW_UNICAST_TEST` | Implemented (`cmd/cmd_espnow_unicast_test.c`) |
| 8 | `LED_RING` | Implemented (`cmd/cmd_led_ring.c`) — ring progress bar (0100 %, RGB, intensity) |
| 26 | `BATTERY_STATUS` | Implemented (`cmd/cmd_battery.c`) — cached LiPo 1/2 per pod from `client_registry` (UART read, no slave round-trip) |
| 16 | `OTA_START` | Implemented (`cmd/cmd_ota.c`) — begin UART OTA on inactive slot |
| 17 | `OTA_PAYLOAD` | Implemented — up to 200 B per frame; device buffers 4 KiB |
| 18 | `OTA_END` | Implemented — flush, `esp_ota_end`, push image to slaves via ESP-NOW, set boot |
@@ -370,6 +372,18 @@ go run . -port /dev/ttyUSB0 restart
go run . -port /dev/ttyUSB0 restart -client 16
```
### BATTERY_STATUS command
Read **cached** LiPo ADC values on the **master** (master local + one entry per registered slave). Slaves push `ESPNOW_BATTERY_REPORT` every **30 s**; the master stores them in `client_registry` (`lipo1/2_valid`, `lipo1/2_mv`, `battery_updated_at`). The master refreshes its own pack on the same interval in `master_monitor_task`.
**Request:** framed `26` + optional `battery_status_request` (`client_id`, `all_clients`).
**Response:** `battery_status_response` with `samples[]` (`client_id`, `lipo1`, `lipo2`, `age_ms`).
```bash
# Host / goTool: all_clients returns master (id 0) + slaves from cache
```
### LED_RING command
Control the 95-LED ring from the host. The firmware **does not** animate digits locally; only UART updates the display.
+40 -20
View File
@@ -6,7 +6,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/idf_additions.h"
#include "freertos/queue.h"
#include <stdint.h>
#include <string.h>
static const char *TAG_BTN = "[BTN]";
static const char *TAG_LIPO = "[LIPO]";
@@ -14,6 +14,8 @@ static const char *TAG_LIPO = "[LIPO]";
#define LIPO_SAMPLE_INTERVAL_MS 10000
#define BUTTON_QUEUE_LEN 4
#define BUTTON_DEBOUNCE_MS 80
#define LIPO_ADC_FULL_SCALE_MV 3300
#define LIPO_ADC_MAX_RAW 4095
static QueueHandle_t s_button_queue;
static adc_oneshot_unit_handle_t s_adc;
@@ -47,33 +49,51 @@ static esp_err_t adc_init_channel(int gpio, adc_channel_t *out_ch, bool *out_ok)
return ESP_OK;
}
static uint32_t raw_to_mv(int raw) {
if (raw < 0) {
return 0;
}
return (uint32_t)((raw * LIPO_ADC_FULL_SCALE_MV) / LIPO_ADC_MAX_RAW);
}
static void sample_one_channel(adc_channel_t ch, bool ok, uint32_t *mv_out,
bool *valid_out) {
*valid_out = false;
*mv_out = 0;
if (!ok || s_adc == NULL) {
return;
}
int raw = 0;
if (adc_oneshot_read(s_adc, ch, &raw) == ESP_OK) {
*valid_out = true;
*mv_out = raw_to_mv(raw);
}
}
void board_input_read_lipo(board_lipo_reading_t *out) {
if (out == NULL) {
return;
}
memset(out, 0, sizeof(*out));
sample_one_channel(s_lipo1_ch, s_lipo1_ok, &out->lipo1_mv, &out->lipo1_valid);
sample_one_channel(s_lipo2_ch, s_lipo2_ok, &out->lipo2_mv, &out->lipo2_valid);
}
static void lipo_monitor_task(void *param) {
(void)param;
ESP_LOGI(TAG_LIPO, "monitor task (interval %d ms)", LIPO_SAMPLE_INTERVAL_MS);
while (1) {
int raw1 = -1;
int raw2 = -1;
int mv1 = -1;
int mv2 = -1;
if (s_lipo1_ok) {
raw1 = 0;
if (adc_oneshot_read(s_adc, s_lipo1_ch, &raw1) == ESP_OK) {
mv1 = (raw1 * 3300) / 4095;
}
}
if (s_lipo2_ok) {
raw2 = 0;
if (adc_oneshot_read(s_adc, s_lipo2_ch, &raw2) == ESP_OK) {
mv2 = (raw2 * 3300) / 4095;
}
}
board_lipo_reading_t reading;
board_input_read_lipo(&reading);
ESP_LOGI(TAG_LIPO,
"LIPO1 GPIO%d raw=%d (~%d mV) LIPO2 GPIO%d raw=%d (~%d mV)",
V_LIPO_1_GPIO, raw1, mv1, V_LIPO_2_GPIO, raw2, mv2);
"LIPO1 GPIO%d %s %lu mV LIPO2 GPIO%d %s %lu mV",
V_LIPO_1_GPIO, reading.lipo1_valid ? "ok" : "n/a",
(unsigned long)reading.lipo1_mv, V_LIPO_2_GPIO,
reading.lipo2_valid ? "ok" : "n/a",
(unsigned long)reading.lipo2_mv);
vTaskDelay(pdMS_TO_TICKS(LIPO_SAMPLE_INTERVAL_MS));
}
+14 -1
View File
@@ -1,12 +1,25 @@
#ifndef BOARD_INPUT_H
#define BOARD_INPUT_H
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
typedef struct {
bool lipo1_valid;
bool lipo2_valid;
uint32_t lipo1_mv;
uint32_t lipo2_mv;
} board_lipo_reading_t;
/**
* Button (log on press) and LiPo ADC sampling (log every 10 s).
* Button (log on press) and LiPo ADC sampling (background log every 10 s).
* TODO: Pin assignments come from powerpod.h and may not match final hardware yet.
*/
esp_err_t board_input_init(void);
/** On-demand ADC read of both LiPo sense inputs (if configured). */
void board_input_read_lipo(board_lipo_reading_t *out);
#endif
+63
View File
@@ -14,6 +14,11 @@ typedef struct {
static client_slot_t s_clients[CLIENT_REGISTRY_MAX];
static struct {
board_lipo_reading_t reading;
uint32_t updated_at;
} s_master_battery;
uint32_t client_registry_now_ms(void) {
return (uint32_t)(xTaskGetTickCount() * portTICK_PERIOD_MS);
}
@@ -320,6 +325,64 @@ esp_err_t client_registry_update_accel(const uint8_t mac[CLIENT_MAC_LEN],
return ESP_OK;
}
void client_registry_set_master_battery(const board_lipo_reading_t *reading) {
if (reading == NULL) {
return;
}
s_master_battery.reading = *reading;
s_master_battery.updated_at = now_ms();
}
bool client_registry_get_master_battery(board_lipo_reading_t *reading_out,
uint32_t *age_ms_out) {
if (reading_out == NULL) {
return false;
}
*reading_out = s_master_battery.reading;
if (age_ms_out != NULL) {
*age_ms_out = client_registry_ms_since(s_master_battery.updated_at);
}
return s_master_battery.updated_at != 0;
}
esp_err_t client_registry_update_battery(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t slave_id, bool lipo1_valid,
uint32_t lipo1_mv, bool lipo2_valid,
uint32_t lipo2_mv) {
if (mac == NULL) {
return ESP_ERR_INVALID_ARG;
}
client_slot_t *slot = find_slot(mac);
if (slot == NULL) {
bool is_new = false;
esp_err_t err = client_registry_upsert(mac, slave_id, 0, true, false, &is_new);
if (err != ESP_OK) {
return err;
}
slot = find_slot(mac);
if (slot == NULL) {
return ESP_ERR_NOT_FOUND;
}
ESP_LOGI(TAG, "battery auto-registered id=%lu (report before heartbeat)",
(unsigned long)slave_id);
}
if (slot->info.id != slave_id) {
ESP_LOGW(TAG, "battery id %lu → %lu for mac %02x:…:%02x",
(unsigned long)slot->info.id, (unsigned long)slave_id, mac[0],
mac[5]);
slot->info.id = slave_id;
}
slot->info.lipo1_valid = lipo1_valid;
slot->info.lipo2_valid = lipo2_valid;
slot->info.lipo1_mv = lipo1_mv;
slot->info.lipo2_mv = lipo2_mv;
slot->info.battery_updated_at = now_ms();
return ESP_OK;
}
const client_info_t *client_registry_at(size_t index) {
size_t n = 0;
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
+18
View File
@@ -1,6 +1,7 @@
#ifndef CLIENT_REGISTRY_H
#define CLIENT_REGISTRY_H
#include "board_input.h"
#include "esp_err.h"
#include <stdbool.h>
#include <stddef.h>
@@ -29,6 +30,12 @@ typedef struct {
uint32_t accel_updated_at;
/** Host-enabled ESP-NOW accel stream to master. */
bool accel_stream_enabled;
/** Latest LiPo ADC from slave ESP-NOW battery report (~30 s). */
bool lipo1_valid;
bool lipo2_valid;
uint32_t lipo1_mv;
uint32_t lipo2_mv;
uint32_t battery_updated_at;
} client_info_t;
#define CLIENT_REGISTRY_DEFAULT_ACCEL_DEADZONE 100u
@@ -80,4 +87,15 @@ esp_err_t client_registry_set_accel_stream(uint32_t client_id, bool enabled);
esp_err_t client_registry_get_accel_stream(uint32_t client_id, bool *enabled_out);
size_t client_registry_set_accel_stream_all(bool enabled);
/** Master local LiPo (client_id 0 in UART battery responses). */
void client_registry_set_master_battery(const board_lipo_reading_t *reading);
bool client_registry_get_master_battery(board_lipo_reading_t *reading_out,
uint32_t *age_ms_out);
/** Store latest battery report from a slave (matched by sender MAC). */
esp_err_t client_registry_update_battery(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t slave_id, bool lipo1_valid,
uint32_t lipo1_mv, bool lipo2_valid,
uint32_t lipo2_mv);
#endif
+119
View File
@@ -0,0 +1,119 @@
#include "cmd_battery.h"
#include "board_input.h"
#include "client_registry.h"
#include "esp_log.h"
#include "uart_cmd.h"
static const char *TAG = "[BATTERY]";
static void fill_lipo(alox_LipoReading *dst, bool *has_dst, bool valid,
uint32_t mv) {
if (dst == NULL || has_dst == NULL) {
return;
}
*has_dst = true;
dst->valid = valid;
dst->voltage_mv = valid ? mv : 0;
}
static bool append_battery_sample(alox_BatteryStatusResponse *resp,
uint32_t client_id, bool lipo1_valid,
uint32_t lipo1_mv, bool lipo2_valid,
uint32_t lipo2_mv, uint32_t age_ms) {
if (resp->samples_count >=
sizeof(resp->samples) / sizeof(resp->samples[0])) {
return false;
}
alox_BatterySample *sample = &resp->samples[resp->samples_count++];
sample->client_id = client_id;
fill_lipo(&sample->lipo1, &sample->has_lipo1, lipo1_valid, lipo1_mv);
fill_lipo(&sample->lipo2, &sample->has_lipo2, lipo2_valid, lipo2_mv);
sample->age_ms = age_ms;
return lipo1_valid || lipo2_valid;
}
static bool append_master_cached(alox_BatteryStatusResponse *resp) {
board_lipo_reading_t reading;
uint32_t age_ms = 0;
if (!client_registry_get_master_battery(&reading, &age_ms)) {
board_input_read_lipo(&reading);
client_registry_set_master_battery(&reading);
age_ms = 0;
}
return append_battery_sample(resp, 0, reading.lipo1_valid, reading.lipo1_mv,
reading.lipo2_valid, reading.lipo2_mv, age_ms);
}
static bool append_slave_cached(alox_BatteryStatusResponse *resp,
const client_info_t *client) {
if (client == NULL) {
return false;
}
if (client->battery_updated_at == 0) {
return false;
}
return append_battery_sample(
resp, client->id, client->lipo1_valid, client->lipo1_mv,
client->lipo2_valid, client->lipo2_mv,
client_registry_ms_since(client->battery_updated_at));
}
static void handle_battery_status(const uint8_t *data, size_t len) {
alox_BatteryStatusRequest req = alox_BatteryStatusRequest_init_zero;
if (len > 0) {
alox_UartMessage uart_msg;
if (uart_cmd_decode(data, len, &uart_msg) == ESP_OK) {
const alox_BatteryStatusRequest *req_ptr = UART_CMD_REQ(
&uart_msg, alox_UartMessage_battery_status_request_tag,
battery_status_request);
if (req_ptr != NULL) {
req = *req_ptr;
}
}
}
alox_UartMessage response;
uart_cmd_init_response(&response, alox_MessageType_BATTERY_STATUS,
alox_UartMessage_battery_status_response_tag);
alox_BatteryStatusResponse *resp =
&response.payload.battery_status_response;
resp->success = false;
resp->samples_count = 0;
bool any = false;
if (req.all_clients) {
any |= append_master_cached(resp);
for (size_t i = 0; i < client_registry_count(); i++) {
const client_info_t *client = client_registry_at(i);
if (client == NULL) {
continue;
}
any |= append_slave_cached(resp, client);
}
ESP_LOGI(TAG, "battery cache all_clients → %u samples",
(unsigned)resp->samples_count);
} else if (req.client_id == 0) {
any = append_master_cached(resp);
ESP_LOGI(TAG, "battery cache master");
} else {
const client_info_t *client = client_registry_find_by_id(req.client_id);
if (client != NULL) {
any = append_slave_cached(resp, client);
} else {
ESP_LOGW(TAG, "client %lu not in registry", (unsigned long)req.client_id);
}
}
resp->success = any;
uart_cmd_send(&response, TAG);
}
void cmd_battery_register(void) {
uart_cmd_register(alox_MessageType_BATTERY_STATUS, handle_battery_status);
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef CMD_BATTERY_H
#define CMD_BATTERY_H
void cmd_battery_register(void);
#endif
+2
View File
@@ -52,6 +52,8 @@ static const char *message_type_name(uint16_t id) {
return "ACCEL_SNAPSHOT";
case alox_MessageType_ACCEL_STREAM:
return "ACCEL_STREAM";
case alox_MessageType_BATTERY_STATUS:
return "BATTERY_STATUS";
default:
return "UNKNOWN";
}
+191 -1
View File
@@ -1,6 +1,7 @@
#include "bosch456.h"
#include "client_registry.h"
#include "esp_now_comm.h"
#include "board_input.h"
#include "cmd_led_ring.h"
#include "led_ring.h"
#include "ota_espnow.h"
@@ -48,6 +49,16 @@ static uint32_t s_last_discover_ms;
static SemaphoreHandle_t s_send_done;
static bool s_send_cb_ready;
#define ESPNOW_BATTERY_INTERVAL_MS 30000
#define SLAVE_BATTERY_AFTER_JOIN_MS 150
typedef enum {
SLAVE_TX_SLAVE_INFO = 1,
SLAVE_TX_BATTERY,
} slave_tx_op_t;
static QueueHandle_t s_slave_tx_queue;
static uint32_t now_ms(void) {
return (uint32_t)(xTaskGetTickCount() * portTICK_PERIOD_MS);
}
@@ -90,6 +101,7 @@ static esp_err_t ensure_broadcast_peer(void) { return ensure_peer(ESPNOW_BCAST);
static esp_err_t send_message_ex(const uint8_t *dest_mac,
const alox_EspNowMessage *msg, bool wait_done);
static void slave_send_battery_report_to_master(void);
static void fill_presence(alox_EspNowSlavePresence *presence) {
presence->network = s_config.network;
@@ -210,6 +222,21 @@ static esp_err_t send_find_me(const uint8_t *dest_mac, uint32_t client_id) {
return send_message(dest_mac, &msg);
}
static esp_err_t send_battery_report(const uint8_t *dest_mac,
const alox_EspNowBatteryReport *report) {
if (report == NULL) {
return ESP_ERR_INVALID_ARG;
}
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
msg.type = alox_EspNowMessageType_ESPNOW_BATTERY_REPORT;
msg.which_payload = alox_EspNowMessage_battery_report_tag;
msg.payload.battery_report = *report;
return send_message(dest_mac, &msg);
}
static esp_err_t send_led_ring(const uint8_t *dest_mac, uint32_t client_id,
const alox_LedRingProgressRequest *req) {
if (req == NULL) {
@@ -470,6 +497,47 @@ static void slave_reset_join(void) {
s_accel_stream_enabled = false;
memset(s_master_mac, 0, sizeof(s_master_mac));
s_last_discover_ms = 0;
if (s_slave_tx_queue != NULL) {
xQueueReset(s_slave_tx_queue);
}
}
static void slave_queue_tx(slave_tx_op_t op) {
if (s_slave_tx_queue == NULL) {
return;
}
if (xQueueSend(s_slave_tx_queue, &op, 0) != pdTRUE) {
ESP_LOGW(TAG, "slave tx queue full (op=%d)", (int)op);
}
}
static void slave_tx_task(void *param) {
(void)param;
slave_tx_op_t op;
ESP_LOGI(TAG, "slave tx task ready");
while (1) {
if (xQueueReceive(s_slave_tx_queue, &op, portMAX_DELAY) != pdTRUE) {
continue;
}
if (!s_slave_joined) {
continue;
}
switch (op) {
case SLAVE_TX_SLAVE_INFO:
send_presence(s_master_mac, alox_EspNowMessageType_ESPNOW_SLAVE_INFO);
break;
case SLAVE_TX_BATTERY:
vTaskDelay(pdMS_TO_TICKS(SLAVE_BATTERY_AFTER_JOIN_MS));
slave_send_battery_report_to_master();
break;
default:
break;
}
}
}
static void handle_slave_unicast_test(const uint8_t *master_mac,
@@ -499,6 +567,77 @@ static void handle_slave_restart(const uint8_t *master_mac,
pod_schedule_restart();
}
static void slave_send_battery_report_to_master(void) {
if (!s_slave_joined) {
return;
}
board_lipo_reading_t reading;
board_input_read_lipo(&reading);
alox_EspNowBatteryReport report = alox_EspNowBatteryReport_init_zero;
report.client_id = s_own_mac[5];
report.lipo1_valid = reading.lipo1_valid;
report.lipo2_valid = reading.lipo2_valid;
report.lipo1_mv = reading.lipo1_mv;
report.lipo2_mv = reading.lipo2_mv;
esp_err_t err = send_battery_report(s_master_mac, &report);
if (err != ESP_OK) {
ESP_LOGW(TAG, "battery report send failed id=%lu: %s",
(unsigned long)report.client_id, esp_err_to_name(err));
} else {
ESP_LOGI(TAG, "battery report sent id=%lu L1=%s %lu mV L2=%s %lu mV",
(unsigned long)report.client_id,
report.lipo1_valid ? "ok" : "n/a",
(unsigned long)report.lipo1_mv,
report.lipo2_valid ? "ok" : "n/a",
(unsigned long)report.lipo2_mv);
}
}
static void handle_slave_battery_query(const uint8_t *master_mac,
const alox_EspNowBatteryQuery *query) {
uint32_t my_id = s_own_mac[5];
if (query->client_id != 0 && query->client_id != my_id) {
return;
}
if (s_slave_joined && !mac_equal(master_mac, s_master_mac)) {
return;
}
slave_send_battery_report_to_master();
}
static void handle_master_battery_report(const uint8_t *mac,
const alox_EspNowBatteryReport *report) {
if (report == NULL || mac == NULL) {
return;
}
esp_err_t err = client_registry_update_battery(
mac, report->client_id, report->lipo1_valid, report->lipo1_mv,
report->lipo2_valid, report->lipo2_mv);
if (err == ESP_ERR_NOT_FOUND) {
ESP_LOGW(TAG, "battery report from unregistered slave id=%lu",
(unsigned long)report->client_id);
return;
}
if (err != ESP_OK) {
ESP_LOGW(TAG, "battery report id=%lu rejected: %s",
(unsigned long)report->client_id, esp_err_to_name(err));
return;
}
ESP_LOGI(TAG, "battery cached id=%lu L1=%s %lu mV L2=%s %lu mV",
(unsigned long)report->client_id,
report->lipo1_valid ? "ok" : "n/a",
(unsigned long)report->lipo1_mv, report->lipo2_valid ? "ok" : "n/a",
(unsigned long)report->lipo2_mv);
}
static void handle_slave_led_ring(const uint8_t *master_mac,
const alox_EspNowLedRing *msg) {
uint32_t my_id = s_own_mac[5];
@@ -670,7 +809,9 @@ static void handle_discover(const uint8_t *sender_mac,
ESP_LOGI(TAG, "joined network %u, master %s", (unsigned)discover->network,
mac_str);
send_presence(sender_mac, alox_EspNowMessageType_ESPNOW_SLAVE_INFO);
/* Do not esp_now_send from recv callback — defer to slave_tx_task. */
slave_queue_tx(SLAVE_TX_SLAVE_INFO);
slave_queue_tx(SLAVE_TX_BATTERY);
}
static void slave_check_master_timeout(void) {
@@ -716,6 +857,7 @@ static void slave_accel_stream_task(void *param) {
static void slave_heartbeat_task(void *param) {
(void)param;
uint32_t last_battery_ms = 0;
ESP_LOGI(TAG, "slave heartbeat task (interval %u ms)",
(unsigned)ESPNOW_HEARTBEAT_INTERVAL_MS);
@@ -726,22 +868,43 @@ static void slave_heartbeat_task(void *param) {
slave_check_master_timeout();
if (!s_slave_joined) {
last_battery_ms = 0;
continue;
}
send_presence(s_master_mac, alox_EspNowMessageType_ESPNOW_HEARTBEAT);
uint32_t now = now_ms();
if (last_battery_ms == 0 ||
(now - last_battery_ms) >= ESPNOW_BATTERY_INTERVAL_MS) {
slave_send_battery_report_to_master();
last_battery_ms = now;
}
}
}
static void master_monitor_task(void *param) {
(void)param;
uint32_t last_local_battery_ms = 0;
ESP_LOGI(TAG, "master monitor task (timeout %u ms)",
(unsigned)ESPNOW_CLIENT_TIMEOUT_MS);
board_lipo_reading_t reading;
board_input_read_lipo(&reading);
client_registry_set_master_battery(&reading);
last_local_battery_ms = now_ms();
while (1) {
vTaskDelay(pdMS_TO_TICKS(ESPNOW_HEARTBEAT_INTERVAL_MS));
client_registry_check_timeouts(ESPNOW_CLIENT_TIMEOUT_MS);
uint32_t t = now_ms();
if (t - last_local_battery_ms >= ESPNOW_BATTERY_INTERVAL_MS) {
board_input_read_lipo(&reading);
client_registry_set_master_battery(&reading);
last_local_battery_ms = t;
}
}
}
@@ -779,6 +942,12 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
}
handle_slave_accel_stream(info->src_addr, &msg.payload.accel_stream);
break;
case alox_EspNowMessage_battery_query_tag:
if (!s_slave_joined || !mac_equal(info->src_addr, s_master_mac)) {
break;
}
handle_slave_battery_query(info->src_addr, &msg.payload.battery_query);
break;
case alox_EspNowMessage_led_ring_tag:
if (!s_slave_joined || !mac_equal(info->src_addr, s_master_mac)) {
break;
@@ -838,6 +1007,17 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
return;
}
if (msg.which_payload == alox_EspNowMessage_battery_report_tag) {
ensure_peer(info->src_addr);
handle_master_battery_report(info->src_addr, &msg.payload.battery_report);
return;
}
if (msg.type == alox_EspNowMessageType_ESPNOW_BATTERY_REPORT &&
msg.which_payload != alox_EspNowMessage_battery_report_tag) {
ESP_LOGW(TAG, "master: BATTERY_REPORT type but which=%u", msg.which_payload);
}
const alox_EspNowSlavePresence *presence = esp_now_proto_get_presence(&msg);
if (presence != NULL) {
/* Registry key is the ESP-NOW sender MAC, not the optional protobuf mac field. */
@@ -933,6 +1113,16 @@ esp_err_t esp_now_comm_init(const app_config_t *config) {
return ESP_FAIL;
}
} else {
s_slave_tx_queue = xQueueCreate(4, sizeof(slave_tx_op_t));
if (s_slave_tx_queue == NULL) {
ESP_LOGE(TAG, "failed to create slave tx queue");
return ESP_ERR_NO_MEM;
}
if (xTaskCreate(slave_tx_task, "espnow_stx", 4096, NULL, 5, NULL) !=
pdPASS) {
ESP_LOGE(TAG, "failed to create slave tx task");
return ESP_FAIL;
}
if (xTaskCreate(slave_heartbeat_task, "espnow_hb", 4096, NULL, 4, NULL) !=
pdPASS) {
ESP_LOGE(TAG, "failed to create heartbeat task");
+1
View File
@@ -4,6 +4,7 @@
#include "app_config.h"
#include "client_registry.h"
#include "esp_err.h"
#include "esp_now_messages.pb.h"
#include "uart_messages.pb.h"
esp_err_t esp_now_comm_init(const app_config_t *config);
+4 -2
View File
@@ -11,6 +11,7 @@
#include "cmd_ota.h"
#include "cmd_ota_slave_progress.h"
#include "cmd_led_ring.h"
#include "cmd_battery.h"
#include "esp_now_comm.h"
#include "powerpod.h"
#include "driver/gpio.h"
@@ -163,6 +164,8 @@ void app_main(void) {
ESP_LOGI(TAG, "Running Partition: %s (OTA slot %d)",
app_config.running_partition, ota_slot);
board_input_init();
err = esp_now_comm_init(&app_config);
if (err != ESP_OK) {
ESP_LOGE(TAG, "ESP-NOW init failed: %s", esp_err_to_name(err));
@@ -170,8 +173,6 @@ void app_main(void) {
led_ring_init();
board_input_init();
if (app_config.master) {
cmd_queue = xQueueCreate(64, sizeof(generic_msg_t));
init_cmdHandler(cmd_queue);
@@ -185,6 +186,7 @@ void app_main(void) {
cmd_espnow_find_me_register();
cmd_restart_register();
cmd_led_ring_register();
cmd_battery_register();
cmd_ota_register();
cmd_ota_slave_progress_register();
}
+6
View File
@@ -30,6 +30,12 @@ PB_BIND(alox_EspNowAccelStream, alox_EspNowAccelStream, AUTO)
PB_BIND(alox_EspNowAccelSample, alox_EspNowAccelSample, AUTO)
PB_BIND(alox_EspNowBatteryQuery, alox_EspNowBatteryQuery, AUTO)
PB_BIND(alox_EspNowBatteryReport, alox_EspNowBatteryReport, AUTO)
PB_BIND(alox_EspNowLedRing, alox_EspNowLedRing, AUTO)
+60 -4
View File
@@ -25,7 +25,9 @@ typedef enum _alox_EspNowMessageType {
alox_EspNowMessageType_ESPNOW_RESTART = 11,
alox_EspNowMessageType_ESPNOW_ACCEL_SAMPLE = 12,
alox_EspNowMessageType_ESPNOW_SET_ACCEL_STREAM = 13,
alox_EspNowMessageType_ESPNOW_LED_RING = 14
alox_EspNowMessageType_ESPNOW_LED_RING = 14,
alox_EspNowMessageType_ESPNOW_BATTERY_QUERY = 15,
alox_EspNowMessageType_ESPNOW_BATTERY_REPORT = 16
} alox_EspNowMessageType;
/* Struct definitions */
@@ -76,6 +78,20 @@ typedef struct _alox_EspNowAccelSample {
int32_t z;
} alox_EspNowAccelSample;
/* * Master → slave: on-demand LiPo read (optional; slaves also push every ~30 s). */
typedef struct _alox_EspNowBatteryQuery {
uint32_t client_id;
} alox_EspNowBatteryQuery;
/* * Slave → master: LiPo voltages (periodic ~30 s and on query). */
typedef struct _alox_EspNowBatteryReport {
uint32_t client_id;
bool lipo1_valid;
bool lipo2_valid;
uint32_t lipo1_mv;
uint32_t lipo2_mv;
} alox_EspNowBatteryReport;
/* * Master → slave: LED ring command (same modes as UART LedRingProgressRequest). */
typedef struct _alox_EspNowLedRing {
uint32_t client_id;
@@ -132,6 +148,8 @@ typedef struct _alox_EspNowMessage {
alox_EspNowAccelSample accel_sample;
alox_EspNowAccelStream accel_stream;
alox_EspNowLedRing led_ring;
alox_EspNowBatteryQuery battery_query;
alox_EspNowBatteryReport battery_report;
} payload;
} alox_EspNowMessage;
@@ -142,8 +160,10 @@ extern "C" {
/* Helper constants for enums */
#define _alox_EspNowMessageType_MIN alox_EspNowMessageType_ESPNOW_UNKNOWN
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_LED_RING
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_LED_RING+1))
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_BATTERY_REPORT
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_BATTERY_REPORT+1))
@@ -170,6 +190,8 @@ extern "C" {
#define alox_EspNowAccelDeadzone_init_default {0, 0}
#define alox_EspNowAccelStream_init_default {0, 0}
#define alox_EspNowAccelSample_init_default {0, 0, 0, 0}
#define alox_EspNowBatteryQuery_init_default {0}
#define alox_EspNowBatteryReport_init_default {0, 0, 0, 0, 0}
#define alox_EspNowLedRing_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define alox_EspNowOtaStart_init_default {0}
#define alox_EspNowOtaPayload_init_default {0, {0, {0}}}
@@ -184,6 +206,8 @@ extern "C" {
#define alox_EspNowAccelDeadzone_init_zero {0, 0}
#define alox_EspNowAccelStream_init_zero {0, 0}
#define alox_EspNowAccelSample_init_zero {0, 0, 0, 0}
#define alox_EspNowBatteryQuery_init_zero {0}
#define alox_EspNowBatteryReport_init_zero {0, 0, 0, 0, 0}
#define alox_EspNowLedRing_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define alox_EspNowOtaStart_init_zero {0}
#define alox_EspNowOtaPayload_init_zero {0, {0, {0}}}
@@ -210,6 +234,12 @@ extern "C" {
#define alox_EspNowAccelSample_x_tag 2
#define alox_EspNowAccelSample_y_tag 3
#define alox_EspNowAccelSample_z_tag 4
#define alox_EspNowBatteryQuery_client_id_tag 1
#define alox_EspNowBatteryReport_client_id_tag 1
#define alox_EspNowBatteryReport_lipo1_valid_tag 2
#define alox_EspNowBatteryReport_lipo2_valid_tag 3
#define alox_EspNowBatteryReport_lipo1_mv_tag 4
#define alox_EspNowBatteryReport_lipo2_mv_tag 5
#define alox_EspNowLedRing_client_id_tag 1
#define alox_EspNowLedRing_mode_tag 2
#define alox_EspNowLedRing_progress_tag 3
@@ -241,6 +271,8 @@ extern "C" {
#define alox_EspNowMessage_accel_sample_tag 13
#define alox_EspNowMessage_accel_stream_tag 14
#define alox_EspNowMessage_led_ring_tag 15
#define alox_EspNowMessage_battery_query_tag 16
#define alox_EspNowMessage_battery_report_tag 17
/* Struct field encoding specification for nanopb */
#define alox_EspNowUnicastTest_FIELDLIST(X, a) \
@@ -293,6 +325,20 @@ X(a, STATIC, SINGULAR, SINT32, z, 4)
#define alox_EspNowAccelSample_CALLBACK NULL
#define alox_EspNowAccelSample_DEFAULT NULL
#define alox_EspNowBatteryQuery_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1)
#define alox_EspNowBatteryQuery_CALLBACK NULL
#define alox_EspNowBatteryQuery_DEFAULT NULL
#define alox_EspNowBatteryReport_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, SINGULAR, BOOL, lipo1_valid, 2) \
X(a, STATIC, SINGULAR, BOOL, lipo2_valid, 3) \
X(a, STATIC, SINGULAR, UINT32, lipo1_mv, 4) \
X(a, STATIC, SINGULAR, UINT32, lipo2_mv, 5)
#define alox_EspNowBatteryReport_CALLBACK NULL
#define alox_EspNowBatteryReport_DEFAULT NULL
#define alox_EspNowLedRing_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, SINGULAR, UINT32, mode, 2) \
@@ -345,7 +391,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,find_me,payload.find_me), 11) \
X(a, STATIC, ONEOF, MESSAGE, (payload,restart,payload.restart), 12) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_sample,payload.accel_sample), 13) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream,payload.accel_stream), 14) \
X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring,payload.led_ring), 15)
X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring,payload.led_ring), 15) \
X(a, STATIC, ONEOF, MESSAGE, (payload,battery_query,payload.battery_query), 16) \
X(a, STATIC, ONEOF, MESSAGE, (payload,battery_report,payload.battery_report), 17)
#define alox_EspNowMessage_CALLBACK NULL
#define alox_EspNowMessage_DEFAULT NULL
#define alox_EspNowMessage_payload_discover_MSGTYPE alox_EspNowDiscover
@@ -362,6 +410,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring,payload.led_ring), 15)
#define alox_EspNowMessage_payload_accel_sample_MSGTYPE alox_EspNowAccelSample
#define alox_EspNowMessage_payload_accel_stream_MSGTYPE alox_EspNowAccelStream
#define alox_EspNowMessage_payload_led_ring_MSGTYPE alox_EspNowLedRing
#define alox_EspNowMessage_payload_battery_query_MSGTYPE alox_EspNowBatteryQuery
#define alox_EspNowMessage_payload_battery_report_MSGTYPE alox_EspNowBatteryReport
extern const pb_msgdesc_t alox_EspNowUnicastTest_msg;
extern const pb_msgdesc_t alox_EspNowFindMe_msg;
@@ -371,6 +421,8 @@ extern const pb_msgdesc_t alox_EspNowSlavePresence_msg;
extern const pb_msgdesc_t alox_EspNowAccelDeadzone_msg;
extern const pb_msgdesc_t alox_EspNowAccelStream_msg;
extern const pb_msgdesc_t alox_EspNowAccelSample_msg;
extern const pb_msgdesc_t alox_EspNowBatteryQuery_msg;
extern const pb_msgdesc_t alox_EspNowBatteryReport_msg;
extern const pb_msgdesc_t alox_EspNowLedRing_msg;
extern const pb_msgdesc_t alox_EspNowOtaStart_msg;
extern const pb_msgdesc_t alox_EspNowOtaPayload_msg;
@@ -387,6 +439,8 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
#define alox_EspNowAccelDeadzone_fields &alox_EspNowAccelDeadzone_msg
#define alox_EspNowAccelStream_fields &alox_EspNowAccelStream_msg
#define alox_EspNowAccelSample_fields &alox_EspNowAccelSample_msg
#define alox_EspNowBatteryQuery_fields &alox_EspNowBatteryQuery_msg
#define alox_EspNowBatteryReport_fields &alox_EspNowBatteryReport_msg
#define alox_EspNowLedRing_fields &alox_EspNowLedRing_msg
#define alox_EspNowOtaStart_fields &alox_EspNowOtaStart_msg
#define alox_EspNowOtaPayload_fields &alox_EspNowOtaPayload_msg
@@ -401,6 +455,8 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
#define alox_EspNowAccelDeadzone_size 12
#define alox_EspNowAccelSample_size 24
#define alox_EspNowAccelStream_size 8
#define alox_EspNowBatteryQuery_size 6
#define alox_EspNowBatteryReport_size 22
#define alox_EspNowDiscover_size 6
#define alox_EspNowFindMe_size 6
#define alox_EspNowLedRing_size 60
+18
View File
@@ -20,6 +20,8 @@ enum EspNowMessageType {
ESPNOW_ACCEL_SAMPLE = 12;
ESPNOW_SET_ACCEL_STREAM = 13;
ESPNOW_LED_RING = 14;
ESPNOW_BATTERY_QUERY = 15;
ESPNOW_BATTERY_REPORT = 16;
}
message EspNowUnicastTest {
@@ -69,6 +71,20 @@ message EspNowAccelSample {
sint32 z = 4;
}
/** Master → slave: on-demand LiPo read (optional; slaves also push every ~30 s). */
message EspNowBatteryQuery {
uint32 client_id = 1;
}
/** Slave → master: LiPo voltages (periodic ~30 s and on query). */
message EspNowBatteryReport {
uint32 client_id = 1;
bool lipo1_valid = 2;
bool lipo2_valid = 3;
uint32 lipo1_mv = 4;
uint32 lipo2_mv = 5;
}
/** Master → slave: LED ring command (same modes as UART LedRingProgressRequest). */
message EspNowLedRing {
uint32 client_id = 1;
@@ -121,5 +137,7 @@ message EspNowMessage {
EspNowAccelSample accel_sample = 13;
EspNowAccelStream accel_stream = 14;
EspNowLedRing led_ring = 15;
EspNowBatteryQuery battery_query = 16;
EspNowBatteryReport battery_report = 17;
}
}
+12
View File
@@ -42,6 +42,18 @@ PB_BIND(alox_AccelStreamRequest, alox_AccelStreamRequest, AUTO)
PB_BIND(alox_AccelStreamResponse, alox_AccelStreamResponse, AUTO)
PB_BIND(alox_BatteryStatusRequest, alox_BatteryStatusRequest, AUTO)
PB_BIND(alox_LipoReading, alox_LipoReading, AUTO)
PB_BIND(alox_BatterySample, alox_BatterySample, AUTO)
PB_BIND(alox_BatteryStatusResponse, alox_BatteryStatusResponse, 2)
PB_BIND(alox_AccelSnapshotRequest, alox_AccelSnapshotRequest, AUTO)
+107 -5
View File
@@ -29,7 +29,8 @@ typedef enum _alox_MessageType {
alox_MessageType_FIND_ME = 22,
alox_MessageType_RESTART = 23,
alox_MessageType_ACCEL_SNAPSHOT = 24,
alox_MessageType_ACCEL_STREAM = 25
alox_MessageType_ACCEL_STREAM = 25,
alox_MessageType_BATTERY_STATUS = 26
} alox_MessageType;
/* Struct definitions */
@@ -108,6 +109,36 @@ typedef struct _alox_AccelStreamResponse {
uint32_t slaves_updated;
} alox_AccelStreamResponse;
/* * Host → master: read LiPo ADC voltages (master local and/or slaves via ESP-NOW). */
typedef struct _alox_BatteryStatusRequest {
/* * 0 = master only; >0 = one slave; ignored when all_clients */
uint32_t client_id;
/* * Master (client_id 0) plus every registered slave */
bool all_clients;
} alox_BatteryStatusRequest;
typedef struct _alox_LipoReading {
bool valid;
/* * Estimated pack voltage in millivolts from ADC */
uint32_t voltage_mv;
} alox_LipoReading;
typedef struct _alox_BatterySample {
uint32_t client_id;
bool has_lipo1;
alox_LipoReading lipo1;
bool has_lipo2;
alox_LipoReading lipo2;
/* * Milliseconds since last ESP-NOW battery report from this pod. */
uint32_t age_ms;
} alox_BatterySample;
typedef struct _alox_BatteryStatusResponse {
bool success;
pb_size_t samples_count;
alox_BatterySample samples[17];
} alox_BatteryStatusResponse;
/* Host → master: read cached accel samples from slaves (only while stream enabled).
client_id 0 = all registered slaves; otherwise one slave. */
typedef struct _alox_AccelSnapshotRequest {
@@ -271,6 +302,8 @@ typedef struct _alox_UartMessage {
alox_AccelSnapshotResponse accel_snapshot_response;
alox_AccelStreamRequest accel_stream_request;
alox_AccelStreamResponse accel_stream_response;
alox_BatteryStatusRequest battery_status_request;
alox_BatteryStatusResponse battery_status_response;
} payload;
} alox_UartMessage;
@@ -281,8 +314,8 @@ extern "C" {
/* Helper constants for enums */
#define _alox_MessageType_MIN alox_MessageType_UNKNOWN
#define _alox_MessageType_MAX alox_MessageType_ACCEL_STREAM
#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_ACCEL_STREAM+1))
#define _alox_MessageType_MAX alox_MessageType_BATTERY_STATUS
#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_BATTERY_STATUS+1))
#define alox_UartMessage_type_ENUMTYPE alox_MessageType
@@ -311,6 +344,10 @@ extern "C" {
@@ -329,6 +366,10 @@ extern "C" {
#define alox_AccelDeadzoneResponse_init_default {0, 0, 0, 0}
#define alox_AccelStreamRequest_init_default {0, 0, 0, 0}
#define alox_AccelStreamResponse_init_default {0, 0, 0, 0}
#define alox_BatteryStatusRequest_init_default {0, 0}
#define alox_LipoReading_init_default {0, 0}
#define alox_BatterySample_init_default {0, false, alox_LipoReading_init_default, false, alox_LipoReading_init_default, 0}
#define alox_BatteryStatusResponse_init_default {0, 0, {alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default}}
#define alox_AccelSnapshotRequest_init_default {0}
#define alox_AccelSample_init_default {0, 0, 0, 0, 0, 0}
#define alox_AccelSnapshotResponse_init_default {0, {alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default}}
@@ -359,6 +400,10 @@ extern "C" {
#define alox_AccelDeadzoneResponse_init_zero {0, 0, 0, 0}
#define alox_AccelStreamRequest_init_zero {0, 0, 0, 0}
#define alox_AccelStreamResponse_init_zero {0, 0, 0, 0}
#define alox_BatteryStatusRequest_init_zero {0, 0}
#define alox_LipoReading_init_zero {0, 0}
#define alox_BatterySample_init_zero {0, false, alox_LipoReading_init_zero, false, alox_LipoReading_init_zero, 0}
#define alox_BatteryStatusResponse_init_zero {0, 0, {alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero}}
#define alox_AccelSnapshotRequest_init_zero {0}
#define alox_AccelSample_init_zero {0, 0, 0, 0, 0, 0}
#define alox_AccelSnapshotResponse_init_zero {0, {alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero}}
@@ -413,6 +458,16 @@ extern "C" {
#define alox_AccelStreamResponse_client_id_tag 2
#define alox_AccelStreamResponse_success_tag 3
#define alox_AccelStreamResponse_slaves_updated_tag 4
#define alox_BatteryStatusRequest_client_id_tag 1
#define alox_BatteryStatusRequest_all_clients_tag 2
#define alox_LipoReading_valid_tag 1
#define alox_LipoReading_voltage_mv_tag 2
#define alox_BatterySample_client_id_tag 1
#define alox_BatterySample_lipo1_tag 2
#define alox_BatterySample_lipo2_tag 3
#define alox_BatterySample_age_ms_tag 4
#define alox_BatteryStatusResponse_success_tag 1
#define alox_BatteryStatusResponse_samples_tag 2
#define alox_AccelSnapshotRequest_client_id_tag 1
#define alox_AccelSample_client_id_tag 1
#define alox_AccelSample_valid_tag 2
@@ -493,6 +548,8 @@ extern "C" {
#define alox_UartMessage_accel_snapshot_response_tag 24
#define alox_UartMessage_accel_stream_request_tag 25
#define alox_UartMessage_accel_stream_response_tag 26
#define alox_UartMessage_battery_status_request_tag 27
#define alox_UartMessage_battery_status_response_tag 28
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@@ -521,7 +578,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,restart_response,payload.restart_res
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_snapshot_request,payload.accel_snapshot_request), 23) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_snapshot_response,payload.accel_snapshot_response), 24) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_request,payload.accel_stream_request), 25) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_stream_response), 26)
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_stream_response), 26) \
X(a, STATIC, ONEOF, MESSAGE, (payload,battery_status_request,payload.battery_status_request), 27) \
X(a, STATIC, ONEOF, MESSAGE, (payload,battery_status_response,payload.battery_status_response), 28)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@@ -549,6 +608,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_
#define alox_UartMessage_payload_accel_snapshot_response_MSGTYPE alox_AccelSnapshotResponse
#define alox_UartMessage_payload_accel_stream_request_MSGTYPE alox_AccelStreamRequest
#define alox_UartMessage_payload_accel_stream_response_MSGTYPE alox_AccelStreamResponse
#define alox_UartMessage_payload_battery_status_request_MSGTYPE alox_BatteryStatusRequest
#define alox_UartMessage_payload_battery_status_response_MSGTYPE alox_BatteryStatusResponse
#define alox_Ack_FIELDLIST(X, a) \
@@ -631,6 +692,35 @@ X(a, STATIC, SINGULAR, UINT32, slaves_updated, 4)
#define alox_AccelStreamResponse_CALLBACK NULL
#define alox_AccelStreamResponse_DEFAULT NULL
#define alox_BatteryStatusRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, SINGULAR, BOOL, all_clients, 2)
#define alox_BatteryStatusRequest_CALLBACK NULL
#define alox_BatteryStatusRequest_DEFAULT NULL
#define alox_LipoReading_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, valid, 1) \
X(a, STATIC, SINGULAR, UINT32, voltage_mv, 2)
#define alox_LipoReading_CALLBACK NULL
#define alox_LipoReading_DEFAULT NULL
#define alox_BatterySample_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, OPTIONAL, MESSAGE, lipo1, 2) \
X(a, STATIC, OPTIONAL, MESSAGE, lipo2, 3) \
X(a, STATIC, SINGULAR, UINT32, age_ms, 4)
#define alox_BatterySample_CALLBACK NULL
#define alox_BatterySample_DEFAULT NULL
#define alox_BatterySample_lipo1_MSGTYPE alox_LipoReading
#define alox_BatterySample_lipo2_MSGTYPE alox_LipoReading
#define alox_BatteryStatusResponse_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, success, 1) \
X(a, STATIC, REPEATED, MESSAGE, samples, 2)
#define alox_BatteryStatusResponse_CALLBACK NULL
#define alox_BatteryStatusResponse_DEFAULT NULL
#define alox_BatteryStatusResponse_samples_MSGTYPE alox_BatterySample
#define alox_AccelSnapshotRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1)
#define alox_AccelSnapshotRequest_CALLBACK NULL
@@ -772,6 +862,10 @@ extern const pb_msgdesc_t alox_AccelDeadzoneRequest_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneResponse_msg;
extern const pb_msgdesc_t alox_AccelStreamRequest_msg;
extern const pb_msgdesc_t alox_AccelStreamResponse_msg;
extern const pb_msgdesc_t alox_BatteryStatusRequest_msg;
extern const pb_msgdesc_t alox_LipoReading_msg;
extern const pb_msgdesc_t alox_BatterySample_msg;
extern const pb_msgdesc_t alox_BatteryStatusResponse_msg;
extern const pb_msgdesc_t alox_AccelSnapshotRequest_msg;
extern const pb_msgdesc_t alox_AccelSample_msg;
extern const pb_msgdesc_t alox_AccelSnapshotResponse_msg;
@@ -804,6 +898,10 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_AccelDeadzoneResponse_fields &alox_AccelDeadzoneResponse_msg
#define alox_AccelStreamRequest_fields &alox_AccelStreamRequest_msg
#define alox_AccelStreamResponse_fields &alox_AccelStreamResponse_msg
#define alox_BatteryStatusRequest_fields &alox_BatteryStatusRequest_msg
#define alox_LipoReading_fields &alox_LipoReading_msg
#define alox_BatterySample_fields &alox_BatterySample_msg
#define alox_BatteryStatusResponse_fields &alox_BatteryStatusResponse_msg
#define alox_AccelSnapshotRequest_fields &alox_AccelSnapshotRequest_msg
#define alox_AccelSample_fields &alox_AccelSample_msg
#define alox_AccelSnapshotResponse_fields &alox_AccelSnapshotResponse_msg
@@ -830,7 +928,7 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
/* alox_ClientInfo_size depends on runtime parameters */
/* alox_ClientInfoResponse_size depends on runtime parameters */
/* alox_ClientInputResponse_size depends on runtime parameters */
#define ALOX_UART_MESSAGES_PB_H_MAX_SIZE alox_AccelSnapshotResponse_size
#define ALOX_UART_MESSAGES_PB_H_MAX_SIZE alox_BatteryStatusResponse_size
#define alox_AccelDeadzoneRequest_size 16
#define alox_AccelDeadzoneResponse_size 20
#define alox_AccelSample_size 32
@@ -839,6 +937,9 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_AccelStreamRequest_size 12
#define alox_AccelStreamResponse_size 16
#define alox_Ack_size 0
#define alox_BatterySample_size 32
#define alox_BatteryStatusRequest_size 8
#define alox_BatteryStatusResponse_size 580
#define alox_ClientInput_size 22
#define alox_EspNowFindMeRequest_size 6
#define alox_EspNowFindMeResponse_size 8
@@ -846,6 +947,7 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_EspNowUnicastTestResponse_size 8
#define alox_LedRingProgressRequest_size 64
#define alox_LedRingProgressResponse_size 32
#define alox_LipoReading_size 8
#define alox_OtaEndPayload_size 0
#define alox_OtaPayload_size 209
#define alox_OtaSlaveProgressEntry_size 30
+30
View File
@@ -24,6 +24,7 @@ enum MessageType {
RESTART = 23;
ACCEL_SNAPSHOT = 24;
ACCEL_STREAM = 25;
BATTERY_STATUS = 26;
}
message UartMessage {
@@ -54,6 +55,8 @@ message UartMessage {
AccelSnapshotResponse accel_snapshot_response = 24;
AccelStreamRequest accel_stream_request = 25;
AccelStreamResponse accel_stream_response = 26;
BatteryStatusRequest battery_status_request = 27;
BatteryStatusResponse battery_status_response = 28;
}
}
@@ -130,6 +133,33 @@ message AccelStreamResponse {
uint32 slaves_updated = 4;
}
/** Host → master: read LiPo ADC voltages (master local and/or slaves via ESP-NOW). */
message BatteryStatusRequest {
/** 0 = master only; >0 = one slave; ignored when all_clients */
uint32 client_id = 1;
/** Master (client_id 0) plus every registered slave */
bool all_clients = 2;
}
message LipoReading {
bool valid = 1;
/** Estimated pack voltage in millivolts from ADC */
uint32 voltage_mv = 2;
}
message BatterySample {
uint32 client_id = 1;
LipoReading lipo1 = 2;
LipoReading lipo2 = 3;
/** Milliseconds since last ESP-NOW battery report from this pod. */
uint32 age_ms = 4;
}
message BatteryStatusResponse {
bool success = 1;
repeated BatterySample samples = 2 [(nanopb).max_count = 17];
}
// Host → master: read cached accel samples from slaves (only while stream enabled).
// client_id 0 = all registered slaves; otherwise one slave.
message AccelSnapshotRequest {