From 222f9bd3afbf9975c7d48562b0196e3116ce015f Mon Sep 17 00:00:00 2001 From: simonduq Date: Thu, 29 Sep 2011 15:07:00 +0200 Subject: [PATCH 1/9] Include string.h --- core/net/mac/nullrdc-noframer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/net/mac/nullrdc-noframer.c b/core/net/mac/nullrdc-noframer.c index 3a909dcb6..38fd246fb 100644 --- a/core/net/mac/nullrdc-noframer.c +++ b/core/net/mac/nullrdc-noframer.c @@ -41,6 +41,7 @@ #include "net/mac/nullrdc-noframer.h" #include "net/packetbuf.h" #include "net/netstack.h" +#include /*---------------------------------------------------------------------------*/ static void From e0ae036a6910ec8c9cf5dbc4e25f74892af02ef6 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Mon, 3 Oct 2011 15:17:30 +0200 Subject: [PATCH 2/9] added static on the list send functions to get less compiler errors with IAR compiler --- core/net/mac/contikimac.c | 2 +- core/net/mac/cxmac.c | 2 +- core/net/mac/lpp.c | 2 +- core/net/mac/nullrdc-noframer.c | 2 +- core/net/mac/nullrdc.c | 2 +- core/net/mac/xmac.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/net/mac/contikimac.c b/core/net/mac/contikimac.c index 78c766d4d..628be7ee4 100644 --- a/core/net/mac/contikimac.c +++ b/core/net/mac/contikimac.c @@ -736,7 +736,7 @@ qsend_packet(mac_callback_t sent, void *ptr) } } /*---------------------------------------------------------------------------*/ -void +static void qsend_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { struct rdc_buf_list *curr = buf_list; diff --git a/core/net/mac/cxmac.c b/core/net/mac/cxmac.c index 61d942813..4e1c336fb 100644 --- a/core/net/mac/cxmac.c +++ b/core/net/mac/cxmac.c @@ -699,7 +699,7 @@ qsend_packet(mac_callback_t sent, void *ptr) mac_call_sent_callback(sent, ptr, ret, 1); } /*---------------------------------------------------------------------------*/ -void +static void qsend_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { if(buf_list != NULL) { diff --git a/core/net/mac/lpp.c b/core/net/mac/lpp.c index 11b73c370..7b5188d6f 100644 --- a/core/net/mac/lpp.c +++ b/core/net/mac/lpp.c @@ -726,7 +726,7 @@ send_packet(mac_callback_t sent, void *ptr) } } /*---------------------------------------------------------------------------*/ -void +static void send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { if(buf_list != NULL) { diff --git a/core/net/mac/nullrdc-noframer.c b/core/net/mac/nullrdc-noframer.c index 38fd246fb..1fa0249bb 100644 --- a/core/net/mac/nullrdc-noframer.c +++ b/core/net/mac/nullrdc-noframer.c @@ -56,7 +56,7 @@ send_packet(mac_callback_t sent, void *ptr) mac_call_sent_callback(sent, ptr, ret, 1); } /*---------------------------------------------------------------------------*/ -void +static void send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { if(buf_list != NULL) { diff --git a/core/net/mac/nullrdc.c b/core/net/mac/nullrdc.c index c705e64f3..9783249a5 100644 --- a/core/net/mac/nullrdc.c +++ b/core/net/mac/nullrdc.c @@ -201,7 +201,7 @@ send_packet(mac_callback_t sent, void *ptr) mac_call_sent_callback(sent, ptr, ret, 1); } /*---------------------------------------------------------------------------*/ -void +static void send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { if(buf_list != NULL) { diff --git a/core/net/mac/xmac.c b/core/net/mac/xmac.c index 864089ecc..7b03bf055 100644 --- a/core/net/mac/xmac.c +++ b/core/net/mac/xmac.c @@ -763,7 +763,7 @@ qsend_packet(mac_callback_t sent, void *ptr) mac_call_sent_callback(sent, ptr, ret, 1); } /*---------------------------------------------------------------------------*/ -void +static void qsend_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { if(buf_list != NULL) { From a2073db715f5a1773e4416b3f78a7b6ded9dc075 Mon Sep 17 00:00:00 2001 From: simonduq Date: Tue, 4 Oct 2011 10:29:40 +0200 Subject: [PATCH 3/9] Removed ContikiMAC burst dependency to phase optimization --- core/net/mac/contikimac.c | 12 +++--------- core/net/mac/phase.c | 10 +++------- core/net/mac/phase.h | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/core/net/mac/contikimac.c b/core/net/mac/contikimac.c index 628be7ee4..ff4809bc0 100644 --- a/core/net/mac/contikimac.c +++ b/core/net/mac/contikimac.c @@ -548,7 +548,7 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr, struct rdc_buf_ #if WITH_PHASE_OPTIMIZATION ret = phase_wait(&phase_list, packetbuf_addr(PACKETBUF_ADDR_RECEIVER), CYCLE_TIME, GUARD_TIME, - mac_callback, mac_callback_ptr, buf_list, 0); + mac_callback, mac_callback_ptr, buf_list); if(ret == PHASE_DEFERRED) { return MAC_TX_DEFERRED; } @@ -748,14 +748,8 @@ qsend_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) } /* Do not send during reception of a burst */ if(we_are_receiving_burst) { - queuebuf_to_packetbuf(curr->buf); - /* We try to defer, and return an error this wasn't possible */ - int ret = phase_wait(&phase_list, packetbuf_addr(PACKETBUF_ADDR_RECEIVER), - CYCLE_TIME, GUARD_TIME, - sent, ptr, curr, 2); - if(ret != PHASE_DEFERRED) { - mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1); - } + /* Return COLLISION so the MAC may try again later */ + mac_call_sent_callback(sent, ptr, MAC_TX_COLLISION, 1); return; } /* The receiver needs to be awoken before we send */ diff --git a/core/net/mac/phase.c b/core/net/mac/phase.c index 513330181..6e29ed959 100644 --- a/core/net/mac/phase.c +++ b/core/net/mac/phase.c @@ -167,7 +167,7 @@ phase_wait(struct phase_list *list, const rimeaddr_t *neighbor, rtimer_clock_t cycle_time, rtimer_clock_t guard_time, mac_callback_t mac_callback, void *mac_callback_ptr, - struct rdc_buf_list *buf_list, int extra_deferment) + struct rdc_buf_list *buf_list) { struct phase *e; // const rimeaddr_t *neighbor = packetbuf_addr(PACKETBUF_ADDR_RECEIVER); @@ -176,7 +176,7 @@ phase_wait(struct phase_list *list, time for the next expected phase and setup a ctimer to switch on the radio just before the phase. */ e = find_neighbor(list, neighbor); - if((e != NULL) | extra_deferment) { + if(e != NULL) { rtimer_clock_t wait, now, expected, sync; clock_time_t ctimewait; @@ -202,14 +202,10 @@ phase_wait(struct phase_list *list, if(wait < guard_time) { wait += cycle_time; } - if(extra_deferment) { - wait += extra_deferment * cycle_time; - } - ctimewait = (CLOCK_SECOND * (wait - guard_time)) / RTIMER_ARCH_SECOND; - if((ctimewait > PHASE_DEFER_THRESHOLD) | extra_deferment) { + if(ctimewait > PHASE_DEFER_THRESHOLD) { struct phase_queueitem *p; p = memb_alloc(&queued_packets_memb); diff --git a/core/net/mac/phase.h b/core/net/mac/phase.h index 1ce17a697..d74431fcc 100644 --- a/core/net/mac/phase.h +++ b/core/net/mac/phase.h @@ -76,7 +76,7 @@ void phase_init(struct phase_list *list); phase_status_t phase_wait(struct phase_list *list, const rimeaddr_t *neighbor, rtimer_clock_t cycle_time, rtimer_clock_t wait_before, mac_callback_t mac_callback, void *mac_callback_ptr, - struct rdc_buf_list *buf_list, int extra_deferment); + struct rdc_buf_list *buf_list); void phase_update(const struct phase_list *list, const rimeaddr_t *neighbor, rtimer_clock_t time, int mac_status); From dd719275766f42d65d37f60b485b529724ffac33 Mon Sep 17 00:00:00 2001 From: David Kopf Date: Tue, 4 Oct 2011 14:10:32 -0400 Subject: [PATCH 4/9] Add ENERGEST, RIMESTATS, COMPOWER to status page --- apps/webserver-nano/httpd-cgi.c | 102 ++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/apps/webserver-nano/httpd-cgi.c b/apps/webserver-nano/httpd-cgi.c index 7608a9da2..2b0fdfce3 100644 --- a/apps/webserver-nano/httpd-cgi.c +++ b/apps/webserver-nano/httpd-cgi.c @@ -524,14 +524,14 @@ static unsigned short generate_sensor_readings(void *arg) { uint16_t numprinted; - uint16_t h,m,s; + uint16_t days,h,m,s; unsigned long seconds=clock_seconds(); -// uint8_t p1; static const char httpd_cgi_sensor0[] HTTPD_STRING_ATTR = "[Updated %d seconds ago]

