Skip to content

Commit 0e8f751

Browse files
committed
feat(sec-touch): add logs to wrong formed messages for future debugging
1 parent 5fdac4a commit 0e8f751

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

components/sec_touch/sec_touch.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,21 @@ void SECTouchComponent::loop() {
6262
EnumToString::TaskType(this->current_running_task_type));
6363
return;
6464
}
65-
ESP_LOGW(TAG, "[watchdog] Task of type %s for property_id %d timed out, forcing cleanup",
66-
EnumToString::TaskType(this->current_running_task_type), this->current_running_task_property_id_);
65+
if (this->incoming_message.buffer_index >= 0) {
66+
char hex_buf[128];
67+
int hex_pos = 0;
68+
int plen = this->incoming_message.buffer_index + 1;
69+
for (int i = 0; i < plen && hex_pos < (int) sizeof(hex_buf) - 4; i++) {
70+
hex_pos += snprintf(hex_buf + hex_pos, sizeof(hex_buf) - hex_pos, "%02X ",
71+
(uint8_t) this->incoming_message.buffer[i]);
72+
}
73+
ESP_LOGW(TAG, "[watchdog] Task of type %s for property_id %d timed out — partial buffer (%d bytes: %s)",
74+
EnumToString::TaskType(this->current_running_task_type), this->current_running_task_property_id_,
75+
plen, hex_buf);
76+
} else {
77+
ESP_LOGW(TAG, "[watchdog] Task of type %s for property_id %d timed out — no response received",
78+
EnumToString::TaskType(this->current_running_task_type), this->current_running_task_property_id_);
79+
}
6780
this->cleanup_after_task_complete(true, true);
6881
}
6982

@@ -399,7 +412,14 @@ Now, we need to extract the parts of the message. It can be either:
399412
}
400413
}
401414
if (tab1 == -1 || tab2 == -1 || tab3 == -1) {
402-
ESP_LOGE(TAG_UART, " [process_data] Not enough TABs in message. Task Failed");
415+
char hex_buf[128];
416+
int hex_pos = 0;
417+
for (int i = 0; i < len && hex_pos < (int) sizeof(hex_buf) - 4; i++) {
418+
hex_pos += snprintf(hex_buf + hex_pos, sizeof(hex_buf) - hex_pos, "%02X ", (uint8_t) buf[i]);
419+
}
420+
ESP_LOGE(TAG_UART, " [process_data] Not enough TABs in message (task=%s property_id=%d len=%d hex: %s). Task Failed",
421+
EnumToString::TaskType(this->current_running_task_type), this->current_running_task_property_id_, len,
422+
hex_buf);
403423
this->cleanup_after_task_complete(true);
404424
return;
405425
}

0 commit comments

Comments
 (0)