mirror of
https://github.com/agessaman/MeshCore.git
synced 2026-10-16 02:20:18 +00:00
feat(mesh): enhance packet logging with human-readable RX/TX output
This commit is contained in:
+31
-24
@@ -1,7 +1,8 @@
|
||||
#include "Dispatcher.h"
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
#if MESH_PACKET_LOGGING_TEXT
|
||||
#include <Arduino.h>
|
||||
#include <helpers/SerialPacketLog.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
@@ -250,22 +251,26 @@ void Dispatcher::checkRecv() {
|
||||
}
|
||||
}
|
||||
if (pkt) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.printf(": RX, len=%d (type=%d, route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d time=%d",
|
||||
pkt->getRawLength(), pkt->getPayloadType(), pkt->isRouteDirect() ? "D" : "F", pkt->payload_len,
|
||||
(int)pkt->getSNR(), (int)_radio->getLastRSSI(), (int)(score*1000), air_time);
|
||||
#if MESH_PACKET_LOGGING_TEXT
|
||||
{
|
||||
SerialLogLine<192> line;
|
||||
line.printf("%s: RX, len=%d (type=%d, route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d time=%d",
|
||||
getLogDateTime(), pkt->getRawLength(), pkt->getPayloadType(),
|
||||
pkt->isRouteDirect() ? "D" : "F", pkt->payload_len,
|
||||
(int)pkt->getSNR(), (int)_radio->getLastRSSI(), (int)(score*1000), air_time);
|
||||
|
||||
static uint8_t packet_hash[MAX_HASH_SIZE];
|
||||
pkt->calculatePacketHash(packet_hash);
|
||||
Serial.print(" hash=");
|
||||
mesh::Utils::printHex(Serial, packet_hash, MAX_HASH_SIZE);
|
||||
uint8_t packet_hash[MAX_HASH_SIZE];
|
||||
pkt->calculatePacketHash(packet_hash);
|
||||
line.printf(" hash=");
|
||||
line.hex(packet_hash, MAX_HASH_SIZE);
|
||||
|
||||
if (pkt->getPayloadType() == PAYLOAD_TYPE_PATH || pkt->getPayloadType() == PAYLOAD_TYPE_REQ
|
||||
|| pkt->getPayloadType() == PAYLOAD_TYPE_RESPONSE || pkt->getPayloadType() == PAYLOAD_TYPE_TXT_MSG) {
|
||||
Serial.printf(" [%02X -> %02X]\n", (uint32_t)pkt->payload[1], (uint32_t)pkt->payload[0]);
|
||||
} else {
|
||||
Serial.printf("\n");
|
||||
if (pkt->getPayloadType() == PAYLOAD_TYPE_PATH || pkt->getPayloadType() == PAYLOAD_TYPE_REQ
|
||||
|| pkt->getPayloadType() == PAYLOAD_TYPE_RESPONSE || pkt->getPayloadType() == PAYLOAD_TYPE_TXT_MSG) {
|
||||
// No spaces around the arrow: a host parser must be able to split CLI replies on
|
||||
// "->" without colliding with log lines.
|
||||
line.printf(" [%02X>%02X]", (uint32_t)pkt->payload[1], (uint32_t)pkt->payload[0]);
|
||||
}
|
||||
line.flush(Serial);
|
||||
}
|
||||
#endif
|
||||
logRx(pkt, pkt->getRawLength(), score); // hook for custom logging
|
||||
@@ -371,15 +376,17 @@ void Dispatcher::checkSend() {
|
||||
}
|
||||
outbound_expiry = futureMillis(max_airtime);
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.printf(": TX, len=%d (type=%d, route=%s, payload_len=%d)",
|
||||
len, outbound->getPayloadType(), outbound->isRouteDirect() ? "D" : "F", outbound->payload_len);
|
||||
if (outbound->getPayloadType() == PAYLOAD_TYPE_PATH || outbound->getPayloadType() == PAYLOAD_TYPE_REQ
|
||||
|| outbound->getPayloadType() == PAYLOAD_TYPE_RESPONSE || outbound->getPayloadType() == PAYLOAD_TYPE_TXT_MSG) {
|
||||
Serial.printf(" [%02X -> %02X]\n", (uint32_t)outbound->payload[1], (uint32_t)outbound->payload[0]);
|
||||
} else {
|
||||
Serial.printf("\n");
|
||||
#if MESH_PACKET_LOGGING_TEXT
|
||||
{
|
||||
SerialLogLine<192> line;
|
||||
line.printf("%s: TX, len=%d (type=%d, route=%s, payload_len=%d)",
|
||||
getLogDateTime(), len, outbound->getPayloadType(),
|
||||
outbound->isRouteDirect() ? "D" : "F", outbound->payload_len);
|
||||
if (outbound->getPayloadType() == PAYLOAD_TYPE_PATH || outbound->getPayloadType() == PAYLOAD_TYPE_REQ
|
||||
|| outbound->getPayloadType() == PAYLOAD_TYPE_RESPONSE || outbound->getPayloadType() == PAYLOAD_TYPE_TXT_MSG) {
|
||||
line.printf(" [%02X>%02X]", (uint32_t)outbound->payload[1], (uint32_t)outbound->payload[0]);
|
||||
}
|
||||
line.flush(Serial);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user