Skip to content

Commit

Permalink
tests: add emb6 test
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 30, 2016
1 parent 0ab8aae commit 43f7f55
Show file tree
Hide file tree
Showing 6 changed files with 587 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/emb6/Makefile
@@ -0,0 +1,38 @@
APPLICATION = emb6

FEATURES_REQUIRED = periph_gpio periph_spi # for at86rf231

BOARD ?= samr21-xpro

RIOTBASE ?= $(CURDIR)/../..

BOARD_INSUFFICIENT_MEMORY := msb-430h stm32f0discovery weio z1

USEMODULE += emb6_router
USEMODULE += emb6_conn_udp
USEMODULE += ipv6_addr
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps
USEMODULE += od

# define the driver to be used for selected boards
ifneq (,$(filter samr21-xpro,$(BOARD)))
DRIVER := at86rf233
endif
ifneq (,$(filter iotlab-m3 fox,$(BOARD)))
DRIVER := at86rf231
endif
ifneq (,$(filter mulle,$(BOARD)))
DRIVER := at86rf212b
endif

# use the at86rf231 as fallback device
DRIVER ?= at86rf231

# include the selected driver
USEMODULE += $(DRIVER)

QUIET ?= 1

include $(RIOTBASE)/Makefile.include
57 changes: 57 additions & 0 deletions tests/emb6/common.c
@@ -0,0 +1,57 @@
/*
* Copyright (C) Freie Universität Berlin
*
* 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.
*/

/**
* @{
*
* @file
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/

#include <stdbool.h>

#include "common.h"

size_t hex2ints(uint8_t *out, const char *in)
{
bool upper = true;
size_t out_size = 0;

while (*in != '\0') {
char c;
if ((*in >= '0') && (*in <= '9')) {
c = '0';
}
else if ((*in >= 'a') && (*in <= 'f')) {
c = 'a' - 10;
}
else if ((*in >= 'A') && (*in <= 'F')) {
c = 'A' - 10;
}
else {
in++;
continue;
}
if (upper) {
*out = (char)(*in - c) << 4;
}
else {
*out |= (char)(*in - c);
out++;
out_size++;
}
upper = !upper;
in++;
}
if (!upper) {
out_size++;
}
return out_size;
}

/** @} */
79 changes: 79 additions & 0 deletions tests/emb6/common.h
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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 Definitions for tests/lwip/
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef MAIN_H_
#define MAIN_H_

#include <stdint.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Application configuration
* @{
*/
#define CONN_INBUF_SIZE (256)
#define SERVER_MSG_QUEUE_SIZE (8)
#define SERVER_BUFFER_SIZE (64)
/**
* @}
*/

/**
* @brief Converts hex string to byte array.
*
* @param[out] out Resulting byte array
* @param[in] in `\0` terminated string. Non-hex characters (all except 0-9, a-f, A-F)
* will be ignored.
*
* @return Length of @p out.
*/
size_t hex2ints(uint8_t *out, const char *in);

/**
* @brief Ping shell command
*
* @param[in] argc number of arguments
* @param[in] argv array of arguments
*
* @return 0 on success
* @return other on error
*/
int ping_cmd(int argc, char **argv);

#ifdef MODULE_CONN_UDP
/**
* @brief UDP IP shell command
*
* @param[in] argc number of arguments
* @param[in] argv array of arguments
*
* @return 0 on success
* @return other on error
*/
int udp_cmd(int argc, char **argv);
#endif

#ifdef __cplusplus
}
#endif

#endif /* MAIN_H_ */
/** @} */
109 changes: 109 additions & 0 deletions tests/emb6/main.c
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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 Test for raw IPv6 connections
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This test application tests the gnrc_conn_ip module. If you select protocol 58 you can also
* test if gnrc is able to deal with multiple subscribers to ICMPv6 (gnrc_icmpv6 and this
* application).
*
* @}
*/

#include <errno.h>
#include <stdio.h>

#include "at86rf2xx.h"
#include "at86rf2xx_params.h"
#include "common.h"
#include "emb6.h"
#include "emb6/netdev2.h"
#include "uip-ds6.h"
#include "net/ipv6/addr.h"
#include "shell.h"
#include "thread.h"
#include "xtimer.h"

#define EMB6_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#define EMB6_PRIO (THREAD_PRIORITY_MAIN - 3)
#define EMB6_DELAY (500)

static at86rf2xx_t at86rf2xx;
static s_ns_t emb6 = {
.hc = &sicslowpan_driver,
.llsec = &nullsec_driver,
.hmac = &nullmac_driver,
.lmac = &sicslowmac_driver,
.frame = &framer_802154,
.c_configured = 1,
};
static char emb6_stack[EMB6_STACKSIZE];

static int ifconfig(int argc, char **argv)
{
(void)argc;
(void)argv;
char addrstr[IPV6_ADDR_MAX_STR_LEN];
printf("0: ");
for (int i = 0; i < UIP_DS6_ADDR_NB; i++) {
if (uip_ds6_if.addr_list[i].isused) {
printf("inet6 %s\n",
ipv6_addr_to_str(addrstr,
(ipv6_addr_t *)&uip_ds6_if.addr_list[i].ipaddr,
sizeof(addrstr)));
if (i != 0) {
printf(" ");
}
}
}
puts("");
return 0;
}

static void *_emb6_thread(void *args)
{
emb6_process(500); /* never stops */
return NULL;
}

static const shell_command_t shell_commands[] = {
{ "ping6", "Send pings and receive pongs", ping_cmd },
#ifdef MODULE_CONN_UDP
{ "udp", "Send UDP messages and listen for messages on UDP port", udp_cmd },
#endif
{ "ifconfig", "Shows assigned IPv6 addresses", ifconfig },
{ NULL, NULL, NULL }
};
static char line_buf[SHELL_DEFAULT_BUFSIZE];

char conn_inbuf[CONN_INBUF_SIZE];

int main(void)
{
netdev2_t *netdev = (netdev2_t *)&at86rf2xx;

puts("RIOT lwip test application");

at86rf2xx_setup(&at86rf2xx, at86rf2xx_params);
netdev->driver->init((netdev2_t *)&at86rf2xx);
emb6_netdev2_setup(netdev);
emb6_init(&emb6);
thread_create(emb6_stack, sizeof(emb6_stack), EMB6_PRIO,
THREAD_CREATE_STACKTEST, _emb6_thread, NULL, "emb6");
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

/* should be never reached */
return 0;
}

0 comments on commit 43f7f55

Please sign in to comment.