Added a debug command for testing reliable unicast (runicast) communication
This commit is contained in:
parent
fcd50868aa
commit
435add5e17
4 changed files with 225 additions and 2 deletions
|
@ -3,7 +3,7 @@ shell_src = shell.c shell-reboot.c \
|
|||
shell-blink.c shell-text.c shell-time.c \
|
||||
shell-file.c shell-netfile.c shell-run.c \
|
||||
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \
|
||||
shell-rime-debug.c shell-coffee.c \
|
||||
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \
|
||||
shell-wget.c shell-httpd.c shell-irc.c \
|
||||
shell-checkpoint.c shell-power.c \
|
||||
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \
|
||||
|
|
174
apps/shell/shell-rime-debug-runicast.c
Normal file
174
apps/shell/shell-rime-debug-runicast.c
Normal file
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 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.
|
||||
*
|
||||
* $Id: shell-rime-debug-runicast.c,v 1.1 2010/01/31 19:35:12 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Debugging command for testing reliable unicast (runicast)
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-conf.h"
|
||||
#include "shell-rime-debug.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "lib/random.h"
|
||||
|
||||
#include "net/rime.h"
|
||||
#include "net/rime/neighbor.h"
|
||||
#include "net/rime/route.h"
|
||||
#include "net/rime/trickle.h"
|
||||
|
||||
#include "net/rime/timesynch.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef HAVE_SNPRINTF
|
||||
int snprintf(char *str, size_t size, const char *format, ...);
|
||||
#endif /* HAVE_SNPRINTF */
|
||||
#include <string.h>
|
||||
|
||||
#define COLLECT_MSG_HDRSIZE 2
|
||||
struct collect_msg {
|
||||
uint16_t timestamp;
|
||||
uint8_t data[1];
|
||||
};
|
||||
|
||||
static struct runicast_conn ruc;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(shell_runicast_process, "runicast");
|
||||
SHELL_COMMAND(runicast_command,
|
||||
"runicast",
|
||||
"runicast <node addr>: reliably unicast data to specific neighbor",
|
||||
&shell_runicast_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(shell_runicast_process, ev, data)
|
||||
{
|
||||
struct shell_input *input;
|
||||
static rimeaddr_t receiver;
|
||||
int len;
|
||||
const char *nextptr;
|
||||
struct collect_msg *msg;
|
||||
char buf[30];
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
receiver.u8[0] = shell_strtolong(data, &nextptr);
|
||||
if(nextptr == data || *nextptr != '.') {
|
||||
shell_output_str(&runicast_command,
|
||||
"runicast <receiver>: recevier must be specified", "");
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
++nextptr;
|
||||
receiver.u8[1] = shell_strtolong(nextptr, &nextptr);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
|
||||
shell_output_str(&runicast_command, "Sending runicast packets to ", buf);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
||||
input = data;
|
||||
|
||||
len = input->len1 + input->len2;
|
||||
|
||||
if(len == 0) {
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
if(len < PACKETBUF_SIZE) {
|
||||
packetbuf_clear();
|
||||
packetbuf_set_datalen(len + COLLECT_MSG_HDRSIZE);
|
||||
msg = packetbuf_dataptr();
|
||||
memcpy(msg->data, input->data1, input->len1);
|
||||
memcpy(msg->data + input->len1, input->data2, input->len2);
|
||||
#if TIMESYNCH_CONF_ENABLED
|
||||
msg->timestamp = timesynch_time();
|
||||
#else
|
||||
msg->timestamp = 0;
|
||||
#endif
|
||||
/* printf("Sending %d bytes\n", len);*/
|
||||
runicast_send(&ruc, &receiver, 4);
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
static void
|
||||
recv_ruc(struct runicast_conn *c, const rimeaddr_t *from, uint8_t seqno)
|
||||
{
|
||||
struct collect_msg *msg;
|
||||
rtimer_clock_t latency;
|
||||
rtimer_clock_t timestamp;
|
||||
|
||||
msg = packetbuf_dataptr();
|
||||
|
||||
#if TIMESYNCH_CONF_ENABLED
|
||||
memcpy(×tamp, &msg->timestamp, sizeof(timestamp));
|
||||
latency = timesynch_time() - timestamp;
|
||||
#else
|
||||
latency = 0;
|
||||
#endif
|
||||
|
||||
printf("runicast message received from %d.%d, latency %lu ms, seqno %d, data '%.*s'\n",
|
||||
from->u8[0], from->u8[1],
|
||||
(1000L * latency) / RTIMER_ARCH_SECOND,
|
||||
seqno,
|
||||
packetbuf_datalen() - COLLECT_MSG_HDRSIZE,
|
||||
msg->data);
|
||||
}
|
||||
static void
|
||||
sent_ruc(struct runicast_conn *c, const rimeaddr_t *to, uint8_t tx)
|
||||
{
|
||||
printf("runicast message sent to %d.%d, %d transmissions\n",
|
||||
to->u8[0], to->u8[1],
|
||||
tx);
|
||||
}
|
||||
static void
|
||||
timedout_ruc(struct runicast_conn *c, const rimeaddr_t *to, uint8_t tx)
|
||||
{
|
||||
printf("runicast message to %d.%d timed out after %d transmissions\n",
|
||||
to->u8[0], to->u8[1],
|
||||
tx);
|
||||
}
|
||||
static const struct runicast_callbacks runicast_callbacks = {recv_ruc,
|
||||
sent_ruc,
|
||||
timedout_ruc};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
shell_rime_debug_runicast_init(void)
|
||||
{
|
||||
runicast_open(&ruc, SHELL_RIME_CHANNEL_RUNICAST,
|
||||
&runicast_callbacks);
|
||||
shell_register_command(&runicast_command);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
48
apps/shell/shell-rime-debug-runicast.h
Normal file
48
apps/shell/shell-rime-debug-runicast.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 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.
|
||||
*
|
||||
* $Id: shell-rime-debug-runicast.h,v 1.1 2010/01/31 19:35:12 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A brief description of what this file is.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __SHELL_RIME_DEBUG_RUNICAST_H__
|
||||
#define __SHELL_RIME_DEBUG_RUNICAST_H__
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
void shell_rime_debug_runicast_init(void);
|
||||
|
||||
#endif /* __SHELL_RIME_DEBUG_RUNICAST_H__ */
|
|
@ -48,7 +48,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: shell.h,v 1.19 2009/11/03 22:52:39 adamdunkels Exp $
|
||||
* $Id: shell.h,v 1.20 2010/01/31 19:35:12 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -369,6 +369,7 @@ struct shell_input {
|
|||
#include "shell-ps.h"
|
||||
#include "shell-reboot.h"
|
||||
#include "shell-rime-debug.h"
|
||||
#include "shell-rime-debug-runicast.h"
|
||||
#include "shell-rime-neighbors.h"
|
||||
#include "shell-rime-netcmd.h"
|
||||
#include "shell-rime-ping.h"
|
||||
|
|
Loading…
Reference in a new issue