Add missing traceroute fields to serialized JSON output (#6087)

This commit is contained in:
noahhaon 2025-02-18 20:25:55 +01:00 committed by GitHub
parent 3b0232de1b
commit c67aa25d19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -220,7 +220,11 @@ std::string MeshPacketSerializer::JsonSerialize(const meshtastic_MeshPacket *mp,
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_RouteDiscovery_msg,
&scratch)) {
decoded = &scratch;
JSONArray route; // Route this message took
JSONArray route; // Route this message took
JSONArray routeBack; // Route this message took back
JSONArray snrTowards; // Snr for forward route
JSONArray snrBack; // Snr for reverse route
// Lambda function for adding a long name to the route
auto addToRoute = [](JSONArray *route, NodeNum num) {
char long_name[40] = "Unknown";
@ -236,7 +240,24 @@ std::string MeshPacketSerializer::JsonSerialize(const meshtastic_MeshPacket *mp,
}
addToRoute(&route, mp->from); // Ended at the original destination (source of response)
addToRoute(&routeBack, mp->from); // Started at the original destination (source of response)
for (uint8_t i = 0; i < decoded->route_back_count; i++) {
addToRoute(&routeBack, decoded->route_back[i]);
}
addToRoute(&routeBack, mp->to); // Ended at the original transmitter (destination of response)
for (uint8_t i = 0; i < decoded->snr_back_count; i++) {
snrBack.push_back(new JSONValue((float)decoded->snr_back[i] / 4));
}
for (uint8_t i = 0; i < decoded->snr_towards_count; i++) {
snrTowards.push_back(new JSONValue((float)decoded->snr_towards[i] / 4));
}
msgPayload["route"] = new JSONValue(route);
msgPayload["route_back"] = new JSONValue(routeBack);
msgPayload["snr_back"] = new JSONValue(snrBack);
msgPayload["snr_towards"] = new JSONValue(snrTowards);
jsonObj["payload"] = new JSONValue(msgPayload);
} else if (shouldLog) {
LOG_ERROR(errStr, msgType.c_str());