prevent watchdog from killing while printing json

This commit is contained in:
2026-02-01 18:59:12 +01:00
parent f9bcfbd5f2
commit 660d1cde94
2 changed files with 23 additions and 1 deletions

View File

@@ -87,6 +87,8 @@ static uint16_t g_inflight_batch_id = 0;
static bool g_inflight_active = false;
static uint32_t g_last_debug_log_ms = 0;
static void watchdog_kick();
static void serial_debug_printf(const char *fmt, ...) {
if (!SERIAL_DEBUG_MODE) {
return;
@@ -99,6 +101,25 @@ static void serial_debug_printf(const char *fmt, ...) {
Serial.println(buf);
}
static void serial_debug_print_json(const String &json) {
if (!SERIAL_DEBUG_MODE || !SERIAL_DEBUG_DUMP_JSON) {
return;
}
const char *data = json.c_str();
size_t len = json.length();
const size_t chunk = 128;
for (size_t i = 0; i < len; i += chunk) {
size_t n = len - i;
if (n > chunk) {
n = chunk;
}
Serial.write(reinterpret_cast<const uint8_t *>(data + i), n);
watchdog_kick();
delay(0);
}
Serial.write('\n');
}
static uint16_t g_last_batch_id_rx[NUM_SENDERS] = {};
struct BatchRxState {
@@ -376,7 +397,7 @@ static bool send_inflight_batch(uint32_t ts_for_display) {
}
if (SERIAL_DEBUG_MODE) {
serial_debug_printf("tx: batch_id=%u count=%u json_len=%u", g_inflight_batch_id, g_inflight_count, static_cast<unsigned>(json.length()));
Serial.println(json);
serial_debug_print_json(json);
}
static uint8_t compressed[BATCH_MAX_COMPRESSED];