From adf95d7d44c9d2ecc3dc18a019dd1ca77e488006 Mon Sep 17 00:00:00 2001 From: waltje Date: Thu, 29 Jan 2026 20:24:17 -0500 Subject: [PATCH] Update several incorrect NodeInfo field values. Added more NodeInfo field values. Renamed structure fields for clarity. --- meshtastic_decoder.cpp | 138 +++++++++++++++++++++++------------------ meshtastic_decoder.h | 10 +-- meshtastic_encoder.cpp | 4 +- meshtastic_encoder.h | 4 +- test_encoder.cpp | 8 +-- 5 files changed, 91 insertions(+), 73 deletions(-) diff --git a/meshtastic_decoder.cpp b/meshtastic_decoder.cpp index 822471f..eca70e8 100644 --- a/meshtastic_decoder.cpp +++ b/meshtastic_decoder.cpp @@ -53,13 +53,13 @@ MeshtasticDecoder::decodePacket(const std::vector& 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 = ""; @@ -650,12 +650,12 @@ MeshtasticDecoder::decodePacket(const std::vector& 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; @@ -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; } } @@ -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 { @@ -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; } @@ -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; } @@ -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; @@ -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; } @@ -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()) @@ -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"; diff --git a/meshtastic_decoder.h b/meshtastic_decoder.h index 70e174e..5e0aabd 100644 --- a/meshtastic_decoder.h +++ b/meshtastic_decoder.h @@ -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; diff --git a/meshtastic_encoder.cpp b/meshtastic_encoder.cpp index 4c70d76..542e951 100644 --- a/meshtastic_encoder.cpp +++ b/meshtastic_encoder.cpp @@ -391,9 +391,9 @@ MeshtasticEncoder::EncodedPacket MeshtasticEncoder::encodeNodeInfo( std::vector 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) diff --git a/meshtastic_encoder.h b/meshtastic_encoder.h index 90bf644..36c6254 100644 --- a/meshtastic_encoder.h +++ b/meshtastic_encoder.h @@ -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) }; /** diff --git a/test_encoder.cpp b/test_encoder.cpp index 6f9c230..c9a4093 100644 --- a/test_encoder.cpp +++ b/test_encoder.cpp @@ -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 @@ -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);