Skip to content

Commit

Permalink
Dump buffer in findAndReadReply
Browse files Browse the repository at this point in the history
  • Loading branch information
enwi committed Aug 3, 2022
1 parent f068cbd commit 9a09396
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
22 changes: 9 additions & 13 deletions src/NETSGPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions src/NETSGPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 9a09396

Please sign in to comment.