Merge branch 'develop' into contrib/rtimer-config

This commit is contained in:
Simon Duquennoy 2018-05-11 21:10:33 +02:00 committed by GitHub
commit 5ef74e9cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
204 changed files with 2138 additions and 1143 deletions

View File

@ -49,6 +49,8 @@ CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1
CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\" CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\"
endif endif
LDFLAGS = -Wl,--fatal-warnings
MODULES += os os/sys os/dev os/lib os/services MODULES += os os/sys os/dev os/lib os/services
# Automatically include project-conf.h if found # Automatically include project-conf.h if found
@ -165,14 +167,12 @@ MAKE_NET ?= MAKE_NET_IPV6
ifeq ($(MAKE_NET),MAKE_NET_NULLNET) ifeq ($(MAKE_NET),MAKE_NET_NULLNET)
CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1 CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1
MODULES += os/net/nullnet
endif endif
ifeq ($(MAKE_NET),MAKE_NET_IPV6) ifeq ($(MAKE_NET),MAKE_NET_IPV6)
CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1 CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1
MODULES += os/net/ipv6 MODULES += os/net/ipv6
else
CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1
MODULES += os/net/nullnet
endif endif
ifeq ($(MAKE_NET),MAKE_NET_OTHER) ifeq ($(MAKE_NET),MAKE_NET_OTHER)
@ -298,14 +298,15 @@ CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@))
.PHONY: clean distclean usage help targets boards savetarget savedefines viewconf .PHONY: clean distclean usage help targets boards savetarget savedefines viewconf
clean: clean:
-rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN) -$(Q)rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN)
-rm -rf $(OBJECTDIR) -$(Q)rm -rf $(OBJECTDIR)
-rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT)) -$(Q)rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT))
-rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) -$(Q)rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT))
@echo Target $(TARGET) cleaned
distclean: distclean:
@for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \ @for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \
echo make $$TARG clean; \ echo Running: make TARGET=$$TARG clean; \
make TARGET=$$TARG clean; \ make TARGET=$$TARG clean; \
done done
@ -397,7 +398,7 @@ usage:
@echo "Miscellaneous targets:" @echo "Miscellaneous targets:"
@echo " targets Prints list of supported platforms" @echo " targets Prints list of supported platforms"
@echo " boards Prints a list of supported boards for TARGET" @echo " boards Prints a list of supported boards for TARGET"
@echo " savegtarget Saves TARGET and BOARD for future invocations of make" @echo " savetarget Saves TARGET and BOARD for future invocations of make"
@echo " savedefines Saves DEFINES for future invocations of make" @echo " savedefines Saves DEFINES for future invocations of make"
@echo " clean Removes all compiled files for TARGET" @echo " clean Removes all compiled files for TARGET"
@echo " distclean Removes all compiled files for all TARGETs" @echo " distclean Removes all compiled files for all TARGETs"

View File

@ -1,7 +1,7 @@
# Contiki-NG: The OS for Next Generation IoT Devices # 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) [![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) [![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) [![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) [![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. 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 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. Contiki-NG started as a fork of the Contiki OS and retains some of its original features.

View File

@ -55,7 +55,7 @@
* - SPIX_FLUSH(x) * - SPIX_FLUSH(x)
* *
* Some of the old functions and macros are still supported. * 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. * has to be be selected by means of the macro SPI_CONF_DEFAULT_INSTANCE.
* *
* This SPI driver depends on the following defines: * This SPI driver depends on the following defines:
@ -95,14 +95,14 @@
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Default values for the clock rate divider */ /* Default values for the clock rate divider */
#ifdef SPI0_CONF_CPRS_CPSDVSR #ifdef SPI0_CONF_CPRS_CPSDVSR
#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR #define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR
#else #else
#define SPI0_CPRS_CPSDVSR 2 #define SPI0_CPRS_CPSDVSR 2
#endif #endif
#ifdef SPI1_CONF_CPRS_CPSDVSR #ifdef SPI1_CONF_CPRS_CPSDVSR
#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR #define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR
#else #else
#define SPI1_CPRS_CPSDVSR 2 #define SPI1_CPRS_CPSDVSR 2
#endif #endif
@ -120,7 +120,7 @@
} while(0) } while(0)
#define SPIX_FLUSH(spi) do { \ #define SPIX_FLUSH(spi) do { \
while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE) { \ while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE) { \
SPIX_BUF(spi); \ SPIX_BUF(spi); \
} \ } \
} while(0) } while(0)
#define SPIX_CS_CLR(port, pin) do { \ #define SPIX_CS_CLR(port, pin) do { \
@ -144,7 +144,7 @@
#endif #endif
#define SPI_CS_CLR(port, pin) SPIX_CS_CLR(port, pin) #define SPI_CS_CLR(port, pin) SPIX_CS_CLR(port, pin)
#define SPI_CS_SET(port, pin) SPIX_CS_SET(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 /** \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. * 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, * \param frame_format Set the SSI frame format. Use SSI_CR0_FRF_MOTOROLA,
* SSI_CR0_FRF_TI, or SSI_CR0_FRF_MICROWIRE. * SSI_CR0_FRF_TI, or SSI_CR0_FRF_MICROWIRE.
* \param clock_polarity In Motorola mode, set whether the clock is high or low * \param clock_polarity In Motorola mode, set whether the clock is high or low

View File

@ -93,10 +93,10 @@ ifeq ($(HOST_OS),Windows)
SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-windows SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-windows
else else
ifeq ($(HOST_OS),Darwin) ifeq ($(HOST_OS),Darwin)
SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-macos SERIALDUMP ?= rlwrap $(CONTIKI)/tools/sky/serialdump-macos
else else
# Else assume Linux # Else assume Linux
SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-linux SERIALDUMP ?= rlwrap $(CONTIKI)/tools/sky/serialdump-linux
endif endif
endif endif

View File

