Public Access
LoRa Scanner: a MeshCore preset, and its packets read
- MeshCore joins the presets (EU/UK Narrow: 869.618 MHz, 62.5 kHz, SF8, CR 4/8, sync 0x12), after the Meshtastic ones so stored choices keep their number; `lora preset MeshCore` on the console - lib/meshcore reads what MeshCore sends in clear: header, path, and a node's advert (name, kind, key, position) - the list row, the details, a Capture's viewer and the console echo read a packet by the sync word it was received on - the bandwidth is printed as 62.5, not 62 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0162FokPdvY2KsS4NBfwyWPk
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
#include "meshcore_packet.h"
|
||||
#include "meshtastic_header.h"
|
||||
#include "meshtastic_presets.h"
|
||||
|
||||
@@ -10,13 +11,97 @@ namespace roro::lora {
|
||||
|
||||
using namespace meshtastic;
|
||||
|
||||
namespace {
|
||||
std::string hex(const uint8_t* p, size_t n) {
|
||||
std::string out;
|
||||
char s[4];
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
std::snprintf(s, sizeof s, "%02x", p[i]);
|
||||
out += s;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// `room` characters at most: a node's name is cut to fit.
|
||||
std::string meshcoreRow(const meshcore::Packet& m, size_t room) {
|
||||
std::string out = meshcore::payloadShort(m.type);
|
||||
std::string hops = m.hops ? " " + std::to_string(m.hops) + "h" : "";
|
||||
meshcore::Advert a;
|
||||
if (meshcore::parseAdvert(m, a)) {
|
||||
size_t used = out.size() + 1 + hops.size();
|
||||
out += " " + (a.name.empty() ? hex(a.key, 2) : a.name.substr(0, room > used ? room - used : 0));
|
||||
} else if (m.addressed() && m.payloadLen >= 2)
|
||||
out += " " + hex(m.payload + 1, 1) + ">" + hex(m.payload, 1);
|
||||
else if (m.group() && m.payloadLen >= 1)
|
||||
out += " #" + hex(m.payload, 1);
|
||||
else if (m.type == meshcore::Payload::AnonRequest && m.payloadLen >= 1)
|
||||
out += " >" + hex(m.payload, 1);
|
||||
return out + hops;
|
||||
}
|
||||
|
||||
std::vector<std::string> meshcoreLines(const uint8_t* data, size_t len) {
|
||||
meshcore::Packet m;
|
||||
if (!meshcore::parsePacket(data, len, m)) return {};
|
||||
char s[64];
|
||||
std::vector<std::string> lines;
|
||||
lines.push_back("MeshCore " + std::string(meshcore::payloadName(m.type)) + ", " + meshcore::routeName(m.route));
|
||||
if (m.hasTransport) {
|
||||
std::snprintf(s, sizeof s, "Region code %04x", m.transport[0]);
|
||||
lines.push_back(s);
|
||||
}
|
||||
// A flood gathers who repeated it; a direct packet carries who is still to repeat it.
|
||||
if (m.hops) {
|
||||
std::string path = std::string(m.flood() ? "Through" : "Route");
|
||||
for (uint8_t i = 0; i < m.hops; ++i) {
|
||||
std::string hop = " " + hex(m.path + i * m.hashSize, m.hashSize);
|
||||
if (path.size() + hop.size() > 36) { // onto another line
|
||||
lines.push_back(path);
|
||||
path = " ";
|
||||
}
|
||||
path += hop;
|
||||
}
|
||||
lines.push_back(path);
|
||||
} else {
|
||||
lines.push_back(m.flood() ? "Heard first hand: no repeater yet" : "No route in it: to a neighbour");
|
||||
}
|
||||
meshcore::Advert a;
|
||||
if (meshcore::parseAdvert(m, a)) {
|
||||
lines.push_back(std::string(meshcore::kindName(a.kind)) + (a.name.empty() ? "" : " " + a.name));
|
||||
lines.push_back("Key " + hex(a.key, 8) + "...");
|
||||
if (a.hasLocation) {
|
||||
std::snprintf(s, sizeof s, "At %.5f, %.5f", a.latE6 / 1e6, a.lonE6 / 1e6);
|
||||
lines.push_back(s);
|
||||
}
|
||||
} else if (m.addressed() && m.payloadLen >= 4) {
|
||||
std::snprintf(s, sizeof s, "From ..%02x to ..%02x, %u B encrypted", m.payload[1], m.payload[0], static_cast<unsigned>(m.payloadLen - 4));
|
||||
lines.push_back(s);
|
||||
} else if (m.group() && m.payloadLen >= 3) {
|
||||
std::snprintf(s, sizeof s, "Channel 0x%02x%s, %u B encrypted", m.payload[0], m.payload[0] == meshcore::kPublicChannelHash ? " (public?)" : "",
|
||||
static_cast<unsigned>(m.payloadLen - 3));
|
||||
lines.push_back(s);
|
||||
} else if (m.type == meshcore::Payload::AnonRequest && m.payloadLen >= 35) {
|
||||
std::snprintf(s, sizeof s, "To ..%02x from key %s...", m.payload[0], hex(m.payload + 1, 4).c_str());
|
||||
lines.push_back(s);
|
||||
} else if (m.type == meshcore::Payload::Ack && m.payloadLen >= 4) {
|
||||
lines.push_back("Acknowledges " + hex(m.payload, 4));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Protocol protocolOf(uint8_t syncWord) {
|
||||
return syncWord == meshtastic::kSyncWord ? Protocol::Meshtastic : syncWord == meshcore::kSyncWord ? Protocol::MeshCore : Protocol::None;
|
||||
}
|
||||
|
||||
std::string row(const PacketSummary& p, const std::string& time) {
|
||||
char s[64];
|
||||
int n = std::snprintf(s, sizeof s, "%s %ld %.1f ", time.c_str(), std::lround(p.rssi), p.snr);
|
||||
std::string out(s, n);
|
||||
PacketHeader h;
|
||||
if (!p.crcOk) return out + "bad CRC, " + std::to_string(p.len) + " B";
|
||||
if (!p.meshtastic || !parseHeader(p.data, p.len, h)) return out + std::to_string(p.len) + " B";
|
||||
meshcore::Packet m;
|
||||
if (p.protocol == Protocol::MeshCore && meshcore::parsePacket(p.data, p.len, m)) return out + meshcoreRow(m, out.size() < 38 ? 38 - out.size() : 0);
|
||||
if (p.protocol != Protocol::Meshtastic || !parseHeader(p.data, p.len, h)) return out + std::to_string(p.len) + " B";
|
||||
auto shortId = [](uint32_t node) {
|
||||
if (node == kBroadcast) return std::string("all");
|
||||
char id[8];
|
||||
@@ -48,7 +133,9 @@ std::vector<std::string> hexDump(const uint8_t* data, size_t len) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::vector<std::string> headerLines(const uint8_t* data, size_t len) {
|
||||
std::vector<std::string> headerLines(const uint8_t* data, size_t len, Protocol protocol) {
|
||||
if (protocol == Protocol::MeshCore) return meshcoreLines(data, len);
|
||||
if (protocol != Protocol::Meshtastic) return {};
|
||||
PacketHeader h;
|
||||
if (!parseHeader(data, len, h)) return {};
|
||||
char s[64];
|
||||
|
||||
Reference in New Issue
Block a user