Contiki 2.5
abc.c
Go to the documentation of this file.
1 /**
2  * \addtogroup rimeabc
3  * @{
4  */
5 
6 
7 /*
8  * Copyright (c) 2004, Swedish Institute of Computer Science.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the Institute nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * This file is part of the Contiki operating system.
36  *
37  * Author: Adam Dunkels <adam@sics.se>
38  *
39  * $Id: abc.c,v 1.20 2010/02/23 18:38:05 adamdunkels Exp $
40  */
41 
42 /**
43  * \file
44  * Anonymous best-effort local area Broad Cast (abc)
45  * \author
46  * Adam Dunkels <adam@sics.se>
47  */
48 
49 #include "contiki-net.h"
50 #include "net/rime.h"
51 
52 
53 #define DEBUG 0
54 #if DEBUG
55 #include <stdio.h>
56 #define PRINTF(...) printf(__VA_ARGS__)
57 #else
58 #define PRINTF(...)
59 #endif
60 
61 static const struct packetbuf_attrlist attributes[] =
62  { ABC_ATTRIBUTES PACKETBUF_ATTR_LAST };
63 
64 /*---------------------------------------------------------------------------*/
65 void
66 abc_open(struct abc_conn *c, uint16_t channelno,
67  const struct abc_callbacks *callbacks)
68 {
69  channel_open(&c->channel, channelno);
70  c->u = callbacks;
71  channel_set_attributes(channelno, attributes);
72 }
73 /*---------------------------------------------------------------------------*/
74 void
75 abc_close(struct abc_conn *c)
76 {
77  channel_close(&c->channel);
78 }
79 /*---------------------------------------------------------------------------*/
80 int
81 abc_send(struct abc_conn *c)
82 {
83  PRINTF("%d.%d: abc: abc_send on channel %d\n",
85  c->channel.channelno);
86  return rime_output(&c->channel);
87 }
88 /*---------------------------------------------------------------------------*/
89 void
90 abc_input(struct channel *channel)
91 {
92  struct abc_conn *c = (struct abc_conn *)channel;
93  PRINTF("%d.%d: abc: abc_input_packet on channel %d\n",
95  channel->channelno);
96 
97  c->u->recv(c);
98 }
99 /*---------------------------------------------------------------------------*/
100 void
101 abc_sent(struct channel *channel, int status, int num_tx)
102 {
103  struct abc_conn *c = (struct abc_conn *)channel;
104  PRINTF("%d.%d: abc: abc_sent on channel %d\n",
106  channel->channelno);
107 
108  if(c->u->sent) {
109  c->u->sent(c, status, num_tx);
110  }
111 }
112 /*---------------------------------------------------------------------------*/
113 
114 /** @} */