Adding the avr-rss2 platform based on AtMega256RFR2

This commit is contained in:
Robert Olsson 2016-02-22 20:46:07 +01:00
parent d3980668ee
commit ce8e87d60e
91 changed files with 9349 additions and 0 deletions

View file

@ -0,0 +1,49 @@
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
all: coap-client coap-server
APPS=servreg-hack
CONTIKI=../../../../..
ifdef WITH_COMPOWER
APPS+=powertrace
CFLAGS+= -DCONTIKIMAC_CONF_COMPOWER=1 -DWITH_COMPOWER=1 -DQUEUEBUF_CONF_NUM=4
endif
ifdef SERVER_REPLY
CFLAGS+=-DSERVER_REPLY=$(SERVER_REPLY)
endif
ifdef PERIOD
CFLAGS+=-DPERIOD=$(PERIOD)
endif
### -------------------------------------------------------- ###
#CONTIKI_TARGET_SOURCEFILES += control.c vdc.c
# automatically build RESTful resources
REST_RESOURCES_DIR = ./resources
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c'))
DC_SENSOR_DIR = ./dev
DC_SENSOR_FILES = $(notdir $(shell find $(DC_SENSOR_DIR) -name '*.c'))
PROJECTDIRS += $(REST_RESOURCES_DIR) $(DC_SENSOR_DIR)
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES) $(DC_SENSOR_FILES)
# linker optimizations
SMALL=1
# REST Engine shall use Erbium CoAP implementation
APPS += er-coap
APPS += rest-engine
#CFLAGS += -DUIP_CONF_BUFFER_SIZE=384
CFLAGS += -DREST_MAX_CHUNK_SIZE=128
CFLAGS += -DCOAP_MAX_HEADER_SIZE=64
CFLAGS += -DUIP_CONF_TCP=0
### -------------------------------------------------------- ###
CONTIKI_WITH_IPV6 = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,67 @@
Example: mockup of DC converter functionality for IoT-grid.
===========================================
This example imitates DC converter functionality for IoT-grid.
We use standard IoT protocol stack with CoAP application-level protocol.
The settings are as follows.
* APPLICATION: CoAP
* TRANSPORT: UDP
* NETWORK: IPv6/RPL
* ADAPTATION: 6LoWPAN
* MAC: nullmac_driver
* RADIO DUTY CYCLE: nullrdc_driver
* PHYSICAL: IEEE 802.15.4
CoAP resources
----------------
We define a CoAP resource for each functionality of DC converter.
Since each functionality may have several parameters, we define each resource
as a vector of parameters as follows.
* /dcdc/status read-only parameters for power monitoring.
It also support periodic monitoring through CoAP observe option.
** 0 VOUT Output voltage
** 1 VIN Input voltage
** 2 IOUT Output current
** 3 IIN Input current
* /dcdc/vdc configurable parameters for voltage droop control function.
** 0 VGRID Desired grid output voltage
** 1 SLOPE Slope of voltage droop control function
** 2 PMAX Maximum output power allowed
* /dcdc/hwcfg configurable parameters for DC converter hardware.
** 0 VMAX Maximum output voltage allowed
** 1 IMAX Maximum output current allowed
Each functionality is implemented as a sensor type device.
They are located in "dev" folder.
* dc-status-sensor for /dcdc/status
* dc-vdc-sensor for /dcdc/vdc
* dc-hw-sensor for /dcdc/hwcfg
The corresponding CoAP handler for each resource is defined in "resources" folder.
* res-dc-status-obs for /dcdc/status
* res-dc-vdc for /dcdc/vdc
* res-dc-hwcfg for /dcdc/hwcfg
coap-server.c
----------------
The server acts as the RPL root node.
It has 3 CoAP resources as described above.
coap-client.c
----------------
The client periodically send a CoAP command (either GET or PUT) to monitor/update
values of parameters of a resource.
project-conf.h
----------------
This file contains definitions needed for this IoT-grid example as follows.
* Enable IPv6 network stack
* Set nullrdc_driver
* Set nullmac_driver
* Activate CoAP observe client library (COAP_OBSERVE_CLIENT = 1)
* Increase the maximum number of observee and maximum number of open transaction to 10
(COAP_MAX_OPEN_TRANSACTIONS and COAP_MAX_OBSERVEES = 10)

