diff --git a/README.md b/README.md index f29f369c1..df7d7ff58 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Contiki-NG: The OS for Next Generation IoT Devices [![Build Status](https://travis-ci.org/contiki-ng/contiki-ng.svg?branch=master)](https://travis-ci.org/contiki-ng/contiki-ng/branches) -[![License](https://img.shields.io/badge/License-3--Clause%20BSD-brightgreen.svg)](https://github.com/contiki-ng/contiki-ng/blob/master/LICENSE.md) +[![license](https://img.shields.io/badge/license-3--clause%20bsd-brightgreen.svg)](https://github.com/contiki-ng/contiki-ng/blob/master/LICENSE.md) [![Latest release](https://img.shields.io/github/release/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/releases/latest) [![GitHub Release Date](https://img.shields.io/github/release-date/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/releases/latest) [![Last commit](https://img.shields.io/github/last-commit/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/commit/HEAD) @@ -9,7 +9,7 @@ Contiki-NG is an open-source, cross-platform operating system for Next-Generation IoT devices. It focuses on dependable (secure and reliable) low-power communication and standard protocols, such as IPv6/6LoWPAN, 6TiSCH, RPL, and CoAP. Contiki-NG comes with extensive documentation, tutorials, a roadmap, release cycle, and well-defined development flow for smooth integration of community contributions. Unless excplicitly stated otherwise, Contiki-NG sources are distributed under -the terms of the [3-clause BSD license](LICENSE.md). +the terms of the [3-clause BSD license](LICENSE.md). Contiki-NG started as a fork of the Contiki OS and retains some of its original features. diff --git a/arch/cpu/cc2538/dev/spi-arch-legacy.h b/arch/cpu/cc2538/dev/spi-arch-legacy.h index de7a765bb..9608110ed 100644 --- a/arch/cpu/cc2538/dev/spi-arch-legacy.h +++ b/arch/cpu/cc2538/dev/spi-arch-legacy.h @@ -55,7 +55,7 @@ * - SPIX_FLUSH(x) * * Some of the old functions and macros are still supported. - * When using these deprecated functions, the SSI module to use + * When using these deprecated functions, the SSI module to use * has to be be selected by means of the macro SPI_CONF_DEFAULT_INSTANCE. * * This SPI driver depends on the following defines: @@ -95,14 +95,14 @@ #endif /*---------------------------------------------------------------------------*/ /* Default values for the clock rate divider */ -#ifdef SPI0_CONF_CPRS_CPSDVSR -#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR +#ifdef SPI0_CONF_CPRS_CPSDVSR +#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR #else #define SPI0_CPRS_CPSDVSR 2 #endif -#ifdef SPI1_CONF_CPRS_CPSDVSR -#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR +#ifdef SPI1_CONF_CPRS_CPSDVSR +#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR #else #define SPI1_CPRS_CPSDVSR 2 #endif @@ -120,7 +120,7 @@ } while(0) #define SPIX_FLUSH(spi) do { \ while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE) { \ - SPIX_BUF(spi); \ + SPIX_BUF(spi); \ } \ } while(0) #define SPIX_CS_CLR(port, pin) do { \ @@ -144,7 +144,7 @@ #endif #define SPI_CS_CLR(port, pin) SPIX_CS_CLR(port, pin) #define SPI_CS_SET(port, pin) SPIX_CS_SET(port, pin) -#endif /* #ifdef SPI_DEFAULT_INSTANCE */ +#endif /* #ifdef SPI_DEFAULT_INSTANCE */ /*---------------------------------------------------------------------------*/ /** \name Arch-specific SPI functions * @{ @@ -183,7 +183,7 @@ void spix_disable(uint8_t spi); * * See section 19.4.4 in the CC2538 user guide for more information. * - * \param spi The SSI instance to use. + * \param spi The SSI instance to use. * \param frame_format Set the SSI frame format. Use SSI_CR0_FRF_MOTOROLA, * SSI_CR0_FRF_TI, or SSI_CR0_FRF_MICROWIRE. * \param clock_polarity In Motorola mode, set whether the clock is high or low diff --git a/arch/cpu/msp430/f1xxx/spi-legacy.c b/arch/cpu/msp430/f1xxx/spi-legacy.c index c9e98508f..38adfaa31 100644 --- a/arch/cpu/msp430/f1xxx/spi-legacy.c +++ b/arch/cpu/msp430/f1xxx/spi-legacy.c @@ -1,30 +1,30 @@ /* * Copyright (c) 2006, Swedish Institute of Computer Science - * All rights reserved. + * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * */ @@ -35,7 +35,7 @@ * exclusive. Set spi_busy so that interrupt handlers can check if * they are allowed to use the bus or not. Only the CC2420 radio needs * this in practice. - * + * */ unsigned char spi_busy = 0; diff --git a/arch/cpu/msp430/msp430-def.h b/arch/cpu/msp430/msp430-def.h index 93e575702..e032bb4a0 100644 --- a/arch/cpu/msp430/msp430-def.h +++ b/arch/cpu/msp430/msp430-def.h @@ -1,30 +1,30 @@ /* * Copyright (c) 2007, Swedish Institute of Computer Science - * All rights reserved. + * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #ifndef MSP430_DEF_H_ diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index 146af3e72..af7328b31 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -1,6 +1,7 @@ CONTIKI_CPU_DIRS = . net dev -CONTIKI_SOURCEFILES += rtimer-arch.c watchdog.c eeprom.c +CONTIKI_SOURCEFILES += rtimer-arch.c watchdog.c eeprom.c int-master.c +CONTIKI_SOURCEFILES += gpio-hal-arch.c ### Compiler definitions CC ?= gcc diff --git a/arch/cpu/native/dev/gpio-hal-arch.c b/arch/cpu/native/dev/gpio-hal-arch.c new file mode 100644 index 000000000..553a23444 --- /dev/null +++ b/arch/cpu/native/dev/gpio-hal-arch.c @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +#include "sys/log.h" + +#include +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#define LOG_MODULE "GPIO arch" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ +static gpio_hal_pin_cfg_t pin_cfg[GPIO_HAL_PIN_COUNT]; +static uint8_t pin_state[GPIO_HAL_PIN_COUNT]; +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + LOG_DBG("Pin %u: Enabled interrupt\n", pin); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + LOG_DBG("Pin %u: Disabled interrupt\n", pin); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + pin_cfg[pin] = cfg; + LOG_DBG("Pin %u: Set config=0x%02x\n", pin, pin_cfg[pin]); +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_cfg_t +gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return 0; + } + + LOG_DBG("Pin %u: Config=0x%02x\n", pin, pin_cfg[pin]); + return pin_cfg[pin]; +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_pin_set_input(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + LOG_DBG("Pin %u: Set input\n", pin); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_pin_set_output(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + LOG_DBG("Pin %u: Set output\n", pin); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_set_pin(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + pin_state[pin] = 1; + LOG_DBG("Pin %u: Set\n", pin); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_clear_pin(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + pin_state[pin] = 0; + LOG_DBG("Pin %u: Clear\n", pin); +} +/*---------------------------------------------------------------------------*/ +uint8_t +gpio_hal_arch_read_pin(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return 0; + } + + LOG_DBG("Pin %u: Read=%u\n", pin, pin_state[pin]); + return pin_state[pin]; +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); + return; + } + + pin_state[pin] = value; + LOG_DBG("Pin %u: Write=%u\n", pin, pin_state[pin]); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins) +{ + gpio_hal_pin_t pin; + + for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) { + if(pins & (1 << pin)) { + pin_state[pin] = 1; + } + } + + LOG_DBG("Set pins 0x%08" PRIx32 "\n", pins); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins) +{ + gpio_hal_pin_t pin; + + for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) { + if(pins & (1 << pin)) { + pin_state[pin] = 0; + } + } + + LOG_DBG("Clear pins 0x%08" PRIx32 "\n", pins); +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_mask_t +gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) +{ + gpio_hal_pin_t pin; + gpio_hal_pin_mask_t state = 0; + + for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) { + state |= (pin_state[pin] << pin); + } + + LOG_DBG("Read pins 0x%08" PRIx32 "\n", state); + return state; +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_write_pins(gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value) +{ + gpio_hal_pin_t pin; + + for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) { + if(pins & (1 << pin)) { + pin_state[pin] = (value & (1 << pin)) == 0 ? 0 : 1; + } + } + + LOG_DBG("Write pins 0x%08" PRIx32 "->0x%08" PRIx32 "\n", pins, value); +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/native/int-master.c b/arch/cpu/native/int-master.c new file mode 100644 index 000000000..177dbd442 --- /dev/null +++ b/arch/cpu/native/int-master.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/int-master.h" + +#include +/*---------------------------------------------------------------------------*/ +#define DISABLED 0 +#define ENABLED 1 +/*---------------------------------------------------------------------------*/ +static int_master_status_t stat = DISABLED; +/*---------------------------------------------------------------------------*/ +void +int_master_enable(void) +{ + stat = ENABLED; +} +/*---------------------------------------------------------------------------*/ +int_master_status_t +int_master_read_and_disable(void) +{ + int_master_status_t rv = stat; + stat = DISABLED; + return rv; +} +/*---------------------------------------------------------------------------*/ +void +int_master_status_set(int_master_status_t status) +{ + stat = status; +} +/*---------------------------------------------------------------------------*/ +bool +int_master_is_enabled(void) +{ + return stat == DISABLED ? false : true; +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/native/native-def.h b/arch/cpu/native/native-def.h new file mode 100644 index 000000000..d85ae7100 --- /dev/null +++ b/arch/cpu/native/native-def.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#ifndef NATIVE_DEF_H_ +#define NATIVE_DEF_H_ +/*---------------------------------------------------------------------------*/ +#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 1 +/*---------------------------------------------------------------------------*/ +#endif /* NATIVE_DEF_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/dev/ext-flash/ext-flash.c b/arch/dev/ext-flash/ext-flash.c index 547ec062c..10e953ffa 100644 --- a/arch/dev/ext-flash/ext-flash.c +++ b/arch/dev/ext-flash/ext-flash.c @@ -113,13 +113,15 @@ static spi_device_t flash_spi_configuration_default = { /** * Get spi configuration, return default configuration if NULL */ -static spi_device_t* -get_spi_conf(spi_device_t *conf) { +static spi_device_t * +get_spi_conf(spi_device_t *conf) +{ if(conf == NULL) { return &flash_spi_configuration_default; } return conf; -}/*---------------------------------------------------------------------------*/ +} +/*---------------------------------------------------------------------------*/ /** * Clear external flash CSN line */ @@ -334,7 +336,7 @@ ext_flash_open(spi_device_t *conf) /* Put the part is standby mode */ power_standby(flash_spi_configuration); - if (verify_part(flash_spi_configuration) == VERIFY_PART_OK) { + if(verify_part(flash_spi_configuration) == VERIFY_PART_OK) { return true; } @@ -353,7 +355,7 @@ ext_flash_close(spi_device_t *conf) /* Put the part in low power mode */ ret = power_down(flash_spi_configuration); - + /* SPI is released no matter if power_down() succeeds or fails */ if(spi_release(flash_spi_configuration) != SPI_DEV_STATUS_OK) { return false; @@ -474,7 +476,7 @@ ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length) uint8_t wbuf[4]; uint32_t i, numsectors; uint32_t endoffset = offset + length - 1; - + spi_device_t *flash_spi_configuration; flash_spi_configuration = get_spi_conf(conf); diff --git a/arch/platform/cc2538dk/dev/leds-arch.c b/arch/platform/cc2538dk/dev/leds-arch.c index c849355b4..78441defc 100644 --- a/arch/platform/cc2538dk/dev/leds-arch.c +++ b/arch/platform/cc2538dk/dev/leds-arch.c @@ -57,5 +57,3 @@ const leds_t leds_arch_leds[] = { #endif }; /*---------------------------------------------------------------------------*/ - - diff --git a/arch/platform/native/Makefile.native b/arch/platform/native/Makefile.native index f8fd7286c..afeddd22f 100644 --- a/arch/platform/native/Makefile.native +++ b/arch/platform/native/Makefile.native @@ -6,8 +6,8 @@ endif CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} -CONTIKI_TARGET_SOURCEFILES += platform.c clock.c xmem.c leds-arch.c -CONTIKI_TARGET_SOURCEFILES += cfs-posix.c cfs-posix-dir.c +CONTIKI_TARGET_SOURCEFILES += platform.c clock.c xmem.c +CONTIKI_TARGET_SOURCEFILES += cfs-posix.c cfs-posix-dir.c buttons.c ifeq ($(HOST_OS),Windows) CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c diff --git a/arch/platform/native/contiki-conf.h b/arch/platform/native/contiki-conf.h index ea1383660..8d2c13820 100644 --- a/arch/platform/native/contiki-conf.h +++ b/arch/platform/native/contiki-conf.h @@ -37,7 +37,9 @@ #ifdef PROJECT_CONF_PATH #include PROJECT_CONF_PATH #endif /* PROJECT_CONF_PATH */ - +/*---------------------------------------------------------------------------*/ +#include "native-def.h" +/*---------------------------------------------------------------------------*/ #include #ifndef WIN32_LEAN_AND_MEAN #include @@ -60,8 +62,6 @@ int select_set_callback(int fd, const struct select_callback *callback); typedef unsigned int uip_stats_t; -#define LEDS_CONF_LEGACY_API 1 - #ifndef UIP_CONF_BYTE_ORDER #define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN #endif @@ -91,6 +91,8 @@ typedef unsigned long clock_time_t; #define LOG_CONF_ENABLED 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 + /* Not part of C99 but actually present */ int strcasecmp(const char*, const char*); diff --git a/examples/coap/sky/module-macros.h b/arch/platform/native/dev/buttons.c similarity index 68% rename from examples/coap/sky/module-macros.h rename to arch/platform/native/dev/buttons.c index 3fcb04015..359f7a409 100644 --- a/examples/coap/sky/module-macros.h +++ b/arch/platform/native/dev/buttons.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2018, RISE SICS AB. + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -14,10 +15,10 @@ * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR @@ -27,21 +28,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#error The CoAP example no longer fits the limited ROM in the Tmote Sky. \ - Please select another platform with more ROM to compile the CoAP example. - /*---------------------------------------------------------------------------*/ -#define COAP_OBSERVE_CLIENT 0 +#include "contiki.h" +#include "dev/button-hal.h" -#define COAP_MAX_CHUNK_SIZE 48 - -/* Turn off DAO-ACK and probing to make code smaller */ -#define RPL_CONF_WITH_DAO_ACK 0 - -#define LOG_CONF_LEVEL_MAIN 0 - -#define DCOSYNCH_CONF_ENABLED 0 - -#define PROCESS_CONF_NUMEVENTS 8 +#include +#include +/*---------------------------------------------------------------------------*/ +button_hal_button_t *button_hal_buttons[] = { NULL }; +const uint8_t button_hal_button_count = 0; /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/native/platform.c b/arch/platform/native/platform.c index fceab0207..c5c4f23e7 100644 --- a/arch/platform/native/platform.c +++ b/arch/platform/native/platform.c @@ -56,6 +56,9 @@ #include "net/netstack.h" #include "dev/serial-line.h" +#include "dev/button-hal.h" +#include "dev/gpio-hal.h" +#include "dev/leds.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-debug.h" @@ -251,6 +254,9 @@ platform_process_args(int argc, char**argv) void platform_init_stage_one() { + gpio_hal_init(); + button_hal_init(); + leds_init(); return; } /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/openmote-cc2538/dev/leds-arch.c b/arch/platform/openmote-cc2538/dev/leds-arch.c index 2bc13bed8..3c1fe333f 100644 --- a/arch/platform/openmote-cc2538/dev/leds-arch.c +++ b/arch/platform/openmote-cc2538/dev/leds-arch.c @@ -54,5 +54,3 @@ const leds_t leds_arch_leds[] = { }, }; /*---------------------------------------------------------------------------*/ - - diff --git a/arch/platform/srf06-cc26xx/cfs-coffee-arch.h b/arch/platform/srf06-cc26xx/cfs-coffee-arch.h index 33cc5123b..6816ca043 100644 --- a/arch/platform/srf06-cc26xx/cfs-coffee-arch.h +++ b/arch/platform/srf06-cc26xx/cfs-coffee-arch.h @@ -43,44 +43,41 @@ #include "contiki-conf.h" #include "dev/xmem.h" -/*** MX25R8035F Memory Organization -The memory is organized as: -8Mbit = 1048576 bytes (8 bits each) -256 sectors (32 Kbits, 4096 bytes each) -4096 pages (256 bytes each). -Each page can be individually programmed (bits are programmed from 1 to 0). The device is -sector or bulk erasable (bits are erased from 0 to 1) but not page erasable -*/ -#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL //Total size of the External Flash Memory in the Z1 +/* + * MX25R8035F Memory Organization + * The memory is organized as: + * 8Mbit = 1048576 bytes (8 bits each) + * 256 sectors (32 Kbits, 4096 bytes each) + * 4096 pages (256 bytes each). + * Each page can be individually programmed (bits are programmed from 1 to 0). + * The device is sector or bulk erasable (bits are erased from 0 to 1) but not + * page erasable + */ +#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL /* Total size of the External Flash Memory in the Z1 */ /* Coffee configuration parameters. */ -#define COFFEE_SECTOR_SIZE 4096UL +#define COFFEE_SECTOR_SIZE 4096UL #define COFFEE_PAGE_SIZE 256UL -#define COFFEE_START 0UL //COFFEE_SECTOR_SIZE +#define COFFEE_START 0UL /* COFFEE_SECTOR_SIZE */ #define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START) #define COFFEE_NAME_LENGTH 16 #define COFFEE_MAX_OPEN_FILES 6 #define COFFEE_FD_SET_SIZE 8 #define COFFEE_LOG_TABLE_LIMIT 256 -#define COFFEE_DYN_SIZE 2*1024 +#define COFFEE_DYN_SIZE 2 * 1024 #define COFFEE_LOG_SIZE 1024 #define COFFEE_MICRO_LOGS 1 - - - - - /* Flash operations. */ -#define COFFEE_WRITE(buf, size, offset) \ - xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) +#define COFFEE_WRITE(buf, size, offset) \ + xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) -#define COFFEE_READ(buf, size, offset) \ - xmem_pread((char *)(buf), (size), COFFEE_START + (offset)) +#define COFFEE_READ(buf, size, offset) \ + xmem_pread((char *)(buf), (size), COFFEE_START + (offset)) -#define COFFEE_ERASE(sector) \ - xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE) +#define COFFEE_ERASE(sector) \ + xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE) /* Coffee types. */ typedef int16_t coffee_page_t; diff --git a/arch/platform/srf06-cc26xx/common/xmem.c b/arch/platform/srf06-cc26xx/common/xmem.c index 116991c66..9228e0fbb 100644 --- a/arch/platform/srf06-cc26xx/common/xmem.c +++ b/arch/platform/srf06-cc26xx/common/xmem.c @@ -49,21 +49,17 @@ #define XMEM_BUFF_LENGHT 128 - #if 0 #define PRINTF(...) printf(__VA_ARGS__) #else -#define PRINTF(...) do {} while (0) +#define PRINTF(...) do {} while(0) #endif - void xmem_init(void) { ext_flash_open(NULL); } - - int xmem_pread(void *_p, int size, unsigned long addr) { @@ -80,21 +76,20 @@ xmem_pread(void *_p, int size, unsigned long addr) } rv = ext_flash_read(NULL, addr, size, _p); - for (i = 0; i < size; i++){ + for(i = 0; i < size; i++) { x = ~*((uint8_t *)_p + i); - *((uint8_t *)_p+i) = x; + *((uint8_t *)_p + i) = x; } ext_flash_close(NULL); - if(rv) + if(rv) { return size; + } PRINTF("Could not read flash memory!\n"); return -1; -} - - +} int xmem_pwrite(const void *_buf, int size, unsigned long addr) { @@ -112,13 +107,13 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr) return -1; } - for (remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) { + for(remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) { int to_write = MIN(XMEM_BUFF_LENGHT, remain); - for (i = 0; i < to_write; i++) { + for(i = 0; i < to_write; i++) { tmp_buf[i] = ~*((uint8_t *)_buf + j + i); } rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf); - if (!rv) { + if(!rv) { PRINTF("Could not write flash memory!\n"); return size - remain; } @@ -128,8 +123,6 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr) return size; } - - int xmem_erase(long size, unsigned long addr) { @@ -137,7 +130,6 @@ xmem_erase(long size, unsigned long addr) rv = ext_flash_open(NULL); - if(!rv) { PRINTF("Could not open flash to save config\n"); ext_flash_close(NULL); @@ -160,8 +152,9 @@ xmem_erase(long size, unsigned long addr) watchdog_periodic(); - if(rv) + if(rv) { return size; + } PRINTF("Could not erase flash memory\n"); return -1; diff --git a/arch/platform/srf06-cc26xx/launchpad/leds-arch.c b/arch/platform/srf06-cc26xx/launchpad/leds-arch.c index 5d70dea40..3c483d3bd 100644 --- a/arch/platform/srf06-cc26xx/launchpad/leds-arch.c +++ b/arch/platform/srf06-cc26xx/launchpad/leds-arch.c @@ -41,5 +41,3 @@ const leds_t leds_arch_leds[] = { { .pin = BOARD_IOID_LED_2, .negative_logic = false }, }; /*---------------------------------------------------------------------------*/ - - diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c b/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c index 21b8cf968..8da95520f 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c @@ -39,5 +39,3 @@ const leds_t leds_arch_leds[] = { { .pin = BOARD_IOID_LED_1, .negative_logic = false }, }; /*---------------------------------------------------------------------------*/ - - diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c b/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c index cab4888b7..ac4abb7d5 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c @@ -40,5 +40,3 @@ const leds_t leds_arch_leds[] = { { .pin = BOARD_IOID_LED_2, .negative_logic = false }, }; /*---------------------------------------------------------------------------*/ - - diff --git a/arch/platform/srf06-cc26xx/srf06/leds-arch.c b/arch/platform/srf06-cc26xx/srf06/leds-arch.c index fba996b39..f504f9cc2 100644 --- a/arch/platform/srf06-cc26xx/srf06/leds-arch.c +++ b/arch/platform/srf06-cc26xx/srf06/leds-arch.c @@ -42,5 +42,3 @@ const leds_t leds_arch_leds[] = { { .pin = BOARD_IOID_LED_4, .negative_logic = false }, }; /*---------------------------------------------------------------------------*/ - - diff --git a/arch/platform/zoul/dev/leds-arch.c b/arch/platform/zoul/dev/leds-arch.c index eea4187c0..ecb02b2f6 100644 --- a/arch/platform/zoul/dev/leds-arch.c +++ b/arch/platform/zoul/dev/leds-arch.c @@ -50,5 +50,3 @@ const leds_t leds_arch_leds[] = { }, }; /*---------------------------------------------------------------------------*/ - - diff --git a/examples/6tisch/6p-packet/project-conf.h b/examples/6tisch/6p-packet/project-conf.h index ece485a17..9771fe4b1 100644 --- a/examples/6tisch/6p-packet/project-conf.h +++ b/examples/6tisch/6p-packet/project-conf.h @@ -28,8 +28,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _PROJECT_CONF_H_ -#define _PROJECT_CONF_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_ND6_SEND_RA 0 @@ -39,4 +39,4 @@ #define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG -#endif /* _PROJECT_CONF_H_ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/6tisch/etsi-plugtest-2017/project-conf.h b/examples/6tisch/etsi-plugtest-2017/project-conf.h index 971f9020d..93c5925b6 100644 --- a/examples/6tisch/etsi-plugtest-2017/project-conf.h +++ b/examples/6tisch/etsi-plugtest-2017/project-conf.h @@ -32,8 +32,8 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ /* Set to enable TSCH security */ #ifndef WITH_SECURITY @@ -115,4 +115,4 @@ #define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG #define TSCH_LOG_CONF_PER_SLOT 1 -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/6tisch/simple-node/project-conf.h b/examples/6tisch/simple-node/project-conf.h index f77e63706..3771fb50f 100644 --- a/examples/6tisch/simple-node/project-conf.h +++ b/examples/6tisch/simple-node/project-conf.h @@ -32,8 +32,8 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ /* Set to enable TSCH security */ #ifndef WITH_SECURITY @@ -78,4 +78,4 @@ #define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_DBG #define TSCH_LOG_CONF_PER_SLOT 1 -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/6tisch/sixtop/project-conf.h b/examples/6tisch/sixtop/project-conf.h index 7f416342e..5235353c2 100755 --- a/examples/6tisch/sixtop/project-conf.h +++ b/examples/6tisch/sixtop/project-conf.h @@ -28,8 +28,8 @@ * */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ /* Set to enable TSCH security */ #ifndef WITH_SECURITY @@ -103,4 +103,4 @@ #endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \ || CONTIKI_TARGET_OPENMOTE_CC2538 */ -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/coap/Makefile b/examples/coap/Makefile deleted file mode 100644 index 1195a37a3..000000000 --- a/examples/coap/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -CONTIKI_PROJECT = coap-example-server coap-example-client -# use target "plugtest-server" explicitly when required - -all: $(CONTIKI_PROJECT) - -CONTIKI=../.. - -# Do not try to build on Sky because of code size limitation -PLATFORMS_EXCLUDE = sky - -# build RESTful resources -include $(CONTIKI)/Makefile.identify-target -ifeq ($(TARGET),native) - MODULES_REL += ./resources-plugtest -endif -MODULES_REL += ./resources -MODULES_REL += $(TARGET) - -# Include the CoAP implementation -MODULES += os/net/app-layer/coap - -include $(CONTIKI)/Makefile.include - -# border router rules -$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c - (cd $(CONTIKI)/tools && $(MAKE) tunslip6) - -connect-router: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 fd00::1/64 - -connect-router-cooja: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 -p 60001 fd00::1/64 - -connect-router-native: $(CONTIKI)/examples/rpl-border-router/border-router.native - sudo $(CONTIKI)/examples/rpl-border-router/border-router.native -a 127.0.0.1 -p 60001 fd00::1/64 - -connect-native: - sudo ip address add fdfd::1/64 dev tun0 diff --git a/examples/coap/README.md b/examples/coap/README.md index 67ba38f26..7d0ac47d2 100644 --- a/examples/coap/README.md +++ b/examples/coap/README.md @@ -1,83 +1,9 @@ -A Quick Introduction to the Erbium (Er) CoAP Engine -=================================================== +# CoAP examples: client, server, and plugtest server -EXAMPLE FILES -------------- +* coap-example-server: A CoAP server example showing how to use the CoAP layer to develop server-side applications. +* coap-example-client: A CoAP client that polls the /actuators/toggle resource every 10 seconds and cycles through 4 resources on button press (target address is hard-coded). +* coap-plugtest-server: The server used for draft compliance testing at ETSI IoT CoAP Plugtests. Erbium (Er) participated in Paris, France, March 2012 and Sophia-Antipolis, France, November 2012 (configured for native). -- coap-example-server.c: A CoAP server example showing how to use the CoAP - layer to develop server-side applications. -- coap-example-client.c: A CoAP client that polls the /actuators/toggle resource - every 10 seconds and cycles through 4 resources on button press (target - address is hard-coded). -- plugtest-server.c: The server used for draft compliance testing at ETSI - IoT CoAP Plugtests. Erbium (Er) participated in Paris, France, March 2012 and - Sophia-Antipolis, France, November 2012 (configured for native). - -PRELIMINARIES -------------- - -- Get the Copper (Cu) CoAP user-agent from - [https://addons.mozilla.org/en-US/firefox/addon/copper-270430](https://addons.mozilla.org/en-US/firefox/addon/copper-270430) - -TMOTE SKY HOWTO ---------------- - -The CoAP example no longer fits in the limited ROM of the Tmote Sky. -Please use a platform with larger ROM instead. - -NATIVE HOWTO ------------- - -With the target native you can test your CoAP applications without -constraints, i.e., with large buffers, debug output, memory protection, etc. -The plugtest-server is thought for the native platform, as it requires -an 1280-byte IP buffer and 1024-byte blocks. - - make TARGET=native plugtest-server - sudo ./plugtest-server.native - -Open new terminal - - make connect-native - -- Start Copper and discover resources at coap://[fdfd::ff:fe00:10]:5683/ -- You can enable the ETSI Plugtest menu in Copper's preferences - -Under Windows/Cygwin, WPCAP might need a patch in -\usr\include\w32api\in6addr.h: - - 21,23c21 - < #ifdef __INSIDE_CYGWIN__ - < uint32_t __s6_addr32[4]; - < #endif - --- - > u_int __s6_addr32[4]; - 36d33 - < #ifdef __INSIDE_CYGWIN__ - 39d35 - < #endif - -DETAILS -------- - -Erbium implements the Proposed Standard of CoAP. Central features are commented -in coap-example-server.c. In general, coap supports: - -- All draft-18 header options -- CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS) -- Blockwise Transfers (note COAP_MAX_CHUNK_SIZE, see plugtest-server.c for - Block1 uploads) -- Separate Responses (no rest_set_pre_handler() required anymore, note - coap_separate_accept(), _reject(), and _resume()) -- Resource Discovery -- Observing Resources (see EVENT_ and PERIODIC_RESOURCE, note - COAP_MAX_OBSERVERS) - -TODOs ------ - -- Dedicated Observe buffers -- Optimize message struct variable access (directly access struct without copying) -- Observe client -- Multiple If-Match ETags -- (Message deduplication) +The examples can run either on a real device or as native. +In the latter case, just start the executable with enough permissions (e.g. sudo), and you will then be able to reach the node via tun. +A tutorial for setting up the CoAP server example and querying it is provided on the wiki. diff --git a/examples/coap/coap-example-client/Makefile b/examples/coap/coap-example-client/Makefile new file mode 100644 index 000000000..1d3440990 --- /dev/null +++ b/examples/coap/coap-example-client/Makefile @@ -0,0 +1,12 @@ +CONTIKI_PROJECT = coap-example-client +# coap-example-observe-client is outdated but will be ported at a later point +all: $(CONTIKI_PROJECT) + +# Do not try to build on Sky because of code size limitation +PLATFORMS_EXCLUDE = sky + +# Include the CoAP implementation +MODULES += os/net/app-layer/coap + +CONTIKI=../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/coap/coap-example-client.c b/examples/coap/coap-example-client/coap-example-client.c similarity index 98% rename from examples/coap/coap-example-client.c rename to examples/coap/coap-example-client/coap-example-client.c index 3fe261cf7..645283093 100644 --- a/examples/coap/coap-example-client.c +++ b/examples/coap/coap-example-client/coap-example-client.c @@ -51,8 +51,8 @@ /* Log configuration */ #include "coap-log.h" -#define LOG_MODULE "client" -#define LOG_LEVEL LOG_LEVEL_COAP +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_APP /* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */ #define SERVER_EP "coap://[fe80::212:7402:0002:0202]" diff --git a/examples/coap/coap-example-observe-client.c b/examples/coap/coap-example-client/coap-example-observe-client.c similarity index 94% rename from examples/coap/coap-example-observe-client.c rename to examples/coap/coap-example-client/coap-example-observe-client.c index 1dbed0bd4..3b6eb9871 100644 --- a/examples/coap/coap-example-observe-client.c +++ b/examples/coap/coap-example-client/coap-example-observe-client.c @@ -47,15 +47,11 @@ #else #include "dev/button-sensor.h" #endif -/*----------------------------------------------------------------------------*/ -#define DEBUG 0 -#if DEBUG -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINTFLN(format, ...) printf(format "\n", ##__VA_ARGS__) -#else -#define PRINTF(...) -#define PRINTFLN(...) -#endif + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_APP /*----------------------------------------------------------------------------*/ /* FIXME: This server address is hard-coded for Cooja */ @@ -145,8 +141,6 @@ PROCESS_THREAD(er_example_observe_client, ev, data) /* store server address in server_ipaddr */ SERVER_NODE(server_ipaddr); - /* receives all CoAP messages */ - coap_init_engine(); /* init timer and button (if available) */ etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); #if PLATFORM_HAS_BUTTON diff --git a/arch/platform/native/dev/leds-arch.c b/examples/coap/coap-example-client/project-conf.h similarity index 70% rename from arch/platform/native/dev/leds-arch.c rename to examples/coap/coap-example-client/project-conf.h index 07addc84e..7247ea08c 100644 --- a/arch/platform/native/dev/leds-arch.c +++ b/examples/coap/coap-example-client/project-conf.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Swedish Institute of Computer Science. + * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,34 +27,21 @@ * SUCH DAMAGE. * * This file is part of the Contiki operating system. - * */ /** * \file - * A brief description of what this file is. + * Erbium (Er) example project configuration. * \author - * Adam Dunkels + * Matthias Kovatsch */ -#include "dev/leds.h" -static leds_mask_t leds; -/*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - leds = 0; -} -/*---------------------------------------------------------------------------*/ -leds_mask_t -leds_arch_get(void) -{ - return leds; -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(leds_mask_t l) -{ - leds = l; -} -/*---------------------------------------------------------------------------*/ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#define LOG_LEVEL_APP LOG_LEVEL_DBG + +/* Enable client-side support for COAP observe */ +#define COAP_OBSERVE_CLIENT 1 + +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/coap/coap-example-server/Makefile b/examples/coap/coap-example-server/Makefile new file mode 100644 index 000000000..6d9e2db85 --- /dev/null +++ b/examples/coap/coap-example-server/Makefile @@ -0,0 +1,14 @@ +CONTIKI_PROJECT = coap-example-server +all: $(CONTIKI_PROJECT) + +# Do not try to build on Sky because of code size limitation +PLATFORMS_EXCLUDE = sky + +# Include the CoAP implementation +MODULES += os/net/app-layer/coap + +# Include CoAP resources +MODULES_REL += ./resources + +CONTIKI=../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/coap/coap-example-server.c b/examples/coap/coap-example-server/coap-example-server.c similarity index 77% rename from examples/coap/coap-example-server.c rename to examples/coap/coap-example-server/coap-example-server.c index 900662324..f32b743f7 100644 --- a/examples/coap/coap-example-server.c +++ b/examples/coap/coap-example-server/coap-example-server.c @@ -48,14 +48,10 @@ #include "dev/button-sensor.h" #endif -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif - +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_APP /* * Resources to be activated need to be imported through the extern keyword. * The build system automatically compiles the resources in the corresponding sub-directory. @@ -84,17 +80,6 @@ extern coap_resource_t res_battery; #include "dev/temperature-sensor.h" extern coap_resource_t res_temperature; #endif -/* -extern coap_resource_t res_battery; -#endif -#if PLATFORM_HAS_RADIO -extern coap_resource_t res_radio; -#endif -#if PLATFORM_HAS_SHT11 -#include "dev/sht11/sht11-sensor.h" -extern coap_resource_t res_sht11; -#endif -*/ PROCESS(er_example_server, "Erbium Example Server"); AUTOSTART_PROCESSES(&er_example_server); @@ -105,28 +90,23 @@ PROCESS_THREAD(er_example_server, ev, data) PROCESS_PAUSE(); - PRINTF("Starting Erbium Example Server\n"); - - PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); - PRINTF("LL header: %u\n", UIP_LLH_LEN); - PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); - PRINTF("CoAP max chunk: %u\n", COAP_MAX_CHUNK_SIZE); + LOG_INFO("Starting Erbium Example Server\n"); /* * Bind the resources to their Uri-Path. * WARNING: Activating twice only means alternate path, not two instances! * All static variables are the same for each URI path. */ - coap_activate_resource(&res_hello, "test/hello"); - coap_activate_resource(&res_mirror, "debug/mirror"); - coap_activate_resource(&res_chunks, "test/chunks"); - coap_activate_resource(&res_separate, "test/separate"); - coap_activate_resource(&res_push, "test/push"); + coap_activate_resource(&res_hello, "test/hello"); + coap_activate_resource(&res_mirror, "debug/mirror"); + coap_activate_resource(&res_chunks, "test/chunks"); + coap_activate_resource(&res_separate, "test/separate"); + coap_activate_resource(&res_push, "test/push"); #if PLATFORM_HAS_BUTTON - coap_activate_resource(&res_event, "sensors/button"); + coap_activate_resource(&res_event, "sensors/button"); #endif /* PLATFORM_HAS_BUTTON */ - coap_activate_resource(&res_sub, "test/sub"); - coap_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); + coap_activate_resource(&res_sub, "test/sub"); + coap_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); #if PLATFORM_HAS_LEDS /* coap_activate_resource(&res_leds, "actuators/leds"); */ coap_activate_resource(&res_toggle, "actuators/toggle"); @@ -143,15 +123,6 @@ PROCESS_THREAD(er_example_server, ev, data) coap_activate_resource(&res_temperature, "sensors/temperature"); SENSORS_ACTIVATE(temperature_sensor); #endif -/* -#if PLATFORM_HAS_RADIO - coap_activate_resource(&res_radio, "sensors/radio"); -#endif -#if PLATFORM_HAS_SHT11 - coap_activate_resource(&res_sht11, "sensors/sht11"); - SENSORS_ACTIVATE(sht11_sensor); -#endif -*/ /* Define application-specific events here. */ while(1) { @@ -162,7 +133,7 @@ PROCESS_THREAD(er_example_server, ev, data) #else if(ev == sensors_event && data == &button_sensor) { #endif - PRINTF("*******BUTTON*******\n"); + LOG_DBG("*******BUTTON*******\n"); /* Call the event_handler for this application-specific event. */ res_event.trigger(); diff --git a/examples/coap/project-conf.h b/examples/coap/coap-example-server/project-conf.h similarity index 62% rename from examples/coap/project-conf.h rename to examples/coap/coap-example-server/project-conf.h index ff7549358..eeec89082 100644 --- a/examples/coap/project-conf.h +++ b/examples/coap/coap-example-server/project-conf.h @@ -36,33 +36,9 @@ * Matthias Kovatsch */ -#ifndef PROJECT_ERBIUM_CONF_H_ -#define PROJECT_ERBIUM_CONF_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ -/* IP buffer size must match all other hops, in particular the border router. */ -/* #define UIP_CONF_BUFFER_SIZE 256 */ +#define LOG_LEVEL_APP LOG_LEVEL_DBG -/* Increase rpl-border-router IP-buffer when using more than 64. */ -#define COAP_MAX_CHUNK_SIZE 48 - -/* Estimate your header size, especially when using Proxy-Uri. */ -/* #define COAP_MAX_HEADER_SIZE 70 */ - -/* Multiplies with chunk size, be aware of memory constraints. */ -#ifndef COAP_MAX_OPEN_TRANSACTIONS -#define COAP_MAX_OPEN_TRANSACTIONS 4 -#endif /* COAP_MAX_OPEN_TRANSACTIONS */ - -/* Must be <= open transactions, default is COAP_MAX_OPEN_TRANSACTIONS-1. */ -/* #define COAP_MAX_OBSERVERS 2 */ - -/* Filtering .well-known/core per query can be disabled to save space. */ -#define COAP_LINK_FORMAT_FILTERING 0 -#define COAP_PROXY_OPTION_PROCESSING 0 - -/* Enable client-side support for COAP observe */ -#ifndef COAP_OBSERVE_CLIENT -#define COAP_OBSERVE_CLIENT 1 -#endif /* COAP_OBSERVE_CLIENT */ - -#endif /* PROJECT_ERBIUM_CONF_H_ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/coap/resources/res-b1-sep-b2.c b/examples/coap/coap-example-server/resources/res-b1-sep-b2.c similarity index 100% rename from examples/coap/resources/res-b1-sep-b2.c rename to examples/coap/coap-example-server/resources/res-b1-sep-b2.c diff --git a/examples/coap/resources/res-battery.c b/examples/coap/coap-example-server/resources/res-battery.c similarity index 100% rename from examples/coap/resources/res-battery.c rename to examples/coap/coap-example-server/resources/res-battery.c diff --git a/examples/coap/resources/res-chunks.c b/examples/coap/coap-example-server/resources/res-chunks.c similarity index 100% rename from examples/coap/resources/res-chunks.c rename to examples/coap/coap-example-server/resources/res-chunks.c diff --git a/examples/coap/resources/res-event.c b/examples/coap/coap-example-server/resources/res-event.c similarity index 80% rename from examples/coap/resources/res-event.c rename to examples/coap/coap-example-server/resources/res-event.c index 5640353b3..f8f754afa 100644 --- a/examples/coap/resources/res-event.c +++ b/examples/coap/coap-example-server/resources/res-event.c @@ -41,17 +41,10 @@ #include "coap-engine.h" #include "coap.h" -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) -#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5]) -#else -#define PRINTF(...) -#define PRINT6ADDR(addr) -#define PRINTLLADDR(addr) -#endif +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_APP static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_event_handler(void); @@ -94,7 +87,7 @@ res_event_handler(void) /* Usually a condition is defined under with subscribers are notified, e.g., event was above a threshold. */ if(1) { - PRINTF("TICK %u for /%s\n", event_counter, res_event.url); + LOG_DBG("TICK %u for /%s\n", (unsigned)event_counter, res_event.url); /* Notify the registered observers which will trigger the res_get_handler to create the response. */ coap_notify_observers(&res_event); diff --git a/examples/coap/resources/res-hello.c b/examples/coap/coap-example-server/resources/res-hello.c similarity index 96% rename from examples/coap/resources/res-hello.c rename to examples/coap/coap-example-server/resources/res-hello.c index 46b0139ef..914bc28d6 100644 --- a/examples/coap/resources/res-hello.c +++ b/examples/coap/coap-example-server/resources/res-hello.c @@ -75,7 +75,9 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff memcpy(buffer, message, length); } else { memcpy(buffer, message, length); - } coap_set_header_content_format(response, TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */ + } + + coap_set_header_content_format(response, TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */ coap_set_header_etag(response, (uint8_t *)&length, 1); coap_set_payload(response, buffer, length); } diff --git a/examples/coap/resources/res-leds.c b/examples/coap/coap-example-server/resources/res-leds.c similarity index 78% rename from examples/coap/resources/res-leds.c rename to examples/coap/coap-example-server/resources/res-leds.c index d601e49f5..72dbc8b41 100644 --- a/examples/coap/resources/res-leds.c +++ b/examples/coap/coap-example-server/resources/res-leds.c @@ -44,17 +44,10 @@ #if PLATFORM_HAS_LEDS || LEDS_COUNT -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) -#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5]) -#else -#define PRINTF(...) -#define PRINT6ADDR(addr) -#define PRINTLLADDR(addr) -#endif +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_APP static void res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -76,7 +69,7 @@ res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t int success = 1; if((len = coap_get_query_variable(request, "color", &color))) { - PRINTF("color %.*s\n", len, color); + LOG_DBG("color %.*s\n", (int)len, color); if(strncmp(color, "r", len) == 0) { led = LEDS_RED; @@ -90,7 +83,7 @@ res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t } else { success = 0; } if(success && (len = coap_get_post_variable(request, "mode", &mode))) { - PRINTF("mode %s\n", mode); + LOG_DBG("mode %s\n", mode); if(strncmp(mode, "on", len) == 0) { leds_on(led); diff --git a/examples/coap/resources/res-light.c b/examples/coap/coap-example-server/resources/res-light.c similarity index 100% rename from examples/coap/resources/res-light.c rename to examples/coap/coap-example-server/resources/res-light.c diff --git a/examples/coap/resources/res-mirror.c b/examples/coap/coap-example-server/resources/res-mirror.c similarity index 91% rename from examples/coap/resources/res-mirror.c rename to examples/coap/coap-example-server/resources/res-mirror.c index 1ba948b0d..619ed08a7 100644 --- a/examples/coap/resources/res-mirror.c +++ b/examples/coap/coap-example-server/resources/res-mirror.c @@ -41,17 +41,10 @@ #include "coap-engine.h" #include "coap.h" -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) -#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5]) -#else -#define PRINTF(...) -#define PRINT6ADDR(addr) -#define PRINTLLADDR(addr) -#endif +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_APP static void res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -158,7 +151,7 @@ res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff } coap_set_payload(response, buffer, strpos); - PRINTF("/mirror options received: %s\n", buffer); + LOG_DBG("/mirror options received: %s\n", buffer); /* Set dummy header options for response. Like getters, some setters are not implemented for HTTP and have no effect. */ coap_set_header_content_format(response, TEXT_PLAIN); diff --git a/examples/coap/resources/res-push.c b/examples/coap/coap-example-server/resources/res-push.c similarity index 100% rename from examples/coap/resources/res-push.c rename to examples/coap/coap-example-server/resources/res-push.c diff --git a/examples/coap/resources/res-radio.c b/examples/coap/coap-example-server/resources/res-radio.c similarity index 100% rename from examples/coap/resources/res-radio.c rename to examples/coap/coap-example-server/resources/res-radio.c diff --git a/examples/coap/resources/res-separate.c b/examples/coap/coap-example-server/resources/res-separate.c similarity index 100% rename from examples/coap/resources/res-separate.c rename to examples/coap/coap-example-server/resources/res-separate.c diff --git a/examples/coap/resources/res-sht11.c b/examples/coap/coap-example-server/resources/res-sht11.c similarity index 100% rename from examples/coap/resources/res-sht11.c rename to examples/coap/coap-example-server/resources/res-sht11.c diff --git a/examples/coap/resources/res-sub.c b/examples/coap/coap-example-server/resources/res-sub.c similarity index 100% rename from examples/coap/resources/res-sub.c rename to examples/coap/coap-example-server/resources/res-sub.c diff --git a/examples/coap/resources/res-temperature.c b/examples/coap/coap-example-server/resources/res-temperature.c similarity index 100% rename from examples/coap/resources/res-temperature.c rename to examples/coap/coap-example-server/resources/res-temperature.c diff --git a/examples/coap/resources/res-toggle.c b/examples/coap/coap-example-server/resources/res-toggle.c similarity index 100% rename from examples/coap/resources/res-toggle.c rename to examples/coap/coap-example-server/resources/res-toggle.c diff --git a/examples/coap/coap-plugtest-server/Makefile b/examples/coap/coap-plugtest-server/Makefile new file mode 100644 index 000000000..ee3bc511b --- /dev/null +++ b/examples/coap/coap-plugtest-server/Makefile @@ -0,0 +1,14 @@ +CONTIKI_PROJECT = coap-plugtest-server +all: $(CONTIKI_PROJECT) + +# Only intended for native +PLATFORMS_ONLY = native + +# Include the CoAP implementation +MODULES += os/net/app-layer/coap + +# Include CoAP resources +MODULES_REL += ./resources + +CONTIKI=../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/coap/plugtest-server.c b/examples/coap/coap-plugtest-server/coap-plugtest-server.c similarity index 94% rename from examples/coap/plugtest-server.c rename to examples/coap/coap-plugtest-server/coap-plugtest-server.c index 561a70b41..8783ae6dd 100644 --- a/examples/coap/plugtest-server.c +++ b/examples/coap/coap-plugtest-server/coap-plugtest-server.c @@ -45,7 +45,11 @@ #include "coap-transactions.h" #include "coap-separate.h" #include "coap-engine.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST /* * Resources to be activated need to be imported through the extern keyword. @@ -80,12 +84,7 @@ PROCESS_THREAD(plugtest_server, ev, data) { PROCESS_BEGIN(); - PRINTF("ETSI IoT CoAP Plugtests Server\n"); - - PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); - PRINTF("LL header: %u\n", UIP_LLH_LEN); - PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); - PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); + LOG_INFO("ETSI IoT CoAP Plugtests Server\n"); /* Activate the application-specific resources. */ coap_activate_resource(&res_plugtest_test, "test"); diff --git a/examples/coap/plugtest.h b/examples/coap/coap-plugtest-server/project-conf.h similarity index 88% rename from examples/coap/plugtest.h rename to examples/coap/coap-plugtest-server/project-conf.h index dff97282f..5c86ae985 100644 --- a/examples/coap/plugtest.h +++ b/examples/coap/coap-plugtest-server/project-conf.h @@ -36,20 +36,10 @@ * Matthias Kovatsch */ -#ifndef PLUGTEST_H_ -#define PLUGTEST_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ -#if !defined(CONTIKI_TARGET_NATIVE) -#warning "Should only be compiled for native!" -#endif - -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif +#define LOG_LEVEL_PLUGTEST LOG_LEVEL_DBG /* double expansion */ #define TO_STRING2(x) # x @@ -59,4 +49,4 @@ #define MAX_PLUGFEST_BODY 2048 #define CHUNKS_TOTAL 2012 -#endif /* PLUGTEST_H_ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/coap/coap-plugtest-server/resources/res-mirror.c b/examples/coap/coap-plugtest-server/resources/res-mirror.c new file mode 100644 index 000000000..ea9ddd3ad --- /dev/null +++ b/examples/coap/coap-plugtest-server/resources/res-mirror.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +/** + * \file + * Example resource + * \author + * Matthias Kovatsch + */ + +#include +#include +#include "coap-engine.h" +#include "coap.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST + +static void res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); + +/* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */ +RESOURCE(res_mirror, + "title=\"Returns your decoded message\";rt=\"Debug\"", + res_any_handler, + res_any_handler, + res_any_handler, + res_any_handler); + +static void +res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + /* The ETag and Token is copied to the header. */ + uint8_t opaque[] = { 0x0A, 0xBC, 0xDE }; + + /* Strings are not copied, so use static string buffers or strings in .text memory (char *str = "string in .text";). */ + static char location[] = { '/', 'f', '/', 'a', '?', 'k', '&', 'e', 0 }; + + /* No default my be assumed for the Content-Format. (Unsigned -1 means all bits set.) */ + unsigned int content_format = -1; + + /* The other getters copy the value (or string/array pointer) to the given pointers and return 1 for success or the length of strings/arrays. */ + uint32_t longint = 0; + const char *str = NULL; + const uint8_t *bytes = NULL; + uint32_t block_num = 0; + uint8_t block_more = 0; + uint16_t block_size = 0; + int len = 0; + + /* Mirror the received header options in the response payload. Unsupported getters (e.g., rest_get_header_observe() with HTTP) will return 0. */ + + int strpos = 0; + /* snprintf() counts the terminating '\0' to the size parameter. + * The additional byte is taken care of by allocating REST_MAX_CHUNK_SIZE+1 bytes in the REST framework. + * Add +1 to fill the complete buffer, as the payload does not need a terminating '\0'. */ + if(coap_get_header_content_format(request, &content_format)) { + strpos += snprintf((char *)buffer, REST_MAX_CHUNK_SIZE + 1, "CF %u\n", content_format); + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_accept(request, &content_format))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ac %u\n", content_format); + /* Some getters such as for ETag or Location are omitted, as these options should not appear in a request. + * Max-Age might appear in HTTP requests or used for special purposes in CoAP. */ + } + if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_max_age(request, &longint)) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "MA %lu\n", (unsigned long) longint); + /* For HTTP this is the Length option, for CoAP it is the Size option. */ + } + if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_size1(request, &longint)) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "SZ %lu\n", (unsigned long) longint); + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_uri_host(request, &str))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UH %.*s\n", len, str); + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_uri_path(request, &str))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UP %.*s\n", len, str); + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_uri_query(request, &str))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UQ %.*s\n", len, str); + /* Undefined request options for debugging: actions not required for normal RESTful Web service. */ + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_path(request, &str))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LP %.*s\n", len, str); + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_query(request, &str))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LQ %.*s\n", len, str); + /* CoAP-specific example: actions not required for normal RESTful Web service. */ + } + coap_message_t *const coap_pkt = (coap_message_t *)request; + + if(strpos <= REST_MAX_CHUNK_SIZE && coap_pkt->token_len > 0) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "To 0x"); + int index = 0; + for(index = 0; index < coap_pkt->token_len; ++index) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%02X", coap_pkt->token[index]); + } + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "\n"); + } + + if(strpos <= REST_MAX_CHUNK_SIZE && coap_is_option(coap_pkt, COAP_OPTION_OBSERVE)) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ob %lu\n", (unsigned long) coap_pkt->observe); + } + if(strpos <= REST_MAX_CHUNK_SIZE && coap_is_option(coap_pkt, COAP_OPTION_ETAG)) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "ET 0x"); + int index = 0; + for(index = 0; index < coap_pkt->etag_len; ++index) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%02X", coap_pkt->etag[index]); + } + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "\n"); + } + if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_block2(request, &block_num, &block_more, &block_size, NULL)) { /* This getter allows NULL pointers to get only a subset of the block parameters. */ + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "B2 %lu%s (%u)\n", (unsigned long) block_num, block_more ? "+" : "", block_size); + } + if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_block1(request, &block_num, &block_more, &block_size, NULL)) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "B1 %lu%s (%u)\n", (unsigned long) block_num, block_more ? "+" : "", block_size); + } + if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_payload(request, &bytes))) { + strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%.*s", len, bytes); + } + if(strpos >= REST_MAX_CHUNK_SIZE) { + buffer[REST_MAX_CHUNK_SIZE - 1] = 0xBB; /* '»' to indicate truncation */ + } + coap_set_payload(response, buffer, strpos); + + LOG_DBG("/mirror options received: %s\n", buffer); + + /* Set dummy header options for response. Like getters, some setters are not implemented for HTTP and have no effect. */ + coap_set_header_content_format(response, TEXT_PLAIN); + coap_set_header_max_age(response, 17); /* For HTTP, browsers will not re-request the page for 17 seconds. */ + coap_set_header_etag(response, opaque, 2); + coap_set_header_location_path(response, location); /* Initial slash is omitted by framework */ + coap_set_header_size1(response, strpos); /* For HTTP, browsers will not re-request the page for 10 s. CoAP action depends on the client. */ + +/* CoAP-specific example: actions not required for normal RESTful Web service. */ + coap_set_header_uri_host(response, "tiki"); + coap_set_header_observe(response, 10); + coap_set_header_proxy_uri(response, "ftp://x"); + coap_set_header_block2(response, 42, 0, 64); /* The block option might be overwritten by the framework when blockwise transfer is requested. */ + coap_set_header_block1(response, 23, 0, 16); + coap_set_header_accept(response, TEXT_PLAIN); + coap_set_header_if_none_match(response); +} diff --git a/examples/coap/resources-plugtest/res-plugtest-create1.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-create1.c similarity index 94% rename from examples/coap/resources-plugtest/res-plugtest-create1.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-create1.c index 50f48a09e..fe57e4961 100644 --- a/examples/coap/resources-plugtest/res-plugtest-create1.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-create1.c @@ -39,7 +39,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -56,7 +60,7 @@ static uint8_t create1_exists = 0; static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - PRINTF("/create1 PUT"); + LOG_DBG("/create1 PUT"); if(coap_get_header_if_none_match(request)) { if(!create1_exists) { @@ -73,7 +77,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - PRINTF("/create1 DELETE "); + LOG_DBG("/create1 DELETE "); coap_set_status_code(response, DELETED_2_02); create1_exists = 0; diff --git a/examples/coap/resources-plugtest/res-plugtest-create2.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-create2.c similarity index 94% rename from examples/coap/resources-plugtest/res-plugtest-create2.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-create2.c index 169f47812..b4520d672 100644 --- a/examples/coap/resources-plugtest/res-plugtest-create2.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-create2.c @@ -39,7 +39,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -53,7 +57,7 @@ RESOURCE(res_plugtest_create2, static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - PRINTF("/create2 "); + LOG_DBG("/create2 "); coap_set_status_code(response, CREATED_2_01); coap_set_header_location_path(response, "/location1/location2/location3"); diff --git a/examples/coap/resources-plugtest/res-plugtest-create3.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-create3.c similarity index 94% rename from examples/coap/resources-plugtest/res-plugtest-create3.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-create3.c index 178a0089e..b78fca67e 100644 --- a/examples/coap/resources-plugtest/res-plugtest-create3.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-create3.c @@ -39,7 +39,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -56,7 +60,7 @@ static uint8_t create3_exists = 0; static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - PRINTF("/create3 PUT "); + LOG_DBG("/create3 PUT "); if(coap_get_header_if_none_match(request)) { if(!create3_exists) { @@ -73,7 +77,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - PRINTF("/create3 DELETE "); + LOG_DBG("/create3 DELETE "); coap_set_status_code(response, DELETED_2_02); create3_exists = 0; diff --git a/examples/coap/resources-plugtest/res-plugtest-large-create.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-large-create.c similarity index 96% rename from examples/coap/resources-plugtest/res-plugtest-large-create.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-large-create.c index 78d21b69b..923702f51 100644 --- a/examples/coap/resources-plugtest/res-plugtest-large-create.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-large-create.c @@ -39,7 +39,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); diff --git a/examples/coap/resources-plugtest/res-plugtest-large-update.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-large-update.c similarity index 97% rename from examples/coap/resources-plugtest/res-plugtest-large-update.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-large-update.c index a79978be1..289fbdfdf 100644 --- a/examples/coap/resources-plugtest/res-plugtest-large-update.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-large-update.c @@ -41,7 +41,11 @@ #include "sys/cc.h" #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); diff --git a/examples/coap/resources-plugtest/res-plugtest-large.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-large.c similarity index 96% rename from examples/coap/resources-plugtest/res-plugtest-large.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-large.c index f828e4dbe..850f88461 100644 --- a/examples/coap/resources-plugtest/res-plugtest-large.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-large.c @@ -40,7 +40,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); diff --git a/examples/coap/resources-plugtest/res-plugtest-links.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-links.c similarity index 95% rename from examples/coap/resources-plugtest/res-plugtest-links.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-links.c index 99315a17f..3bbd2a062 100644 --- a/examples/coap/resources-plugtest/res-plugtest-links.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-links.c @@ -39,7 +39,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); diff --git a/examples/coap/resources-plugtest/res-plugtest-locquery.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-locquery.c similarity index 95% rename from examples/coap/resources-plugtest/res-plugtest-locquery.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-locquery.c index e93ef8b65..e7163e8b1 100644 --- a/examples/coap/resources-plugtest/res-plugtest-locquery.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-locquery.c @@ -39,7 +39,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -53,11 +57,9 @@ RESOURCE(res_plugtest_locquery, static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { -#if DEBUG coap_message_t *const coap_req = (coap_message_t *)request; -#endif - PRINTF( + LOG_DBG( "/location-query POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); coap_set_status_code(response, CREATED_2_01); diff --git a/examples/coap/resources-plugtest/res-plugtest-longpath.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-longpath.c similarity index 91% rename from examples/coap/resources-plugtest/res-plugtest-longpath.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-longpath.c index 7a1271321..990ad2677 100644 --- a/examples/coap/resources-plugtest/res-plugtest-longpath.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-longpath.c @@ -41,7 +41,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -57,7 +61,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff { coap_message_t *const coap_req = (coap_message_t *)request; - PRINTF("/seg1/seg2/seg3 GET "); + LOG_DBG("/seg1/seg2/seg3 GET "); /* Code 2.05 CONTENT is default. */ coap_set_header_content_format(response, TEXT_PLAIN); coap_set_payload( @@ -66,5 +70,5 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid)); - PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); } diff --git a/examples/coap/resources-plugtest/res-plugtest-multi.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-multi.c similarity index 91% rename from examples/coap/resources-plugtest/res-plugtest-multi.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-multi.c index f0a388430..9606d91a6 100644 --- a/examples/coap/resources-plugtest/res-plugtest-multi.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-multi.c @@ -40,7 +40,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -59,7 +63,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff unsigned int accept = -1; coap_get_header_accept(request, &accept); - PRINTF("/multi-format GET (%s %u) ", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + LOG_DBG("/multi-format GET (%s %u) ", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); if(accept == -1 || accept == TEXT_PLAIN) { coap_set_header_content_format(response, TEXT_PLAIN); @@ -69,7 +73,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u%s", coap_req->type, coap_req->code, coap_req->mid, accept != -1 ? "\nAccept: 0" : "")); - PRINTF("PLAIN\n"); + LOG_DBG_("PLAIN\n"); } else if(accept == APPLICATION_XML) { coap_set_header_content_format(response, APPLICATION_XML); coap_set_payload( @@ -78,11 +82,11 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "", coap_req->type, coap_req->code, coap_req->mid, accept)); - PRINTF("XML\n"); + LOG_DBG_("XML\n"); } else { coap_set_status_code(response, NOT_ACCEPTABLE_4_06); const char *msg = "Supporting content-types text/plain and application/xml"; coap_set_payload(response, msg, strlen(msg)); - PRINTF("ERROR\n"); + LOG_DBG_("ERROR\n"); } } diff --git a/examples/coap/resources-plugtest/res-plugtest-obs.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c similarity index 94% rename from examples/coap/resources-plugtest/res-plugtest-obs.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c index d60aaec04..7d191e751 100644 --- a/examples/coap/resources-plugtest/res-plugtest-obs.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c @@ -41,7 +41,11 @@ #include "coap-engine.h" #include "coap.h" #include "coap-observe.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -67,7 +71,7 @@ static char obs_status = 0; static void obs_purge_list() { - PRINTF("### SERVER ACTION ### Purging obs list"); + LOG_DBG("### SERVER ACTION ### Purging obs list\n"); coap_remove_observer_by_uri(NULL, res_plugtest_obs.url); } static void @@ -75,7 +79,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff { /* Keep server log clean from ticking events */ if(request != NULL) { - PRINTF("/obs GET\n"); + LOG_DBG("/obs GET\n"); } coap_set_header_content_format(response, obs_format); coap_set_header_max_age(response, 5); @@ -98,7 +102,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff coap_get_header_content_format(request, &ct); - PRINTF("/obs PUT\n"); + LOG_DBG("/obs PUT\n"); if(ct != obs_format) { obs_status = 1; @@ -115,7 +119,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - PRINTF("/obs DELETE\n"); + LOG_DBG("/obs DELETE\n"); obs_status = 2; @@ -130,14 +134,12 @@ res_periodic_handler() { ++obs_counter; - /* PRINTF("TICK %u for /%s\n", obs_counter, r->url); */ - if(obs_status == 1) { /* Notify the registered observers with the given message type, observe option, and payload. */ coap_notify_observers(&res_plugtest_obs); - PRINTF("######### sending 5.00\n"); + LOG_DBG("######### sending 5.00\n"); obs_purge_list(); } else if(obs_status == 2) { diff --git a/examples/coap/resources-plugtest/res-plugtest-path.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-path.c similarity index 96% rename from examples/coap/resources-plugtest/res-plugtest-path.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-path.c index fac05ccb0..767609f09 100644 --- a/examples/coap/resources-plugtest/res-plugtest-path.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-path.c @@ -40,7 +40,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); diff --git a/examples/coap/resources-plugtest/res-plugtest-query.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-query.c similarity index 94% rename from examples/coap/resources-plugtest/res-plugtest-query.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-query.c index 10df145b3..1080d3162 100644 --- a/examples/coap/resources-plugtest/res-plugtest-query.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-query.c @@ -40,7 +40,11 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -58,11 +62,11 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff int len = 0; const char *query = NULL; - PRINTF( + LOG_DBG( "/query GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); if((len = coap_get_header_uri_query(request, &query))) { - PRINTF("Query: %.*s\n", len, query); + LOG_DBG("Query: %.*s\n", len, query); /* Code 2.05 CONTENT is default. */ } coap_set_header_content_format(response, diff --git a/examples/coap/resources-plugtest/res-plugtest-separate.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c similarity index 93% rename from examples/coap/resources-plugtest/res-plugtest-separate.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c index 16aa267ce..c0ae81d11 100644 --- a/examples/coap/resources-plugtest/res-plugtest-separate.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c @@ -42,7 +42,11 @@ #include "coap.h" #include "coap-transactions.h" #include "coap-separate.h" -#include "plugtest.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_resume_handler(void); @@ -72,12 +76,12 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff { coap_message_t *const coap_req = (coap_message_t *)request; - PRINTF("/separate "); + LOG_DBG("/separate "); if(separate_active) { - PRINTF("REJECTED "); + LOG_DBG_("REJECTED "); coap_separate_reject(); } else { - PRINTF("STORED "); + LOG_DBG_("STORED "); separate_active = 1; /* Take over and skip response by engine. */ @@ -89,17 +93,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff coap_req->mid); } - PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); } static void res_resume_handler() { if(separate_active) { - PRINTF("/separate "); + LOG_DBG("/separate "); coap_transaction_t *transaction = NULL; if((transaction = coap_new_transaction(separate_store->request_metadata.mid, &separate_store->request_metadata.endpoint))) { - PRINTF( + LOG_DBG_( "RESPONSE (%s %u)\n", separate_store->request_metadata.type == COAP_TYPE_CON ? "CON" : "NON", separate_store->request_metadata.mid); coap_message_t response[1]; /* This way the message can be treated as pointer as usual. */ @@ -127,7 +131,7 @@ res_resume_handler() separate_active = 0; } else { - PRINTF("ERROR (transaction)\n"); + LOG_DBG_("ERROR (transaction)\n"); } } /* if (separate_active) */ } diff --git a/examples/coap/resources-plugtest/res-plugtest-test.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-test.c similarity index 81% rename from examples/coap/resources-plugtest/res-plugtest-test.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-test.c index f7ac97c83..d02b3026d 100644 --- a/examples/coap/resources-plugtest/res-plugtest-test.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-test.c @@ -40,9 +40,13 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" #include "random.h" +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST + static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -68,7 +72,7 @@ test_update_etag() } test_change = 0; - PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]); + LOG_DBG("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]); } static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) @@ -78,17 +82,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff if(test_change) { test_update_etag(); } - PRINTF("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + LOG_DBG("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); if((len = coap_get_header_etag(request, &bytes)) > 0 && len == test_etag_len && memcmp(test_etag, bytes, len) == 0) { - PRINTF("validate "); + LOG_DBG("validate\n"); coap_set_status_code(response, VALID_2_03); coap_set_header_etag(response, test_etag, test_etag_len); test_change = 1; - PRINTF("### SERVER ACTION ### Resource will change\n"); + LOG_DBG("### SERVER ACTION ### Resource will change\n"); } else { /* Code 2.05 CONTENT is default. */ coap_set_header_content_format(response, TEXT_PLAIN); @@ -103,32 +107,28 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { -#if DEBUG - coap_message_t *const coap_req = (coap_message_t *)request; - PRINTF("/test POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); -#endif + coap_message_t *const coap_req = (coap_message_t *)request; + LOG_DBG("/test POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); coap_set_status_code(response, CREATED_2_01); coap_set_header_location_path(response, "/location1/location2/location3"); } static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { -#if DEBUG coap_message_t *const coap_req = (coap_message_t *)request; - PRINTF("/test PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); -#endif + LOG_DBG("/test PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); if(coap_get_header_if_none_match(request)) { if(test_none_match_okay) { coap_set_status_code(response, CREATED_2_01); test_none_match_okay = 0; - PRINTF("### SERVER ACTION ### If-None-Match will FAIL\n"); + LOG_DBG("### SERVER ACTION ### If-None-Match will FAIL\n"); } else { coap_set_status_code(response, PRECONDITION_FAILED_4_12); test_none_match_okay = 1; - PRINTF("### SERVER ACTION ### If-None-Match will SUCCEED\n"); + LOG_DBG("### SERVER ACTION ### If-None-Match will SUCCEED\n"); } } else if(((len = coap_get_header_if_match(request, &bytes)) > 0 && (len == test_etag_len @@ -141,12 +141,12 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff if(len > 0) { test_change = 1; - PRINTF("### SERVER ACTION ### Resource will change\n"); + LOG_DBG("### SERVER ACTION ### Resource will change\n"); } } else { - PRINTF("Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", - len, - test_etag_len, + LOG_DBG("Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", + (unsigned)len, + (unsigned)test_etag_len, bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]); @@ -156,9 +156,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { -#if DEBUG coap_message_t *const coap_req = (coap_message_t *)request; - PRINTF("/test DELETE (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); -#endif + LOG_DBG("/test DELETE (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); coap_set_status_code(response, DELETED_2_02); } diff --git a/examples/coap/resources-plugtest/res-plugtest-validate.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-validate.c similarity index 87% rename from examples/coap/resources-plugtest/res-plugtest-validate.c rename to examples/coap/coap-plugtest-server/resources/res-plugtest-validate.c index 30d97e727..7a5920c2b 100644 --- a/examples/coap/resources-plugtest/res-plugtest-validate.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-validate.c @@ -40,9 +40,13 @@ #include #include "coap-engine.h" #include "coap.h" -#include "plugtest.h" #include "random.h" +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Plugtest" +#define LOG_LEVEL LOG_LEVEL_PLUGTEST + static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); @@ -70,7 +74,7 @@ validate_update_etag() } validate_change = 0; - PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", + LOG_DBG("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", validate_etag_len, validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]); } static void @@ -81,17 +85,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff if(validate_change) { validate_update_etag(); } - PRINTF("/validate GET"); - PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + LOG_DBG("/validate GET"); + LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); if((len = coap_get_header_etag(request, &bytes)) > 0 && len == validate_etag_len && memcmp(validate_etag, bytes, len) == 0) { - PRINTF("validate "); + LOG_DBG("validate\n"); coap_set_status_code(response, VALID_2_03); coap_set_header_etag(response, validate_etag, validate_etag_len); validate_change = 1; - PRINTF("### SERVER ACTION ### Resouce will change\n"); + LOG_DBG("### SERVER ACTION ### Resouce will change\n"); } else { /* Code 2.05 CONTENT is default. */ coap_set_header_content_format(response, TEXT_PLAIN); @@ -108,12 +112,10 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { -#if DEBUG coap_message_t *const coap_req = (coap_message_t *)request; -#endif - PRINTF("/validate PUT "); - PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + LOG_DBG("/validate PUT "); + LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); if(((len = coap_get_header_if_match(request, &bytes)) > 0 && (len == validate_etag_len @@ -126,13 +128,13 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff if(len > 0) { validate_change = 1; - PRINTF("### SERVER ACTION ### Resouce will change\n"); + LOG_DBG("### SERVER ACTION ### Resouce will change\n"); } } else { - PRINTF( - "Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X] ", - len, - validate_etag_len, + LOG_DBG( + "Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", + (unsigned)len, + (unsigned)validate_etag_len, bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]); diff --git a/examples/dev/button-hal/Makefile b/examples/dev/button-hal/Makefile index 071ec02ec..0c209918c 100644 --- a/examples/dev/button-hal/Makefile +++ b/examples/dev/button-hal/Makefile @@ -3,6 +3,6 @@ CONTIKI = ../../.. all: $(CONTIKI_PROJECT) -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul +PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native include $(CONTIKI)/Makefile.include diff --git a/examples/dev/button-hal/button-hal-example.c b/examples/dev/button-hal/button-hal-example.c index b4d584e3e..db34b86af 100644 --- a/examples/dev/button-hal/button-hal-example.c +++ b/examples/dev/button-hal/button-hal-example.c @@ -47,10 +47,13 @@ PROCESS_THREAD(button_hal_example, ev, data) printf("Button HAL example.\n"); printf("Device button count: %u.\n", button_hal_button_count); - printf("%s on pin %u with ID=0, Logic=%s, Pull=%s\n", - BUTTON_HAL_GET_DESCRIPTION(btn), btn->pin, - btn->negative_logic ? "Negative" : "Positive", - btn->pull == GPIO_HAL_PIN_CFG_PULL_UP ? "Pull Up" : "Pull Down"); + + if(btn) { + printf("%s on pin %u with ID=0, Logic=%s, Pull=%s\n", + BUTTON_HAL_GET_DESCRIPTION(btn), btn->pin, + btn->negative_logic ? "Negative" : "Positive", + btn->pull == GPIO_HAL_PIN_CFG_PULL_UP ? "Pull Up" : "Pull Down"); + } while(1) { diff --git a/examples/dev/gpio-hal/Makefile b/examples/dev/gpio-hal/Makefile index efbdf6e05..016f53377 100644 --- a/examples/dev/gpio-hal/Makefile +++ b/examples/dev/gpio-hal/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = gpio-hal-example CONTIKI = ../../.. -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul +PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native include $(CONTIKI)/Makefile.identify-target diff --git a/examples/dev/gpio-hal/gpio-hal-example.c b/examples/dev/gpio-hal/gpio-hal-example.c index 040df3b38..380c06388 100644 --- a/examples/dev/gpio-hal/gpio-hal-example.c +++ b/examples/dev/gpio-hal/gpio-hal-example.c @@ -36,6 +36,7 @@ #include "dev/button-hal.h" #include +#include /*---------------------------------------------------------------------------*/ extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3; extern gpio_hal_pin_t btn_pin; @@ -43,6 +44,13 @@ extern gpio_hal_pin_t btn_pin; static struct etimer et; static uint8_t counter; /*---------------------------------------------------------------------------*/ +/* Print gpio_hal_pin_mask_t using the correct format */ +#if GPIO_HAL_PIN_COUNT > 32 +#define PIN_MASK_FMT PRIx64 +#else +#define PIN_MASK_FMT PRIx32 +#endif +/*---------------------------------------------------------------------------*/ PROCESS(gpio_hal_example, "GPIO HAL Example"); AUTOSTART_PROCESSES(&gpio_hal_example); /*---------------------------------------------------------------------------*/ @@ -119,7 +127,8 @@ PROCESS_THREAD(gpio_hal_example, ev, data) } /* Test read */ - printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08lx\n", counter & 7, + printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08" PIN_MASK_FMT "\n", + counter & 7, gpio_hal_arch_read_pin(out_pin1), gpio_hal_arch_read_pin(out_pin2), gpio_hal_arch_read_pin(out_pin3), diff --git a/examples/dev/gpio-hal/native/pins.c b/examples/dev/gpio-hal/native/pins.c new file mode 100644 index 000000000..10472b78a --- /dev/null +++ b/examples/dev/gpio-hal/native/pins.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_t out_pin1 = 0; +gpio_hal_pin_t out_pin2 = 1; +gpio_hal_pin_t out_pin3 = 2; +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_t btn_pin = 4; +/*---------------------------------------------------------------------------*/ diff --git a/examples/ipso-objects/README.md b/examples/ipso-objects/README.md deleted file mode 100644 index e9be82dcb..000000000 --- a/examples/ipso-objects/README.md +++ /dev/null @@ -1,48 +0,0 @@ -IPSO Objects Example -============================================ - -This is an example of how to make use of the IPSO Object and LWM2M -implementation in Contiki. - -The LWM2M implementation is based on the Erbium CoAP implementation -and consists of two apps: lwm2m-engine and ipso-objects. The -lwm2m-engine handle the specifics of LWM2M including bootstrapping and -how read/writes of objects and resources are handled. The ipso-objects -contains implementations of some of the IPSO Smart Objects. - -The implementation was used during the IPSO Interop in May 2015, -Kista, Sweden, and was successfully tested with other -implementations. - -The examples use some of the basic IPSO object for controlling LEDs on -Contiki devices and for reading out temperature. - -##Testing IPSO-objects with Leshan - -First program a device with the examples/ipso-objects/example-ipso-objects.c - -```bash ->make example-ipso-objects.upload TARGET=zoul ->... -``` - -After that start up a native-border router or other border router on fd00::1/64 -or another prefix - NOTE: if you use another prefix you will need to change LWM2M_SERVER_ADDRESS for which the device will register - in project-conf.h: -``` -#define LWM2M_SERVER_ADDRESS "fd00::1" -``` - -Then when everything is setup you can download a Leshan and use that to -test controlling LEDs of the device. - -###Starting Leshan -```bash -wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-standalone.jar -java -jar ./leshan-standalone.jar -``` -Browse to leshans device page with http://127.0.0.1:8080 . - -When you have started the border-router and also Leshan you should now -start (or reboot) your IPSO Object enabled device. Within 30 seconds -you should be able to see it on the Leshan device page. - diff --git a/examples/ipv6-hooks/Makefile b/examples/libs/ipv6-hooks/Makefile similarity index 84% rename from examples/ipv6-hooks/Makefile rename to examples/libs/ipv6-hooks/Makefile index be8cc953e..63085face 100644 --- a/examples/ipv6-hooks/Makefile +++ b/examples/libs/ipv6-hooks/Makefile @@ -1,5 +1,5 @@ CONTIKI_PROJECT = ipv6-hooks all: $(CONTIKI_PROJECT) -CONTIKI=../.. +CONTIKI=../../.. include $(CONTIKI)/Makefile.include diff --git a/examples/ipv6-hooks/README.md b/examples/libs/ipv6-hooks/README.md similarity index 100% rename from examples/ipv6-hooks/README.md rename to examples/libs/ipv6-hooks/README.md diff --git a/examples/ipv6-hooks/ipv6-hooks.c b/examples/libs/ipv6-hooks/ipv6-hooks.c similarity index 100% rename from examples/ipv6-hooks/ipv6-hooks.c rename to examples/libs/ipv6-hooks/ipv6-hooks.c diff --git a/examples/libs/stack-check/project-conf.h b/examples/libs/stack-check/project-conf.h index 2509dd080..a9cbe2265 100644 --- a/examples/libs/stack-check/project-conf.h +++ b/examples/libs/stack-check/project-conf.h @@ -36,9 +36,9 @@ * */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define STACK_CHECK_CONF_ENABLED 1 -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/ipso-objects/Makefile b/examples/lwm2m-ipso-objects/Makefile similarity index 100% rename from examples/ipso-objects/Makefile rename to examples/lwm2m-ipso-objects/Makefile diff --git a/examples/lwm2m-ipso-objects/README.md b/examples/lwm2m-ipso-objects/README.md new file mode 100644 index 000000000..30cc5832f --- /dev/null +++ b/examples/lwm2m-ipso-objects/README.md @@ -0,0 +1,10 @@ +LWM2M with IPSO Objects Example +============================================ + +This is an OMA LWM2M example implementing IPSO Objects. +It can connect to a Leshan server out-of-the-box. +Important configuration paramters: +* `LWM2M_SERVER_ADDRESS`: the address of the server to register to (or bosstrap from) +* `REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER`: set to bootstrap via `LWM2M_SERVER_ADDRESS` and then obtain the registration server address + +A tutorial for setting up this example is provided on the wiki. diff --git a/examples/ipso-objects/example-ipso-objects.c b/examples/lwm2m-ipso-objects/example-ipso-objects.c similarity index 100% rename from examples/ipso-objects/example-ipso-objects.c rename to examples/lwm2m-ipso-objects/example-ipso-objects.c diff --git a/examples/ipso-objects/example-ipso-temperature.c b/examples/lwm2m-ipso-objects/example-ipso-temperature.c similarity index 100% rename from examples/ipso-objects/example-ipso-temperature.c rename to examples/lwm2m-ipso-objects/example-ipso-temperature.c diff --git a/examples/ipso-objects/example-server.c b/examples/lwm2m-ipso-objects/example-server.c similarity index 100% rename from examples/ipso-objects/example-server.c rename to examples/lwm2m-ipso-objects/example-server.c diff --git a/examples/ipso-objects/project-conf.h b/examples/lwm2m-ipso-objects/project-conf.h similarity index 100% rename from examples/ipso-objects/project-conf.h rename to examples/lwm2m-ipso-objects/project-conf.h diff --git a/examples/ipso-objects/serial-protocol.c b/examples/lwm2m-ipso-objects/serial-protocol.c similarity index 100% rename from examples/ipso-objects/serial-protocol.c rename to examples/lwm2m-ipso-objects/serial-protocol.c diff --git a/examples/ipso-objects/serial-protocol.h b/examples/lwm2m-ipso-objects/serial-protocol.h similarity index 100% rename from examples/ipso-objects/serial-protocol.h rename to examples/lwm2m-ipso-objects/serial-protocol.h diff --git a/examples/mqtt-client/Makefile b/examples/mqtt-client/Makefile index c4741bec9..d315cfea3 100644 --- a/examples/mqtt-client/Makefile +++ b/examples/mqtt-client/Makefile @@ -8,6 +8,6 @@ CONTIKI = ../.. MODULES_REL += arch/platform/$(TARGET) -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul +PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/cc26xx/ble-ipv6/README.md b/examples/platform-specific/cc26xx/ble-ipv6/README.md index d72ab752d..d33c7329f 100644 --- a/examples/platform-specific/cc26xx/ble-ipv6/README.md +++ b/examples/platform-specific/cc26xx/ble-ipv6/README.md @@ -6,7 +6,7 @@ can be exchanged using BLE connections (IPv6 over BLE). This Contiki extenstion implements [BLEach][bleachWeb], a fully open-source IPv6-over-BLE stack for Contiki. BLEach in Contiki-NG can be used for node (BLE slave) devices. -It was developed by +It was developed by * [Michael Spoerk](http://www.michaelspoerk.com), Graz University of Technology, michael.spoerk@tugraz.at, github user: [spoerk](https://github.com/spoerk) This IPv6-over-BLE stack is presented and evaluated in the paper: @@ -21,7 +21,7 @@ This implementation includes: * BLE link layer support for version [4.1][bleSpec]: * BLE advertisement * BLE connection slave - + It has been tested on the TI CC2650 SensorTag and the TI CC2650 LaunchPad hardware. ## Modules @@ -78,4 +78,3 @@ specifies the used advertisement interval in milliseconds. [rfc7668]: https://tools.ietf.org/html/rfc7668 [bleSpec]: https://www.bluetooth.com/specifications/bluetooth-core-specification/legacy-specifications [bleachWeb]: http://www.iti.tugraz.at/BLEach - diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile b/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile index 3ddf9671b..05dbface1 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile @@ -5,9 +5,14 @@ PLATFORMS_ONLY = srf06-cc26xx MODULES_REL += ./resources -PROJECT_SOURCEFILES += cetic-6lbr-client.c coap-server.c net-uart.c mqtt-client.c +PROJECT_SOURCEFILES += coap-server.c net-uart.c mqtt-client.c PROJECT_SOURCEFILES += httpd-simple.c +ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_CLASSIC) +# 6lbr only supports RPL Classic +PROJECT_SOURCEFILES += cetic-6lbr-client.c +endif + # REST Engine shall use Erbium CoAP implementation MODULES += os/net/app-layer/mqtt MODULES += os/net/app-layer/coap diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c b/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c index d3042bf81..569a36a89 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c @@ -37,10 +37,11 @@ #include "contiki-net.h" #include "net/routing/routing.h" #include "net/ipv6/uip.h" -#if ROUTING_CONF_RPL_LITE -#include "net/routing/rpl-lite/rpl.h" -#elif ROUTING_CONF_RPL_CLASSIC +#if ROUTING_CONF_RPL_CLASSIC #include "net/routing/rpl-classic/rpl.h" +#include "net/routing/rpl-classic/rpl-private.h" +#else +#error The 6LBR client is only meant for RPL Classic. Set MAKE_ROUTING accordingly. #endif #include @@ -160,8 +161,8 @@ timeout_handler(void) PRINT6ADDR(&client_conn->ripaddr); i = sprintf(buf, "%d | ", ++seq_id); instance = rpl_get_default_instance(); - if(instance && instance->dag.preferred_parent) { - add_ipaddr(buf + i, rpl_parent_get_ipaddr(instance->dag.preferred_parent)); + if(instance && instance->current_dag->preferred_parent) { + add_ipaddr(buf + i, rpl_parent_get_ipaddr(instance->current_dag->preferred_parent)); } else { sprintf(buf + i, "(null)"); } diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h b/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h index c69ceb209..2463a9e8f 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h @@ -42,7 +42,7 @@ /* Enable/Disable Components of this Demo */ #define CC26XX_WEB_DEMO_CONF_MQTT_CLIENT 1 -#define CC26XX_WEB_DEMO_CONF_6LBR_CLIENT 1 +#define CC26XX_WEB_DEMO_CONF_6LBR_CLIENT ROUTING_CONF_RPL_CLASSIC #define CC26XX_WEB_DEMO_CONF_COAP_SERVER 1 #define CC26XX_WEB_DEMO_CONF_NET_UART 1 diff --git a/examples/platform-specific/jn516x/rpl/coap-dongle-node/project-conf.h b/examples/platform-specific/jn516x/rpl/coap-dongle-node/project-conf.h index a46f32f1c..bb7d4d785 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dongle-node/project-conf.h +++ b/examples/platform-specific/jn516x/rpl/coap-dongle-node/project-conf.h @@ -31,11 +31,11 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_TCP 0 #include "../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/project-conf.h b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/project-conf.h index a46f32f1c..bb7d4d785 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/project-conf.h +++ b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/project-conf.h @@ -31,11 +31,11 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_TCP 0 #include "../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/project-conf.h b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/project-conf.h index a46f32f1c..bb7d4d785 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/project-conf.h +++ b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/project-conf.h @@ -31,11 +31,11 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_TCP 0 #include "../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/rpl/node/project-conf.h b/examples/platform-specific/jn516x/rpl/node/project-conf.h index 9db6f0229..52adee3b9 100644 --- a/examples/platform-specific/jn516x/rpl/node/project-conf.h +++ b/examples/platform-specific/jn516x/rpl/node/project-conf.h @@ -32,9 +32,9 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #include "../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/project-conf.h b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/project-conf.h index 360fdef25..65ddcef46 100644 --- a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/project-conf.h +++ b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/project-conf.h @@ -32,12 +32,12 @@ * */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_TCP 0 #define UART_BAUD_RATE UART_RATE_115200 #include "../../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/project-conf.h b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/project-conf.h index 0394b0ad5..94e17dc1c 100644 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/project-conf.h +++ b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/project-conf.h @@ -31,12 +31,12 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_TCP 0 #define UART_BAUD_RATE UART_RATE_115200 #include "../../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/tsch/uart1-test-node/project-conf.h b/examples/platform-specific/jn516x/tsch/uart1-test-node/project-conf.h index 373ea0f27..d833869bb 100644 --- a/examples/platform-specific/jn516x/tsch/uart1-test-node/project-conf.h +++ b/examples/platform-specific/jn516x/tsch/uart1-test-node/project-conf.h @@ -31,8 +31,8 @@ * \author Simon Duquennoy */ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UIP_CONF_TCP 0 @@ -46,4 +46,4 @@ #include "../common-conf.h" -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/http-socket/Makefile b/examples/websocket/Makefile similarity index 100% rename from examples/http-socket/Makefile rename to examples/websocket/Makefile diff --git a/examples/http-socket/http-example.c b/examples/websocket/http-example.c similarity index 100% rename from examples/http-socket/http-example.c rename to examples/websocket/http-example.c diff --git a/examples/http-socket/project-conf.h b/examples/websocket/project-conf.h similarity index 100% rename from examples/http-socket/project-conf.h rename to examples/websocket/project-conf.h diff --git a/examples/http-socket/websocket-example.c b/examples/websocket/websocket-example.c similarity index 100% rename from examples/http-socket/websocket-example.c rename to examples/websocket/websocket-example.c diff --git a/examples/http-socket/websocket-node/Makefile b/examples/websocket/websocket-node/Makefile similarity index 100% rename from examples/http-socket/websocket-node/Makefile rename to examples/websocket/websocket-node/Makefile diff --git a/examples/http-socket/websocket-node/example-server.js b/examples/websocket/websocket-node/example-server.js similarity index 100% rename from examples/http-socket/websocket-node/example-server.js rename to examples/websocket/websocket-node/example-server.js diff --git a/os/lib/dbg-io/strformat.h b/os/lib/dbg-io/strformat.h index 62d99b303..478fb7af7 100644 --- a/os/lib/dbg-io/strformat.h +++ b/os/lib/dbg-io/strformat.h @@ -53,7 +53,7 @@ typedef struct strformat_context_s { /*---------------------------------------------------------------------------*/ int format_str(const strformat_context_t *ctxt, const char *format, ...) __attribute__ ((__format__ (__printf__, 2,3))); - + int format_str_v(const strformat_context_t *ctxt, const char *format, va_list ap); /*---------------------------------------------------------------------------*/ diff --git a/os/net/app-layer/coap/coap-engine.c b/os/net/app-layer/coap/coap-engine.c index 816393ec0..474826c1c 100644 --- a/os/net/app-layer/coap/coap-engine.c +++ b/os/net/app-layer/coap/coap-engine.c @@ -199,10 +199,18 @@ coap_receive(const coap_endpoint_t *src, new_offset = block_offset; } - /* call CoAP framework and check if found and allowed */ - status = call_service(message, response, - transaction->message + COAP_MAX_HEADER_SIZE, - block_size, &new_offset); + if(new_offset < 0) { + LOG_DBG("Blockwise: block request offset overflow\n"); + coap_status_code = BAD_OPTION_4_02; + coap_error_message = "BlockOutOfScope"; + status = COAP_HANDLER_STATUS_CONTINUE; + } else { + /* call CoAP framework and check if found and allowed */ + status = call_service(message, response, + transaction->message + COAP_MAX_HEADER_SIZE, + block_size, &new_offset); + } + if(status != COAP_HANDLER_STATUS_CONTINUE) { if(coap_status_code == NO_ERROR) { diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 4708acca7..4e3e4e00c 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -97,6 +97,7 @@ /* define the buffer as a byte array */ #define PACKETBUF_IPHC_BUF ((uint8_t *)(packetbuf_ptr + packetbuf_hdr_len)) +#define PACKETBUF_PAYLOAD_END ((uint8_t *)(packetbuf_ptr + mac_max_payload)) #define PACKETBUF_6LO_PTR (packetbuf_ptr + packetbuf_hdr_len) #define PACKETBUF_6LO_DISPATCH 0 /* 8 bit */ @@ -197,6 +198,11 @@ static int packetbuf_payload_len; */ static uint8_t uncomp_hdr_len; +/** + * mac_max_payload is the maimum payload space on the MAC frame. + */ +static int mac_max_payload; + /** * The current page (RFC 4944) */ @@ -663,8 +669,9 @@ uncompress_addr(uip_ipaddr_t *ipaddr, uint8_t const prefix[], * compress the IID. * \param link_destaddr L2 destination address, needed to compress IP * dest + * \return 1 if success, else 0 */ -static void +static int compress_hdr_iphc(linkaddr_t *link_destaddr) { uint8_t tmp, iphc0, iphc1, *next_hdr, *next_nhc; @@ -681,7 +688,23 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) LOG_DBG_("\n"); } +/* Macro used only internally, during header compression. Checks if there + * is sufficient space in packetbuf before writing any further. */ +#define CHECK_BUFFER_SPACE(writelen) do { \ + if(hc06_ptr + (writelen) >= PACKETBUF_PAYLOAD_END) { \ + LOG_WARN("Not enough packetbuf space to compress header (%u bytes, %u left). Aborting.\n", \ + (unsigned)(writelen), (unsigned)(PACKETBUF_PAYLOAD_END - hc06_ptr)); \ + return 0; \ + } \ +} while(0); + hc06_ptr = PACKETBUF_IPHC_BUF + 2; + + /* Check if there is enough space for the compressed IPv6 header, in the + * worst case (least compressed case). Extension headers and transport + * layer will be checked when they are compressed. */ + CHECK_BUFFER_SPACE(38); + /* * As we copy some bit-length fields, in the IPHC encoding bytes, * we sometimes use |= @@ -910,11 +933,13 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) NHC byte extra - before the next header here. This is due to next not being elided in that case. */ if(!IS_COMPRESSABLE_PROTO(*next_hdr)) { + CHECK_BUFFER_SPACE(1); hc06_ptr++; LOG_INFO("Keeping the next header in this ext hdr: %d\n", ext_hdr->next); } /* copy the ext-hdr into the hc06 buffer */ + CHECK_BUFFER_SPACE(len); memcpy(hc06_ptr, ext_hdr, len); /* modify the len to octets */ ext_hdr = (struct uip_ext_hdr *) hc06_ptr; @@ -944,6 +969,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* we can compress 12 bits of both source and dest */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_11; LOG_INFO("IPHC: remove 12 b of both source & dest with prefix 0xFOB\n"); + CHECK_BUFFER_SPACE(1); *hc06_ptr = (uint8_t)((UIP_HTONS(udp_buf->srcport) - SICSLOWPAN_UDP_4_BIT_PORT_MIN) << 4) + @@ -954,6 +980,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* we can compress 8 bits of dest, leave source. */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_01; LOG_INFO("IPHC: leave source, remove 8 bits of dest with prefix 0xF0\n"); + CHECK_BUFFER_SPACE(3); memcpy(hc06_ptr, &udp_buf->srcport, 2); *(hc06_ptr + 2) = (uint8_t)((UIP_HTONS(udp_buf->destport) - @@ -963,6 +990,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* we can compress 8 bits of src, leave dest. Copy compressed port */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_10; LOG_INFO("IPHC: remove 8 bits of source with prefix 0xF0, leave dest. hch: %i\n", *next_nhc); + CHECK_BUFFER_SPACE(3); *hc06_ptr = (uint8_t)((UIP_HTONS(udp_buf->srcport) - SICSLOWPAN_UDP_8_BIT_PORT_MIN)); @@ -972,10 +1000,12 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* we cannot compress. Copy uncompressed ports, full checksum */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_00; LOG_INFO("IPHC: cannot compress UDP headers\n"); + CHECK_BUFFER_SPACE(4); memcpy(hc06_ptr, &udp_buf->srcport, 4); hc06_ptr += 4; } /* always inline the checksum */ + CHECK_BUFFER_SPACE(2); memcpy(hc06_ptr, &udp_buf->udpchksum, 2); hc06_ptr += 2; uncomp_hdr_len += UIP_UDPH_LEN; @@ -1006,6 +1036,8 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) } packetbuf_hdr_len = hc06_ptr - packetbuf_ptr; + + return 1; } /*--------------------------------------------------------------------*/ @@ -1477,7 +1509,6 @@ static uint8_t output(const linkaddr_t *localdest) { int framer_hdrlen; - int max_payload; /* The MAC address of the destination of the packet */ linkaddr_t dest; @@ -1513,6 +1544,20 @@ output(const linkaddr_t *localdest) packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); +/* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC */ +#ifndef SICSLOWPAN_USE_FIXED_HDRLEN + packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest); + framer_hdrlen = NETSTACK_FRAMER.length(); + if(framer_hdrlen < 0) { + /* Framing failed, we assume the maximum header length */ + framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN; + } +#else /* USE_FRAMER_HDRLEN */ + framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN; +#endif /* USE_FRAMER_HDRLEN */ + + mac_max_payload = MAC_MAX_PAYLOAD - framer_hdrlen; + /* Try to compress the headers */ #if SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_IPV6 compress_hdr_ipv6(&dest); @@ -1526,26 +1571,14 @@ output(const linkaddr_t *localdest) } #endif /* SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_6LORH */ #if SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC - compress_hdr_iphc(&dest); + if(compress_hdr_iphc(&dest) == 0) { + /* Warning should already be issued by function above */ + return 0; + } #endif /* SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC */ LOG_INFO("output: header of len %d\n", packetbuf_hdr_len); - /* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC. - * We calculate it here only to make a better decision of whether the outgoing packet - * needs to be fragmented or not. */ -#ifndef SICSLOWPAN_USE_FIXED_HDRLEN - packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest); - framer_hdrlen = NETSTACK_FRAMER.length(); - if(framer_hdrlen < 0) { - /* Framing failed, we assume the maximum header length */ - framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN; - } -#else /* USE_FRAMER_HDRLEN */ - framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN; -#endif /* USE_FRAMER_HDRLEN */ - - max_payload = MAC_MAX_PAYLOAD - framer_hdrlen; - if((int)uip_len - (int)uncomp_hdr_len > max_payload - (int)packetbuf_hdr_len) { + if((int)uip_len - (int)uncomp_hdr_len > mac_max_payload - (int)packetbuf_hdr_len) { #if SICSLOWPAN_CONF_FRAG /* Number of bytes processed. */ uint16_t processed_ip_out_len; @@ -1560,7 +1593,7 @@ output(const linkaddr_t *localdest) * IPv6/IPHC/HC_UDP dispatchs/headers. * The following fragments contain only the fragn dispatch. */ - int estimated_fragments = ((int)uip_len) / (max_payload - SICSLOWPAN_FRAGN_HDR_LEN) + 1; + int estimated_fragments = ((int)uip_len) / (mac_max_payload - SICSLOWPAN_FRAGN_HDR_LEN) + 1; int freebuf = queuebuf_numfree() - 1; LOG_INFO("uip_len: %d, fragments: %d, free bufs: %d\n", uip_len, estimated_fragments, freebuf); if(freebuf < estimated_fragments) { @@ -1590,8 +1623,17 @@ output(const linkaddr_t *localdest) /* Copy payload and send */ packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; - packetbuf_payload_len = (max_payload - packetbuf_hdr_len) & 0xfffffff8; + packetbuf_payload_len = (mac_max_payload - packetbuf_hdr_len) & 0xfffffff8; LOG_INFO_("(len %d, tag %d)\n", packetbuf_payload_len, frag_tag); + + if(packetbuf_payload_len < 0) { + /* The current implementation requires that all headers fit in the first + * fragment. Here is a corner case where the header did fit packetbuf + * but do no longer fit after truncating for a length multiple of 8. */ + LOG_WARN("compressed header does not fit first fragment\n"); + return 0; + } + memcpy(packetbuf_ptr + packetbuf_hdr_len, (uint8_t *)UIP_IP_BUF + uncomp_hdr_len, packetbuf_payload_len); packetbuf_set_datalen(packetbuf_payload_len + packetbuf_hdr_len); @@ -1626,7 +1668,7 @@ output(const linkaddr_t *localdest) /* uip_htons((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len); */ SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE, ((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len)); - packetbuf_payload_len = (max_payload - packetbuf_hdr_len) & 0xfffffff8; + packetbuf_payload_len = (mac_max_payload - packetbuf_hdr_len) & 0xfffffff8; while(processed_ip_out_len < uip_len) { LOG_INFO("output: fragment "); PACKETBUF_FRAG_PTR[PACKETBUF_FRAG_OFFSET] = processed_ip_out_len >> 3; diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index 899322264..742ef16c4 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -829,7 +829,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) if(best_dag->preferred_parent != last_parent) { rpl_set_default_route(instance, rpl_parent_get_ipaddr(best_dag->preferred_parent)); PRINTF("RPL: Changed preferred parent, rank changed from %u to %u\n", - (unsigned)old_rank, best_dag->rank); + (unsigned)old_rank, best_dag->rank); RPL_STAT(rpl_stats.parent_switch++); if(RPL_IS_STORING(instance)) { if(last_parent != NULL) { @@ -848,7 +848,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) #endif } else if(best_dag->rank != old_rank) { PRINTF("RPL: Preferred parent update, rank changed from %u to %u\n", - (unsigned)old_rank, best_dag->rank); + (unsigned)old_rank, best_dag->rank); } return best_dag; } diff --git a/os/net/routing/rpl-lite/rpl-dag.c b/os/net/routing/rpl-lite/rpl-dag.c index 00ee1663e..68d9e7aaa 100644 --- a/os/net/routing/rpl-lite/rpl-dag.c +++ b/os/net/routing/rpl-lite/rpl-dag.c @@ -183,14 +183,14 @@ void rpl_refresh_routes(const char *str) { if(rpl_dag_root_is_root()) { - LOG_WARN("incrementing DTSN (%s), current %u)\n", + /* Increment DTSN */ + RPL_LOLLIPOP_INCREMENT(curr_instance.dtsn_out); + + LOG_WARN("incremented DTSN (%s), current %u\n", str, curr_instance.dtsn_out); if(LOG_INFO_ENABLED) { rpl_neighbor_print_list("Refresh routes (before)"); } - - /* Increment DTSN */ - RPL_LOLLIPOP_INCREMENT(curr_instance.dtsn_out); } } /*---------------------------------------------------------------------------*/ @@ -198,15 +198,16 @@ void rpl_global_repair(const char *str) { if(rpl_dag_root_is_root()) { - LOG_WARN("initiating global repair (%s), version %u, rank %u)\n", + RPL_LOLLIPOP_INCREMENT(curr_instance.dag.version); /* New DAG version */ + curr_instance.dtsn_out = RPL_LOLLIPOP_INIT; /* Re-initialize DTSN */ + + LOG_WARN("initiating global repair (%s), version %u, rank %u\n", str, curr_instance.dag.version, curr_instance.dag.rank); if(LOG_INFO_ENABLED) { rpl_neighbor_print_list("Global repair (before)"); } - /* Initiate global repair */ - RPL_LOLLIPOP_INCREMENT(curr_instance.dag.version); /* New DAG version */ - RPL_LOLLIPOP_INCREMENT(curr_instance.dtsn_out); /* Request new DAOs */ + /* Now do a local repair to disseminate the new version */ rpl_local_repair("Global repair"); } } @@ -215,12 +216,13 @@ static void global_repair_non_root(rpl_dio_t *dio) { if(!rpl_dag_root_is_root()) { - LOG_WARN("participating in global repair, version %u, rank %u)\n", - curr_instance.dag.version, curr_instance.dag.rank); + LOG_WARN("participating in global repair, version %u, rank %u\n", + dio->version, curr_instance.dag.rank); if(LOG_INFO_ENABLED) { rpl_neighbor_print_list("Global repair (before)"); } /* Re-initialize configuration from DIO */ + rpl_timers_stop_dag_timers(); init_dag_from_dio(dio); rpl_local_repair("Global repair"); } @@ -395,9 +397,15 @@ process_dio_from_current_dag(uip_ipaddr_t *from, rpl_dio_t *dio) return; } - /* If the DIO sender is on an older version of the DAG, ignore it. The node - will eventually hear the global repair and catch up. */ + /* If the DIO sender is on an older version of the DAG, do not process it + * further. The sender will eventually hear the global repair and catch up. */ if(rpl_lollipop_greater_than(curr_instance.dag.version, dio->version)) { + if(dio->rank == ROOT_RANK) { + /* Before returning, if the DIO was from the root, an old DAG versions + * likely incidates a root reboot. Reset our DIO timer to make sure the + * root hears our version ASAP, and in turn triggers a global repair. */ + rpl_timers_dio_reset("Heard old version from root"); + } return; } @@ -412,10 +420,12 @@ process_dio_from_current_dag(uip_ipaddr_t *from, rpl_dio_t *dio) * Must come first, as it might remove all neighbors, and we then need * to re-add this source of the DIO to the neighbor table */ if(rpl_lollipop_greater_than(dio->version, curr_instance.dag.version)) { - if(curr_instance.dag.rank == ROOT_RANK) { /* The root should not hear newer versions */ + if(curr_instance.dag.rank == ROOT_RANK) { + /* The root should not hear newer versions unless it just rebooted */ LOG_ERR("inconsistent DIO version (current: %u, received: %u), initiate global repair\n", curr_instance.dag.version, dio->version); - curr_instance.dag.version = dio->version; /* Update version and trigger global repair */ + /* Update version and trigger global repair */ + curr_instance.dag.version = dio->version; rpl_global_repair("Inconsistent DIO version"); } else { LOG_WARN("new DIO version (current: %u, received: %u), apply global repair\n", @@ -451,7 +461,7 @@ process_dio_from_current_dag(uip_ipaddr_t *from, rpl_dio_t *dio) if(curr_instance.mop != RPL_MOP_NO_DOWNWARD_ROUTES) { if(nbr != NULL && nbr == curr_instance.dag.preferred_parent && rpl_lollipop_greater_than(dio->dtsn, last_dtsn)) { RPL_LOLLIPOP_INCREMENT(curr_instance.dtsn_out); - LOG_INFO("DTSN increment %u->%u, schedule new DAO with DTSN %u", + LOG_WARN("DTSN increment %u->%u, schedule new DAO with DTSN %u\n", last_dtsn, dio->dtsn, curr_instance.dtsn_out); rpl_timers_schedule_dao(); } diff --git a/os/net/routing/rpl-lite/rpl-neighbor.c b/os/net/routing/rpl-lite/rpl-neighbor.c index d6a545e13..8afa2440f 100644 --- a/os/net/routing/rpl-lite/rpl-neighbor.c +++ b/os/net/routing/rpl-lite/rpl-neighbor.c @@ -63,6 +63,18 @@ static rpl_nbr_t * best_parent(int fresh_only); /* Per-neighbor RPL information */ NBR_TABLE_GLOBAL(rpl_nbr_t, rpl_neighbors); +/*---------------------------------------------------------------------------*/ +static int +max_acceptable_rank(void) +{ + if(curr_instance.max_rankinc == 0) { + /* There is no max rank increment */ + return RPL_INFINITE_RANK; + } else { + /* Make sure not to exceed RPL_INFINITE_RANK */ + return MIN((uint32_t)curr_instance.dag.lowest_rank + curr_instance.max_rankinc, RPL_INFINITE_RANK); + } +} /*---------------------------------------------------------------------------*/ /* As per RFC 6550, section 8.2.2.4 */ static int @@ -70,8 +82,7 @@ acceptable_rank(rpl_rank_t rank) { return rank != RPL_INFINITE_RANK && rank >= ROOT_RANK - && ((curr_instance.max_rankinc == 0) || - rank <= curr_instance.dag.lowest_rank + curr_instance.max_rankinc); + && rank <= max_acceptable_rank(); } /*---------------------------------------------------------------------------*/ void @@ -89,7 +100,7 @@ rpl_neighbor_print_list(const char *str) LOG_INFO_(", DAG state: %s, MOP %u OCP %u rank %u max-rank %u, dioint %u, nbr count %u (%s)\n", rpl_dag_state_to_str(curr_instance.dag.state), curr_instance.mop, curr_instance.of->ocp, curr_rank, - curr_instance.max_rankinc != 0 ? curr_instance.dag.lowest_rank + curr_instance.max_rankinc : 0xffff, + max_acceptable_rank(), curr_dio_interval, rpl_neighbor_count(), str); while(nbr != NULL) { const struct link_stats *stats = rpl_neighbor_get_link_stats(nbr); diff --git a/os/net/routing/rpl-lite/rpl-timers.c b/os/net/routing/rpl-lite/rpl-timers.c index 80a24fe66..5b4ab8faa 100644 --- a/os/net/routing/rpl-lite/rpl-timers.c +++ b/os/net/routing/rpl-lite/rpl-timers.c @@ -435,7 +435,7 @@ handle_probing_timer(void *ptr) LOG_INFO_6ADDR(target_ipaddr); LOG_INFO_(" %s last tx %u min ago\n", curr_instance.dag.urgent_probing_target != NULL ? "(urgent)" : "", - probing_target != NULL ? + stats != NULL ? (unsigned)((clock_time() - stats->last_tx_time) / (60 * CLOCK_SECOND)) : 0 ); /* Send probe, e.g. unicast DIO or DIS */ diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 46ee92fe5..7920fb086 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -174,7 +174,7 @@ PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args)) SHELL_OUTPUT(output, "-- State: %s\n", rpl_state_to_str(curr_instance.dag.state)); SHELL_OUTPUT(output, "-- Preferred parent: "); shell_output_6addr(output, rpl_neighbor_get_ipaddr(curr_instance.dag.preferred_parent)); - SHELL_OUTPUT(output, "\n"); + SHELL_OUTPUT(output, " (last DTSN: %u)\n", curr_instance.dag.preferred_parent->dtsn); SHELL_OUTPUT(output, "-- Rank: %u\n", curr_instance.dag.rank); SHELL_OUTPUT(output, "-- Lowest rank: %u (%u)\n", curr_instance.dag.lowest_rank, curr_instance.max_rankinc); SHELL_OUTPUT(output, "-- DTSN out: %u\n", curr_instance.dtsn_out); diff --git a/os/sys/stack-check.h b/os/sys/stack-check.h index a9068f216..805c4b7da 100644 --- a/os/sys/stack-check.h +++ b/os/sys/stack-check.h @@ -45,7 +45,6 @@ * On startup, fills the area between the stack and the heap with a known pattern. * During execution, the fill can be checked in order to find out * the extent to which the stack has been used. - * * * @{ */ diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index 0c7e248e0..5dfb3f149 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -14,14 +14,18 @@ libs/energest/sky \ libs/data-structures/native \ libs/data-structures/sky \ libs/stack-check/sky \ -ipso-objects/native \ -ipso-objects/native:MAKE_WITH_DTLS=1 \ +lwm2m-ipso-objects/native \ +lwm2m-ipso-objects/native:MAKE_WITH_DTLS=1 \ rpl-udp/sky \ rpl-border-router/native \ rpl-border-router/sky \ slip-radio/sky \ -ipv6-hooks/sky \ +libs/ipv6-hooks/sky \ nullnet/native \ +mqtt-client/native \ +coap/coap-example-client/native \ +coap/coap-example-server/native \ +coap/coap-plugtest-server/native \ TOOLS= diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index 51b232173..5e73c4ecb 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -3,6 +3,7 @@ TOOLSDIR=../../tools EXAMPLES = \ platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx \ +platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ platform-specific/cc26xx/very-sleepy-demo/srf06-cc26xx:BOARD=sensortag/cc2650 \ platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=sensortag/cc2650 \ platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=sensortag/cc1350 \ @@ -38,9 +39,10 @@ mqtt-client/cc2538dk \ storage/cfs-coffee/cc2538dk \ sensniff/cc2538dk \ rpl-udp/cc2538dk \ -coap/cc2538dk \ +coap/coap-example-client/cc2538dk \ +coap/coap-example-server/cc2538dk \ slip-radio/cc2538dk \ -ipso-objects/cc2538dk \ +lwm2m-ipso-objects/cc2538dk \ multicast/cc2538dk \ dev/gpio-hal/cc2538dk \ dev/leds/cc2538dk \ diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index a69ec44a0..db016afaa 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -12,10 +12,11 @@ platform-specific/zoul/rev-b/zoul:BOARD=remote-revb \ platform-specific/zoul/at-test/zoul \ platform-specific/zoul/rtcc/zoul \ platform-specific/zoul/zoul \ -coap/zoul \ +coap/coap-example-client/zoul \ +coap/coap-example-server/zoul \ multicast/zoul \ -ipso-objects/zoul \ -ipso-objects/zoul:MAKE_WITH_DTLS=1 \ +lwm2m-ipso-objects/zoul \ +lwm2m-ipso-objects/zoul:MAKE_WITH_DTLS=1 \ hello-world/zoul \ sensniff/zoul \ sensniff/zoul:ZOUL_CONF_SUB_GHZ_SNIFFER=1 \ @@ -28,7 +29,7 @@ libs/logging/zoul \ 6tisch/etsi-plugtest-2017/zoul:BOARD=remote \ 6tisch/6p-packet/zoul \ 6tisch/sixtop/zoul \ -http-socket/zoul \ +websocket/zoul \ libs/timers/zoul \ libs/energest/zoul \ libs/trickle-library/zoul \ @@ -59,7 +60,7 @@ rpl-udp/openmote-cc2538 \ dev/gpio-hal/openmote-cc2538 \ dev/leds/openmote-cc2538 \ rpl-border-router/openmote-cc2538 \ -ipv6-hooks/openmote-cc2538 \ +libs/ipv6-hooks/openmote-cc2538 \ TOOLS= diff --git a/tests/04-compile-nxp-ports/Makefile b/tests/04-compile-nxp-ports/Makefile index cec1f91af..214bced26 100644 --- a/tests/04-compile-nxp-ports/Makefile +++ b/tests/04-compile-nxp-ports/Makefile @@ -12,6 +12,8 @@ platform-specific/jn516x/rpl/coap-dr1199-node/jn516x \ platform-specific/jn516x/tsch/simple-sensor-network/node/jn516x \ platform-specific/jn516x/tsch/tx-power-verification/node/jn516x \ platform-specific/jn516x/tsch/uart1-test-node/jn516x \ +coap/coap-example-client/jn516x \ +coap/coap-example-server/jn516x \ sensniff/jn516x \ rpl-border-router/jn516x \ 6tisch/simple-node/jn516x \ diff --git a/tests/07-simulation-base/code-ringbufindex/project-conf.h b/tests/07-simulation-base/code-ringbufindex/project-conf.h index a7683dbb5..e745536d9 100644 --- a/tests/07-simulation-base/code-ringbufindex/project-conf.h +++ b/tests/07-simulation-base/code-ringbufindex/project-conf.h @@ -29,9 +29,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _PROJECT_CONF_H_ -#define _PROJECT_CONF_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UNIT_TEST_PRINT_FUNCTION test_print_report -#endif /* !_PROJECT_CONF_H_ */ +#endif /* !PROJECT_CONF_H_ */ diff --git a/tests/07-simulation-base/code-slip-radio/project-conf.h b/tests/07-simulation-base/code-slip-radio/project-conf.h index 616601c1c..e8af03208 100644 --- a/tests/07-simulation-base/code-slip-radio/project-conf.h +++ b/tests/07-simulation-base/code-slip-radio/project-conf.h @@ -1,6 +1,6 @@ -#ifndef __PROJECT_CONF_H__ -#define __PROJECT_CONF_H__ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define RPL_CONF_DAO_ACK 1 -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/tests/07-simulation-base/js/04-ringbufindex.js b/tests/07-simulation-base/js/04-ringbufindex.js index 153f920af..5acb27f11 100644 --- a/tests/07-simulation-base/js/04-ringbufindex.js +++ b/tests/07-simulation-base/js/04-ringbufindex.js @@ -6,7 +6,7 @@ while(true) { YIELD(); log.log(time + " " + "node-" + id + " "+ msg + "\n"); - + if(msg.contains("=check-me=") == false) { continue; } @@ -23,4 +23,3 @@ if(failed) { log.testFailed(); } log.testOK(); - diff --git a/tests/07-simulation-base/js/22-stack-check.js b/tests/07-simulation-base/js/22-stack-check.js index c6915cc66..3dd0b381c 100644 --- a/tests/07-simulation-base/js/22-stack-check.js +++ b/tests/07-simulation-base/js/22-stack-check.js @@ -11,12 +11,12 @@ while(true) { log.log("> " + msg + "\n"); var found = msg.match(re); - + if(found) { var n = parseInt(found[1]); minusage = minusage < n ? minusage : n; maxusage = maxusage > n ? maxusage : n; - + if(minusage < 800 && maxusage >= 1000) { log.testOK(); } diff --git a/tests/13-ieee802154/code-6tisch/project-conf.h b/tests/13-ieee802154/code-6tisch/project-conf.h index 657244d5a..acf60cbab 100644 --- a/tests/13-ieee802154/code-6tisch/project-conf.h +++ b/tests/13-ieee802154/code-6tisch/project-conf.h @@ -28,8 +28,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _PROJECT_CONF_H_ -#define _PROJECT_CONF_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define SIXTOP_CONF_MAX_SCHEDULING_FUNCTIONS 2 @@ -52,4 +52,4 @@ /* Custom MAC layer */ #define NETSTACK_CONF_MAC test_mac_driver -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/tests/13-ieee802154/code-flush-nbr-queue/project-conf.h b/tests/13-ieee802154/code-flush-nbr-queue/project-conf.h index 6923ae6fb..039bc7c49 100644 --- a/tests/13-ieee802154/code-flush-nbr-queue/project-conf.h +++ b/tests/13-ieee802154/code-flush-nbr-queue/project-conf.h @@ -29,8 +29,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _PROJECT_CONF_H_ -#define _PROJECT_CONF_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UNIT_TEST_PRINT_FUNCTION test_print_report @@ -41,4 +41,4 @@ #define TSCH_CONF_WITH_SIXTOP 1 -#endif /* __PROJECT_CONF_H__ */ +#endif /* PROJECT_CONF_H_ */ diff --git a/tests/13-ieee802154/code-panid-handling/project-conf.h b/tests/13-ieee802154/code-panid-handling/project-conf.h index 5c17b28a2..89b2c289e 100644 --- a/tests/13-ieee802154/code-panid-handling/project-conf.h +++ b/tests/13-ieee802154/code-panid-handling/project-conf.h @@ -29,8 +29,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _PROJECT_CONF_H_ -#define _PROJECT_CONF_H_ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ #define UNIT_TEST_PRINT_FUNCTION test_print_report @@ -38,4 +38,4 @@ #include "project-tsch-conf.h" #endif /* MAC_CONF_WITH_TSCH */ -#endif /* !_PROJECT_CONF_H_ */ +#endif /* !PROJECT_CONF_H_ */ diff --git a/tests/13-ieee802154/js/sixtop-test.js b/tests/13-ieee802154/js/sixtop-test.js index 962182e33..c410644ec 100644 --- a/tests/13-ieee802154/js/sixtop-test.js +++ b/tests/13-ieee802154/js/sixtop-test.js @@ -24,4 +24,3 @@ if(failed) { log.testFailed(); } log.testOK(); - diff --git a/tests/17-tun-rpl-br/06-native-coap.sh b/tests/17-tun-rpl-br/06-native-coap.sh index 16dd8aab7..88627ec19 100755 --- a/tests/17-tun-rpl-br/06-native-coap.sh +++ b/tests/17-tun-rpl-br/06-native-coap.sh @@ -12,8 +12,8 @@ declare -i TESTCOUNT=0 # Starting Contiki-NG native node echo "Starting native CoAP server" -make -C $CONTIKI/examples/coap > make.log 2> make.err -sudo $CONTIKI/examples/coap/coap-example-server.native > node.log 2> node.err & +make -C $CONTIKI/examples/coap/coap-example-server > make.log 2> make.err +sudo $CONTIKI/examples/coap/coap-example-server/coap-example-server.native > node.log 2> node.err & CPID=$! sleep 2 @@ -41,7 +41,7 @@ sleep 2 pgrep coap-example | sudo xargs kill -9 if [ $TESTCOUNT -eq $OKCOUNT ] ; then - printf "%-32s TEST OK %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" > $BASENAME.testlog; + printf "%-32s TEST OK %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" | tee $BASENAME.testlog; else echo "==== make.log ====" ; cat make.log; echo "==== make.err ====" ; cat make.err; @@ -49,7 +49,7 @@ else echo "==== node.err ====" ; cat node.err; echo "==== $BASENAME.log ====" ; cat $BASENAME.log; - printf "%-32s TEST FAIL %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" > $BASENAME.testlog; + printf "%-32s TEST FAIL %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" | tee $BASENAME.testlog; fi rm -f make.log make.err node.log node.err coap.log diff --git a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh index 7684044a8..9aacc2976 100755 --- a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh +++ b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh @@ -9,9 +9,9 @@ IPADDR=fd00::302:304:506:708 # Starting Contiki-NG native node echo "Starting native node - lwm2m/ipso objects" -make -C $CONTIKI/examples/ipso-objects clean >/dev/null -make -C $CONTIKI/examples/ipso-objects > make.log 2> make.err -sudo $CONTIKI/examples/ipso-objects/example-ipso-objects.native > node.log 2> node.err & +make -C $CONTIKI/examples/lwm2m-ipso-objects clean >/dev/null +make -C $CONTIKI/examples/lwm2m-ipso-objects > make.log 2> make.err +sudo $CONTIKI/examples/lwm2m-ipso-objects/example-ipso-objects.native > node.log 2> node.err & CPID=$! sleep 10