rudolph0.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup rime
00003  * @{
00004  */
00005 
00006 /**
00007  * \defgroup rudolph0 Single-hop reliable bulk data transfer
00008  * @{
00009  *
00010  * The rudolph0 module implements a single-hop reliable bulk data
00011  * transfer mechanism.
00012  *
00013  * \section channels Channels
00014  *
00015  * The rudolph0 module uses 2 channels; one for data packets and one
00016  * for NACK and repair packets.
00017  *
00018  */
00019 
00020 /*
00021  * Copyright (c) 2007, Swedish Institute of Computer Science.
00022  * All rights reserved.
00023  *
00024  * Redistribution and use in source and binary forms, with or without
00025  * modification, are permitted provided that the following conditions
00026  * are met:
00027  * 1. Redistributions of source code must retain the above copyright
00028  *    notice, this list of conditions and the following disclaimer.
00029  * 2. Redistributions in binary form must reproduce the above copyright
00030  *    notice, this list of conditions and the following disclaimer in the
00031  *    documentation and/or other materials provided with the distribution.
00032  * 3. Neither the name of the Institute nor the names of its contributors
00033  *    may be used to endorse or promote products derived from this software
00034  *    without specific prior written permission.
00035  *
00036  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00037  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00038  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00039  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00040  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00041  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00042  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00043  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00044  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00045  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  *
00048  * This file is part of the Contiki operating system.
00049  *
00050  * $Id: rudolph0.h,v 1.10 2008/06/30 08:28:53 adamdunkels Exp $
00051  */
00052 
00053 /**
00054  * \file
00055  *         Header file for the single-hop reliable bulk data transfer module
00056  * \author
00057  *         Adam Dunkels <adam@sics.se>
00058  */
00059 
00060 #ifndef __RUDOLPH0_H__
00061 #define __RUDOLPH0_H__
00062 
00063 #include "net/rime/stbroadcast.h"
00064 #include "net/rime/polite.h"
00065 
00066 struct rudolph0_conn;
00067 
00068 enum {
00069   RUDOLPH0_FLAG_NONE,
00070   RUDOLPH0_FLAG_NEWFILE,
00071   RUDOLPH0_FLAG_LASTCHUNK,
00072 };
00073 
00074 struct rudolph0_callbacks {
00075   void (* write_chunk)(struct rudolph0_conn *c, int offset, int flag,
00076                        uint8_t *data, int len);
00077   int (* read_chunk)(struct rudolph0_conn *c, int offset, uint8_t *to,
00078                      int maxsize);
00079 };
00080 
00081 #ifdef RUDOLPH0_CONF_DATASIZE
00082 #define RUDOLPH0_DATASIZE RUDOLPH0_CONF_DATASIZE
00083 #else
00084 #define RUDOLPH0_DATASIZE 64
00085 #endif
00086 
00087 struct rudolph0_hdr {
00088   uint8_t type;
00089   uint8_t version;
00090   uint16_t chunk;
00091 };
00092 
00093 struct rudolph0_datapacket {
00094   struct rudolph0_hdr h;
00095   uint8_t datalen;
00096   uint8_t data[RUDOLPH0_DATASIZE];
00097 };
00098 
00099 struct rudolph0_conn {
00100   struct stbroadcast_conn c;
00101   struct polite_conn nackc;
00102   const struct rudolph0_callbacks *cb;
00103   clock_time_t send_interval;
00104   uint8_t state;
00105   struct rudolph0_datapacket current;
00106 };
00107 
00108 void rudolph0_open(struct rudolph0_conn *c, uint16_t channel,
00109                    const struct rudolph0_callbacks *cb);
00110 void rudolph0_close(struct rudolph0_conn *c);
00111 void rudolph0_send(struct rudolph0_conn *c, clock_time_t interval);
00112 void rudolph0_stop(struct rudolph0_conn *c);
00113 
00114 /* Force the sender to restart sending the file from the start. */
00115 void rudolph0_force_restart(struct rudolph0_conn *c);
00116 
00117 void rudolph0_set_version(struct rudolph0_conn *c, int version);
00118 int rudolph0_version(struct rudolph0_conn *c);
00119 
00120 #endif /* __RUDOLPH0_H__ */
00121 /** @} */
00122 /** @} */
00123     

Generated on Mon Apr 11 14:23:31 2011 for Contiki 2.5 by  doxygen 1.6.1