Hoymiles Lib: Return command string directly instead of printing it to a stream

This commit is contained in:
Thomas Basler
2025-04-10 22:48:01 +02:00
parent 613f8ab5a6
commit 86e5aa1576
4 changed files with 10 additions and 11 deletions

View File

@@ -165,7 +165,7 @@ void HoymilesRadio_CMT::loop()
if (nullptr != inv) {
// Save packet in inverter rx buffer
Hoymiles.getMessageOutput()->printf("RX %.2f MHz --> %s | %" PRId8 " dBm\r\n",
getFrequencyFromChannel(f.channel) / 1000000.0, Utils::dumpArray(f.fragment, f.len).c_str(), f.rssi);
getFrequencyFromChannel(f.channel) / 1000000.0, Utils::dumpArray(f.fragment, f.len).c_str(), f.rssi);
inv->addRxFragment(f.fragment, f.len, f.rssi);
} else {
@@ -272,9 +272,8 @@ void HoymilesRadio_CMT::sendEsbPacket(CommandAbstract& cmd)
cmtSwitchDtuFreq(getInvBootFrequency());
}
Hoymiles.getMessageOutput()->printf("TX %s %.2f MHz --> ",
cmd.getCommandName().c_str(), getFrequencyFromChannel(_radio->getChannel()) / 1000000.0);
cmd.dumpDataPayload(Hoymiles.getMessageOutput());
Hoymiles.getMessageOutput()->printf("TX %s %.2f MHz --> %s\r\n",
cmd.getCommandName().c_str(), getFrequencyFromChannel(_radio->getChannel()) / 1000000.0, cmd.dumpDataPayload().c_str());
if (!_radio->write(cmd.getDataPayload(), cmd.getDataSize())) {
Hoymiles.getMessageOutput()->printf("TX SPI Timeout\r\n");

View File

@@ -182,9 +182,8 @@ void HoymilesRadio_NRF::sendEsbPacket(CommandAbstract& cmd)
openWritingPipe(s);
_radio->setRetries(3, 15);
Hoymiles.getMessageOutput()->printf("TX %s Channel: %" PRIu8 " --> ",
cmd.getCommandName().c_str(), _radio->getChannel());
cmd.dumpDataPayload(Hoymiles.getMessageOutput());
Hoymiles.getMessageOutput()->printf("TX %s Channel: %" PRIu8 " --> %s\r\n",
cmd.getCommandName().c_str(), _radio->getChannel(), cmd.dumpDataPayload().c_str());
_radio->write(cmd.getDataPayload(), cmd.getDataSize());
_radio->setRetries(0, 0);

View File

@@ -51,10 +51,10 @@ const uint8_t* CommandAbstract::getDataPayload()
return _payload;
}
void CommandAbstract::dumpDataPayload(Print* stream)
String CommandAbstract::dumpDataPayload()
{
const uint8_t* payload = getDataPayload();
stream->printf("%s\r\n", Utils::dumpArray(payload, getDataSize()).c_str());
return Utils::dumpArray(payload, getDataSize());
}
uint8_t CommandAbstract::getDataSize() const

View File

@@ -3,6 +3,7 @@
#include "types.h"
#include <Stream.h>
#include <WString.h>
#include <cstdint>
#define RF_LEN 32
@@ -26,10 +27,10 @@ enum class QueueInsertType {
class CommandAbstract {
public:
explicit CommandAbstract(InverterAbstract* inv, const uint64_t router_address = 0);
virtual ~CommandAbstract() {};
virtual ~CommandAbstract() { };
const uint8_t* getDataPayload();
void dumpDataPayload(Print* stream);
String dumpDataPayload();
uint8_t getDataSize() const;