Contiki-Inga 3.x
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  */
40 
41 /**
42  * \file
43  * Anonymous best-effort local area Broad Cast (abc)
44  * \author
45  * Adam Dunkels <adam@sics.se>
46  */
47 
48 #include "contiki-net.h"
49 #include "net/rime/rime.h"
50 
51 
52 #define DEBUG 0
53 #if DEBUG
54 #include <stdio.h>
55 #define PRINTF(...) printf(__VA_ARGS__)
56 #else
57 #define PRINTF(...)
58 #endif
59 
60 static const struct packetbuf_attrlist attributes[] =
61  { ABC_ATTRIBUTES PACKETBUF_ATTR_LAST };
62 
63 /*---------------------------------------------------------------------------*/
64 void
65 abc_open(struct abc_conn *c, uint16_t channelno,
66  const struct abc_callbacks *callbacks)
67 {
68  channel_open(&c->channel, channelno);
69  c->u = callbacks;
70  channel_set_attributes(channelno, attributes);
71 }
72 /*---------------------------------------------------------------------------*/
73 void
74 abc_close(struct abc_conn *c)
75 {
76  channel_close(&c->channel);
77 }
78 /*---------------------------------------------------------------------------*/
79 int
80 abc_send(struct abc_conn *c)
81 {
82  PRINTF("%d.%d: abc: abc_send on channel %d\n",
84  c->channel.channelno);
85  return rime_output(&c->channel);
86 }
87 /*---------------------------------------------------------------------------*/
88 void
89 abc_input(struct channel *channel)
90 {
91  struct abc_conn *c = (struct abc_conn *)channel;
92  PRINTF("%d.%d: abc: abc_input_packet on channel %d\n",
94  channel->channelno);
95 
96  if(c->u->recv) {
97  c->u->recv(c);
98  }
99 }
100 /*---------------------------------------------------------------------------*/
101 void
102 abc_sent(struct channel *channel, int status, int num_tx)
103 {
104  struct abc_conn *c = (struct abc_conn *)channel;
105  PRINTF("%d.%d: abc: abc_sent on channel %d\n",
107  channel->channelno);
108 
109  if(c->u->sent) {
110  c->u->sent(c, status, num_tx);
111  }
112 }
113 /*---------------------------------------------------------------------------*/
114 
115 /** @} */