Erbium code cleanup.
This commit is contained in:
parent
4c3e858df5
commit
2240289d1f
9 changed files with 430 additions and 340 deletions
|
@ -59,7 +59,7 @@ DETAILS
|
|||
The Erbium CoAP currently implements draft 08.
|
||||
Central features are commented in rest-server-example.c.
|
||||
In general, apps/er-coap-07 supports:
|
||||
* All CoAP-07 header options
|
||||
* All draft 08 header options
|
||||
* CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS)
|
||||
* Blockwise Transfers (note REST_MAX_CHUNK_SIZE)
|
||||
* Separate Responses (see rest_set_pre_handler() and coap_separate_handler())
|
||||
|
@ -73,6 +73,7 @@ The Makefile uses WITH_COAP to configure different implementations for the Erbiu
|
|||
The default port for coap-07 is 5683.
|
||||
* WITH_COAP=3 uses Erbium CoAP 03 apps/er-coap-03/.
|
||||
The default port for coap-03 is 61616.
|
||||
er-coap-03 produces some warnings, as it not fully maintained anymore.
|
||||
* WITH_COAP=0 is a stub to link an Erbium HTTP engine that uses the same resource abstraction (REST.x() functions and RESOURCE macros.
|
||||
|
||||
TODOs
|
||||
|
|
|
@ -99,7 +99,7 @@ static int uri_switch = 0;
|
|||
void
|
||||
client_chunk_handler(void *response)
|
||||
{
|
||||
const uint8_t *chunk;
|
||||
uint8_t *chunk;
|
||||
int len = coap_get_payload(response, &chunk);
|
||||
printf("|%.*s", len, (char *)chunk);
|
||||
}
|
||||
|
@ -128,16 +128,13 @@ PROCESS_THREAD(coap_client_example, ev, data)
|
|||
if (etimer_expired(&et)) {
|
||||
printf("--Toggle timer--\n");
|
||||
|
||||
#if PLATFORM_HAS_LEDS
|
||||
/* prepare request, TID is set by COAP_BLOCKING_REQUEST() */
|
||||
coap_init_message(request, COAP_TYPE_CON, COAP_POST, 0 );
|
||||
coap_set_header_uri_path(request, service_urls[1]);
|
||||
coap_set_payload(request, (uint8_t *)"Toggle!", 8);
|
||||
#else
|
||||
/* prepare request, TID is set by COAP_BLOCKING_REQUEST() */
|
||||
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0 );
|
||||
coap_set_header_uri_path(request, "hello");
|
||||
#endif
|
||||
|
||||
const char msg[] = "Toggle!";
|
||||
coap_set_payload(request, (uint8_t *)msg, sizeof(msg)-1);
|
||||
|
||||
|
||||
PRINT6ADDR(&server_ipaddr);
|
||||
PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT));
|
||||
|
|
|
@ -158,7 +158,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
|||
|
||||
/* The other getters copy the value (or string/array pointer) to the given pointers and return 1 for success or the length of strings/arrays. */
|
||||
uint32_t max_age = 0;
|
||||
const char *str = "";
|
||||
const char *str = NULL;
|
||||
uint32_t observe = 0;
|
||||
const uint8_t *bytes = NULL;
|
||||
uint32_t block_num = 0;
|
||||
|
@ -312,7 +312,9 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
|||
{
|
||||
REST.set_response_status(response, REST.status.BAD_OPTION);
|
||||
/* A block error message should not exceed the minimum block size (16). */
|
||||
REST.set_response_payload(response, (uint8_t*)"BlockOutOfScope", 15);
|
||||
|
||||
const char error_msg[] = "BlockOutOfScope";
|
||||
REST.set_response_payload(response, (uint8_t *)error_msg, sizeof(error_msg)-1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -359,7 +361,10 @@ void
|
|||
polling_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
REST.set_response_payload(response, (uint8_t *)"It's periodic!", 14);
|
||||
|
||||
/* Usually, a CoAP server would response with the current resource representation. */
|
||||
const char msg[] = "It's periodic!";
|
||||
REST.set_response_payload(response, (uint8_t *)msg, sizeof(msg)-1);
|
||||
|
||||
/* A post_handler that handles subscriptions will be called for periodic resources by the REST framework. */
|
||||
}
|
||||
|
@ -397,7 +402,10 @@ void
|
|||
event_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
REST.set_response_payload(response, (uint8_t *)"It's eventful!", 14);
|
||||
|
||||
/* Usually, a CoAP server would response with the current resource representation. */
|
||||
const char msg[] = "It's eventful!";
|
||||
REST.set_response_payload(response, (uint8_t *)msg, sizeof(msg)-1);
|
||||
|
||||
/* A post_handler that handles subscriptions/observing will be called for periodic resources by the framework. */
|
||||
}
|
||||
|
@ -519,7 +527,8 @@ light_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
|
|||
else
|
||||
{
|
||||
REST.set_response_status(response, REST.status.UNSUPPORTED_MADIA_TYPE);
|
||||
REST.set_response_payload(response, (uint8_t *)"Supporting content-types text/plain, application/xml, and application/json", 74);
|
||||
const char msg[] = "Supporting content-types text/plain, application/xml, and application/json";
|
||||
REST.set_response_payload(response, (uint8_t *)msg, sizeof(msg)-1);
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_HAS_LIGHT */
|
||||
|
@ -552,7 +561,8 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
|||
else
|
||||
{
|
||||
REST.set_response_status(response, REST.status.UNSUPPORTED_MADIA_TYPE);
|
||||
REST.set_response_payload(response, (uint8_t *)"Supporting content-types text/plain and application/json", 56);
|
||||
const char msg[] = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, (uint8_t *)msg, sizeof(msg)-1);
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_HAS_BATTERY */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue