29 lines
No EOL
764 B
C++
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();
|
|
} |