Skip to content

Commit

Permalink
Bitfield
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-bennett committed Sep 6, 2024
1 parent 9f849a6 commit 16c0b06
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/mesh/ProtobufModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ template <class T> 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");
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/modules/AtakPluginModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/modules/PositionModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/SerialModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/esp32/StoreForwardModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 16c0b06

Please sign in to comment.