Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino / Bone Serial Tests #211

Merged
merged 6 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Tests/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
In order to quickly test Arduino code without unpluging and repluging the
Arduino, these tests have been writen to use PlatformIO. PlatformIO enables
combiling and uploading Arduino code, directly from the terminal without ever
leaving your chair.



* Installing PlatformIO *

In a Linux terminal, run the following commands:
> python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)"
> python get-platformio.py

To confirm PlatformIO is installed sucessfully, run:
> platformio --help



* Compiling and Uploading with PlatformIO *

> # list serial ports
> platformio serialports list

> # upload code
> platformio run -e due -t upload

> # compile code
> platformio run -e due



* Running Tests *

Step 1. Upload the corresponding Arduino code with PlatformIO (as needed)
Step 2. Compile test w/dependencies:
> g++ --std=c++11 Test_<name>.cpp [dependencies] -o run
Step 3. Run the test:
> ./run

2 changes: 2 additions & 0 deletions Tests/SerialTest/PIO_ArduinoToBone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pioenvs
.piolibdeps
65 changes: 65 additions & 0 deletions Tests/SerialTest/PIO_ArduinoToBone/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#


#
# Template #1: General project. Test it using existing `platformio.ini`.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
#
# script:
# - platformio run


#
# Template #2: The project is intended to by used as a library with examples
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
36 changes: 36 additions & 0 deletions Tests/SerialTest/PIO_ArduinoToBone/lib/readme.txt
Original file line number Diff line number Diff line change
@@ -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 <Foo.h>
#include <Bar.h>

// 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
19 changes: 19 additions & 0 deletions Tests/SerialTest/PIO_ArduinoToBone/platformio.ini
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions Tests/SerialTest/PIO_ArduinoToBone/src/Arduino.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <Arduino.h>
#include "SerialTools.h"

#define B115200 115200
#define GARBAGE 0

void setup() {
Serial.begin(B115200);
SerialTools::writeString("Ready!", 6);
while((!Serial.available())||(Serial.read()==GARBAGE));

int test = 0x0A0B0C0D;
SerialTools::writeData((char*)&test, 4);
SerialTools::writeByte(0xFF);
SerialTools::writeFloat(0.1F);
SerialTools::writeDouble(0.2);
SerialTools::writeInt(-3);
SerialTools::writeUInt(4);
SerialTools::writeShort(-5);
SerialTools::writeUShort(6);
}

void loop() { }
145 changes: 145 additions & 0 deletions Tests/SerialTest/PIO_ArduinoToBone/src/SerialTools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* Created by TekuConcept on 8/3/2016.
*/
#ifndef SERIAL_TOOLS_H
#define SERIAL_TOOLS_H

/**
* Extend the functionality of the Serial object,
* providing various useful type value streams.
*/
class SerialTools{
public:

/* - - - - - - - - - - - - - - - - - - - - - - - - - - *\
* READ FUNCTIONS *
\* - - - - - - - - - - - - - - - - - - - - - - - - - - */

/* reading strings is not yet implemented here */
static uint8_t readByte() {
uint8_t result = 0;
readData((char*)&result, sizeof(uint8_t));
return result;
}

static float readFloat() {
float result = 0;
readData((char*)&result, sizeof(float));
return result;
}

static double readDouble() {
double result = 0;
readData((char*)&result, sizeof(double));
return result;
}

static int32_t readInt() {
int result = 0;
readData((char*)&result, sizeof(int32_t));
return result;
}

static uint32_t readUInt() {
uint32_t result = 0;
readData((char*)&result, sizeof(uint32_t));
return result;
}

static int16_t readShort() {
int16_t result = 0;
readData((char*)&result, sizeof(int16_t));
return result;
}

static uint16_t readUShort() {
uint16_t result = 0;
readData((char*)&result, sizeof(uint16_t));
return result;
}

static void readData(char* ptr, int size) {
while(Serial.available() < size);
for(int i = 0; i < size; i++) {
ptr[i] = Serial.read();
}
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - *\
* WRITE FUNCTIONS *
\* - - - - - - - - - - - - - - - - - - - - - - - - - - */

/**
* Writes a null-terminated string to the Serial's
* out buffer.
*/
static void writeString(const char* data, int size) {
for(int i = 0; i < size; i++) {
Serial.print(data[i]);
}
Serial.print('\0');
}

static void writeByte(uint8_t out) {
writeData((char*)&out, sizeof(uint8_t));
}

static void writeFloat(float out) {
writeData((char*)&out, sizeof(float));
}

static void writeDouble(double out) {
writeData((char*)&out, sizeof(double));
}

static void writeInt(int32_t out) {
writeData((char*)&out, sizeof(int32_t));
}

static void writeUInt(uint32_t out) {
writeData((char*)&out, sizeof(uint32_t));
}

static void writeShort(int16_t out) {
writeData((char*)&out, sizeof(int16_t));
}

static void writeUShort(uint16_t out) {
writeData((char*)&out, sizeof(uint16_t));
}

static void writeData(char* ptr, int size) {
for(int i = 0; i < size; i++){
// #ifdef DEBUG
// printHex((uint8_t)ptr[i]);
// #else
Serial.print(ptr[i]);
// #endif
}
}

static void printHex(uint8_t c) {
printHexChar((uint8_t)((c&0xF0) >> 4));
printHexChar((uint8_t)(c&0x0F));
}

private:
SerialTools(){}
static void printHexChar(uint8_t val) {
char res = '0';
if(val < 10)
Serial.print(val);
else
switch(val-10) {
case 0: res = 'A'; break;
case 1: res = 'B'; break;
case 2: res = 'C'; break;
case 3: res = 'D'; break;
case 4: res = 'E'; break;
case 5: res = 'F'; break;
}
Serial.print(res);
}
};

#endif
2 changes: 2 additions & 0 deletions Tests/SerialTest/PIO_BoneToArduino/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pioenvs
.piolibdeps
Loading