Code style fixes: sensinode examples

This commit is contained in:
George Oikonomou 2012-12-16 15:29:45 +00:00
parent 594ba9a0ed
commit 64a95dcb59
19 changed files with 205 additions and 251 deletions

View file

@ -10,61 +10,36 @@
#include "contiki.h" #include "contiki.h"
#include "dev/leds.h" #include "dev/leds.h"
#include <stdio.h> /* For printf() */ #include <stdio.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* We declare the two processes */
PROCESS(hello_world_process, "Hello world process"); PROCESS(hello_world_process, "Hello world process");
PROCESS(blink_process, "LED blink process"); PROCESS(blink_process, "LED blink process");
/* We require the processes to be started automatically */
AUTOSTART_PROCESSES(&hello_world_process, &blink_process); AUTOSTART_PROCESSES(&hello_world_process, &blink_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Implementation of the first process */ /* Implementation of the first process */
PROCESS_THREAD(hello_world_process, ev, data) PROCESS_THREAD(hello_world_process, ev, data)
{ {
/* variables are declared static to ensure their values are maintained
between subsequent calls.
All the code between PROCESS_THREAD and PROCESS_BEGIN() runs each time
the process is invoked. */
static struct etimer timer; static struct etimer timer;
static int count; static int count;
/* any process must start with this. */
PROCESS_BEGIN(); PROCESS_BEGIN();
/* set the etimer module to generate an event in one second.
CLOCK_CONF_SECOND is #define as 128 */
etimer_set(&timer, CLOCK_CONF_SECOND * 4); etimer_set(&timer, CLOCK_CONF_SECOND * 4);
count = 0; count = 0;
/* Don't declare variables after PROCESS_BEGIN.
* While it will compile fine with TARGET=native (gcc is happy), while(1) {
* SDCC doesn't like it. Soon as you try TARGET=sensinode you will get:
* syntax error: token -> 'int' ;
* Try uncommenting the line below and observe the results */
/* int whoops = 0;
* whoops = 0; */
while (1)
{
/* wait here for an event to happen */
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();
/* This achieves the same
* PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); */
/* if the event is the timer event as expected... */ if(ev == PROCESS_EVENT_TIMER) {
if(ev == PROCESS_EVENT_TIMER)
{
/* do the process work */
printf("Sensor says no... #%d\r\n", count); printf("Sensor says no... #%d\r\n", count);
count ++; count++;
/* reset the timer so it will generate an other event
* the exact same time after it expired (periodicity guaranteed) */
etimer_reset(&timer); etimer_reset(&timer);
} }
/* and loop */
} }
/* any process must end with this, even if it is never reached. */
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -74,16 +49,12 @@ PROCESS_THREAD(blink_process, ev, data)
static struct etimer timer; static struct etimer timer;
PROCESS_BEGIN(); PROCESS_BEGIN();
while (1) while(1) {
{
/* we set the timer from here every time */
etimer_set(&timer, CLOCK_CONF_SECOND); etimer_set(&timer, CLOCK_CONF_SECOND);
/* and wait until the event we receive is the one we're waiting for */
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
printf("Blink... (state %0.2X).\r\n", leds_get()); printf("Blink... (state %0.2X).\r\n", leds_get());
/* update the LEDs */
leds_toggle(LEDS_GREEN); leds_toggle(LEDS_GREEN);
} }
PROCESS_END(); PROCESS_END();

View file

@ -75,7 +75,7 @@ print_local_addresses(void) CC_NON_BANKED
PUTSTRING(" "); PUTSTRING(" ");
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PUTCHAR('\n'); PUTCHAR('\n');
if (state == ADDR_TENTATIVE) { if(state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
} }
} }

View file

