Smeshlink / MxRadioRF2xx

Dependents:   xBedRadio MxSniffer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MxRadio_Events.cpp Source File

MxRadio_Events.cpp

00001 /* Copyright (c) 2011 Frank Zhao
00002    All rights reserved.
00003 
00004    Redistribution and use in source and binary forms, with or without
00005    modification, are permitted provided that the following conditions
00006    are met:
00007 
00008  * Redistributions of source code must retain the above copyright
00009      notice, this list of conditions and the following disclaimer.
00010  * Redistributions in binary form must reproduce the above copyright
00011      notice, this list of conditions and the following disclaimer in the
00012      documentation and/or other materials provided with the distribution.
00013  * Neither the name of the authors nor the names of its contributors
00014      may be used to endorse or promote products derived from this software
00015      without specific prior written permission.
00016 
00017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027    POSSIBILITY OF SUCH DAMAGE. */
00028 
00029 #include "MxRadio.h"
00030 
00031 
00032 void (*user_radio_error)(radio_error_t) = 0;
00033 void (*user_radio_irq)(uint8_t) = 0;
00034 uint8_t* (*user_radio_receive_frame)(uint8_t, uint8_t*, uint8_t,int8_t, uint8_t) = 0;
00035 void (*user_radio_tx_done)(radio_tx_done_t) = 0;
00036 
00037 void cMxRadio::zr_attach_error(void (*funct)(radio_error_t))
00038 {
00039     user_radio_error = funct;
00040 }
00041 
00042 void cMxRadio::zr_attach_irq(void (*funct)(uint8_t))
00043 {
00044     user_radio_irq = funct;
00045 }
00046 
00047 void cMxRadio::zr_attach_receive_frame(uint8_t* (cMxRadio::*funct)(uint8_t, uint8_t*, uint8_t, int8_t, uint8_t))
00048 {
00049     user_radio_receive_frame = funct;
00050 }
00051 
00052 void cMxRadio::zr_attach_tx_done(void (cMxRadio::*funct)(radio_tx_done_t))
00053 {
00054     user_radio_tx_done = funct;
00055 }
00056 void cMxRadio::usr_radio_error(radio_error_t err)
00057 {
00058     if (user_radio_error) user_radio_error(err);
00059 }
00060 
00061 void cMxRadio::usr_radio_irq(uint8_t cause)
00062 {
00063     if (user_radio_irq) user_radio_irq(cause);
00064 }
00065 
00066 uint8_t* cMxRadio::usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, int8_t ed,uint8_t crc_fail)
00067 {
00068     if (user_radio_receive_frame)
00069         return (this->*user_radio_receive_frame)(len, frm, lqi,ed, crc_fail);
00070     else return frm;
00071 }
00072 
00073 void cMxRadio::usr_radio_tx_done(radio_tx_done_t status)
00074 {
00075     if (user_radio_tx_done) (this->*user_radio_tx_done)(status);
00076 }