DRV802_15_4.h
Go to the documentation of this file.00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2008-2010 00004 * Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de> 00005 * Thomas Kiebel <kiebel@ivs.cs.uni-magdeburg.de> 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * * Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * * Neither the name of the copyright holders nor the names of 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00026 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00027 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00028 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00029 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00030 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00031 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00032 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00033 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00034 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00035 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 * 00038 * $Id$ 00039 * 00040 ******************************************************************************/ 00041 00042 #ifndef __DRV802_15_4_h__ 00043 #define __DRV802_15_4_h__ 00044 00045 #include "case/Delegate.h" 00046 #include "debug.h" 00047 00048 namespace device { 00049 namespace nic { 00050 namespace ieee802_15_4 { 00051 00064 template <class RFLayer> 00065 class DRV802_15_4 { 00066 public: 00068 typedef DRV802_15_4 type; 00070 typedef wsn::dll::mac::MACReceiveData mob_t; 00071 private: 00072 RFLayer _rflayer; 00073 00078 void rfReceiveCallback(const mob_t& rxData) { 00079 // trigger interrupt after receiving data 00080 //TODO if ( !(rx_Interrupt.isEmpty()) ) { 00081 if ( rx_Interrupt ) { 00082 rx_Interrupt(rxData); 00083 } 00084 } 00085 00088 void rfErrorCallback(const wsn::dll::mac::ErrorData<uint8_t>& errData) { 00089 //TODO need there be an action if the error callback is triggered? 00090 } 00091 00092 public: 00093 DRV802_15_4() {} 00094 ~DRV802_15_4() {} 00095 00101 void init() { 00102 // Register our receive callback at the MAC layer object 00103 _rflayer.rx_Interrupt.template bind<type, &type::rfReceiveCallback>(this); 00104 // Register our error callback at the MAC layer object 00105 _rflayer.error_Interrupt.template bind<type, &type::rfErrorCallback>(this); 00106 00107 _rflayer.init(SHORT_ADDR, PAN_ID, COMM_CHANNEL); 00108 } 00109 00118 void send(const uint8_t* buffer, uint8_t size) { 00119 TRACE_FUNCTION; 00120 // asserts if data size corresponds to payload size of communication layer 00121 if ( size > _rflayer.getMaxPayload() ) { 00122 ::logging::log::emit< ::logging::Error>() 00123 << PROGMEMSTRING("Payload size violation sending DATA RF") 00124 << ::logging::log::endl; 00125 return; 00126 } 00127 00128 // transmit buffer 00129 if (!(_rflayer.send(buffer, size, DESTINATION))) { 00130 ::logging::log::emit< ::logging::Error>() 00131 << PROGMEMSTRING("MAC transmission failed!") 00132 << ::logging::log::endl; 00133 //TODO need there be an error response if transmission failed? 00134 } 00135 } 00136 00139 famouso::util::Delegate<const mob_t&> rx_Interrupt; 00140 00146 famouso::util::Delegate<> tx_Interrupt; 00147 }; 00148 } /* namespace ieee802_15_4 */ 00149 } /* namespace nic */ 00150 } /* namespace device */ 00151 00152 #endif 00153