@ -78,9 +78,17 @@
#define IEEE802154_CONF_DEFAULT_CHANNEL 0 #define IEEE802154_CONF_DEFAULT_CHANNEL 0
#endif /* IEEE802154_CONF_DEFAULT_CHANNEL */ #endif /* IEEE802154_CONF_DEFAULT_CHANNEL */
#ifndef CSMA_CONF_ACK_WAIT_TIME
#define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400) #define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400)
#endif /* CSMA_CONF_ACK_WAIT_TIME */
#ifndef CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME
#define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000) #define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000)
#endif /* CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME */
#ifndef CSMA_CONF_SEND_SOFT_ACK
#define CSMA_CONF_SEND_SOFT_ACK 1 #define CSMA_CONF_SEND_SOFT_ACK 1
#endif /* CSMA_CONF_SEND_SOFT_ACK */
#else /* CC13XX_CONF_PROP_MODE */ #else /* CC13XX_CONF_PROP_MODE */
#ifndef NETSTACK_CONF_RADIO #ifndef NETSTACK_CONF_RADIO
@ -190,7 +198,7 @@
* @{ * @{
*/ */
#ifndef ROM_BOOTLOADER_ENABLE #ifndef ROM_BOOTLOADER_ENABLE
#define ROM_BOOTLOADER_ENABLE 0 #define ROM_BOOTLOADER_ENABLE 1
#endif #endif
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -49,20 +49,21 @@
#include "driverlib/rf_mailbox.h" #include "driverlib/rf_mailbox.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* IEEE 802.15.4g frequency band identifiers (Table 68f) */ /* IEEE 802.15.4g frequency band identifiers (Table 68f) */
#define DOT_15_4G_FREQUENCY_BAND_169 0 /* 169.400169.475 (Europe) - 169 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_169 0 /* 169.400169.475 (Europe) - 169 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_450 1 /* 450470 (US FCC Part 22/90) - 450 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_450 1 /* 450470 (US FCC Part 22/90) - 450 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_470 2 /* 470510 (China) - 470 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_470 2 /* 470510 (China) - 470 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_780 3 /* 779787 (China) - 780 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_780 3 /* 779787 (China) - 780 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_863 4 /* 863870 (Europe) - 863 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_863 4 /* 863870 (Europe) - 863 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_896 5 /* 896901 (US FCC Part 90) - 896 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_896 5 /* 896901 (US FCC Part 90) - 896 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_901 6 /* 901902 (US FCC Part 24) - 901 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_901 6 /* 901902 (US FCC Part 24) - 901 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_915 7 /* 902928 (US) - 915 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_915 7 /* 902928 (US) - 915 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_917 8 /* 917923.5 (Korea) - 917 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_917 8 /* 917923.5 (Korea) - 917 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_920 9 /* 920928 (Japan) - 920 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_920 9 /* 920928 (Japan) - 920 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_928 10 /* 928960 (US, non-contiguous) - 928 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_928 10 /* 928960 (US, non-contiguous) - 928 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_950 11 /* 950958 (Japan) - 950 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_950 11 /* 950958 (Japan) - 950 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_1427 12 /* 14271518 (US and Canada, non-contiguous) - 1427 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_1427 12 /* 14271518 (US and Canada, non-contiguous) - 1427 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_2450 13 /* 24002483.5 2450 MHz band */ #define DOT_15_4G_FREQUENCY_BAND_2450 13 /* 24002483.5 2450 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_CUSTOM 14 /* For use with custom frequency band settings */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Default band selection to band 4 - 863MHz */ /* Default band selection to band 4 - 863MHz */
#ifdef DOT_15_4G_CONF_FREQUENCY_BAND_ID #ifdef DOT_15_4G_CONF_FREQUENCY_BAND_ID
@ -77,6 +78,18 @@
* bands we only support operating mode #1 (Table 134). * bands we only support operating mode #1 (Table 134).
* *
* DOT_15_4G_CHAN0_FREQUENCY is specified here in KHz * DOT_15_4G_CHAN0_FREQUENCY is specified here in KHz
*
* Custom bands and configuration can be used with DOT_15_4G_FREQUENCY_BAND_CUSTOM.
*
* Example of custom setup for the 868Mhz sub-band in Europe with 11 channels,
* center frequency at 868.050MHz and channel spacing at 100KHz.
* These should be put in project-config.h or similar.
*
* #define DOT_15_4G_FREQUENCY_BAND_ID DOT_15_4G_FREQUENCY_BAND_CUSTOM
* #define DOT_15_4G_CHAN0_FREQUENCY 868050
* #define DOT_15_4G_CHANNEL_SPACING 100
* #define DOT_15_4G_CHANNEL_MAX 11
* #define PROP_MODE_CONF_LO_DIVIDER 0x05
*/ */
#if DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_470 #if DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_470
#define DOT_15_4G_CHANNEL_MAX 198 #define DOT_15_4G_CHANNEL_MAX 198
@ -116,6 +129,22 @@
#define DOT_15_4G_CHAN0_FREQUENCY 951000 #define DOT_15_4G_CHAN0_FREQUENCY 951000
#define PROP_MODE_CONF_LO_DIVIDER 0x05 #define PROP_MODE_CONF_LO_DIVIDER 0x05
#elif DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_CUSTOM
#ifndef DOT_15_4G_CHANNEL_MAX
#error DOT_15_4G_CHANNEL_MAX must be manually set when using custom frequency band
#endif
#ifndef DOT_15_4G_CHANNEL_SPACING
#error DOT_15_4G_CHANNEL_SPACING must be manually set when using custom frequency band
#endif
#ifndef DOT_15_4G_CHAN0_FREQUENCY
#error DOT_15_4G_CHAN0_FREQUENCY must be manually set when using custom frequency band
#endif
#ifndef PROP_MODE_CONF_LO_DIVIDER
#error PROP_MODE_CONF_LO_DIVIDER must be manually set when using custom frequency band
#endif
#else #else
#error The selected frequency band is not supported #error The selected frequency band is not supported
#endif #endif

View File

@ -1,30 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science * 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
*/ */
@ -35,7 +35,7 @@
* exclusive. Set spi_busy so that interrupt handlers can check if * 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 * they are allowed to use the bus or not. Only the CC2420 radio needs
* this in practice. * this in practice.
* *
*/ */
unsigned char spi_busy = 0; unsigned char spi_busy = 0;

View File

@ -1,6 +1,7 @@
CONTIKI_CPU_DIRS = . net dev 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 ### Compiler definitions
CC ?= gcc CC ?= gcc

View File

@ -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 <stdint.h>
/*---------------------------------------------------------------------------*/
/* 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);
}
/*---------------------------------------------------------------------------*/

View File

@ -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 <stdbool.h>
/*---------------------------------------------------------------------------*/
#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;
}
/*---------------------------------------------------------------------------*/

View File

@ -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_ */
/*---------------------------------------------------------------------------*/

View File

@ -113,13 +113,15 @@ static spi_device_t flash_spi_configuration_default = {
/** /**
* Get spi configuration, return default configuration if NULL * Get spi configuration, return default configuration if NULL
*/ */
static spi_device_t* static spi_device_t *
get_spi_conf(spi_device_t *conf) { get_spi_conf(spi_device_t *conf)
{
if(conf == NULL) { if(conf == NULL) {
return &flash_spi_configuration_default; return &flash_spi_configuration_default;
} }
return conf; return conf;
}/*---------------------------------------------------------------------------*/ }
/*---------------------------------------------------------------------------*/
/** /**
* Clear external flash CSN line * Clear external flash CSN line
*/ */
@ -334,7 +336,7 @@ ext_flash_open(spi_device_t *conf)
/* Put the part is standby mode */ /* Put the part is standby mode */
power_standby(flash_spi_configuration); 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; return true;
} }
@ -353,7 +355,7 @@ ext_flash_close(spi_device_t *conf)
/* Put the part in low power mode */ /* Put the part in low power mode */
ret = power_down(flash_spi_configuration); ret = power_down(flash_spi_configuration);
/* SPI is released no matter if power_down() succeeds or fails */ /* SPI is released no matter if power_down() succeeds or fails */
if(spi_release(flash_spi_configuration) != SPI_DEV_STATUS_OK) { if(spi_release(flash_spi_configuration) != SPI_DEV_STATUS_OK) {
return false; return false;
@ -474,7 +476,7 @@ ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length)
uint8_t wbuf[4]; uint8_t wbuf[4];
uint32_t i, numsectors; uint32_t i, numsectors;
uint32_t endoffset = offset + length - 1; uint32_t endoffset = offset + length - 1;
spi_device_t *flash_spi_configuration; spi_device_t *flash_spi_configuration;
flash_spi_configuration = get_spi_conf(conf); flash_spi_configuration = get_spi_conf(conf);

View File

@ -37,3 +37,17 @@ else
sort -g | head -1)) sort -g | head -1))
$(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $< $(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $<
endif endif
ifeq ($(HOST_OS),Darwin)
RENODE = mono /Applications/Renode.app/Contents/MacOS/bin/Renode.exe
else
RENODE = renode
endif
SCRIPT ?= $(notdir $(CURDIR)).resc
.PHONY: renode
renode: all
$(RENODE) $(SCRIPT)

View File

@ -57,5 +57,3 @@ const leds_t leds_arch_leds[] = {
#endif #endif
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -180,12 +180,12 @@ else
ifeq ($(HOST_OS),Darwin) ifeq ($(HOST_OS),Darwin)
USBDEVPREFIX= USBDEVPREFIX=
USBDEVBASENAME=/dev/tty.usbserial- USBDEVBASENAME=/dev/tty.usbserial-
SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-macos SERIALDUMP ?= rlwrap $(CONTIKI)/tools/jn516x/serialdump-macos
else else
# Else we assume Linux # Else we assume Linux
USBDEVPREFIX= USBDEVPREFIX=
USBDEVBASENAME=/dev/ttyUSB USBDEVBASENAME=/dev/ttyUSB
SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-linux SERIALDUMP ?= rlwrap $(CONTIKI)/tools/jn516x/serialdump-linux
endif endif
endif endif

View File

@ -6,8 +6,8 @@ endif
CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_DIRS = . dev
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
CONTIKI_TARGET_SOURCEFILES += platform.c clock.c xmem.c leds-arch.c CONTIKI_TARGET_SOURCEFILES += platform.c clock.c xmem.c
CONTIKI_TARGET_SOURCEFILES += cfs-posix.c cfs-posix-dir.c CONTIKI_TARGET_SOURCEFILES += cfs-posix.c cfs-posix-dir.c buttons.c
ifeq ($(HOST_OS),Windows) ifeq ($(HOST_OS),Windows)
CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c

View File

@ -37,7 +37,9 @@
#ifdef PROJECT_CONF_PATH #ifdef PROJECT_CONF_PATH
#include PROJECT_CONF_PATH #include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */ #endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
#include "native-def.h"
/*---------------------------------------------------------------------------*/
#include <inttypes.h> #include <inttypes.h>
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#include <sys/select.h> #include <sys/select.h>
@ -60,8 +62,6 @@ int select_set_callback(int fd, const struct select_callback *callback);
typedef unsigned int uip_stats_t; typedef unsigned int uip_stats_t;
#define LEDS_CONF_LEGACY_API 1
#ifndef UIP_CONF_BYTE_ORDER #ifndef UIP_CONF_BYTE_ORDER
#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN #define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
#endif #endif
@ -91,6 +91,8 @@ typedef unsigned long clock_time_t;
#define LOG_CONF_ENABLED 1 #define LOG_CONF_ENABLED 1
#define PLATFORM_SUPPORTS_BUTTON_HAL 1
/* Not part of C99 but actually present */ /* Not part of C99 but actually present */
int strcasecmp(const char*, const char*); int strcasecmp(const char*, const char*);

View File

@ -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/button-hal.h"
#include <stdint.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
button_hal_button_t *button_hal_buttons[] = { NULL };
const uint8_t button_hal_button_count = 0;
/*---------------------------------------------------------------------------*/

View File

@ -56,6 +56,9 @@
#include "net/netstack.h" #include "net/netstack.h"
#include "dev/serial-line.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.h"
#include "net/ipv6/uip-debug.h" #include "net/ipv6/uip-debug.h"
@ -251,6 +254,9 @@ platform_process_args(int argc, char**argv)
void void
platform_init_stage_one() platform_init_stage_one()
{ {
gpio_hal_init();
button_hal_init();
leds_init();
return; return;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -54,5 +54,3 @@ const leds_t leds_arch_leds[] = {
}, },
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -54,7 +54,7 @@ else
ifeq ($(HOST_OS),Darwin) ifeq ($(HOST_OS),Darwin)
ifndef MOTELIST ifndef MOTELIST
USBDEVPREFIX= USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-macos SERIALDUMP = rlwrap $(CONTIKI)/tools/sky/serialdump-macos
MOTELIST = $(CONTIKI)/tools/sky/motelist-macos MOTELIST = $(CONTIKI)/tools/sky/motelist-macos
TMOTE_BSL_FILE = tmote-bsl-linux TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0) TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)
@ -75,7 +75,7 @@ else
# Else we assume Linux # Else we assume Linux
ifndef MOTELIST ifndef MOTELIST
USBDEVPREFIX= USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux SERIALDUMP = rlwrap $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/sky/motelist-linux MOTELIST = $(CONTIKI)/tools/sky/motelist-linux
TMOTE_BSL_FILE = tmote-bsl-linux TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0) TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)

