Broke out the 'neighbor' command functionality from the shell-rime.c file; reimplemented it to use the announcemnet primitive instead

This commit is contained in:
adamdunkels 2009-05-10 21:04:06 +00:00
parent 8458a4fe28
commit 904bb1487c
3 changed files with 150 additions and 38 deletions

View File

@ -0,0 +1,102 @@
/*
* 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-neighbors.c,v 1.1 2009/05/10 21:04:06 adamdunkels Exp $
*/
/**
* \file
* The Contiki shell Rime ping application
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "shell.h"
#include "net/rime.h"
PROCESS(shell_neighbors_process, "neighbors");
SHELL_COMMAND(neighbors_command,
"neighbors",
"neighbors: dump neighbor list in binary format",
&shell_neighbors_process);
static uint8_t listening_for_neighbors = 0;
/*---------------------------------------------------------------------------*/
static void
received_announcement(struct announcement *a, rimeaddr_t *from,
uint16_t id, uint16_t value)
{
struct {
uint16_t len;
uint16_t addr;
uint16_t rssi;
uint16_t lqi;
} msg;
if(listening_for_neighbors) {
memset(&msg, 0, sizeof(msg));
msg.len = 3;
rimeaddr_copy((rimeaddr_t *)&msg.addr, from);
msg.rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI);
msg.lqi = packetbuf_attr(PACKETBUF_ATTR_LINK_QUALITY);
shell_output(&neighbors_command, &msg, sizeof(msg), "", 0);
}
}
static struct announcement neighbor_announcement;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_neighbors_process, ev, data)
{
static struct etimer et;
PROCESS_EXITHANDLER(announcement_remove(&neighbor_announcement);)
PROCESS_BEGIN();
listening_for_neighbors = 1;
announcement_listen(1);
etimer_set(&et, CLOCK_SECOND * 10);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
listening_for_neighbors = 0;
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_rime_neighbors_init(void)
{
announcement_register(&neighbor_announcement,
SHELL_RIME_ANNOUNCEMENT_IDENTIFIER_NEIGHBORS, 0,
received_announcement);
shell_register_command(&neighbors_command);
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,46 @@
/*
* 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-neighbors.h,v 1.1 2009/05/10 21:04:06 adamdunkels Exp $
*/
/**
* \file
* Header file for the Contiki shell Rime neighbors application
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __SHELL_RIME_NEIGHBORS_H__
#define __SHELL_RIME_NEIGHBORS_H__
void shell_rime_neighbors_init(void);
#endif /* __SHELL-RIME_-NEIGHBORS_H__ */

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: shell-rime.c,v 1.13 2009/03/12 21:58:20 adamdunkels Exp $
* $Id: shell-rime.c,v 1.14 2009/05/10 21:04:06 adamdunkels Exp $
*/
/**
@ -131,11 +131,6 @@ SHELL_COMMAND(treedepth_command,
"treedepth: print the collection tree depth",
&shell_treedepth_process);
#endif /* WITH_TREEDEPTH */
PROCESS(shell_neighbors_process, "neighbors");
SHELL_COMMAND(neighbors_command,
"neighbors",
"neighbors: dump neighbor list in binary format",
&shell_neighbors_process);
PROCESS(shell_routes_process, "routes");
SHELL_COMMAND(routes_command,
"routes",
@ -237,7 +232,7 @@ PROCESS_THREAD(shell_routes_process, ev, data)
r = route_get(i);
rimeaddr_copy((rimeaddr_t *)&msg.dest, &r->dest);
rimeaddr_copy((rimeaddr_t *)&msg.nexthop, &r->nexthop);
msg.hop_count = r->hop_count;
msg.hop_count = r->cost;
msg.seqno = r->seqno;
shell_output(&routes_command, &msg, sizeof(msg), "", 0);
}
@ -245,36 +240,6 @@ PROCESS_THREAD(shell_routes_process, ev, data)
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_neighbors_process, ev, data)
{
struct {
uint16_t len;
uint16_t addr;
uint16_t rtmetric;
uint16_t etx;
} msg;
int i;
struct neighbor *n;
PROCESS_BEGIN();
for(i = 0; i < neighbor_num(); ++i) {
n = neighbor_get(i);
if(!rimeaddr_cmp(&n->addr, &rimeaddr_null)) {
memset(&msg, 0, sizeof(msg));
msg.len = 3;
rimeaddr_copy((rimeaddr_t *)&msg.addr, &n->addr);
msg.rtmetric = n->rtmetric;
msg.etx = neighbor_etx(n);
shell_output(&neighbors_command, &msg, sizeof(msg), "", 0);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_nodes_process, ev, data)
{
static struct etimer etimer;
@ -478,7 +443,6 @@ shell_rime_init(void)
shell_register_command(&collect_command);
shell_register_command(&mac_command);
shell_register_command(&neighbors_command);
shell_register_command(&nodes_command);
shell_register_command(&packetize_command);
shell_register_command(&routes_command);