This repository has been archived on 2023-12-22. You can view files and clone it, but cannot push or open issues or pull requests.
old-monorepo/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.cpp
2022-02-04 09:42:15 +01:00

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();
}