Skip to content

Commit

Permalink
VE.Direct: do not use debug buffer at all if verbose logging disabled (
Browse files Browse the repository at this point in the history
…#437)

this avoids the debug buffer being overrun if verbose logging is
disabled in particular. that would happen because the buffer would
only be reset if verbose logging was enabled but filled in any case.
  • Loading branch information
schlimmchen authored Sep 13, 2023
1 parent 2eeb5f1 commit 88a5117
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/VeDirectFrameHandler/VeDirectFrameHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ VeDirectFrameHandler::VeDirectFrameHandler() :
void VeDirectFrameHandler::setVerboseLogging(bool verboseLogging)
{
_verboseLogging = verboseLogging;
if (!_verboseLogging) { _debugIn = 0; }
}

void VeDirectFrameHandler::init(int8_t rx, int8_t tx, Print* msgOut, bool verboseLogging)
Expand Down Expand Up @@ -120,16 +121,18 @@ void VeDirectFrameHandler::loop()
}

/*
* rxData
* rxData
* This function is called by loop() which passes a byte of serial data
* Based on Victron's example code. But using String and Map instead of pointer and arrays
*/
void VeDirectFrameHandler::rxData(uint8_t inbyte)
{
_debugBuffer[_debugIn] = inbyte;
_debugIn = (_debugIn + 1) % _debugBuffer.size();
if (0 == _debugIn) {
_msgOut->println("[VE.Direct] ERROR: debug buffer overrun!");
if (_verboseLogging) {
_debugBuffer[_debugIn] = inbyte;
_debugIn = (_debugIn + 1) % _debugBuffer.size();
if (0 == _debugIn) {
_msgOut->println("[VE.Direct] ERROR: debug buffer overrun!");
}
}

if ( (inbyte == ':') && (_state != CHECKSUM) ) {
Expand Down

0 comments on commit 88a5117

Please sign in to comment.