Code Search for Developers
 
 
  

libssync_types.c from EmStar at Krugle


Show libssync_types.c syntax highlighted

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

#include "ssync.h"
#include "libmisc/misc.h"
#include "link/link.h"
#include "devel/state/cluster_map.h"

/*
 *  A simple type for workload testing purposes...
 */

SSYNC_PUB_TYPESAFE_FUNCS(workload,wl_info_t);

void workload_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  wl_info_t *wl = (wl_info_t *)entry;
  bufprintf(buf, "%skey:", indent);
  buf_print_raw(buf, wl->key, sizeof(wl->key));
  bufprintf(buf, ", seq: %d, data: ", wl->app_seq);
  buf_print_raw(buf, wl->data, sizeof(wl->data));
  bufprintf(buf, "\n");
}


/*
 *  Cluster info type
 */

SSYNC_PUB_TYPESAFE_FUNCS(cluster,cluster_info_t);

void cluster_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  cluster_info_t *cl = (cluster_info_t *)entry;
  bufprintf(buf, "%sIndex: %s, NodeID: %s, ", indent,
	    cluster_map_index_to_str(cl->index),
	    print_if_id(cl->node_id));
  bufprintf(buf, "IfaceID: %s\n", print_if_id(cl->if_id));
}


// leader entry type
SSYNC_PUB_TYPESAFE_FUNCS(le_entry, le_entry_t);
void le_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
    if (entry == NULL) return;
    le_entry_t *le = (le_entry_t *)entry;
    bufprintf(buf, "%sMicroserver %s: TID=%lld, requester=%s\n",
            indent, print_if_id(le->my_id), le->tid, 
            print_if_id(le->querier_id));
}

/*
 * Flock entry type
 */


SSYNC_PUB_TYPESAFE_FUNCS(flock_member_entry, flock_member_entry_t);

void flock_member_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  flock_member_entry_t *re = (flock_member_entry_t *)entry;
  bufprintf(buf, "%sMote %s: seqno %u, state %d:, etx %3.2f\n",
	    indent, print_if_id(re->uid),
	    re->seqnum, re->state, re->etx);
}

// herd data entry type

SSYNC_PUB_TYPESAFE_FUNCS(herd_data_entry, herd_data_entry_t);

void herd_data_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  herd_data_entry_t *re = (herd_data_entry_t *)entry;
  bufprintf(buf, "%sMote %s: rcvd %u, ttx %u, acks %u, lost %u\n",
	    indent, print_if_id(re->uid),
            re->pkts_rcvd,
            re->total_tx,
            re->acks_sent,
            re->pkts_lost);
}

// herd reg entry type

SSYNC_PUB_TYPESAFE_FUNCS(herd_res_entry, herd_res_entry_t);

void herd_res_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  herd_res_entry_t *re = (herd_res_entry_t *)entry;
  bufprintf(buf, "%sMote %s: loc = %2.2f, %2.2f, %2.2f\n",
	    indent, print_if_id(re->node_id),
            re->location.x,
            re->location.y,
            re->location.z);
}

/*
 *  Interest entry
 *  Used by the sink tree implementation
 */        

SSYNC_PUB_TYPESAFE_FUNCS(interest,interest_entry_t);

void interest_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  interest_entry_t *re = (interest_entry_t *)entry;
  bufprintf(buf, "%sInterestType: %x\n", indent, re->interest_type);
}

/*
 *  Flow info types
 */

SSYNC_PUB_TYPESAFE_FUNCS(flow_map,flow_map_t);
SSYNC_PUB_TYPESAFE_FUNCS(flow_status,flow_status_t);

void flow_map_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  flow_map_t *cl = (flow_map_t *)entry;
  bufprintf(buf, "%sIndex: %d, FlowID: %s\n",
	    indent, cl->flow_index, ssync_flowid_to_str(&(cl->flow_id)));
}

void flow_status_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  flow_status_t *cl = (flow_status_t *)entry;
  bufprintf(buf, "%sIndex: %d, Seqno: %x,%u, HopsRemain: %d, Parent: %s\n",
	    indent, cl->flow_index, cl->log_index, cl->seqno, cl->hops_remain,
	    cluster_map_index_to_str(cl->parent));
}


/*
 *  Range Entry
 */


SSYNC_PUB_TYPESAFE_FUNCS(range_entry,range_entry_t);