View file

@ -0,0 +1,413 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "contiki-net.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ip/uip-udp-packet.h"
#ifdef WITH_COMPOWER
#include "powertrace.h"
#endif
#include <stdio.h>
#include <string.h>
/**************************************************************************/
/* from er-rest-example/er-rexample-client.c */
#include <stdlib.h>
#include "er-coap-engine.h"
#include "er-coap.h"
#include "er-coap-observe-client.h"
/* #include "dev/button-sensor.h" */
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#define DEBUG 1
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */
/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) / * cooja2 * / */
/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1) */
/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0x2000, 0, 0, 0, 0, 0, 0, 0x0001) */
#define LOCAL_PORT UIP_HTONS(COAP_DEFAULT_PORT + 1)
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
#define GET_INTERVAL 10
/* #define OBSERVE_INTERVAL 10 */
/**************************************************************************/
#define UDP_CLIENT_PORT 8765
#define UDP_SERVER_PORT 5678
#define UDP_EXAMPLE_ID 190
/* #define DEBUG DEBUG_PRINT */
/* #include "net/ip/uip-debug.h" */
#ifndef PERIOD
/* #define PERIOD 60 */
#define PERIOD 10
#endif
#define START_INTERVAL (15 * CLOCK_SECOND)
#define SEND_INTERVAL (PERIOD * CLOCK_SECOND)
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
/* static struct uip_udp_conn *client_conn; */
static uip_ipaddr_t server_ipaddr;
static coap_observee_t *obs;
static int count_notify = 0;
/**************************************************************************/
static struct etimer et;
/* Example URIs that can be queried. */
#define NUMBER_OF_URLS 4
/* leading and ending slashes only for demo purposes, get cropped automatically when setting the Uri-Path */
char *service_urls[NUMBER_OF_URLS] =
{ ".well-known/core", "/dcdc/status", "/dcdc/vdc", "/dcdc/hwcfg" };
/*
#if PLATFORM_HAS_BUTTON
static int uri_switch = 0;
#endif
*/
/* This function is will be passed to COAP_BLOCKING_REQUEST() to handle responses. */
void
client_chunk_handler(void *response)
{
const uint8_t *chunk;
int len = coap_get_payload(response, &chunk);
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
/* printf("|%.*s", len, (char *)chunk); */
printf("RX: %d\n%s\n", len, (char *)chunk);
}
/**************************************************************************/
/*---------------------------------------------------------------------------*/
PROCESS(coap_client_process, "CoAP client process");
AUTOSTART_PROCESSES(&coap_client_process);
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
char *str;
if(uip_newdata()) {
str = uip_appdata;
str[uip_datalen()] = '\0';
printf("DATA recv '%s'\n", str);
}
}
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTF("Client IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(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;
}
}
}
}
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
/* The choice of server address determines its 6LoPAN header compression.
* (Our address will be compressed Mode 3 since it is derived from our link-local address)
* Obviously the choice made here must also be selected in udp-server.c.
*
* For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences,
* e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx)
*
* Note the IPCMV6 checksum verification depends on the correct uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from server link-local (MAC) address */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); /* redbee-econotag */
#endif
/* Voravit Added */
/* PRINTF("VORAVIT CLIENT: SERVER IPv6 addresses: \n"); */
/* PRINT6ADDR(&server_ipaddr); */
}
/*---------------------------------------------------------------------------*/
static void
generate_random_payload(int type, char *msg)
{
if(type == 2) { /* /dcdc/vdc */
snprintf((char *)msg, 64, "&VG=%d&SL=%d&PMX=%d", (random_rand() % 25) + 1, (random_rand() % 10) + 1, (random_rand() % 100) + 1);
} else if(type == 3) { /* /dcdc/hwcfg */
snprintf((char *)msg, 64, "&VMX=%d&IMX=%d", (random_rand() % 25) + 1, (random_rand() % 6) + 1);
}
}
/*----------------------------------------------------------------------------*/
/*
* Handle the response to the observe request and the following notifications
*/
static void
notification_callback(coap_observee_t *obs, void *notification, coap_notification_flag_t flag)
{
int len = 0;
const uint8_t *payload = NULL;
/* printf("Notification handler\n"); */
/* printf("Observee URI: %s\n", obs->url); */
if(notification) {
len = coap_get_payload(notification, &payload);
}
switch(flag) {
case NOTIFICATION_OK:
count_notify++;
printf("NOTIFICATION OK: %d\n%*s\n", count_notify, len, (char *)payload);
break;
case OBSERVE_OK: /* server accepeted observation request */
printf("OBSERVE_OK: \n%*s\n", len, (char *)payload);
break;
case OBSERVE_NOT_SUPPORTED:
printf("OBSERVE_NOT_SUPPORTED: \n%*s\n", len, (char *)payload);
obs = NULL;
break;
case ERROR_RESPONSE_CODE:
printf("ERROR_RESPONSE_CODE: \n%*s\n", len, (char *)payload);
obs = NULL;
break;
case NO_REPLY_FROM_SERVER:
printf("NO_REPLY_FROM_SERVER: "
"removing observe registration with token %x%x\n",
obs->token[0], obs->token[1]);
obs = NULL;
break;
}
}
/*---------------------------------------------------------------------------*/
/*
* Toggle the observation of the remote resource
*/
void
toggle_observation(void)
{
if(obs) {
printf("Stopping observation\n");
coap_obs_remove_observee(obs);
obs = NULL;
} else {
printf("Starting observation\n");
obs = coap_obs_request_registration(&server_ipaddr, REMOTE_PORT, service_urls[1], notification_callback, NULL);
}
}
/*---------------------------------------------------------------------------*/
static int count_get = 0;
static int count_put = 0;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_client_process, ev, data)
{
/*
#if WITH_COMPOWER
static int print = 0;
#endif
*/
PROCESS_BEGIN();
PROCESS_PAUSE();
set_global_address();
PRINTF("CoAP client process started\n");
print_local_addresses();
/**************************************************************************/
static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */
/* receives all CoAP messages */
coap_init_engine();
etimer_set(&et, GET_INTERVAL * CLOCK_SECOND);
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
printf("TCPIP_HANDLER\n");
tcpip_handler();
}
if(etimer_expired(&et)) {
count_get++;
/*---------------------------------------------------------------------------*/
if(count_get < 10) { /* we do normal GET 3 times for each resource */
/* TEST GET: looping through the 3 resources: status, vdc, hwcfg */
/* Also CoAP GET doesn't need to have a payload */
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
if(count_get % 3 == 1) {
coap_set_header_uri_path(request, service_urls[1]);
PRINTF("GET %d: %s\n", count_get, service_urls[1]);
} else if(count_get % 3 == 2) {
coap_set_header_uri_path(request, service_urls[2]);
PRINTF("GET %d: %s\n", count_get, service_urls[2]);
} else {
coap_set_header_uri_path(request, service_urls[3]);
PRINTF("GET %d: %s\n", count_get, service_urls[3]);
}
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
} /* if (count_get < 10) */
/*---------------------------------------------------------------------------*/
/* test PUT: vdc and hwcfg on odd and even packet */
/* every 10th timer we PUT a resource: vdc and hwcfg alternately */
if(count_get % 10 == 0) {
/* static char msg[64] = ""; */
char msg[64] = "";
/*---------------------------------------------------------------------------*/
/* We read CO2 sensor if it is enable */
#ifdef CO2
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
coap_set_header_uri_path(request, "/dcdc/co2");
PRINTF("GET %d: %s\n", count_get, "/dcdc/co2");
#if PLATFORM_HAS_LEDS
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
#endif
/*---------------------------------------------------------------------------*/
count_put++;
coap_init_message(request, COAP_TYPE_CON, COAP_PUT, 0);
if(count_put % 2 == 0) {
coap_set_header_uri_path(request, service_urls[3]);
generate_random_payload(3, msg);
coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1);
PRINTF("PUT %d: %s PAYLOAD: %s\n", count_get, service_urls[3], msg);
} else {
coap_set_header_uri_path(request, service_urls[2]);
generate_random_payload(2, msg);
coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1);
PRINTF("PUT %d: %s PAYLOAD: %s\n", count_get, service_urls[2], msg);
}
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
}
/* after 2 more timeout we do GET to check the resource new value */
if((count_get > 10) && ((count_get - 2) % 10 == 0)) {
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
if(count_put % 2 == 0) {
coap_set_header_uri_path(request, service_urls[3]);
PRINTF("GET %d: %s\n", count_get, service_urls[3]);
} else {
coap_set_header_uri_path(request, service_urls[2]);
PRINTF("GET %d: %s\n", count_get, service_urls[2]);
}
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
}
/*---------------------------------------------------------------------------*/
/* test GET with observe option when timer expires the 15th time */
if(count_get == 15) {
/* PRINTF("GET %d: OBSERVE: %s\n", count_get, service_urls[2]); */
toggle_observation();
}
etimer_reset(&et);
}
} /* END_WHILE(1) */
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,269 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/rpl/rpl.h"
#include "net/netstack.h"
/* #include "dev/leds.h" */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
*/
/**************************************************************************/
/* add mock-up code for DC-DC converter */
/* #include "control.h" */
/* #include "vdc.h" */
#ifdef CO2
#include "dev/co2_sa_kxx-sensor.h"
#endif
#include "dev/dc-status-sensor.h"
#include "dev/dc-vdc-sensor.h"
#include "dev/dc-hw-sensor.h"
/* from er-rest-example/er-rexample-server.c */
#include "rest-engine.h"
/* #include "er-coap.h" */
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
/*
#if PLATFORM_HAS_BUTTON
#include "dev/button-sensor.h"
#endif
*/
#define DEBUG 1
#if DEBUG
/* #include <stdio.h> */
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* #define TOGGLE_INTERVAL 10 */
/* #define OBSERVE_INTERVAL 10 */
/*
* Resources to be activated need to be imported through the extern keyword.
* The build system automatically compiles the resources in the corresponding sub-directory.
*/
extern resource_t
/* res_hello, */
/* res_push, */
/* res_event, */
/* res_sub; */
/* res_dc_status_obs; */
/* res_dc_status, */
#ifdef CO2
res_dc_co2,
#endif
res_dc_status_obs,
res_dc_vdc,
res_dc_hwcfg;
/*
#if PLATFORM_HAS_LEDS
extern resource_t
// res_leds,
res_toggle;
#endif
*/
/* #if PLATFORM_HAS_LIGHT */
/* #include "dev/light-sensor.h" */
/* extern resource_t res_light; */
/* #endif */
/**************************************************************************/
PROCESS(coap_server_process, "CoAP server process");
AUTOSTART_PROCESSES(&coap_server_process);
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTF("Server 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;
}
}
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_server_process, ev, data)
{
uip_ipaddr_t ipaddr;
struct uip_ds6_addr *root_if;
PROCESS_BEGIN();
PROCESS_PAUSE();
/* SENSORS_ACTIVATE(button_sensor); */
#ifdef CO2
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
#endif
SENSORS_ACTIVATE(dc_status_sensor);
SENSORS_ACTIVATE(dc_vdc_sensor);
SENSORS_ACTIVATE(dc_hw_sensor);
/**************************************************************************/
#if PLATFORM_HAS_LEDS
/* initialize leds */
leds_init();
leds_on(LEDS_RED);
leds_on(LEDS_YELLOW);
#endif
/* Initilize DC-DC converter parameters */
/* ValueInit(); */
/* VDCInit(); */
/*
#ifdef PARAMS_CHANNEL
PRINTF("PARAMs channel: %u\n", PARAMS_CHANNEL);
#endif
*/
#ifdef RF_CHANNEL
PRINTF("RF channel: %u\n", RF_CHANNEL);
#endif
#ifdef IEEE802154_PANID
PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID);
#endif
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);
/* Initialize the REST engine. */
rest_init_engine();
/*
* Bind the resources to their Uri-Path.
* WARNING: Activating twice only means alternate path, not two instances!
* All static variables are the same for each URI path.
*/
/* rest_activate_resource(&res_hello, "test/hello"); */
/* rest_activate_resource(&res_mirror, "debug/mirror"); */
/* rest_activate_resource(&res_chunks, "test/chunks"); */
/* rest_activate_resource(&res_separate, "test/separate"); */
/* rest_activate_resource(&res_push, "test/push"); */
/* rest_activate_resource(&res_event, "sensors/button"); */
/* rest_activate_resource(&res_sub, "test/sub"); */
/* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */
#ifdef CO2
rest_activate_resource(&res_dc_co2, "dcdc/co2");
#endif
rest_activate_resource(&res_dc_status_obs, "dcdc/status");
/* rest_activate_resource(&res_dc_status, "dcdc/status"); */
rest_activate_resource(&res_dc_vdc, "dcdc/vdc");
rest_activate_resource(&res_dc_hwcfg, "dcdc/hwcfg");
/* #if PLATFORM_HAS_LEDS */
/* / * rest_activate_resource(&res_leds, "actuators/leds"); * / */
/* rest_activate_resource(&res_toggle, "actuators/toggle"); */
/* #endif */
/* #if PLATFORM_HAS_LIGHT */
/* rest_activate_resource(&res_light, "sensors/light"); */
/* SENSORS_ACTIVATE(light_sensor); */
/* #endif */
/**************************************************************************/
PRINTF("CoAP server started\n");
#if UIP_CONF_ROUTER
/* The choice of server address determines its 6LoPAN header compression.
* 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 aaaa::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::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, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL);
root_if = uip_ds6_addr_lookup(&ipaddr);
if(root_if != NULL) {
rpl_dag_t *dag;
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, (uip_ip6addr_t *)&ipaddr);
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
} else {
PRINTF("failed to create a new RPL DAG\n");
}
#endif /* UIP_CONF_ROUTER */
print_local_addresses();
/* The data sink runs with a 100% duty cycle in order to ensure high
packet reception rates. */
NETSTACK_MAC.off(1);
while(1) {
PROCESS_WAIT_EVENT();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/native_gateway</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/mobility</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/powertracker</project>
<simulation>
<title>My simulation</title>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
se.sics.cooja.radiomediums.UDGM
<transmitting_range>50.0</transmitting_range>
<interference_range>100.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
se.sics.cooja.avrmote.RSS2MoteType
<identifier>mote1</identifier>
<description>Mote1</description>
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c</source>
<commands EXPORT="discard">make coap-server.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
</motetype>
<motetype>
se.sics.cooja.avrmote.RSS2MoteType
<identifier>mote2</identifier>
<description>Mote2</description>
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c</source>
<commands EXPORT="discard">make coap-client.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>100.0</x>
<y>100.0</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.avrmote.interfaces.AvroraMoteID
<id>1</id>
</interface_config>
<motetype_identifier>mote1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>110.0</x>
<y>100.0</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.avrmote.interfaces.AvroraMoteID
<id>2</id>
</interface_config>
<motetype_identifier>mote2</motetype_identifier>
</mote>
</simulation>
<plugin>
se.sics.cooja.plugins.SimControl
<width>280</width>
<z>9</z>
<height>160</height>
<location_x>400</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Visualizer
<plugin_config>
<moterelations>true</moterelations>
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.GridVisualizerSkin</skin>
<viewport>3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074</viewport>
</plugin_config>
<width>400</width>
<z>5</z>
<height>400</height>
<location_x>1</location_x>
<location_y>1</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.LogListener
<plugin_config>
<filter />
<formatted_time />
<coloring />
</plugin_config>
<width>1269</width>
<z>8</z>
<height>240</height>
<location_x>400</location_x>
<location_y>160</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Notes
<plugin_config>
<notes>Enter notes here</notes>
<decorations>true</decorations>
</plugin_config>
<width>989</width>
<z>6</z>
<height>160</height>
<location_x>680</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>0</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>508</width>
<z>4</z>
<height>389</height>
<location_x>13</location_x>
<location_y>413</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>1</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>545</width>
<z>3</z>
<height>392</height>
<location_x>531</location_x>
<location_y>413</location_y>
</plugin>
</simconf>

View file

@ -0,0 +1,93 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/hwcfg for DC-DC converter hardware configuration
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include "contiki.h"
/* #include "lib/sensors.h" */
#include "dev/dc-hw-sensor.h"
const struct sensors_sensor dc_hw_sensor;
/*
* hw contains 2 parameters
* hw[0] VMAX
* hw[1] IMAX
*/
uint32_t volatile hw[2] = { 25, 6 };
static int
value(int type)
{
switch(type) {
case 0:
return hw[0];
case 1:
return hw[1];
}
return -1;
}
static int
configure(int type, int c)
{
switch(type) {
case 0:
if((c >= 0) && (c <= 25)) {
hw[0] = c;
return 0;
} else {
return 1;
}
case 1:
if((c >= 0) && (c <= 6)) {
hw[1] = c;
return 0;
} else {
return 0;
}
}
return 1;
}
static int
status(int type)
{
return 1;
}
SENSORS_SENSOR(dc_hw_sensor, "hw sensors", value, configure, status);

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/hwcfg header file
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef DC_HW_SENSOR_H
#define DC_HW_SENSOR_H
#include "lib/sensors.h"
extern const struct sensors_sensor dc_hw_sensor;
#endif /* DC_HW_SENSOR_H */

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/status read-only parameters for power monitoring
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include "contiki.h"
/* #include "lib/sensors.h" */
#include "dev/dc-status-sensor.h"
const struct sensors_sensor dc_status_sensor;
/*
* Status contains 4 parameters
* status[0] VOUT
* status[1] VIN
* status[2] IOUT
* status[3] IIN
*/
uint32_t volatile s[4] = { 18, 20, 1, 2 };
static int
value(int type)
{
switch(type) {
case 0:
return s[0];
case 1:
return s[1];
case 2:
return s[2];
case 3:
return s[3];
}
return -1;
}
static int
configure(int type, int c)
{
return 0;
}
static int
status(int type)
{
return 1;
}
SENSORS_SENSOR(dc_status_sensor, "DC status sensors", value, configure, status);

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/status header file
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef DC_STATUS_SENSOR_H
#define DC_STATUS_SENSOR_H
#include "lib/sensors.h"
extern const struct sensors_sensor dc_status_sensor;
#endif /* DC_STATUS_SENSOR_H */

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc for voltage droop control function
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include "contiki.h"
/* #include "lib/sensors.h" */
#include "dev/dc-vdc-sensor.h"
const struct sensors_sensor dc_vdc_sensor;
/*
* vdc contains 3 parameters
* vdc[0] VGRID
* vdc[1] SLOPE
* vdc[2] PMAX
*/
uint32_t volatile vdc[3] = { 18, 1, 100 };
static int
value(int type)
{
switch(type) {
case 0:
return vdc[0];
case 1:
return vdc[1];
case 2:
return vdc[2];
}
return -1;
}
static int
configure(int type, int c)
{
switch(type) {
case 0:
if((c >= 0) && (c <= 25)) {
vdc[0] = c;
return 0;
} else {
return 1;
}
case 1:
vdc[1] = c;
return 0;
case 2:
vdc[2] = c;
return 0;
}
return 1;
}
static int
status(int type)
{
return 1;
}
SENSORS_SENSOR(dc_vdc_sensor, "vdc sensors", value, configure, status);

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc sensor header file
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef DC_VDC_SENSOR_H
#define DC_VDC_SENSOR_H
#include "lib/sensors.h"
extern const struct sensors_sensor dc_vdc_sensor;
#endif /* DC_VDC_SENSOR_H */

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* header file for resources
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef __ER_DC_TEST_H__
#define __ER_DC_TEST_H__
#define DEBUG 1
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* double expansion */
#define TO_STRING2(x) # x
#define TO_STRING(x) TO_STRING2(x)
#define MAX_COAP_PAYLOAD 64 + 1 /* +1 for the terminating zero, which is not transmitted */
/* #define MAX_PLUGFEST_BODY 2048 */
/* #define CHUNKS_TOTAL 2012 */
#endif /* __ER_DC_TEST_H__ */

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* test rpl configuration.
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* enable IPv6 */
/* #ifndef NETSTACK_CONF_WITH_IPV6 */
#define NETSTACK_CONF_WITH_IPV6 1
/* #endif / * NETSTACK_CONF_WITH_IPV6 * / */
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
#define COAP_OBSERVE_CLIENT 1
#define COAP_MAX_OBSERVEES 10
#define COAP_MAX_OPEN_TRANSACTIONS 10
/* enable debug to activate PRINT6ADDR macro */
/* #undef DEBUG_PRINT */
/* #define DEBUG_PRINT 1 */
/* #define PRINTF(...) printf(__VA_ARGS__) */
/* #define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) */
#endif /* PROJECT_CONF_H_ */

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/co2 testing coap with CO2 sensor from SenseAir
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
/* #include <math.h> */
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/co2_sa_kxx-sensor.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_dc_co2, "title=\"co2 reading\"", res_get_handler, NULL, NULL, NULL);
/*---------------------------------------------------------------------------*/
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
int co2 = co2_sa_kxx_sensor.value(CO2_SA_KXX_CO2); // 0 is CO2_SA_KXX_CO2
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/co2 GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
/* REST.set_header_max_age(response, 30); */
REST.set_response_payload(
response,
buffer,
/* snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\nINT\t%d\n", v_max, i_max, interval)); */
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "CO2\t%d\n", co2));
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc configurable parameters for voltage droop control function
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
/* #include <math.h> */
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/dc-hw-sensor.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_dc_hwcfg, "title=\"hwcfg parameters\"", res_get_handler, res_post_put_handler, res_post_put_handler, NULL);
/*---------------------------------------------------------------------------*/
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
int v_max = dc_hw_sensor.value(0);
int i_max = dc_hw_sensor.value(1);
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/hwcfg GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
/* REST.set_header_max_age(response, 30); */
REST.set_response_payload(
response,
buffer,
/* snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\nINT\t%d\n", v_max, i_max, interval)); */
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\n", v_max, i_max));
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}
/*---------------------------------------------------------------------------*/
static void
res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/hwcfg PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
const char *variable = NULL;
if(REST.get_post_variable(request, "VMX", &variable) > 0) {
int v_max = atoi(variable);
if(dc_hw_sensor.configure(0, v_max)) {
PRINTF("Value out of range: must be 0 <= VMX <= 30");
}
}
if(REST.get_post_variable(request, "IMX", &variable) > 0) {
int i_max = atoi(variable);
if(dc_hw_sensor.configure(1, i_max)) {
PRINTF("Value out of range: must be 0 <= Imax <= 6");
}
}
REST.set_response_status(response, REST.status.CHANGED);
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}