View File

@ -43,44 +43,41 @@
#include "contiki-conf.h" #include "contiki-conf.h"
#include "dev/xmem.h" #include "dev/xmem.h"
/*** MX25R8035F Memory Organization /*
The memory is organized as: * MX25R8035F Memory Organization
8Mbit = 1048576 bytes (8 bits each) * The memory is organized as:
256 sectors (32 Kbits, 4096 bytes each) * 8Mbit = 1048576 bytes (8 bits each)
4096 pages (256 bytes each). * 256 sectors (32 Kbits, 4096 bytes each)
Each page can be individually programmed (bits are programmed from 1 to 0). The device is * 4096 pages (256 bytes each).
sector or bulk erasable (bits are erased from 0 to 1) but not page erasable * 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
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL //Total size of the External Flash Memory in the Z1 * page erasable
*/
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL /* Total size of the External Flash Memory in the Z1 */
/* Coffee configuration parameters. */ /* Coffee configuration parameters. */
#define COFFEE_SECTOR_SIZE 4096UL #define COFFEE_SECTOR_SIZE 4096UL
#define COFFEE_PAGE_SIZE 256UL #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_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START)
#define COFFEE_NAME_LENGTH 16 #define COFFEE_NAME_LENGTH 16
#define COFFEE_MAX_OPEN_FILES 6 #define COFFEE_MAX_OPEN_FILES 6
#define COFFEE_FD_SET_SIZE 8 #define COFFEE_FD_SET_SIZE 8
#define COFFEE_LOG_TABLE_LIMIT 256 #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_LOG_SIZE 1024
#define COFFEE_MICRO_LOGS 1 #define COFFEE_MICRO_LOGS 1
/* Flash operations. */ /* Flash operations. */
#define COFFEE_WRITE(buf, size, offset) \ #define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
#define COFFEE_READ(buf, size, offset) \ #define COFFEE_READ(buf, size, offset) \
xmem_pread((char *)(buf), (size), COFFEE_START + (offset)) xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
#define COFFEE_ERASE(sector) \ #define COFFEE_ERASE(sector) \
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE) xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
/* Coffee types. */ /* Coffee types. */
typedef int16_t coffee_page_t; typedef int16_t coffee_page_t;

View File

@ -49,21 +49,17 @@
#define XMEM_BUFF_LENGHT 128 #define XMEM_BUFF_LENGHT 128
#if 0 #if 0
#define PRINTF(...) printf(__VA_ARGS__) #define PRINTF(...) printf(__VA_ARGS__)
#else #else
#define PRINTF(...) do {} while (0) #define PRINTF(...) do {} while(0)
#endif #endif
void void
xmem_init(void) xmem_init(void)
{ {
ext_flash_open(NULL); ext_flash_open(NULL);
} }
int int
xmem_pread(void *_p, int size, unsigned long addr) 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); 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); x = ~*((uint8_t *)_p + i);
*((uint8_t *)_p+i) = x; *((uint8_t *)_p + i) = x;
} }
ext_flash_close(NULL); ext_flash_close(NULL);
if(rv) if(rv) {
return size; return size;
}
PRINTF("Could not read flash memory!\n"); PRINTF("Could not read flash memory!\n");
return -1; return -1;
} }
int int
xmem_pwrite(const void *_buf, int size, unsigned long addr) 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; 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); 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); tmp_buf[i] = ~*((uint8_t *)_buf + j + i);
} }
rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf); rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf);
if (!rv) { if(!rv) {
PRINTF("Could not write flash memory!\n"); PRINTF("Could not write flash memory!\n");
return size - remain; return size - remain;
} }
@ -128,8 +123,6 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
return size; return size;
} }
int int
xmem_erase(long size, unsigned long addr) xmem_erase(long size, unsigned long addr)
{ {
@ -137,7 +130,6 @@ xmem_erase(long size, unsigned long addr)
rv = ext_flash_open(NULL); rv = ext_flash_open(NULL);
if(!rv) { if(!rv) {
PRINTF("Could not open flash to save config\n"); PRINTF("Could not open flash to save config\n");
ext_flash_close(NULL); ext_flash_close(NULL);
@ -160,8 +152,9 @@ xmem_erase(long size, unsigned long addr)
watchdog_periodic(); watchdog_periodic();
if(rv) if(rv) {
return size; return size;
}
PRINTF("Could not erase flash memory\n"); PRINTF("Could not erase flash memory\n");
return -1; return -1;

View File

@ -41,5 +41,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_2, .negative_logic = false }, { .pin = BOARD_IOID_LED_2, .negative_logic = false },
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -39,5 +39,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_1, .negative_logic = false }, { .pin = BOARD_IOID_LED_1, .negative_logic = false },
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -40,5 +40,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_2, .negative_logic = false }, { .pin = BOARD_IOID_LED_2, .negative_logic = false },
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -42,5 +42,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_4, .negative_logic = false }, { .pin = BOARD_IOID_LED_4, .negative_logic = false },
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -56,11 +56,11 @@ ifeq ($(HOST_OS),Darwin)
USBDEVPREFIX= USBDEVPREFIX=
MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia-macos MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia-macos
MOTES := $(shell $(MOTELIST) -c 2>&- | cut -f 2 -d ,) MOTES := $(shell $(MOTELIST) -c 2>&- | cut -f 2 -d ,)
SERIALDUMP := $(CONTIKI)/tools/sky/serialdump-macos SERIALDUMP := rlwrap $(CONTIKI)/tools/sky/serialdump-macos
else else
### If we are not running under Mac, we assume Linux ### If we are not running under Mac, we assume Linux
USBDEVPREFIX= USBDEVPREFIX=
SERIALDUMP := $(CONTIKI)/tools/sky/serialdump-linux SERIALDUMP := rlwrap $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia
MOTES := $(shell $(MOTELIST) -b $(MOTELIST_ZOLERTIA) -c 2>&- | cut -f 2 -d , | \ MOTES := $(shell $(MOTELIST) -b $(MOTELIST_ZOLERTIA) -c 2>&- | cut -f 2 -d , | \
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);') perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')

View File

