changed slip-radio to be able to change panid over slip command
This commit is contained in:
parent
033adfa678
commit
20e8eba08b
8 changed files with 752 additions and 0 deletions
20
examples/osd/slip-radio/Makefile
Normal file
20
examples/osd/slip-radio/Makefile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
CONTIKI_PROJECT=slip-radio
|
||||||
|
all: $(CONTIKI_PROJECT)
|
||||||
|
APPS = slip-cmd
|
||||||
|
|
||||||
|
CONTIKI=../../..
|
||||||
|
|
||||||
|
WITH_UIP6=1
|
||||||
|
UIP_CONF_IPV6=1
|
||||||
|
UIP_CONF_RPL=0
|
||||||
|
|
||||||
|
#linker optimizations
|
||||||
|
SMALL=1
|
||||||
|
|
||||||
|
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||||
|
PROJECT_SOURCEFILES += slip-net.c no-framer.c
|
||||||
|
ifeq ($(TARGET),sky)
|
||||||
|
PROJECT_SOURCEFILES += slip-radio-cc2420.c slip-radio-sky-sensors.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(CONTIKI)/Makefile.include
|
114
examples/osd/slip-radio/no-framer.c
Normal file
114
examples/osd/slip-radio/no-framer.c
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009, Swedish Institute of 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* MAC framer that does nothing...
|
||||||
|
* \author
|
||||||
|
* Niclas Finne <nfi@sics.se>
|
||||||
|
* Joakim Eriksson <joakime@sics.se>
|
||||||
|
*/
|
||||||
|
#include "net/mac/framer.h"
|
||||||
|
#include "net/mac/frame802154.h"
|
||||||
|
#include "net/packetbuf.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define DEBUG 2
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
#define PRINTADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7])
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#define PRINTADDR(addr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** \brief The 16-bit identifier of the PAN on which the device is
|
||||||
|
* sending to. If this value is 0xffff, the device is not
|
||||||
|
* associated.
|
||||||
|
*/
|
||||||
|
static const uint16_t mac_dst_pan_id = IEEE802154_PANID;
|
||||||
|
|
||||||
|
/** \brief The 16-bit identifier of the PAN on which the device is
|
||||||
|
* operating. If this value is 0xffff, the device is not
|
||||||
|
* associated.
|
||||||
|
*/
|
||||||
|
static const uint16_t mac_src_pan_id = IEEE802154_PANID;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
is_broadcast_addr(uint8_t mode, uint8_t *addr)
|
||||||
|
{
|
||||||
|
int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
|
||||||
|
while(i-- > 0) {
|
||||||
|
if(addr[i] != 0xff) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
create(void)
|
||||||
|
{
|
||||||
|
/* nothing extra... */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
parse(void)
|
||||||
|
{
|
||||||
|
frame802154_t frame;
|
||||||
|
int len;
|
||||||
|
len = packetbuf_datalen();
|
||||||
|
if(frame802154_parse(packetbuf_dataptr(), len, &frame)) {
|
||||||
|
if(frame.fcf.dest_addr_mode) {
|
||||||
|
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
|
||||||
|
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (rimeaddr_t *)&frame.dest_addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (rimeaddr_t *)&frame.src_addr);
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending);
|
||||||
|
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
|
||||||
|
|
||||||
|
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
|
||||||
|
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
||||||
|
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||||
|
PRINTF("%u (%u)\n", packetbuf_datalen(), len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
const struct framer no_framer = {
|
||||||
|
create, parse
|
||||||
|
};
|
76
examples/osd/slip-radio/project-conf.h
Normal file
76
examples/osd/slip-radio/project-conf.h
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010, Swedish Institute of 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PROJECT_CONF_H__
|
||||||
|
#define __PROJECT_CONF_H__
|
||||||
|
|
||||||
|
#undef QUEUEBUF_CONF_NUM
|
||||||
|
#define QUEUEBUF_CONF_NUM 4
|
||||||
|
|
||||||
|
#undef UIP_CONF_BUFFER_SIZE
|
||||||
|
#define UIP_CONF_BUFFER_SIZE 140
|
||||||
|
|
||||||
|
#undef UIP_CONF_ROUTER
|
||||||
|
#define UIP_CONF_ROUTER 0
|
||||||
|
|
||||||
|
#undef UIP_CONF_IPV6_RPL
|
||||||
|
#define UIP_CONF_IPV6_RPL 0
|
||||||
|
|
||||||
|
#define CMD_CONF_OUTPUT slip_radio_cmd_output
|
||||||
|
|
||||||
|
/* add the cmd_handler_cc2420 + some sensors if TARGET_SKY */
|
||||||
|
#ifdef CONTIKI_TARGET_SKY
|
||||||
|
#define CMD_CONF_HANDLERS slip_radio_cmd_handler,cmd_handler_cc2420
|
||||||
|
#define SLIP_RADIO_CONF_SENSORS slip_radio_sky_sensors
|
||||||
|
#else
|
||||||
|
#define CMD_CONF_HANDLERS slip_radio_cmd_handler
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* configuration for the slipradio/network driver */
|
||||||
|
#undef NETSTACK_CONF_MAC
|
||||||
|
#define NETSTACK_CONF_MAC csma_driver
|
||||||
|
|
||||||
|
#undef NETSTACK_CONF_RDC
|
||||||
|
/* #define NETSTACK_CONF_RDC nullrdc_noframer_driver */
|
||||||
|
#define NETSTACK_CONF_RDC contikimac_driver
|
||||||
|
|
||||||
|
#undef NETSTACK_CONF_NETWORK
|
||||||
|
#define NETSTACK_CONF_NETWORK slipnet_driver
|
||||||
|
|
||||||
|
#undef NETSTACK_CONF_FRAMER
|
||||||
|
#define NETSTACK_CONF_FRAMER no_framer
|
||||||
|
|
||||||
|
#undef CC2420_CONF_AUTOACK
|
||||||
|
#define CC2420_CONF_AUTOACK 1
|
||||||
|
|
||||||
|
#undef UART1_CONF_RX_WITH_DMA
|
||||||
|
#define UART1_CONF_RX_WITH_DMA 1
|
||||||
|
|
||||||
|
#endif /* __PROJECT_CONF_H__ */
|
103
examples/osd/slip-radio/slip-net.c
Normal file
103
examples/osd/slip-radio/slip-net.c
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "net/netstack.h"
|
||||||
|
#include "net/uip.h"
|
||||||
|
#include "net/packetbuf.h"
|
||||||
|
#include "dev/slip.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define SLIP_END 0300
|
||||||
|
#define SLIP_ESC 0333
|
||||||
|
#define SLIP_ESC_END 0334
|
||||||
|
#define SLIP_ESC_ESC 0335
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
slipnet_init(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
slip_send_packet(const uint8_t *ptr, int len)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
uint8_t c;
|
||||||
|
|
||||||
|
slip_arch_writeb(SLIP_END);
|
||||||
|
for(i = 0; i < len; ++i) {
|
||||||
|
c = *ptr++;
|
||||||
|
if(c == SLIP_END) {
|
||||||
|
slip_arch_writeb(SLIP_ESC);
|
||||||
|
c = SLIP_ESC_END;
|
||||||
|
} else if(c == SLIP_ESC) {
|
||||||
|
slip_arch_writeb(SLIP_ESC);
|
||||||
|
c = SLIP_ESC_ESC;
|
||||||
|
}
|
||||||
|
slip_arch_writeb(c);
|
||||||
|
}
|
||||||
|
slip_arch_writeb(SLIP_END);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
slipnet_input(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
/* radio should be configured for filtering so this should be simple */
|
||||||
|
/* this should be sent over SLIP! */
|
||||||
|
/* so just copy into uip-but and send!!! */
|
||||||
|
/* Format: !R<data> ? */
|
||||||
|
uip_len = packetbuf_datalen();
|
||||||
|
i = packetbuf_copyto(uip_buf);
|
||||||
|
|
||||||
|
if(DEBUG) {
|
||||||
|
printf("Slipnet got input of len: %d, copied: %d\n",
|
||||||
|
packetbuf_datalen(), i);
|
||||||
|
|
||||||
|
for(i = 0; i < uip_len; i++) {
|
||||||
|
printf("%02x", (unsigned char) uip_buf[i]);
|
||||||
|
if((i & 15) == 15) printf("\n");
|
||||||
|
else if((i & 7) == 7) printf(" ");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* printf("SUT: %u\n", uip_len); */
|
||||||
|
slip_send_packet(uip_buf, uip_len);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
const struct network_driver slipnet_driver = {
|
||||||
|
"slipnet",
|
||||||
|
slipnet_init,
|
||||||
|
slipnet_input
|
||||||
|
};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
60
examples/osd/slip-radio/slip-radio-cc2420.c
Normal file
60
examples/osd/slip-radio/slip-radio-cc2420.c
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of 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.
|
||||||
|
*
|
||||||
|
* Sets up some commands for the CC2420 radio chip.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/cc2420.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_handler_cc2420(const uint8_t *data, int len)
|
||||||
|
{
|
||||||
|
if(data[0] == '!') {
|
||||||
|
if(data[1] == 'C') {
|
||||||
|
printf("cc2420_cmd: setting channel: %d\n", data[2]);
|
||||||
|
cc2420_set_channel(data[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if(data[0] == '?') {
|
||||||
|
if(data[1] == 'C') {
|
||||||
|
uint8_t buf[4];
|
||||||
|
printf("cc2420_cmd: getting channel: %d\n", data[2]);
|
||||||
|
buf[0] = '!';
|
||||||
|
buf[1] = 'C';
|
||||||
|
buf[2] = cc2420_get_channel();
|
||||||
|
cmd_send(buf, 3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
90
examples/osd/slip-radio/slip-radio-sky-sensors.c
Normal file
90
examples/osd/slip-radio/slip-radio-sky-sensors.c
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/sht11-sensor.h"
|
||||||
|
#include "slip-radio.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
init(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
write_percent_float(char *data, int maxlen, int temp)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
t = temp % 100;
|
||||||
|
if(t < 0) {
|
||||||
|
t = -t;
|
||||||
|
}
|
||||||
|
return snprintf(data, maxlen, "%d.%02d", temp / 100, t);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
send(void)
|
||||||
|
{
|
||||||
|
#define MAX_SIZE 40
|
||||||
|
char data[MAX_SIZE];
|
||||||
|
int temperature;
|
||||||
|
int ms;
|
||||||
|
long hum;
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
/* SENSORS_ACTIVATE(light_sensor); */
|
||||||
|
SENSORS_ACTIVATE(sht11_sensor);
|
||||||
|
|
||||||
|
pos += snprintf(data, MAX_SIZE, "!D");
|
||||||
|
/* int light1 = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC); */
|
||||||
|
/* int light2 = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR); */
|
||||||
|
temperature = -3970 + sht11_sensor.value(SHT11_SENSOR_TEMP);
|
||||||
|
ms = sht11_sensor.value(SHT11_SENSOR_HUMIDITY);
|
||||||
|
/* this is in * 10000 */
|
||||||
|
/* -2.0468 + 0.0367 * ms + -1.5955e-6 * ms * ms ...too small value... */
|
||||||
|
hum = (-20468L + 367L * ms) / 100L;
|
||||||
|
|
||||||
|
/* SENSORS_DEACTIVATE(light_sensor); */
|
||||||
|
SENSORS_DEACTIVATE(sht11_sensor);
|
||||||
|
|
||||||
|
pos += snprintf(&data[pos], MAX_SIZE - pos, "temp=");
|
||||||
|
pos += write_percent_float(&data[pos], MAX_SIZE - pos, temperature);
|
||||||
|
pos += snprintf(&data[pos], MAX_SIZE - pos, ";hum=");
|
||||||
|
pos += write_percent_float(&data[pos], MAX_SIZE - pos, hum);
|
||||||
|
|
||||||
|
cmd_send((uint8_t *)data, pos);
|
||||||
|
}
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
const struct slip_radio_sensors slip_radio_sky_sensors = {
|
||||||
|
init, send
|
||||||
|
};
|
||||||
|
/* ---------------------------------------------------------------------- */
|
248
examples/osd/slip-radio/slip-radio.c
Normal file
248
examples/osd/slip-radio/slip-radio.c
Normal file
|
@ -0,0 +1,248 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Slip-radio driver
|
||||||
|
* \author
|
||||||
|
* Niclas Finne <nfi@sics.se>
|
||||||
|
* Joakim Eriksson <joakime@sics.se>
|
||||||
|
* Andreas Reder
|
||||||
|
*/
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "net/uip.h"
|
||||||
|
#include "net/uip-ds6.h"
|
||||||
|
#include "dev/slip.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "net/netstack.h"
|
||||||
|
#include "net/packetbuf.h"
|
||||||
|
|
||||||
|
#define DEBUG DEBUG_FULL
|
||||||
|
#include "net/uip-debug.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
#include "slip-radio.h"
|
||||||
|
#include "packetutils.h"
|
||||||
|
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
#include "watchdog.h"
|
||||||
|
#include "params.h"
|
||||||
|
|
||||||
|
extern uint16_t eemem_panid EEMEM;
|
||||||
|
extern uint8_t eemem_channel[] EEMEM;
|
||||||
|
|
||||||
|
#ifdef SLIP_RADIO_CONF_SENSORS
|
||||||
|
extern const struct slip_radio_sensors SLIP_RADIO_CONF_SENSORS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void slip_send_packet(const uint8_t *ptr, int len);
|
||||||
|
|
||||||
|
/* max 16 packets at the same time??? */
|
||||||
|
uint8_t packet_ids[16];
|
||||||
|
int packet_pos;
|
||||||
|
|
||||||
|
static int slip_radio_cmd_handler(const uint8_t *data, int len);
|
||||||
|
int cmd_handler_cc2420(const uint8_t *data, int len);
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#ifdef CMD_CONF_HANDLERS
|
||||||
|
CMD_HANDLERS(CMD_CONF_HANDLERS);
|
||||||
|
#else
|
||||||
|
CMD_HANDLERS(slip_radio_cmd_handler);
|
||||||
|
#endif
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
packet_sent(void *ptr, int status, int transmissions)
|
||||||
|
{
|
||||||
|
uint8_t buf[20];
|
||||||
|
uint8_t sid;
|
||||||
|
int pos;
|
||||||
|
sid = *((uint8_t *)ptr);
|
||||||
|
PRINTF("Slip-radio: packet sent! sid: %d, status: %d, tx: %d\n",
|
||||||
|
sid, status, transmissions);
|
||||||
|
/* packet callback from lower layers */
|
||||||
|
/* neighbor_info_packet_sent(status, transmissions); */
|
||||||
|
pos = 0;
|
||||||
|
buf[pos++] = '!';
|
||||||
|
buf[pos++] = 'R';
|
||||||
|
buf[pos++] = sid;
|
||||||
|
buf[pos++] = status; /* one byte ? */
|
||||||
|
buf[pos++] = transmissions;
|
||||||
|
cmd_send(buf, pos);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
slip_radio_cmd_handler(const uint8_t *data, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint16_t panid;
|
||||||
|
|
||||||
|
if(data[0] == '!') {
|
||||||
|
/* should send out stuff to the radio - ignore it as IP */
|
||||||
|
/* --- s e n d --- */
|
||||||
|
if(data[1] == 'S') {
|
||||||
|
int pos;
|
||||||
|
packet_ids[packet_pos] = data[2];
|
||||||
|
|
||||||
|
packetbuf_clear();
|
||||||
|
pos = packetutils_deserialize_atts(&data[3], len - 3);
|
||||||
|
if(pos < 0) {
|
||||||
|
PRINTF("slip-radio: illegal packet attributes\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
pos += 3;
|
||||||
|
len -= pos;
|
||||||
|
if(len > PACKETBUF_SIZE) {
|
||||||
|
len = PACKETBUF_SIZE;
|
||||||
|
}
|
||||||
|
memcpy(packetbuf_dataptr(), &data[pos], len);
|
||||||
|
packetbuf_set_datalen(len);
|
||||||
|
|
||||||
|
PRINTF("slip-radio: sending %u (%d bytes)\n",
|
||||||
|
data[2], packetbuf_datalen());
|
||||||
|
|
||||||
|
/* parse frame before sending to get addresses, etc. */
|
||||||
|
no_framer.parse();
|
||||||
|
NETSTACK_MAC.send(packet_sent, &packet_ids[packet_pos]);
|
||||||
|
|
||||||
|
packet_pos++;
|
||||||
|
if(packet_pos >= sizeof(packet_ids)) {
|
||||||
|
packet_pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if(uip_buf[0] == '?') {
|
||||||
|
PRINTF("Got request message of type %c\n", uip_buf[1]);
|
||||||
|
if(data[1] == 'M') {
|
||||||
|
/* this is just a test so far... just to see if it works */
|
||||||
|
uip_buf[0] = '!';
|
||||||
|
uip_buf[1] = 'M';
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
uip_buf[2 + i] = uip_lladdr.addr[i];
|
||||||
|
}
|
||||||
|
uip_len = 10;
|
||||||
|
cmd_send(uip_buf, uip_len);
|
||||||
|
return 1;
|
||||||
|
} else if( data[1] == 'P'){
|
||||||
|
panid = (data[2] << 8) + data[3];
|
||||||
|
PRINTF("slip-radio: received change panid command, new panid %u\n", len);
|
||||||
|
cli();
|
||||||
|
eeprom_write_word(&eemem_panid, panid);
|
||||||
|
sei();
|
||||||
|
watchdog_reboot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
slip_radio_cmd_output(const uint8_t *data, int data_len)
|
||||||
|
{
|
||||||
|
slip_send_packet(data, data_len);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
slip_input_callback(void)
|
||||||
|
{
|
||||||
|
PRINTF("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]);
|
||||||
|
cmd_input(uip_buf, uip_len);
|
||||||
|
uip_len = 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
init(void)
|
||||||
|
{
|
||||||
|
#ifndef BAUD2UBR
|
||||||
|
#define BAUD2UBR(baud) baud
|
||||||
|
#endif
|
||||||
|
slip_arch_init(BAUD2UBR(115200));
|
||||||
|
process_start(&slip_process, NULL);
|
||||||
|
slip_set_input_callback(slip_input_callback);
|
||||||
|
packet_pos = 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#if !SLIP_RADIO_CONF_NO_PUTCHAR
|
||||||
|
#undef putchar
|
||||||
|
int
|
||||||
|
putchar(int c)
|
||||||
|
{
|
||||||
|
#define SLIP_END 0300
|
||||||
|
static char debug_frame = 0;
|
||||||
|
|
||||||
|
if(!debug_frame) { /* Start of debug output */
|
||||||
|
slip_arch_writeb(SLIP_END);
|
||||||
|
slip_arch_writeb('\r'); /* Type debug line == '\r' */
|
||||||
|
debug_frame = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Need to also print '\n' because for example COOJA will not show
|
||||||
|
any output before line end */
|
||||||
|
slip_arch_writeb((char)c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Line buffered output, a newline marks the end of debug output and
|
||||||
|
* implicitly flushes debug output.
|
||||||
|
*/
|
||||||
|
if(c == '\n') {
|
||||||
|
slip_arch_writeb(SLIP_END);
|
||||||
|
debug_frame = 0;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
PROCESS(slip_radio_process, "Slip radio process");
|
||||||
|
AUTOSTART_PROCESSES(&slip_radio_process);
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
PROCESS_THREAD(slip_radio_process, ev, data)
|
||||||
|
{
|
||||||
|
static struct etimer et;
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
init();
|
||||||
|
NETSTACK_RDC.off(1);
|
||||||
|
#ifdef SLIP_RADIO_CONF_SENSORS
|
||||||
|
SLIP_RADIO_CONF_SENSORS.init();
|
||||||
|
#endif
|
||||||
|
printf("Slip Radio started...\n");
|
||||||
|
|
||||||
|
etimer_set(&et, CLOCK_SECOND * 3);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_YIELD();
|
||||||
|
|
||||||
|
if(etimer_expired(&et)) {
|
||||||
|
etimer_reset(&et);
|
||||||
|
#ifdef SLIP_RADIO_CONF_SENSORS
|
||||||
|
SLIP_RADIO_CONF_SENSORS.send();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
41
examples/osd/slip-radio/slip-radio.h
Normal file
41
examples/osd/slip-radio/slip-radio.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SLIP_RADIO_H__
|
||||||
|
#define __SLIP_RADIO_H__
|
||||||
|
|
||||||
|
struct slip_radio_sensors {
|
||||||
|
/** Initialize the driver */
|
||||||
|
void (* init)(void);
|
||||||
|
/** Send the sensor data packet via the command send */
|
||||||
|
void (* send)(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __SLIP_RADIO_H__ */
|
Loading…
Add table
Reference in a new issue