Code Search for Developers
 
 
  

sympathy_emview.c from EmStar at Krugle


Show sympathy_emview.c syntax highlighted

/* ex: set tabstop=2 expandtab shiftwidth=2 softtabstop=2: */
/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University 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 REGENTS 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 REGENTS 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.
 *
 */

 /*
  *
  * Author: Nithya Ramanthan
  *
  */

/* NR TODO:
 * cache data from nodes in addition to configuration */

#include "sympathy.h"
#include <emproxy/emproxy.h>
#include <emrun/emrun.h>
#include <routing/routing_table.h>

buf_t* emview_cmd=NULL;
buf_t* sink_cmd=NULL;
static void sympathy_push_radio(sympathy_node_info_t* stat);

void sympathy_update_emview(if_id_t node_id)
{
  if ((node_id == my_node_id) && sink_cmd) {
    emproxy_emit_buf_to_gw(EMRUN_EMVIEW_CONFIG_DEVNAME,
      node_id, NULL, sink_cmd);
  }
  else if (emview_cmd) {
    emproxy_emit_buf_to_gw(EMRUN_EMVIEW_CONFIG_DEVNAME,
      node_id, NULL, emview_cmd);
  }
}

static
int se_push_emview(void *data, int interval, g_event_t *ev)
{
  int i;
  sympathy_node_info_t* stat;

  /* USe to test nodes that are added which don't necessarily exist
  static int ctr = 0;
  if (ctr == 5)  sympathy_update_emview(100);
  ctr++;
  */

  for (i=0; i<sink.num_srcs; i++) {
    stat = &sink.status_srcs[i];

    /* NR Even with caching - need to update this regularly? */
    sympathy_push_radio(stat);
    sympathy_emview_text(stat);
    sympathy_emview_route(stat);
    sympathy_emview_neighbors(stat);
  }
  return TIMER_RENEW;
}


static
void sympathy_push_emview(char* device, if_id_t src, buf_t* buf)
{
  struct timeval now;
  gettimeofday(&now, NULL);
  emproxy_emit_buf_to_gw(sim_path(device), src, &now, buf);
}

static
void sympathy_push_radio(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  link_status_t info = {
    if_id: (if_id_t) stat->addr,
  };
  bufcpy(buf, &info, sizeof(info));
  sympathy_push_emview(SYMPATHY_EMVIEW_RADIO, stat->addr, buf);
  buf_free(buf);
}


/* GLOBAL FUNCTIONS */
void sympathy_emview_text(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  buf_t* buf2 = buf_new();

  /* If there is a failure, then set the node to a color, and print the
   * text status. Otherwise, do not print anything */
  if (stat->failure_type == SFL_OK) {
    bufcpy(buf, "", 1);
    bufprintf(buf2, "white");
  }
  else {
    bufprintf(buf, "%s(%d pds)\n", decode_root_cause(stat->failure_root_cause,
          stat->addr), sink.metric_pd - stat->period_root_caused);
    bufprintf(buf2, "red");
  }

  sympathy_push_emview(SYMPATHY_EMVIEW_TEXTSTATUS, stat->addr, buf);
  sympathy_push_emview(SYMPATHY_EMVIEW_COLOR, stat->addr, buf2);

  buf_free(buf);
  buf_free(buf2);
}

void sympathy_emview_route(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  route_entry_t null_r = {};
  route_entry_t r = {
    dst: stat->next_hop.sink,
    next_hop: stat->next_hop.next_hop,
    path_metric: stat->next_hop.quality
  };

  if (route_valid(stat)) {
    bufcpy(buf, (char*)&r, sizeof(route_entry_t));

    /* Add a "null" neighbor to the end in case they didnt */
    bufcpy(buf, (char*)&null_r, sizeof(route_entry_t));
  }
  else bufcpy(buf, "", 1);

  sympathy_push_emview(SYMPATHY_EMVIEW_ROUTE, stat->addr, buf);
  buf_free(buf);
}

void sympathy_emview_neighbors(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  neighbor_t null_n = {};

  if (neighbors_valid(stat)) {
    bufcpy(buf, stat->neighbors, stat->num_neighbors*sizeof(neighbor_t));

    /* Add a "null" neighbor to the end in case they didnt */
    bufcpy(buf, (char*)&null_n, sizeof(neighbor_t));
  }
  else bufcpy(buf, "", 1);

  sympathy_push_emview(SYMPATHY_EMVIEW_NEIGHBORS, stat->addr, buf);

  buf_free(buf);
}

void sympathy_init_emview()
{
  emview_cmd = buf_new();
  sink_cmd = buf_new();
  se_push_emview(NULL,0,NULL);
  g_timer_add(10000, se_push_emview, NULL, NULL, NULL);

  /* Radio interface */
  bufprintf(emview_cmd, "module=Link/Radio:dev=%s,%s:core\n", 
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_RADIO);
  bufprintf(sink_cmd, "module=Link/Radio:dev=%s,%s:core\n", 
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_RADIO);

  /* Initialize neighbors device */
  bufprintf(emview_cmd, "module=Link/Neighbors:dev=%s,%s:links=alive,0,1,black,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_NEIGHBORS);
  bufprintf(sink_cmd, "module=Link/Neighbors:dev=%s,%s:links=alive,0,1,black,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_NEIGHBORS);

  /* Initialize routing device */
  bufprintf(sink_cmd, "module=Routing/Trees:dev=%s,%s:dest-tree=blue,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_ROUTE);
  bufprintf(emview_cmd, "module=Routing/Trees:dev=%s,%s:leaf\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_ROUTE);

  /* Initialize color box device */
  bufprintf(sink_cmd, "module=ColorStatus:dev=%s,%s:core:component=Link/Radio/%s\n",
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_COLOR, SYMPATHY_EMVIEW_INTERFACE);
  bufprintf(emview_cmd, "module=ColorStatus:dev=%s,%s:core:component=Link/Radio/%s\n",
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_COLOR, SYMPATHY_EMVIEW_INTERFACE);

  /* Initialize text-status device */
  bufprintf(emview_cmd, "module=TextStatus:dev=%s,%s:core\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_TEXTSTATUS);
  bufprintf(sink_cmd, "module=TextStatus:dev=%s,%s:core\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_TEXTSTATUS);
}




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  bayes/
    lib/
      libnetica.a
    src/
      Netica.h
      NeticaEx.c
      NeticaEx.h
    bayes_classifier.c
    nodes.states
    training.prob
  include/
    sympathy.h
    sympathy_app.h
    sympathy_dev.h
    sympathy_routing.h
  libsympathy/
    sympathy_routing.c
  scripts/
    get_recent_status.pl
    get_throughput.pl
  testtabs/
    essjr.run
    essjr_sensor.run
    rr_mote.run
    rr_mote_ceiling.run
    sympathy.run
    sympathy_ceiling.sim
    sympathy_sim.sim
    sympathy_sim_small.sim
    sympathy_snoop.run
    sympathy_test.sim
  BUILD
  data.xml
  jr_loc_small
  sars.pl
  sympathy_analyze.c
  sympathy_battery.c
  sympathy_device.c
  sympathy_doc
  sympathy_emview.c
  sympathy_events.c
  sympathy_main.c
  sympathy_print_stats.c
  sympathy_status.c