Broke out shell code from the collect-view app to make it useful for non-shell apps too. Added a shell app for interacting with collect-view. Broke out handling of parent, rtmetric, etx, and num_neighbors to make collect-view independent of rime collect.

This commit is contained in:
adamdunkels 2010-10-20 15:21:43 +00:00
parent ce53d7b748
commit d6cb77a1d0
6 changed files with 163 additions and 45 deletions

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: collect-view.c,v 1.2 2010/10/19 07:33:47 adamdunkels Exp $
* $Id: collect-view.c,v 1.3 2010/10/20 15:21:43 adamdunkels Exp $
*/
/**
@ -39,30 +39,26 @@
*/
#include "contiki.h"
#include "shell.h"
#include "net/rime/collect-neighbor.h"
#include "net/rime.h"
#include "net/rime/broadcast-announcement.h"
#include "net/rime/timesynch.h"
#include "collect-view.h"
/*---------------------------------------------------------------------------*/
PROCESS(collect_view_data_process, "collect-view-data");
SHELL_COMMAND(collect_view_data_command,
"collect-view-data",
"collect-view-data: sensor data, power consumption, network stats",
&collect_view_data_process);
/*---------------------------------------------------------------------------*/
void
collect_view_construct_message(struct collect_view_data_msg *msg)
collect_view_construct_message(struct collect_view_data_msg *msg,
rimeaddr_t *parent,
uint16_t parent_etx,
uint16_t parent_rtmetric,
uint16_t num_neighbors,
uint16_t beacon_interval)
{
static unsigned long last_cpu, last_lpm, last_transmit, last_listen;
unsigned long cpu, lpm, transmit, listen;
struct collect_neighbor *n;
msg->len = sizeof(struct collect_view_data_msg) / sizeof(uint16_t);
msg->clock = clock_time();
@ -99,37 +95,13 @@ collect_view_construct_message(struct collect_view_data_msg *msg)
last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
rimeaddr_copy(&msg->parent, &shell_collect_conn.parent);
n = collect_neighbor_list_find(&shell_collect_conn.neighbor_list,
&shell_collect_conn.parent);
if(n != NULL) {
msg->parent_etx = collect_neighbor_link_estimate(n);
msg->parent_rtmetric = n->rtmetric;
} else {
msg->parent_etx = 0;
msg->parent_rtmetric = 0;
}
msg->num_neighbors = collect_neighbor_list_num(&shell_collect_conn.neighbor_list);
msg->beacon_interval = broadcast_announcement_beacon_interval() / CLOCK_SECOND;
rimeaddr_copy(&msg->parent, parent);
msg->parent_etx = parent_etx;
msg->parent_rtmetric = parent_rtmetric;
msg->num_neighbors = num_neighbors;
msg->beacon_interval = beacon_interval;
memset(msg->sensors, 0, sizeof(msg->sensors));
collect_view_arch_read_sensors(msg);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(collect_view_data_process, ev, data)
{
struct collect_view_data_msg msg;
PROCESS_BEGIN();
collect_view_construct_message(&msg);
shell_output(&collect_view_data_command, &msg, sizeof(msg), "", 0);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
collect_view_init(void)
{
shell_register_command(&collect_view_data_command);
}
/*---------------------------------------------------------------------------*/

View File

@ -3,6 +3,7 @@
#include "contiki-conf.h"
#include "net/rime/rimeaddr.h"
#include "net/rime/collect.h"
struct collect_view_data_msg {
uint16_t len;
@ -21,8 +22,12 @@ struct collect_view_data_msg {
uint16_t sensors[10];
};
void collect_view_init(void);
void collect_view_construct_message(struct collect_view_data_msg *msg);
void collect_view_construct_message(struct collect_view_data_msg *msg,
rimeaddr_t *parent,
uint16_t etx_to_parent,
uint16_t rtmetric_rtmetric,
uint16_t num_neighbors,
uint16_t beacon_interval);
void collect_view_arch_read_sensors(struct collect_view_data_msg *msg);

View File

@ -11,7 +11,7 @@ shell_src = shell.c shell-reboot.c \
shell-rime-unicast.c \
shell-tweet.c shell-base64.c \
shell-netperf.c shell-memdebug.c \
shell-powertrace.c
shell-powertrace.c shell-collect-view.c
shell_dsc = shell-dsc.c
APPS += webserver
@ -44,6 +44,10 @@ include $(CONTIKI)/apps/twitter/Makefile.twitter
APPS += powertrace
include $(CONTIKI)/apps/powertrace/Makefile.powertrace
APPS += collect-view
include $(CONTIKI)/apps/collect-view/Makefile.collect-view
ifeq ($(TARGET),sky)
shell_src += shell-sky.c shell-exec.c shell-sensortweet.c
endif

View File

@ -0,0 +1,88 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
* $Id: shell-collect-view.c,v 1.1 2010/10/20 15:21:43 adamdunkels Exp $
*/
/**
* \file
* Collect view client code
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "shell.h"
#include "collect-view.h"
#include "net/rime/broadcast-announcement.h"
/*---------------------------------------------------------------------------*/
PROCESS(collect_view_data_process, "collect-view-data");
SHELL_COMMAND(collect_view_data_command,
"collect-view-data",
"collect-view-data: sensor data, power consumption, network stats",
&collect_view_data_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(collect_view_data_process, ev, data)
{
struct collect_view_data_msg msg;
struct collect_neighbor *n;
uint16_t parent_etx, parent_rtmetric;
uint16_t num_neighbors;
uint16_t beacon_interval;
PROCESS_BEGIN();
n = collect_neighbor_list_find(&shell_collect_conn.neighbor_list,
&shell_collect_conn.parent);
if(n != NULL) {
parent_etx = collect_neighbor_link_estimate(n);
parent_rtmetric = n->rtmetric;
} else {
parent_etx = 0;
parent_rtmetric = 0;
}
num_neighbors = collect_neighbor_list_num(&shell_collect_conn.neighbor_list);
beacon_interval = broadcast_announcement_beacon_interval() / CLOCK_SECOND;
collect_view_construct_message(&msg, &shell_collect_conn.parent,
parent_etx, parent_rtmetric,
num_neighbors, beacon_interval);
shell_output(&collect_view_data_command, &msg, sizeof(msg), "", 0);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_collect_view_init(void)
{
shell_register_command(&collect_view_data_command);
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,48 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
* $Id: shell-collect-view.h,v 1.1 2010/10/20 15:21:43 adamdunkels Exp $
*/
/**
* \file
* Header file for CFS Coffee-specific Contiki shell commands
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef SHELL_COFFEE_H
#define SHELL_COFFEE_H
#include "shell.h"
void shell_collect_view_init(void);
#endif /* SHELL_COFFEE_H */

View File

@ -48,7 +48,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: shell.h,v 1.23 2010/10/12 11:34:49 adamdunkels Exp $
* $Id: shell.h,v 1.24 2010/10/20 15:21:43 adamdunkels Exp $
*/
/**
@ -356,6 +356,7 @@ struct shell_input {
#include "shell-base64.h"
#include "shell-blink.h"
#include "shell-checkpoint.h"
#include "shell-collect-view.h"
#include "shell-coffee.h"
#include "shell-download.h"
#include "shell-exec.h"