Code Search for Developers
 
 
  

tosnic_i.h from EmStar at Krugle


Show tosnic_i.h syntax highlighted

/*
 *
 * Copyright (c) 2005 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 "libmisc/misc.h"
#include "link/link.h"
#include "libevent/event.h"
#include "emrun/emrun.h"

#include "tosnic_status_types.h"

#define TOSH_DATA_LENGTH 0
#define PLATFORM_EMSTAR
#define PLATFORM_PC
#include "../tos-contrib/include/AM_emstar.h"

#ifndef __TOSNIC_I_H__
#define __TOSNIC_I_H__

enum {
  TOSNIC_MICA2=0,
  TOSNIC_MICA2DOT,
  TOSNIC_TELOS,
  TOSNIC_CRICKET,
  TOSNIC_MICA1
};

#define TOSNIC_MAX_CLIENTS   32
#define TOSNIC_PENDING_QUEUE_MAX  20

typedef struct tosnic_state tosnic_state_t; 
typedef void (* framer_notify_cb) (tosnic_state_t *s, int client_index, int type, buf_t *pkt);
typedef void (* framer_notify_ack_cb) (tosnic_state_t *s, int client_index, int type, buf_t *pkt, int acked);

typedef struct tosnic_client {
  int type;                       /* 0 to receive all traffic */
  framer_notify_cb handler;       /* handles arriving message (client frees) */
  framer_notify_ack_cb send_done; /* notify that message has gone out (system frees) */
  buf_t *on_deck;                 /* outgoing message for this client (system frees) */
  int type_on_deck;               /* type of outgoing message */
  char *description;
  int in_use;
  int index;                      /* in clients array */
} tosnic_client_t;

struct pending_send {
  uint8_t seqno;
  link_pkt_t hdr;
};

typedef struct status_entry {
  char *description;
  char *type;
  uint8_t index;
  uint8_t in_use:1;
  uint8_t read_only:1;
  uint8_t stale:1;
  uint8_t reserved:5;
  uint16_t parsed_type_code;
  buf_t *value;
} status_entry_t;

struct tosnic_state {

  /* command line configuration */
  char *dev_name;
  char *class_name;
  char *serial_devname;
  char *mote_type_str;
  char *mote_type_detected;
  int mote_type;
  int baud_requested;
  int power_requested;

  /* port/net configutation */
  char *hostname;
  int port_num;
  char *local_device;
  uint baud;
  int rtscts;

  /* event for upper interface */
  lp_context_t *lp;
  struct pending_send pending[TOSNIC_PENDING_QUEUE_MAX];
  int pending_queue_length;
  int pending_count;
  int packet_pending;
  uint8_t data_seqno;
  int data_client_index;
  uint8_t last_send_done;
  g_event_t *tx_watchdog;
  
  /* additional mote interfaces */
  status_context_t *mote_proto_status;
  pd_context_t *mote_raw_access;
  int raw_client_index;

  /* events reading from port/net */
  g_event_t *serial;
  int serial_fd;
  ev_tcp_peer_t *net_port;

  /* current interface status info */
  if_id_t if_id;
  uint MTU;
  uint power;
  uint channel;
  uint requested_power;
  char *trace;
  char *description;
  uint8_t default_group;

  /* last status struct for comparison */
  radio_stats_t last_radio_stats;
  int tosbase_version;

  /* status request state */
  g_event_t *periodic_status_req;
  int status_request_pending;
  int status_pending;
  int status_client_index;
  int config_client_index;

  /* reported status */
  status_entry_t status_entry[256];
  status_context_t *mote_app_status;

