From 41755e01d681312de7508ed5edf23d3a9a83f4a6 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 21 Mar 2018 11:54:46 +0100 Subject: [PATCH] tests: add test application for Cayenne LPP package --- tests/pkg_cayenne-lpp/Makefile | 8 ++++ tests/pkg_cayenne-lpp/README.md | 17 ++++++++ tests/pkg_cayenne-lpp/main.c | 59 +++++++++++++++++++++++++++ tests/pkg_cayenne-lpp/tests/01-run.py | 16 ++++++++ 4 files changed, 100 insertions(+) create mode 100644 tests/pkg_cayenne-lpp/Makefile create mode 100644 tests/pkg_cayenne-lpp/README.md create mode 100644 tests/pkg_cayenne-lpp/main.c create mode 100755 tests/pkg_cayenne-lpp/tests/01-run.py diff --git a/tests/pkg_cayenne-lpp/Makefile b/tests/pkg_cayenne-lpp/Makefile new file mode 100644 index 0000000000000..30ed3b63c91ea --- /dev/null +++ b/tests/pkg_cayenne-lpp/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +USEPKG += cayenne-lpp + +include $(RIOTBASE)/Makefile.include + +test: + tests/01-run.py diff --git a/tests/pkg_cayenne-lpp/README.md b/tests/pkg_cayenne-lpp/README.md new file mode 100644 index 0000000000000..7a4038e658f0e --- /dev/null +++ b/tests/pkg_cayenne-lpp/README.md @@ -0,0 +1,17 @@ +Cayenne LPP test +================ + +Usage +----- + +Simply run the application on native using: + + make all term + +Expected result +--------------- + +The application should display the following output: + + Cayenne LPP test application + 03670110056700FF diff --git a/tests/pkg_cayenne-lpp/main.c b/tests/pkg_cayenne-lpp/main.c new file mode 100644 index 0000000000000..edb32efe0eb32 --- /dev/null +++ b/tests/pkg_cayenne-lpp/main.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2018 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup test + * @{ + * + * @file + * @brief Cayenne Low Power Payload example application + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "cayenne-lpp.h" + +static cayenne_lpp_t lpp; + +static void _print_buffer(cayenne_lpp_t *lpp) +{ + for (uint8_t i = 0; i < lpp->cursor; ++i) { + printf("%02X", lpp->buffer[i]); + } + puts(""); +} + +int main(void) +{ + puts("Cayenne LPP test application"); + + /* generate payload like the one given as example at + * https://mydevices.com/cayenne/docs_stage/lora/#lora-cayenne-low-power-payload + */ + /* Device with 2 temperature sensors */ + cayenne_lpp_add_temperature(&lpp, 3, 27.2); + cayenne_lpp_add_temperature(&lpp, 5, 25.5); + _print_buffer(&lpp); + + /* Device with temperature and acceleration sensors */ + cayenne_lpp_reset(&lpp); + cayenne_lpp_add_temperature(&lpp, 1, -4.1); + cayenne_lpp_add_accelerometer(&lpp, 6, 1.234, -1.234, 0); + _print_buffer(&lpp); + + /* Device with GPS */ + cayenne_lpp_reset(&lpp); + cayenne_lpp_add_gps(&lpp, 1, 42.3519, -87.9094, 10); + _print_buffer(&lpp); + + return 0; +} diff --git a/tests/pkg_cayenne-lpp/tests/01-run.py b/tests/pkg_cayenne-lpp/tests/01-run.py new file mode 100755 index 0000000000000..608060948bba6 --- /dev/null +++ b/tests/pkg_cayenne-lpp/tests/01-run.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import os +import sys + + +def testfunc(child): + child.expect_exact('03670110056700FF') + child.expect_exact('0167FFD8067104D1FB2F0000') + child.expect_exact('018806765EF2960A0003E8') + + +if __name__ == "__main__": + sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) + from testrunner import run + sys.exit(run(testfunc))