Reincarnate the sensinode/cc2430 port
This commit is contained in:
parent
c78b5bad5c
commit
b7674c3636
114 changed files with 10044 additions and 3068 deletions
19
examples/sensinode/sensors-ipv6/Makefile
Normal file
19
examples/sensinode/sensors-ipv6/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
ifndef TARGET
|
||||
TARGET=sensinode
|
||||
endif
|
||||
|
||||
# Make absolutely certain that you specify your device here
|
||||
DEFINES+=MODEL_N740,PROJECT_CONF_H
|
||||
|
||||
# This example won't fit in flash without banking so we turn it on
|
||||
HAVE_BANKING=1
|
||||
UIP_CONF_IPV6=1
|
||||
|
||||
CONTIKI_SOURCEFILES += sensors-driver.c
|
||||
|
||||
CONTIKI_PROJECT = sensors-ipv6
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../../..
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
51
examples/sensinode/sensors-ipv6/project-conf.h
Normal file
51
examples/sensinode/sensors-ipv6/project-conf.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Loughborough University - Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Project specific configuration defines for the UDP client/server
|
||||
* example.
|
||||
*
|
||||
* We make sure that buttons and ADC are on. We also demonstrate the
|
||||
* new LPM functionality
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
|
||||
#define BUTTON_SENSOR_CONF_ON 1
|
||||
#define ADC_SENSOR_CONF_ON 1
|
||||
#define LPM_CONF_MODE 1
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
246
examples/sensinode/sensors-ipv6/sensors-driver.c
Normal file
246
examples/sensinode/sensors-ipv6/sensors-driver.c
Normal file
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Loughborough University - Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* This file handles the sensor readings and float conversions
|
||||
* for sensors-example. We keep this separate in order to place it
|
||||
* to a higher BANK.
|
||||
*
|
||||
* Bankable
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "uip.h" /* for htons / htonl */
|
||||
#include "dev/leds.h"
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#include "sensinode-debug.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define SENSOR_OK 0
|
||||
#define SENSOR_ADC_OFF -1
|
||||
#define SENSOR_UNKNOWN -2
|
||||
|
||||
/* Request Bits */
|
||||
#define REQUEST_BIT_P0_GET 0x0400
|
||||
#define REQUEST_BIT_L2_SET 0x0200
|
||||
#define REQUEST_BIT_L1_SET 0x0100
|
||||
#define REQUEST_BIT_LED_GET 0x0080
|
||||
#define REQUEST_BIT_ACC 0x0040
|
||||
#define REQUEST_BIT_BAT 0x0020
|
||||
#define REQUEST_BIT_VDD 0x0010
|
||||
#define REQUEST_BIT_TEMP 0x0008
|
||||
#define REQUEST_BIT_LIGHT 0x0004
|
||||
#define REQUEST_BIT_UPTIME 0x0002
|
||||
#define REQUEST_BIT_CHIPID 0x0001
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int8_t
|
||||
read_sensor(char * rs)
|
||||
{
|
||||
/* Sensor Values */
|
||||
static int rv;
|
||||
static struct sensors_sensor * sensor;
|
||||
|
||||
/* Those 3 variables are only used for debugging */
|
||||
#if DEBUG
|
||||
static float sane = 0;
|
||||
static int dec;
|
||||
static float frac;
|
||||
#endif
|
||||
uint16_t r;
|
||||
uint8_t len = 0;
|
||||
|
||||
sensor = sensors_find(ADC_SENSOR);
|
||||
if (!sensor) {
|
||||
PRINTF("ADC not found\n");
|
||||
return (SENSOR_ADC_OFF);
|
||||
}
|
||||
|
||||
/* Fetch the request bytes */
|
||||
memcpy(&r, rs, 2);
|
||||
r = uip_ntohs(r);
|
||||
PRINTF("R=%u\n", r);
|
||||
|
||||
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) {
|
||||
/* Uptime */
|
||||
unsigned long l;
|
||||
|
||||
l = uip_htonl(clock_seconds());
|
||||
memcpy(rs + len, &l, sizeof(l));
|
||||
len += sizeof(l);
|
||||
PRINTF("Uptime=%lu secs\n", uip_ntohl(l));
|
||||
}
|
||||
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);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
}
|
||||
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);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
}
|
||||
if (r & (REQUEST_BIT_VDD | REQUEST_BIT_BAT)) {
|
||||
/* We want VDD for both cases */
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_VDD);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = rv * 3.75 / 2047;
|
||||
dec = sane;
|
||||
frac = sane - dec;
|
||||
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
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
/* And then carry on with battery if needed */
|
||||
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);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r & REQUEST_BIT_ACC) {
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_ACC_X);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = ((rv * 3.75 / 2047) - 1.65) / 0.44;
|
||||
dec = sane;
|
||||
frac = sane - dec;
|
||||
frac = (frac < 0) ? -frac : frac;
|
||||
|
||||
PRINTF(" AccX=");
|
||||
if(sane < 0 && dec == 0) {
|
||||
PRINTF('-');
|
||||
}
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_ACC_Y);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = ((rv * 3.75 / 2047) - 1.65) / 0.44;
|
||||
dec = sane;
|
||||
frac = sane - dec;
|
||||
frac = (frac < 0) ? -frac : frac;
|
||||
PRINTF(" AccY=");
|
||||
if(sane < 0 && dec == 0) {
|
||||
PRINTF('-');
|
||||
}
|
||||
PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac*100), rv);
|
||||
#endif
|
||||
memcpy(rs + len, &rv, sizeof(rv));
|
||||
len += sizeof(rv);
|
||||
}
|
||||
rv = sensor->value(ADC_SENSOR_TYPE_ACC_Z);
|
||||
if(rv != -1) {
|
||||
#if DEBUG
|
||||
sane = ((rv * 3.75 / 2047) - 1.65) / 0.44;
|
||||
dec = sane;
|
||||
frac = sane - dec;
|
||||
frac = (frac < 0) ? -frac : frac;
|
||||
PRINTF(" AccZ=");
|
||||
if(sane < 0 && dec == 0) {
|
||||
PRINTF('-');
|
||||
}
|
||||
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) {
|
||||
leds_toggle(LEDS_GREEN);
|
||||
}
|
||||
if (r & REQUEST_BIT_L2_SET) {
|
||||
leds_toggle(LEDS_RED);
|
||||
}
|
||||
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) {
|
||||
uint8_t p0 = P0_3;
|
||||
memcpy(rs + len, &p0, sizeof(p0));
|
||||
len += sizeof(p0);
|
||||
}
|
||||
return len;
|
||||
}
|
154
examples/sensinode/sensors-ipv6/sensors-ipv6.c
Normal file
154
examples/sensinode/sensors-ipv6/sensors-ipv6.c
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Loughborough University - Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Example to demonstrate-test the sensors functionality on
|
||||
* sensinode/cc2430 devices.
|
||||
*
|
||||
* A UDP/IPv6 process waits for requests from a monitoring station
|
||||
* and responds with sensor values.
|
||||
*
|
||||
* The message exchange is based on a custom protocol.
|
||||
* Check sensors-driver.c for protocol details.
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/leds.h"
|
||||
#include "net/rpl/rpl.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if CONTIKI_TARGET_SENSINODE
|
||||
#include "sensinode-debug.h"
|
||||
#include "dev/sensinode-sensors.h"
|
||||
#else
|
||||
#define putstring(s)
|
||||
#endif
|
||||
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
|
||||
#define MAX_PAYLOAD_LEN 120
|
||||
|
||||
static struct uip_udp_conn *server_conn;
|
||||
static char buf[MAX_PAYLOAD_LEN];
|
||||
static uint16_t len;
|
||||
|
||||
#define SERVER_PORT 60000
|
||||
|
||||
#define SENSOR_OK 0
|
||||
#define SENSOR_ADC_OFF 1
|
||||
#define SENSOR_UNKNOWN 2
|
||||
|
||||
int8_t read_sensor(char * rs);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor adc_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(udp_server_process, "UDP server process");
|
||||
AUTOSTART_PROCESSES(&udp_server_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tcpip_handler(void)
|
||||
{
|
||||
memset(buf, 0, MAX_PAYLOAD_LEN);
|
||||
|
||||
if(uip_newdata()) {
|
||||
len = uip_datalen();
|
||||
memcpy(buf, uip_appdata, len);
|
||||
PRINTF("%u bytes from [", len);
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
|
||||
len = read_sensor(buf);
|
||||
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);
|
||||
PRINTF("Sent %u bytes\n", len);
|
||||
}
|
||||
|
||||
/* Restore server connection to allow data from any node */
|
||||
uip_create_unspecified(&server_conn->ripaddr);
|
||||
server_conn->rport = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(udp_server_process, ev, data)
|
||||
{
|
||||
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
|
||||
static struct sensors_sensor *b1;
|
||||
static struct sensors_sensor *b2;
|
||||
#endif
|
||||
|
||||
PROCESS_BEGIN();
|
||||
putstring("Starting UDP server\n");
|
||||
|
||||
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
|
||||
putstring("Button X: Toggle LED X\n");
|
||||
#endif
|
||||
|
||||
server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
|
||||
udp_bind(server_conn, UIP_HTONS(SERVER_PORT));
|
||||
|
||||
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
|
||||
b1 = sensors_find(BUTTON_1_SENSOR);
|
||||
b2 = sensors_find(BUTTON_2_SENSOR);
|
||||
#endif
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(ev == tcpip_event) {
|
||||
tcpip_handler();
|
||||
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
|
||||
} else if(ev == sensors_event && data != NULL) {
|
||||
if(data == b1) {
|
||||
leds_toggle(LEDS_GREEN);
|
||||
} else if(data == b2) {
|
||||
leds_toggle(LEDS_RED);
|
||||
}
|
||||
#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
Loading…
Add table
Add a link
Reference in a new issue