Add clearBuffer() function
This commit is contained in:
parent
55a7d2cd0c
commit
10d4d42c7e
2 changed files with 12 additions and 2 deletions
|
@ -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;
|
||||||
|
|
|
@ -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
|
Reference in a new issue