Public Access
- 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
76 lines
3.1 KiB
C++
76 lines
3.1 KiB
C++
#include <unity.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "packet_view.h"
|
|
|
|
using namespace roro::lora;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
static const uint8_t kMeshtastic[] = {
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0x78, 0x56, 0x34, 0x12, 0xEF, 0xBE, 0xAD, 0xDE,
|
|
0x62, // hop start 3, hop limit 2: relayed once
|
|
0x08, 0x00, 0x42, 0x01, 0x02, 0x03,
|
|
};
|
|
|
|
void test_row_for_a_meshtastic_packet() {
|
|
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.4f, 6.25f, true, Protocol::Meshtastic};
|
|
// Time, RSSI, SNR, then who sent it to whom (by default short name: the last 4 hex digits,
|
|
// as Meshtastic names a Node) and how far it came. Fits 40 columns with two node numbers.
|
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.2 5678>all 1/3", row(p, "21:45:07").c_str());
|
|
const uint8_t direct[] = {0x0a, 0x0b, 0x0c, 0x0d, 0xc4, 0xd3, 0xb2, 0xa1, 1, 2, 3, 4, 0x6a, 8, 0, 0xaa};
|
|
PacketSummary d{direct, sizeof direct, -117.0f, -9.25f, true, Protocol::Meshtastic};
|
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -117 -9.2 d3c4>0b0a 1/3", row(d, "21:45:07").c_str());
|
|
TEST_ASSERT_TRUE(row(d, "21:45:07").size() <= 38);
|
|
}
|
|
|
|
void test_row_for_something_else() {
|
|
const uint8_t data[] = {0x40, 0x01, 0x02};
|
|
PacketSummary p{data, sizeof data, -120.6f, -7.5f, true, Protocol::None};
|
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -121 -7.5 3 B", row(p, "21:45:07").c_str());
|
|
}
|
|
|
|
// Not on Meshtastic settings (LoRaWAN, say): the same bytes aren't read as a Meshtastic header.
|
|
void test_row_not_meshtastic() {
|
|
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.0f, 6.0f, true, Protocol::None};
|
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.0 19 B", row(p, "21:45:07").c_str());
|
|
}
|
|
|
|
void test_row_with_a_bad_crc() {
|
|
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.0f, 6.0f, false, Protocol::Meshtastic};
|
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.0 bad CRC, 19 B", row(p, "21:45:07").c_str());
|
|
}
|
|
|
|
void test_hex_dump() {
|
|
auto lines = hexDump(kMeshtastic, sizeof kMeshtastic);
|
|
TEST_ASSERT_EQUAL_size_t(3, lines.size());
|
|
TEST_ASSERT_EQUAL_STRING("0000 ff ff ff ff 78 56 34 12 ....xV4.", lines[0].c_str());
|
|
TEST_ASSERT_EQUAL_STRING("0008 ef be ad de 62 08 00 42 ....b..B", lines[1].c_str());
|
|
TEST_ASSERT_EQUAL_STRING("0010 01 02 03 ...", lines[2].c_str());
|
|
}
|
|
|
|
void test_header_lines() {
|
|
auto lines = headerLines(kMeshtastic, sizeof kMeshtastic);
|
|
TEST_ASSERT_EQUAL_size_t(5, lines.size());
|
|
TEST_ASSERT_EQUAL_STRING("From !12345678 to all", lines[0].c_str());
|
|
TEST_ASSERT_EQUAL_STRING("Packet deadbeef", lines[1].c_str());
|
|
TEST_ASSERT_EQUAL_STRING("Hops 1 of 3, limit 2 left", lines[2].c_str());
|
|
TEST_ASSERT_EQUAL_STRING("Channel 0x08 (LongFast, default key)", lines[3].c_str());
|
|
TEST_ASSERT_EQUAL_STRING("Relayed by ..42", lines[4].c_str());
|
|
TEST_ASSERT_EQUAL_size_t(0, headerLines(kMeshtastic, 12).size()); // too short to be Meshtastic
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_row_for_a_meshtastic_packet);
|
|
RUN_TEST(test_row_for_something_else);
|
|
RUN_TEST(test_row_not_meshtastic);
|
|
RUN_TEST(test_row_with_a_bad_crc);
|
|
RUN_TEST(test_hex_dump);
|
|
RUN_TEST(test_header_lines);
|
|
return UNITY_END();
|
|
}
|