From ce6f8de0785dd11d60682420990f60560298c1c0 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Mon, 10 Oct 2011 14:16:27 +0200 Subject: [PATCH] Fixed Erbium example simulation --- examples/er-rest-example/Makefile | 3 +- examples/er-rest-example/project-conf.h | 12 ++++-- .../er-rest-example/rest-server-example.c | 26 +++++------ .../er-rest-example/rest-server-example.csc | 43 ++++++++++--------- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/examples/er-rest-example/Makefile b/examples/er-rest-example/Makefile index 2d2227c8f..7bf002ebc 100644 --- a/examples/er-rest-example/Makefile +++ b/examples/er-rest-example/Makefile @@ -24,8 +24,7 @@ CFLAGS += -DUIP_CONF_IPV6_RPL=1 endif # linker optimizations -CFLAGS += -ffunction-sections -LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__ +SMALL=1 # REST framework, requires WITH_COAP ifeq ($(WITH_COAP), 7) diff --git a/examples/er-rest-example/project-conf.h b/examples/er-rest-example/project-conf.h index f1c94e750..1672795d7 100644 --- a/examples/er-rest-example/project-conf.h +++ b/examples/er-rest-example/project-conf.h @@ -34,9 +34,11 @@ #define SICSLOWPAN_CONF_FRAG 1 -#ifndef QUEUEBUF_CONF_NUM -#define QUEUEBUF_CONF_NUM 6 -#endif +/* 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 /* Increase rpl-border-router IP-buffer when using 128 */ #ifndef REST_MAX_CHUNK_SIZE @@ -45,7 +47,7 @@ /* Decrease to 2 if no space left for stack when using 128-byte chunks */ #ifndef COAP_MAX_OPEN_TRANSACTIONS -#define COAP_MAX_OPEN_TRANSACTIONS 4 +#define COAP_MAX_OPEN_TRANSACTIONS 4 #endif /* Must be <= open transaction number */ @@ -62,4 +64,6 @@ #define WEBSERVER_CONF_CFS_CONNS 2 #endif + + #endif /* __PROJECT_RPL_WEB_CONF_H__ */ diff --git a/examples/er-rest-example/rest-server-example.c b/examples/er-rest-example/rest-server-example.c index 846211169..3307f808f 100644 --- a/examples/er-rest-example/rest-server-example.c +++ b/examples/er-rest-example/rest-server-example.c @@ -93,7 +93,7 @@ * Resources are defined by the RESOURCE macro. * Signature: resource name, the RESTful methods it handles, and its URI path (omitting the leading slash). */ -RESOURCE(helloworld, METHOD_GET, "hello", "title=\"Hello world (set length with ?len query)\";rt=\"Text\""); +RESOURCE(helloworld, METHOD_GET, "hello", "title=\"Hello world: ?len=0..\";rt=\"Text\""); /* * A handler function named [resource name]_handler must be implemented for each RESOURCE. @@ -105,8 +105,9 @@ void helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { const char *len = NULL; - int length = 12; /* ------->| */ - char *message = "Hello World! ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789?!at 86 now+2+4at 99 now100..105..110..115..120..125..130..135..140..145..150..155..160"; + /* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */ + char const * const message = "Hello World! ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy"; + int length = 12; /* |<-------->| */ /* The query string can be retrieved by rest_get_query() or parsed for its key-value pairs. */ if (REST.get_query_variable(request, "len", &len)) { @@ -124,7 +125,7 @@ helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t pref } /* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */ -RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE | HAS_SUB_RESOURCES, "mirror", "title=\"Returns your decoded message\";rt=\"Debug\""); +RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "mirror", "title=\"Returns your decoded message\";rt=\"Debug\""); void mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) @@ -283,7 +284,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre */ RESOURCE(chunks, METHOD_GET, "chunks", "title=\"Blockwise demo\";rt=\"Data\""); -#define CHUNKS_TOTAL 1030 +#define CHUNKS_TOTAL 2050 void chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) @@ -294,7 +295,8 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre if (*offset>=CHUNKS_TOTAL) { REST.set_response_status(response, REST.status.BAD_OPTION); - REST.set_response_payload(response, (uint8_t*)"Block out of scope", 18); + /* A block error message should not exceed the minimum block size (16). */ + REST.set_response_payload(response, (uint8_t*)"BlockOutOfScope", 15); return; } @@ -310,7 +312,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre REST.set_response_payload(response, buffer, strpos); - /* Signal chunk awareness of resource to framework. */ + /* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */ *offset += strpos; /* Signal end of resource. */ @@ -395,7 +397,7 @@ event_event_handler(resource_t *r) #if defined (PLATFORM_HAS_LEDS) /*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/ -RESOURCE(led, METHOD_POST | METHOD_PUT , "leds", "title=\"Led control (use ?color=red|green|blue and POST/PUT mode=on|off)\";rt=\"Control\""); +RESOURCE(led, METHOD_POST | METHOD_PUT , "leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\""); void led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) @@ -409,11 +411,11 @@ led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s if ((len=REST.get_query_variable(request, "color", &color))) { PRINTF("color %.*s\n", len, color); - if (strncmp(color, "red", len)==0) { + if (strncmp(color, "r", len)==0) { led = LEDS_RED; - } else if(strncmp(color,"green", len)==0) { + } else if(strncmp(color,"g", len)==0) { led = LEDS_GREEN; - } else if (strncmp(color,"blue", len)==0) { + } else if (strncmp(color,"b", len)==0) { led = LEDS_BLUE; } else { success = 0; @@ -524,7 +526,6 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr } #endif /* PLATFORM_HAS_BATTERY */ - PROCESS(rest_server_example, "Rest Server Example"); AUTOSTART_PROCESSES(&rest_server_example); @@ -569,6 +570,7 @@ PROCESS_THREAD(rest_server_example, ev, data) rest_activate_resource(&resource_led); rest_activate_resource(&resource_toggle); #endif /* PLATFORM_HAS_LEDS */ + #if defined (PLATFORM_HAS_LIGHT) SENSORS_ACTIVATE(light_sensor); rest_activate_resource(&resource_light); diff --git a/examples/er-rest-example/rest-server-example.csc b/examples/er-rest-example/rest-server-example.csc index de5c85fa8..837e3d1d4 100644 --- a/examples/er-rest-example/rest-server-example.csc +++ b/examples/er-rest-example/rest-server-example.csc @@ -47,9 +47,9 @@ se.sics.cooja.mspmote.SkyMoteType skyweb Rest - [CONTIKI_DIR]/examples/rest-example/rest-server-example.c + [CONTIKI_DIR]/examples/er-rest-example/rest-server-example.c make rest-server-example.sky TARGET=sky - [CONTIKI_DIR]/examples/rest-example/rest-server-example.sky + [CONTIKI_DIR]/examples/er-rest-example/rest-server-example.sky se.sics.cooja.interfaces.Position se.sics.cooja.interfaces.RimeAddress se.sics.cooja.interfaces.IPAddress @@ -98,7 +98,7 @@ se.sics.cooja.plugins.SimControl 259 - 1 + 5 179 0 0 @@ -115,21 +115,22 @@ 7.9849281638410705 0.0 0.0 7.9849281638410705 -133.27812697619663 -225.04752569190535 300 - 0 + 4 175 - 371 - 2 + 263 + 3 se.sics.cooja.plugins.LogListener + - 762 - 3 + 560 + 1 326 - 12 - 294 + 1 + 293 se.sics.cooja.plugins.RadioLogger @@ -148,10 +149,10 @@ SerialSocketServer 0 422 - 5 + 2 74 - 1234 - 93 + 39 + 199 se.sics.cooja.plugins.TimeLine @@ -166,10 +167,10 @@ 25.49079397896416 1624 - 4 + 3 252 - 166 - 699 + 4 + 622 se.sics.cooja.plugins.MoteInterfaceViewer @@ -178,11 +179,11 @@ Serial port 0,0 - 662 - 2 - 362 - 7 - 221 + 702 + 0 + 646 + 564 + 2