Skip to content

Commit

Permalink
Add bridge packet queue limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammy1Am committed Mar 21, 2024
1 parent 03b2f8c commit a20950d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/mitsubishi_uart/muart_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ void ThermostatBridge::loop() {
}
}

/* Queues a packet to be sent by the bridge. If the queue is full, the packet will not be
enqueued.*/
void MUARTBridge::sendPacket(const Packet &packetToSend) {
pkt_queue.push(packetToSend);
if (pkt_queue.size() <= MAX_QUEUE_SIZE) {
pkt_queue.push(packetToSend) ;
} else {
ESP_LOGW(BRIDGE_TAG, "Packet queue full! %x packet not sent.", packetToSend.getPacketType());
}
}

void MUARTBridge::writeRawPacket(const RawPacket &packetToSend) const {
Expand Down
4 changes: 4 additions & 0 deletions components/mitsubishi_uart/muart_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace mitsubishi_uart {

static const char *BRIDGE_TAG = "muart_bridge";
static const uint32_t RESPONSE_TIMEOUT_MS = 3000; // Maximum amount of time to wait for an expected response packet
/* Maximum number of packets allowed to be queued for sending. In some circumstances the equipment response
time can be very slow and packets would queue up faster than they were being received. TODO: Not sure what size this should
be, 4ish should be enough for almost all situations, so 8 seems plenty.*/
static const size_t MAX_QUEUE_SIZE = 8;

// A UARTComponent wrapper to send and receieve packets
class MUARTBridge {
Expand Down

0 comments on commit a20950d

Please sign in to comment.