Skip to content

Commit

Permalink
Updated to CoAP draft 13.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Kovatsch committed Mar 31, 2013
1 parent 1a41527 commit 3da616c
Show file tree
Hide file tree
Showing 26 changed files with 195 additions and 190 deletions.
2 changes: 2 additions & 0 deletions apps/er-coap-03/er-coap-03-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ const struct rest_implementation coap_rest_implementation = {
coap_get_header_content_type,
coap_set_header_content_type,
NULL,
NULL,
NULL,
coap_get_header_max_age,
coap_set_header_max_age,
coap_set_header_etag,
Expand Down
42 changes: 25 additions & 17 deletions apps/er-coap-03/er-coap-03-observing.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,39 +122,47 @@ coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token,
}
/*-----------------------------------------------------------------------------------*/
void
coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len)
coap_notify_observers(resource_t *resource, int32_t obs_counter, void *notification)
{
coap_packet_t *const coap_res = (coap_packet_t *) notification;
coap_observer_t* obs = NULL;
uint8_t preferred_type = coap_res->type;

PRINTF("Observing: Notification from %s\n", resource->url);

/* Iterate over observers. */
for (obs = (coap_observer_t*)list_head(observers_list); obs; obs = obs->next)
{
if (obs->url==url) /* using RESOURCE url string as handle */
if (obs->url==resource->url) /* using RESOURCE url pointer as handle */
{
coap_transaction_t *transaction = NULL;

/*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */
/*TODO implement special transaction for CON, sharing the same buffer to allow for more observers. */

if ( (transaction = coap_new_transaction(coap_get_tid(), &obs->addr, obs->port)) )
{
PRINTF(" Observer ");
PRINT6ADDR(&obs->addr);
PRINTF(":%u\n", obs->port);

/* Prepare response */
coap_res->tid = transaction->tid;
coap_set_header_observe(coap_res, obs_counter);
coap_set_header_token(coap_res, obs->token, obs->token_len);

/* Use CON to check whether client is still there/interested after COAP_OBSERVING_REFRESH_INTERVAL. */
if (stimer_expired(&obs->refresh_timer))
{
PRINTF("Observing: Refresh client with CON\n");
type = COAP_TYPE_CON;
PRINTF(" Refreshing with CON\n");
coap_res->type = COAP_TYPE_CON;
stimer_restart(&obs->refresh_timer);
}
else
{
coap_res->type = preferred_type;
}

/* prepare response */
coap_packet_t push[1]; /* This way the packet can be treated as pointer as usual. */
coap_init_message(push, (coap_message_type_t)type, OK_200, transaction->tid );
coap_set_header_observe(push, observe);
coap_set_header_token(push, obs->token, obs->token_len);
coap_set_payload(push, payload, payload_len);
transaction->packet_len = coap_serialize_message(push, transaction->packet);

PRINTF("Observing: Notify from /%s for ", url);
PRINT6ADDR(&obs->addr);
PRINTF(":%u\n", obs->port);
PRINTF(" %.*s\n", payload_len, payload);
transaction->packet_len = coap_serialize_message(coap_res, transaction->packet);

coap_send_transaction(transaction);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-03/er-coap-03-observing.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ coap_observer_t *coap_add_observer(uip_ipaddr_t *addr, uint16_t port, const uint
void coap_remove_observer(coap_observer_t *o);
int coap_remove_observer_by_client(uip_ipaddr_t *addr, uint16_t port);
int coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token, size_t token_len);
void coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len);
void coap_notify_observers(resource_t *resource, int32_t obs_counter, void *notification);

void coap_observe_handler(resource_t *resource, void *request, void *response);

Expand Down
2 changes: 2 additions & 0 deletions apps/er-coap-07/er-coap-07-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ const struct rest_implementation coap_rest_implementation = {
coap_get_header_content_type,
coap_set_header_content_type,
coap_get_header_accept,
NULL,
NULL,
coap_get_header_max_age,
coap_set_header_max_age,
coap_set_header_etag,
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-07/er-coap-07-observing.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid)
}
/*-----------------------------------------------------------------------------------*/
void
coap_notify_observers(resource_t *resource, uint16_t obs_counter, void *notification)
coap_notify_observers(resource_t *resource, int32_t obs_counter, void *notification)
{
coap_packet_t *const coap_res = (coap_packet_t *) notification;
coap_observer_t* obs = NULL;
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-07/er-coap-07-observing.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *to
int coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url);
int coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid);

void coap_notify_observers(resource_t *resource, uint16_t obs_counter, void *notification);
void coap_notify_observers(resource_t *resource, int32_t obs_counter, void *notification);

void coap_observe_handler(resource_t *resource, void *request, void *response);

Expand Down
6 changes: 3 additions & 3 deletions apps/er-coap-13/er-coap-13-engine.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -102,7 +102,7 @@ coap_receive(void)

/*TODO duplicates suppression, if required by application */

PRINTF(" Parsed: v %u, t %u, oc %u, c %u, mid %u\n", message->version, message->type, message->option_count, message->code, message->mid);
PRINTF(" Parsed: v %u, t %u, tkl %u, c %u, mid %u\n", message->version, message->type, message->token_len, message->code, message->mid);
PRINTF(" URL: %.*s\n", message->uri_path_len, message->uri_path);
PRINTF(" Payload: %.*s\n", message->payload_len, message->payload);

Expand Down Expand Up @@ -384,7 +384,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
}
#endif

PRINTF("res: /%s (%p)\npos: s%d, o%d, b%d\n", resource->url, resource, strpos, *offset, bufpos);
PRINTF("res: /%s (%p)\npos: s%d, o%ld, b%d\n", resource->url, resource, strpos, *offset, bufpos);

if (strpos>0)
{
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-13/er-coap-13-engine.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-13/er-coap-13-observing.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
3 changes: 2 additions & 1 deletion apps/er-coap-13/er-coap-13-observing.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_

#include "sys/stimer.h"
#include "er-coap-13.h"
#include "er-coap-13-transactions.h"

Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-13/er-coap-13-separate.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-13/er-coap-13-separate.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-13/er-coap-13-transactions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion apps/er-coap-13/er-coap-13-transactions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
Loading

0 comments on commit 3da616c

Please sign in to comment.