Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 78 additions & 60 deletions meshtastic_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ MeshtasticDecoder::decodePacket(const std::vector<uint8_t>& raw_data)
result.sensor_id = 0;
result.next_update = 0;
result.seq_number = 0;
result.node_id = "";
result.node_id_str = "";
result.long_name = "";
result.short_name = "";
result.macaddr = "";
result.hw_model = "";
result.firmware_version = "";
result.mqtt_id = "";
result.macaddr_str = "";
result.hw_model_str = "";
result.is_licensed_str = "";
result.role_str = "";
result.text_message = "";
result.from_node = "";
result.to_node = "";
Expand Down Expand Up @@ -650,12 +650,12 @@ MeshtasticDecoder::decodePacket(const std::vector<uint8_t>& raw_data)
}

// Set node_id from from_address (only if not already set by protobuf parsing)
if (result.node_id.empty())
if (result.node_id_str.empty())
{
std::stringstream ss;
ss << "!" << std::hex << std::setfill('0') << std::setw(8)
<< result.from_address;
result.node_id = ss.str();
result.node_id_str = ss.str();
}

result.success = true;
Expand Down Expand Up @@ -1456,7 +1456,7 @@ bool MeshtasticDecoder::decodeNodeInfo(
std::string field_data(
user_data.begin() + offset,
user_data.begin() + offset + field_length);
packet.node_id = field_data;
packet.node_id_str = field_data;
offset += field_length;
}
}
Expand Down Expand Up @@ -1519,7 +1519,7 @@ bool MeshtasticDecoder::decodeNodeInfo(
mac_bytes[3],
mac_bytes[4],
mac_bytes[5]);
packet.macaddr = std::string(mac_str);
packet.macaddr_str = std::string(mac_str);
}
else
{
Expand All @@ -1531,7 +1531,7 @@ bool MeshtasticDecoder::decodeNodeInfo(
snprintf(hex, sizeof(hex), "%02X", b);
hex_mac += hex;
}
packet.macaddr = hex_mac;
packet.macaddr_str = hex_mac;
}
offset += field_length;
}
Expand All @@ -1546,85 +1546,85 @@ bool MeshtasticDecoder::decodeNodeInfo(
switch (hw_model)
{
case 0:
packet.hw_model = "UNSET";
packet.hw_model_str = "UNSET";
break;
case 1:
packet.hw_model = "TLORA_V2";
packet.hw_model_str = "TLORA_V2";
break;
case 2:
packet.hw_model = "TLORA_V1";
packet.hw_model_str = "TLORA_V1";
break;
case 3:
packet.hw_model = "TLORA_V2_1_1P6";
packet.hw_model_str = "TLORA_V2_1_1P6";
break;
case 4:
packet.hw_model = "TBEAM";
packet.hw_model_str = "TBEAM";
break;
case 5:
packet.hw_model = "HELTEC_V2_0";
packet.hw_model_str = "HELTEC_V2_0";
break;
case 6:
packet.hw_model = "TBEAM_V0P7";
packet.hw_model_str = "TBEAM_V0P7";
break;
case 7:
packet.hw_model = "T_ECHO";
packet.hw_model_str = "T_ECHO";
break;
case 8:
packet.hw_model = "TLORA_V1_1P3";
packet.hw_model_str = "TLORA_V1_1P3";
break;
case 9:
packet.hw_model = "RAK4631";
packet.hw_model_str = "RAK4631";
break;
case 10:
packet.hw_model = "HELTEC_V2_1";
packet.hw_model_str = "HELTEC_V2_1";
break;
case 11:
packet.hw_model = "HELTEC_V1";
packet.hw_model_str = "HELTEC_V1";
break;
case 12:
packet.hw_model = "LILYGO_TBEAM_S3_CORE";
packet.hw_model_str = "LILYGO_TBEAM_S3_CORE";
break;
case 13:
packet.hw_model = "RAK11200";
packet.hw_model_str = "RAK11200";
break;
case 14:
packet.hw_model = "NANO_G1";
packet.hw_model_str = "NANO_G1";
break;
case 15:
packet.hw_model = "TLORA_V2_1_1P8";
packet.hw_model_str = "TLORA_V2_1_1P8";
break;
case 16:
packet.hw_model = "TLORA_T3_S3";
packet.hw_model_str = "TLORA_T3_S3";
break;
case 17:
packet.hw_model = "NANO_G1_EXPLORER";
packet.hw_model_str = "NANO_G1_EXPLORER";
break;
case 18:
packet.hw_model = "NANO_G2_ULTRA";
packet.hw_model_str = "NANO_G2_ULTRA";
break;
case 19:
packet.hw_model = "LORA_TYPE";
packet.hw_model_str = "LORA_TYPE";
break;
case 20:
packet.hw_model = "WIPHONE";
packet.hw_model_str = "WIPHONE";
break;
case 21:
packet.hw_model = "WIO_WM1110";
packet.hw_model_str = "WIO_WM1110";
break;
case 22:
packet.hw_model = "RAK2560";
packet.hw_model_str = "RAK2560";
break;
case 23:
packet.hw_model = "HELTEC_HRU_3601";
packet.hw_model_str = "HELTEC_HRU_3601";
break;
case 24:
packet.hw_model = "T_DECK";
case 50:
packet.hw_model_str = "T_DECK";
break;
case 25:
packet.hw_model = "T_PAGER";
case 103:
packet.hw_model_str = "T_LORA_PAGER";
break;
default:
packet.hw_model =
packet.hw_model_str =
"UNKNOWN_" + std::to_string(hw_model);
break;
}
Expand All @@ -1635,7 +1635,7 @@ bool MeshtasticDecoder::decodeNodeInfo(
if (wire_type == 0)
{ // Varint
uint64_t licensed = decodeVarint(user_data, offset);
packet.firmware_version = licensed ? "Yes" : "No";
packet.is_licensed_str = licensed ? "Yes" : "No";
}
break;

Expand All @@ -1646,28 +1646,46 @@ bool MeshtasticDecoder::decodeNodeInfo(
switch (role)
{
case 0:
packet.mqtt_id = "CLIENT";
packet.role_str = "CLIENT";
break;
case 1:
packet.mqtt_id = "CLIENT_MUTE";
packet.role_str = "CLIENT_MUTE";
break;
case 2:
packet.mqtt_id = "ROUTER";
packet.role_str = "ROUTER";
break;
case 3:
packet.mqtt_id = "ROUTER_CLIENT";
packet.role_str = "ROUTER_CLIENT";
break;
case 4:
packet.mqtt_id = "REPEATER";
packet.role_str = "REPEATER";
break;
case 5:
packet.mqtt_id = "TRACKER";
packet.role_str = "TRACKER";
break;
case 6:
packet.mqtt_id = "SENSOR";
packet.role_str = "SENSOR";
break;
case 7:
packet.role_str = "TAK";
break;
case 8:
packet.role_str = "CLIENT_HIDDEN";
break;
case 9:
packet.role_str = "LOST_AND_FOUND";
break;
case 10:
packet.role_str = "TAK_TRACKER";
break;
case 11:
packet.role_str = "ROUTER_LATE";
break;
case 12:
packet.role_str = "CLIENT_BASE";
break;
default:
packet.mqtt_id =
packet.role_str =
"UNKNOWN_" + std::to_string(role);
break;
}
Expand Down Expand Up @@ -3198,12 +3216,12 @@ std::string MeshtasticDecoder::toJson(const DecodedPacket& packet)
{ // NODEINFO_APP
json << " \"node_info\": {\n";
bool first = true;
if (!packet.node_id.empty())
if (!packet.node_id_str.empty())
{
if (!first)
json << ",\n";
json << " \"node_id\": \""
<< escapeJsonString(packet.node_id) << "\"";
<< escapeJsonString(packet.node_id_str) << "\"";
first = false;
}
if (!packet.long_name.empty())
Expand All @@ -3222,36 +3240,36 @@ std::string MeshtasticDecoder::toJson(const DecodedPacket& packet)
<< escapeJsonString(packet.short_name) << "\"";
first = false;
}
if (!packet.macaddr.empty())
if (!packet.macaddr_str.empty())
{
if (!first)
json << ",\n";
json << " \"macaddr\": \""
<< escapeJsonString(packet.macaddr) << "\"";
<< escapeJsonString(packet.macaddr_str) << "\"";
first = false;
}
if (!packet.hw_model.empty())
if (!packet.hw_model_str.empty())
{
if (!first)
json << ",\n";
json << " \"hw_model\": \""
<< escapeJsonString(packet.hw_model) << "\"";
<< escapeJsonString(packet.hw_model_str) << "\"";
first = false;
}
if (!packet.firmware_version.empty())
if (!packet.is_licensed_str.empty())
{
if (!first)
json << ",\n";
json << " \"firmware_version\": \""
<< escapeJsonString(packet.firmware_version) << "\"";
json << " \"is_licensed\": \""
<< escapeJsonString(packet.is_licensed_str) << "\"";
first = false;
}
if (!packet.mqtt_id.empty())
if (!packet.role_str.empty())
{
if (!first)
json << ",\n";
json << " \"mqtt_id\": \""
<< escapeJsonString(packet.mqtt_id) << "\"";
json << " \"role\": \""
<< escapeJsonString(packet.role_str) << "\"";
first = false;
}
json << "\n },\n";
Expand Down
10 changes: 5 additions & 5 deletions meshtastic_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class MeshtasticDecoder
uint32_t seq_number;

// Node info data (for NODEINFO_APP)
std::string node_id;
std::string node_id_str;
std::string long_name;
std::string short_name;
std::string macaddr;
std::string hw_model;
std::string firmware_version;
std::string mqtt_id;
std::string macaddr_str;
std::string hw_model_str;
std::string is_licensed_str;
std::string role_str;

// Text message data (for TEXT_MESSAGE_APP)
std::string text_message;
Expand Down
4 changes: 2 additions & 2 deletions meshtastic_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ MeshtasticEncoder::EncodedPacket MeshtasticEncoder::encodeNodeInfo(
std::vector<uint8_t> user_protobuf;

// Field 1: id (string)
if (!nodeinfo.id.empty())
if (!nodeinfo.node_id_str.empty())
{
encodeString(user_protobuf, 1, nodeinfo.id);
encodeString(user_protobuf, 1, nodeinfo.node_id_str);
}

// Field 2: long_name (string)
Expand Down
4 changes: 2 additions & 2 deletions meshtastic_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class MeshtasticEncoder
uint32_t node_id; // Node ID
std::string long_name; // Long node name
std::string short_name; // Short node name
std::string id; // Node ID string (e.g., "!12345678")
std::string node_id_str; // Node ID string (e.g., "!12345678")
uint8_t hw_model; // Hardware model enum
uint8_t role; // Device role enum
bool is_licensed; // Is licensed operator
uint8_t public_key[32]; // Public key (32 bytes)
bool is_unmessagable; // Can receive messages?
uint8_t hop_limit; // Maximum hops (default: 3)
uint8_t hop_limit; // Maximum hops (default: 3)
};

/**
Expand Down
8 changes: 4 additions & 4 deletions test_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ bool testNodeInfo()
nodeinfo.node_id = 0x12345678;
nodeinfo.long_name = "Test Node";
nodeinfo.short_name = "TEST";
nodeinfo.id = "!12345678";
nodeinfo.hw_model = 24; // T_DECK
nodeinfo.node_id_str = "!12345678";
nodeinfo.hw_model = 50; // T_DECK
nodeinfo.role = 0; // CLIENT
nodeinfo.is_licensed = false;
memset(nodeinfo.public_key, 0xAA, 32); // Dummy key
Expand Down Expand Up @@ -117,12 +117,12 @@ bool testNodeInfo()

std::cout << "\nDecoder results:\n";
std::cout << " Port: " << (int)decoded.port << " (expected: 4)\n";
std::cout << " Node ID: \"" << decoded.node_id << "\" (expected: \"" << nodeinfo.id << "\")\n";
std::cout << " Node ID: \"" << decoded.node_id_str << "\" (expected: \"" << nodeinfo.node_id_str << "\")\n";
std::cout << " Long name: \"" << decoded.long_name << "\" (expected: \"" << nodeinfo.long_name << "\")\n";
std::cout << " Short name: \"" << decoded.short_name << "\" (expected: \"" << nodeinfo.short_name << "\")\n";

bool success = (decoded.port == 4) &&
(decoded.node_id == nodeinfo.id) &&
(decoded.node_id_str == nodeinfo.node_id_str) &&
(decoded.long_name == nodeinfo.long_name) &&
(decoded.short_name == nodeinfo.short_name);

Expand Down