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())
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -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
|
Reference in a new issue