From cc950ace98d0be3068d4b204566133bc5a7f645c Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Thu, 28 Nov 2013 15:25:17 +0100 Subject: [PATCH] cleanup code --- examples/osd/embedd-vm-merkurboard/Makefile | 3 - .../embedd-vm-merkurboard/embedd-vm-server.c | 71 +------- .../osd/embedd-vm-merkurboard/project-conf.h | 24 ++- .../embedd-vm-merkurboard/static-routing.c | 155 ------------------ .../embedd-vm-merkurboard/static-routing.h | 20 --- 5 files changed, 17 insertions(+), 256 deletions(-) delete mode 100644 examples/osd/embedd-vm-merkurboard/static-routing.c delete mode 100644 examples/osd/embedd-vm-merkurboard/static-routing.h diff --git a/examples/osd/embedd-vm-merkurboard/Makefile b/examples/osd/embedd-vm-merkurboard/Makefile index 11973023b..e11ebef28 100644 --- a/examples/osd/embedd-vm-merkurboard/Makefile +++ b/examples/osd/embedd-vm-merkurboard/Makefile @@ -5,9 +5,6 @@ all: embedd-vm-server # configure CoAP implementation (3|7|12|13) (er-coap-07 also supports CoAP draft 08) WITH_COAP=13 - -# variable for Makefile.include -WITH_UIP6=1 # for some platforms UIP_CONF_IPV6=1 # IPv6 make config disappeared completely diff --git a/examples/osd/embedd-vm-merkurboard/embedd-vm-server.c b/examples/osd/embedd-vm-merkurboard/embedd-vm-server.c index 146d75eab..09ffe7927 100644 --- a/examples/osd/embedd-vm-merkurboard/embedd-vm-server.c +++ b/examples/osd/embedd-vm-merkurboard/embedd-vm-server.c @@ -46,16 +46,10 @@ /* Define which resources to include to meet memory constraints. */ #define REST_RES_INFO 1 #define REST_RES_EVM 1 -#define REST_RES_CHUNKS 0 #define REST_RES_BATTERY 1 #define REST_RES_LEDS 1 #define REST_RES_TOGGLE 1 -#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE) -#warning "Compiling with static routing!" -#include "static-routing.h" -#endif - #include "erbium.h" #if defined (PLATFORM_HAS_BUTTON) @@ -120,7 +114,7 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_ /* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */ // jSON Format - index += sprintf(message + index,"{\n \"version\" : \"V0.1\",\n"); + index += sprintf(message + index,"{\n \"version\" : \"V0.2\",\n"); index += sprintf(message + index," \"name\" : \"embedd-vm demo\"\n"); index += sprintf(message + index,"}\n"); @@ -132,66 +126,6 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_ } #endif -/******************************************************************************/ -#if REST_RES_CHUNKS -/* - * For data larger than REST_MAX_CHUNK_SIZE (e.g., stored in flash) resources must be aware of the buffer limitation - * and split their responses by themselves. To transfer the complete resource through a TCP stream or CoAP's blockwise transfer, - * the byte offset where to continue is provided to the handler as int32_t pointer. - * These chunk-wise resources must set the offset value to its new position or -1 of the end is reached. - * (The offset for CoAP's blockwise transfer can go up to 2'147'481'600 = ~2047 M for block size 2048 (reduced to 1024 in observe-03.) - */ -RESOURCE(chunks, METHOD_GET, "test/chunks", "title=\"Blockwise demo\";rt=\"Data\""); - -#define CHUNKS_TOTAL 2050 - -void -chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - int32_t strpos = 0; - - /* Check the offset for boundaries of the resource data. */ - if (*offset>=CHUNKS_TOTAL) - { - REST.set_response_status(response, REST.status.BAD_OPTION); - /* A block error message should not exceed the minimum block size (16). */ - - const char *error_msg = "BlockOutOfScope"; - REST.set_response_payload(response, error_msg, strlen(error_msg)); - return; - } - - /* Generate data until reaching CHUNKS_TOTAL. */ - while (strpos preferred_size) - { - strpos = preferred_size; - } - - /* Truncate if above CHUNKS_TOTAL bytes. */ - if (*offset+(int32_t)strpos > CHUNKS_TOTAL) - { - strpos = CHUNKS_TOTAL - *offset; - } - - REST.set_response_payload(response, buffer, strpos); - - /* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */ - *offset += strpos; - - /* Signal end of resource representation. */ - if (*offset>=CHUNKS_TOTAL) - { - *offset = -1; - } -} -#endif - /******************************************************************************/ #if defined (PLATFORM_HAS_LEDS) /******************************************************************************/ @@ -502,9 +436,6 @@ PROCESS_THREAD(rest_server_example, ev, data) #if REST_RES_INFO rest_activate_resource(&resource_info); #endif -#if REST_RES_CHUNKS - rest_activate_resource(&resource_chunks); -#endif #if defined (PLATFORM_HAS_LEDS) #if REST_RES_LEDS rest_activate_resource(&resource_leds); diff --git a/examples/osd/embedd-vm-merkurboard/project-conf.h b/examples/osd/embedd-vm-merkurboard/project-conf.h index 2b6d52421..7cfb06128 100644 --- a/examples/osd/embedd-vm-merkurboard/project-conf.h +++ b/examples/osd/embedd-vm-merkurboard/project-conf.h @@ -29,8 +29,8 @@ * */ -#ifndef __PROJECT_RPL_WEB_CONF_H__ -#define __PROJECT_RPL_WEB_CONF_H__ +#ifndef PROJECT_RPL_WEB_CONF_H_ +#define PROJECT_RPL_WEB_CONF_H_ #define SICSLOWPAN_CONF_FRAG 1 @@ -44,19 +44,23 @@ //#define NETSTACK_CONF_RDC nullrdc_driver /* Debugmode Dont allow MCU sleeping between channel checks */ +/* #undef RDC_CONF_MCU_SLEEP #define RDC_CONF_MCU_SLEEP 0 +*/ /* The IP buffer size must fit all other hops, in particular the border router. */ #undef UIP_CONF_BUFFER_SIZE -#define UIP_CONF_BUFFER_SIZE 1280 +#define UIP_CONF_BUFFER_SIZE 256 /* Save some memory for the sky platform. */ -#undef UIP_CONF_DS6_NBR_NBU -#define UIP_CONF_DS6_NBR_NBU 10 -#undef UIP_CONF_DS6_ROUTE_NBU -#define UIP_CONF_DS6_ROUTE_NBU 10 +/* +#undef NBR_TABLE_CONF_MAX_NEIGHBORS +#define NBR_TABLE_CONF_MAX_NEIGHBORS 10 +#undef UIP_CONF_MAX_ROUTES +#define UIP_CONF_MAX_ROUTES 10 +*/ /* Increase rpl-border-router IP-buffer when using 128. */ #ifndef REST_MAX_CHUNK_SIZE @@ -69,12 +73,16 @@ #endif /* Must be <= open transaction number. */ +/* #ifndef COAP_MAX_OBSERVERS #define COAP_MAX_OBSERVERS COAP_MAX_OPEN_TRANSACTIONS-1 #endif +*/ /* Reduce 802.15.4 frame queue to save RAM. */ +/* #undef QUEUEBUF_CONF_NUM #define QUEUEBUF_CONF_NUM 4 +*/ -#endif /* __PROJECT_RPL_WEB_CONF_H__ */ +#endif /* _PROJECT_RPL_WEB_CONF_H_ */ diff --git a/examples/osd/embedd-vm-merkurboard/static-routing.c b/examples/osd/embedd-vm-merkurboard/static-routing.c deleted file mode 100644 index 628594892..000000000 --- a/examples/osd/embedd-vm-merkurboard/static-routing.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * static-routing.c - * - * Created on: Oct 12, 2010 - * Author: simonduq - */ - -#include -#include "static-routing.h" - -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) -#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5]) -#else -#define PRINTF(...) -#define PRINT6ADDR(addr) -#define PRINTLLADDR(addr) -#endif - -#include "contiki-net.h" -#include "node-id.h" - -int node_rank; - -struct id_to_addrs { - int id; - uint32_t addr; -}; - -const struct id_to_addrs motes_addrs[] = { -/* - * Static routing requires a map nodeid => address. - * The nodeid can be programmed with the sky-shell. - * The addresses should also be added to /etc/hosts. - * - * aaaa::212:7400:1160:f62d sky1 - * aaaa::212:7400:0da0:d748 sky2 - * aaaa::212:7400:116e:c325 sky3 - * aaaa::212:7400:116e:c444 sky4 - * aaaa::212:7400:115e:b717 sky5 - * - * Add the nodeid and last 4 bytes of the address to the map. - */ - {1, 0x1160f62d}, - {2, 0x0da0d748}, - {3, 0x116ec325}, - {4, 0x116ec444}, - {5, 0x115eb717}, -}; -/* Define the size of the map. */ -#define NODES_IN_MAP 5 - -uint32_t get_mote_suffix(int rank) { - if(--rank >=0 && rank<(sizeof(motes_addrs)/sizeof(struct id_to_addrs))) { - return motes_addrs[rank].addr; - } - return 0; -} - -int get_mote_id(uint32_t suffix) { -#if IN_COOJA - return suffix & 0xff; -#else - int i; - for(i=0; i<(sizeof(motes_addrs)/sizeof(struct id_to_addrs)); i++) { - if(suffix == motes_addrs[i].addr) { - return motes_addrs[i].id; - } - } - return 0; -#endif -} - -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); -} - -static void add_route_ext(int dest, int next) { - PRINTF("add route ext %d %d\n", dest, next); - uip_ipaddr_t ipaddr_dest, ipaddr_next; - uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0, 0, 0, dest); -#if IN_COOJA - uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400 | next, next, next<<8 | next); -#else - uint32_t next_suffix = get_mote_suffix(next); - uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400, (next_suffix >> 16) & 0xffff, next_suffix & 0xffff); -#endif - uip_ds6_route_add(&ipaddr_dest, 128, &ipaddr_next, 0); -} - -void add_route(int dest, int next) { - PRINTF("add route %d %d\n", dest, next); - uip_ipaddr_t ipaddr_dest, ipaddr_next; -#if IN_COOJA - uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0x0212, 0x7400 | dest, dest, dest<<8 | dest); - uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400 | next, next, next<<8 | next); -#else - uint32_t dest_suffix = get_mote_suffix(dest); - uint32_t next_suffix = get_mote_suffix(next); - uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0x0212, 0x7400, (dest_suffix >> 16) & 0xffff, dest_suffix & 0xffff); - uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400, (next_suffix >> 16) & 0xffff, next_suffix & 0xffff); -#endif - uip_ds6_route_add(&ipaddr_dest, 128, &ipaddr_next, 0); -} - -void configure_routing(void) { - int i; -#if IN_COOJA - node_rank = node_id; -#else - node_rank = -1; - for(i=0; i<(sizeof(motes_addrs)/sizeof(struct id_to_addrs)); ++i) { - if(node_id == motes_addrs[i].id) { - node_rank = i+1; - break; - } - } - - if(node_rank == -1) { - printf("unable to configure routing, node_id=%d\n", node_id); - return; - } -#endif - - printf("configure_routing, node_id=%d, node_rank %d\n", node_id, node_rank); - - if (node_rank == 1) { /* border router #1 */ - add_route_ext(2, 2); - for(i=2; i<=NODES_IN_MAP; ++i) { - add_route(i, 2); - } - } else if (node_rank < NODES_IN_MAP) { /* other node */ - add_route_ext(1, node_rank-1); - add_route_ext(2, node_rank+1); - for(i=1; i<=NODES_IN_MAP; ++i) { - if(inode_rank) { - add_route(i, node_rank+1); - } - } - } else if (node_rank == NODES_IN_MAP) { /* 2nd border router */ - add_route_ext(1, NODES_IN_MAP-1); - for(i=1; i<=NODES_IN_MAP-1; ++i) { - add_route(i, NODES_IN_MAP-1); - } - } -} diff --git a/examples/osd/embedd-vm-merkurboard/static-routing.h b/examples/osd/embedd-vm-merkurboard/static-routing.h deleted file mode 100644 index 0dff0b7ba..000000000 --- a/examples/osd/embedd-vm-merkurboard/static-routing.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * static-routing.h - * - * Created on: Oct 12, 2010 - * Author: simonduq - */ - -#ifndef STATICROUTING_H_ -#define STATICROUTING_H_ - -#include "contiki.h" - -extern int node_rank; -extern uint32_t get_mote_suffix(int id); -extern int get_mote_id(uint32_t suffix); -extern void add_route(int dest, int next); -extern void set_global_address(void); -extern void configure_routing(void); - -#endif /* STATICROUTING_H_ */