mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-02-22 06:29:01 +00:00
Used Uncrustify and fixed Travis build errors.
This commit is contained in:
parent
3dd5bd7a37
commit
bb737f85ae
0
apps/er-coap/er-coap-conf.h
Executable file → Normal file
0
apps/er-coap/er-coap-conf.h
Executable file → Normal file
0
apps/er-coap/er-coap-constants.h
Executable file → Normal file
0
apps/er-coap/er-coap-constants.h
Executable file → Normal file
41
apps/er-coap/er-coap-engine.c
Executable file → Normal file
41
apps/er-coap/er-coap-engine.c
Executable file → Normal file
@ -41,8 +41,17 @@
|
||||
#include <string.h>
|
||||
#include "er-coap-engine.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
PROCESS(coap_engine, "CoAP Engine");
|
||||
|
||||
@ -107,14 +116,12 @@ coap_receive(void)
|
||||
/* unreliable NON requests are answered with a NON as well */
|
||||
coap_init_message(response, COAP_TYPE_NON, CONTENT_2_05,
|
||||
coap_get_mid());
|
||||
}
|
||||
|
||||
/* mirror token */
|
||||
}
|
||||
if(message->token_len) {
|
||||
coap_set_token(response, message->token, message->token_len);
|
||||
}
|
||||
|
||||
/* get offset for blockwise transfers */
|
||||
}
|
||||
if(coap_get_header_block2
|
||||
(message, &block_num, NULL, &block_size, &block_offset)) {
|
||||
PRINTF("Blockwise: block request %lu (%u/%u) @ %lu bytes\n",
|
||||
@ -133,7 +140,7 @@ coap_receive(void)
|
||||
|
||||
if(erbium_status_code == NO_ERROR) {
|
||||
|
||||
//TODO coap_handle_blockwise(request, response, start_offset, end_offset);
|
||||
/* TODO coap_handle_blockwise(request, response, start_offset, end_offset); */
|
||||
|
||||
/* resource is unaware of Block1 */
|
||||
if(IS_OPTION(message, COAP_OPTION_BLOCK1)
|
||||
@ -197,9 +204,9 @@ coap_receive(void)
|
||||
REST_MAX_CHUNK_SIZE));
|
||||
} /* blockwise transfer handling */
|
||||
} /* no errors/hooks */
|
||||
} /* successful service callback */
|
||||
|
||||
/* successful service callback */
|
||||
/* serialize response */
|
||||
}
|
||||
if(erbium_status_code == NO_ERROR) {
|
||||
if((transaction->packet_len = coap_serialize_message(response,
|
||||
transaction->
|
||||
@ -208,12 +215,10 @@ coap_receive(void)
|
||||
erbium_status_code = PACKET_SERIALIZATION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
erbium_status_code = NOT_IMPLEMENTED_5_01;
|
||||
coap_error_message = "NoServiceCallbck"; /* no 'a' to fit into 16 bytes */
|
||||
} /* if(service callback) */
|
||||
|
||||
} else {
|
||||
erbium_status_code = SERVICE_UNAVAILABLE_5_03;
|
||||
coap_error_message = "NoFreeTraBuffer";
|
||||
@ -249,14 +254,14 @@ coap_receive(void)
|
||||
}
|
||||
/* if(ACKed transaction) */
|
||||
transaction = NULL;
|
||||
|
||||
} /* request or response */
|
||||
} /* parsed correctly */
|
||||
|
||||
/* if(parsed correctly) */
|
||||
if(erbium_status_code == NO_ERROR) {
|
||||
if(transaction)
|
||||
if(transaction) {
|
||||
coap_send_transaction(transaction);
|
||||
}
|
||||
} else if(erbium_status_code == MANUAL_RESPONSE) {
|
||||
PRINTF("Clearing transaction for manual response");
|
||||
coap_clear_transaction(transaction);
|
||||
@ -272,9 +277,8 @@ coap_receive(void)
|
||||
} else if(erbium_status_code >= 192) {
|
||||
/* set to sendable error code */
|
||||
erbium_status_code = INTERNAL_SERVER_ERROR_5_00;
|
||||
}
|
||||
|
||||
/* reuse input buffer for error message */
|
||||
}
|
||||
coap_init_message(message, reply_type, erbium_status_code,
|
||||
message->mid);
|
||||
coap_set_payload(message, coap_error_message,
|
||||
@ -381,7 +385,6 @@ PT_THREAD(coap_blocking_request
|
||||
coap_set_header_block2(request, state->block_num, 0,
|
||||
REST_MAX_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
state->transaction->packet_len = coap_serialize_message(request,
|
||||
state->
|
||||
transaction->
|
||||
@ -473,7 +476,8 @@ const struct rest_implementation coap_rest_implementation = {
|
||||
BAD_GATEWAY_5_02,
|
||||
SERVICE_UNAVAILABLE_5_03,
|
||||
GATEWAY_TIMEOUT_5_04,
|
||||
PROXYING_NOT_SUPPORTED_5_05},
|
||||
PROXYING_NOT_SUPPORTED_5_05
|
||||
},
|
||||
|
||||
{
|
||||
TEXT_PLAIN,
|
||||
@ -497,6 +501,7 @@ const struct rest_implementation coap_rest_implementation = {
|
||||
APPLICATION_FASTINFOSET,
|
||||
APPLICATION_SOAP_FASTINFOSET,
|
||||
APPLICATION_JSON,
|
||||
APPLICATION_X_OBIX_BINARY}
|
||||
APPLICATION_X_OBIX_BINARY
|
||||
}
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
0
apps/er-coap/er-coap-engine.h
Executable file → Normal file
0
apps/er-coap/er-coap-engine.h
Executable file → Normal file
19
apps/er-coap/er-coap-observe.c
Executable file → Normal file
19
apps/er-coap/er-coap-observe.c
Executable file → Normal file
@ -40,8 +40,17 @@
|
||||
#include <string.h>
|
||||
#include "er-coap-observe.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
MEMB(observers_memb, coap_observer_t, COAP_MAX_OBSERVERS);
|
||||
@ -199,8 +208,9 @@ coap_notify_observers(resource_t * resource)
|
||||
transaction->packet + COAP_MAX_HEADER_SIZE,
|
||||
REST_MAX_CHUNK_SIZE, NULL);
|
||||
|
||||
if(notification->code < BAD_REQUEST_4_00)
|
||||
if(notification->code < BAD_REQUEST_4_00) {
|
||||
coap_set_header_observe(notification, (obs->obs_counter)++);
|
||||
}
|
||||
coap_set_token(notification, obs->token, obs->token_len);
|
||||
|
||||
/* TODO use resource-specific COAP_OBSERVE_REFRESH_INTERVAL for CON to check client interest */
|
||||
@ -248,7 +258,8 @@ coap_observe_handler(resource_t * resource, void *request, void *response)
|
||||
coap_remove_observer_by_token(&UIP_IP_BUF->srcipaddr,
|
||||
UIP_UDP_BUF->srcport, coap_req->token,
|
||||
coap_req->token_len);
|
||||
} /* if(observe) */
|
||||
/* if(observe) */
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
0
apps/er-coap/er-coap-observe.h
Executable file → Normal file
0
apps/er-coap/er-coap-observe.h
Executable file → Normal file
22
apps/er-coap/er-coap-res-well-known-core.c
Executable file → Normal file
22
apps/er-coap/er-coap-res-well-known-core.c
Executable file → Normal file
@ -39,8 +39,17 @@
|
||||
#include <string.h>
|
||||
#include "er-coap-engine.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*- Resource Handlers -------------------------------------------------------*/
|
||||
@ -89,15 +98,17 @@ well_known_core_get_handler(void *request, void *response, uint8_t * buffer,
|
||||
if(len) {
|
||||
if(strcmp(filter, "href") == 0) {
|
||||
attrib = strstr(resource->url, value);
|
||||
if(attrib == NULL || (value[-1] == '/' && attrib != resource->url))
|
||||
if(attrib == NULL || (value[-1] == '/' && attrib != resource->url)) {
|
||||
continue;
|
||||
}
|
||||
end = attrib + strlen(attrib);
|
||||
} else {
|
||||
attrib = strstr(resource->attributes, filter);
|
||||
if(attrib == NULL
|
||||
|| (attrib[strlen(filter)] != '='
|
||||
&& attrib[strlen(filter)] != '"'))
|
||||
&& attrib[strlen(filter)] != '"')) {
|
||||
continue;
|
||||
}
|
||||
attrib += strlen(filter) + 2;
|
||||
end = strchr(attrib, '"');
|
||||
}
|
||||
@ -119,8 +130,9 @@ well_known_core_get_handler(void *request, void *response, uint8_t * buffer,
|
||||
}
|
||||
PRINTF("Filter: res has prefix %s\n", found);
|
||||
if(lastchar != '*'
|
||||
&& (found[len] != '"' && found[len] != ' ' && found[len] != '\0'))
|
||||
&& (found[len] != '"' && found[len] != ' ' && found[len] != '\0')) {
|
||||
continue;
|
||||
}
|
||||
PRINTF("Filter: res has match\n");
|
||||
}
|
||||
#endif
|
||||
|
16
apps/er-coap/er-coap-separate.c
Executable file → Normal file
16
apps/er-coap/er-coap-separate.c
Executable file → Normal file
@ -41,8 +41,17 @@
|
||||
#include "er-coap-separate.h"
|
||||
#include "er-coap-transactions.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*- Separate Response API ---------------------------------------------------*/
|
||||
@ -58,7 +67,7 @@
|
||||
void
|
||||
coap_separate_reject()
|
||||
{
|
||||
// TODO: Accept string pointer for custom error message
|
||||
/* TODO: Accept string pointer for custom error message */
|
||||
erbium_status_code = SERVICE_UNAVAILABLE_5_03;
|
||||
coap_error_message = "AlreadyInUse";
|
||||
}
|
||||
@ -112,7 +121,6 @@ coap_separate_accept(void *request, coap_separate_t * separate_store)
|
||||
|
||||
/* signal the engine to skip automatic response and clear transaction by engine */
|
||||
erbium_status_code = MANUAL_RESPONSE;
|
||||
|
||||
} else {
|
||||
PRINTF("ERROR: Response transaction for separate request not found!\n");
|
||||
erbium_status_code = INTERNAL_SERVER_ERROR_5_00;
|
||||
|
1
apps/er-coap/er-coap-separate.h
Executable file → Normal file
1
apps/er-coap/er-coap-separate.h
Executable file → Normal file
@ -55,7 +55,6 @@ typedef struct coap_separate {
|
||||
/* separate + blockwise is untested! */
|
||||
uint32_t block2_num;
|
||||
uint16_t block2_size;
|
||||
|
||||
} coap_separate_t;
|
||||
|
||||
int coap_separate_handler(resource_t *resource, void *request,
|
||||
|
15
apps/er-coap/er-coap-transactions.c
Executable file → Normal file
15
apps/er-coap/er-coap-transactions.c
Executable file → Normal file
@ -41,8 +41,17 @@
|
||||
#include "er-coap-transactions.h"
|
||||
#include "er-coap-observe.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS);
|
||||
@ -58,7 +67,6 @@ coap_register_as_transaction_handler()
|
||||
{
|
||||
transaction_handler_process = PROCESS_CURRENT();
|
||||
}
|
||||
|
||||
coap_transaction_t *
|
||||
coap_new_transaction(uint16_t mid, uip_ipaddr_t *addr, uint16_t port)
|
||||
{
|
||||
@ -147,7 +155,6 @@ coap_clear_transaction(coap_transaction_t * t)
|
||||
memb_free(&transactions_memb, t);
|
||||
}
|
||||
}
|
||||
|
||||
coap_transaction_t *
|
||||
coap_get_transaction_by_mid(uint16_t mid)
|
||||
{
|
||||
|
0
apps/er-coap/er-coap-transactions.h
Executable file → Normal file
0
apps/er-coap/er-coap-transactions.h
Executable file → Normal file
182
apps/er-coap/er-coap.c
Executable file → Normal file
182
apps/er-coap/er-coap.c
Executable file → Normal file
@ -40,11 +40,21 @@
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include "er-coap.h"
|
||||
#include "er-coap-transactions.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*- Variables ---------------------------------------------------------------*/
|
||||
@ -125,29 +135,35 @@ coap_serialize_int_option(unsigned int number, unsigned int current_number,
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
if(0xFF000000 & value)
|
||||
if(0xFF000000 & value) {
|
||||
++i;
|
||||
if(0xFFFF0000 & value)
|
||||
}
|
||||
if(0xFFFF0000 & value) {
|
||||
++i;
|
||||
if(0xFFFFFF00 & value)
|
||||
}
|
||||
if(0xFFFFFF00 & value) {
|
||||
++i;
|
||||
if(0xFFFFFFFF & value)
|
||||
}
|
||||
if(0xFFFFFFFF & value) {
|
||||
++i;
|
||||
|
||||
}
|
||||
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number,
|
||||
i);
|
||||
|
||||
i = coap_set_option_header(number - current_number, i, buffer);
|
||||
|
||||
if(0xFF000000 & value)
|
||||
if(0xFF000000 & value) {
|
||||
buffer[i++] = (uint8_t)(value >> 24);
|
||||
if(0xFFFF0000 & value)
|
||||
}
|
||||
if(0xFFFF0000 & value) {
|
||||
buffer[i++] = (uint8_t)(value >> 16);
|
||||
if(0xFFFFFF00 & value)
|
||||
}
|
||||
if(0xFFFFFF00 & value) {
|
||||
buffer[i++] = (uint8_t)(value >> 8);
|
||||
if(0xFFFFFFFF & value)
|
||||
}
|
||||
if(0xFFFFFFFF & value) {
|
||||
buffer[i++] = (uint8_t)(value);
|
||||
|
||||
}
|
||||
return i;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -246,13 +262,11 @@ coap_get_variable(const char *buffer, size_t length, const char *name,
|
||||
if(value_end == NULL) {
|
||||
value_end = end;
|
||||
}
|
||||
|
||||
*output = start;
|
||||
|
||||
return (value_end - start);
|
||||
return value_end - start;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -467,9 +481,8 @@ coap_parse_message(void *packet, uint8_t * data, uint16_t data_len)
|
||||
/* also for receiving, the Erbium upper bound is REST_MAX_CHUNK_SIZE */
|
||||
if(coap_pkt->payload_len > REST_MAX_CHUNK_SIZE) {
|
||||
coap_pkt->payload_len = REST_MAX_CHUNK_SIZE;
|
||||
}
|
||||
|
||||
/* null-terminate payload */
|
||||
}
|
||||
coap_pkt->payload[coap_pkt->payload_len] = '\0';
|
||||
|
||||
break;
|
||||
@ -671,7 +684,6 @@ coap_get_query_variable(void *packet, const char *name, const char **output)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
coap_get_post_variable(void *packet, const char *name, const char **output)
|
||||
{
|
||||
@ -713,13 +725,12 @@ coap_get_header_content_format(void *packet, unsigned int *format)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*format = coap_pkt->content_format;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_content_format(void *packet, unsigned int format)
|
||||
{
|
||||
@ -735,13 +746,12 @@ coap_get_header_accept(void *packet, unsigned int *accept)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*accept = coap_pkt->accept;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_accept(void *packet, unsigned int accept)
|
||||
{
|
||||
@ -761,10 +771,8 @@ coap_get_header_max_age(void *packet, uint32_t * age)
|
||||
*age = COAP_DEFAULT_MAX_AGE;
|
||||
} else {
|
||||
*age = coap_pkt->max_age;
|
||||
} return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_max_age(void *packet, uint32_t age)
|
||||
{
|
||||
@ -780,13 +788,12 @@ coap_get_header_etag(void *packet, const uint8_t ** etag)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_ETAG))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_ETAG)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*etag = coap_pkt->etag;
|
||||
return coap_pkt->etag_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len)
|
||||
{
|
||||
@ -805,13 +812,12 @@ coap_get_header_if_match(void *packet, const uint8_t ** etag)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*etag = coap_pkt->if_match;
|
||||
return coap_pkt->if_match_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_if_match(void *packet, const uint8_t *etag, size_t etag_len)
|
||||
{
|
||||
@ -830,7 +836,6 @@ coap_get_header_if_none_match(void *packet)
|
||||
return IS_OPTION((coap_packet_t *)packet,
|
||||
COAP_OPTION_IF_NONE_MATCH) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_if_none_match(void *packet)
|
||||
{
|
||||
@ -843,13 +848,12 @@ coap_get_header_proxy_uri(void *packet, const char **uri)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*uri = coap_pkt->proxy_uri;
|
||||
return coap_pkt->proxy_uri_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_proxy_uri(void *packet, const char *uri)
|
||||
{
|
||||
@ -869,13 +873,12 @@ coap_get_header_uri_host(void *packet, const char **host)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*host = coap_pkt->uri_host;
|
||||
return coap_pkt->uri_host_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_host(void *packet, const char *host)
|
||||
{
|
||||
@ -893,13 +896,12 @@ coap_get_header_uri_path(void *packet, const char **path)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*path = coap_pkt->uri_path;
|
||||
return coap_pkt->uri_path_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_path(void *packet, const char *path)
|
||||
{
|
||||
@ -920,13 +922,12 @@ coap_get_header_uri_query(void *packet, const char **query)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*query = coap_pkt->uri_query;
|
||||
return coap_pkt->uri_query_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_query(void *packet, const char *query)
|
||||
{
|
||||
@ -947,13 +948,12 @@ coap_get_header_location_path(void *packet, const char **path)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*path = coap_pkt->location_path;
|
||||
return coap_pkt->location_path_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_location_path(void *packet, const char *path)
|
||||
{
|
||||
@ -969,12 +969,11 @@ coap_set_header_location_path(void *packet, const char *path)
|
||||
coap_pkt->location_path_len = query - path;
|
||||
} else {
|
||||
coap_pkt->location_path_len = strlen(path);
|
||||
}
|
||||
} coap_pkt->location_path = path;
|
||||
|
||||
coap_pkt->location_path = path;
|
||||
|
||||
if(coap_pkt->location_path_len > 0)
|
||||
if(coap_pkt->location_path_len > 0) {
|
||||
SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH);
|
||||
}
|
||||
return coap_pkt->location_path_len;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -983,13 +982,12 @@ coap_get_header_location_query(void *packet, const char **query)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*query = coap_pkt->location_query;
|
||||
return coap_pkt->location_query_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_location_query(void *packet, const char *query)
|
||||
{
|
||||
@ -1010,13 +1008,12 @@ coap_get_header_observe(void *packet, uint32_t * observe)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*observe = coap_pkt->observe;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_observe(void *packet, uint32_t observe)
|
||||
{
|
||||
@ -1033,35 +1030,39 @@ coap_get_header_block2(void *packet, uint32_t * num, uint8_t * more,
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* pointers may be NULL to get only specific block parameters */
|
||||
if(num != NULL)
|
||||
if(num != NULL) {
|
||||
*num = coap_pkt->block2_num;
|
||||
if(more != NULL)
|
||||
}
|
||||
if(more != NULL) {
|
||||
*more = coap_pkt->block2_more;
|
||||
if(size != NULL)
|
||||
}
|
||||
if(size != NULL) {
|
||||
*size = coap_pkt->block2_size;
|
||||
if(offset != NULL)
|
||||
}
|
||||
if(offset != NULL) {
|
||||
*offset = coap_pkt->block2_offset;
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_block2(void *packet, uint32_t num, uint8_t more,
|
||||
uint16_t size)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(size < 16)
|
||||
if(size < 16) {
|
||||
return 0;
|
||||
if(size > 2048)
|
||||
}
|
||||
if(size > 2048) {
|
||||
return 0;
|
||||
if(num > 0x0FFFFF)
|
||||
}
|
||||
if(num > 0x0FFFFF) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
coap_pkt->block2_num = num;
|
||||
coap_pkt->block2_more = more ? 1 : 0;
|
||||
coap_pkt->block2_size = size;
|
||||
@ -1076,35 +1077,39 @@ coap_get_header_block1(void *packet, uint32_t * num, uint8_t * more,
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* pointers may be NULL to get only specific block parameters */
|
||||
if(num != NULL)
|
||||
if(num != NULL) {
|
||||
*num = coap_pkt->block1_num;
|
||||
if(more != NULL)
|
||||
}
|
||||
if(more != NULL) {
|
||||
*more = coap_pkt->block1_more;
|
||||
if(size != NULL)
|
||||
}
|
||||
if(size != NULL) {
|
||||
*size = coap_pkt->block1_size;
|
||||
if(offset != NULL)
|
||||
}
|
||||
if(offset != NULL) {
|
||||
*offset = coap_pkt->block1_offset;
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_block1(void *packet, uint32_t num, uint8_t more,
|
||||
uint16_t size)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(size < 16)
|
||||
if(size < 16) {
|
||||
return 0;
|
||||
if(size > 2048)
|
||||
}
|
||||
if(size > 2048) {
|
||||
return 0;
|
||||
if(num > 0x0FFFFF)
|
||||
}
|
||||
if(num > 0x0FFFFF) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
coap_pkt->block1_num = num;
|
||||
coap_pkt->block1_more = more;
|
||||
coap_pkt->block1_size = size;
|
||||
@ -1118,13 +1123,12 @@ coap_get_header_size2(void *packet, uint32_t * size)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*size = coap_pkt->size2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_size2(void *packet, uint32_t size)
|
||||
{
|
||||
@ -1140,13 +1144,12 @@ coap_get_header_size1(void *packet, uint32_t * size)
|
||||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1))
|
||||
if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1)) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
*size = coap_pkt->size1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_size1(void *packet, uint32_t size)
|
||||
{
|
||||
@ -1170,7 +1173,6 @@ coap_get_payload(void *packet, const uint8_t ** payload)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_payload(void *packet, const void *payload, size_t length)
|
||||
{
|
||||
|
5
apps/er-coap/er-coap.h
Executable file → Normal file
5
apps/er-coap/er-coap.h
Executable file → Normal file
@ -40,7 +40,7 @@
|
||||
#define ER_COAP_H_
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include "net/uip.h"
|
||||
#include "contiki-net.h"
|
||||
#include "er-coap-constants.h"
|
||||
#include "er-coap-conf.h"
|
||||
|
||||
@ -123,7 +123,6 @@ typedef struct {
|
||||
|
||||
uint16_t payload_len;
|
||||
uint8_t *payload;
|
||||
|
||||
} coap_packet_t;
|
||||
|
||||
/* option format serialization */
|
||||
@ -159,7 +158,7 @@ typedef struct {
|
||||
{ \
|
||||
PRINTF(text " [%lu%s (%u B/blk)]\n", coap_pkt->field##_num, coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size); \
|
||||
uint32_t block = coap_pkt->field##_num << 4; \
|
||||
if (coap_pkt->field##_more) block |= 0x8; \
|
||||
if(coap_pkt->field##_more) { block |= 0x8; } \
|
||||
block |= 0xF & coap_log_2(coap_pkt->field##_size / 16); \
|
||||
PRINTF(text " encoded: 0x%lX\n", block); \
|
||||
option += coap_serialize_int_option(number, current_number, option, block); \
|
||||
|
0
apps/rest-engine/rest-constants.h
Executable file → Normal file
0
apps/rest-engine/rest-constants.h
Executable file → Normal file
16
apps/rest-engine/rest-engine.c
Executable file → Normal file
16
apps/rest-engine/rest-engine.c
Executable file → Normal file
@ -42,8 +42,17 @@
|
||||
#include "contiki.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
PROCESS(rest_engine_process, "REST Engine");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -151,7 +160,6 @@ rest_invoke_restful_service(void *request, void *response, uint8_t * buffer,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
REST.set_response_status(response, REST.status.NOT_FOUND);
|
||||
} else if(allowed) {
|
||||
@ -160,7 +168,6 @@ rest_invoke_restful_service(void *request, void *response, uint8_t * buffer,
|
||||
REST.subscription_handler(resource, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
return found & allowed;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -184,7 +191,6 @@ PROCESS_THREAD(rest_engine_process, ev, data)
|
||||
periodic_resource->period);
|
||||
}
|
||||
}
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
|
1
apps/rest-engine/rest-engine.h
Executable file → Normal file
1
apps/rest-engine/rest-engine.h
Executable file → Normal file
@ -66,7 +66,6 @@
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif /* MIN */
|
||||
|
||||
|
||||
struct resource_s;
|
||||
struct periodic_resource_s;
|
||||
|
||||
|
@ -13,7 +13,15 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
# automatically build RESTful resources
|
||||
REST_RESOURCES_DIR = ./resources
|
||||
ifndef TARGET
|
||||
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c'))
|
||||
else
|
||||
ifeq ($(TARGET), native)
|
||||
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c'))
|
||||
else
|
||||
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c' ! -name 'res-plugtest*'))
|
||||
endif
|
||||
endif
|
||||
|
||||
PROJECTDIRS += $(REST_RESOURCES_DIR)
|
||||
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
|
||||
|
21
examples/er-rest-example/er-example-client.c
Executable file → Normal file
21
examples/er-rest-example/er-example-client.c
Executable file → Normal file
@ -44,13 +44,21 @@
|
||||
#include "er-coap-engine.h"
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#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, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1) */
|
||||
|
||||
#define LOCAL_PORT UIP_HTONS(COAP_DEFAULT_PORT + 1)
|
||||
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
|
||||
@ -60,7 +68,6 @@
|
||||
PROCESS(er_example_client, "Erbium Example Client");
|
||||
AUTOSTART_PROCESSES(&er_example_client);
|
||||
|
||||
|
||||
uip_ipaddr_t server_ipaddr;
|
||||
static struct etimer et;
|
||||
|
||||
@ -83,8 +90,6 @@ client_chunk_handler(void *response)
|
||||
|
||||
printf("|%.*s", len, (char *)chunk);
|
||||
}
|
||||
|
||||
|
||||
PROCESS_THREAD(er_example_client, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
@ -117,7 +122,6 @@ PROCESS_THREAD(er_example_client, ev, data)
|
||||
|
||||
coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1);
|
||||
|
||||
|
||||
PRINT6ADDR(&server_ipaddr);
|
||||
PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT));
|
||||
|
||||
@ -148,7 +152,6 @@ PROCESS_THREAD(er_example_client, ev, data)
|
||||
|
||||
uri_switch = (uri_switch + 1) % NUMBER_OF_URLS;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
0
examples/er-rest-example/er-example-server.c
Executable file → Normal file
0
examples/er-rest-example/er-example-server.c
Executable file → Normal file
1
examples/er-rest-example/er-plugtest-server.c
Executable file → Normal file
1
examples/er-rest-example/er-plugtest-server.c
Executable file → Normal file
@ -122,7 +122,6 @@ PROCESS_THREAD(plugtest_server, ev, data)
|
||||
/* Define application-specific events here. */
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
} /* while (1) */
|
||||
|
||||
PROCESS_END();
|
||||
|
13
examples/er-rest-example/er-plugtest.h
Executable file → Normal file
13
examples/er-rest-example/er-plugtest.h
Executable file → Normal file
@ -43,8 +43,17 @@
|
||||
#warning "Should only be compiled for native!"
|
||||
#endif
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
0
examples/er-rest-example/project-conf.h
Executable file → Normal file
0
examples/er-rest-example/project-conf.h
Executable file → Normal file
1
examples/er-rest-example/resources/res-battery.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-battery.c
Executable file → Normal file
@ -78,5 +78,4 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PLATFORM_HAS_BATTERY */
|
||||
|
4
examples/er-rest-example/resources/res-chunks.c
Executable file → Normal file
4
examples/er-rest-example/resources/res-chunks.c
Executable file → Normal file
@ -80,13 +80,11 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
/* snprintf() does not adjust return value if truncated by size. */
|
||||
if(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. */
|
||||
|
14
examples/er-rest-example/resources/res-event.c
Executable file → Normal file
14
examples/er-rest-example/resources/res-event.c
Executable file → Normal file
@ -40,8 +40,17 @@
|
||||
#include "rest-engine.h"
|
||||
#include "er-coap.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
static void res_event_handler();
|
||||
@ -72,7 +81,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
|
||||
/* A post_handler that handles subscriptions/observing will be called for periodic resources by the framework. */
|
||||
}
|
||||
|
||||
/*
|
||||
* Additionally, res_event_handler must be implemented for each EVENT_RESOURCE.
|
||||
* It is called through <res_name>.trigger(), usually from the server process.
|
||||
|
12
examples/er-rest-example/resources/res-hello.c
Executable file → Normal file
12
examples/er-rest-example/resources/res-hello.c
Executable file → Normal file
@ -66,14 +66,16 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
/* 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)) {
|
||||
length = atoi(len);
|
||||
if(length<0) length = 0;
|
||||
if(length>REST_MAX_CHUNK_SIZE) length = REST_MAX_CHUNK_SIZE;
|
||||
if(length < 0) {
|
||||
length = 0;
|
||||
}
|
||||
if(length > REST_MAX_CHUNK_SIZE) {
|
||||
length = REST_MAX_CHUNK_SIZE;
|
||||
}
|
||||
memcpy(buffer, message, length);
|
||||
} else {
|
||||
memcpy(buffer, message, length);
|
||||
}
|
||||
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
|
||||
} REST.set_header_content_type(response, REST.type.TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
|
||||
REST.set_header_etag(response, (uint8_t *)&length, 1);
|
||||
REST.set_response_payload(response, buffer, length);
|
||||
}
|
||||
|
22
examples/er-rest-example/resources/res-leds.c
Executable file → Normal file
22
examples/er-rest-example/resources/res-leds.c
Executable file → Normal file
@ -44,8 +44,17 @@
|
||||
#include "rest-engine.h"
|
||||
#include "dev/leds.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
@ -80,9 +89,7 @@ res_post_put_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
|
||||
}
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
|
||||
if(success && (len=REST.get_post_variable(request, "mode", &mode))) {
|
||||
} if(success && (len = REST.get_post_variable(request, "mode", &mode))) {
|
||||
PRINTF("mode %s\n", mode);
|
||||
|
||||
if(strncmp(mode, "on", len) == 0) {
|
||||
@ -94,11 +101,8 @@ res_post_put_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
|
||||
}
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
|
||||
if(!success) {
|
||||
} if(!success) {
|
||||
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PLATFORM_HAS_LEDS */
|
||||
|
1
examples/er-rest-example/resources/res-light.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-light.c
Executable file → Normal file
@ -84,5 +84,4 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PLATFORM_HAS_LIGHT */
|
||||
|
30
examples/er-rest-example/resources/res-mirror.c
Executable file → Normal file
30
examples/er-rest-example/resources/res-mirror.c
Executable file → Normal file
@ -40,8 +40,17 @@
|
||||
#include "rest-engine.h"
|
||||
#include "er-coap.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#define DEBUG 0
|
||||
#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
|
||||
|
||||
static void res_any_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
@ -85,18 +94,16 @@ res_any_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
}
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_header_accept(request, &content_format))) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ac %u\n", content_format);
|
||||
}
|
||||
|
||||
/* Some getters such as for ETag or Location are omitted, as these options should not appear in a request.
|
||||
* Max-Age might appear in HTTP requests or used for special purposes in CoAP. */
|
||||
}
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && REST.get_header_max_age(request, &longint)) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "MA %lu\n", longint);
|
||||
}
|
||||
/* For HTTP this is the Length option, for CoAP it is the Size option. */
|
||||
}
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && REST.get_header_length(request, &longint)) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "SZ %lu\n", longint);
|
||||
}
|
||||
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_header_host(request, &str))) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UH %.*s\n", len, str);
|
||||
}
|
||||
@ -105,17 +112,15 @@ res_any_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
}
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_query(request, &str))) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UQ %.*s\n", len, str);
|
||||
}
|
||||
|
||||
/* Undefined request options for debugging: actions not required for normal RESTful Web service. */
|
||||
}
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_path(request, &str))) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LP %.*s\n", len, str);
|
||||
}
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_query(request, &str))) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LQ %.*s\n", len, str);
|
||||
}
|
||||
|
||||
/* CoAP-specific example: actions not required for normal RESTful Web service. */
|
||||
}
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)request;
|
||||
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && coap_pkt->token_len > 0) {
|
||||
@ -144,17 +149,12 @@ res_any_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_block1(request, &block_num, &block_more, &block_size, NULL)) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "B1 %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
||||
}
|
||||
|
||||
|
||||
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_request_payload(request, &bytes))) {
|
||||
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%.*s", len, bytes);
|
||||
}
|
||||
|
||||
|
||||
if(strpos >= REST_MAX_CHUNK_SIZE) {
|
||||
buffer[REST_MAX_CHUNK_SIZE - 1] = 0xBB; /* '»' to indicate truncation */
|
||||
}
|
||||
|
||||
REST.set_response_payload(response, buffer, strpos);
|
||||
|
||||
PRINTF("/mirror options received: %s\n", buffer);
|
||||
|
1
examples/er-rest-example/resources/res-plugtest-create1.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-plugtest-create1.c
Executable file → Normal file
@ -70,7 +70,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
REST.set_response_status(response, REST.status.CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
0
examples/er-rest-example/resources/res-plugtest-create2.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-create2.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-plugtest-create3.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-plugtest-create3.c
Executable file → Normal file
@ -70,7 +70,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
REST.set_response_status(response, REST.status.CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
0
examples/er-rest-example/resources/res-plugtest-large-create.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-large-create.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-plugtest-large-update.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-plugtest-large-update.c
Executable file → Normal file
@ -81,7 +81,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
*offset = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
4
examples/er-rest-example/resources/res-plugtest-large.c
Executable file → Normal file
4
examples/er-rest-example/resources/res-plugtest-large.c
Executable file → Normal file
@ -74,13 +74,11 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
/* snprintf() does not adjust return value if truncated by size. */
|
||||
if(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);
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
|
||||
|
0
examples/er-rest-example/resources/res-plugtest-links.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-links.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-locquery.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-locquery.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-longpath.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-longpath.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-multi.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-multi.c
Executable file → Normal file
10
examples/er-rest-example/resources/res-plugtest-obs.c
Executable file → Normal file
10
examples/er-rest-example/resources/res-plugtest-obs.c
Executable file → Normal file
@ -69,7 +69,6 @@ obs_purge_list()
|
||||
PRINTF("### SERVER ACTION ### Purging obs list");
|
||||
coap_remove_observer_by_uri(NULL, 0, res_plugtest_obs.url);
|
||||
}
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -77,7 +76,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
if(request != NULL) {
|
||||
PRINTF("/obs GET\n");
|
||||
}
|
||||
|
||||
REST.set_header_content_type(response, obs_format);
|
||||
REST.set_header_max_age(response, 5);
|
||||
|
||||
@ -91,7 +89,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
}
|
||||
/* A post_handler that handles subscriptions will be called for periodic resources by the REST framework. */
|
||||
}
|
||||
|
||||
static void
|
||||
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -114,7 +111,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
|
||||
REST.set_response_status(response, REST.status.CHANGED);
|
||||
}
|
||||
|
||||
static void
|
||||
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -124,7 +120,6 @@ res_delete_handler(void* request, void* response, uint8_t *buffer, uint16_t pref
|
||||
|
||||
REST.set_response_status(response, REST.status.DELETED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE.
|
||||
* It will be called by the REST manager process with the defined period.
|
||||
@ -134,7 +129,7 @@ res_periodic_handler()
|
||||
{
|
||||
++obs_counter;
|
||||
|
||||
//PRINTF("TICK %u for /%s\n", obs_counter, r->url);
|
||||
/* PRINTF("TICK %u for /%s\n", obs_counter, r->url); */
|
||||
|
||||
if(obs_status == 1) {
|
||||
|
||||
@ -156,6 +151,5 @@ res_periodic_handler()
|
||||
} else {
|
||||
/* Notify the registered observers with the given message type, observe option, and payload. */
|
||||
REST.notify_subscribers(&res_plugtest_obs);
|
||||
}
|
||||
obs_status = 0;
|
||||
} obs_status = 0;
|
||||
}
|
||||
|
0
examples/er-rest-example/resources/res-plugtest-path.c
Executable file → Normal file
0
examples/er-rest-example/resources/res-plugtest-path.c
Executable file → Normal file
5
examples/er-rest-example/resources/res-plugtest-query.c
Executable file → Normal file
5
examples/er-rest-example/resources/res-plugtest-query.c
Executable file → Normal file
@ -62,9 +62,8 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
|
||||
if((len = REST.get_query(request, &query))) {
|
||||
PRINTF("Query: %.*s\n", len, query);
|
||||
}
|
||||
|
||||
/* Code 2.05 CONTENT is default. */REST.set_header_content_type(response,
|
||||
} /* Code 2.05 CONTENT is default. */
|
||||
REST.set_header_content_type(response,
|
||||
REST.type.TEXT_PLAIN);
|
||||
REST.set_response_payload(
|
||||
response,
|
||||
|
4
examples/er-rest-example/resources/res-plugtest-separate.c
Executable file → Normal file
4
examples/er-rest-example/resources/res-plugtest-separate.c
Executable file → Normal file
@ -56,8 +56,7 @@ PERIODIC_RESOURCE(res_plugtest_separate,
|
||||
res_resume_handler);
|
||||
|
||||
/* A structure to store the required information */
|
||||
typedef struct application_separate_store
|
||||
{
|
||||
typedef struct application_separate_store {
|
||||
/* Provided by Erbium to store generic request information such as remote address and token. */
|
||||
coap_separate_t request_metadata;
|
||||
/* Add fields for addition information to be stored for finalizing, e.g.: */
|
||||
@ -91,7 +90,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
|
||||
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
|
||||
}
|
||||
|
||||
static void
|
||||
res_resume_handler()
|
||||
{
|
||||
|
5
examples/er-rest-example/resources/res-plugtest-test.c
Executable file → Normal file
5
examples/er-rest-example/resources/res-plugtest-test.c
Executable file → Normal file
@ -68,7 +68,6 @@ test_update_etag()
|
||||
|
||||
PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]);
|
||||
}
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -77,7 +76,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
if(test_change) {
|
||||
test_update_etag();
|
||||
}
|
||||
|
||||
PRINTF("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
|
||||
|
||||
if((len = coap_get_header_etag(request, &bytes)) > 0
|
||||
@ -100,7 +98,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_post_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -110,7 +107,6 @@ res_post_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
|
||||
REST.set_response_status(response, REST.status.CREATED);
|
||||
REST.set_header_location(response, "/location1/location2/location3");
|
||||
}
|
||||
|
||||
static void
|
||||
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -153,7 +149,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
REST.set_response_status(response, PRECONDITION_FAILED_4_12);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
4
examples/er-rest-example/resources/res-plugtest-validate.c
Executable file → Normal file
4
examples/er-rest-example/resources/res-plugtest-validate.c
Executable file → Normal file
@ -55,7 +55,6 @@ static uint8_t validate_etag[8] = { 0 };
|
||||
static uint8_t validate_etag_len = 1;
|
||||
static uint8_t validate_change = 1;
|
||||
|
||||
|
||||
static const uint8_t *bytes = NULL;
|
||||
static size_t len = 0;
|
||||
|
||||
@ -72,7 +71,6 @@ validate_update_etag()
|
||||
PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
|
||||
validate_etag_len, validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]);
|
||||
}
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
@ -81,7 +79,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
if(validate_change) {
|
||||
validate_update_etag();
|
||||
}
|
||||
|
||||
PRINTF("/validate GET");
|
||||
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
|
||||
|
||||
@ -106,7 +103,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
coap_req->mid));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
1
examples/er-rest-example/resources/res-push.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-push.c
Executable file → Normal file
@ -71,7 +71,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
|
||||
/* The REST.subscription_handler() will be called for observable resources by the REST framework. */
|
||||
}
|
||||
|
||||
/*
|
||||
* Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE.
|
||||
* It will be called by the REST manager process with the defined period.
|
||||
|
6
examples/er-rest-example/resources/res-radio.c
Executable file → Normal file
6
examples/er-rest-example/resources/res-radio.c
Executable file → Normal file
@ -75,9 +75,7 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
}
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
|
||||
if(success) {
|
||||
} if(success) {
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", radio_sensor.value(param));
|
||||
@ -91,7 +89,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
} else if(param == RADIO_SENSOR_LAST_PACKET) {
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d}", radio_sensor.value(param));
|
||||
}
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
@ -102,5 +99,4 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PLATFORM_HAS_RADIO */
|
||||
|
4
examples/er-rest-example/resources/res-separate.c
Executable file → Normal file
4
examples/er-rest-example/resources/res-separate.c
Executable file → Normal file
@ -60,7 +60,6 @@ typedef struct application_separate_store {
|
||||
|
||||
/* Add fields for addition information to be stored for finalizing, e.g.: */
|
||||
char buffer[16];
|
||||
|
||||
} application_separate_store_t;
|
||||
|
||||
#define COAP_MAX_OPEN_SEPARATE 2
|
||||
@ -92,7 +91,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
snprintf(separate_store->buffer, sizeof(separate_store->buffer), "StoredInfo");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
res_resume_handler()
|
||||
{
|
||||
@ -117,7 +115,7 @@ res_resume_handler()
|
||||
coap_send_transaction(transaction);
|
||||
/* The engine will clear the transaction (right after send for NON, after acked for CON). */
|
||||
|
||||
//FIXME there could me more!
|
||||
/* FIXME there could me more! */
|
||||
separate_active = 0;
|
||||
} else {
|
||||
/*
|
||||
|
4
examples/er-rest-example/resources/res-sub.c
Executable file → Normal file
4
examples/er-rest-example/resources/res-sub.c
Executable file → Normal file
@ -65,7 +65,5 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "Request any sub-resource of /%s", res_sub.url);
|
||||
} else {
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, ".%.*s", len - base_len, uri_path + base_len);
|
||||
}
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
}
|
||||
|
1
examples/er-rest-example/resources/res-toggle.c
Executable file → Normal file
1
examples/er-rest-example/resources/res-toggle.c
Executable file → Normal file
@ -60,5 +60,4 @@ res_post_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
|
||||
{
|
||||
leds_invert(LEDS_RED);
|
||||
}
|
||||
|
||||
#endif /* PLATFORM_HAS_LEDS */
|
||||
|
Loading…
x
Reference in New Issue
Block a user