From 805eb9c38bed1c5160193db4ce34da0cd598ce4f Mon Sep 17 00:00:00 2001 From: smlng Date: Tue, 31 Oct 2017 01:31:40 +0100 Subject: [PATCH 1/2] pkg: add uMorse --- pkg/umorse/Makefile | 12 ++++++++++++ pkg/umorse/Makefile.include | 1 + pkg/umorse/Makefile.umorse | 2 ++ pkg/umorse/doc.txt | 8 ++++++++ 4 files changed, 23 insertions(+) create mode 100644 pkg/umorse/Makefile create mode 100644 pkg/umorse/Makefile.include create mode 100644 pkg/umorse/Makefile.umorse create mode 100644 pkg/umorse/doc.txt diff --git a/pkg/umorse/Makefile b/pkg/umorse/Makefile new file mode 100644 index 000000000..30678ace1 --- /dev/null +++ b/pkg/umorse/Makefile @@ -0,0 +1,12 @@ +PKG_NAME=umorse +PKG_URL=https://github.com/smlng/uMorse +PKG_VERSION=1dc14abdba22cca2f7efc053b2bce327bc7db97e +PKG_LICENSE=MIT + +.PHONY: all + +all: git-download + @cp Makefile.umorse $(PKG_BUILDDIR)/Makefile + $(MAKE) -C $(PKG_BUILDDIR) + +include $(RIOTBASE)/pkg/pkg.mk diff --git a/pkg/umorse/Makefile.include b/pkg/umorse/Makefile.include new file mode 100644 index 000000000..f3fc9946a --- /dev/null +++ b/pkg/umorse/Makefile.include @@ -0,0 +1 @@ +INCLUDES += -I$(PKGDIRBASE)/umorse diff --git a/pkg/umorse/Makefile.umorse b/pkg/umorse/Makefile.umorse new file mode 100644 index 000000000..9084f67e6 --- /dev/null +++ b/pkg/umorse/Makefile.umorse @@ -0,0 +1,2 @@ +SRC := umorse.c print.c +include $(RIOTBASE)/Makefile.base diff --git a/pkg/umorse/doc.txt b/pkg/umorse/doc.txt new file mode 100644 index 000000000..26b59e746 --- /dev/null +++ b/pkg/umorse/doc.txt @@ -0,0 +1,8 @@ +/** + * @defgroup pkg_umorse Lightweight Morse encoder + * @ingroup pkg + * @ingroup sys + * @brief Provides slim Morse encoding functionality + * + * @see https://github.com/smlng/uMorse + */ From ac4a0fd063bdb9fd31763fdc261942d40ef2d3ec Mon Sep 17 00:00:00 2001 From: smlng Date: Tue, 31 Oct 2017 01:32:12 +0100 Subject: [PATCH 2/2] tests: add test for uMorse package add README for tests/pkg_umorse add script for tests/pkg_umorse --- tests/pkg_umorse/Makefile | 14 ++++ tests/pkg_umorse/README.md | 20 ++++++ tests/pkg_umorse/main.c | 118 +++++++++++++++++++++++++++++++ tests/pkg_umorse/tests/01-run.py | 26 +++++++ 4 files changed, 178 insertions(+) create mode 100644 tests/pkg_umorse/Makefile create mode 100644 tests/pkg_umorse/README.md create mode 100644 tests/pkg_umorse/main.c create mode 100755 tests/pkg_umorse/tests/01-run.py diff --git a/tests/pkg_umorse/Makefile b/tests/pkg_umorse/Makefile new file mode 100644 index 000000000..c14831fd6 --- /dev/null +++ b/tests/pkg_umorse/Makefile @@ -0,0 +1,14 @@ +APPLICATION = pkg_umorse +include ../Makefile.tests_common + +USEMODULE += xtimer + +USEPKG += umorse + +UMORSE_DELAY_DIT ?= 120 +CFLAGS += -DUMORSE_DELAY_DIT=$(UMORSE_DELAY_DIT) + +include $(RIOTBASE)/Makefile.include + +test: + tests/01-run.py diff --git a/tests/pkg_umorse/README.md b/tests/pkg_umorse/README.md new file mode 100644 index 000000000..c63b6fcc2 --- /dev/null +++ b/tests/pkg_umorse/README.md @@ -0,0 +1,20 @@ +# Description + +This test verifies that the uMorse package compiles with RIOT. It also checks +its basic functions by encoding a text string into Morse code. The encoded text +is printed to the shell using `.` and `_` for DIT (short) and DAH (long) Morse +chars. Inter char gaps are represented by ` ` (space), inter word gaps are +printed as ` / ` (dash). Even longer gaps are printed as `\n` (new line). + +The Morse code will be printed 2 times using different encoding strategies +provided by uMorse. The first run is printed with delays, i.e., the Morse +code is printed with a certain timing. The second run is printed without +delay, i.e., Morse code is printed all at once. However, if compiled for a +board with a LED0_ON defined, the second run will use the LED0 to blink the +Morse encoded text with delays. + +# Configure delays + +The delay can be configured by setting `UMORSE_DELAY_DIT`, see Makefile. +The default in uMorse is 60ms, as this is quite fast for beginners, its +set to 120ms for this test and could be further raised, e.g. 240ms. diff --git a/tests/pkg_umorse/main.c b/tests/pkg_umorse/main.c new file mode 100644 index 000000000..921cd40b6 --- /dev/null +++ b/tests/pkg_umorse/main.c @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2017 HAW Hamburg + * + * 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 tests + * @{ + * @file + * @brief Check if the uMorse package builds. + * + * @author Sebastian Meiling + * @} + */ + +#include +#include + +#include "board.h" +#include "led.h" +#include "periph_conf.h" +#include "xtimer.h" +#define UMORSE_MSLEEP(m) xtimer_usleep(m * US_PER_MS) + +#include "umorse.h" +#include "print.h" + +#define CODE_LEN (64U) + +void blink_dit(void *args, uint8_t flags) +{ + (void) args; + (void) flags; + + LED0_ON; + UMORSE_MSLEEP(UMORSE_DELAY_DIT); + LED0_OFF; +} + +void blink_dah(void *args, uint8_t flags) +{ + (void) args; + (void) flags; + + LED0_ON; + UMORSE_MSLEEP(UMORSE_DELAY_DAH); + LED0_OFF; +} + +void blink_nil(void *args, uint8_t flags) +{ + (void) args; + + uint8_t cnt = flags & UMORSE_MASK_COUNT; + UMORSE_MSLEEP(cnt * UMORSE_DELAY_DIT); +} + +static const umorse_out_t blink = { + .dit = blink_dit, + .dah = blink_dah, + .nil = blink_nil, + .params = NULL +}; + +static const umorse_out_t print = { + .dit = umorse_print_dit, + .dah = umorse_print_dah, + .nil = umorse_print_nil, + .params = NULL +}; + +static const char text[] = "Hello RIOT-OS!\nThis is uMorse."; + +int test_umorse_out(void) +{ + uint8_t code[CODE_LEN]; + + printf("> Translate text of length %u into Morse code:\n\"%s\"\n", + (unsigned)strlen(text), text); + + memset(code, 0, CODE_LEN); + printf("> using aligned encoding:\n"); + int ret = umorse_encode_aligned(text, sizeof(text), code, sizeof(code)); + if (ret < 0) { + return 1; + } + umorse_output(&print, code, ret, 0x0); + printf("> encoded length=%d\n", ret); + + memset(code, 0, CODE_LEN); + printf("> using compact encoding:\n"); + ret = umorse_encode_compact(text, sizeof(text), code, sizeof(code)); + if (ret < 0) { + return 2; + } + umorse_output(&print, code, ret, UMORSE_FLAG_NODELAY); + umorse_output(&blink, code, ret, 0x0); + printf("> encoded length=%d\n", ret); + + return 0; +} + +int main(void) +{ + LED0_OFF; + + puts("[START]"); + int ret = test_umorse_out(); + if (ret) { + puts("[FAILURE]"); + return 1; + } + puts("[SUCCESS]"); + return 0; +} diff --git a/tests/pkg_umorse/tests/01-run.py b/tests/pkg_umorse/tests/01-run.py new file mode 100755 index 000000000..6dcb50421 --- /dev/null +++ b/tests/pkg_umorse/tests/01-run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017 HAW Hamburg +# +# 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. + +import os +import sys + +sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) +import testrunner + +def testfunc(child): + + child.expect(u".... . ._.. ._.. ___ / ._. .. ___ _ ___ ...", timeout=30) + child.expect(u"_ .... .. ... / .. ... / .._ __ ___ ._. ... .", timeout=30) + + child.expect(u".... . ._.. ._.. ___ / ._. .. ___ _ ___ ...", timeout=30) + child.expect(u"_ .... .. ... / .. ... / .._ __ ___ ._. ... .", timeout=30) + + child.expect_exact("[SUCCESS]", timeout=120) + +if __name__ == "__main__": + sys.exit(testrunner.run(testfunc))