diff --git a/main/main.c b/main/main.c index c5976d2..f411a46 100644 --- a/main/main.c +++ b/main/main.c @@ -68,6 +68,7 @@ static void resync_wrapper(tcp_bridge_resync_type_t type, const uint8_t *data, i case TCP_BRIDGE_RESYNC_BAD_END: s_pool_state.resyncs_bad_end++; break; case TCP_BRIDGE_RESYNC_BAD_DATA_CHECKSUM: s_pool_state.resyncs_bad_data_checksum++; break; case TCP_BRIDGE_RESYNC_BUFFER_OVERFLOW: s_pool_state.resyncs_buffer_overflow++; break; + default: s_pool_state.resyncs_unexpected++; break; } xSemaphoreGive(s_pool_state_mutex); diff --git a/main/message_decoder.c b/main/message_decoder.c index 6eae2fd..3b9c22b 100644 --- a/main/message_decoder.c +++ b/main/message_decoder.c @@ -2899,6 +2899,11 @@ static bool handle_pump_buttons( static bool dispatch_message(const uint8_t *data, int len, const uint8_t *payload, int payload_len, const char *addr_info, message_decoder_context_t *ctx); +// This function assumes the framing layer has validated that the message buffer +// has valid checksums, start and stop bytes etc. It does not repeat the validation. +// Note also that this function can be called directly by the test harness and from +// the TX-echo path - in these cases it is incumbent on the caller to ensure that +// messages are valid. bool decode_message(const uint8_t *data, int len, message_decoder_context_t *ctx) { if (!ctx || !ctx->pool_state) { diff --git a/main/pool_state.h b/main/pool_state.h index 2944a6a..4531d63 100644 --- a/main/pool_state.h +++ b/main/pool_state.h @@ -259,6 +259,7 @@ typedef struct { uint32_t resyncs_bad_end; // End byte != 0x03 at declared length uint32_t resyncs_bad_data_checksum; // Data checksum mismatch uint32_t resyncs_buffer_overflow; // Buffer filled without a complete frame + uint32_t resyncs_unexpected; // Resync for unexpected reason - this should be investigated // Timers (up to MAX_TIMERS) timer_state_t timers[MAX_TIMERS]; diff --git a/main/web_handlers.c b/main/web_handlers.c index ed387d6..356137e 100644 --- a/main/web_handlers.c +++ b/main/web_handlers.c @@ -639,6 +639,7 @@ static esp_err_t status_get_handler(httpd_req_t *req) cJSON_AddNumberToObject(resyncs, "bad_end", state.resyncs_bad_end); cJSON_AddNumberToObject(resyncs, "data_checksum", state.resyncs_bad_data_checksum); cJSON_AddNumberToObject(resyncs, "buffer_overflow", state.resyncs_buffer_overflow); + cJSON_AddNumberToObject(resyncs, "unexpected", state.resyncs_unexpected); cJSON_AddItemToObject(root, "resyncs", resyncs); // Devices observed on the bus