@ -58,7 +58,7 @@ static void
slip_input_callback(void) slip_input_callback(void)
{ {
PRINTF("SIN: %u\n", uip_len); PRINTF("SIN: %u\n", uip_len);
if((char) uip_buf[0] == '!') { if((char)uip_buf[0] == '!') {
PRINTF("Got configuration message of type %c\n", uip_buf[1]); PRINTF("Got configuration message of type %c\n", uip_buf[1]);
uip_len = 0; uip_len = 0;
if((char)uip_buf[1] == 'P') { if((char)uip_buf[1] == 'P') {

View file

@ -58,14 +58,18 @@
PROCESS(example_broadcast_process, "BROADCAST example"); PROCESS(example_broadcast_process, "BROADCAST example");
AUTOSTART_PROCESSES(&example_broadcast_process); AUTOSTART_PROCESSES(&example_broadcast_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from) static void
broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
{ {
leds_toggle(LEDS_RED); leds_toggle(LEDS_RED);
PRINTF("broadcast message received from %02x.%02x\n", from->u8[0], from->u8[1]); PRINTF("broadcast message received from %02x.%02x\n", from->u8[0],
PRINTF("Size=0x%02x: '0x%04x'\n", packetbuf_datalen(), *(uint16_t *) packetbuf_dataptr()); from->u8[1]);
PRINTF("Size=0x%02x: '0x%04x'\n", packetbuf_datalen(),
*(uint16_t *)packetbuf_dataptr());
} }
/*---------------------------------------------------------------------------*/
static void print_rime_stats() static void
print_rime_stats()
{ {
PRINTF("\nNetwork Stats\n"); PRINTF("\nNetwork Stats\n");
PRINTF(" TX=%lu , RX=%lu\n", rimestats.tx, rimestats.rx); PRINTF(" TX=%lu , RX=%lu\n", rimestats.tx, rimestats.rx);
@ -90,7 +94,7 @@ PROCESS_THREAD(example_broadcast_process, ev, data)
PRINTF("Start\n"); PRINTF("Start\n");
broadcast_open(&broadcast, BROADCAST_CHANNEL, &bc_rx); broadcast_open(&broadcast, BROADCAST_CHANNEL, &bc_rx);
PRINTF("Open Broadcast Connection, channel %u\n", BROADCAST_CHANNEL); PRINTF("Open Broadcast Connection, channel %u\n", BROADCAST_CHANNEL);
// leds_off(LEDS_ALL);
while(1) { while(1) {
/* Delay 2-4 seconds */ /* Delay 2-4 seconds */
@ -98,8 +102,9 @@ PROCESS_THREAD(example_broadcast_process, ev, data)
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_on(LEDS_GREEN); leds_on(LEDS_GREEN);
packetbuf_copyfrom(&counter, sizeof(counter)); packetbuf_copyfrom(&counter, sizeof(counter));
PRINTF("Sending %u bytes: 0x%04x\n", packetbuf_datalen(), *(uint16_t *) packetbuf_dataptr()); PRINTF("Sending %u bytes: 0x%04x\n", packetbuf_datalen(),
if (broadcast_send(&broadcast) == 0) { *(uint16_t *)packetbuf_dataptr());
if(broadcast_send(&broadcast) == 0) {
PRINTF("Error Sending\n"); PRINTF("Error Sending\n");
} }

View file

@ -181,7 +181,8 @@ broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
/* Convert RSSI to the loc. eng. format */ /* Convert RSSI to the loc. eng. format */
parameters.rssi[from->u8[1] - 1] = (-2 * rssi); parameters.rssi[from->u8[1] - 1] = (-2 * rssi);
/* Raw dump the packetbuf into the ref_coords struct */ /* Raw dump the packetbuf into the ref_coords struct */
memcpy(&ref_coords[from->u8[1] - 1], packetbuf_dataptr(), 2 * sizeof(uint8_t)); memcpy(&ref_coords[from->u8[1] - 1], packetbuf_dataptr(),
2 * sizeof(uint8_t));
} }
return; return;
@ -194,7 +195,8 @@ broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
set_imaginary_ref_nodes() { set_imaginary_ref_nodes()
{
ref_coords[0].x = 1; ref_coords[0].x = 1;
ref_coords[0].y = 5; ref_coords[0].y = 5;
parameters.rssi[0] = SAMPLE_RSSI; parameters.rssi[0] = SAMPLE_RSSI;
@ -243,11 +245,11 @@ PROCESS_THREAD(blindnode_bcast_rec, ev, data)
* Just hard-coding measurement parameters here. * Just hard-coding measurement parameters here.
* Ideally, this should be part of a calibration mechanism * Ideally, this should be part of a calibration mechanism
*/ */
parameters.alpha=SAMPLE_ALPHA; parameters.alpha = SAMPLE_ALPHA;
parameters.x_min=0; parameters.x_min = 0;
parameters.x_delta=255; parameters.x_delta = 255;
parameters.y_min=0; parameters.y_min = 0;
parameters.y_delta=255; parameters.y_delta = 255;
set_imaginary_ref_nodes(); set_imaginary_ref_nodes();
@ -263,13 +265,15 @@ PROCESS_THREAD(blindnode_bcast_rec, ev, data)
* With the hard-coded parameters and locations, we will calculate * With the hard-coded parameters and locations, we will calculate
* for all possible values of n [0 , 31] * for all possible values of n [0 , 31]
*/ */
parameters.n=n; parameters.n = n;
calculate(); calculate();
n++; n++;
if(n==32) { n=0; } if(n == 32) {
n = 0;
}
/* Send our calculated location to some monitoring node */ /* Send our calculated location to some monitoring node */
packetbuf_copyfrom(&coords, 2*sizeof(uint8_t)); packetbuf_copyfrom(&coords, 2 * sizeof(uint8_t));
broadcast_send(&broadcast); broadcast_send(&broadcast);
} }
PROCESS_END(); PROCESS_END();

View file

@ -47,4 +47,3 @@ netstack_init(void)
NETSTACK_RADIO.init(); NETSTACK_RADIO.init();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -14,67 +14,44 @@
#include "contiki.h" #include "contiki.h"
//#include "dev/leds.h" //#include "dev/leds.h"
#include <limits.h> #include <limits.h>
#include <stdio.h> /* For printf() */ #include <stdio.h>
#include "event-post.h" #include "event-post.h"
/* This is our event type */ /* This is our event type */
static process_event_t event_data_ready; static process_event_t event_data_ready;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Declare the two processes here */ /* Declare the two processes here */
PROCESS(sensor_process, "Sensor process"); PROCESS(sensor_process, "Sensor process");
PROCESS(print_process, "Print process"); PROCESS(print_process, "Print process");
/* Tell Contiki that we want them to start automatically */
AUTOSTART_PROCESSES(&sensor_process, &print_process); AUTOSTART_PROCESSES(&sensor_process, &print_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Implementation "Sensor Process" */
PROCESS_THREAD(sensor_process, ev, data) PROCESS_THREAD(sensor_process, ev, data)
{ {
/* static variables to preserve values across consecutive calls of this
* process. */
/* Set an etimer */
static struct etimer timer; static struct etimer timer;
/* And the 'sensor' monitoring variable */
static struct event_struct es; static struct event_struct es;
PROCESS_BEGIN(); PROCESS_BEGIN();
/* Set some near-the-limit initial values */ es.s_val = SHRT_MAX - 2;
/* signed primitives */ es.i_val = INT_MAX - 2;
es.s_val = SHRT_MAX-2; es.l_val = LONG_MAX - 2;
es.i_val = INT_MAX-2; es.ll_val = LONG_MAX - 2;
es.l_val = LONG_MAX-2; es.u8_val = UCHAR_MAX - 2;
/* sizeof(long long) == sizeof(long) on sensinodes - see other examples*/ es.u16_val = USHRT_MAX - 2;
es.ll_val = LONG_MAX-2; es.u32_val = ULONG_MAX - 2;
/* and some typedef-ed unsigned variables */
es.u8_val = UCHAR_MAX-2;
es.u16_val = USHRT_MAX-2;
es.u32_val = ULONG_MAX-2;
/* allocate the required event */
event_data_ready = process_alloc_event(); event_data_ready = process_alloc_event();
/* process_event_t is actually a u_char. What did the OS allocate for us? */
printf("Contiki allocated event ID %d.\r\n", event_data_ready); printf("Contiki allocated event ID %d.\r\n", event_data_ready);
/* Set a timer here. We will generate an event every times this timer expires
* etimer_set accepts clock ticks as its 2nd argument.
* CLOCK_CONF_SECOND is the number of ticks per second.
* This CLOCK_CONF_SECOND * N = N seconds */
etimer_set(&timer, CLOCK_CONF_SECOND * 2); etimer_set(&timer, CLOCK_CONF_SECOND * 2);
while (1) while(1) {
{
printf("Sensor process: Wait for timer event...\r\n"); printf("Sensor process: Wait for timer event...\r\n");
/* Wait on our timer */
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
/* blip */
/* leds_toggle(LEDS_BLUE); */
/* Set the 'sensor' value before throwing the event */
printf("Sensor Process: Incrementing values...\r\n"); printf("Sensor Process: Incrementing values...\r\n");
es.s_val++; es.s_val++;
es.i_val++; es.i_val++;
@ -84,13 +61,9 @@ PROCESS_THREAD(sensor_process, ev, data)
es.u16_val++; es.u16_val++;
es.u32_val++; es.u32_val++;
/* Post our event.
* N.B. es is declared static.
* Try passing a volatile variable and observe the results... */
printf("Sensor Process: Generating 'Data Ready' event.\r\n"); printf("Sensor Process: Generating 'Data Ready' event.\r\n");
process_post(&print_process, event_data_ready, &es); process_post(&print_process, event_data_ready, &es);
/* reset the timer so we can wait on it again */
etimer_reset(&timer); etimer_reset(&timer);
} }
@ -101,20 +74,14 @@ PROCESS_THREAD(sensor_process, ev, data)
PROCESS_THREAD(print_process, ev, data) PROCESS_THREAD(print_process, ev, data)
{ {
struct event_struct * sd; struct event_struct *sd;
PROCESS_BEGIN(); PROCESS_BEGIN();
while (1) while(1) {
{
/* Stop here and wait until "event_data_ready" occurs */
PROCESS_WAIT_EVENT_UNTIL(ev == event_data_ready); PROCESS_WAIT_EVENT_UNTIL(ev == event_data_ready);
/* When the event occurs, the incoming data will be stored in
* process_data_t data (careful, this is void *)
*
* Print away...
* es is volatile, we need to set it = data again and dereference it. */
sd = data; sd = data;
printf("Print Process - Data Ready:\r\n"); printf("Print Process - Data Ready:\r\n");
printf(" s: %d\r\n", sd->s_val); printf(" s: %d\r\n", sd->s_val);
@ -125,7 +92,6 @@ PROCESS_THREAD(print_process, ev, data)
printf(" u16: %u\r\n", sd->u16_val); printf(" u16: %u\r\n", sd->u16_val);
printf(" u32: %lu\r\n", sd->u32_val); printf(" u32: %lu\r\n", sd->u32_val);
/* aaaaand back to waiting for the next event */
} }
PROCESS_END(); PROCESS_END();
} }

View file

@ -77,11 +77,11 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int8_t int8_t
read_sensor(char * rs) read_sensor(char *rs)
{ {
/* Sensor Values */ /* Sensor Values */
static int rv; static int rv;
static struct sensors_sensor * sensor; static struct sensors_sensor *sensor;
/* Those 3 variables are only used for debugging */ /* Those 3 variables are only used for debugging */
#if DEBUG #if DEBUG
@ -93,7 +93,7 @@ read_sensor(char * rs)
uint8_t len = 0; uint8_t len = 0;
sensor = sensors_find(ADC_SENSOR); sensor = sensors_find(ADC_SENSOR);
if (!sensor) { if(!sensor) {
PRINTF("ADC not found\n"); PRINTF("ADC not found\n");
return (SENSOR_ADC_OFF); return (SENSOR_ADC_OFF);
} }
@ -103,13 +103,13 @@ read_sensor(char * rs)
r = uip_ntohs(r); r = uip_ntohs(r);
PRINTF("R=%u\n", r); PRINTF("R=%u\n", r);
if (r & REQUEST_BIT_CHIPID) { if(r & REQUEST_BIT_CHIPID) {
uint8_t chipid = CHIPID; uint8_t chipid = CHIPID;
memcpy(rs + len, &chipid, sizeof(chipid)); memcpy(rs + len, &chipid, sizeof(chipid));
len += sizeof(chipid); len += sizeof(chipid);
PRINTF("ChipID=0x%02x\n", chipid); PRINTF("ChipID=0x%02x\n", chipid);
} }
if (r & REQUEST_BIT_UPTIME) { if(r & REQUEST_BIT_UPTIME) {
/* Uptime */ /* Uptime */
unsigned long l; unsigned long l;
@ -118,33 +118,33 @@ read_sensor(char * rs)
len += sizeof(l); len += sizeof(l);
PRINTF("Uptime=%lu secs\n", uip_ntohl(l)); PRINTF("Uptime=%lu secs\n", uip_ntohl(l));
} }
if (r & REQUEST_BIT_LIGHT) { if(r & REQUEST_BIT_LIGHT) {
rv = sensor->value(ADC_SENSOR_TYPE_LIGHT); rv = sensor->value(ADC_SENSOR_TYPE_LIGHT);
if(rv != -1) { if(rv != -1) {
#if DEBUG #if DEBUG
sane = (float)(rv * 0.4071); sane = (float)(rv * 0.4071);
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF(" Light=%d.%02ulux (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF(" Light=%d.%02ulux (%d)\n", dec, (unsigned int)(frac * 100), rv);
#endif #endif
memcpy(rs + len, &rv, sizeof(rv)); memcpy(rs + len, &rv, sizeof(rv));
len += sizeof(rv); len += sizeof(rv);
} }
} }
if (r & REQUEST_BIT_TEMP) { if(r & REQUEST_BIT_TEMP) {
rv = sensor->value(ADC_SENSOR_TYPE_TEMP); rv = sensor->value(ADC_SENSOR_TYPE_TEMP);
if(rv != -1) { if(rv != -1) {
#if DEBUG #if DEBUG
sane = ((rv * 0.61065 - 773) / 2.45); sane = ((rv * 0.61065 - 773) / 2.45);
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF(" Temp=%d.%02u C (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF(" Temp=%d.%02u C (%d)\n", dec, (unsigned int)(frac * 100), rv);
#endif #endif
memcpy(rs + len, &rv, sizeof(rv)); memcpy(rs + len, &rv, sizeof(rv));
len += sizeof(rv); len += sizeof(rv);
} }
} }
if (r & (REQUEST_BIT_VDD | REQUEST_BIT_BAT)) { if(r & (REQUEST_BIT_VDD | REQUEST_BIT_BAT)) {
/* We want VDD for both cases */ /* We want VDD for both cases */
rv = sensor->value(ADC_SENSOR_TYPE_VDD); rv = sensor->value(ADC_SENSOR_TYPE_VDD);
if(rv != -1) { if(rv != -1) {
@ -152,7 +152,7 @@ read_sensor(char * rs)
sane = rv * 3.75 / 2047; sane = rv * 3.75 / 2047;
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF("Supply=%d.%02uV (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("Supply=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv);
/* Store rv temporarily in dec so we can use it for the battery */ /* Store rv temporarily in dec so we can use it for the battery */
dec = rv; dec = rv;
#endif #endif
@ -160,21 +160,21 @@ read_sensor(char * rs)
len += sizeof(rv); len += sizeof(rv);
} }
/* And then carry on with battery if needed */ /* And then carry on with battery if needed */
if (r & REQUEST_BIT_BAT) { if(r & REQUEST_BIT_BAT) {
rv = sensor->value(ADC_SENSOR_TYPE_BATTERY); rv = sensor->value(ADC_SENSOR_TYPE_BATTERY);
if(rv != -1) { if(rv != -1) {
#if DEBUG #if DEBUG
sane = (11.25 * rv * dec) / (0x7FE002); sane = (11.25 * rv * dec) / (0x7FE002);
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF(" Batt.=%d.%02uV (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF(" Batt.=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv);
#endif #endif
memcpy(rs + len, &rv, sizeof(rv)); memcpy(rs + len, &rv, sizeof(rv));
len += sizeof(rv); len += sizeof(rv);
} }
} }
} }
if (r & REQUEST_BIT_ACC) { if(r & REQUEST_BIT_ACC) {
rv = sensor->value(ADC_SENSOR_TYPE_ACC_X); rv = sensor->value(ADC_SENSOR_TYPE_ACC_X);
if(rv != -1) { if(rv != -1) {
#if DEBUG #if DEBUG
@ -187,7 +187,7 @@ read_sensor(char * rs)
if(sane < 0 && dec == 0) { if(sane < 0 && dec == 0) {
PRINTF('-'); PRINTF('-');
} }
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
#endif #endif
memcpy(rs + len, &rv, sizeof(rv)); memcpy(rs + len, &rv, sizeof(rv));
len += sizeof(rv); len += sizeof(rv);
@ -203,7 +203,7 @@ read_sensor(char * rs)
if(sane < 0 && dec == 0) { if(sane < 0 && dec == 0) {
PRINTF('-'); PRINTF('-');
} }
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
#endif #endif
memcpy(rs + len, &rv, sizeof(rv)); memcpy(rs + len, &rv, sizeof(rv));
len += sizeof(rv); len += sizeof(rv);
@ -219,25 +219,25 @@ read_sensor(char * rs)
if(sane < 0 && dec == 0) { if(sane < 0 && dec == 0) {
PRINTF('-'); PRINTF('-');
} }
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
#endif #endif
memcpy(rs + len, &rv, sizeof(rv)); memcpy(rs + len, &rv, sizeof(rv));
len += sizeof(rv); len += sizeof(rv);
} }
} }
if (r & REQUEST_BIT_L1_SET) { if(r & REQUEST_BIT_L1_SET) {
leds_toggle(LEDS_GREEN); leds_toggle(LEDS_GREEN);
} }
if (r & REQUEST_BIT_L2_SET) { if(r & REQUEST_BIT_L2_SET) {
leds_toggle(LEDS_RED); leds_toggle(LEDS_RED);
} }
if (r & REQUEST_BIT_LED_GET) { if(r & REQUEST_BIT_LED_GET) {
uint8_t leds = leds_get(); uint8_t leds = leds_get();
memcpy(rs + len, &leds, sizeof(leds)); memcpy(rs + len, &leds, sizeof(leds));
len += sizeof(leds); len += sizeof(leds);
PRINTF(" LED 2=%u\n", leds); PRINTF(" LED 2=%u\n", leds);
} }
if (r & REQUEST_BIT_P0_GET) { if(r & REQUEST_BIT_P0_GET) {
uint8_t p0 = P0_3; uint8_t p0 = P0_3;
memcpy(rs + len, &p0, sizeof(p0)); memcpy(rs + len, &p0, sizeof(p0));
len += sizeof(p0); len += sizeof(p0);

View file

@ -79,7 +79,7 @@ static uint16_t len;
#define SENSOR_ADC_OFF 1 #define SENSOR_ADC_OFF 1
#define SENSOR_UNKNOWN 2 #define SENSOR_UNKNOWN 2
int8_t read_sensor(char * rs); int8_t read_sensor(char *rs);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
extern const struct sensors_sensor adc_sensor; extern const struct sensors_sensor adc_sensor;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -98,7 +98,7 @@ tcpip_handler(void)
PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport)); PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
len = read_sensor(buf); len = read_sensor(buf);
if( len ) { if(len) {
server_conn->rport = UIP_UDP_BUF->srcport; server_conn->rport = UIP_UDP_BUF->srcport;
uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr); uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
uip_udp_packet_send(server_conn, buf, len); uip_udp_packet_send(server_conn, buf, len);

View file

@ -110,7 +110,9 @@
#define SEND_BATTERY_INFO 0 #define SEND_BATTERY_INFO 0
#if SEND_BATTERY_INFO #if SEND_BATTERY_INFO
#include "sensors-example.h" #include "sensors-example.h"
static void bc_rx(struct broadcast_conn *c, const rimeaddr_t *from) { static void
bc_rx(struct broadcast_conn *c, const rimeaddr_t *from)
{
return; return;
} }
@ -138,7 +140,7 @@ PROCESS_THREAD(buttons_test_process, ev, data)
PROCESS_BEGIN(); PROCESS_BEGIN();
while (1) { while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event); PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);
@ -165,7 +167,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
/* Sensor Values */ /* Sensor Values */
static int rv; static int rv;
static struct sensors_sensor * sensor; static struct sensors_sensor *sensor;
static float sane = 0; static float sane = 0;
static int dec; static int dec;
static float frac; static float frac;
@ -187,7 +189,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
/* Set an etimer. We take sensor readings when it expires and reset it. */ /* Set an etimer. We take sensor readings when it expires and reset it. */
etimer_set(&et, CLOCK_SECOND * 2); etimer_set(&et, CLOCK_SECOND * 2);
while (1) { while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
@ -196,7 +198,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
* Return value -1 means sensor not available or turned off in conf * Return value -1 means sensor not available or turned off in conf
*/ */
sensor = sensors_find(ADC_SENSOR); sensor = sensors_find(ADC_SENSOR);
if (sensor) { if(sensor) {
putstring("------------------\n"); putstring("------------------\n");
leds_on(LEDS_RED); leds_on(LEDS_RED);
/* /*
@ -217,7 +219,8 @@ PROCESS_THREAD(sensors_test_process, ev, data)
sane = ((rv * 0.61065 - 773) / 2.45); sane = ((rv * 0.61065 - 773) / 2.45);
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF(" Temp=%d.%02u C (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF(" Temp=%d.%02u C (%d)\n", dec, (unsigned int)(frac * 100),
rv);
} }
/* /*
* Accelerometer: Freescale Semiconductor MMA7340L * Accelerometer: Freescale Semiconductor MMA7340L
@ -263,7 +266,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
if(sane < 0 && dec == 0) { if(sane < 0 && dec == 0) {
putchar('-'); putchar('-');
} }
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
} }
rv = sensor->value(ADC_SENSOR_TYPE_ACC_Y); rv = sensor->value(ADC_SENSOR_TYPE_ACC_Y);
if(rv != -1) { if(rv != -1) {
@ -275,7 +278,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
if(sane < 0 && dec == 0) { if(sane < 0 && dec == 0) {
putchar('-'); putchar('-');
} }
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
} }
rv = sensor->value(ADC_SENSOR_TYPE_ACC_Z); rv = sensor->value(ADC_SENSOR_TYPE_ACC_Z);
if(rv != -1) { if(rv != -1) {
@ -287,7 +290,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
if(sane < 0 && dec == 0) { if(sane < 0 && dec == 0) {
putchar('-'); putchar('-');
} }
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
} }
/* /*
* Light: Vishay Semiconductors TEPT4400 * Light: Vishay Semiconductors TEPT4400
@ -305,7 +308,8 @@ PROCESS_THREAD(sensors_test_process, ev, data)
sane = (float)(rv * 0.4071); sane = (float)(rv * 0.4071);
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF(" Light=%d.%02ulux (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF(" Light=%d.%02ulux (%d)\n", dec, (unsigned int)(frac * 100),
rv);
} }
/* /*
* Power Supply Voltage. * Power Supply Voltage.
@ -326,7 +330,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
sane = rv * 3.75 / 2047; sane = rv * 3.75 / 2047;
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF("Supply=%d.%02uV (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF("Supply=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv);
/* Store rv temporarily in dec so we can use it for the battery */ /* Store rv temporarily in dec so we can use it for the battery */
dec = rv; dec = rv;
} }
@ -356,7 +360,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
sane = (11.25 * rv * dec) / (0x7FE002); sane = (11.25 * rv * dec) / (0x7FE002);
dec = sane; dec = sane;
frac = sane - dec; frac = sane - dec;
PRINTF(" Batt.=%d.%02uV (%d)\n", dec, (unsigned int)(frac*100), rv); PRINTF(" Batt.=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv);
#if SEND_BATTERY_INFO #if SEND_BATTERY_INFO
sd.bat = rv; sd.bat = rv;
packetbuf_copyfrom(&sd, sizeof(sd)); packetbuf_copyfrom(&sd, sizeof(sd));
@ -368,5 +372,5 @@ PROCESS_THREAD(sensors_test_process, ev, data)
etimer_reset(&et); etimer_reset(&et);
} }
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -256,7 +256,7 @@ PROCESS_THREAD(serial_flash_process, ev, data)
while(M25P16_WIP()); while(M25P16_WIP());
/* Drop to Deep Power Down */ /* Drop to Deep Power Down */
m25p16_dp(); m25p16_dp();
counter ++; counter++;
} }
n740_analog_activate(); n740_analog_activate();
} }

View file

@ -47,4 +47,3 @@ netstack_init(void)
NETSTACK_RADIO.init(); NETSTACK_RADIO.init();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -48,7 +48,8 @@ AUTOSTART_PROCESSES(&clock_test_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if TEST_RTIMER #if TEST_RTIMER
void void
rt_callback(struct rtimer *t, void *ptr) { rt_callback(struct rtimer *t, void *ptr)
{
rt_now = RTIMER_NOW(); rt_now = RTIMER_NOW();
ct = clock_time(); ct = clock_time();
printf("Task called at %u (clock = %u)\n", rt_now, ct); printf("Task called at %u (clock = %u)\n", rt_now, ct);
@ -82,14 +83,14 @@ PROCESS_THREAD(clock_test_process, ev, data)
printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND); printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND);
i = 0; i = 0;
while(i < 5) { while(i < 5) {
etimer_set(&et, 2*CLOCK_SECOND); etimer_set(&et, 2 * CLOCK_SECOND);
printf("=======================\n"); printf("=======================\n");
ct = clock_time(); ct = clock_time();
rt_now = RTIMER_NOW(); rt_now = RTIMER_NOW();
rt_for = rt_now + RTIMER_SECOND; rt_for = rt_now + RTIMER_SECOND;
printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for); printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for);
if (rtimer_set(&rt, rt_for, 1, if(rtimer_set(&rt, rt_for, 1, (rtimer_callback_t) rt_callback, NULL) !=
(void (*)(struct rtimer *, void *))rt_callback, NULL) != RTIMER_OK) { RTIMER_OK) {
printf("Error setting\n"); printf("Error setting\n");
} }
@ -99,7 +100,8 @@ PROCESS_THREAD(clock_test_process, ev, data)
#endif #endif
#if TEST_ETIMER #if TEST_ETIMER
printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", CLOCK_SECOND); printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n",
CLOCK_SECOND);
i = 0; i = 0;
while(i < 10) { while(i < 10) {
etimer_set(&et, CLOCK_SECOND); etimer_set(&et, CLOCK_SECOND);

View file

@ -88,7 +88,7 @@ static void
timeout_handler(void) timeout_handler(void)
{ {
static int seq_id; static int seq_id;
struct uip_udp_conn * this_conn; struct uip_udp_conn *this_conn;
leds_on(LEDS_RED); leds_on(LEDS_RED);
memset(buf, 0, MAX_PAYLOAD_LEN); memset(buf, 0, MAX_PAYLOAD_LEN);
@ -133,7 +133,7 @@ print_local_addresses(void)
if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state
== ADDR_PREFERRED)) { == ADDR_PREFERRED)) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
if (state == ADDR_TENTATIVE) { if(state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
} }
PRINTF(" state: %u.\n", uip_ds6_if.addr_list[i].state); PRINTF(" state: %u.\n", uip_ds6_if.addr_list[i].state);
@ -168,7 +168,7 @@ PROCESS_THREAD(udp_client_process, ev, data)
print_local_addresses(); print_local_addresses();
uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x0215,0x2000,0x0002,0x0302); uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0x0215, 0x2000, 0x0002, 0x0302);
/* new connection with remote host */ /* new connection with remote host */
l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
if(!l_conn) { if(!l_conn) {
@ -182,7 +182,8 @@ PROCESS_THREAD(udp_client_process, ev, data)
UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport)); UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport));
#if UIP_CONF_ROUTER #if UIP_CONF_ROUTER
uip_ip6addr(&ipaddr,0x2001,0x630,0x301,0x6453,0x0215,0x2000,0x0002,0x0302); uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0x0215, 0x2000, 0x0002,
0x0302);
g_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); g_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
if(!g_conn) { if(!g_conn) {
PRINTF("udp_new g_conn error.\n"); PRINTF("udp_new g_conn error.\n");

View file

@ -103,14 +103,15 @@ PROCESS_THREAD(ping6_process, ev, data)
{ {
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) #if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
static struct sensors_sensor * btn; static struct sensors_sensor *btn;
#endif #endif
PROCESS_BEGIN(); PROCESS_BEGIN();
PRINTF("ping6 running.\n"); PRINTF("ping6 running.\n");
PRINTF("Button 1: 5 pings 16 byte payload.\n"); PRINTF("Button 1: 5 pings 16 byte payload.\n");
uip_ip6addr(&dest_addr,0x2001,0x470,0x55,0,0x0215,0x2000,0x0002,0x0302); uip_ip6addr(&dest_addr, 0x2001, 0x470, 0x55, 0, 0x0215, 0x2000, 0x0002,
0x0302);
count = 0; count = 0;
/* Check if we have buttons */ /* Check if we have buttons */

View file

@ -104,9 +104,10 @@ static void
print_stats() print_stats()
{ {
PRINTF("tl=%lu, ts=%lu, bs=%lu, bc=%lu\n", PRINTF("tl=%lu, ts=%lu, bs=%lu, bc=%lu\n",
rimestats.toolong, rimestats.tooshort, rimestats.badsynch, rimestats.badcrc); rimestats.toolong, rimestats.tooshort, rimestats.badsynch,
PRINTF("llrx=%lu, lltx=%lu, rx=%lu, tx=%lu\n", rimestats.badcrc);
rimestats.llrx, rimestats.lltx, rimestats.rx, rimestats.tx); PRINTF("llrx=%lu, lltx=%lu, rx=%lu, tx=%lu\n", rimestats.llrx,
rimestats.lltx, rimestats.rx, rimestats.tx);
} }
#else #else
#define print_stats() #define print_stats()
@ -126,7 +127,7 @@ print_local_addresses(void)
PRINTF(" "); PRINTF(" ");
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n"); PRINTF("\n");
if (state == ADDR_TENTATIVE) { if(state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
} }
} }
@ -145,7 +146,8 @@ create_dag()
print_local_addresses(); print_local_addresses();
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &uip_ds6_get_global(ADDR_PREFERRED)->ipaddr); dag = rpl_set_root(RPL_DEFAULT_INSTANCE,
&uip_ds6_get_global(ADDR_PREFERRED)->ipaddr);
if(dag != NULL) { if(dag != NULL) {
uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64); rpl_set_prefix(dag, &ipaddr, 64);