diff --git a/Devices/Control/Firmware/lib/Communicator/Communicator.cpp b/Devices/Control/Firmware/lib/Communicator/Communicator.cpp index ffa6c8f..69ab6b6 100644 --- a/Devices/Control/Firmware/lib/Communicator/Communicator.cpp +++ b/Devices/Control/Firmware/lib/Communicator/Communicator.cpp @@ -44,5 +44,5 @@ void Communicator::sendMessage(char *message) char *Communicator::receiveMessage() { - return ""; + return nullptr; } \ No newline at end of file diff --git a/Devices/Control/Firmware/lib/Communicator/I2CCommunicator.cpp b/Devices/Control/Firmware/lib/Communicator/I2CCommunicator.cpp deleted file mode 100644 index 48837fd..0000000 --- a/Devices/Control/Firmware/lib/Communicator/I2CCommunicator.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -I2CCommunicator::I2CCommunicator(int slaveAddr, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize) -{ - Wire.begin(slaveAddr); -} - -void I2CCommunicator::sendMessage(int *values, int numberOfValues) -{ - char message[calculateMessageOutSize(numberOfValues)]; - parseIDs(values, numberOfValues, message); - Serial.println(message); -} - -void I2CCommunicator::sendMessage(char *message) -{ - Wire.println(message); -} - -char *I2CCommunicator::receiveMessage() -{ - if (Wire.available()) - { - memset(getBuffer(), '\0', getBufferSize()); - Wire.readBytesUntil('\n', getBuffer(), getBufferSize()); - } - return getBuffer(); -} \ No newline at end of file diff --git a/Devices/Control/Firmware/lib/Communicator/I2CCommunicator.h b/Devices/Control/Firmware/lib/Communicator/I2CCommunicator.h deleted file mode 100644 index ac1ce45..0000000 --- a/Devices/Control/Firmware/lib/Communicator/I2CCommunicator.h +++ /dev/null @@ -1,11 +0,0 @@ -#include - -class I2CCommunicator : public Communicator -{ -private: -public: - I2CCommunicator(int slaveAddr, __SIZE_TYPE__ bufferSize); - void sendMessage(int *values, int numberOfValues); - void sendMessage(char *message); - char *receiveMessage(); -}; \ No newline at end of file diff --git a/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.cpp b/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.cpp deleted file mode 100644 index 16ff238..0000000 --- a/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -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(); -} \ No newline at end of file diff --git a/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.h b/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.h deleted file mode 100644 index 656cc07..0000000 --- a/Devices/Control/Firmware/lib/Communicator/SerialCommunicator.h +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -class SerialCommunicator : public Communicator -{ -protected: - HardwareSerial &port; - -public: - SerialCommunicator(HardwareSerial &port, int baudRate, int timeout, __SIZE_TYPE__ bufferSize); - void sendMessage(int *values, int numberOfValues); - void sendMessage(char *message); - char *receiveMessage(); -}; diff --git a/Devices/Control/Firmware/lib/README b/Devices/Control/Firmware/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/Devices/Control/Firmware/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/Devices/Control/Firmware/lib/SerialCommunicator/SerialCommunicator.cpp b/Devices/Control/Firmware/lib/SerialCommunicator/SerialCommunicator.cpp new file mode 100644 index 0000000..5bafb71 --- /dev/null +++ b/Devices/Control/Firmware/lib/SerialCommunicator/SerialCommunicator.cpp @@ -0,0 +1,7 @@ +#include +#include + +SerialCommunicator::SerialCommunicator(HardwareSerial &p_out, int baudRate, int timeout, __SIZE_TYPE__ bufferSize) : StreamCommunicator(p_out, bufferSize) +{ + p_out.begin(baudRate); +} \ No newline at end of file diff --git a/Devices/Control/Firmware/lib/SerialCommunicator/SerialCommunicator.h b/Devices/Control/Firmware/lib/SerialCommunicator/SerialCommunicator.h new file mode 100644 index 0000000..9c2c050 --- /dev/null +++ b/Devices/Control/Firmware/lib/SerialCommunicator/SerialCommunicator.h @@ -0,0 +1,8 @@ +#include +#include + +class SerialCommunicator : public StreamCommunicator +{ +public: + SerialCommunicator(HardwareSerial &p_out, int baudRate, int timeout, __SIZE_TYPE__ bufferSize); +}; diff --git a/Devices/Control/Firmware/lib/StreamCommunicator/StreamCommunicator.cpp b/Devices/Control/Firmware/lib/StreamCommunicator/StreamCommunicator.cpp new file mode 100644 index 0000000..dbd2f03 --- /dev/null +++ b/Devices/Control/Firmware/lib/StreamCommunicator/StreamCommunicator.cpp @@ -0,0 +1,27 @@ +#include + +StreamCommunicator::StreamCommunicator(Stream &s_out, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize), stream(s_out) +{ +} + +void StreamCommunicator::sendMessage(int *values, int numberOfValues) +{ + char message[calculateMessageOutSize(numberOfValues)]; + parseIDs(values, numberOfValues, message); + stream.println(message); +} + +void StreamCommunicator::sendMessage(char *message) +{ + stream.println(message); +} + +char *StreamCommunicator::receiveMessage() +{ + if (stream.available()) + { + memset(getBuffer(), '\0', getBufferSize()); + stream.readBytesUntil('\n', getBuffer(), getBufferSize()); + } + return getBuffer(); +} \ No newline at end of file diff --git a/Devices/Control/Firmware/lib/StreamCommunicator/StreamCommunicator.h b/Devices/Control/Firmware/lib/StreamCommunicator/StreamCommunicator.h new file mode 100644 index 0000000..2f7a8da --- /dev/null +++ b/Devices/Control/Firmware/lib/StreamCommunicator/StreamCommunicator.h @@ -0,0 +1,14 @@ +#include +#include "Stream.h" + +class StreamCommunicator : public Communicator +{ +protected: + Stream &stream; + +public: + StreamCommunicator(Stream &s_out, __SIZE_TYPE__ bufferSize); + void sendMessage(int *values, int numberOfValues); + void sendMessage(char *message); + char *receiveMessage(); +}; \ No newline at end of file