@ -72,7 +72,7 @@ dht22_read(void)
{ {
uint8_t i; uint8_t i;
uint8_t j = 0; uint8_t j = 0;
uint8_t last_state; uint8_t last_state = 0xFF;
uint8_t counter = 0; uint8_t counter = 0;
uint8_t checksum = 0; uint8_t checksum = 0;
@ -95,7 +95,6 @@ dht22_read(void)
* if the line is high between 70-74us the bit sent will be "1" (one). * if the line is high between 70-74us the bit sent will be "1" (one).
*/ */
GPIO_SET_INPUT(DHT22_PORT_BASE, DHT22_PIN_MASK); GPIO_SET_INPUT(DHT22_PORT_BASE, DHT22_PIN_MASK);
last_state = GPIO_READ_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK);
for(i = 0; i < DHT22_MAX_TIMMING; i++) { for(i = 0; i < DHT22_MAX_TIMMING; i++) {
counter = 0; counter = 0;
@ -208,8 +207,8 @@ value(int type)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int16_t
dht22_read_all(int *temperature, int *humidity) dht22_read_all(int16_t *temperature, int16_t *humidity)
{ {
if((temperature == NULL) || (humidity == NULL)) { if((temperature == NULL) || (humidity == NULL)) {
PRINTF("DHT22: Invalid arguments\n"); PRINTF("DHT22: Invalid arguments\n");

View File

@ -90,7 +90,7 @@
#define DHT22_COUNT 8 /**< Minimum ticks to detect a "1" bit */ #define DHT22_COUNT 8 /**< Minimum ticks to detect a "1" bit */
#define DHT22_MAX_TIMMING 85 /**< Maximum ticks in a single operation */ #define DHT22_MAX_TIMMING 85 /**< Maximum ticks in a single operation */
#define DHT22_READING_DELAY 1 /**< 1 us */ #define DHT22_READING_DELAY 1 /**< 1 us */
#define DHT22_READY_TIME 20 /**< 40 us */ #define DHT22_READY_TIME 40 /**< 40 us */
#define DHT22_START_TIME (RTIMER_SECOND / 50) /**< 20 ms */ #define DHT22_START_TIME (RTIMER_SECOND / 50) /**< 20 ms */
#define DHT22_AWAKE_TIME (RTIMER_SECOND / 4) /**< 250 ms */ #define DHT22_AWAKE_TIME (RTIMER_SECOND / 4) /**< 250 ms */
/** @} */ /** @} */
@ -99,7 +99,7 @@
* \name DHT22 auxiliary functions * \name DHT22 auxiliary functions
* @{ * @{
*/ */
int dht22_read_all(int *temperature, int *humidity); int16_t dht22_read_all(int16_t *temperature, int16_t *humidity);
/** @} */ /** @} */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
#define DHT22_SENSOR "DHT22 sensor" #define DHT22_SENSOR "DHT22 sensor"

View File

@ -50,5 +50,3 @@ const leds_t leds_arch_leds[] = {
}, },
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -28,8 +28,8 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _PROJECT_CONF_H_ #ifndef PROJECT_CONF_H_
#define _PROJECT_CONF_H_ #define PROJECT_CONF_H_
#define UIP_CONF_ND6_SEND_RA 0 #define UIP_CONF_ND6_SEND_RA 0
@ -39,4 +39,4 @@
#define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG #define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG
#endif /* _PROJECT_CONF_H_ */ #endif /* PROJECT_CONF_H_ */

View File

@ -32,8 +32,8 @@
* \author Simon Duquennoy <simonduq@sics.se> * \author Simon Duquennoy <simonduq@sics.se>
*/ */
#ifndef __PROJECT_CONF_H__ #ifndef PROJECT_CONF_H_
#define __PROJECT_CONF_H__ #define PROJECT_CONF_H_
/* Set to enable TSCH security */ /* Set to enable TSCH security */
#ifndef WITH_SECURITY #ifndef WITH_SECURITY
@ -115,4 +115,4 @@
#define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG #define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG
#define TSCH_LOG_CONF_PER_SLOT 1 #define TSCH_LOG_CONF_PER_SLOT 1
#endif /* __PROJECT_CONF_H__ */ #endif /* PROJECT_CONF_H_ */

View File

@ -32,8 +32,8 @@
* \author Simon Duquennoy <simonduq@sics.se> * \author Simon Duquennoy <simonduq@sics.se>
*/ */
#ifndef __PROJECT_CONF_H__ #ifndef PROJECT_CONF_H_
#define __PROJECT_CONF_H__ #define PROJECT_CONF_H_
/* Set to enable TSCH security */ /* Set to enable TSCH security */
#ifndef WITH_SECURITY #ifndef WITH_SECURITY
@ -78,4 +78,4 @@
#define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_DBG #define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_DBG
#define TSCH_LOG_CONF_PER_SLOT 1 #define TSCH_LOG_CONF_PER_SLOT 1
#endif /* __PROJECT_CONF_H__ */ #endif /* PROJECT_CONF_H_ */

View File

@ -28,8 +28,8 @@
* *
*/ */
#ifndef __PROJECT_CONF_H__ #ifndef PROJECT_CONF_H_
#define __PROJECT_CONF_H__ #define PROJECT_CONF_H_
/* Set to enable TSCH security */ /* Set to enable TSCH security */
#ifndef WITH_SECURITY #ifndef WITH_SECURITY
@ -103,4 +103,4 @@
#endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \ #endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \
|| CONTIKI_TARGET_OPENMOTE_CC2538 */ || CONTIKI_TARGET_OPENMOTE_CC2538 */
#endif /* __PROJECT_CONF_H__ */ #endif /* PROJECT_CONF_H_ */

View File

@ -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

View File

@ -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 The examples can run either on a real device or as native.
layer to develop server-side applications. 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.
- coap-example-client.c: A CoAP client that polls the /actuators/toggle resource A tutorial for setting up the CoAP server example and querying it is provided on the wiki.
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
<cygwin>\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)

View File

@ -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

View File

@ -51,8 +51,8 @@
/* Log configuration */ /* Log configuration */
#include "coap-log.h" #include "coap-log.h"
#define LOG_MODULE "client" #define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_COAP #define LOG_LEVEL LOG_LEVEL_APP
/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */ /* 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]" #define SERVER_EP "coap://[fe80::212:7402:0002:0202]"

View File

@ -47,15 +47,11 @@
#else #else
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#endif #endif
/*----------------------------------------------------------------------------*/
#define DEBUG 0 /* Log configuration */
#if DEBUG #include "sys/log.h"
#define PRINTF(...) printf(__VA_ARGS__) #define LOG_MODULE "App"
#define PRINTFLN(format, ...) printf(format "\n", ##__VA_ARGS__) #define LOG_LEVEL LOG_LEVEL_APP
#else
#define PRINTF(...)
#define PRINTFLN(...)
#endif
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* FIXME: This server address is hard-coded for Cooja */ /* 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 */ /* store server address in server_ipaddr */
SERVER_NODE(server_ipaddr); SERVER_NODE(server_ipaddr);
/* receives all CoAP messages */
coap_init_engine();
/* init timer and button (if available) */ /* init timer and button (if available) */
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
#if PLATFORM_HAS_BUTTON #if PLATFORM_HAS_BUTTON

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Swedish Institute of Computer Science. * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -27,34 +27,21 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
*
*/ */
/** /**
* \file * \file
* A brief description of what this file is. * Erbium (Er) example project configuration.
* \author * \author
* Adam Dunkels <adam@sics.se> * Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/ */
#include "dev/leds.h" #ifndef PROJECT_CONF_H_
static leds_mask_t leds; #define PROJECT_CONF_H_
/*---------------------------------------------------------------------------*/
void #define LOG_LEVEL_APP LOG_LEVEL_DBG
leds_arch_init(void)
{ /* Enable client-side support for COAP observe */
leds = 0; #define COAP_OBSERVE_CLIENT 1
}
/*---------------------------------------------------------------------------*/ #endif /* PROJECT_CONF_H_ */
leds_mask_t
leds_arch_get(void)
{
return leds;
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(leds_mask_t l)
{
leds = l;
}
/*---------------------------------------------------------------------------*/

View File

@ -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

View File

@ -48,14 +48,10 @@
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#endif #endif
#define DEBUG 0 /* Log configuration */
#if DEBUG #include "sys/log.h"
#include <stdio.h> #define LOG_MODULE "App"
#define PRINTF(...) printf(__VA_ARGS__) #define LOG_LEVEL LOG_LEVEL_APP
#else
#define PRINTF(...)
#endif
/* /*
* Resources to be activated need to be imported through the extern keyword. * Resources to be activated need to be imported through the extern keyword.
* The build system automatically compiles the resources in the corresponding sub-directory. * 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" #include "dev/temperature-sensor.h"
extern coap_resource_t res_temperature; extern coap_resource_t res_temperature;
#endif #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"); PROCESS(er_example_server, "Erbium Example Server");
AUTOSTART_PROCESSES(&er_example_server); AUTOSTART_PROCESSES(&er_example_server);
@ -105,28 +90,23 @@ PROCESS_THREAD(er_example_server, ev, data)
PROCESS_PAUSE(); PROCESS_PAUSE();
PRINTF("Starting Erbium Example Server\n"); LOG_INFO("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);
/* /*
* Bind the resources to their Uri-Path. * Bind the resources to their Uri-Path.
* WARNING: Activating twice only means alternate path, not two instances! * WARNING: Activating twice only means alternate path, not two instances!
* All static variables are the same for each URI path. * All static variables are the same for each URI path.
*/ */
coap_activate_resource(&res_hello, "test/hello"); coap_activate_resource(&res_hello, "test/hello");
coap_activate_resource(&res_mirror, "debug/mirror"); coap_activate_resource(&res_mirror, "debug/mirror");
coap_activate_resource(&res_chunks, "test/chunks"); coap_activate_resource(&res_chunks, "test/chunks");
coap_activate_resource(&res_separate, "test/separate"); coap_activate_resource(&res_separate, "test/separate");
coap_activate_resource(&res_push, "test/push"); coap_activate_resource(&res_push, "test/push");
#if PLATFORM_HAS_BUTTON #if PLATFORM_HAS_BUTTON
coap_activate_resource(&res_event, "sensors/button"); coap_activate_resource(&res_event, "sensors/button");
#endif /* PLATFORM_HAS_BUTTON */ #endif /* PLATFORM_HAS_BUTTON */
coap_activate_resource(&res_sub, "test/sub"); coap_activate_resource(&res_sub, "test/sub");
coap_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); coap_activate_resource(&res_b1_sep_b2, "test/b1sepb2");
#if PLATFORM_HAS_LEDS #if PLATFORM_HAS_LEDS
/* coap_activate_resource(&res_leds, "actuators/leds"); */ /* coap_activate_resource(&res_leds, "actuators/leds"); */
coap_activate_resource(&res_toggle, "actuators/toggle"); 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"); coap_activate_resource(&res_temperature, "sensors/temperature");
SENSORS_ACTIVATE(temperature_sensor); SENSORS_ACTIVATE(temperature_sensor);
#endif #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. */ /* Define application-specific events here. */
while(1) { while(1) {
@ -162,7 +133,7 @@ PROCESS_THREAD(er_example_server, ev, data)
#else #else
if(ev == sensors_event && data == &button_sensor) { if(ev == sensors_event && data == &button_sensor) {
#endif #endif
PRINTF("*******BUTTON*******\n"); LOG_DBG("*******BUTTON*******\n");
/* Call the event_handler for this application-specific event. */ /* Call the event_handler for this application-specific event. */
res_event.trigger(); res_event.trigger();

View File

@ -36,33 +36,9 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch> * Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/ */
#ifndef PROJECT_ERBIUM_CONF_H_ #ifndef PROJECT_CONF_H_
#define PROJECT_ERBIUM_CONF_H_ #define PROJECT_CONF_H_
/* IP buffer size must match all other hops, in particular the border router. */ #define LOG_LEVEL_APP LOG_LEVEL_DBG
/* #define UIP_CONF_BUFFER_SIZE 256 */
/* Increase rpl-border-router IP-buffer when using more than 64. */ #endif /* PROJECT_CONF_H_ */
#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_ */

View File

@ -41,17 +41,10 @@
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.h" #include "coap.h"
#define DEBUG 0 /* Log configuration */
#if DEBUG #include "sys/log.h"
#include <stdio.h> #define LOG_MODULE "App"
#define PRINTF(...) printf(__VA_ARGS__) #define LOG_LEVEL LOG_LEVEL_APP
#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
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_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); 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. */ /* Usually a condition is defined under with subscribers are notified, e.g., event was above a threshold. */
if(1) { 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. */ /* Notify the registered observers which will trigger the res_get_handler to create the response. */
coap_notify_observers(&res_event); coap_notify_observers(&res_event);

View File

@ -75,7 +75,9 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
memcpy(buffer, message, length); memcpy(buffer, message, length);
} else { } else {
memcpy(buffer, message, length); 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_header_etag(response, (uint8_t *)&length, 1);
coap_set_payload(response, buffer, length); coap_set_payload(response, buffer, length);
} }

View File

@ -44,17 +44,10 @@
#if PLATFORM_HAS_LEDS || LEDS_COUNT #if PLATFORM_HAS_LEDS || LEDS_COUNT
#define DEBUG 0 /* Log configuration */
#if DEBUG #include "sys/log.h"
#include <stdio.h> #define LOG_MODULE "App"
#define PRINTF(...) printf(__VA_ARGS__) #define LOG_LEVEL LOG_LEVEL_APP
#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
static void res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); 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; int success = 1;
if((len = coap_get_query_variable(request, "color", &color))) { 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) { if(strncmp(color, "r", len) == 0) {
led = LEDS_RED; led = LEDS_RED;
@ -90,7 +83,7 @@ res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t
} else { } else {
success = 0; success = 0;
} if(success && (len = coap_get_post_variable(request, "mode", &mode))) { } 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) { if(strncmp(mode, "on", len) == 0) {
leds_on(led); leds_on(led);

View File

@ -41,17 +41,10 @@
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.h" #include "coap.h"
#define DEBUG 0 /* Log configuration */
#if DEBUG #include "sys/log.h"
#include <stdio.h> #define LOG_MODULE "App"
#define PRINTF(...) printf(__VA_ARGS__) #define LOG_LEVEL LOG_LEVEL_APP
#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
static void res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); 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); 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. */ /* 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_content_format(response, TEXT_PLAIN);

View File

@ -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

View File

@ -45,7 +45,11 @@
#include "coap-transactions.h" #include "coap-transactions.h"
#include "coap-separate.h" #include "coap-separate.h"
#include "coap-engine.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. * Resources to be activated need to be imported through the extern keyword.
@ -80,12 +84,7 @@ PROCESS_THREAD(plugtest_server, ev, data)
{ {
PROCESS_BEGIN(); PROCESS_BEGIN();
PRINTF("ETSI IoT CoAP Plugtests Server\n"); LOG_INFO("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);
/* Activate the application-specific resources. */ /* Activate the application-specific resources. */
coap_activate_resource(&res_plugtest_test, "test"); coap_activate_resource(&res_plugtest_test, "test");

View File

@ -36,20 +36,10 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch> * Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/ */
#ifndef PLUGTEST_H_ #ifndef PROJECT_CONF_H_
#define PLUGTEST_H_ #define PROJECT_CONF_H_
#if !defined(CONTIKI_TARGET_NATIVE) #define LOG_LEVEL_PLUGTEST LOG_LEVEL_DBG
#warning "Should only be compiled for native!"
#endif
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/* double expansion */ /* double expansion */
#define TO_STRING2(x) # x #define TO_STRING2(x) # x
@ -59,4 +49,4 @@
#define MAX_PLUGFEST_BODY 2048 #define MAX_PLUGFEST_BODY 2048
#define CHUNKS_TOTAL 2012 #define CHUNKS_TOTAL 2012
#endif /* PLUGTEST_H_ */ #endif /* PROJECT_CONF_H_ */

View File

@ -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 <kovatsch@inf.ethz.ch>
*/
#include <stdio.h>
#include <string.h>
#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);
}

View File

@ -39,7 +39,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_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); 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 static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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(coap_get_header_if_none_match(request)) {
if(!create1_exists) { if(!create1_exists) {
@ -73,7 +77,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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); coap_set_status_code(response, DELETED_2_02);
create1_exists = 0; create1_exists = 0;

View File

@ -39,7 +39,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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); 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 static void
res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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_status_code(response, CREATED_2_01);
coap_set_header_location_path(response, "/location1/location2/location3"); coap_set_header_location_path(response, "/location1/location2/location3");

View File

@ -39,7 +39,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_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); 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 static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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(coap_get_header_if_none_match(request)) {
if(!create3_exists) { if(!create3_exists) {
@ -73,7 +77,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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); coap_set_status_code(response, DELETED_2_02);
create3_exists = 0; create3_exists = 0;

View File

@ -39,7 +39,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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); static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -41,7 +41,11 @@
#include "sys/cc.h" #include "sys/cc.h"
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_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); static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -40,7 +40,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -39,7 +39,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -39,7 +39,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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); 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 static void
res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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; 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); "/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); coap_set_status_code(response, CREATED_2_01);

View File

@ -41,7 +41,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_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; 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. */ /* Code 2.05 CONTENT is default. */
coap_set_header_content_format(response, TEXT_PLAIN); coap_set_header_content_format(response, TEXT_PLAIN);
coap_set_payload( 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, snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD,
"Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid)); "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);
} }

View File

@ -40,7 +40,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_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; unsigned int accept = -1;
coap_get_header_accept(request, &accept); 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) { if(accept == -1 || accept == TEXT_PLAIN) {
coap_set_header_content_format(response, 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, snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD,
"Type: %u\nCode: %u\nMID: %u%s", coap_req->type, coap_req->code, "Type: %u\nCode: %u\nMID: %u%s", coap_req->type, coap_req->code,
coap_req->mid, accept != -1 ? "\nAccept: 0" : "")); coap_req->mid, accept != -1 ? "\nAccept: 0" : ""));
PRINTF("PLAIN\n"); LOG_DBG_("PLAIN\n");
} else if(accept == APPLICATION_XML) { } else if(accept == APPLICATION_XML) {
coap_set_header_content_format(response, APPLICATION_XML); coap_set_header_content_format(response, APPLICATION_XML);
coap_set_payload( 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, snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD,
"<status type=\"%u\" code=\"%u\" mid=\"%u\" accept=\"%u\"/>", "<status type=\"%u\" code=\"%u\" mid=\"%u\" accept=\"%u\"/>",
coap_req->type, coap_req->code, coap_req->mid, accept)); coap_req->type, coap_req->code, coap_req->mid, accept));
PRINTF("XML\n"); LOG_DBG_("XML\n");
} else { } else {
coap_set_status_code(response, NOT_ACCEPTABLE_4_06); coap_set_status_code(response, NOT_ACCEPTABLE_4_06);
const char *msg = "Supporting content-types text/plain and application/xml"; const char *msg = "Supporting content-types text/plain and application/xml";
coap_set_payload(response, msg, strlen(msg)); coap_set_payload(response, msg, strlen(msg));
PRINTF("ERROR\n"); LOG_DBG_("ERROR\n");
} }
} }

