Skip to content

Commit

Permalink
fix DUP flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis committed May 20, 2022
1 parent 2263c77 commit d5fdd11
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"type": "git",
"url": "https://github.com/bertmelis/espMqttClient.git"
},
"version": "0.0.2",
"version": "0.0.3",
"frameworks": "arduino",
"platforms": ["espressif8266", "espressif32"]
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=espMqttClient
version=0.0.2
version=0.0.3
author=Bert Melis
maintainer=Bert Melis
sentence=an MQTT client for the Arduino framework for ESP8266 / ESP32
Expand Down
1 change: 1 addition & 0 deletions src/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ void MqttClient::_checkOutgoing() {
} else {
// handle with care! millis() returns unsigned 32 bit, token is void*
packet->token = reinterpret_cast<void*>(millis());
if ((packet->data(0)[0] & 0xF0) == PacketType.PUBLISH) packet->setDup();
_outbox.next();
}
packet = _outbox.getCurrent();
Expand Down
24 changes: 3 additions & 21 deletions src/Packets/Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,10 @@ size_t Packet::size() const {
return _size;
}

/*
Removeable is treated as "_packetId != 0" hence can be filtered out by
calling `packetId()`.
Packets without packet ID will return 0.
bool Packet::removeable() const {
if (!_data) return true;
uint8_t packetType = _data[0] & 0xF0;
uint8_t headerFlags = _data[0] & 0x0F;
// part of session data for clients are
// - QoS 1 and 2 messages sent to server but not yet completely acked
// - QoS 2 messages received from server but not yet completely acked
if ((packetType == PacketType.PUBREC) ||
(packetType == PacketType.PUBREL) ||
(packetType == PacketType.PUBCOMP) ||
(packetType == PacketType.PUBLISH && headerFlags & 0x06)) { // mask QoS bits
return false;
} else {
return true;
}
void Packet::setDup() {
if (!data) return;
_data[0] |= 0x08;
}
*/

uint16_t Packet::packetId() const {
return _packetId;
Expand Down
2 changes: 1 addition & 1 deletion src/Packets/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Packet {

const uint8_t* data(size_t index) const;
size_t size() const;
// bool removeable() const // functionality offered by packetId()
void setDup();
uint16_t packetId() const;

void* token; // native typeless variable to store any additional data
Expand Down

0 comments on commit d5fdd11

Please sign in to comment.