void range_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  range_entry_t *re = (range_entry_t *)entry;
  bufprintf(buf, "%sFrom %s: %.3fm [%.1f], azi %.1f, zen %.1f [%.1f], seqno=%u\n",
	    indent, print_if_id(re->source),
	    re->distance / 1000.0, re->conf / 10.0,
	    re->theta / 10.0, re->phi / 10.0, re->a_conf / 10.0, re->seqno % 256);
}


/*
 *  Coord Entry
 */


SSYNC_PUB_TYPESAFE_FUNCS(coord_entry,coord_entry_t);

void coord_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  coord_entry_t *re = (coord_entry_t *)entry;
  bufprintf(buf, "%s%15s  %10.3f  %10.3f  %10.3f  %5.1f  %5.1f  %5.1f %s\n",
	    indent, print_if_id(re->node),
	    re->coord[0] / 1000.0,
	    re->coord[1] / 1000.0,
	    re->coord[2] / 1000.0,
	    re->rpy[0] / 10.0,
	    re->rpy[1] / 10.0,
	    re->rpy[2] / 10.0,
	    re->valid ? "" : "**STALE**");
}


/*
 *  compressed proxy stuff 
 */

SSYNC_PUB_TYPESAFE_FUNCS(cp_link_state,cp_link_state_t);
SSYNC_PUB_TYPESAFE_FUNCS(cp_neighbor_entry,cp_neighbor_entry_t);

void cp_neigh_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  cp_neighbor_entry_t *n = (cp_neighbor_entry_t *)entry;
  if (n->bidirectional!=0) {
      // if bidirectional is set, use the extra fields
    bufprintf(buf, "%s%s--%s[%d], %3d%%   %3d%%\n",
	    indent, print_if_id(n->src_if_id), 
            print_if_id(n->dst_if_id), n->link_index, 
            n->quality, n->out_quality);
  } else {
    bufprintf(buf, "%s%s[%d], %d%%\n",
	    indent, 
            print_if_id(n->dst_if_id), n->link_index, 
            n->quality);
  }

}

void cp_link_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  cp_link_state_t *n = (cp_link_state_t *)entry;
  bufprintf(buf, "%s%d: %s, %d rx %d tx\n",
	    indent, n->link_index, print_if_id(n->if_id),
	    n->bytes_rx, n->bytes_tx);
}


/*
 *  Fault logging (see emrun/fault_logger.h)
 */

SSYNC_PUB_TYPESAFE_FUNCS(fault_entry,fault_entry_t);

void fault_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  fault_entry_t *n = (fault_entry_t *)entry;
  bufprintf(buf, "%s%d: %s reported %s, time %ld.%06ld\n",
	    indent, n->index, n->fault_proc, n->fault_info,  n->timestamp.tv_sec, n->timestamp.tv_usec);
}

/*
 * Martin's filemover sink tree
 */
// SSYNC_PUB_TYPESAFE_FUNCS(sink_tree, sink_tree_t);


/*
 * DTS sequence number table
 */
SSYNC_PUB_TYPESAFE_FUNCS(dts_sequence_numbers, dts_sequence_number_t);

/*
 * The filemover entries of what files to delete
 */
SSYNC_PUB_TYPESAFE_FUNCS(filemover_deleter, filemover_deleter_t);

/*
 * AENSBox Network Control
 */

SSYNC_PUB_TYPESAFE_FUNCS(netrec,aensbox_net_control_t);

void netrec_entry_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) {
    bufprintf(buf, 
	      "%sNomSRate SRate    ExtFlash OnBoard  Remote   Load     Seqno    AppMode     GPS_SEC RPid  Stat Levels      Flags\n"
	      "%s-------- -------- -------- -------- -------- -------- -------- -------- ---------- ----- ---- ----------- -------\n",
	      indent, indent);
    return;
  }
  
  aensbox_net_control_t *ptr = (aensbox_net_control_t *)entry;
  
  char *appmode;
  switch (ptr->application_mode) {
  case NETREC_APP_OFF: appmode = "Off"; break;
  case NETREC_APP_RECORDING: appmode = "Record"; break;
  case NETREC_APP_DETECTOR: appmode = "Detect"; break;
  default: appmode = "*INV*"; break;
  }

  char remote_state[9];
  switch (ptr->remote_storage.status) {
  default:
  case REMOTE_UNK:
    strcpy(remote_state, "Unknown"); break;
  case REMOTE_NOCARD:
    strcpy(remote_state, "No Card"); break;
  case REMOTE_NOMOUNT:
    strcpy(remote_state, "No Mount"); break;
  case REMOTE_READY:
    sprintf(remote_state, "%8.1f", ptr->remote_storage.avail / 10.0);
  }

  bufprintf(buf, 
	    "%s%8d %8d %8.1f %8.1f %8s %8.2f %8d %8s %10d %5d %4x %02d/%02d/%02d/%02d %s, %s\n",
	    indent,
	    ptr->nominal_sample_rate,
	    ptr->sample_rate,
	    ptr->external_flash_MB / 10.0,
	    ptr->onboard_flash_MB / 10.0,
	    remote_state,
	    ptr->load_avg / 100.0,
	    ptr->seqno,
	    appmode,
	    ptr->gps_seconds,
	    ptr->record_pid,
	    ptr->last_status,
	    ptr->levels[0],
	    ptr->levels[1],
	    ptr->levels[2],
	    ptr->levels[3],
	    ptr->have_sync ? "Sync OK" : "***NO SYNC***",
	    ptr->am_master ? "Master" : "Slave");
}


