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

29 lines
No EOL
764 B
C++

#include <SerialCommunicator.h>
#include <HardwareSerial.h>
SerialCommunicator::SerialCommunicator(HardwareSerial &p_out, int baudRate, int timeout, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize), port(p_out)
{
port.begin(baudRate);
}
void SerialCommunicator::sendMessage(int *values, int numberOfValues)
{
char message[calculateMessageOutSize(numberOfValues)];
parseIDs(values, numberOfValues, message);
port.println(message);
}
void SerialCommunicator::sendMessage(char *message)
{
port.println(message);
}
char *SerialCommunicator::receiveMessage()
{
if (port.available())
{
memset(getBuffer(), '\0', getBufferSize());
port.readBytesUntil('\n', getBuffer(), getBufferSize());
}
return getBuffer();
}