30 lines
No EOL
770 B
C++
30 lines
No EOL
770 B
C++
#include <SerialCommunicator.h>
|
|
#include <HardwareSerial.h>
|
|
|
|
SerialCommunicator::SerialCommunicator(int baudRate, int timeout, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize)
|
|
{
|
|
Serial.begin(baudRate);
|
|
Serial.setTimeout(timeout);
|
|
}
|
|
|
|
void SerialCommunicator::sendMessage(int *values, int numberOfValues)
|
|
{
|
|
char message[calculateMessageOutSize(numberOfValues)];
|
|
parseIDs(values, numberOfValues, message);
|
|
Serial.println(message);
|
|
}
|
|
|
|
void SerialCommunicator::sendMessage(char *message)
|
|
{
|
|
Serial.println(message);
|
|
}
|
|
|
|
char *SerialCommunicator::receiveMessage()
|
|
{
|
|
if (Serial.available())
|
|
{
|
|
memset(getBuffer(), '\0', getBufferSize());
|
|
Serial.readBytesUntil('\n', getBuffer(), getBufferSize());
|
|
}
|
|
return getBuffer();
|
|
} |