View File

@ -41,7 +41,11 @@
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.h" #include "coap.h"
#include "coap-observe.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_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); 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 static void
obs_purge_list() 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); coap_remove_observer_by_uri(NULL, res_plugtest_obs.url);
} }
static void 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 */ /* Keep server log clean from ticking events */
if(request != NULL) { if(request != NULL) {
PRINTF("/obs GET\n"); LOG_DBG("/obs GET\n");
} }
coap_set_header_content_format(response, obs_format); coap_set_header_content_format(response, obs_format);
coap_set_header_max_age(response, 5); 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); coap_get_header_content_format(request, &ct);
PRINTF("/obs PUT\n"); LOG_DBG("/obs PUT\n");
if(ct != obs_format) { if(ct != obs_format) {
obs_status = 1; obs_status = 1;
@ -115,7 +119,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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; obs_status = 2;
@ -130,14 +134,12 @@ res_periodic_handler()
{ {
++obs_counter; ++obs_counter;
/* PRINTF("TICK %u for /%s\n", obs_counter, r->url); */
if(obs_status == 1) { if(obs_status == 1) {
/* Notify the registered observers with the given message type, observe option, and payload. */ /* Notify the registered observers with the given message type, observe option, and payload. */
coap_notify_observers(&res_plugtest_obs); coap_notify_observers(&res_plugtest_obs);
PRINTF("######### sending 5.00\n"); LOG_DBG("######### sending 5.00\n");
obs_purge_list(); obs_purge_list();
} else if(obs_status == 2) { } else if(obs_status == 2) {

View File

@ -40,7 +40,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -40,7 +40,11 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.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_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; int len = 0;
const char *query = NULL; const char *query = NULL;
PRINTF( LOG_DBG(
"/query GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); "/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))) { 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. */ /* Code 2.05 CONTENT is default. */
} }
coap_set_header_content_format(response, coap_set_header_content_format(response,

View File

@ -42,7 +42,11 @@
#include "coap.h" #include "coap.h"
#include "coap-transactions.h" #include "coap-transactions.h"
#include "coap-separate.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_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); 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; coap_message_t *const coap_req = (coap_message_t *)request;
PRINTF("/separate "); LOG_DBG("/separate ");
if(separate_active) { if(separate_active) {
PRINTF("REJECTED "); LOG_DBG_("REJECTED ");
coap_separate_reject(); coap_separate_reject();
} else { } else {
PRINTF("STORED "); LOG_DBG_("STORED ");
separate_active = 1; separate_active = 1;
/* Take over and skip response by engine. */ /* 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); 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 static void
res_resume_handler() res_resume_handler()
{ {
if(separate_active) { if(separate_active) {
PRINTF("/separate "); LOG_DBG("/separate ");
coap_transaction_t *transaction = NULL; coap_transaction_t *transaction = NULL;
if((transaction = coap_new_transaction(separate_store->request_metadata.mid, if((transaction = coap_new_transaction(separate_store->request_metadata.mid,
&separate_store->request_metadata.endpoint))) { &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); "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. */ 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; separate_active = 0;
} else { } else {
PRINTF("ERROR (transaction)\n"); LOG_DBG_("ERROR (transaction)\n");
} }
} /* if (separate_active) */ } /* if (separate_active) */
} }

View File

@ -40,9 +40,13 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.h" #include "coap.h"
#include "plugtest.h"
#include "random.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_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_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); 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; 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 static void
res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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) { if(test_change) {
test_update_etag(); 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 if((len = coap_get_header_etag(request, &bytes)) > 0
&& len == test_etag_len && len == test_etag_len
&& memcmp(test_etag, bytes, len) == 0) { && memcmp(test_etag, bytes, len) == 0) {
PRINTF("validate "); LOG_DBG("validate\n");
coap_set_status_code(response, VALID_2_03); coap_set_status_code(response, VALID_2_03);
coap_set_header_etag(response, test_etag, test_etag_len); coap_set_header_etag(response, test_etag, test_etag_len);
test_change = 1; test_change = 1;
PRINTF("### SERVER ACTION ### Resource will change\n"); LOG_DBG("### SERVER ACTION ### Resource will change\n");
} else { } else {
/* Code 2.05 CONTENT is default. */ /* Code 2.05 CONTENT is default. */
coap_set_header_content_format(response, TEXT_PLAIN); 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 static void
res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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;
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);
PRINTF("/test POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
#endif
coap_set_status_code(response, CREATED_2_01); coap_set_status_code(response, CREATED_2_01);
coap_set_header_location_path(response, "/location1/location2/location3"); coap_set_header_location_path(response, "/location1/location2/location3");
} }
static void static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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; 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); LOG_DBG("/test PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
#endif
if(coap_get_header_if_none_match(request)) { if(coap_get_header_if_none_match(request)) {
if(test_none_match_okay) { if(test_none_match_okay) {
coap_set_status_code(response, CREATED_2_01); coap_set_status_code(response, CREATED_2_01);
test_none_match_okay = 0; 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 { } else {
coap_set_status_code(response, PRECONDITION_FAILED_4_12); coap_set_status_code(response, PRECONDITION_FAILED_4_12);
test_none_match_okay = 1; 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 } else if(((len = coap_get_header_if_match(request, &bytes)) > 0
&& (len == test_etag_len && (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) { if(len > 0) {
test_change = 1; test_change = 1;
PRINTF("### SERVER ACTION ### Resource will change\n"); LOG_DBG("### SERVER ACTION ### Resource will change\n");
} }
} else { } 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", 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",
len, (unsigned)len,
test_etag_len, (unsigned)test_etag_len,
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], 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]); 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 static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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; 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); LOG_DBG("/test DELETE (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
#endif
coap_set_status_code(response, DELETED_2_02); coap_set_status_code(response, DELETED_2_02);
} }

View File

@ -40,9 +40,13 @@
#include <string.h> #include <string.h>
#include "coap-engine.h" #include "coap-engine.h"
#include "coap.h" #include "coap.h"
#include "plugtest.h"
#include "random.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_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); 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; 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]); 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 static void
@ -81,17 +85,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
if(validate_change) { if(validate_change) {
validate_update_etag(); validate_update_etag();
} }
PRINTF("/validate GET"); LOG_DBG("/validate GET");
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);
if((len = coap_get_header_etag(request, &bytes)) > 0 if((len = coap_get_header_etag(request, &bytes)) > 0
&& len == validate_etag_len && memcmp(validate_etag, bytes, len) == 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_status_code(response, VALID_2_03);
coap_set_header_etag(response, validate_etag, validate_etag_len); coap_set_header_etag(response, validate_etag, validate_etag_len);
validate_change = 1; validate_change = 1;
PRINTF("### SERVER ACTION ### Resouce will change\n"); LOG_DBG("### SERVER ACTION ### Resouce will change\n");
} else { } else {
/* Code 2.05 CONTENT is default. */ /* Code 2.05 CONTENT is default. */
coap_set_header_content_format(response, TEXT_PLAIN); 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 static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) 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; coap_message_t *const coap_req = (coap_message_t *)request;
#endif
PRINTF("/validate PUT "); LOG_DBG("/validate PUT ");
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);
if(((len = coap_get_header_if_match(request, &bytes)) > 0 if(((len = coap_get_header_if_match(request, &bytes)) > 0
&& (len == validate_etag_len && (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) { if(len > 0) {
validate_change = 1; validate_change = 1;
PRINTF("### SERVER ACTION ### Resouce will change\n"); LOG_DBG("### SERVER ACTION ### Resouce will change\n");
} }
} else { } else {
PRINTF( 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] ", "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, (unsigned)len,
validate_etag_len, (unsigned)validate_etag_len,
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], 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]); validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]);

View File

@ -3,6 +3,6 @@ CONTIKI = ../../..
all: $(CONTIKI_PROJECT) all: $(CONTIKI_PROJECT)
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native
include $(CONTIKI)/Makefile.include include $(CONTIKI)/Makefile.include

View File

@ -47,10 +47,13 @@ PROCESS_THREAD(button_hal_example, ev, data)
printf("Button HAL example.\n"); printf("Button HAL example.\n");
printf("Device button count: %u.\n", button_hal_button_count); 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, if(btn) {
btn->negative_logic ? "Negative" : "Positive", printf("%s on pin %u with ID=0, Logic=%s, Pull=%s\n",
btn->pull == GPIO_HAL_PIN_CFG_PULL_UP ? "Pull Up" : "Pull Down"); 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) { while(1) {

View File

@ -1,7 +1,7 @@
CONTIKI_PROJECT = gpio-hal-example CONTIKI_PROJECT = gpio-hal-example
CONTIKI = ../../.. CONTIKI = ../../..
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native
include $(CONTIKI)/Makefile.identify-target include $(CONTIKI)/Makefile.identify-target

View File

@ -36,6 +36,7 @@
#include "dev/button-hal.h" #include "dev/button-hal.h"
#include <stdio.h> #include <stdio.h>
#include <inttypes.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3; extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3;
extern gpio_hal_pin_t btn_pin; extern gpio_hal_pin_t btn_pin;
@ -43,6 +44,13 @@ extern gpio_hal_pin_t btn_pin;
static struct etimer et; static struct etimer et;
static uint8_t counter; 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"); PROCESS(gpio_hal_example, "GPIO HAL Example");
AUTOSTART_PROCESSES(&gpio_hal_example); AUTOSTART_PROCESSES(&gpio_hal_example);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -119,7 +127,8 @@ PROCESS_THREAD(gpio_hal_example, ev, data)
} }
/* Test read */ /* 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_pin1),
gpio_hal_arch_read_pin(out_pin2), gpio_hal_arch_read_pin(out_pin2),
gpio_hal_arch_read_pin(out_pin3), gpio_hal_arch_read_pin(out_pin3),

View File

@ -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;
/*---------------------------------------------------------------------------*/

View File

@ -46,10 +46,21 @@ AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data) PROCESS_THREAD(hello_world_process, ev, data)
{ {
static struct etimer timer;
PROCESS_BEGIN(); PROCESS_BEGIN();
printf("Hello, world\n"); /* Setup a periodic timer that expires after 10 seconds. */
etimer_set(&timer, CLOCK_SECOND * 10);
while(1) {
printf("Hello, world\n");
/* Wait for the periodic timer to expire and then restart the timer. */
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
etimer_reset(&timer);
}
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -1,27 +0,0 @@
CONTIKI_PROJECT = example-ipso-objects
CONTIKI_SOURCEFILES += serial-protocol.c example-ipso-temperature.c
PLATFORMS_EXCLUDE = sky
all: $(CONTIKI_PROJECT)
MODULES += os/net/app-layer/coap
MODULES += os/services/lwm2m
MODULES += os/services/ipso-objects
CONTIKI=../..
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 aaaa::1/64
connect-router-cooja: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 -p 60001 aaaa::1/64
connect-router-native: $(CONTIKI)/examples/native-border-router/border-router.native
sudo $(CONTIKI)/examples/native-border-router/border-router.native -a 127.0.0.1 -p 60001 aaaa::1/64

View File

@ -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.

View File

@ -1,5 +1,5 @@
CONTIKI_PROJECT = ipv6-hooks CONTIKI_PROJECT = ipv6-hooks
all: $(CONTIKI_PROJECT) all: $(CONTIKI_PROJECT)
CONTIKI=../.. CONTIKI=../../..
include $(CONTIKI)/Makefile.include include $(CONTIKI)/Makefile.include

View File

@ -36,9 +36,9 @@
* *
*/ */
#ifndef __PROJECT_CONF_H__ #ifndef PROJECT_CONF_H_
#define __PROJECT_CONF_H__ #define PROJECT_CONF_H_
#define STACK_CHECK_CONF_ENABLED 1 #define STACK_CHECK_CONF_ENABLED 1
#endif /* __PROJECT_CONF_H__ */ #endif /* PROJECT_CONF_H_ */

View File

@ -0,0 +1,14 @@
CONTIKI_PROJECT = example-ipso-objects
CONTIKI_SOURCEFILES += serial-protocol.c example-ipso-temperature.c
PLATFORMS_EXCLUDE = sky
all: $(CONTIKI_PROJECT)
MODULES += os/net/app-layer/coap
MODULES += os/services/lwm2m
MODULES += os/services/ipso-objects
CONTIKI=../..
include $(CONTIKI)/Makefile.include

View File

@ -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 parameters:
* `LWM2M_SERVER_ADDRESS`: the address of the server to register to (or bootstrap 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.

View File

@ -38,19 +38,23 @@
#include "contiki.h" #include "contiki.h"
#include "net/ipv6/uip.h" #include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/netstack.h" #include "net/netstack.h"
#include "net/routing/routing.h" #include "net/routing/routing.h"
#include "coap-constants.h" #include "coap-transport.h"
#include "coap-engine.h" #include "coap-blocking-api.h"
#include "lwm2m-engine.h" #include "lwm2m-engine.h"
#include "lwm2m-tlv.h" #include "lwm2m-tlv.h"
#include "dev/serial-line.h" #include "dev/serial-line.h"
#include "serial-protocol.h" #include "serial-protocol.h"
#include <stdbool.h>
#define DEBUG DEBUG_PRINT #define DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h" #include "net/ipv6/uip-debug.h"
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT) #define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
#define EVENT_RUN_NOW 0
#define URL_WELL_KNOWN ".well-known/core" #define URL_WELL_KNOWN ".well-known/core"
#define URL_DEVICE_MODEL "/3/0/1" #define URL_DEVICE_MODEL "/3/0/1"
@ -63,8 +67,8 @@
#define NODE_HAS_TYPE (1 << 0) #define NODE_HAS_TYPE (1 << 0)
struct node { struct node {
uip_ipaddr_t ipaddr; coap_endpoint_t endpoint;
char type[32]; char type[64];
uint8_t flags; uint8_t flags;
uint8_t retries; uint8_t retries;
}; };
@ -86,13 +90,15 @@ add_node(const uip_ipaddr_t *addr)
{ {
int i; int i;
for(i = 0; i < node_count; i++) { for(i = 0; i < node_count; i++) {
if(uip_ipaddr_cmp(&nodes[i].ipaddr, addr)) { if(uip_ipaddr_cmp(&nodes[i].endpoint.ipaddr, addr)) {
/* Node already added */ /* Node already added */
return &nodes[i]; return &nodes[i];
} }
} }
if(node_count < MAX_NODES) { if(node_count < MAX_NODES) {
uip_ipaddr_copy(&nodes[node_count].ipaddr, addr); memset(&nodes[node_count].endpoint, 0, sizeof(coap_endpoint_t));
uip_ipaddr_copy(&nodes[node_count].endpoint.ipaddr, addr);
nodes[node_count].endpoint.port = REMOTE_PORT;
return &nodes[node_count++]; return &nodes[node_count++];
} }
return NULL; return NULL;
@ -107,13 +113,13 @@ set_value(const uip_ipaddr_t *addr, char *uri, char *value)
printf(" URI: %s Value: %s\n", uri, value); printf(" URI: %s Value: %s\n", uri, value);
for(i = 0; i < node_count; i++) { for(i = 0; i < node_count; i++) {
if(uip_ipaddr_cmp(&nodes[i].ipaddr, addr)) { if(uip_ipaddr_cmp(&nodes[i].endpoint.ipaddr, addr)) {
/* setup command */ /* setup command */
current_target = &nodes[i]; current_target = &nodes[i];
current_request = COAP_PUT; current_request = COAP_PUT;
strncpy(current_uri, uri, sizeof(current_uri) - 1); strncpy(current_uri, uri, sizeof(current_uri) - 1);
strncpy(current_value, value, sizeof(current_value) - 1); strncpy(current_value, value, sizeof(current_value) - 1);
process_poll(&router_process); process_post(&router_process, EVENT_RUN_NOW, NULL);
break; break;
} }
} }
@ -128,13 +134,13 @@ get_value(const uip_ipaddr_t *addr, char *uri)
printf(" URI: %s\n", uri); printf(" URI: %s\n", uri);
for(i = 0; i < node_count; i++) { for(i = 0; i < node_count; i++) {
if(uip_ipaddr_cmp(&nodes[i].ipaddr, addr)) { if(uip_ipaddr_cmp(&nodes[i].endpoint.ipaddr, addr)) {
/* setup command */ /* setup command */
current_target = &nodes[i]; current_target = &nodes[i];
current_request = COAP_GET; current_request = COAP_GET;
strncpy(current_uri, uri, sizeof(current_uri) - 1); strncpy(current_uri, uri, sizeof(current_uri) - 1);
current_value[0] = 0; current_value[0] = 0;
process_poll(&router_process); process_post(&router_process, EVENT_RUN_NOW, NULL);
break; break;
} }
} }
@ -151,7 +157,7 @@ print_node_list(void)
printf(";"); printf(";");
} }
printf("%s,", nodes[i].type); printf("%s,", nodes[i].type);
uip_debug_ipaddr_print(&nodes[i].ipaddr); uip_debug_ipaddr_print(&nodes[i].endpoint.ipaddr);
} }
} }
printf("\n"); printf("\n");
@ -162,7 +168,7 @@ print_node_list(void)
* handle responses. * handle responses.
*/ */
static void static void
client_chunk_handler(void *response) client_chunk_handler(coap_message_t *response)
{ {
const uint8_t *chunk; const uint8_t *chunk;
unsigned int format; unsigned int format;
@ -172,7 +178,9 @@ client_chunk_handler(void *response)
/* if(len > 0) { */ /* if(len > 0) { */
/* printf("|%.*s (%d,%d)", len, (char *)chunk, len, format); */ /* printf("|%.*s (%d,%d)", len, (char *)chunk, len, format); */
/* } */ /* } */
if(current_target != NULL && fetching_type) { if(response->code >= BAD_REQUEST_4_00) {
PRINTF("\nReceived error %u: %.*s\n", response->code, len, (char *)chunk);
} else if(current_target != NULL && fetching_type) {
if(len > sizeof(current_target->type) - 1) { if(len > sizeof(current_target->type) - 1) {
len = sizeof(current_target->type) - 1; len = sizeof(current_target->type) - 1;
} }
@ -181,7 +189,7 @@ client_chunk_handler(void *response)
current_target->flags |= NODE_HAS_TYPE; current_target->flags |= NODE_HAS_TYPE;
PRINTF("\nNODE "); PRINTF("\nNODE ");
PRINT6ADDR(&current_target->ipaddr); PRINT6ADDR(&current_target->endpoint.ipaddr);
PRINTF(" HAS TYPE %s\n", current_target->type); PRINTF(" HAS TYPE %s\n", current_target->type);
} else { } else {
/* otherwise update the current value */ /* otherwise update the current value */
@ -193,7 +201,9 @@ client_chunk_handler(void *response)
/* tlv.type, tlv.length, tlv.id, tlv.value[0]); */ /* tlv.type, tlv.length, tlv.id, tlv.value[0]); */
int value = lwm2m_tlv_get_int32(&tlv); int value = lwm2m_tlv_get_int32(&tlv);
snprintf(current_value, sizeof(current_value), "%d", value); snprintf(current_value, sizeof(current_value) - 1, "%d", value);
} else {
PRINTF("Failed to parse LWM2M TLV\n");
} }
} else { } else {
if(len > sizeof(current_value) - 1) { if(len > sizeof(current_value) - 1) {
@ -205,69 +215,81 @@ client_chunk_handler(void *response)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void #if UIP_CONF_IPV6_RPL
setup_network(void) static bool
check_rpl_routes(void)
{ {
uip_ipaddr_t ipaddr; uip_sr_node_t *link;
struct uip_ds6_addr *root_if; uip_ipaddr_t child_ipaddr;
rpl_dag_t *dag; uip_ipaddr_t parent_ipaddr;
int i;
uint8_t state;
#if UIP_CONF_ROUTER /* Our routing links */
/** for(link = uip_sr_node_head(); link != NULL; link = uip_sr_node_next(link)) {
* The choice of server address determines its 6LoWPAN header compression. NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link);
* Obviously the choice made here must also be selected in udp-client.c.
*
* For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences,
* e.g. set Context 0 to fd00::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to fd00::1111:2222:3333:4444 will report a 16 bit compressed address of fd00::1111:22ff:fe33:xxxx)
* Note Wireshark's IPCMV6 checksum verification depends on the correct uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
NETSTACK_ROUTING.root_set_prefix(&ipaddr, &ipaddr); if(link->parent == NULL) {
NETSTACK_ROUTING.root_start(); /* Igore the DAG root */
#endif /* UIP_CONF_ROUTER */ continue;
PRINTF("IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(state == ADDR_TENTATIVE || state == ADDR_PREFERRED) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n");
/* hack to make address "final" */
if (state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
}
} }
current_target = add_node(&child_ipaddr);
if(current_target == NULL ||
(current_target->flags & NODE_HAS_TYPE) != 0 ||
current_target->retries > 5) {
continue;
}
NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent);
PRINTF(" ");
PRINT6ADDR(&child_ipaddr);
PRINTF(" -> ");
PRINT6ADDR(&parent_ipaddr);
PRINTF("\n");
return true;
} }
return false;
} }
#endif /* UIP_CONF_IPV6_RPL */
/*---------------------------------------------------------------------------*/
#if (UIP_MAX_ROUTES != 0)
static bool
check_routes(void)
{
uip_ds6_route_t *r;
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
current_target = add_node(&r->ipaddr);
if(current_target == NULL ||
(current_target->flags & NODE_HAS_TYPE) != 0 ||
current_target->retries > 5) {
continue;
}
PRINTF(" ");
PRINT6ADDR(&r->ipaddr);
PRINTF(" -> ");
nexthop = uip_ds6_route_nexthop(r);
if(nexthop != NULL) {
PRINT6ADDR(nexthop);
} else {
PRINTF("-");
}
PRINTF("\n");
return true;
}
return false;
}
#endif /* (UIP_MAX_ROUTES != 0) */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(router_process, ev, data) PROCESS_THREAD(router_process, ev, data)
{ {
/* This way the message can be treated as pointer as usual. */ /* This way the message can be treated as pointer as usual. */
static coap_message_t request[1]; static coap_message_t request[1];
static struct etimer timer; static struct etimer timer;
uip_ds6_route_t *r;
uip_ipaddr_t *nexthop;
int n;
PROCESS_BEGIN(); PROCESS_BEGIN();
PROCESS_PAUSE(); /* Initialize DAG root */
NETSTACK_ROUTING.root_start();
setup_network();
while(1) { while(1) {
etimer_set(&timer, CLOCK_SECOND * 5); etimer_set(&timer, CLOCK_SECOND * 5);
@ -280,28 +302,15 @@ PROCESS_THREAD(router_process, ev, data)
if(etimer_expired(&timer)) { if(etimer_expired(&timer)) {
current_target = NULL; current_target = NULL;
n = 0; #if UIP_CONF_IPV6_RPL
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) { check_rpl_routes();
current_target = add_node(&r->ipaddr); #endif /* UIP_CONF_IPV6_RPL */
if(current_target == NULL ||
(current_target->flags & NODE_HAS_TYPE) != 0 || #if (UIP_MAX_ROUTES != 0)
current_target->retries > 5) { if(current_target == NULL) {
continue; check_routes();
}
PRINTF(" ");
PRINT6ADDR(&r->ipaddr);
PRINTF(" -> ");
nexthop = uip_ds6_route_nexthop(r);
if(nexthop != NULL) {
PRINT6ADDR(nexthop);
PRINTF("\n");
} else {
PRINTF("-");
}
PRINTF("\n");
n++;
break;
} }
#endif /* (UIP_MAX_ROUTES != 0) */
} }
/* This is a node type discovery */ /* This is a node type discovery */
@ -316,15 +325,15 @@ PROCESS_THREAD(router_process, ev, data)
current_target->retries++; current_target->retries++;
PRINTF("CoAP request to ["); PRINTF("CoAP request to [");
PRINT6ADDR(&current_target->ipaddr); PRINT6ADDR(&current_target->endpoint.ipaddr);
PRINTF("]:%u (%u tx)\n", UIP_HTONS(REMOTE_PORT), PRINTF("]:%u (%u tx)\n", UIP_HTONS(current_target->endpoint.port),
current_target->retries); current_target->retries);
fetching_type = 1; fetching_type = 1;
COAP_BLOCKING_REQUEST(&current_target->ipaddr, REMOTE_PORT, request, COAP_BLOCKING_REQUEST(&current_target->endpoint, request,
client_chunk_handler); client_chunk_handler);
fetching_type = 0; fetching_type = 0;
strncpy(current_uri, URL_LIGHT_CONTROL, sizeof(current_uri)); strncpy(current_uri, URL_LIGHT_CONTROL, sizeof(current_uri) - 1);
printf("\n--Done--\n"); printf("\n--Done--\n");
} }
@ -341,10 +350,11 @@ PROCESS_THREAD(router_process, ev, data)
} }
PRINTF("CoAP request to ["); PRINTF("CoAP request to [");
PRINT6ADDR(&current_target->ipaddr); PRINT6ADDR(&current_target->endpoint.ipaddr);
PRINTF("]:%u %s\n", UIP_HTONS(REMOTE_PORT), current_uri); PRINTF("]:%u %s\n", UIP_HTONS(current_target->endpoint.port),
current_uri);
COAP_BLOCKING_REQUEST(&current_target->ipaddr, REMOTE_PORT, request, COAP_BLOCKING_REQUEST(&current_target->endpoint, request,
client_chunk_handler); client_chunk_handler);
/* print out result of command */ /* print out result of command */
@ -353,13 +363,12 @@ PROCESS_THREAD(router_process, ev, data)
} else { } else {
printf("g "); printf("g ");
} }
uip_debug_ipaddr_print(&current_target->ipaddr); uip_debug_ipaddr_print(&current_target->endpoint.ipaddr);
printf(" %s %s\n", current_uri, current_value); printf(" %s %s\n", current_uri, current_value);
current_target = NULL; current_target = NULL;
current_uri[0] = 0; current_uri[0] = 0;
current_value[0] = 0; current_value[0] = 0;
} }
} }

View File

@ -60,7 +60,7 @@ find_next_sep(const char *str, char sep, int pos)
/* /*
* l - list all discovered devices * l - list all discovered devices
* s - set <IP> <URI> <value> * s - set <IP> <URI> <value>
* d - get <IP> <URI> * g - get <IP> <URI>
*/ */
void void
serial_protocol_input(char *data) serial_protocol_input(char *data)
@ -119,8 +119,12 @@ serial_protocol_input(char *data)
} }
break; break;
} }
case '\0':
/* Ignore empty lines */
break;
default: default:
printf("Unknown command\n"); printf("Unknown command\n");
} }
printf("> ");
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -8,6 +8,6 @@ CONTIKI = ../..
MODULES_REL += arch/platform/$(TARGET) 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 include $(CONTIKI)/Makefile.include

Some files were not shown because too many files have changed in this diff Show More