Manage directory structure
This commit is contained in:
parent
2f22c89331
commit
ce843015d6
10 changed files with 57 additions and 130 deletions
|
@ -44,5 +44,5 @@ void Communicator::sendMessage(char *message)
|
|||
|
||||
char *Communicator::receiveMessage()
|
||||
{
|
||||
return "";
|
||||
return nullptr;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
#include <I2CCommunicator.h>
|
||||
#include <Wire.h>
|
||||
|
||||
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();
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#include <Communicator.h>
|
||||
|
||||
class I2CCommunicator : public Communicator
|
||||
{
|
||||
private:
|
||||
public:
|
||||
I2CCommunicator(int slaveAddr, __SIZE_TYPE__ bufferSize);
|
||||
void sendMessage(int *values, int numberOfValues);
|
||||
void sendMessage(char *message);
|
||||
char *receiveMessage();
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
#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();
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#include <Communicator.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
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();
|
||||
};
|
|
@ -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 <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
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
|
|
@ -0,0 +1,7 @@
|
|||
#include <SerialCommunicator.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
SerialCommunicator::SerialCommunicator(HardwareSerial &p_out, int baudRate, int timeout, __SIZE_TYPE__ bufferSize) : StreamCommunicator(p_out, bufferSize)
|
||||
{
|
||||
p_out.begin(baudRate);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#include <StreamCommunicator.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
class SerialCommunicator : public StreamCommunicator
|
||||
{
|
||||
public:
|
||||
SerialCommunicator(HardwareSerial &p_out, int baudRate, int timeout, __SIZE_TYPE__ bufferSize);
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
#include <StreamCommunicator.h>
|
||||
|
||||
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();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#include <Communicator.h>
|
||||
#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();
|
||||
};
|
Reference in a new issue