From 9a0939656bf956ff36865c0b947f7035132d36cc Mon Sep 17 00:00:00 2001 From: Moritz Wirger Date: Sun, 31 Jul 2022 17:21:31 +0200 Subject: [PATCH] Dump buffer in findAndReadReply --- src/NETSGPClient.cpp | 22 +++++++++------------- src/NETSGPClient.h | 7 +++++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/NETSGPClient.cpp b/src/NETSGPClient.cpp index 191c62a..6508b23 100644 --- a/src/NETSGPClient.cpp +++ b/src/NETSGPClient.cpp @@ -16,7 +16,6 @@ NETSGPClient::InverterStatus NETSGPClient::getStatus(const uint32_t deviceID) InverterStatus status; if (waitForMessage() && findAndReadReply(Command::STATUS)) { - dumpBuffer(); fillInverterStatusFromBuffer(&mBuffer[0], status); } else @@ -165,8 +164,6 @@ bool NETSGPClient::sendCommandAndValidate(const uint32_t deviceID, const Command sendCommand(deviceID, command, value); if (waitForMessage() && findAndReadReply(command)) { - dumpBuffer(); - const bool crc = mBuffer[14] == calcCRC(14); const bool valid = mBuffer[13] == value; @@ -224,12 +221,8 @@ bool NETSGPClient::findAndReadReply(const Command command) if (bytesToRead) { const size_t bytesRead = mStream.readBytes(&mBuffer[2], bytesToRead); - const bool success = bytesRead == bytesToRead; - if (!success) - { - DEBUGF("[findAndReadReply] Only read %d of %d bytes\n", bytesRead, bytesToRead); - } - return success; + dumpBuffer(2 + bytesRead); + return bytesRead == bytesToRead; } return false; @@ -283,13 +276,16 @@ bool NETSGPClient::fillInverterStatusFromBuffer(const uint8_t* buffer, InverterS return status.valid; } -void NETSGPClient::dumpBuffer() +void NETSGPClient::dumpBuffer(const size_t bytes) { #ifdef DEBUG_SERIAL - for (uint8_t i = 0; i < 32; ++i) + if (bytes <= BUFFER_SIZE) { - DEBUGF("%02X", mBuffer[i]); + for (uint8_t i = 0; i < bytes; ++i) + { + DEBUGF("%02X", mBuffer[i]); + } + DEBUGLN(); } - DEBUGLN(); #endif } \ No newline at end of file diff --git a/src/NETSGPClient.h b/src/NETSGPClient.h index 6a27ca5..2389ac3 100644 --- a/src/NETSGPClient.h +++ b/src/NETSGPClient.h @@ -345,11 +345,14 @@ class NETSGPClient bool fillInverterStatusFromBuffer(const uint8_t* buffer, InverterStatus& status); /// @brief Dump the buffer contents to debug serial - void dumpBuffer(); + /// + /// @param bytes Amount of bytes to dump + void dumpBuffer(const size_t bytes = BUFFER_SIZE); protected: + constexpr static const size_t BUFFER_SIZE = 32; constexpr static const uint8_t MAGIC_BYTE = 0x43; /// Magic byte indicating start of messages Stream& mStream; /// Stream for communication uint8_t mProgPin; /// Programming enable pin of RF module (active low) - uint8_t mBuffer[32] = {0}; /// Inernal buffer + uint8_t mBuffer[BUFFER_SIZE] = {0}; /// Inernal buffer };