/*
 *  Default unparse
 */

void libssync_default_unparse(buf_t *buf, void *entry, int len, char *indent)
{
  if (entry == NULL) return;
  misc_hexdump_to_buf(buf, (char*)entry, len, indent);
  bufprintf(buf, "\n");
}

/*
 *  Human readable "unparse" functions
 */

typedef struct ssync_unparse_table {
  ssync_type_t type;
  ssync_unparse_cb_t cb;
} ssync_unparse_table_t;


static ssync_unparse_table_t ssync_unparse_funcs[] = {
  {
    type: {
      fixed_len: sizeof(fault_entry_t),
      key_len: sizeof(uint16_t),
      type: "fault"
    },
    cb: fault_entry_unparse
  },
  {
    type: {
      fixed_len: sizeof(wl_info_t),
      key_len: 4,
      type: "wl"
    },
    cb: workload_unparse
  },
  {
    type: {
      fixed_len: sizeof(cluster_info_t),
      key_len: 1,
      type: "cluster"
    },
    cb: cluster_unparse
  },
  {
    type: {
      fixed_len: sizeof(flow_map_t),
      key_len: 1,
      type: "flow_map"
    },
    cb: flow_map_unparse
  },
  {
    type: {
      fixed_len: sizeof(flow_status_t),
      key_len: 1,
      type: "flow_stat"
    },
    cb: flow_status_unparse
  },
  {
    type: {
      fixed_len: sizeof(range_entry_t),
      key_len: sizeof(node_id_t),
      type: "range"
    },
    cb: range_entry_unparse
  },
  {
    type: {
      fixed_len: sizeof(coord_entry_t),
      key_len: sizeof(node_id_t),
      type: "coord"
    },
    cb: coord_entry_unparse
  },
  {
    type: {
      fixed_len: sizeof(interest_entry_t),
      key_len: sizeof(interest_entry_t),
      type: "interest"
    },
    cb: interest_entry_unparse
  },
  {
    type: {
      fixed_len: sizeof(flock_member_entry_t),
      key_len: sizeof(node_id_t),
      type: "flock"
    },
    cb: flock_member_entry_unparse
  },
  {
    type: {
      fixed_len: sizeof(herd_data_entry_t),
      key_len: sizeof(node_id_t),
      type: "herd"
    },
    cb: herd_data_entry_unparse
  },
  {
    type: {
      fixed_len: sizeof(cp_neighbor_entry_t),
      key_len: sizeof(if_id_t)*2+1,
      type: "cp_neigh"
    },
    cb: cp_neigh_unparse
  },
  {
    type: {
      fixed_len: sizeof(cp_link_state_t),
      key_len: 1,
      type: "cp_link"
    },
    cb: cp_link_unparse
  },
  {
    type: {
      fixed_len: sizeof(aensbox_net_control_t),
      key_len: 0,
      type: "netrec"
    },
    cb: netrec_entry_unparse
  },
  {}      
};


ssync_unparse_cb_t ssync_lookup_unparse(ssync_type_t *type)
{
  int i;
  for (i=0; ssync_unparse_funcs[i].cb; i++) {
    if (memcmp(&(ssync_unparse_funcs[i].type), type, sizeof(type)) == 0)
      return ssync_unparse_funcs[i].cb;
  }
  return libssync_default_unparse;
}





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

  libssync_name.c
  libssync_pub.c
  libssync_types.c