00001 /** 00002 * \addtogroup rimeabc 00003 * @{ 00004 */ 00005 00006 00007 /* 00008 * Copyright (c) 2004, Swedish Institute of Computer Science. 00009 * All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions 00013 * are met: 00014 * 1. Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright 00017 * notice, this list of conditions and the following disclaimer in the 00018 * documentation and/or other materials provided with the distribution. 00019 * 3. Neither the name of the Institute nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00024 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00029 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00032 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00033 * SUCH DAMAGE. 00034 * 00035 * This file is part of the Contiki operating system. 00036 * 00037 * Author: Adam Dunkels <adam@sics.se> 00038 * 00039 * $Id: abc.c,v 1.20 2010/02/23 18:38:05 adamdunkels Exp $ 00040 */ 00041 00042 /** 00043 * \file 00044 * Anonymous best-effort local area Broad Cast (abc) 00045 * \author 00046 * Adam Dunkels <adam@sics.se> 00047 */ 00048 00049 #include "contiki-net.h" 00050 #include "net/rime.h" 00051 00052 00053 #define DEBUG 0 00054 #if DEBUG 00055 #include <stdio.h> 00056 #define PRINTF(...) printf(__VA_ARGS__) 00057 #else 00058 #define PRINTF(...) 00059 #endif 00060 00061 static const struct packetbuf_attrlist attributes[] = 00062 { ABC_ATTRIBUTES PACKETBUF_ATTR_LAST }; 00063 00064 /*---------------------------------------------------------------------------*/ 00065 void 00066 abc_open(struct abc_conn *c, uint16_t channelno, 00067 const struct abc_callbacks *callbacks) 00068 { 00069 channel_open(&c->channel, channelno); 00070 c->u = callbacks; 00071 channel_set_attributes(channelno, attributes); 00072 } 00073 /*---------------------------------------------------------------------------*/ 00074 void 00075 abc_close(struct abc_conn *c) 00076 { 00077 channel_close(&c->channel); 00078 } 00079 /*---------------------------------------------------------------------------*/ 00080 int 00081 abc_send(struct abc_conn *c) 00082 { 00083 PRINTF("%d.%d: abc: abc_send on channel %d\n", 00084 rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], 00085 c->channel.channelno); 00086 return rime_output(&c->channel); 00087 } 00088 /*---------------------------------------------------------------------------*/ 00089 void 00090 abc_input(struct channel *channel) 00091 { 00092 struct abc_conn *c = (struct abc_conn *)channel; 00093 PRINTF("%d.%d: abc: abc_input_packet on channel %d\n", 00094 rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], 00095 channel->channelno); 00096 00097 c->u->recv(c); 00098 } 00099 /*---------------------------------------------------------------------------*/ 00100 void 00101 abc_sent(struct channel *channel, int status, int num_tx) 00102 { 00103 struct abc_conn *c = (struct abc_conn *)channel; 00104 PRINTF("%d.%d: abc: abc_sent on channel %d\n", 00105 rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], 00106 channel->channelno); 00107 00108 if(c->u->sent) { 00109 c->u->sent(c, status, num_tx); 00110 } 00111 } 00112 /*---------------------------------------------------------------------------*/ 00113 00114 /** @} */