Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki
This commit is contained in:
commit
26ee7cb5db
48 changed files with 297 additions and 763 deletions
|
@ -67,13 +67,13 @@
|
|||
|
||||
PROCESS(coap_receiver, "CoAP Receiver");
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*- Variables -----------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*- Variables ----------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static service_callback_t service_cbk = NULL;
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static
|
||||
int
|
||||
handle_incoming_data(void)
|
||||
|
@ -279,27 +279,27 @@ handle_incoming_data(void)
|
|||
|
||||
return coap_error_code;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
coap_receiver_init()
|
||||
{
|
||||
process_start(&coap_receiver, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
coap_set_service_callback(service_callback_t callback)
|
||||
{
|
||||
service_cbk = callback;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
rest_resource_flags_t
|
||||
coap_get_rest_method(void *packet)
|
||||
{
|
||||
return (rest_resource_flags_t)(1 << (((coap_packet_t *)packet)->code - 1));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*- Server part ---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*- Server part --------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/* The discover resource is automatically included for CoAP. */
|
||||
RESOURCE(well_known_core, METHOD_GET, ".well-known/core", "ct=40");
|
||||
|
@ -311,8 +311,19 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
|||
size_t tmplen = 0;
|
||||
resource_t* resource = NULL;
|
||||
|
||||
/* For filtering. */
|
||||
const char *filter = NULL;
|
||||
int len = coap_get_query_variable(request, "rt", &filter);
|
||||
char *rt = NULL;
|
||||
|
||||
for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next)
|
||||
{
|
||||
/* Filtering */
|
||||
if (len && ((rt=strstr(resource->attributes, "rt=\""))==NULL || memcmp(rt+4, filter, len-1)!=0 || (filter[len-1]!='*' && (filter[len-1]!=rt[3+len] || rt[4+len]!='"'))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
PRINTF("res: /%s (%p)\npos: s%d, o%d, b%d\n", resource->url, resource, strpos, *offset, bufpos);
|
||||
|
||||
if (strpos >= *offset && bufpos < preferred_size)
|
||||
|
@ -390,7 +401,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
|||
coap_set_payload(response, buffer, bufpos );
|
||||
coap_set_header_content_type(response, APPLICATION_LINK_FORMAT);
|
||||
}
|
||||
else
|
||||
else if (strpos>0)
|
||||
{
|
||||
PRINTF("well_known_core_handler(): bufpos<=0\n");
|
||||
|
||||
|
@ -408,7 +419,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
|||
*offset += preferred_size;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(coap_receiver, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
@ -433,15 +444,15 @@ PROCESS_THREAD(coap_receiver, ev, data)
|
|||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*- Client part ---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*- Client part --------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void blocking_request_callback(void *callback_data, void *response) {
|
||||
struct request_state_t *state = (struct request_state_t *) callback_data;
|
||||
state->response = (coap_packet_t*) response;
|
||||
process_poll(state->process);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
PT_THREAD(coap_blocking_request(struct request_state_t *state, process_event_t ev,
|
||||
uip_ipaddr_t *remote_ipaddr, uint16_t remote_port,
|
||||
coap_packet_t *request,
|
||||
|
@ -509,9 +520,9 @@ PT_THREAD(coap_blocking_request(struct request_state_t *state, process_event_t e
|
|||
|
||||
PT_END(&state->pt);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*- Engine Interface ----------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*- Engine Interface ---------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
const struct rest_implementation coap_rest_implementation = {
|
||||
"CoAP-07",
|
||||
|
||||
|
|
|
@ -60,6 +60,9 @@ LIST(observers_list);
|
|||
coap_observer_t *
|
||||
coap_add_observer(uip_ipaddr_t *addr, uint16_t port, const uint8_t *token, size_t token_len, const char *url)
|
||||
{
|
||||
/* Remove existing observe relationship, if any. */
|
||||
coap_remove_observer_by_url(addr, port, url);
|
||||
|
||||
coap_observer_t *o = memb_alloc(&observers_memb);
|
||||
|
||||
if (o)
|
||||
|
@ -164,43 +167,51 @@ coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid)
|
|||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
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, uint16_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 pointer 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_mid(), &obs->addr, obs->port)) )
|
||||
{
|
||||
/* 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;
|
||||
stimer_restart(&obs->refresh_timer);
|
||||
}
|
||||
|
||||
/* 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, CONTENT_2_05, transaction->mid );
|
||||
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);
|
||||
PRINTF(" Observer ");
|
||||
PRINT6ADDR(&obs->addr);
|
||||
PRINTF(":%u\n", obs->port);
|
||||
PRINTF(" %.*s\n", payload_len, payload);
|
||||
|
||||
/* Update last MID for RST matching. */
|
||||
obs->last_mid = transaction->mid;
|
||||
|
||||
/* Prepare response */
|
||||
coap_res->mid = transaction->mid;
|
||||
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(" Refreshing with CON\n");
|
||||
coap_res->type = COAP_TYPE_CON;
|
||||
stimer_restart(&obs->refresh_timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
coap_res->type = preferred_type;
|
||||
}
|
||||
|
||||
transaction->packet_len = coap_serialize_message(coap_res, transaction->packet);
|
||||
|
||||
coap_send_transaction(transaction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len);
|
||||
void coap_notify_observers(resource_t *resource, uint16_t obs_counter, void *notification);
|
||||
|
||||
void coap_observe_handler(resource_t *resource, void *request, void *response);
|
||||
|
||||
|
|
|
@ -53,41 +53,40 @@
|
|||
#define PRINTLLADDR(addr)
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int coap_separate_handler(resource_t *resource, void *request, void *response)
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
coap_separate_reject()
|
||||
{
|
||||
coap_packet_t *const coap_req = (coap_packet_t *) request;
|
||||
|
||||
PRINTF("Separate response for /%s MID %u\n", resource->url, coap_res->mid);
|
||||
|
||||
/* Only ack CON requests. */
|
||||
if (coap_req->type==COAP_TYPE_CON)
|
||||
{
|
||||
/* send separate ACK. */
|
||||
coap_packet_t ack[1];
|
||||
/* ACK with empty code (0) */
|
||||
coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);
|
||||
/* Serializing into IPBUF: Only overwrites header parts that are already parsed into the request struct. */
|
||||
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, (uip_appdata), coap_serialize_message(ack, uip_appdata));
|
||||
}
|
||||
|
||||
/* Pre-handlers could skip the handling by returning 0. */
|
||||
return 1;
|
||||
coap_error_code = SERVICE_UNAVAILABLE_5_03;
|
||||
coap_error_message = "AlreadyInUse";
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int
|
||||
coap_separate_yield(void *request, coap_separate_t *separate_store)
|
||||
coap_separate_accept(void *request, coap_separate_t *separate_store)
|
||||
{
|
||||
coap_packet_t *const coap_req = (coap_packet_t *) request;
|
||||
coap_transaction_t *const t = coap_get_transaction_by_mid(coap_req->mid);
|
||||
|
||||
PRINTF("Separate ACCEPT: /%.*s MID %u\n", coap_req->uri_path_len, coap_req->uri_path, coap_req->mid);
|
||||
if (t)
|
||||
{
|
||||
/* Send separate ACK for CON. */
|
||||
if (coap_req->type==COAP_TYPE_CON)
|
||||
{
|
||||
coap_packet_t ack[1];
|
||||
/* ACK with empty code (0) */
|
||||
coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);
|
||||
/* Serializing into IPBUF: Only overwrites header parts that are already parsed into the request struct. */
|
||||
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, (uip_appdata), coap_serialize_message(ack, uip_appdata));
|
||||
}
|
||||
|
||||
/* Store remote address. */
|
||||
uip_ipaddr_copy(&separate_store->addr, &t->addr);
|
||||
separate_store->port = t->port;
|
||||
|
||||
/* Store correct response type. */
|
||||
separate_store->type = coap_req->type==COAP_TYPE_CON ? COAP_TYPE_CON : COAP_TYPE_NON;
|
||||
separate_store->mid = coap_get_mid(); // if it was NON, we burned one MID in the engine...
|
||||
separate_store->mid = coap_get_mid(); /* if it was a NON, we burned one MID in the engine... */
|
||||
|
||||
memcpy(separate_store->token, coap_req->token, coap_req->token_len);
|
||||
separate_store->token_len = coap_req->token_len;
|
||||
|
@ -102,13 +101,17 @@ coap_separate_yield(void *request, coap_separate_t *separate_store)
|
|||
}
|
||||
else
|
||||
{
|
||||
PRINTF("ERROR: Response transaction for separate request not found!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
coap_separate_resume(void *response, coap_separate_t *separate_store, uint8_t code)
|
||||
{
|
||||
coap_init_message(response, separate_store->type, code, separate_store->mid);
|
||||
coap_set_header_token(response, separate_store->token, separate_store->token_len);
|
||||
if (separate_store->token_len)
|
||||
{
|
||||
coap_set_header_token(response, separate_store->token, separate_store->token_len);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ typedef struct coap_separate {
|
|||
} coap_separate_t;
|
||||
|
||||
int coap_separate_handler(resource_t *resource, void *request, void *response);
|
||||
int coap_separate_yield(void *request, coap_separate_t *separate_store);
|
||||
void coap_separate_reject();
|
||||
int coap_separate_accept(void *request, coap_separate_t *separate_store);
|
||||
void coap_separate_resume(void *response, coap_separate_t *separate_store, uint8_t code);
|
||||
|
||||
#endif /* COAP_SEPARATE_H_ */
|
||||
|
|
|
@ -105,6 +105,7 @@ coap_send_transaction(coap_transaction_t *t)
|
|||
{
|
||||
if (t->retrans_counter<COAP_MAX_RETRANSMIT)
|
||||
{
|
||||
/* Not timed out yet. */
|
||||
PRINTF("Keeping transaction %u\n", t->mid);
|
||||
|
||||
if (t->retrans_counter==0)
|
||||
|
@ -118,7 +119,10 @@ coap_send_transaction(coap_transaction_t *t)
|
|||
PRINTF("Doubled (%u) interval %f\n", t->retrans_counter, (float)t->retrans_timer.timer.interval/CLOCK_SECOND);
|
||||
}
|
||||
|
||||
/*FIXME hack, maybe there is a better way, but avoid posting everything to the process */
|
||||
/*FIXME
|
||||
* Hack: Setting timer for responsible process.
|
||||
* Maybe there is a better way, but avoid posting everything to the process.
|
||||
*/
|
||||
struct process *process_actual = PROCESS_CURRENT();
|
||||
process_current = transaction_handler_process;
|
||||
etimer_restart(&t->retrans_timer); /* interval updated above */
|
||||
|
@ -128,7 +132,7 @@ coap_send_transaction(coap_transaction_t *t)
|
|||
}
|
||||
else
|
||||
{
|
||||
/* timeout */
|
||||
/* Timed out. */
|
||||
PRINTF("Timeout\n");
|
||||
restful_response_handler callback = t->callback;
|
||||
void *callback_data = t->callback_data;
|
||||
|
|
|
@ -75,7 +75,7 @@ struct periodic_resource_s;
|
|||
typedef void (*restful_handler) (void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
typedef int (*restful_pre_handler) (struct resource_s *resource, void* request, void* response);
|
||||
typedef void (*restful_post_handler) (struct resource_s *resource, void* request, void* response);
|
||||
typedef int (*restful_periodic_handler) (struct resource_s* resource);
|
||||
typedef void (*restful_periodic_handler) (struct resource_s* resource);
|
||||
typedef void (*restful_response_handler) (void *data, void* response);
|
||||
|
||||
/* Signature of the rest-engine service function. */
|
||||
|
@ -134,6 +134,31 @@ struct rest_implementation_type
|
|||
unsigned int APPLICATION_X_OBIX_BINARY;
|
||||
};
|
||||
|
||||
/*
|
||||
* Data structure representing a resource in REST.
|
||||
*/
|
||||
struct resource_s {
|
||||
struct resource_s *next; /* for LIST, points to next resource defined */
|
||||
rest_resource_flags_t flags; /* handled RESTful methods */
|
||||
const char* url; /*handled URL*/
|
||||
const char* attributes; /* link-format attributes */
|
||||
restful_handler handler; /* handler function */
|
||||
restful_pre_handler pre_handler; /* to be called before handler, may perform initializations */
|
||||
restful_post_handler post_handler; /* to be called after handler, may perform finalizations (cleanup, etc) */
|
||||
void* user_data; /* pointer to user specific data */
|
||||
unsigned int benchmark; /* to benchmark resource handler, used for separate response */
|
||||
};
|
||||
typedef struct resource_s resource_t;
|
||||
|
||||
struct periodic_resource_s {
|
||||
struct periodic_resource_s *next; /* for LIST, points to next resource defined */
|
||||
resource_t *resource;
|
||||
uint32_t period;
|
||||
struct etimer periodic_timer;
|
||||
restful_periodic_handler periodic_handler;
|
||||
};
|
||||
typedef struct periodic_resource_s periodic_resource_t;
|
||||
|
||||
struct rest_implementation {
|
||||
char *name;
|
||||
|
||||
|
@ -199,7 +224,7 @@ struct rest_implementation {
|
|||
int (* get_post_variable)(void *request, const char *name, const char **value);
|
||||
|
||||
/** Send the payload to all subscribers of the resource at url. */
|
||||
void (* notify_subscribers)(const char *url, int implementation_secific_mode, uint32_t counter, uint8_t *payload, size_t payload_len);
|
||||
void (* notify_subscribers)(resource_t *resource, uint16_t counter, void *notification);
|
||||
|
||||
/** The handler for resource subscriptions. */
|
||||
restful_post_handler subscription_handler;
|
||||
|
@ -222,32 +247,6 @@ struct rest_implementation {
|
|||
*/
|
||||
extern const struct rest_implementation REST;
|
||||
|
||||
/*
|
||||
* Data structure representing a resource in REST.
|
||||
*/
|
||||
struct resource_s {
|
||||
struct resource_s *next; /* for LIST, points to next resource defined */
|
||||
rest_resource_flags_t flags; /* handled RESTful methods */
|
||||
const char* url; /*handled URL*/
|
||||
const char* attributes; /* link-format attributes */
|
||||
restful_handler handler; /* handler function */
|
||||
restful_pre_handler pre_handler; /* to be called before handler, may perform initializations */
|
||||
restful_post_handler post_handler; /* to be called after handler, may perform finalizations (cleanup, etc) */
|
||||
void* user_data; /* pointer to user specific data */
|
||||
unsigned int benchmark; /* to benchmark resource handler, used for separate response */
|
||||
};
|
||||
typedef struct resource_s resource_t;
|
||||
|
||||
struct periodic_resource_s {
|
||||
struct periodic_resource_s *next; /* for LIST, points to next resource defined */
|
||||
resource_t *resource;
|
||||
uint32_t period;
|
||||
struct etimer periodic_timer;
|
||||
restful_periodic_handler periodic_handler;
|
||||
};
|
||||
typedef struct periodic_resource_s periodic_resource_t;
|
||||
|
||||
|
||||
/*
|
||||
* Macro to define a Resource
|
||||
* Resources are statically defined for the sake of efficiency and better memory management.
|
||||
|
@ -260,7 +259,7 @@ resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL
|
|||
* Macro to define a sub-resource
|
||||
* Make sure to define its parent resource beforehand and set 'parent' to that name.
|
||||
*/
|
||||
#define SUB_RESOURCE(name, flags, url, attributes, parent) \
|
||||
#define SUB_RESOURCE(name, flags, url, attributes, parent) \
|
||||
resource_t resource_##name = {NULL, flags, url, attributes, parent##_handler, NULL, NULL, NULL}
|
||||
|
||||
/*
|
||||
|
@ -270,8 +269,8 @@ resource_t resource_##name = {NULL, flags, url, attributes, parent##_handler, NU
|
|||
*/
|
||||
#define EVENT_RESOURCE(name, flags, url, attributes) \
|
||||
void name##_handler(void *, void *, uint8_t *, uint16_t, int32_t *); \
|
||||
resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL}; \
|
||||
int name##_event_handler(resource_t*)
|
||||
void name##_event_handler(resource_t*); \
|
||||
resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL}
|
||||
|
||||
/*
|
||||
* Macro to define a periodic resource
|
||||
|
@ -282,7 +281,7 @@ int name##_event_handler(resource_t*)
|
|||
#define PERIODIC_RESOURCE(name, flags, url, attributes, period) \
|
||||
void name##_handler(void *, void *, uint8_t *, uint16_t, int32_t *); \
|
||||
resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL}; \
|
||||
int name##_periodic_handler(resource_t*); \
|
||||
void name##_periodic_handler(resource_t*); \
|
||||
periodic_resource_t periodic_resource_##name = {NULL, &resource_##name, period, {{0}}, name##_periodic_handler}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct announcement_data {
|
||||
|
@ -131,32 +130,31 @@ static void
|
|||
adv_packet_received(struct broadcast_conn *ibc, const rimeaddr_t *from)
|
||||
{
|
||||
struct announcement_msg adata;
|
||||
struct announcement_data data;
|
||||
uint8_t *ptr;
|
||||
int i;
|
||||
|
||||
ptr = packetbuf_dataptr();
|
||||
|
||||
/* Copy number of announcements */
|
||||
memcpy(&adata, packetbuf_dataptr(), sizeof(struct announcement_msg));
|
||||
memcpy(&adata, ptr, sizeof(struct announcement_msg));
|
||||
PRINTF("%d.%d: adv_packet_received from %d.%d with %d announcements\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
from->u8[0], from->u8[1], adata.num);
|
||||
|
||||
if(adata.num / sizeof(struct announcement_data) > sizeof(struct announcement_msg)) {
|
||||
if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num * sizeof(struct announcement_data) > packetbuf_datalen()) {
|
||||
/* The number of announcements is too large - corrupt packet has
|
||||
been received. */
|
||||
printf("adata.num way out there: %d\n", adata.num);
|
||||
PRINTF("adata.num way out there: %d\n", adata.num);
|
||||
return;
|
||||
}
|
||||
|
||||
for(i = 0; i < adata.num; ++i) {
|
||||
struct announcement_data data;
|
||||
|
||||
ptr += ANNOUNCEMENT_MSG_HEADERLEN;
|
||||
for(i = 0; i < adata.num; ++i) {
|
||||
/* Copy announcements */
|
||||
memcpy(&data.id, &((struct announcement_msg *)packetbuf_dataptr())->data[i].id,
|
||||
sizeof(uint16_t));
|
||||
memcpy(&data.value, &((struct announcement_msg *)packetbuf_dataptr())->data[i].value,
|
||||
sizeof(uint16_t));
|
||||
announcement_heard(from,
|
||||
data.id,
|
||||
data.value);
|
||||
memcpy(&data, ptr, sizeof(struct announcement_data));
|
||||
announcement_heard(from, data.id, data.value);
|
||||
ptr += sizeof(struct announcement_data);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -758,8 +758,7 @@ send_next_packet(struct collect_conn *tc)
|
|||
static void
|
||||
handle_ack(struct collect_conn *tc)
|
||||
{
|
||||
struct ack_msg *msg;
|
||||
uint16_t rtmetric;
|
||||
struct ack_msg msg;
|
||||
struct collect_neighbor *n;
|
||||
|
||||
PRINTF("handle_ack: sender %d.%d current_parent %d.%d, id %d seqno %d\n",
|
||||
|
@ -778,8 +777,7 @@ handle_ack(struct collect_conn *tc)
|
|||
(int)(((100 * (clock_time() - tc->send_time)) / CLOCK_SECOND) % 100));*/
|
||||
|
||||
stats.ackrecv++;
|
||||
msg = packetbuf_dataptr();
|
||||
memcpy(&rtmetric, &msg->rtmetric, sizeof(uint16_t));
|
||||
memcpy(&msg, packetbuf_dataptr(), sizeof(struct ack_msg));
|
||||
|
||||
/* It is possible that we receive an ACK for a packet that we
|
||||
think we have not yet sent: if our transmission was received by
|
||||
|
@ -797,7 +795,7 @@ handle_ack(struct collect_conn *tc)
|
|||
|
||||
if(n != NULL) {
|
||||
collect_neighbor_tx(n, tc->transmissions);
|
||||
collect_neighbor_update_rtmetric(n, rtmetric);
|
||||
collect_neighbor_update_rtmetric(n, msg.rtmetric);
|
||||
update_rtmetric(tc);
|
||||
}
|
||||
|
||||
|
@ -805,8 +803,8 @@ handle_ack(struct collect_conn *tc)
|
|||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
tc->current_parent.u8[0], tc->current_parent.u8[1],
|
||||
tc->transmissions,
|
||||
msg->flags,
|
||||
rtmetric);
|
||||
msg.flags,
|
||||
msg.rtmetric);
|
||||
|
||||
/* The ack contains information about the state of the packet and
|
||||
of the node that received it. We do different things depending
|
||||
|
@ -814,20 +812,20 @@ handle_ack(struct collect_conn *tc)
|
|||
the receiving node was congested. If so, we add a maximum
|
||||
transmission number to its routing metric, which increases the
|
||||
chance that another parent will be chosen. */
|
||||
if(msg->flags & ACK_FLAGS_CONGESTED) {
|
||||
if(msg.flags & ACK_FLAGS_CONGESTED) {
|
||||
PRINTF("ACK flag indicated parent was congested.\n");
|
||||
collect_neighbor_set_congested(n);
|
||||
collect_neighbor_tx(n, tc->max_rexmits * 2);
|
||||
update_rtmetric(tc);
|
||||
}
|
||||
if((msg->flags & ACK_FLAGS_DROPPED) == 0) {
|
||||
if((msg.flags & ACK_FLAGS_DROPPED) == 0) {
|
||||
/* If the packet was successfully received, we send the next packet. */
|
||||
send_next_packet(tc);
|
||||
} else {
|
||||
/* If the packet was lost due to its lifetime being exceeded,
|
||||
there is not much more we can do with the packet, so we send
|
||||
the next one instead. */
|
||||
if((msg->flags & ACK_FLAGS_LIFETIME_EXCEEDED)) {
|
||||
if((msg.flags & ACK_FLAGS_LIFETIME_EXCEEDED)) {
|
||||
send_next_packet(tc);
|
||||
} else {
|
||||
/* If the packet was dropped, but without the node being
|
||||
|
@ -845,7 +843,7 @@ handle_ack(struct collect_conn *tc)
|
|||
|
||||
/* Our neighbor's rtmetric needs to be updated, so we bump our
|
||||
advertisements. */
|
||||
if(msg->flags & ACK_FLAGS_RTMETRIC_NEEDS_UPDATE) {
|
||||
if(msg.flags & ACK_FLAGS_RTMETRIC_NEEDS_UPDATE) {
|
||||
bump_advertisement(tc);
|
||||
}
|
||||
set_keepalive_timer(tc);
|
||||
|
|
|
@ -96,23 +96,22 @@ static void
|
|||
adv_packet_received(struct broadcast_conn *ibc, const rimeaddr_t *from)
|
||||
{
|
||||
struct neighbor_discovery_conn *c = (struct neighbor_discovery_conn *)ibc;
|
||||
struct adv_msg *msg = packetbuf_dataptr();
|
||||
uint16_t val;
|
||||
struct adv_msg msg;
|
||||
|
||||
memcpy(&val, &msg->val, sizeof(val));
|
||||
memcpy(&msg, packetbuf_dataptr(), sizeof(struct adv_msg));
|
||||
|
||||
PRINTF("%d.%d: adv_packet_received from %d.%d with val %d\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
from->u8[0], from->u8[1], val);
|
||||
from->u8[0], from->u8[1], msg.val);
|
||||
|
||||
/* If we receive an announcement with a lower value than ours, we
|
||||
cancel our own announcement. */
|
||||
if(val < c->val) {
|
||||
if(msg.val < c->val) {
|
||||
/* ctimer_stop(&c->send_timer);*/
|
||||
}
|
||||
|
||||
if(c->u->recv) {
|
||||
c->u->recv(c, from, val);
|
||||
c->u->recv(c, from, msg.val);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -125,25 +125,31 @@ static void
|
|||
adv_packet_received(struct ipolite_conn *ipolite, const rimeaddr_t *from)
|
||||
{
|
||||
struct announcement_msg adata;
|
||||
struct announcement_data data;
|
||||
uint8_t *ptr;
|
||||
int i;
|
||||
|
||||
ptr = packetbuf_dataptr();
|
||||
|
||||
/* Copy number of announcements */
|
||||
memcpy(&adata, packetbuf_dataptr(), sizeof(struct announcement_msg));
|
||||
memcpy(&adata, ptr, sizeof(struct announcement_msg));
|
||||
PRINTF("%d.%d: adv_packet_received from %d.%d with %d announcements\n",
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||
from->u8[0], from->u8[1], adata.num);
|
||||
|
||||
for(i = 0; i < adata.num; ++i) {
|
||||
struct announcement_data data;
|
||||
if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num * sizeof(struct announcement_data) > packetbuf_datalen()) {
|
||||
/* The number of announcements is too large - corrupt packet has
|
||||
been received. */
|
||||
PRINTF("adata.num way out there: %d\n", adata.num);
|
||||
return;
|
||||
}
|
||||
|
||||
ptr += ANNOUNCEMENT_MSG_HEADERLEN;
|
||||
for(i = 0; i < adata.num; ++i) {
|
||||
/* Copy announcements */
|
||||
memcpy(&data.id, &((struct announcement_msg *)packetbuf_dataptr())->data[i].id,
|
||||
sizeof(uint16_t));
|
||||
memcpy(&data.value, &((struct announcement_msg *)packetbuf_dataptr())->data[i].value,
|
||||
sizeof(uint16_t));
|
||||
announcement_heard(from,
|
||||
data.id,
|
||||
data.value);
|
||||
memcpy(&data, ptr, sizeof(struct announcement_data));
|
||||
announcement_heard(from, data.id, data.value);
|
||||
ptr += sizeof(struct announcement_data);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -40,16 +40,13 @@
|
|||
#define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant
|
||||
|
||||
/* Generic types. */
|
||||
typedef unsigned char u8_t; /* 8 bit type */
|
||||
typedef unsigned short u16_t; /* 16 bit type */
|
||||
typedef unsigned long u32_t; /* 32 bit type */
|
||||
typedef signed long s32_t; /* 32 bit type */
|
||||
typedef unsigned short uip_stats_t;
|
||||
|
||||
|
||||
/* Time type. */
|
||||
typedef unsigned short clock_time_t;
|
||||
#define MAX_TICKS (~((clock_time_t)0) / 2)
|
||||
/* Defines tick counts for a second. */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
|
||||
/* Compiler configurations */
|
||||
#define CCIF
|
||||
|
@ -80,8 +77,8 @@ typedef unsigned short clock_time_t;
|
|||
__endasm; \
|
||||
}
|
||||
|
||||
/* Macro for a soft reset. In many respects better than H/W reboot via W/D */
|
||||
#define SOFT_RESET() {((void (__code *) (void)) 0x0000) ();}
|
||||
/* Macro for a soft reset. */
|
||||
#define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0)
|
||||
|
||||
/* We don't provide architecture-specific checksum calculations */
|
||||
#define UIP_ARCH_ADD32 0
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
EXE_MAKE=$(notdir $(shell which "make.exe" 2>/dev/null))
|
||||
ifeq "$(EXE_MAKE)" "make.exe"
|
||||
PLATFORM=windows
|
||||
else
|
||||
PLATFORM=linux
|
||||
endif
|
||||
|
||||
OBJECTS = ihex.o converter.o
|
||||
SUBDIRS =
|
||||
|
||||
CFLAGS = -Wall -D_REENTRANT -I.
|
||||
LDFLAGS = -L. -D_REENTRANT -lpthread
|
||||
ifeq "$(PLATFORM)" "linux"
|
||||
SUFFIX=
|
||||
else
|
||||
SUFFIX=.exe
|
||||
endif
|
||||
|
||||
TARGET = converter$(SUFFIX)
|
||||
|
||||
all: binary
|
||||
|
||||
binary: $(TARGET)
|
||||
strip $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
gcc -o $(TARGET) $(OBJECTS) $(LDFLAGS)
|
||||
|
||||
.c.o:
|
||||
gcc -c -o $(<:.c=.o) -O2 -Wall $(CFLAGS) $<
|
||||
|
||||
platform-test:
|
||||
@echo $(PLATFORM)
|
||||
|
||||
old-strip:
|
||||
if [ -x $(TARGET).exe ]; then $(PLATFORM)strip $(TARGET).exe; else $(PLATFORM)strip $(TARGET); fi
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
|
@ -1,227 +0,0 @@
|
|||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "converter.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int cdi_programmer(conf_opts_t *conf, char *filename);
|
||||
|
||||
void usage(char *prg_name)
|
||||
{
|
||||
printf("\nUsage: %s -f ihex file\n", prg_name);
|
||||
printf("General options:\n");
|
||||
printf(" -v/--version Get converter version\n");
|
||||
}
|
||||
|
||||
conf_opts_t conf_opts;
|
||||
|
||||
static int option_index = 0;
|
||||
|
||||
int do_exit = 0;
|
||||
|
||||
#define OPTIONS_STRING "vhf:"
|
||||
/* long option list */
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"version", 0, NULL, 'v'},
|
||||
{"file", 1, NULL, 'f'},
|
||||
{"help", 0, NULL, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int parse_opts(int count, char* param[])
|
||||
{
|
||||
int opt;
|
||||
int error=0;
|
||||
|
||||
conf_opts.target_type = UNDEFINED;
|
||||
while ((opt = getopt_long(count, param, OPTIONS_STRING,
|
||||
long_options, &option_index)) != -1)
|
||||
{
|
||||
switch(opt)
|
||||
{
|
||||
case 'v':
|
||||
conf_opts.target_type = VERSION;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
conf_opts.target_type = UNDEFINED;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
strcpy(conf_opts.ihex_file, optarg);
|
||||
conf_opts.target_type = CONVERT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error && (conf_opts.target_type == CONVERT) )
|
||||
{
|
||||
printf("File: %s.\n", conf_opts.ihex_file);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
conf_opts.target_type = 0;
|
||||
|
||||
|
||||
printf("Sensinode hex file converter "CONVERTER_VERSION "\n");
|
||||
if ( (argc < 1) || (error = parse_opts(argc, argv)) )
|
||||
{
|
||||
usage(argv[0]);
|
||||
if (error < 0) return error;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
if(conf_opts.target_type == CONVERT)
|
||||
{ /*Convert*/
|
||||
int pages;
|
||||
int sdcc_file = 0;
|
||||
|
||||
FILE *ihex = 0;
|
||||
unsigned char check = 0;
|
||||
unsigned long ext_addr=0;
|
||||
unsigned short int addr=0;
|
||||
unsigned char page_buffer[128*1024];
|
||||
unsigned char page_table[64];
|
||||
unsigned char buffer[256];
|
||||
int i;
|
||||
int retval = 0;
|
||||
|
||||
bzero(buffer, sizeof(buffer));
|
||||
|
||||
/*initialize page data*/
|
||||
memset(page_table, 0, 64);
|
||||
memset(page_buffer, 0xFF, sizeof(page_buffer));
|
||||
pages = 0;
|
||||
|
||||
ihex = fopen(conf_opts.ihex_file, "rb");
|
||||
if (ihex == 0)
|
||||
{
|
||||
printf("Can't open file.\n");
|
||||
return -1;
|
||||
}
|
||||
error = 0;
|
||||
while((!error) && ((retval = fscanf(ihex, "%s", buffer)) == 1) )
|
||||
{
|
||||
unsigned char data_len = 0;
|
||||
|
||||
if (memcmp(&buffer[7], "00", 2) == 0)
|
||||
{ /*Data record*/
|
||||
i=0;
|
||||
sscanf((char *)&buffer[1], "%2hhx", &data_len);
|
||||
sscanf((char *)&(buffer[3]),"%4hx", &addr);
|
||||
while(i<data_len)
|
||||
{
|
||||
uint32_t absolute_address = ext_addr+addr+i;
|
||||
|
||||
if (page_table[absolute_address/2048] == 0)
|
||||
{
|
||||
page_table[absolute_address/2048] = 1;
|
||||
pages++;
|
||||
}
|
||||
sscanf((char *)&buffer[2*i+9], "%2hhx", &page_buffer[absolute_address]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if (memcmp(&buffer[7], "01", 2) == 0)
|
||||
{ /*end file*/
|
||||
printf("File read complete.\n");
|
||||
break;
|
||||
}
|
||||
else if (memcmp(&buffer[7], "04", 2) == 0)
|
||||
{
|
||||
sscanf((char *)&(buffer[3]),"%4hx", &addr);
|
||||
sscanf((char *)&(buffer[9]),"%4lx", &ext_addr);
|
||||
/*printf("Extended page address: 0x%8.8lX\n", ext_addr*0x8000 );*/
|
||||
|
||||
if (ext_addr >= 0x0002) sdcc_file = 1;
|
||||
|
||||
if (ext_addr) ext_addr--;
|
||||
ext_addr *= 0x8000;
|
||||
}
|
||||
}
|
||||
fclose(ihex);
|
||||
if (retval == -1)
|
||||
{
|
||||
printf("Read error\n");
|
||||
}
|
||||
if (sdcc_file == 0)
|
||||
{
|
||||
printf("Not a SDCC banked file.\n");
|
||||
return 0;
|
||||
}
|
||||
printf("Writing %d pages.\n", pages);
|
||||
{ /*cut off extension*/
|
||||
char *ptr = strrchr(conf_opts.ihex_file, '.');
|
||||
if (ptr != NULL)
|
||||
{
|
||||
*ptr = 0;
|
||||
}
|
||||
}
|
||||
strcat(conf_opts.ihex_file, ".hex");
|
||||
printf("Output file: %s.\n", conf_opts.ihex_file);
|
||||
ihex = fopen(conf_opts.ihex_file, "wb");
|
||||
ext_addr=0;
|
||||
addr = 0;
|
||||
if (pages)
|
||||
{
|
||||
int j;
|
||||
error = 0;
|
||||
for (i=0; i<64; i++)
|
||||
{
|
||||
addr = (i & 0x1F) * 2048;
|
||||
if ( ((i / 32) * 0x10000) != ext_addr)
|
||||
{ /*write out ext addr*/
|
||||
/*printf("Ext: %4.4X\n", ((i / 32) * 0x10000));*/
|
||||
ext_addr = (i / 32) * 0x10000;
|
||||
fprintf(ihex, ":02000004%4.4X%2.2X\r\n",
|
||||
(int)(ext_addr>>16), (int)(0xFA-(ext_addr>>16)));
|
||||
}
|
||||
|
||||
if (page_table[i] != 0)
|
||||
{
|
||||
/*printf("%4.4X", addr & 0xF800);*/
|
||||
for (j=0; j<2048; j++)
|
||||
{
|
||||
addr =(i & 0x1F) * 2048 + j;
|
||||
if ((j & 0x1F) == 0)
|
||||
{
|
||||
check = 0;
|
||||
check -= 0x20;
|
||||
check -= (uint8_t) (addr >> 8);
|
||||
check -= (uint8_t) (addr);
|
||||
fprintf(ihex, ":20%4.4X00", (int) addr);
|
||||
}
|
||||
fprintf(ihex, "%2.2X", page_buffer[ext_addr+addr]);
|
||||
check -= page_buffer[ext_addr+addr];
|
||||
if ((j & 0x1F) == 0x1F)
|
||||
{
|
||||
fprintf(ihex, "%2.2X\r\n", check);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ((i & 0x07) == 0x07) printf("\n");
|
||||
else printf(" ");
|
||||
*/
|
||||
}
|
||||
fprintf(ihex, ":00000001FF\r\n");
|
||||
printf("Write complete.\n");
|
||||
}
|
||||
fclose(ihex);
|
||||
}
|
||||
else if(conf_opts.target_type == UNDEFINED)
|
||||
{
|
||||
usage(argv[0]);
|
||||
}
|
||||
return error;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef CONVERTER_H
|
||||
#define CONVERTER_H
|
||||
|
||||
#define CONVERTER_VERSION "v1.4"
|
||||
|
||||
typedef struct {
|
||||
int target_type;
|
||||
char ihex_file[128];
|
||||
}conf_opts_t;
|
||||
|
||||
enum target { UNDEFINED, VERSION, CONVERT };
|
||||
|
||||
#endif
|
|
@ -1,70 +0,0 @@
|
|||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
int hexfile_parse(char *line, unsigned int *type, unsigned int *addr, unsigned char *buffer)
|
||||
{
|
||||
unsigned int row_len = 0;
|
||||
unsigned int row_index = 7;
|
||||
unsigned int i;
|
||||
int tmp;
|
||||
|
||||
uint8_t cksum = 0;
|
||||
int retval = 0;
|
||||
|
||||
retval = sscanf(line, ":%2x%4x%2x", &row_len, addr, type);
|
||||
|
||||
cksum += row_len;
|
||||
cksum += *addr >> 8;
|
||||
cksum += *addr & 0xFF;
|
||||
cksum += *type;
|
||||
|
||||
i = 0;
|
||||
if (retval == 3)
|
||||
{
|
||||
while(i < row_len)
|
||||
{
|
||||
|
||||
if (sscanf(&line[row_index], "%2x", &tmp) == 1)
|
||||
{
|
||||
cksum += tmp;
|
||||
buffer[i++] = (unsigned char) tmp;
|
||||
row_index += 2;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
if (sscanf(&line[row_index], "%2x", &tmp) == 1)
|
||||
{
|
||||
if ((cksum + (uint8_t) tmp) == 0) return row_len;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int hexfile_out(char *line, unsigned int type, unsigned int address, unsigned char *data, unsigned int bytes)
|
||||
{
|
||||
uint8_t cksum = 0;
|
||||
uint8_t i = 0;
|
||||
char tmp[8];
|
||||
|
||||
sprintf(line, ":%2.2X%4.4X%2.2X", bytes, address, type);
|
||||
cksum -= bytes;
|
||||
cksum -= address >> 8;
|
||||
cksum -= address & 0xFF;
|
||||
cksum -= type;
|
||||
|
||||
for (i=0; i<bytes; i++)
|
||||
{
|
||||
sprintf(tmp, "%2.2X", data[i]);
|
||||
strcat(line, tmp);
|
||||
cksum -= data[i];
|
||||
}
|
||||
sprintf(tmp, "%2.2X\r\n", cksum);
|
||||
strcat(line, tmp);
|
||||
|
||||
return strlen(line);
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#ifndef _IHEX_H
|
||||
#define _IHEX_H
|
||||
|
||||
extern int hexfile_parse(char *line, unsigned char *type, unsigned int *addr, char *buffer);
|
||||
extern int hexfile_out(char *line, unsigned int type, unsigned int address, unsigned char *data, unsigned int bytes);
|
||||
|
||||
#endif /*_IHEX_H*/
|
|
@ -57,79 +57,3 @@ bus_init (void)
|
|||
clock_init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Read a block of code memory.
|
||||
* The code must be placed in the lowest bank of flash.
|
||||
*
|
||||
* \param address address to read from flash
|
||||
* \param buffer buffer to store data
|
||||
* \param size number of bytes to read
|
||||
*/
|
||||
#if !SHORTCUTS_CONF_FLASH_READ
|
||||
void
|
||||
flash_read(uint8_t *buf, uint32_t address, uint8_t size)
|
||||
{
|
||||
buf; /*dptr0*/
|
||||
address; /*stack-6*/
|
||||
size; /*stack-7*/
|
||||
|
||||
buf;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
__asm
|
||||
mov dpl, r2
|
||||
mov dph, r3
|
||||
mov a, r0
|
||||
push acc
|
||||
mov a, r2
|
||||
push acc
|
||||
mov a, _MEMCTR
|
||||
push acc
|
||||
|
||||
mov a, _bp
|
||||
add a, #0xf9 ;stack - 7 = size
|
||||
mov r0,a
|
||||
mov a, @r0 ;r2 = size
|
||||
mov r2, a ;r2 = size
|
||||
|
||||
inc r0
|
||||
mov a, @r0
|
||||
mov _DPL1, a ;DPTR1 = address & 0x7FFF | 0x8000
|
||||
inc r0
|
||||
mov a, @r0
|
||||
orl a, #0x80
|
||||
mov _DPH1, a
|
||||
inc r0 ;MEMCTR = ((address >> 15 & 3) << 4) | 0x01 (bank select)
|
||||
mov a, @r0
|
||||
dec r0
|
||||
rrc a
|
||||
mov a, @r0
|
||||
rrc a
|
||||
rr a
|
||||
rr a
|
||||
anl a, #0x30
|
||||
orl a, #1
|
||||
mov _MEMCTR,a
|
||||
lp1:
|
||||
mov _DPS, #1 ;active DPTR = 1
|
||||
clr a
|
||||
movc a, @a+dptr ;read flash (DPTR1)
|
||||
inc dptr
|
||||
mov _DPS, #0 ;active DPTR = 0
|
||||
movx @dptr,a ;write to DPTR0
|
||||
inc dptr
|
||||
djnz r2,lp1 ;while (--size)
|
||||
|
||||
pop acc
|
||||
mov _MEMCTR, a ;restore bank
|
||||
|
||||
pop acc
|
||||
mov r2,a
|
||||
pop acc
|
||||
mov r0,a
|
||||
__endasm;
|
||||
ENABLE_INTERRUPTS();
|
||||
DPL1 = *buf++;
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -49,9 +49,6 @@
|
|||
#define inline
|
||||
|
||||
void bus_init(void);
|
||||
#if !SHORTCUTS_CONF_FLASH_READ
|
||||
void flash_read(uint8_t *buf, uint32_t address, uint8_t size);
|
||||
#endif
|
||||
void clock_ISR( void ) __interrupt (ST_VECTOR);
|
||||
|
||||
#endif /* __BUS_H__ */
|
||||
|
|
|
@ -98,7 +98,7 @@ uint8_t rf_error = 0;
|
|||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
PROCESS(cc2430_rf_process, "CC2430 RF driver");
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -152,7 +152,7 @@ flush_rx()
|
|||
cc2430_rf_command(ISFLUSHRX);
|
||||
cc2430_rf_command(ISFLUSHRX);
|
||||
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
IEN2 |= RFIE;
|
||||
#endif
|
||||
#if CC2430_RFERR_INTERRUPT
|
||||
|
@ -338,7 +338,7 @@ init(void)
|
|||
RFIF &= ~(IRQ_FIFOP);
|
||||
|
||||
S1CON &= ~(RFIF_0 | RFIF_1);
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
IEN2 |= RFIE;
|
||||
#endif
|
||||
|
||||
|
@ -351,7 +351,7 @@ init(void)
|
|||
RF_RX_LED_OFF();
|
||||
rf_initialized = 1;
|
||||
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
process_start(&cc2430_rf_process, NULL);
|
||||
#endif
|
||||
|
||||
|
@ -476,7 +476,7 @@ read(void *buf, unsigned short bufsize)
|
|||
#endif /* CC2420_CONF_CHECKSUM */
|
||||
|
||||
/* Don't interrupt us while emptying the FIFO */
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
IEN2 &= ~RFIE;
|
||||
#endif
|
||||
#if CC2430_RFERR_INTERRUPT
|
||||
|
@ -576,7 +576,7 @@ read(void *buf, unsigned short bufsize)
|
|||
|
||||
RF_RX_LED_OFF();
|
||||
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
IEN2 |= RFIE;
|
||||
#endif
|
||||
#if CC2430_RFERR_INTERRUPT
|
||||
|
@ -688,7 +688,7 @@ const struct radio_driver cc2430_rf_driver =
|
|||
off,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(cc2430_rf_process, ev, data)
|
||||
{
|
||||
|
|
|
@ -77,7 +77,7 @@ int8_t cc2430_rf_channel_set(uint8_t channel);
|
|||
uint8_t cc2430_rf_power_set(uint8_t new_power);
|
||||
void cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr);
|
||||
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
extern void cc2430_rf_ISR( void ) __interrupt (RF_VECTOR);
|
||||
#endif
|
||||
#if CC2430_RFERR_INTERRUPT
|
||||
|
|
|
@ -50,7 +50,7 @@ uint8_t rf_error = 0;
|
|||
|
||||
PROCESS_NAME(cc2430_rf_process);
|
||||
|
||||
#if !SHORTCUTS_CONF_NETSTACK
|
||||
#if !NETSTACK_CONF_SHORTCUTS
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* RF interrupt service routine.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* \file
|
||||
* This file contains a set of configuration for using SDCC as a compiler.
|
||||
* Modified from z80 port for cc2430 port.
|
||||
* This is based on the cc2430 file (which in turn is based on the z80 one)
|
||||
*
|
||||
* \author
|
||||
* Takahide Matsutsuka <markn@markn.org> (Original)
|
||||
|
@ -40,18 +40,20 @@
|
|||
#define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant
|
||||
|
||||
/* Generic types. */
|
||||
typedef unsigned char u8_t; /* 8 bit type */
|
||||
typedef unsigned short u16_t; /* 16 bit type */
|
||||
typedef unsigned long u32_t; /* 32 bit type */
|
||||
typedef signed long s32_t; /* 32 bit type */
|
||||
typedef unsigned short uip_stats_t;
|
||||
|
||||
/* Time type. */
|
||||
typedef unsigned short clock_time_t;
|
||||
#define MAX_TICKS (~((clock_time_t)0) / 2)
|
||||
/* Defines tick counts for a second. */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
|
||||
/* Compiler configurations */
|
||||
#define CCIF
|
||||
#define CLIF
|
||||
|
||||
/* Single asm instruction without messing up syntax highlighting */
|
||||
#if defined SDCC_mcs51
|
||||
#if defined(__SDCC_mcs51) || defined(SDCC_mcs51)
|
||||
#define ASM(x) __asm \
|
||||
x \
|
||||
__endasm
|
||||
|
@ -63,8 +65,8 @@ typedef unsigned short uip_stats_t;
|
|||
#define DISABLE_INTERRUPTS() do {EA = 0;} while(0)
|
||||
#define ENABLE_INTERRUPTS() do {EA = 1;} while(0)
|
||||
|
||||
/* Macro for a soft reset. In many respects better than H/W reboot via W/D */
|
||||
#define SOFT_RESET() {((void (__code *) (void)) 0x0000) ();}
|
||||
/* Macro for a soft reset. */
|
||||
#define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0)
|
||||
|
||||
/* We don't provide architecture-specific checksum calculations */
|
||||
#define UIP_ARCH_ADD32 0
|
||||
|
|
|
@ -36,16 +36,8 @@
|
|||
#include "dev/button-sensor.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define DEBUG 1
|
||||
#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 ", ((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])
|
||||
#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)
|
||||
#endif
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#define PING6_NB 5
|
||||
#define PING6_DATALEN 16
|
||||
|
@ -54,8 +46,7 @@
|
|||
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
|
||||
static struct etimer ping6_periodic_timer;
|
||||
static u8_t count = 0;
|
||||
static u16_t addr[8];
|
||||
static uint8_t count = 0;
|
||||
static uip_ipaddr_t dest_addr;
|
||||
|
||||
PROCESS(ping6_process, "PING6 process");
|
||||
|
@ -82,16 +73,16 @@ ping6handler()
|
|||
|
||||
|
||||
uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN;
|
||||
UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8);
|
||||
UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF);
|
||||
UIP_IP_BUF->len[0] = (uint8_t)((uip_len - 40) >> 8);
|
||||
UIP_IP_BUF->len[1] = (uint8_t)((uip_len - 40) & 0x00FF);
|
||||
|
||||
UIP_ICMP_BUF->icmpchksum = 0;
|
||||
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
||||
|
||||
|
||||
PRINTF("Echo Request to");
|
||||
PRINTF("Echo Request to ");
|
||||
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
||||
PRINTF("from");
|
||||
PRINTF(" from ");
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("\n");
|
||||
UIP_STAT(++uip_stat.icmp.sent);
|
||||
|
|
|
@ -70,7 +70,7 @@ tcpip_handler(void)
|
|||
leds_on(LEDS_RED);
|
||||
len = uip_datalen();
|
||||
memcpy(buf, uip_appdata, len);
|
||||
PRINTF("%u bytes from [", len, *(uint16_t *)buf);
|
||||
PRINTF("%u bytes from [", len);
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
|
||||
#if SERVER_REPLY
|
||||
|
|
|
@ -5,8 +5,10 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
|||
|
||||
# for static routing, if enabled
|
||||
ifneq ($(TARGET), minimal-net)
|
||||
ifneq ($(TARGET), native)
|
||||
PROJECT_SOURCEFILES += static-routing.c
|
||||
endif
|
||||
endif
|
||||
|
||||
# variable for root Makefile.include
|
||||
WITH_UIP6=1
|
||||
|
@ -37,13 +39,11 @@ ifeq ($(WITH_COAP), 7)
|
|||
${info INFO: compiling with CoAP-07}
|
||||
CFLAGS += -DWITH_COAP=7
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-07
|
||||
else ifeq ($(WITH_COAP), 3)
|
||||
${info INFO: compiling with CoAP-03}
|
||||
CFLAGS += -DWITH_COAP=3
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-03
|
||||
else
|
||||
${info INFO: compiling with HTTP}
|
||||
|
|
|
@ -207,10 +207,8 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
|
|||
PRINTF("/separate ");
|
||||
if (separate_active)
|
||||
{
|
||||
PRINTF("BUSY ");
|
||||
REST.set_response_status(response, REST.status.SERVICE_UNAVAILABLE);
|
||||
const char *msg = "AlreadyInUse";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
PRINTF("REJECTED ");
|
||||
coap_separate_reject();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -218,7 +216,7 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
|
|||
separate_active = 1;
|
||||
|
||||
/* Take over and skip response by engine. */
|
||||
coap_separate_yield(request, &separate_store->request_metadata);
|
||||
coap_separate_accept(request, &separate_store->request_metadata);
|
||||
/* Be aware to respect the Block2 option, which is also stored in the coap_separate_t. */
|
||||
|
||||
snprintf(separate_store->buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid);
|
||||
|
@ -227,7 +225,7 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
|
|||
PRINTF("(%s %u)\n", coap_req->type==COAP_TYPE_CON?"CON":"NON", coap_req->mid);
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
separate_periodic_handler(resource_t *resource)
|
||||
{
|
||||
if (separate_active)
|
||||
|
@ -258,14 +256,10 @@ separate_periodic_handler(resource_t *resource)
|
|||
/* The engine will clear the transaction (right after send for NON, after acked for CON). */
|
||||
|
||||
separate_active = 0;
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
PRINTF("ERROR (transaction)\n");
|
||||
}
|
||||
} /* if (separate_active) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -366,7 +360,7 @@ large_update_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
|
|||
*offset = -1;
|
||||
}
|
||||
} else {
|
||||
const uint8_t *incoming = NULL;
|
||||
uint8_t *incoming = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
unsigned int ct = REST.get_header_content_type(request);
|
||||
|
@ -417,9 +411,8 @@ void
|
|||
large_create_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
coap_packet_t *const coap_req = (coap_packet_t *) request;
|
||||
uint8_t method = REST.get_method_type(request);
|
||||
|
||||
const uint8_t *incoming = NULL;
|
||||
uint8_t *incoming = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
unsigned int ct = REST.get_header_content_type(request);
|
||||
|
@ -463,7 +456,7 @@ large_create_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
|
|||
*/
|
||||
PERIODIC_RESOURCE(obs, METHOD_GET, "obs", "title=\"Observable resource which changes every 5 seconds\";obs;rt=\"observe\"", 5*CLOCK_SECOND);
|
||||
|
||||
static uint32_t obs_counter = 0;
|
||||
static uint16_t obs_counter = 0;
|
||||
static char obs_content[16];
|
||||
|
||||
void
|
||||
|
@ -472,7 +465,7 @@ obs_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s
|
|||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
REST.set_header_max_age(response, 5);
|
||||
|
||||
REST.set_response_payload(response, buffer, snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "TICK %lu", obs_counter));
|
||||
REST.set_response_payload(response, obs_content, snprintf(obs_content, MAX_PLUGFEST_PAYLOAD, "TICK %lu", obs_counter));
|
||||
|
||||
/* A post_handler that handles subscriptions will be called for periodic resources by the REST framework. */
|
||||
}
|
||||
|
@ -481,18 +474,23 @@ obs_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s
|
|||
* 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.
|
||||
*/
|
||||
int
|
||||
void
|
||||
obs_periodic_handler(resource_t *r)
|
||||
{
|
||||
++obs_counter;
|
||||
|
||||
PRINTF("TICK /%s\n", r->url);
|
||||
obs_counter = obs_counter + 1;
|
||||
PRINTF("TICK %u for /%s\n", obs_counter, r->url);
|
||||
|
||||
/* Build notification. */
|
||||
/*TODO: REST.new_response() */
|
||||
coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */
|
||||
coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0 );
|
||||
|
||||
/* Better use a generator function for both handlers that only takes *resonse. */
|
||||
obs_handler(NULL, notification, NULL, 0, NULL);
|
||||
|
||||
/* Notify the registered observers with the given message type, observe option, and payload. */
|
||||
REST.notify_subscribers(r->url, 1, obs_counter, (uint8_t *)obs_content, snprintf(obs_content, sizeof(obs_content), "TICK %lu", obs_counter));
|
||||
/* |-> implementation-specific, e.g. CoAP: 0=CON and 1=NON notification */
|
||||
|
||||
return 1;
|
||||
REST.notify_subscribers(r, obs_counter, notification);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -537,7 +535,6 @@ PROCESS_THREAD(plugtest_server, ev, data)
|
|||
rest_activate_resource(&resource_query);
|
||||
#endif
|
||||
#if REST_RES_SEPARATE
|
||||
rest_set_pre_handler(&resource_separate, coap_separate_handler);
|
||||
rest_activate_periodic_resource(&periodic_resource_separate);
|
||||
#endif
|
||||
#if REST_RES_LARGE
|
||||
|
|
|
@ -381,16 +381,14 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
|
|||
*/
|
||||
if (separate_active)
|
||||
{
|
||||
REST.set_response_status(response, REST.status.SERVICE_UNAVAILABLE);
|
||||
const char *msg = "AlreadyInUse";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
coap_separate_reject();
|
||||
}
|
||||
else
|
||||
{
|
||||
separate_active = 1;
|
||||
|
||||
/* Take over and skip response by engine. */
|
||||
coap_separate_yield(request, &separate_store->request_metadata);
|
||||
coap_separate_accept(request, &separate_store->request_metadata);
|
||||
/* Be aware to respect the Block2 option, which is also stored in the coap_separate_t. */
|
||||
|
||||
/*
|
||||
|
@ -465,20 +463,23 @@ pushing_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
|||
* 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.
|
||||
*/
|
||||
int
|
||||
void
|
||||
pushing_periodic_handler(resource_t *r)
|
||||
{
|
||||
static uint32_t periodic_i = 0;
|
||||
static char content[16];
|
||||
static uint16_t obs_counter = 0;
|
||||
static char content[11];
|
||||
|
||||
PRINTF("TICK /%s\n", r->url);
|
||||
periodic_i = periodic_i + 1;
|
||||
++obs_counter;
|
||||
|
||||
PRINTF("TICK %u for /%s\n", periodic_i, r->url);
|
||||
|
||||
/* Build notification. */
|
||||
coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */
|
||||
coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0 );
|
||||
coap_set_payload(notification, content, snprintf(content, sizeof(content), "TICK %u", obs_counter));
|
||||
|
||||
/* Notify the registered observers with the given message type, observe option, and payload. */
|
||||
REST.notify_subscribers(r->url, 1, periodic_i, (uint8_t *)content, snprintf(content, sizeof(content), "TICK %lu", periodic_i));
|
||||
/* |-> implementation-specific, e.g. CoAP: 0=CON and 1=NON notification */
|
||||
|
||||
return 1;
|
||||
REST.notify_subscribers(r, obs_counter, notification);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -503,21 +504,23 @@ event_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
|
|||
|
||||
/* Additionally, a handler function named [resource name]_event_handler must be implemented for each PERIODIC_RESOURCE defined.
|
||||
* It will be called by the REST manager process with the defined period. */
|
||||
int
|
||||
void
|
||||
event_event_handler(resource_t *r)
|
||||
{
|
||||
static uint32_t event_i = 0;
|
||||
static char content[10];
|
||||
static uint16_t event_counter = 0;
|
||||
static char content[12];
|
||||
|
||||
PRINTF("EVENT /%s\n", r->url);
|
||||
++event_i;
|
||||
++event_counter;
|
||||
|
||||
/* Notify registered observers with the given message type, observe option, and payload.
|
||||
* The token will be set automatically. */
|
||||
PRINTF("TICK %u for /%s\n", event_counter, r->url);
|
||||
|
||||
// FIXME provide a rest_notify_subscribers call; how to manage specific options such as COAP_TYPE?
|
||||
REST.notify_subscribers(r->url, 0, event_i, content, snprintf(content, sizeof(content), "EVENT %lu", event_i));
|
||||
return 1;
|
||||
/* Build notification. */
|
||||
coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */
|
||||
coap_init_message(notification, COAP_TYPE_CON, CONTENT_2_05, 0 );
|
||||
coap_set_payload(notification, content, snprintf(content, sizeof(content), "EVENT %u", event_counter));
|
||||
|
||||
/* Notify the registered observers with the given message type, observe option, and payload. */
|
||||
REST.notify_subscribers(r, event_counter, notification);
|
||||
}
|
||||
#endif /* PLATFORM_HAS_BUTTON */
|
||||
|
||||
|
@ -705,8 +708,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
|||
rest_activate_event_resource(&resource_event);
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3
|
||||
/* Use this pre-handler for separate response resources. */
|
||||
rest_set_pre_handler(&resource_separate, coap_separate_handler);
|
||||
/* No pre-handler anymore, user coap_separate_accept() and coap_separate_reject(). */
|
||||
rest_activate_resource(&resource_separate);
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3))
|
||||
|
|
|
@ -19,7 +19,7 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
static struct etimer et;
|
||||
static clock_time_t count, start_count, end_count, diff;
|
||||
static unsigned long sec;
|
||||
static u8_t i;
|
||||
static uint8_t i;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
|
@ -41,8 +41,8 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
etimer_reset(&et);
|
||||
|
||||
count = clock_time();
|
||||
printf("%u ticks\n", count);
|
||||
count = clock_time();
|
||||
printf("%u ticks\n", count);
|
||||
|
||||
leds_toggle(LEDS_RED);
|
||||
i++;
|
||||
|
@ -55,8 +55,8 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
etimer_reset(&et);
|
||||
|
||||
sec = clock_seconds();
|
||||
printf("%u seconds\n", (u16_t) sec);
|
||||
sec = clock_seconds();
|
||||
printf("%u seconds\n", (uint16_t) sec);
|
||||
|
||||
leds_toggle(LEDS_GREEN);
|
||||
i++;
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "contiki.h"
|
||||
#include "cc2430_sfr.h"
|
||||
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#include "dev/cc2430_rf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
#define EVENT_POST_H_
|
||||
|
||||
struct event_struct {
|
||||
short s_val;
|
||||
int i_val;
|
||||
long l_val;
|
||||
long long ll_val;
|
||||
u8_t u8_val;
|
||||
u16_t u16_val;
|
||||
u32_t u32_val;
|
||||
short s_val;
|
||||
int i_val;
|
||||
long l_val;
|
||||
long long ll_val;
|
||||
uint8_t u8_val;
|
||||
uint16_t u16_val;
|
||||
uint32_t u32_val;
|
||||
};
|
||||
|
||||
#endif /* EVENT_POST_H_ */
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#include "dev/leds.h"
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG 0
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#else
|
||||
#define putstring(s)
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#endif /* CONTIKI_TARGET_SENSINODE */
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else /* DEBUG */
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#define PUTBIN(b) putbin(b)
|
||||
#else
|
||||
|
|
|
@ -111,7 +111,7 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
etimer_reset(&et);
|
||||
|
||||
sec = clock_seconds();
|
||||
printf("%u seconds\n", (u16_t) sec);
|
||||
printf("%u seconds\n", (uint16_t) sec);
|
||||
|
||||
leds_toggle(LEDS_GREEN);
|
||||
i++;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#else
|
||||
#define putstring(s)
|
||||
#define puthex(s)
|
||||
|
|
|
@ -35,19 +35,11 @@
|
|||
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#endif
|
||||
|
||||
#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 ", ((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])
|
||||
#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)
|
||||
#endif
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#define PING6_NB 5
|
||||
#define PING6_DATALEN 16
|
||||
|
@ -56,8 +48,7 @@
|
|||
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
|
||||
static struct etimer ping6_periodic_timer;
|
||||
static u8_t count = 0;
|
||||
static u16_t addr[8];
|
||||
static uint8_t count = 0;
|
||||
static uip_ipaddr_t dest_addr;
|
||||
|
||||
PROCESS(ping6_process, "PING6 process");
|
||||
|
@ -84,16 +75,16 @@ ping6handler()
|
|||
|
||||
|
||||
uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN;
|
||||
UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8);
|
||||
UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF);
|
||||
UIP_IP_BUF->len[0] = (uint8_t)((uip_len - 40) >> 8);
|
||||
UIP_IP_BUF->len[1] = (uint8_t)((uip_len - 40) & 0x00FF);
|
||||
|
||||
UIP_ICMP_BUF->icmpchksum = 0;
|
||||
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
||||
|
||||
|
||||
PRINTF("Echo Request to");
|
||||
PRINTF("Echo Request to ");
|
||||
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
||||
PRINTF("from");
|
||||
PRINTF(" from ");
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("\n");
|
||||
UIP_STAT(++uip_stat.icmp.sent);
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#else
|
||||
#define putstring(s)
|
||||
#endif
|
||||
|
@ -77,7 +77,7 @@ tcpip_handler(void)
|
|||
leds_on(LEDS_RED);
|
||||
len = uip_datalen();
|
||||
memcpy(buf, uip_appdata, len);
|
||||
PRINTF("%u bytes from [", len, *(uint16_t *)buf);
|
||||
PRINTF("%u bytes from [", len);
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("]:%u", UIP_HTONS(UIP_UDP_BUF->srcport));
|
||||
PRINTF(" V=%u", *buf);
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
#include "project-conf.h"
|
||||
#endif /* PROJECT_CONF_H */
|
||||
|
||||
/* Time type. */
|
||||
typedef unsigned short clock_time_t;
|
||||
|
||||
/* Defines tick counts for a second. */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
|
||||
/* Energest Module */
|
||||
#ifndef ENERGEST_CONF_ON
|
||||
#define ENERGEST_CONF_ON 0
|
||||
|
@ -70,18 +64,14 @@ typedef unsigned short clock_time_t;
|
|||
|
||||
/* Code Shortcuts */
|
||||
/*
|
||||
* When set, the RF driver is no longer a contiki process and the RX ISR is
|
||||
* disabled. Instead of polling the radio process when data arrives, we
|
||||
* periodically check for data by directly invoking the driver from main()
|
||||
|
||||
* When set, this directive also configures the following bypasses:
|
||||
* - process_post_synch() in tcpip_input() (we call packet_input())
|
||||
* - process_post_synch() in tcpip_uipcall (we call the relevant pthread)
|
||||
* - mac_call_sent_callback() is replaced with sent() in various places
|
||||
*
|
||||
* These are good things to do, we reduce stack usage, RAM size and code size
|
||||
* These are good things to do, they reduce stack usage and prevent crashes
|
||||
*/
|
||||
#define SHORTCUTS_CONF_NETSTACK 1
|
||||
#define NETSTACK_CONF_SHORTCUTS 1
|
||||
|
||||
/*
|
||||
* Sensors
|
||||
|
|
|
@ -254,7 +254,6 @@ main(void)
|
|||
watchdog_periodic();
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
#if SHORTCUTS_CONF_NETSTACK
|
||||
len = NETSTACK_RADIO.pending_packet();
|
||||
if(len) {
|
||||
packetbuf_clear();
|
||||
|
@ -264,7 +263,6 @@ main(void)
|
|||
NETSTACK_RDC.input();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LPM_MODE
|
||||
#if (LPM_MODE==LPM_MODE_PM2)
|
||||
|
|
|
@ -71,7 +71,6 @@ extern uip_ds6_netif_t uip_ds6_if;
|
|||
extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB];
|
||||
extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
|
||||
extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB];
|
||||
extern u16_t uip_len;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
process_request()
|
||||
|
|
|
@ -40,7 +40,7 @@ CONTIKI_TARGET_SOURCEFILES = contiki-sensinode-main.c
|
|||
CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c serial-line.c sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += sensinode-sensors.c button-sensor.c adc-sensor.c
|
||||
CONTIKI_TARGET_SOURCEFILES += n740.c models.c m25p16.c slip-arch.c slip.c
|
||||
CONTIKI_TARGET_SOURCEFILES += putchar.c sensinode-debug.c
|
||||
CONTIKI_TARGET_SOURCEFILES += putchar.c debug.c
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
#include "project-conf.h"
|
||||
#endif /* PROJECT_CONF_H */
|
||||
|
||||
/* Defines tick counts for a second. */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
|
||||
/* The clock ISR is stack-hungry and may cause crashes.
|
||||
* Define this as 0 if you are suffering from frequent stack overflows */
|
||||
#ifndef CLOCK_CONF_ACCURATE
|
||||
|
@ -85,21 +82,15 @@
|
|||
* When set, the RF driver is no longer a contiki process and the RX ISR is
|
||||
* disabled. Instead of polling the radio process when data arrives, we
|
||||
* periodically check for data by directly invoking the driver from main()
|
||||
|
||||
*
|
||||
* When set, this directive also configures the following bypasses:
|
||||
* - process_post_synch() in tcpip_input() (we call packet_input())
|
||||
* - process_post_synch() in tcpip_uipcall (we call the relevant pthread)
|
||||
* - mac_call_sent_callback() is replaced with sent() in various places
|
||||
*
|
||||
* These are good things to do, we reduce stack usage, RAM size and code size
|
||||
* These are good things to do, they reduce stack usage and prevent crashes
|
||||
*/
|
||||
#define SHORTCUTS_CONF_NETSTACK 1
|
||||
|
||||
/*
|
||||
* Directly read mac from flash with a __code pointer, instead of using the
|
||||
* generic flash_read() routine. This reduces HOME code size
|
||||
*/
|
||||
#define SHORTCUTS_CONF_FLASH_READ 1
|
||||
#define NETSTACK_CONF_SHORTCUTS 1
|
||||
|
||||
/*
|
||||
* Sensors
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "net/rime.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
#include "dev/watchdog-cc2430.h"
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#include "disco.h"
|
||||
|
@ -32,7 +32,7 @@ PROCESS_NAME(viztool_process);
|
|||
PROCESS_NAME(batmon_process);
|
||||
#endif
|
||||
|
||||
#if SHORTCUTS_CONF_NETSTACK
|
||||
#if NETSTACK_CONF_SHORTCUTS
|
||||
static __data int len;
|
||||
#endif
|
||||
|
||||
|
@ -99,12 +99,7 @@ set_rime_addr(void)
|
|||
uint8_t *addr_long = NULL;
|
||||
uint16_t addr_short = 0;
|
||||
char i;
|
||||
|
||||
#if SHORTCUTS_CONF_FLASH_READ
|
||||
__code unsigned char * macp;
|
||||
#else
|
||||
static uint8_t ft_buffer[8];
|
||||
#endif
|
||||
|
||||
PUTSTRING("Rime is 0x");
|
||||
PUTHEX(sizeof(rimeaddr_t));
|
||||
|
@ -112,7 +107,6 @@ set_rime_addr(void)
|
|||
|
||||
if(node_id == 0) {
|
||||
PUTSTRING("Reading MAC from flash\n");
|
||||
#if SHORTCUTS_CONF_FLASH_READ
|
||||
/*
|
||||
* The MAC is always stored in 0x1FFF8 of our flash. This maps to address
|
||||
* 0xFFF8 of our CODE segment, when BANK3 is selected.
|
||||
|
@ -124,7 +118,7 @@ set_rime_addr(void)
|
|||
/* Don't interrupt us to make sure no BANK switching happens while working */
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
/* Switch to BANK3, map CODE: 0x8000 – 0xFFFF to FLASH: 0x18000 – 0x1FFFF */
|
||||
/* Switch to BANK3, map CODE: 0x8000 - 0xFFFF to FLASH: 0x18000 - 0x1FFFF */
|
||||
FMAP = 3;
|
||||
|
||||
/* Set our pointer to the correct address and fetch 8 bytes of MAC */
|
||||
|
@ -135,21 +129,9 @@ set_rime_addr(void)
|
|||
macp++;
|
||||
}
|
||||
|
||||
/* Remap 0x8000 – 0xFFFF to BANK1 */
|
||||
/* Remap 0x8000 - 0xFFFF to BANK1 */
|
||||
FMAP = 1;
|
||||
ENABLE_INTERRUPTS();
|
||||
#else
|
||||
/*
|
||||
* Or use the more generic flash_read() routine which can read from any
|
||||
* address of our flash
|
||||
*/
|
||||
flash_read(ft_buffer, 0x1FFF8, 8);
|
||||
|
||||
/* Flip the byte order and store MSB first */
|
||||
for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) {
|
||||
rimeaddr_node_addr.u8[RIMEADDR_SIZE - 1 - i] = ft_buffer[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
PUTSTRING("Setting manual address from node_id\n");
|
||||
|
@ -324,7 +306,7 @@ main(void)
|
|||
#endif
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
#if SHORTCUTS_CONF_NETSTACK
|
||||
#if NETSTACK_CONF_SHORTCUTS
|
||||
len = NETSTACK_RADIO.pending_packet();
|
||||
if(len) {
|
||||
packetbuf_clear();
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "cc2430_sfr.h"
|
||||
#include "8051def.h"
|
||||
#include "sensinode-debug.h"
|
||||
#include "debug.h"
|
||||
|
||||
static const char hexconv[] = "0123456789abcdef";
|
||||
static const char binconv[] = "01";
|
|
@ -40,8 +40,8 @@
|
|||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef SENSINODE_DEBUG_H_
|
||||
#define SENSINODE_DEBUG_H_
|
||||
#ifndef DEBUG_H_
|
||||
#define DEBUG_H_
|
||||
|
||||
#include "8051def.h"
|
||||
#include "dev/uart1.h"
|
||||
|
@ -51,4 +51,4 @@ void putstring(char *s);
|
|||
void puthex(uint8_t c);
|
||||
void putbin(uint8_t c);
|
||||
|
||||
#endif /* SENSINODE_DEBUG_H_ */
|
||||
#endif /* DEBUG_H_ */
|
|
@ -71,7 +71,6 @@ extern uip_ds6_netif_t uip_ds6_if;
|
|||
extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB];
|
||||
extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
|
||||
extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB];
|
||||
extern u16_t uip_len;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
process_request()
|
||||
|
|
Loading…
Reference in a new issue