"; static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "Temperature: %s
"; static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "Battery: %s
"; // static const char httpd_cgi_sensr12[] HTTPD_STRING_ATTR = "Temperature: %s Battery: %s
"; - static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "Elapsed timer : %02d:%02d:%02d
"; + static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "Uptime : %02d:%02d:%02d
"; + static const char httpd_cgi_sensor3d[] HTTPD_STRING_ATTR = "Uptime : %u days %02u:%02u:%02u
"; // static const char httpd_cgi_sensor4[] HTTPD_STRING_ATTR = "Sleeping time : %02d:%02d:%02d (%d%%)
"; numprinted=0; @@ -554,33 +554,97 @@ generate_sensor_readings(void *arg) numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor2, sensor_extvoltage); // numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensr12, sensor_temperature,sensor_extvoltage); + #if RADIOSTATS /* Remember radioontime for display below - slow connection might make it report longer than cpu ontime! */ savedradioontime = radioontime; #endif - h=seconds/3600; - s=seconds-h*3600; - m=s/60; - s=s-m*60; - numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3, h,m,s); - -/* TODO: some gcc's have a bug with %02d format that adds a zero byte and extra chars to the end of the string. + h=seconds/3600;s=seconds-h*3600;m=s/60;s=s-m*60; + days=h/24; + if (days == 0) { + numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3, h,m,s); + } else { + h=h-days*24; + numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3d, days,h,m,s); + } +/* TODO: some gcc's have a bug with %02d format that adds an extra char after the string terminator. * Seen with arm-none-eabi-gcc.exe (Sourcery G++ Lite 2008q3-66) 4.3.2 * Quick cosmetic fix to strip that off: */ - if (*(char *)(uip_appdata + numprinted-3)==0) {numprinted-=3;} - else if (*(char *)(uip_appdata + numprinted-2)==0) {numprinted-=2;} - else if (*(char *)(uip_appdata + numprinted-1)==0) {numprinted-=1;} - + if (*(char *)(uip_appdata + numprinted-3)==0) {numprinted-=3;} + else if (*(char *)(uip_appdata + numprinted-2)==0) {numprinted-=2;} + else if (*(char *)(uip_appdata + numprinted-1)==0) {numprinted-=1;} + #if 0 if (sleepseconds) { - p1=100UL*sleepseconds/seconds; - h=sleepseconds/3600; - s=sleepseconds-h*3600; - m=s/60; - s=s-m*60; + uint8_t p1; + p1=100UL*sleepseconds/seconds;h=sleepseconds/3600;s=sleepseconds-h*3600;m=s/60;s=s-m*60; numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor4, h,m,s,p1); } #endif + +#if ENERGEST_CONF_ON +{uint8_t p1,p2; +#if 0 +/* Update all the timers to get current values */ + for (p1=1;p1 Date: Mon, 10 Oct 2011 14:16:27 +0200 Subject: [PATCH 5/9] 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 From 65955ca4770747892006029fd98658b6eebd4194 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Mon, 10 Oct 2011 14:17:56 +0200 Subject: [PATCH 6/9] Fixed bug in well-known/core resource for small block sizes --- apps/er-coap-07/er-coap-07-engine.c | 90 +++++++++++++++++++---------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-engine.c b/apps/er-coap-07/er-coap-07-engine.c index 4b3312ca6..b81d0ee37 100644 --- a/apps/er-coap-07/er-coap-07-engine.c +++ b/apps/er-coap-07/er-coap-07-engine.c @@ -169,7 +169,7 @@ handle_incoming_data(void) PRINTF("handle_incoming_data(): block_offset >= response->payload_len\n"); response->code = BAD_OPTION_4_02; - coap_set_payload(response, (uint8_t*)"Block out of scope", 18); + coap_set_payload(response, (uint8_t*)"BlockOutOfScope", 15); } else { @@ -308,55 +308,82 @@ RESOURCE(well_known_core, METHOD_GET, ".well-known/core", ""); void well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - /* Response might be NULL for non-confirmable requests. */ - if (response) - { size_t strpos = 0; size_t bufpos = 0; + size_t tmplen = 0; resource_t* resource = NULL; for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next) { - strpos += snprintf((char *) buffer + bufpos, REST_MAX_CHUNK_SIZE - bufpos + 1, - "%s%s%s", - resource->url, - resource->attributes[0] ? ";" : "", - resource->attributes, - resource->next ? "," : "" ); + PRINTF("res: /%s (%p)\n", resource->url, resource); - PRINTF("discover: %s\n", resource->url); - - if (strpos <= *offset) + if (strpos >= *offset && bufpos < preferred_size) { - /* Discard output before current block */ - PRINTF(" if %d <= %ld B\n", strpos, *offset); - PRINTF(" %s\n", buffer); - bufpos = 0; + buffer[bufpos++] = '<'; } - else /* (strpos > *offset) */ + ++strpos; + + if (strpos >= *offset && bufpos < preferred_size) { - /* output partly in block */ - size_t len = MIN(strpos - *offset, preferred_size); + buffer[bufpos++] = '/'; + } + ++strpos; - PRINTF(" el %d/%d @ %ld B\n", len, preferred_size, *offset); + tmplen = strlen(resource->url); + if (strpos+tmplen > *offset) + { + bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1, + "%s", resource->url + (*offset-strpos > 0 ? *offset-strpos : 0)); + } + strpos += tmplen; - /* Block might start in the middle of the output; align with buffer start. */ - if (bufpos == 0) + if (strpos >= *offset && bufpos < preferred_size) + { + buffer[bufpos++] = '>'; + } + ++strpos; + + if (resource->attributes[0]) + { + if (strpos >= *offset && bufpos < preferred_size) { - memmove(buffer, buffer+strlen((char *)buffer)-strpos+*offset, len); + buffer[bufpos++] = ';'; } + ++strpos; - bufpos = len; - PRINTF(" %s\n", buffer); - - if (bufpos >= preferred_size) + tmplen = strlen(resource->attributes); + if (strpos+tmplen > *offset) { - break; + bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1, + "%s", resource->attributes + (*offset-strpos > 0 ? *offset-strpos : 0)); } + strpos += tmplen; + + } + + if (resource->next) + { + if (strpos >= *offset && bufpos < preferred_size) + { + buffer[bufpos++] = ','; + } + if (bufpos <= preferred_size) + { + ++strpos; + } + } + + /* buffer full, but resource not completed yet; or: do not break if resource exactly fills buffer. */ + if (bufpos >= preferred_size && strpos-bufpos > *offset) + { + PRINTF("res: BREAK at %s (%p)\n", resource->url, resource); + break; } } if (bufpos>0) { + PRINTF("BUF %d: %.*s\n", bufpos, bufpos, (char *) buffer); + coap_set_payload(response, buffer, bufpos ); coap_set_header_content_type(response, APPLICATION_LINK_FORMAT); } @@ -365,17 +392,18 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t PRINTF("well_known_core_handler(): bufpos<=0\n"); coap_set_rest_status(response, BAD_OPTION_4_02); - coap_set_payload(response, (uint8_t*)"Block out of scope", 18); + coap_set_payload(response, (uint8_t*)"BlockOutOfScope", 15); } if (resource==NULL) { + PRINTF("res: DONE\n"); *offset = -1; } else { + PRINTF("res: MORE at %s (%p)\n", resource->url, resource); *offset += bufpos; } - } } /*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(coap_receiver, ev, data) From efeebe953c1ecbff6067d86153ee09eb593ae72a Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Mon, 10 Oct 2011 14:25:03 +0200 Subject: [PATCH 7/9] Enabled UDP checksums for minimal-net --- platform/minimal-net/contiki-conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/minimal-net/contiki-conf.h b/platform/minimal-net/contiki-conf.h index 02ac073f9..2483e8b5a 100644 --- a/platform/minimal-net/contiki-conf.h +++ b/platform/minimal-net/contiki-conf.h @@ -141,7 +141,7 @@ typedef unsigned short uip_stats_t; #define UIP_CONF_TCP_SPLIT 0 #define UIP_CONF_IP_FORWARD 0 #define UIP_CONF_LOGGING 0 -#define UIP_CONF_UDP_CHECKSUMS 0 +#define UIP_CONF_UDP_CHECKSUMS 1 /* Not used but avoids compile errors while sicslowpan.c is being developed */ #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 From 2522566b6861abe8dd655635c0876a1a1242f649 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Mon, 10 Oct 2011 14:26:03 +0200 Subject: [PATCH 8/9] Added SMALL flag for border-router (exceeded sky memory) --- examples/ipv6/rpl-border-router/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/ipv6/rpl-border-router/Makefile b/examples/ipv6/rpl-border-router/Makefile index dbc8abbb1..c166000bc 100644 --- a/examples/ipv6/rpl-border-router/Makefile +++ b/examples/ipv6/rpl-border-router/Makefile @@ -7,6 +7,9 @@ WITH_UIP6=1 UIP_CONF_IPV6=1 CFLAGS+= -DUIP_CONF_IPV6_RPL +#linker optimizations +SMALL=1 + CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" PROJECT_SOURCEFILES += slip-bridge.c From df9f871313d597c1f0c29fc1ca42c0e48db81331 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Mon, 10 Oct 2011 16:09:17 +0200 Subject: [PATCH 9/9] Fixed Erbium chunks for minimal-net --- apps/er-coap-07/er-coap-07-engine.c | 15 ++++++--------- examples/er-rest-example/rest-server-example.c | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-engine.c b/apps/er-coap-07/er-coap-07-engine.c index b81d0ee37..6c0c44628 100644 --- a/apps/er-coap-07/er-coap-07-engine.c +++ b/apps/er-coap-07/er-coap-07-engine.c @@ -44,7 +44,7 @@ #include "er-coap-07-engine.h" -#define DEBUG 0 +#define DEBUG 0 #if DEBUG #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]", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15]) @@ -315,7 +315,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next) { - PRINTF("res: /%s (%p)\n", resource->url, resource); + PRINTF("res: /%s (%p)\npos: s%d, o%d, b%d\n", resource->url, resource, strpos, *offset, bufpos); if (strpos >= *offset && bufpos < preferred_size) { @@ -333,7 +333,8 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t if (strpos+tmplen > *offset) { bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1, - "%s", resource->url + (*offset-strpos > 0 ? *offset-strpos : 0)); + "%s", resource->url + ((*offset-(int32_t)strpos > 0) ? (*offset-(int32_t)strpos) : 0)); + /* minimal-net requires these casts */ } strpos += tmplen; @@ -355,10 +356,9 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t if (strpos+tmplen > *offset) { bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1, - "%s", resource->attributes + (*offset-strpos > 0 ? *offset-strpos : 0)); + "%s", resource->attributes + (*offset-(int32_t)strpos > 0 ? *offset-(int32_t)strpos : 0)); } strpos += tmplen; - } if (resource->next) @@ -367,10 +367,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t { buffer[bufpos++] = ','; } - if (bufpos <= preferred_size) - { - ++strpos; - } + ++strpos; } /* buffer full, but resource not completed yet; or: do not break if resource exactly fills buffer. */ diff --git a/examples/er-rest-example/rest-server-example.c b/examples/er-rest-example/rest-server-example.c index 3307f808f..48bfffb26 100644 --- a/examples/er-rest-example/rest-server-example.c +++ b/examples/er-rest-example/rest-server-example.c @@ -301,11 +301,19 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre } /* Generate data until reaching CHUNKS_TOTAL. */ - while (strpos CHUNKS_TOTAL) + + /* snprintf() does not adjust return value if truncated by size. */ + if (strpos > preferred_size) + { + strpos = preferred_size; + } + + /* Truncate if above total size. */ + if (*offset+(int32_t)strpos > CHUNKS_TOTAL) { strpos = CHUNKS_TOTAL - *offset; } @@ -315,7 +323,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre /* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */ *offset += strpos; - /* Signal end of resource. */ + /* Signal end of resource representation. */ if (*offset>=CHUNKS_TOTAL) { *offset = -1;