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())
{
memset(getBuffer(), '\0', getBufferSize());
clearBuffer();
stream.readBytesUntil('\n', getBuffer(), getBufferSize());
}
return getBuffer();
@ -52,6 +52,11 @@ char *StreamCommunicator::getBuffer()
return messageBuffer;
}
void StreamCommunicator::clearBuffer()
{
memset(getBuffer(), '\0', getBufferSize());
}
int StreamCommunicator::getBufferSize()
{
return this->bufferSize;

View file

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