Code Search for Developers
 
 
  

sympathy_print_stats.c from EmStar at Krugle


Show sympathy_print_stats.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
  *
  */


#include <sympathy.h>
/* This is the example code for printing generic stats out! */

typedef struct _mdtnsym{
  uint16_t my_stored_pkt_count;
  uint16_t others_stored_pkt_count;
  uint16_t current_pkts_stored;    
  uint32_t bytesUsed;
} __attribute__ ((packed)) mDTN_Sym_t;

lu_context_t* comp_status;

/* Component has translated the binar struct from the component -
 * in this case it is from mDTN, and is sending back the ascii
 * translaction. THIS WILL NOT work if the mDTN module is not
 * wired in on the node side! */
static
void send_stats_pkt(link_pkt_t* pkt, buf_t* data_buf)
{
  buf_t* buf = buf_new();
  pkt->dst.id = LINK_BROADCAST;
  pkt->type = SCOMP_ASCII_STATS;

  bufcpy(buf, pkt, sizeof(link_pkt_t));
  bufcpy(buf, data_buf->buf, data_buf->len);

  elog(LOG_DEBUG(1), "buflen: %d\n", buf->len);
  if (lu_send(comp_status, (link_pkt_t *)buf->buf, buf->len - sizeof(link_pkt_t)) < 0)
  {
    elog(LOG_ERR, "Unable to send pkt: %m!\n");
  }
  buf_free(buf);
}

static 
void translate_comp3(link_pkt_t* pkt)
{
  buf_t* buf = buf_new();
  mDTN_Sym_t* d = (mDTN_Sym_t*) pkt->data;

  bufprintf(buf, "Reliability Stats: My Pkt Stored, Other Pkts Stored, Current Stored, Bytes Used \n &*& %d,%d,%d,%d,%d  \n",
	  pkt->src.id, d->my_stored_pkt_count, d->others_stored_pkt_count, d->current_pkts_stored, d->bytesUsed);
  elog(LOG_DEBUG(1), "buf: %s\n", buf->buf);

  /* Send the packet to sympathy */
  send_stats_pkt(pkt, buf);
  buf_free(buf);
}

static
int status_receive(lu_context_t* lu, link_pkt_t* pkt, ssize_t data_len)
{
  elog(LOG_DEBUG(3), "src %d, Pkt w type/comp: %d/%d, datalen: %d\n",
          pkt->src.id, pkt->type, pkt->ext_type, data_len);

  /* Call print funcs! */
  switch(pkt->type) {
    case (SCOMP_STATS):
      if (pkt->ext_type == SCOMP_STATS3_GEN) {
	translate_comp3(pkt);
      }
      break;
    default:
      elog(LOG_DEBUG(3), "Ignoring pkt type %d\n", pkt->type);
      break;
  }

  g_free(pkt);
  return EVENT_RENEW;
}

static
void sympathy_shutdown(void *data)
{
  elog(LOG_NOTICE, "sympathy-sink shutting down");
  exit(0);
}

int main(int argc, char **argv)
{
  emrun_opts_t emrun_opts = {
    shutdown: sympathy_shutdown,
    silent: 1
  };

  /* generic initialization common to all programs */
  misc_init(&argc, argv, CVSTAG);

  /* Link-user to pass status between components on the sink */
  {
    lu_opts_t lopts = {
      opts: {
        name: SYMPATHY_STATS_DEVICE,
        pkt_type: PKT_TYPE_ALL
      },
      receive: status_receive
    };
    if (lu_open(&lopts, &comp_status) < 0)
    {
      elog(LOG_ERR, "UNable to open status device: %s: %m!\n",
        lopts.opts.name);
      exit(1);
    }
    elog(LOG_DEBUG(1), "Opened device: %s\n", lopts.opts.name);
  }

  emrun_init(&emrun_opts); 
  g_main();
  elog_g(LOG_CRIT, "event loop terminated abnormally!");
  return 0;
}




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