Merge pull request #7914 from smlng/pkg/umorse

pkg: add uMorse
This commit is contained in:
Kaspar Schleiser
2017-11-02 10:20:38 +01:00
committed by GitHub
8 changed files with 201 additions and 0 deletions
+12
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
INCLUDES += -I$(PKGDIRBASE)/umorse
+2
View File
@@ -0,0 +1,2 @@
SRC := umorse.c print.c
include $(RIOTBASE)/Makefile.base
+8
View File
@@ -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
*/
+14
View File
@@ -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
+20
View File
@@ -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.
+118
View File
@@ -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 <s@mlng.net>
* @}
*/
#include <stdio.h>
#include <string.h>
#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;
}
+26
View File
@@ -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))