Implement Communication object file structure
This commit is contained in:
parent
98bd6db4b3
commit
591a8c27cd
6 changed files with 79 additions and 0 deletions
11
Devices/Control/Firmware/lib/Communicator/Communicator.cpp
Normal file
11
Devices/Control/Firmware/lib/Communicator/Communicator.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <Communicator.h>
|
||||
|
||||
Communicator::Communicator(__SIZE_TYPE__ bufferSize)
|
||||
{
|
||||
this->messageBuffer = new char[bufferSize];
|
||||
}
|
||||
|
||||
char *Communicator::getBuffer()
|
||||
{
|
||||
return messageBuffer;
|
||||
}
|
12
Devices/Control/Firmware/lib/Communicator/Communicator.h
Normal file
12
Devices/Control/Firmware/lib/Communicator/Communicator.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
class Communicator
|
||||
{
|
||||
private:
|
||||
char *messageBuffer;
|
||||
|
||||
public:
|
||||
Communicator(__SIZE_TYPE__ bufferSize);
|
||||
virtual void sendMessage(int *values);
|
||||
virtual void sendMessage(char *message);
|
||||
virtual char *receiveMessage();
|
||||
char *getBuffer();
|
||||
};
|
|
@ -0,0 +1,17 @@
|
|||
#include <I2CCommunicator.h>
|
||||
#include <Wire.h>
|
||||
|
||||
I2CCommunicator::I2CCommunicator(int slaveAddr, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize)
|
||||
{
|
||||
Wire.begin(slaveAddr);
|
||||
//Wire.onReceive(receiveEvent);
|
||||
}
|
||||
|
||||
void I2CCommunicator::sendMessage(int *values)
|
||||
{
|
||||
}
|
||||
|
||||
void I2CCommunicator::sendMessage(char *message)
|
||||
{
|
||||
Wire.println(message);
|
||||
}
|
11
Devices/Control/Firmware/lib/Communicator/I2CCommunicator.h
Normal file
11
Devices/Control/Firmware/lib/Communicator/I2CCommunicator.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <Communicator.h>
|
||||
|
||||
class I2CCommunicator : public Communicator
|
||||
{
|
||||
private:
|
||||
public:
|
||||
I2CCommunicator(int slaveAddr, __SIZE_TYPE__ bufferSize);
|
||||
void sendMessage(int *values);
|
||||
void sendMessage(char *message);
|
||||
char *receiveMessage();
|
||||
};
|
|
@ -0,0 +1,17 @@
|
|||
#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)
|
||||
{
|
||||
}
|
||||
|
||||
void SerialCommunicator::sendMessage(char *message)
|
||||
{
|
||||
Serial.println(message);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include <Communicator.h>
|
||||
|
||||
class SerialCommunicator : public Communicator
|
||||
{
|
||||
private:
|
||||
public:
|
||||
SerialCommunicator(int baudRate, int timeout, __SIZE_TYPE__ bufferSize);
|
||||
void sendMessage(int *values);
|
||||
void sendMessage(char *message);
|
||||
char *receiveMessage();
|
||||
};
|
Reference in a new issue