From d42846484d699155772c278fb95601575d314b04 Mon Sep 17 00:00:00 2001 From: TekuConcept Date: Wed, 15 Mar 2017 18:39:08 -0600 Subject: [PATCH] Bone To Arduino Test --- .../PIO_BoneToArduino/lib/readme.txt | 36 ++++++++++++++ .../PIO_BoneToArduino/platformio.ini | 19 ++++++++ .../PIO_BoneToArduino/src/Arduino.ino | 29 +++++++++++ Tests/SerialTest/Test_BoneToArduino.cpp | 48 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 Tests/SerialTest/PIO_BoneToArduino/lib/readme.txt create mode 100644 Tests/SerialTest/PIO_BoneToArduino/platformio.ini create mode 100644 Tests/SerialTest/PIO_BoneToArduino/src/Arduino.ino create mode 100644 Tests/SerialTest/Test_BoneToArduino.cpp diff --git a/Tests/SerialTest/PIO_BoneToArduino/lib/readme.txt b/Tests/SerialTest/PIO_BoneToArduino/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/Tests/SerialTest/PIO_BoneToArduino/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/Tests/SerialTest/PIO_BoneToArduino/platformio.ini b/Tests/SerialTest/PIO_BoneToArduino/platformio.ini new file mode 100644 index 0000000..b4fb831 --- /dev/null +++ b/Tests/SerialTest/PIO_BoneToArduino/platformio.ini @@ -0,0 +1,19 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:uno] +platform = atmelavr +framework = arduino +board = uno + +[env:due] +platform = atmelsam +framework = arduino +board = due \ No newline at end of file diff --git a/Tests/SerialTest/PIO_BoneToArduino/src/Arduino.ino b/Tests/SerialTest/PIO_BoneToArduino/src/Arduino.ino new file mode 100644 index 0000000..179ff4a --- /dev/null +++ b/Tests/SerialTest/PIO_BoneToArduino/src/Arduino.ino @@ -0,0 +1,29 @@ +#include +#include "SerialTools.h" + +#define m_assert(T,V) if(T != V) { result = (result<<1)|1; } else { result <<= 1; } +#define B115200 115200 +#define GARBAGE 0 + +void setup() { + Serial.begin(B115200); + SerialTools::writeString("Ready!", 6); + while((!Serial.available())||(Serial.read()==GARBAGE)); + + uint16_t result = 0; + int test = 0; + + SerialTools::readData((char*)&test, sizeof(int)); + m_assert(test, 0x0A0B0C0D) + m_assert(SerialTools::readByte(), 0xFF) + m_assert(SerialTools::readFloat(), 0.1F) + m_assert(SerialTools::readDouble(), 0.2) + m_assert(SerialTools::readInt(), -3) + m_assert(SerialTools::readUInt(), 4) + m_assert(SerialTools::readShort(), -5) + m_assert(SerialTools::readUShort(), 6) + + SerialTools::writeInt(result); +} + +void loop() { } \ No newline at end of file diff --git a/Tests/SerialTest/Test_BoneToArduino.cpp b/Tests/SerialTest/Test_BoneToArduino.cpp new file mode 100644 index 0000000..5a73ca7 --- /dev/null +++ b/Tests/SerialTest/Test_BoneToArduino.cpp @@ -0,0 +1,48 @@ +#include +#include +#include "Serial.h" + +#define MSG(x) std::cout << x +#define MSGN(x) std::cout << x << "\n" +#define ERR(x) std::cerr << x << "\n" +#define m_assert(x) (x)&0x01 == 1 ? MSGN("FAIL") : MSGN("PASS") + +int main() { + MSGN("-- BEGIN TEST --"); + + MSG("\nCreating Serial Object... "); + Serial serial("/dev/ttyACM0"); + MSGN("Done!\n"); + + std::string res = serial.readString(); + MSG("Message: "); MSGN(res); + serial.writeByte('R'); + + MSGN("Sending Static Values to Arduino..."); + int bytes = 0x0A0B0C0D; + + serial.writeData((char*)&bytes, 4); + serial.writeByte(0xFF); + serial.writeFloat(0.1F); + serial.writeDouble(0.2); + serial.writeInt(-3); + serial.writeUInt(4); + serial.writeShort(-5); + serial.writeUShort(6); + + MSG("Results: "); + int ires = serial.readInt(); + + MSGN(ires); + MSG("> Sending Bytes\t\t\t"); m_assert(ires>>7); + MSG("> Sending Byte\t\t\t"); m_assert(ires>>6); + MSG("> Sending Float\t\t\t"); m_assert(ires>>5); + MSG("> Sending Double\t\t"); m_assert(ires>>4); + MSG("> Sending Int\t\t\t"); m_assert(ires>>3); + MSG("> Sending Unsigned Int\t\t"); m_assert(ires>>2); + MSG("> Sending Short\t\t\t"); m_assert(ires>>1); + MSG("> Sending Unsigned Short\t"); m_assert(ires>>0); + + MSGN("\n-- END TEST --"); + return 0; +} \ No newline at end of file