  /* interface performance stats */
  int serial_crc_fail;          /* total number of serial crc errors */
  int small_packet_fail;        /* total number of small packets dropped */
  int mote_to_pc_drops;         /* estimate of number packets dropped */
  int retrans_count;            /* number of times packets have been retransmitted */
  int retrans_ack_count;        /* number of times dup acks recd */
  int dup_send_done_count;      /* number of times dup send done recd */
  int dropped_send_done_count;  /* number of times dup send done recd */
  int spurious_send_done_count; /* number of times dup send done recd */
  int reset_count;              /* number of times mote/comm has been reset */
  int tx_watchdog_fires;        /* number of times watchdog fired */
  uint serial_rx_count;         /* low level serial byte counts */
  uint serial_tx_count;
  int serial_data_recd;         /* flags that indicate whether data is arriving */
  int serial_packet_recd;
  int mote_fail_warn;           /* indicates that mote may have failed */
  int mote_serial_crc_fail;     /* mote-side serial crc count */
  int mote_radio_crc_fail;      /* mote-side radio crc count */
  int mote_radio_queue_drops;   /* mote-side radio queue drop count */
  int mote_no_handler_drops;    /* mote-side drop due to no handler */

  
  /* framer state */
  tosnic_client_t demux[TOSNIC_MAX_CLIENTS];
  int curr_client_index;       /* current/next client */         
  int clients_count;           /* number of registered clients */         
  buf_t *current_buffer;       /* input data to deframe */

  g_event_t *ack_timeout;      /* send ack timer */
  int ack_timeout_length;      /* ack timeout duration */      
  buf_t *framed;               /* current framed outgoing */
  uint8_t type_of_framed;      /* type of current outgoing packet */
  uint8_t serial_seqno;        /* current serial sequence number */
  uint8_t last_mote_seqno;     /* last mote side serial sequence number */
  uint8_t msg_out;             /* a message is pending */
  int sequential_ack_fail;     /* counter for sequential failures */

  /* compatibility configuration options */
  uint tosbase_mode;
};


/* tosnic_upper.c */
void tosnic_upper_init(tosnic_state_t *s, int *argc, char **argv);
void tosnic_upper_push_to_clients(tosnic_state_t *s, buf_t *pkt);
void tosnic_upper_reset(tosnic_state_t *s);

void tosnic_upper_process_status_channel(tosnic_state_t *s, uint8_t channel);
void tosnic_upper_process_status_power(tosnic_state_t *s, uint8_t power);
void tosnic_upper_process_status_stats(tosnic_state_t *s, radio_stats_t *stats);

/* tosnic_lower.c */
int tosnic_lower_init(tosnic_state_t *s, int *argc, char **argv);
void tosnic_lower_write(tosnic_state_t *s, buf_t *framed);
int tosnic_lower_reset(tosnic_state_t *s);

/* tosnic_framer.c */
void tosnic_framer_enqueue_from_upper(tosnic_state_t *s, int client_index, int type, buf_t *pkt);
void tosnic_framer_data_from_lower(tosnic_state_t *s, buf_t *pkt);
int tosnic_framer_register(tosnic_state_t *s, tosnic_client_t *client_spec);
void tosnic_framer_reset(tosnic_state_t *s);

/* tosnic_forwarder.c */
void tosnic_fwd_init(tosnic_state_t *s, int *argc, char **argv);
void tosnic_fwd_push_to_clients(tosnic_state_t *s, buf_t *pkt);

/* tosnic_status.c */
void tosnic_status_init(tosnic_state_t *s, int *argc, char **argv);
 
/* tosnic_main.c */
void usage(char *name);
void tosnic_reset(tosnic_state_t *s);

#define TOSNIC_ACK_TIMEOUT    100
#define TOSNIC_READ_LEN       4096
#define TOSNIC_MAX_ACK_FAIL   5
#define TOSNIC_TX_WATCHDOG    1000
#define TOSNIC_STATUS_PERIOD  30000

#endif




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

  status_scheme.txt
  tosnic_framer.c
  tosnic_i.h
  tosnic_lower.c
  tosnic_main.c
  tosnic_status.c
  tosnic_status_types.h
  tosnic_upper.c