prevent watchdog from killing while printing json
This commit is contained in:
@@ -74,6 +74,7 @@ constexpr BatchRetryPolicy BATCH_RETRY_POLICY = BatchRetryPolicy::Keep;
|
||||
constexpr uint32_t WATCHDOG_TIMEOUT_SEC = 120;
|
||||
constexpr bool ENABLE_HA_DISCOVERY = true;
|
||||
constexpr bool SERIAL_DEBUG_MODE = true;
|
||||
constexpr bool SERIAL_DEBUG_DUMP_JSON = true;
|
||||
|
||||
constexpr uint8_t NUM_SENDERS = 1;
|
||||
inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = {
|
||||
|
||||
23
src/main.cpp
23
src/main.cpp
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user