From 7f31b9dd95d1aef80fbe2e0159192b8df9b5fc19 Mon Sep 17 00:00:00 2001 From: acidburns Date: Sun, 1 Feb 2026 19:21:59 +0100 Subject: [PATCH] instrument tx timings for watchdog analysis --- src/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8b68f8a..0dcc846 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -339,12 +339,19 @@ static bool send_batch_payload(const uint8_t *data, size_t len, uint32_t ts_for_ write_u16_le(&payload[4], static_cast(len)); memcpy(&payload[BATCH_HEADER_SIZE], data + offset, chunk_len); + watchdog_kick(); + uint32_t tx_start = millis(); bool ok = lora_send(pkt); + uint32_t tx_ms = millis() - tx_start; all_ok = all_ok && ok; if (!ok) { note_fault(g_sender_faults, g_sender_last_error, g_sender_last_error_utc, g_sender_last_error_ms, FaultType::LoraTx); display_set_last_error(g_sender_last_error, g_sender_last_error_utc, g_sender_last_error_ms); } + if (SERIAL_DEBUG_MODE && tx_ms > 500) { + serial_debug_printf("tx: chunk %u/%u took %lums ok=%u", static_cast(i + 1), + static_cast(chunk_count), static_cast(tx_ms), ok ? 1 : 0); + } offset += chunk_len; delay(10); } @@ -391,22 +398,37 @@ static bool send_inflight_batch(uint32_t ts_for_display) { if (!g_inflight_active || g_inflight_count == 0) { return false; } + uint32_t json_start = millis(); String json; if (!meterBatchToJson(g_inflight_samples, g_inflight_count, g_inflight_batch_id, json, &g_sender_faults, g_sender_last_error)) { return false; } + uint32_t json_ms = millis() - json_start; 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(json.length())); + if (json_ms > 200) { + serial_debug_printf("tx: json encode took %lums", static_cast(json_ms)); + } serial_debug_print_json(json); } static uint8_t compressed[BATCH_MAX_COMPRESSED]; size_t compressed_len = 0; + uint32_t compress_start = millis(); if (!compressBuffer(reinterpret_cast(json.c_str()), json.length(), compressed, sizeof(compressed), compressed_len)) { return false; } + uint32_t compress_ms = millis() - compress_start; + if (SERIAL_DEBUG_MODE && compress_ms > 200) { + serial_debug_printf("tx: compress took %lums", static_cast(compress_ms)); + } + uint32_t send_start = millis(); bool ok = send_batch_payload(compressed, compressed_len, ts_for_display, g_inflight_batch_id); + uint32_t send_ms = millis() - send_start; + if (SERIAL_DEBUG_MODE && send_ms > 1000) { + serial_debug_printf("tx: send batch took %lums", static_cast(send_ms)); + } if (ok) { g_last_batch_send_ms = millis(); serial_debug_printf("tx: sent batch_id=%u len=%u", g_inflight_batch_id, static_cast(compressed_len));