Contiki 3.x
stbroadcast.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Header file for the Rime module Stubborn Anonymous BroadCast (stbroadcast)
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43 */
44 
45 /**
46  * \defgroup rimestbroadcast Stubborn best-effort local area broadcast
47  * @{
48  *
49  * The stbroadcast module provides stubborn anonymous best-effort local area
50  * broadcast. A message sent with the stbroadcast module is repeated until
51  * either the message is canceled or a new message is sent. Messages
52  * sent with the stbroadcast module are not identified with a sender ID.
53  *
54  * \section channels Channels
55  *
56  * The stbroadcast module uses 1 channel.
57  *
58  */
59 
60 #ifndef STBROADCAST_H_
61 #define STBROADCAST_H_
62 
63 #include "sys/ctimer.h"
64 
65 #include "net/rime/broadcast.h"
66 #include "net/queuebuf.h"
67 
68 struct stbroadcast_conn;
69 
70 struct stbroadcast_callbacks {
71  void (* recv)(struct stbroadcast_conn *c);
72  void (* sent)(struct stbroadcast_conn *c);
73 };
74 
75 /**
76  * A stbroadcast connection. This is an opaque structure with no user-visible
77  * fields. The stbroadcast_open() function is used for setting up a stbroadcast
78  * connection.
79  */
81  struct broadcast_conn c;
82  struct ctimer t;
83  struct queuebuf *buf;
84  const struct stbroadcast_callbacks *u;
85 };
86 
87 
88 /**
89  * \brief Set up a stbroadcast connection.
90  * \param c A pointer to a user-supplied struct stbroadcast variable.
91  * \param channel The Rime channel on which messages should be sent.
92  * \param u Pointer to the upper layer functions that should be used
93  * for this connection.
94  *
95  * This function sets up a stbroadcast connection on the
96  * specified channel. No checks are made if the channel is
97  * currently used by another connection.
98  *
99  * This function must be called before any other function
100  * that operates on the connection is called.
101  *
102  */
103 void stbroadcast_open(struct stbroadcast_conn *c, uint16_t channel,
104  const struct stbroadcast_callbacks *u);
105 void stbroadcast_close(struct stbroadcast_conn *c);
106 
107 /**
108  * \brief Send a stubborn message.
109  * \param c A stbroadcast connection that must have been previously set up
110  * with stbroadcast_open()
111  * \param t The time between message retransmissions.
112  *
113  * This function sends a message from the Rime buffer. The
114  * message must have been previously constructed in the
115  * Rime buffer. When this function returns, the message
116  * has been copied into a queue buffer.
117  *
118  * If another message has previously been sent, the old
119  * message is canceled.
120  *
121  */
122 int stbroadcast_send_stubborn(struct stbroadcast_conn *c, clock_time_t t);
123 
124 /**
125  * \brief Cancel the current stubborn message.
126  * \param c A stbroadcast connection that must have been previously set up
127  * with stbroadcast_open()
128  *
129  * This function cancels a stubborn message that has
130  * previously been sent with the stbroadcast_send_stubborn()
131  * function.
132  *
133  */
134 void stbroadcast_cancel(struct stbroadcast_conn *c);
135 
136 
137 
138 /**
139  * \brief Set the retransmission time of the current stubborn message.
140  * \param c A stbroadcast connection that must have been previously set up
141  * with stbroadcast_open()
142  * \param t The new time between message retransmissions.
143  *
144  * This function sets the retransmission timer for the
145  * current stubborn message to a new value.
146  *
147  */
148 void stbroadcast_set_timer(struct stbroadcast_conn *c, clock_time_t t);
149 
150 #endif /* STBROADCAST_H_ */
151 
152 /** @} */
153 /** @} */
void stbroadcast_cancel(struct stbroadcast_conn *c)
Cancel the current stubborn message.
Definition: stbroadcast.c:115
Header file for the Rime queue buffer management
void stbroadcast_open(struct stbroadcast_conn *c, uint16_t channel, const struct stbroadcast_callbacks *u)
Set up a stbroadcast connection.
Definition: stbroadcast.c:64
Header file for the callback timer
void stbroadcast_set_timer(struct stbroadcast_conn *c, clock_time_t t)
Set the retransmission time of the current stubborn message.
Definition: stbroadcast.c:93
Header file for identified best-effort local area broadcast
A stbroadcast connection.
Definition: stbroadcast.h:80
int stbroadcast_send_stubborn(struct stbroadcast_conn *c, clock_time_t t)
Send a stubborn message.
Definition: stbroadcast.c:99