From 41e2ba7fcf1d41f95cb60a9bb7ae8e1891e42e4d Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Mon, 6 Mar 2023 23:42:05 +0100 Subject: [PATCH] Move serveral methods from the HoymilesRadio_NRF class to the HoymilesRadio base class --- lib/Hoymiles/src/HoymilesRadio.cpp | 24 ++++++++++++++++++++++++ lib/Hoymiles/src/HoymilesRadio.h | 5 +++++ lib/Hoymiles/src/HoymilesRadio_NRF.cpp | 25 +------------------------ lib/Hoymiles/src/HoymilesRadio_NRF.h | 3 --- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/Hoymiles/src/HoymilesRadio.cpp b/lib/Hoymiles/src/HoymilesRadio.cpp index 08ef1c3..c68def6 100644 --- a/lib/Hoymiles/src/HoymilesRadio.cpp +++ b/lib/Hoymiles/src/HoymilesRadio.cpp @@ -4,6 +4,7 @@ */ #include "HoymilesRadio.h" #include "Hoymiles.h" +#include "crc.h" serial_u HoymilesRadio::DtuSerial() { @@ -27,6 +28,29 @@ serial_u HoymilesRadio::convertSerialToRadioId(serial_u serial) return radioId; } +bool HoymilesRadio::checkFragmentCrc(fragment_t* fragment) +{ + uint8_t crc = crc8(fragment->fragment, fragment->len - 1); + return (crc == fragment->fragment[fragment->len - 1]); +} + +void HoymilesRadio::sendRetransmitPacket(uint8_t fragment_id) +{ + CommandAbstract* cmd = _commandQueue.front().get(); + + CommandAbstract* requestCmd = cmd->getRequestFrameCommand(fragment_id); + + if (requestCmd != nullptr) { + sendEsbPacket(requestCmd); + } +} + +void HoymilesRadio::sendLastPacketAgain() +{ + CommandAbstract* cmd = _commandQueue.front().get(); + sendEsbPacket(cmd); +} + void HoymilesRadio::dumpBuf(const char* info, uint8_t buf[], uint8_t len) { diff --git a/lib/Hoymiles/src/HoymilesRadio.h b/lib/Hoymiles/src/HoymilesRadio.h index 557bfaf..93bc457 100644 --- a/lib/Hoymiles/src/HoymilesRadio.h +++ b/lib/Hoymiles/src/HoymilesRadio.h @@ -22,6 +22,11 @@ protected: static serial_u convertSerialToRadioId(serial_u serial); void dumpBuf(const char* info, uint8_t buf[], uint8_t len); + bool checkFragmentCrc(fragment_t* fragment); + virtual void sendEsbPacket(CommandAbstract* cmd) = 0; + void sendRetransmitPacket(uint8_t fragment_id); + void sendLastPacketAgain(); + serial_u _dtuSerial; std::queue> _commandQueue; }; \ No newline at end of file diff --git a/lib/Hoymiles/src/HoymilesRadio_NRF.cpp b/lib/Hoymiles/src/HoymilesRadio_NRF.cpp index 120bde5..ded07f6 100644 --- a/lib/Hoymiles/src/HoymilesRadio_NRF.cpp +++ b/lib/Hoymiles/src/HoymilesRadio_NRF.cpp @@ -5,7 +5,6 @@ #include "HoymilesRadio_NRF.h" #include "Hoymiles.h" #include "commands/RequestFrameCommand.h" -#include "crc.h" #include #include @@ -215,11 +214,7 @@ void HoymilesRadio_NRF::switchRxCh() _radio->startListening(); } -bool HoymilesRadio_NRF::checkFragmentCrc(fragment_t* fragment) -{ - uint8_t crc = crc8(fragment->fragment, fragment->len - 1); - return (crc == fragment->fragment[fragment->len - 1]); -} + void HoymilesRadio_NRF::sendEsbPacket(CommandAbstract* cmd) { @@ -250,21 +245,3 @@ void HoymilesRadio_NRF::sendEsbPacket(CommandAbstract* cmd) _busyFlag = true; _rxTimeout.set(cmd->getTimeout()); } - -void HoymilesRadio_NRF::sendRetransmitPacket(uint8_t fragment_id) -{ - CommandAbstract* cmd = _commandQueue.front().get(); - - CommandAbstract* requestCmd = cmd->getRequestFrameCommand(fragment_id); - - if (requestCmd != nullptr) { - sendEsbPacket(requestCmd); - } -} - -void HoymilesRadio_NRF::sendLastPacketAgain() -{ - CommandAbstract* cmd = _commandQueue.front().get(); - sendEsbPacket(cmd); -} - diff --git a/lib/Hoymiles/src/HoymilesRadio_NRF.h b/lib/Hoymiles/src/HoymilesRadio_NRF.h index 5ed2e36..63e85f5 100644 --- a/lib/Hoymiles/src/HoymilesRadio_NRF.h +++ b/lib/Hoymiles/src/HoymilesRadio_NRF.h @@ -31,11 +31,8 @@ private: void switchRxCh(); void openReadingPipe(); void openWritingPipe(serial_u serial); - bool checkFragmentCrc(fragment_t* fragment); void sendEsbPacket(CommandAbstract* cmd); - void sendRetransmitPacket(uint8_t fragment_id); - void sendLastPacketAgain(); std::unique_ptr _spiPtr; std::unique_ptr _radio;