View file

@ -0,0 +1,113 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/status read-only parameters for power monitoring
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-coap-observe.h"
#include "../er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/dc-status-sensor.h"
static void res_dc_status_obs_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_dc_status_obs_periodic_handler(void);
PERIODIC_RESOURCE(res_dc_status_obs, "title=\"status parameters\"", res_dc_status_obs_get_handler, NULL, NULL, NULL, 10 * CLOCK_SECOND, res_dc_status_obs_periodic_handler);
static uint32_t observe = 0;
static count = 0;
/*---------------------------------------------------------------------------*/
static void
res_dc_status_obs_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
int vout_value = dc_status_sensor.value(0);
int vin_value = dc_status_sensor.value(1);
int iout_value = dc_status_sensor.value(2);
int iin_value = dc_status_sensor.value(3);
/* a request comes from a remote host */
if(request != NULL) {
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
coap_packet_t *const coap_req = (coap_packet_t *)request;
PRINTF("dcdc/status GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* if comes with observe then register it */
if(coap_get_header_observe(request, &observe)) {
/* PRINTF("OBSERVE set\n"); */
/* respond with empty ack */
REST.set_header_content_type(response, observe);
REST.set_response_payload(response, 0, 0);
} else { /* if no observe option, then answer to GET request as normal */
/* PRINTF("OBSERVE NOT set\n"); */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
REST.set_response_payload(
response,
buffer,
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "ST\tON\nVO\t%d.000\nIO\t%d.000\nVI\t%d.000\nII\t%d.000\n", vout_value, iout_value, vin_value, iin_value));
}
} else { /* this is a notification: need to set payload */
/* PRINTF("NULL REQUEST = PERIODIC\n"); */
REST.set_response_payload(
response,
buffer,
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "ST\tON\nVO\t%d.000\nIO\t%d.000\nVI\t%d.000\nII\t%d.000\n", vout_value, iout_value, vin_value, iin_value));
}
count++;
printf("PERIODIC %d: ST:ON VO:%d IO:%d VI:%d II:%d\n", count, vout_value, iout_value, vin_value, iin_value);
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}
/*---------------------------------------------------------------------------*/
static void
res_dc_status_obs_periodic_handler()
{
/* send periodic notification to the observers */
REST.notify_subscribers(&res_dc_status_obs);
}

