Send ESP-NOW accel only on deadzone change and harden BLE+WiFi OTA coex.
Quiet pods no longer spam 100 Hz samples; mute wifi logs and throttle BLE notifies during slave distribution so the wifi task stack does not panic. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+36
-1
@@ -5,8 +5,10 @@
|
||||
#include "pod_reboot.h"
|
||||
#include "uart_cmd.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/idf_additions.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -32,6 +34,14 @@ typedef struct {
|
||||
uint32_t written;
|
||||
int slot;
|
||||
} ota_dist_job_t;
|
||||
|
||||
/** Cap host DISTRIBUTING pushes (BLE notifies compete with ESP-NOW OTA TX). */
|
||||
#define OTA_DIST_NOTIFY_MIN_US (250 * 1000ull)
|
||||
|
||||
static int64_t s_last_dist_agg_us;
|
||||
static int64_t s_last_dist_slave_us;
|
||||
static uint32_t s_last_dist_agg_bytes = UINT32_MAX;
|
||||
|
||||
static void send_ota_status(ota_uart_status_t status, uint32_t err_code) {
|
||||
alox_UartMessage response;
|
||||
uart_cmd_init_response(&response, alox_MessageType_OTA_STATUS,
|
||||
@@ -64,15 +74,33 @@ static void send_ota_distributing(uint32_t kind, uint32_t bytes_done,
|
||||
|
||||
static void ota_dist_aggregate(uint32_t bytes_done, uint32_t total_bytes,
|
||||
uint8_t slave_count) {
|
||||
(void)slave_count;
|
||||
led_ring_show_ota_progress(bytes_done, total_bytes, OTA_LED_ESPNOW_TX_R,
|
||||
OTA_LED_ESPNOW_TX_G, OTA_LED_ESPNOW_TX_B);
|
||||
|
||||
const int64_t now = esp_timer_get_time();
|
||||
const bool first = (s_last_dist_agg_bytes == UINT32_MAX);
|
||||
const bool boundary =
|
||||
(bytes_done == 0) || (total_bytes > 0 && bytes_done >= total_bytes);
|
||||
const bool paced =
|
||||
(now - s_last_dist_agg_us) >= (int64_t)OTA_DIST_NOTIFY_MIN_US;
|
||||
if (!first && !boundary && !paced) {
|
||||
return;
|
||||
}
|
||||
s_last_dist_agg_us = now;
|
||||
s_last_dist_agg_bytes = bytes_done;
|
||||
send_ota_distributing(OTA_DIST_AGGREGATE, bytes_done, (uint32_t)slave_count);
|
||||
}
|
||||
|
||||
static void ota_dist_per_slave(uint32_t slave_id, uint32_t bytes_done,
|
||||
uint32_t total_bytes) {
|
||||
(void)total_bytes;
|
||||
/* Host also polls OTA_SLAVE_PROGRESS; keep per-slave pushes rare on BLE. */
|
||||
const int64_t now = esp_timer_get_time();
|
||||
if ((now - s_last_dist_slave_us) < (int64_t)OTA_DIST_NOTIFY_MIN_US &&
|
||||
bytes_done > 0) {
|
||||
return;
|
||||
}
|
||||
s_last_dist_slave_us = now;
|
||||
send_ota_distributing(OTA_DIST_PER_SLAVE, bytes_done, slave_id);
|
||||
}
|
||||
|
||||
@@ -225,6 +253,9 @@ static void ota_distribute_task(void *param) {
|
||||
|
||||
led_ring_show_ota_progress(0, image_size, OTA_LED_ESPNOW_TX_R, OTA_LED_ESPNOW_TX_G,
|
||||
OTA_LED_ESPNOW_TX_B);
|
||||
s_last_dist_agg_us = 0;
|
||||
s_last_dist_slave_us = 0;
|
||||
s_last_dist_agg_bytes = UINT32_MAX;
|
||||
send_ota_distributing(OTA_DIST_AGGREGATE, 0, 0);
|
||||
|
||||
esp_err_t err = ota_espnow_distribute(part, image_size, &s_dist_progress);
|
||||
@@ -315,6 +346,10 @@ static void ota_start_espnow_task(void *param) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_last_dist_agg_us = 0;
|
||||
s_last_dist_slave_us = 0;
|
||||
s_last_dist_agg_bytes = UINT32_MAX;
|
||||
|
||||
esp_err_t err = ota_espnow_distribute(part, image_size, &s_dist_progress);
|
||||
if (err != ESP_OK) {
|
||||
send_ota_failed(42);
|
||||
|
||||
Reference in New Issue
Block a user