OpenDTU-old/lib/Hoymiles/src/HoymilesRadio.h
Thomas Basler 0441bbbe72 Fix: Queue consumed whole memory on inverter timeout
When the poll interval was e.g. 1sec it was possible that the queue ran full and consumed the whole memory.
Now new entries are only added to the queue automatically if the queue is empty.  This issue also caused a lot of "DTU command failed" messages.
2023-04-25 19:24:56 +02:00

38 lines
996 B
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "commands/CommandAbstract.h"
#include "types.h"
#include <memory>
#include <queue>
class HoymilesRadio {
public:
serial_u DtuSerial();
virtual void setDtuSerial(uint64_t serial);
bool isIdle();
bool isQueueEmpty();
bool isInitialized();
template <typename T>
T* enqueCommand()
{
_commandQueue.push(std::make_shared<T>());
return static_cast<T*>(_commandQueue.back().get());
}
protected:
static serial_u convertSerialToRadioId(serial_u serial);
void dumpBuf(const uint8_t buf[], uint8_t len, bool appendNewline = true);
bool checkFragmentCrc(fragment_t* fragment);
virtual void sendEsbPacket(CommandAbstract* cmd) = 0;
void sendRetransmitPacket(uint8_t fragment_id);
void sendLastPacketAgain();
serial_u _dtuSerial;
std::queue<std::shared_ptr<CommandAbstract>> _commandQueue;
bool _isInitialized = false;
bool _busyFlag = false;
};