Refactor Data bitfield into an enum

pull/6429/head
Jason B. Cox 2025-03-27 22:29:43 -07:00 zatwierdzone przez Thomas Göttgens
rodzic bd2d2981c9
commit e94d4200e6
4 zmienionych plików z 12 dodań i 10 usunięć

Wyświetl plik

@ -417,8 +417,9 @@ DecodeState perhapsDecode(meshtastic_MeshPacket *p)
if (decrypted) {
// parsing was successful
p->channel = chIndex; // change to store the index instead of the hash
if (p->decoded.has_bitfield)
p->decoded.want_response |= p->decoded.bitfield & BITFIELD_WANT_RESPONSE_MASK;
if (p->decoded.has_bitfield) {
p->decoded.want_response |= p->decoded.bitfield & DataBitfield::WANT_RESPONSE;
}
/* Not actually ever used.
// Decompress if needed. jm
@ -467,8 +468,8 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p)
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
if (isFromUs(p)) {
p->decoded.has_bitfield = true;
p->decoded.bitfield |= (config.lora.config_ok_to_mqtt << BITFIELD_OK_TO_MQTT_SHIFT);
p->decoded.bitfield |= (p->decoded.want_response << BITFIELD_WANT_RESPONSE_SHIFT);
p->decoded.bitfield |= (config.lora.config_ok_to_mqtt * DataBitfield::OK_TO_MQTT);
p->decoded.bitfield |= (p->decoded.want_response * DataBitfield::WANT_RESPONSE);
}
size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_Data_msg, &p->decoded);

Wyświetl plik

@ -159,7 +159,8 @@ extern Router *router;
// FIXME, move this someplace better
PacketId generatePacketId();
#define BITFIELD_WANT_RESPONSE_SHIFT 1
#define BITFIELD_OK_TO_MQTT_SHIFT 0
#define BITFIELD_WANT_RESPONSE_MASK (1 << BITFIELD_WANT_RESPONSE_SHIFT)
#define BITFIELD_OK_TO_MQTT_MASK (1 << BITFIELD_OK_TO_MQTT_SHIFT)
enum DataBitfield : uint32_t {
EMPTY = 0,
OK_TO_MQTT = (1 << 0),
WANT_RESPONSE = (1 << 1),
};

Wyświetl plik

@ -689,7 +689,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp_encrypted, const meshtastic_Me
// mp_decoded will not be decoded when it's PKI encrypted and not directed to us
if (mp_decoded.which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
// For uplinking other's packets, check if it's not OK to MQTT or if it's an older packet without the bitfield
bool dontUplink = !mp_decoded.decoded.has_bitfield || !(mp_decoded.decoded.bitfield & BITFIELD_OK_TO_MQTT_MASK);
bool dontUplink = !mp_decoded.decoded.has_bitfield || !(mp_decoded.decoded.bitfield & DataBitfield::OK_TO_MQTT);
// check for the lowest bit of the data bitfield set false, and the use of one of the default keys.
if (!isFromUs(&mp_decoded) && !isMqttServerAddressPrivate && dontUplink &&
(ch.settings.psk.size < 2 || (ch.settings.psk.size == 16 && memcmp(ch.settings.psk.bytes, defaultpsk, 16)) ||

Wyświetl plik

@ -293,7 +293,7 @@ const meshtastic_MeshPacket decoded = {
.from = 1,
.to = 2,
.which_payload_variant = meshtastic_MeshPacket_decoded_tag,
.decoded = {.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP, .has_bitfield = true, .bitfield = BITFIELD_OK_TO_MQTT_MASK},
.decoded = {.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP, .has_bitfield = true, .bitfield = DataBitfield::OK_TO_MQTT},
.id = 4,
};
const meshtastic_MeshPacket encrypted = {