View file

@ -0,0 +1,129 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc configurable parameters for voltage droop control function
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
/* #include <math.h> */
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/dc-vdc-sensor.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_dc_vdc, "title=\"vdc parameters\"", res_get_handler, res_post_put_handler, res_post_put_handler, NULL);
/*---------------------------------------------------------------------------*/
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
int vdc_grid = dc_vdc_sensor.value(0);
int vdc_slope = dc_vdc_sensor.value(1);
int vdc_pmax = dc_vdc_sensor.value(2);
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/vdc GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
/* REST.set_header_max_age(response, 30); */
REST.set_response_payload(
response,
buffer,
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VG\t%d.000\nSL\t%d.000\nPMAX\t%d.000\n", vdc_grid, vdc_slope, vdc_pmax));
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}
/*---------------------------------------------------------------------------*/
static void
res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/vdc PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
const char *variable = NULL;
if(REST.get_post_variable(request, "VG", &variable) > 0) {
int vdc_grid = atoi(variable);
/* PRINTF("VG: %d\n",vdc_grid); */
if(dc_vdc_sensor.configure(0, vdc_grid)) {
PRINTF("Value out of range: must be 0 <= Vgrid <= Vmax");
}
}
if(REST.get_post_variable(request, "SL", &variable) > 0) {
int vdc_slope = atoi(variable);
/* PRINTF("SL: %d\n",vdc_slope); */
if(dc_vdc_sensor.configure(1, vdc_slope)) {
PRINTF("Error: SLOPE is not set!");
}
}
if(REST.get_post_variable(request, "PMX", &variable) > 0) {
int vdc_pmax = atoi(variable);
/* PRINTF("PMAX: %d\n",vdc_pmax); */
if(dc_vdc_sensor.configure(2, vdc_pmax)) {
PRINTF("Error: PMAX is not set!");
}
}
REST.set_response_status(response, REST.status.CHANGED);
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}