Unverified Commit 63a96752 authored by George Oikonomou's avatar George Oikonomou Committed by GitHub
Browse files

Merge branch 'develop' into contrib/coap-lwm2m-dtls

parents 7d5fe004 9db7245d
......@@ -253,6 +253,7 @@ void
platform_init_stage_two()
{
set_lladdr();
serial_line_init();
}
/*---------------------------------------------------------------------------*/
void
......
......@@ -66,7 +66,9 @@ void input_callback(const void *data, uint16_t len,
const linkaddr_t *src, const linkaddr_t *dest)
{
if(len == sizeof(unsigned)) {
LOG_INFO("Received %u from ", *(unsigned *)data);
unsigned count;
memcpy(&count, data, sizeof(count));
LOG_INFO("Received %u from ", count);
LOG_INFO_LLADDR(src);
LOG_INFO_("\n");
}
......
......@@ -68,7 +68,9 @@ void input_callback(const void *data, uint16_t len,
const linkaddr_t *src, const linkaddr_t *dest)
{
if(len == sizeof(unsigned)) {
LOG_INFO("Received %u from ", *(unsigned *)data);
unsigned count;
memcpy(&count, data, sizeof(count));
LOG_INFO("Received %u from ", count);
LOG_INFO_LLADDR(src);
LOG_INFO_("\n");
}
......
......@@ -32,7 +32,5 @@
#define QUEUEBUF_CONF_NUM 4
#define UIP_CONF_BUFFER_SIZE 140
#define CMD_CONF_HANDLERS slip_radio_cmd_handler,cmd_handler_cc2420
#define SLIP_RADIO_CONF_SENSORS slip_radio_sky_sensors
#define UART1_CONF_RX_WITH_DMA 1
/*---------------------------------------------------------------------------*/
/*
* 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 "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;
}
/*
* 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/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
};
/* ---------------------------------------------------------------------- */
......@@ -64,7 +64,7 @@ slipnet_input(void)
packetbuf_datalen(), i);
for(i = 0; i < uip_len; i++) {
LOG_DBG("%02x", (unsigned char)uip_buf[i]);
LOG_DBG_("%02x", (unsigned char)uip_buf[i]);
if((i & 15) == 15) {
LOG_DBG_("\n");
} else if((i & 7) == 7) {
......
......@@ -166,6 +166,25 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
packet_pos = 0;
}
return 1;
} else if(data[1] == 'V') {
int type = ((uint16_t)data[2] << 8) | data[3];
int value = ((uint16_t)data[4] << 8) | data[5];
int param = type; /* packetutils_to_radio_param(type); */
if(param < 0) {
printf("radio: unknown parameter %d (can not set to %d)\n", type, value);
} else {
if(param == RADIO_PARAM_RX_MODE) {
printf("radio: setting rxmode to 0x%x\n", value);
} else if(param == RADIO_PARAM_PAN_ID) {
printf("radio: setting pan id to 0x%04x\n", value);
} else if(param == RADIO_PARAM_CHANNEL) {
printf("radio: setting channel: %u\n", value);
} else {
printf("radio: setting param %d to %d (0x%02x)\n", param, value, value);
}
NETSTACK_RADIO.set_value(param, value);
}
return 1;
}
} else if(uip_buf[0] == '?') {
......@@ -180,6 +199,25 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
uip_len = 10;
cmd_send(uip_buf, uip_len);
return 1;
} else if(data[1] == 'V') {
/* ask the radio about the specific parameter and send it back... */
int type = ((uint16_t)data[2] << 8) | data[3];
int value;
int param = type; /* packetutils_to_radio_param(type); */
if(param < 0) {
printf("radio: unknown parameter %d\n", type);
}
NETSTACK_RADIO.get_value(param, &value);
uip_buf[0] = '!';
uip_buf[1] = 'V';
uip_buf[2] = type >> 8;
uip_buf[3] = type & 0xff;
uip_buf[4] = value >> 8;
uip_buf[5] = value & 0xff;
uip_len = 6;
cmd_send(uip_buf, uip_len);
}
}
return 0;
......@@ -189,7 +227,9 @@ static void
slip_input_callback(void)
{
LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]);
cmd_input(uip_buf, uip_len);
if(!cmd_input(uip_buf, uip_len)) {
cmd_send((uint8_t *)"EUnknown command", 16);
}
uip_clear_buf();
}
/*---------------------------------------------------------------------------*/
......
......@@ -36,7 +36,27 @@
* Joakim Eriksson <joakime@sics.se>
*/
#include "net/mac/framer/framer.h"
#include "net/packetbuf.h"
#ifdef NULLFRAMER_CONF_PARSE_802154
#define NULLFRAMER_PARSE_802154 NULLFRAMER_CONF_PARSE_802154
#else
/* defaults to parsing of the 802154 header as that is used for Slip-Radio */
#define NULLFRAMER_PARSE_802154 1
#endif
/*---------------------------------------------------------------------------*/
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
hdr_length(void)
......@@ -55,6 +75,21 @@ create(void)
static int
parse(void)
{
#if NULLFRAMER_PARSE_802154
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, (linkaddr_t *)&frame.dest_addr);
}
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
return 0;
}
#endif
return 0;
}
/*---------------------------------------------------------------------------*/
......
MODULES += os/services/slip-cmd
MODULES += os/services/shell
MAKE_MAC = MAKE_MAC_OTHER
MAKE_NET = MAKE_NET_IPV6
PREFIX ?= fd00::1/64
connect-router: border-router.native
sudo ./border-router.native $(PREFIX)
connect-router-cooja: border-router.native
sudo ./border-router.native -a localhost $(PREFIX)
......@@ -43,6 +43,8 @@
#include "rpl.h"
#include "net/ipv6/uiplib.h"
#include <string.h>
#include "shell.h"
#include <stdio.h>
#define DEBUG DEBUG_NONE
#include "net/ipv6/uip-debug.h"
......@@ -54,6 +56,56 @@ void nbr_print_stat(void);
/*---------------------------------------------------------------------------*/
PROCESS(border_router_cmd_process, "Border router cmd process");
/*---------------------------------------------------------------------------*/
static const uint8_t *
hextoi(const uint8_t *buf, int len, int *v)
{
*v = 0;
for(; len > 0; len--, buf++) {
if(*buf >= '0' && *buf <= '9') {
*v = (*v << 4) + ((*buf - '0') & 0xf);
} else if(*buf >= 'a' && *buf <= 'f') {
*v = (*v << 4) + ((*buf - 'a' + 10) & 0xf);
} else if(*buf >= 'A' && *buf <= 'F') {
*v = (*v << 4) + ((*buf - 'A' + 10) & 0xf);
} else {
break;
}
}
return buf;
}
/*---------------------------------------------------------------------------*/
static const uint8_t *
dectoi(const uint8_t *buf, int len, int *v)
{
int negative = 0;
*v = 0;
if(len <= 0) {
return buf;
}
if(*buf == '$') {
return hextoi(buf + 1, len - 1, v);
}
if(*buf == '0' && *(buf + 1) == 'x' && len > 2) {
return hextoi(buf + 2, len - 2, v);
}
if(*buf == '-') {
negative = 1;
buf++;
}
for(; len > 0; len--, buf++) {
if(*buf < '0' || *buf > '9') {
break;
}
*v = (*v * 10) + ((*buf - '0') & 0xf);
}
if(negative) {
*v = - *v;
}
return buf;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* TODO: the below code needs some way of identifying from where the command */
/* comes. In this case it can be from stdin or from SLIP. */
......@@ -64,35 +116,64 @@ border_router_cmd_handler(const uint8_t *data, int len)
/* handle global repair, etc here */
if(data[0] == '!') {
PRINTF("Got configuration message of type %c\n", data[1]);
if(data[1] == 'G' && command_context == CMD_CONTEXT_STDIO) {
/* This is supposed to be from stdin */
printf("Performing Global Repair...\n");
if(command_context == CMD_CONTEXT_STDIO) {
switch(data[1]) {
case 'G':
/* This is supposed to be from stdin */
printf("Performing Global Repair...\n");
#if UIP_CONF_IPV6_RPL_LITE
rpl_global_repair();
rpl_global_repair();
#else
rpl_repair_root(RPL_DEFAULT_INSTANCE);
rpl_repair_root(RPL_DEFAULT_INSTANCE);
#endif
return 1;
} else if(data[1] == 'M' && command_context == CMD_CONTEXT_RADIO) {
/* We need to know that this is from the slip-radio here. */
PRINTF("Setting MAC address\n");
border_router_set_mac(&data[2]);
return 1;
} else if(data[1] == 'C' && command_context == CMD_CONTEXT_RADIO) {
/* We need to know that this is from the slip-radio here. */
printf("Channel is:%d\n", data[2]);
return 1;
} else if(data[1] == 'R' && command_context == CMD_CONTEXT_RADIO) {
return 1;
case 'C': {
/* send on a set-param thing! */
uint8_t set_param[] = {'!', 'V', 0, RADIO_PARAM_CHANNEL, 0, 0 };
int channel = -1;
dectoi(&data[2], len - 2, &channel);
if(channel >= 0) {
set_param[5] = channel & 0xff;
write_to_slip(set_param, sizeof(set_param));
}
return 1;
}
case 'P': {
/* send on a set-param thing! */
uint8_t set_param[] = {'!', 'V', 0, RADIO_PARAM_PAN_ID, 0, 0 };
int pan_id;
dectoi(&data[2], len - 2, &pan_id);
set_param[4] = (pan_id >> 8) & 0xff;
set_param[5] = pan_id & 0xff;
write_to_slip(set_param, sizeof(set_param));
return 1;
}
default:
return 0;
}
} else if(command_context == CMD_CONTEXT_RADIO) {
/* We need to know that this is from the slip-radio here. */
PRINTF("Packet data report for sid:%d st:%d tx:%d\n",
data[2], data[3], data[4]);
packet_sent(data[2], data[3], data[4]);
return 1;
} else if(data[1] == 'D' && command_context == CMD_CONTEXT_RADIO) {
/* We need to know that this is from the slip-radio here... */
PRINTF("Sensor data received\n");
border_router_set_sensors((const char *)&data[2], len - 2);
return 1;
switch(data[1]) {
case 'M':
PRINTF("Setting MAC address\n");
border_router_set_mac(&data[2]);
return 1;
case 'V':
if(data[3] == RADIO_PARAM_CHANNEL) {
printf("Channel is %d\n", data[5]);
}
if(data[3] == RADIO_PARAM_PAN_ID) {
printf("PAN_ID is 0x%04x\n", (data[4] << 8) + data[5]);
}
return 1;
case 'R':
PRINTF("Packet data report for sid:%d st:%d tx:%d\n",
data[2], data[3], data[4]);
packet_sent(data[2], data[3], data[4]);
return 1;
default:
return 0;
}
}
} else if(data[0] == '?') {
PRINTF("Got request message of type %c\n", data[1]);
......@@ -110,8 +191,14 @@ border_router_cmd_handler(const uint8_t *data, int len)
cmd_send(buf, 18);
return 1;
} else if(data[1] == 'C' && command_context == CMD_CONTEXT_STDIO) {
/* send on! */
write_to_slip(data, len);
/* send on a set-param thing! */
uint8_t set_param[] = {'?', 'V', 0, RADIO_PARAM_CHANNEL};
write_to_slip(set_param, sizeof(set_param));
return 1;
} else if(data[1] == 'P' && command_context == CMD_CONTEXT_STDIO) {
/* send on a set-param thing! */
uint8_t set_param[] = {'?', 'V', 0, RADIO_PARAM_PAN_ID};
write_to_slip(set_param, sizeof(set_param));
return 1;
} else if(data[1] == 'S') {
border_router_print_stat();
......@@ -132,17 +219,33 @@ border_router_cmd_output(const uint8_t *data, int data_len)
printf("\n");
}
/*---------------------------------------------------------------------------*/
static void
serial_shell_output(const char *str)
{
printf("%s", str);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_cmd_process, ev, data)
{
static struct pt shell_input_pt;
PROCESS_BEGIN();
PRINTF("Started br-cmd process\n");
shell_init();
while(1) {
PROCESS_YIELD();
if(ev == serial_line_event_message && data != NULL) {
PRINTF("Got serial data!!! %s of len: %d\n",
PRINTF("Got serial data!!! %s of len: %lu\n",
(char *)data, strlen((char *)data));
command_context = CMD_CONTEXT_STDIO;
cmd_input(data, strlen((char *)data));
if(cmd_input(data, strlen((char *)data))) {
/* Commnand executed - all is fine */
} else {
/* did not find command - run shell and see if ... */
PROCESS_PT_SPAWN(&shell_input_pt, shell_input(&shell_input_pt, serial_shell_output, data));
}
}
}
PROCESS_END();
......
......@@ -63,7 +63,7 @@ struct tx_callback {
struct packetbuf_attr attrs[PACKETBUF_NUM_ATTRS];
struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
};
/*---------------------------------------------------------------------------*/
static struct tx_callback callbacks[MAX_CALLBACKS];
/*---------------------------------------------------------------------------*/
void
......@@ -111,6 +111,10 @@ send_packet(mac_callback_t sent, void *ptr)
/* ack or not ? */
packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
/* Will make it send only DATA packets... for now */
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
/* printf("Sending packet of type: %s \n", get_frame_type(packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE))); */
if(NETSTACK_FRAMER.create() < 0) {
/* Failed to allocate space for headers */
PRINTF("br-rdc: send failed, too large header\n");
......
......@@ -51,18 +51,11 @@
#include <stdlib.h>
#define MAX_SENSORS 4
extern long slip_sent;
extern long slip_received;
static uint8_t mac_set;
static uint8_t sensor_count = 0;
/* allocate MAX_SENSORS char[32]'s */
static char sensors[MAX_SENSORS][32];
extern int contiki_argc;
extern char **contiki_argv;
extern const char *slip_config_ipaddr;
......@@ -101,30 +94,6 @@ border_router_print_stat()
printf("bytes sent over SLIP: %ld\n", slip_sent);
}
/*---------------------------------------------------------------------------*/
/* Format: <name=value>;<name=value>;...;<name=value>*/
/* this function just cut at ; and store in the sensor array */
void
border_router_set_sensors(const char *data, int len)
{
int i;
int last_pos = 0;
int sc = 0;
for(i = 0; i < len; i++) {
if(data[i] == ';') {