Add clearBuffer() function

This commit is contained in:
GHOSCHT 2022-02-05 20:50:54 +01:00
parent 55a7d2cd0c
commit 10d4d42c7e
No known key found for this signature in database
GPG key ID: A35BD466B8871994
2 changed files with 12 additions and 2 deletions

View file

@ -22,7 +22,7 @@ char *StreamCommunicator::receiveMessage()
{ {
if (stream.available()) if (stream.available())
{ {
memset(getBuffer(), '\0', getBufferSize()); clearBuffer();
stream.readBytesUntil('\n', getBuffer(), getBufferSize()); stream.readBytesUntil('\n', getBuffer(), getBufferSize());
} }
return getBuffer(); return getBuffer();
@ -52,6 +52,11 @@ char *StreamCommunicator::getBuffer()
return messageBuffer; return messageBuffer;
} }
void StreamCommunicator::clearBuffer()
{
memset(getBuffer(), '\0', getBufferSize());
}
int StreamCommunicator::getBufferSize() int StreamCommunicator::getBufferSize()
{ {
return this->bufferSize; return this->bufferSize;

View file

@ -1,5 +1,8 @@
#include "Stream.h" #include "Stream.h"
#ifndef _STREAM_COMMUNICATOR_INCLUDED_
#define _STREAM_COMMUNICATOR_INCLUDED_
class StreamCommunicator class StreamCommunicator
{ {
protected: protected:
@ -15,6 +18,8 @@ public:
void sendMessage(const char message[]); void sendMessage(const char message[]);
char *receiveMessage(); char *receiveMessage();
char *getBuffer(); char *getBuffer();
void clearBuffer();
int getBufferSize(); int getBufferSize();
Stream *getStream(); Stream *getStream();
}; };
#endif