From 9e640ae79a18c610b22744c2b2fe8c10ef770655 Mon Sep 17 00:00:00 2001 From: zhuoshuguo Date: Wed, 21 Jun 2017 16:41:19 +0200 Subject: [PATCH] tests: provide test for LWMAC. --- tests/lwmac/Makefile | 70 +++++++++++++++++++++++++++++++++++++++++++ tests/lwmac/README.md | 53 ++++++++++++++++++++++++++++++++ tests/lwmac/main.c | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 tests/lwmac/Makefile create mode 100644 tests/lwmac/README.md create mode 100644 tests/lwmac/main.c diff --git a/tests/lwmac/Makefile b/tests/lwmac/Makefile new file mode 100644 index 000000000..6114630a4 --- /dev/null +++ b/tests/lwmac/Makefile @@ -0,0 +1,70 @@ +# name of your application +APPLICATION = lwmac + +# If no BOARD is found in the environment, use this default: +BOARD ?= samr21-xpro + +# Currently, LWMAC is only tested and evaluated through on samr21-xpro. +# Once LWMAC has also been tested through on other boards, the whitelist should be +# then accordingly extended. +BOARD_WHITELIST := samr21-xpro + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Uncomment these lines if you want to use platform support from external +# repositories: +#RIOTCPU ?= $(CURDIR)/../../RIOT/thirdparty_cpu +#RIOTBOARD ?= $(CURDIR)/../../RIOT/thirdparty_boards + +# Uncomment this to enable scheduler statistics for ps: +#CFLAGS += -DSCHEDSTATISTICS + +# If you want to use native with valgrind, you should recompile native +# with the target all-valgrind instead of all: +# make -B clean all-valgrind + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +CFLAGS += -DDEVELHELP + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# Modules to include: +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps +# include and auto-initialize all available sensors +USEMODULE += saul_default + +BOARD_PROVIDES_NETIF := airfy-beacon cc2538dk fox iotlab-m3 iotlab-a8-m3 mulle \ + microbit native nrf51dongle nrf52dk nrf6310 openmote-cc2538 pba-d-01-kw2x \ + pca10000 pca10005 remote-pa remote-reva saml21-xpro samr21-xpro \ + spark-core telosb yunjia-nrf51822 z1 + +# Use modules for networking +# gnrc is a meta module including all required, basic gnrc networking modules +USEMODULE += gnrc +# use the default network interface for the board +USEMODULE += gnrc_netdev_default +# automatically initialize the network interface +USEMODULE += auto_init_gnrc_netif +# shell command to send L2 packets with a simple string +USEMODULE += gnrc_txtsnd +# the application dumps received packets to stdout +USEMODULE += gnrc_pktdump +# Use LWMAC +USEMODULE += gnrc_lwmac +# We use only the lower layers of the GNRC network stack, hence, we can +# reduce the size of the packet buffer a bit +CFLAGS += -DGNRC_PKTBUF_SIZE=512 + +FEATURES_OPTIONAL += config + +include $(RIOTBASE)/Makefile.include + +# Set a custom channel if needed +DEFAULT_CHANNEL ?= 26 +CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) diff --git a/tests/lwmac/README.md b/tests/lwmac/README.md new file mode 100644 index 000000000..fc287b0f3 --- /dev/null +++ b/tests/lwmac/README.md @@ -0,0 +1,53 @@ +examples/default +================ +This application is a showcase for testing LWMAC communications. Using it +for your board, you should be able to interactively use any hardware +that is supported for communications among devices based on LWMAC. + +Usage +===== + +Build, flash and start the application: +``` +export BOARD=your_board +make +make flash +make term +``` + +The `term` make target starts a terminal emulator for your board. It +connects to a default port so you can interact with the shell, usually +that is `/dev/ttyUSB0`. If your port is named differently, the +`PORT=/dev/yourport` variable can be used to override this. + + +Example output +========== + +The `ifconfig` command will help you to configure all available network +interfaces. On an samr21 board it will print something like: +``` +2015-09-16 16:58:37,762 - INFO # ifconfig +2015-09-16 16:58:37,766 - INFO # Iface 4 HWaddr: 9e:72 Channel: 26 NID: 0x23 TX-Power: 0dBm State: IDLE CSMA Retries: 4 +2015-09-16 16:58:37,768 - INFO # Long HWaddr: 36:32:48:33:46:da:9e:72 +2015-09-16 16:58:37,769 - INFO # AUTOACK CSMA +2015-09-16 16:58:37,770 - INFO # Source address length: 2 +``` + +The `txtsnd` command allows you to send a simple string directly over the link +layer (here, it is LWMAC) using unicast or broadcast. The application will also automatically print +information about any received packet over the serial. This will look like: +``` +2015-09-16 16:59:29,187 - INFO # PKTDUMP: data received: +2015-09-16 16:59:29,189 - INFO # ~~ SNIP 0 - size: 28 byte, type: +NETTYPE_UNDEF (0) +2015-09-16 16:59:29,190 - INFO # 000000 7b 3b 3a 02 85 00 e7 fb 00 00 00 00 01 +02 5a 55 +2015-09-16 16:59:29,192 - INFO # 000010 40 42 3e 62 f2 1a 00 00 00 00 00 00 +2015-09-16 16:59:29,194 - INFO # ~~ SNIP 1 - size: 18 byte, type: +NETTYPE_NETIF (-1) +2015-09-16 16:59:29,195 - INFO # if_pid: 4 rssi: 49 lqi: 78 +2015-09-16 16:59:29,196 - INFO # src_l2addr: 5a:55:40:42:3e:62:f2:1a +2015-09-16 16:59:29,197 - INFO # dst_l2addr: ff:ff +2015-09-16 16:59:29,198 - INFO # ~~ PKT - 2 snips, total size: 46 byte +``` diff --git a/tests/lwmac/main.c b/tests/lwmac/main.c new file mode 100644 index 000000000..a9e56d215 --- /dev/null +++ b/tests/lwmac/main.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008, 2009, 2010 Kaspar Schleiser + * Copyright (C) 2013 INRIA + * Copyright (C) 2013 Ludwig Knüpfer + * + * 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 examples + * @{ + * + * @file + * @brief Default application that shows a lot of functionality of RIOT + * + * @author Kaspar Schleiser + * @author Oliver Hahm + * @author Ludwig Knüpfer + * + * @} + */ + +#include +#include + +#include "thread.h" +#include "shell.h" +#include "shell_commands.h" + +#if FEATURE_PERIPH_RTC +#include "periph/rtc.h" +#endif + +#ifdef MODULE_LTC4150 +#include "ltc4150.h" +#endif + +#ifdef MODULE_NETIF +#include "net/gnrc/pktdump.h" +#include "net/gnrc.h" +#endif + +int main(void) +{ +#ifdef MODULE_LTC4150 + ltc4150_start(); +#endif + +#ifdef FEATURE_PERIPH_RTC + rtc_init(); +#endif + +#ifdef MODULE_NETIF + gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + gnrc_pktdump_pid); + gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); +#endif + + (void) puts("Welcome to RIOT!"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +}