Code style fixes: sensinode examples
This commit is contained in:
parent
594ba9a0ed
commit
64a95dcb59
19 changed files with 205 additions and 251 deletions
|
@ -10,82 +10,53 @@
|
|||
#include "contiki.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(blink_process, "LED blink process");
|
||||
|
||||
/* We require the processes to be started automatically */
|
||||
AUTOSTART_PROCESSES(&hello_world_process, &blink_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Implementation of the first process */
|
||||
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 int count;
|
||||
|
||||
/* any process must start with this. */
|
||||
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);
|
||||
count = 0;
|
||||
/* Don't declare variables after PROCESS_BEGIN.
|
||||
* While it will compile fine with TARGET=native (gcc is happy),
|
||||
* 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();
|
||||
/* This achieves the same
|
||||
* PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); */
|
||||
static struct etimer timer;
|
||||
static int count;
|
||||
|
||||
/* if the event is the timer event as expected... */
|
||||
if(ev == PROCESS_EVENT_TIMER)
|
||||
{
|
||||
/* do the process work */
|
||||
printf("Sensor says no... #%d\r\n", count);
|
||||
count ++;
|
||||
|
||||
/* reset the timer so it will generate an other event
|
||||
* the exact same time after it expired (periodicity guaranteed) */
|
||||
etimer_reset(&timer);
|
||||
}
|
||||
|
||||
/* and loop */
|
||||
PROCESS_BEGIN();
|
||||
|
||||
etimer_set(&timer, CLOCK_CONF_SECOND * 4);
|
||||
count = 0;
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == PROCESS_EVENT_TIMER) {
|
||||
printf("Sensor says no... #%d\r\n", count);
|
||||
count++;
|
||||
|
||||
etimer_reset(&timer);
|
||||
}
|
||||
/* any process must end with this, even if it is never reached. */
|
||||
PROCESS_END();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Implementation of the second process */
|
||||
PROCESS_THREAD(blink_process, ev, data)
|
||||
{
|
||||
static struct etimer timer;
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* we set the timer from here every time */
|
||||
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);
|
||||
|
||||
printf("Blink... (state %0.2X).\r\n", leds_get());
|
||||
/* update the LEDs */
|
||||
leds_toggle(LEDS_GREEN);
|
||||
}
|
||||
PROCESS_END();
|
||||
static struct etimer timer;
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
etimer_set(&timer, CLOCK_CONF_SECOND);
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
|
||||
|
||||
printf("Blink... (state %0.2X).\r\n", leds_get());
|
||||
leds_toggle(LEDS_GREEN);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -71,11 +71,11 @@ print_local_addresses(void) CC_NON_BANKED
|
|||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state
|
||||
== ADDR_PREFERRED)) {
|
||||
== ADDR_PREFERRED)) {
|
||||
PUTSTRING(" ");
|
||||
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PUTCHAR('\n');
|
||||
if (state == ADDR_TENTATIVE) {
|
||||
if(state == ADDR_TENTATIVE) {
|
||||
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ static void
|
|||
slip_input_callback(void)
|
||||
{
|
||||
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]);
|
||||
uip_len = 0;
|
||||
if((char)uip_buf[1] == 'P') {
|
||||
|
|
|
@ -58,21 +58,25 @@
|
|||
PROCESS(example_broadcast_process, "BROADCAST example");
|
||||
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);
|
||||
PRINTF("broadcast message received from %02x.%02x\n", from->u8[0], from->u8[1]);
|
||||
PRINTF("Size=0x%02x: '0x%04x'\n", packetbuf_datalen(), *(uint16_t *) packetbuf_dataptr());
|
||||
PRINTF("broadcast message received from %02x.%02x\n", from->u8[0],
|
||||
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(" TX=%lu , RX=%lu\n", rimestats.tx, rimestats.rx);
|
||||
PRINTF("LL-TX=%lu , LL-RX=%lu\n", rimestats.lltx, rimestats.llrx);
|
||||
PRINTF(" Long=%lu , Short=%lu\n", rimestats.toolong, rimestats.tooshort);
|
||||
PRINTF("T/Out=%lu , CCA-Err=%lu\n", rimestats.timedout,
|
||||
rimestats.contentiondrop);
|
||||
rimestats.contentiondrop);
|
||||
}
|
||||
|
||||
static const struct broadcast_callbacks bc_rx = { broadcast_recv };
|
||||
|
@ -90,7 +94,7 @@ PROCESS_THREAD(example_broadcast_process, ev, data)
|
|||
PRINTF("Start\n");
|
||||
broadcast_open(&broadcast, BROADCAST_CHANNEL, &bc_rx);
|
||||
PRINTF("Open Broadcast Connection, channel %u\n", BROADCAST_CHANNEL);
|
||||
// leds_off(LEDS_ALL);
|
||||
|
||||
while(1) {
|
||||
|
||||
/* Delay 2-4 seconds */
|
||||
|
@ -98,8 +102,9 @@ PROCESS_THREAD(example_broadcast_process, ev, data)
|
|||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
leds_on(LEDS_GREEN);
|
||||
packetbuf_copyfrom(&counter, sizeof(counter));
|
||||
PRINTF("Sending %u bytes: 0x%04x\n", packetbuf_datalen(), *(uint16_t *) packetbuf_dataptr());
|
||||
if (broadcast_send(&broadcast) == 0) {
|
||||
PRINTF("Sending %u bytes: 0x%04x\n", packetbuf_datalen(),
|
||||
*(uint16_t *)packetbuf_dataptr());
|
||||
if(broadcast_send(&broadcast) == 0) {
|
||||
PRINTF("Error Sending\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,8 @@ broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
|
|||
/* Convert RSSI to the loc. eng. format */
|
||||
parameters.rssi[from->u8[1] - 1] = (-2 * rssi);
|
||||
/* 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;
|
||||
|
@ -194,7 +195,8 @@ broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
|
|||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_imaginary_ref_nodes() {
|
||||
set_imaginary_ref_nodes()
|
||||
{
|
||||
ref_coords[0].x = 1;
|
||||
ref_coords[0].y = 5;
|
||||
parameters.rssi[0] = SAMPLE_RSSI;
|
||||
|
@ -243,11 +245,11 @@ PROCESS_THREAD(blindnode_bcast_rec, ev, data)
|
|||
* Just hard-coding measurement parameters here.
|
||||
* Ideally, this should be part of a calibration mechanism
|
||||
*/
|
||||
parameters.alpha=SAMPLE_ALPHA;
|
||||
parameters.x_min=0;
|
||||
parameters.x_delta=255;
|
||||
parameters.y_min=0;
|
||||
parameters.y_delta=255;
|
||||
parameters.alpha = SAMPLE_ALPHA;
|
||||
parameters.x_min = 0;
|
||||
parameters.x_delta = 255;
|
||||
parameters.y_min = 0;
|
||||
parameters.y_delta = 255;
|
||||
|
||||
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
|
||||
* for all possible values of n [0 , 31]
|
||||
*/
|
||||
parameters.n=n;
|
||||
parameters.n = n;
|
||||
calculate();
|
||||
n++;
|
||||
if(n==32) { n=0; }
|
||||
if(n == 32) {
|
||||
n = 0;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
PROCESS_END();
|
||||
|
|
|
@ -47,4 +47,3 @@ netstack_init(void)
|
|||
NETSTACK_RADIO.init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
|
|
@ -88,13 +88,13 @@ init(void)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const struct rdc_driver stub_rdc_driver = {
|
||||
"stub-rdc",
|
||||
init,
|
||||
send,
|
||||
send_list,
|
||||
input,
|
||||
on,
|
||||
off,
|
||||
cca,
|
||||
"stub-rdc",
|
||||
init,
|
||||
send,
|
||||
send_list,
|
||||
input,
|
||||
on,
|
||||
off,
|
||||
cca,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -14,119 +14,85 @@
|
|||
#include "contiki.h"
|
||||
//#include "dev/leds.h"
|
||||
#include <limits.h>
|
||||
#include <stdio.h> /* For printf() */
|
||||
#include <stdio.h>
|
||||
#include "event-post.h"
|
||||
|
||||
/* This is our event type */
|
||||
static process_event_t event_data_ready;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Declare the two processes here */
|
||||
PROCESS(sensor_process, "Sensor process");
|
||||
PROCESS(print_process, "Print process");
|
||||
|
||||
/* Tell Contiki that we want them to start automatically */
|
||||
AUTOSTART_PROCESSES(&sensor_process, &print_process);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Implementation "Sensor Process" */
|
||||
PROCESS_THREAD(sensor_process, ev, data)
|
||||
{
|
||||
/* static variables to preserve values across consecutive calls of this
|
||||
* process. */
|
||||
/* Set an etimer */
|
||||
static struct etimer timer;
|
||||
/* And the 'sensor' monitoring variable */
|
||||
static struct event_struct es;
|
||||
static struct etimer timer;
|
||||
static struct event_struct es;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Set some near-the-limit initial values */
|
||||
/* signed primitives */
|
||||
es.s_val = SHRT_MAX-2;
|
||||
es.i_val = INT_MAX-2;
|
||||
es.l_val = LONG_MAX-2;
|
||||
/* sizeof(long long) == sizeof(long) on sensinodes - see other examples*/
|
||||
es.ll_val = LONG_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;
|
||||
es.s_val = SHRT_MAX - 2;
|
||||
es.i_val = INT_MAX - 2;
|
||||
es.l_val = LONG_MAX - 2;
|
||||
es.ll_val = LONG_MAX - 2;
|
||||
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();
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("Sensor process: Wait for timer event...\r\n");
|
||||
/* Wait on our timer */
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
|
||||
event_data_ready = process_alloc_event();
|
||||
|
||||
/* blip */
|
||||
/* leds_toggle(LEDS_BLUE); */
|
||||
printf("Contiki allocated event ID %d.\r\n", event_data_ready);
|
||||
|
||||
/* Set the 'sensor' value before throwing the event */
|
||||
printf("Sensor Process: Incrementing values...\r\n");
|
||||
es.s_val++;
|
||||
es.i_val++;
|
||||
es.l_val++;
|
||||
es.ll_val++;
|
||||
es.u8_val++;
|
||||
es.u16_val++;
|
||||
es.u32_val++;
|
||||
etimer_set(&timer, CLOCK_CONF_SECOND * 2);
|
||||
|
||||
/* 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");
|
||||
process_post(&print_process, event_data_ready, &es);
|
||||
while(1) {
|
||||
printf("Sensor process: Wait for timer event...\r\n");
|
||||
|
||||
/* reset the timer so we can wait on it again */
|
||||
etimer_reset(&timer);
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
printf("Sensor Process: Incrementing values...\r\n");
|
||||
es.s_val++;
|
||||
es.i_val++;
|
||||
es.l_val++;
|
||||
es.ll_val++;
|
||||
es.u8_val++;
|
||||
es.u16_val++;
|
||||
es.u32_val++;
|
||||
|
||||
printf("Sensor Process: Generating 'Data Ready' event.\r\n");
|
||||
process_post(&print_process, event_data_ready, &es);
|
||||
|
||||
etimer_reset(&timer);
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Implementation of "Print Process" */
|
||||
PROCESS_THREAD(print_process, ev, data)
|
||||
{
|
||||
|
||||
struct event_struct * sd;
|
||||
struct event_struct *sd;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Stop here and wait until "event_data_ready" occurs */
|
||||
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;
|
||||
printf("Print Process - Data Ready:\r\n");
|
||||
printf(" s: %d\r\n", sd->s_val);
|
||||
printf(" i: %d\r\n", sd->i_val);
|
||||
printf(" l: %ld\r\n", sd->l_val);
|
||||
printf(" ll: %lld\r\n", sd->ll_val);
|
||||
printf(" u8: %u\r\n", sd->u8_val);
|
||||
printf(" u16: %u\r\n", sd->u16_val);
|
||||
printf(" u32: %lu\r\n", sd->u32_val);
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* aaaaand back to waiting for the next event */
|
||||
}
|
||||
PROCESS_END();
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == event_data_ready);
|
||||
|
||||
sd = data;
|
||||
printf("Print Process - Data Ready:\r\n");
|
||||
printf(" s: %d\r\n", sd->s_val);
|
||||
printf(" i: %d\r\n", sd->i_val);
|
||||
printf(" l: %ld\r\n", sd->l_val);
|
||||
printf(" ll: %lld\r\n", sd->ll_val);
|
||||
printf(" u8: %u\r\n", sd->u8_val);
|
||||
printf(" u16: %u\r\n", sd->u16_val);
|
||||
printf(" u32: %lu\r\n", sd->u32_val);
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
#define EVENT_POST_H_
|
||||
|
||||
struct event_struct {
|
||||
short s_val;
|
||||
int i_val;
|
||||
long l_val;
|
||||
short s_val;
|
||||
int i_val;
|
||||
long l_val;
|
||||
long long ll_val;
|
||||
uint8_t u8_val;
|
||||
uint8_t u8_val;
|
||||
uint16_t u16_val;
|
||||
uint32_t u32_val;
|
||||
};
|
||||
|
|
|
@ -77,11 +77,11 @@
|
|||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int8_t
|
||||
read_sensor(char * rs)
|
||||
read_sensor(char *rs)
|
||||
{
|
||||
/* Sensor Values */
|
||||
static int rv;
|
||||
static struct sensors_sensor * sensor;
|
||||
static struct sensors_sensor *sensor;
|
||||
|
||||
/* Those 3 variables are only used for debugging */
|
||||
#if DEBUG
|
||||
|
@ -93,7 +93,7 @@ read_sensor(char * rs)
|
|||
uint8_t len = 0;
|
||||
|
||||
sensor = sensors_find(ADC_SENSOR);
|
||||
if (!sensor) {
|
||||
if(!sensor) {
|
||||
PRINTF("ADC not found\n");
|
||||
return (SENSOR_ADC_OFF);
|
||||
}
|
||||
|
@ -103,13 +103,13 @@ read_sensor(char * rs)
|
|||
r = uip_ntohs(r);
|
||||
PRINTF("R=%u\n", r);
|
||||
|
||||
if (r & REQUEST_BIT_CHIPID) {
|
||||
if(r & REQUEST_BIT_CHIPID) {
|
||||
uint8_t chipid = CHIPID;
|
||||
memcpy(rs + len, &chipid, sizeof(chipid));
|
||||
len += sizeof(chipid);
|
||||
PRINTF("ChipID=0x%02x\n", chipid);
|
||||
}
|
||||
if (r & REQUEST_BIT_UPTIME) {
|
||||
if(r & REQUEST_BIT_UPTIME) {
|
||||
/* Uptime */
|
||||
unsigned long l;
|
||||
|
||||
|
@ -118,33 +118,33 @@ read_sensor(char * rs)
|
|||
len += sizeof(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);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = (float)(rv * 0.4071);
|
||||
dec = sane;
|
||||
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
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
}
|
||||
if (r & REQUEST_BIT_TEMP) {
|
||||
if(r & REQUEST_BIT_TEMP) {
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_TEMP);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = ((rv * 0.61065 - 773) / 2.45);
|
||||
dec = sane;
|
||||
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
|
||||
memcpy(rs + len, &rv, 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 */
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_VDD);
|
||||
if(rv != -1) {
|
||||
|
@ -152,7 +152,7 @@ read_sensor(char * rs)
|
|||
sane = rv * 3.75 / 2047;
|
||||
dec = sane;
|
||||
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 */
|
||||
dec = rv;
|
||||
#endif
|
||||
|
@ -160,21 +160,21 @@ read_sensor(char * rs)
|
|||
len += sizeof(rv);
|
||||
}
|
||||
/* 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);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = (11.25 * rv * dec) / (0x7FE002);
|
||||
dec = sane;
|
||||
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
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r & REQUEST_BIT_ACC) {
|
||||
if(r & REQUEST_BIT_ACC) {
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_ACC_X);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
|
@ -187,7 +187,7 @@ read_sensor(char * rs)
|
|||
if(sane < 0 && dec == 0) {
|
||||
PRINTF('-');
|
||||
}
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv);
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
|
@ -203,7 +203,7 @@ read_sensor(char * rs)
|
|||
if(sane < 0 && dec == 0) {
|
||||
PRINTF('-');
|
||||
}
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv);
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
|
@ -219,25 +219,25 @@ read_sensor(char * rs)
|
|||
if(sane < 0 && dec == 0) {
|
||||
PRINTF('-');
|
||||
}
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv);
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
}
|
||||
if (r & REQUEST_BIT_L1_SET) {
|
||||
if(r & REQUEST_BIT_L1_SET) {
|
||||
leds_toggle(LEDS_GREEN);
|
||||
}
|
||||
if (r & REQUEST_BIT_L2_SET) {
|
||||
if(r & REQUEST_BIT_L2_SET) {
|
||||
leds_toggle(LEDS_RED);
|
||||
}
|
||||
if (r & REQUEST_BIT_LED_GET) {
|
||||
if(r & REQUEST_BIT_LED_GET) {
|
||||
uint8_t leds = leds_get();
|
||||
memcpy(rs + len, &leds, sizeof(leds));
|
||||
len += sizeof(leds);
|
||||
PRINTF(" LED 2=%u\n", leds);
|
||||
}
|
||||
if (r & REQUEST_BIT_P0_GET) {
|
||||
if(r & REQUEST_BIT_P0_GET) {
|
||||
uint8_t p0 = P0_3;
|
||||
memcpy(rs + len, &p0, sizeof(p0));
|
||||
len += sizeof(p0);
|
||||
|
|
|
@ -79,7 +79,7 @@ static uint16_t len;
|
|||
#define SENSOR_ADC_OFF 1
|
||||
#define SENSOR_UNKNOWN 2
|
||||
|
||||
int8_t read_sensor(char * rs);
|
||||
int8_t read_sensor(char *rs);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor adc_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -98,7 +98,7 @@ tcpip_handler(void)
|
|||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
|
||||
len = read_sensor(buf);
|
||||
if( len ) {
|
||||
if(len) {
|
||||
server_conn->rport = UIP_UDP_BUF->srcport;
|
||||
uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
|
||||
uip_udp_packet_send(server_conn, buf, len);
|
||||
|
|
|
@ -110,7 +110,9 @@
|
|||
#define SEND_BATTERY_INFO 0
|
||||
#if SEND_BATTERY_INFO
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -138,7 +140,7 @@ PROCESS_THREAD(buttons_test_process, ev, data)
|
|||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while (1) {
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);
|
||||
|
||||
|
@ -165,7 +167,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
|
||||
/* Sensor Values */
|
||||
static int rv;
|
||||
static struct sensors_sensor * sensor;
|
||||
static struct sensors_sensor *sensor;
|
||||
static float sane = 0;
|
||||
static int dec;
|
||||
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. */
|
||||
etimer_set(&et, CLOCK_SECOND * 2);
|
||||
|
||||
while (1) {
|
||||
while(1) {
|
||||
|
||||
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
|
||||
*/
|
||||
sensor = sensors_find(ADC_SENSOR);
|
||||
if (sensor) {
|
||||
if(sensor) {
|
||||
putstring("------------------\n");
|
||||
leds_on(LEDS_RED);
|
||||
/*
|
||||
|
@ -217,7 +219,8 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
sane = ((rv * 0.61065 - 773) / 2.45);
|
||||
dec = sane;
|
||||
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
|
||||
|
@ -263,7 +266,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
if(sane < 0 && dec == 0) {
|
||||
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);
|
||||
if(rv != -1) {
|
||||
|
@ -275,7 +278,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
if(sane < 0 && dec == 0) {
|
||||
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);
|
||||
if(rv != -1) {
|
||||
|
@ -287,7 +290,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
if(sane < 0 && dec == 0) {
|
||||
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
|
||||
|
@ -305,7 +308,8 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
sane = (float)(rv * 0.4071);
|
||||
dec = sane;
|
||||
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.
|
||||
|
@ -326,7 +330,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
sane = rv * 3.75 / 2047;
|
||||
dec = sane;
|
||||
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 */
|
||||
dec = rv;
|
||||
}
|
||||
|
@ -356,7 +360,7 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
sane = (11.25 * rv * dec) / (0x7FE002);
|
||||
dec = sane;
|
||||
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
|
||||
sd.bat = rv;
|
||||
packetbuf_copyfrom(&sd, sizeof(sd));
|
||||
|
@ -368,5 +372,5 @@ PROCESS_THREAD(sensors_test_process, ev, data)
|
|||
etimer_reset(&et);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -256,7 +256,7 @@ PROCESS_THREAD(serial_flash_process, ev, data)
|
|||
while(M25P16_WIP());
|
||||
/* Drop to Deep Power Down */
|
||||
m25p16_dp();
|
||||
counter ++;
|
||||
counter++;
|
||||
}
|
||||
n740_analog_activate();
|
||||
}
|
||||
|
|
|
@ -47,4 +47,3 @@ netstack_init(void)
|
|||
NETSTACK_RADIO.init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
|
|
@ -88,13 +88,13 @@ init(void)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const struct rdc_driver stub_rdc_driver = {
|
||||
"stub-rdc",
|
||||
init,
|
||||
send,
|
||||
send_list,
|
||||
input,
|
||||
on,
|
||||
off,
|
||||
cca,
|
||||
"stub-rdc",
|
||||
init,
|
||||
send,
|
||||
send_list,
|
||||
input,
|
||||
on,
|
||||
off,
|
||||
cca,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -48,7 +48,8 @@ AUTOSTART_PROCESSES(&clock_test_process);
|
|||
/*---------------------------------------------------------------------------*/
|
||||
#if TEST_RTIMER
|
||||
void
|
||||
rt_callback(struct rtimer *t, void *ptr) {
|
||||
rt_callback(struct rtimer *t, void *ptr)
|
||||
{
|
||||
rt_now = RTIMER_NOW();
|
||||
ct = clock_time();
|
||||
printf("Task called at %u (clock = %u)\n", rt_now, ct);
|
||||
|
@ -73,7 +74,7 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
end_count = RTIMER_NOW();
|
||||
diff = end_count - start_count;
|
||||
printf("Requested: %u usec, Real: %u rtimer ticks = ~%u us\n",
|
||||
10000 * i, diff, diff * 64);
|
||||
10000 * i, diff, diff * 64);
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
|
@ -82,14 +83,14 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND);
|
||||
i = 0;
|
||||
while(i < 5) {
|
||||
etimer_set(&et, 2*CLOCK_SECOND);
|
||||
etimer_set(&et, 2 * CLOCK_SECOND);
|
||||
printf("=======================\n");
|
||||
ct = clock_time();
|
||||
rt_now = RTIMER_NOW();
|
||||
rt_for = rt_now + RTIMER_SECOND;
|
||||
printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for);
|
||||
if (rtimer_set(&rt, rt_for, 1,
|
||||
(void (*)(struct rtimer *, void *))rt_callback, NULL) != RTIMER_OK) {
|
||||
if(rtimer_set(&rt, rt_for, 1, (rtimer_callback_t) rt_callback, NULL) !=
|
||||
RTIMER_OK) {
|
||||
printf("Error setting\n");
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,8 @@ PROCESS_THREAD(clock_test_process, ev, data)
|
|||
#endif
|
||||
|
||||
#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;
|
||||
while(i < 10) {
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
|
|
|
@ -88,7 +88,7 @@ static void
|
|||
timeout_handler(void)
|
||||
{
|
||||
static int seq_id;
|
||||
struct uip_udp_conn * this_conn;
|
||||
struct uip_udp_conn *this_conn;
|
||||
|
||||
leds_on(LEDS_RED);
|
||||
memset(buf, 0, MAX_PAYLOAD_LEN);
|
||||
|
@ -131,9 +131,9 @@ print_local_addresses(void)
|
|||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].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);
|
||||
if (state == ADDR_TENTATIVE) {
|
||||
if(state == ADDR_TENTATIVE) {
|
||||
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
|
||||
}
|
||||
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();
|
||||
|
||||
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 */
|
||||
l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
|
||||
if(!l_conn) {
|
||||
|
@ -179,10 +179,11 @@ PROCESS_THREAD(udp_client_process, ev, data)
|
|||
PRINTF("Link-Local connection with ");
|
||||
PRINT6ADDR(&l_conn->ripaddr);
|
||||
PRINTF(" local/remote port %u/%u\n",
|
||||
UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport));
|
||||
UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport));
|
||||
|
||||
#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);
|
||||
if(!g_conn) {
|
||||
PRINTF("udp_new g_conn error.\n");
|
||||
|
@ -192,7 +193,7 @@ PROCESS_THREAD(udp_client_process, ev, data)
|
|||
PRINTF("Global connection with ");
|
||||
PRINT6ADDR(&g_conn->ripaddr);
|
||||
PRINTF(" local/remote port %u/%u\n",
|
||||
UIP_HTONS(g_conn->lport), UIP_HTONS(g_conn->rport));
|
||||
UIP_HTONS(g_conn->lport), UIP_HTONS(g_conn->rport));
|
||||
#endif
|
||||
|
||||
etimer_set(&et, SEND_INTERVAL);
|
||||
|
|
|
@ -101,18 +101,19 @@ ping6handler()
|
|||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(ping6_process, ev, data)
|
||||
{
|
||||
|
||||
|
||||
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
|
||||
static struct sensors_sensor * btn;
|
||||
static struct sensors_sensor *btn;
|
||||
#endif
|
||||
|
||||
PROCESS_BEGIN();
|
||||
PRINTF("ping6 running.\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;
|
||||
|
||||
|
||||
/* Check if we have buttons */
|
||||
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
|
||||
btn = sensors_find(BUTTON_1_SENSOR);
|
||||
|
@ -132,7 +133,7 @@ PROCESS_THREAD(ping6_process, ev, data)
|
|||
ping6handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -104,9 +104,10 @@ static void
|
|||
print_stats()
|
||||
{
|
||||
PRINTF("tl=%lu, ts=%lu, bs=%lu, bc=%lu\n",
|
||||
rimestats.toolong, rimestats.tooshort, rimestats.badsynch, rimestats.badcrc);
|
||||
PRINTF("llrx=%lu, lltx=%lu, rx=%lu, tx=%lu\n",
|
||||
rimestats.llrx, rimestats.lltx, rimestats.rx, rimestats.tx);
|
||||
rimestats.toolong, rimestats.tooshort, rimestats.badsynch,
|
||||
rimestats.badcrc);
|
||||
PRINTF("llrx=%lu, lltx=%lu, rx=%lu, tx=%lu\n", rimestats.llrx,
|
||||
rimestats.lltx, rimestats.rx, rimestats.tx);
|
||||
}
|
||||
#else
|
||||
#define print_stats()
|
||||
|
@ -122,11 +123,11 @@ print_local_addresses(void)
|
|||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state
|
||||
== ADDR_PREFERRED)) {
|
||||
== ADDR_PREFERRED)) {
|
||||
PRINTF(" ");
|
||||
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTF("\n");
|
||||
if (state == ADDR_TENTATIVE) {
|
||||
if(state == ADDR_TENTATIVE) {
|
||||
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +146,8 @@ create_dag()
|
|||
|
||||
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) {
|
||||
uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0);
|
||||
rpl_set_prefix(dag, &ipaddr, 64);
|
||||
|
|
Loading…
Reference in a new issue