From 16c0b06971534219106df572cfbe84b46b92695f Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Fri, 6 Sep 2024 18:27:36 -0500 Subject: [PATCH] Bitfield --- src/mesh/ProtobufModule.h | 4 ++-- src/mesh/Router.cpp | 4 ++-- src/modules/AtakPluginModule.cpp | 4 ++-- src/modules/PositionModule.cpp | 8 ++++---- src/modules/SerialModule.cpp | 4 ++-- src/modules/esp32/StoreForwardModule.cpp | 4 ++-- src/mqtt/MQTT.cpp | 5 +++-- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/mesh/ProtobufModule.h b/src/mesh/ProtobufModule.h index 56bf71e725..862526a32e 100644 --- a/src/mesh/ProtobufModule.h +++ b/src/mesh/ProtobufModule.h @@ -44,8 +44,8 @@ template class ProtobufModule : protected SinglePortModule { // Update our local node info with our position (even if we don't decide to update anyone else) meshtastic_MeshPacket *p = allocDataPacket(); - p->decoded.has_ok_to_mqtt = true; - p->decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + p->decoded.has_bitfield = true; + p->decoded.bitfield |= config.lora.config_ok_to_mqtt; p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), fields, &payload); // LOG_DEBUG("did encode\n"); diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index a7315fa727..8ca1eeede3 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -424,8 +424,8 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) // If the packet is not yet encrypted, do so now if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { - p->decoded.has_ok_to_mqtt = true; - p->decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + p->decoded.has_bitfield = true; + p->decoded.bitfield |= config.lora.config_ok_to_mqtt; size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_Data_msg, &p->decoded); diff --git a/src/modules/AtakPluginModule.cpp b/src/modules/AtakPluginModule.cpp index 2664d978db..dbf7b3f248 100644 --- a/src/modules/AtakPluginModule.cpp +++ b/src/modules/AtakPluginModule.cpp @@ -116,8 +116,8 @@ void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtast LOG_DEBUG("Compressed chat to_callsign: %d bytes\n", length); } } - mp.decoded.has_ok_to_mqtt = true; - mp.decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + mp.decoded.has_bitfield = true; + mp.decoded.bitfield |= config.lora.config_ok_to_mqtt; mp.decoded.payload.size = pb_encode_to_bytes(mp.decoded.payload.bytes, sizeof(mp.decoded.payload.bytes), meshtastic_TAKPacket_fields, &compressed); LOG_DEBUG("Final payload: %d bytes\n", mp.decoded.payload.size); diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index ca3959a120..8e329a69a9 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -118,8 +118,8 @@ void PositionModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic p->latitude_i += (1 << (31 - precision)); p->longitude_i += (1 << (31 - precision)); - mp.decoded.has_ok_to_mqtt = true; - mp.decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + mp.decoded.has_bitfield = true; + mp.decoded.bitfield |= config.lora.config_ok_to_mqtt; mp.decoded.payload.size = pb_encode_to_bytes(mp.decoded.payload.bytes, sizeof(mp.decoded.payload.bytes), &meshtastic_Position_msg, p); } @@ -272,8 +272,8 @@ meshtastic_MeshPacket *PositionModule::allocAtakPli() LOG_INFO("Sending TAK PLI packet\n"); meshtastic_MeshPacket *mp = allocDataPacket(); mp->decoded.portnum = meshtastic_PortNum_ATAK_PLUGIN; - mp->decoded.has_ok_to_mqtt = true; - mp->decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + mp->decoded.has_bitfield = true; + mp->decoded.bitfield |= config.lora.config_ok_to_mqtt; meshtastic_TAKPacket takPacket = {.is_compressed = true, .has_contact = true, diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 3a4e2fdd1d..4f263f417c 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -235,8 +235,8 @@ void SerialModule::sendTelemetry(meshtastic_Telemetry m) pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Telemetry_msg, &m); p->to = NODENUM_BROADCAST; p->decoded.want_response = false; - p->decoded.has_ok_to_mqtt = true; - p->decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + p->decoded.has_bitfield = true; + p->decoded.bitfield |= config.lora.config_ok_to_mqtt; p->priority = meshtastic_MeshPacket_Priority_RELIABLE; service->sendToMesh(p, RX_SRC_LOCAL, true); } diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index 6a10fbfcbb..b03bfa239a 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -260,8 +260,8 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t } else { sf.rr = meshtastic_StoreAndForward_RequestResponse_ROUTER_TEXT_DIRECT; } - p->decoded.has_ok_to_mqtt = true; - p->decoded.ok_to_mqtt = config.lora.config_ok_to_mqtt; + p->decoded.has_bitfield = true; + p->decoded.bitfield |= config.lora.config_ok_to_mqtt; p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_StoreAndForward_msg, &sf); } diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index ef07281a0e..a82d3dfad8 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -520,10 +520,11 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket & return; } - if (mp_decoded.decoded.has_ok_to_mqtt && !mp_decoded.decoded.ok_to_mqtt && + // check for the lowest bit of the data bitfield set false, and the use of one of the default keys. + if (mp_decoded.decoded.has_bitfield && !(mp_decoded.decoded.bitfield | 1) && (ch.settings.psk.size < 2 || (ch.settings.psk.size == 16 && memcmp(ch.settings.psk.bytes, defaultpsk, 16)) || (ch.settings.psk.size == 32 && memcmp(ch.settings.psk.bytes, eventpsk, 32)))) { - LOG_INFO("MQTT onSend - Not forwarding packet with ok_to_mqtt set false\n"); + LOG_INFO("MQTT onSend - Not forwarding packet due to DontMqttMeBro flag\n"); return; }