From 45fe53697945acfe624c46264fddb26a28fd614a Mon Sep 17 00:00:00 2001 From: Pkarc Date: Sat, 17 Dec 2011 01:31:52 -0500 Subject: [PATCH] Implements "much easier to use" as KarlP said in his blog, and some functions to get only the relatively "important data bytes --- mrf24j.h | 90 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 32 deletions(-) diff --git a/mrf24j.h b/mrf24j.h index dc55949..a4550fb 100644 --- a/mrf24j.h +++ b/mrf24j.h @@ -1,4 +1,4 @@ -/* +/* * File: mrf24j.h * copyright Karl Palsson, karlp@tweak.net.au, 2011 * modified BSD License / apache license @@ -7,7 +7,11 @@ #ifndef LIB_MRF24J_H #define LIB_MRF24J_H -#include "WProgram.h" +#if defined(ARDUINO) && ARDUINO >= 100 // Arduino IDE version >= 1.0 + #include "Arduino.h" +#else // older Arduino IDE versions + #include "WProgram.h" +#endif #include "SPI.h" @@ -143,52 +147,74 @@ #define MRF_I_RXIF 0b00001000 #define MRF_I_TXNIF 0b00000001 +typedef struct _rx_info_t{ + uint8_t frame_length; + uint8_t rx_data[116]; //max data length = (127 aMaxPHYPacketSize - 2 Frame control - 1 sequence number - 2 panid - 2 shortAddr Destination - 2 shortAddr Source - 2 FCS) + uint8_t lqi; + uint8_t rssi; +} rx_info_t; + +/** + * Based on the TXSTAT register, but "better" + */ +typedef struct _tx_info_t{ + uint8_t tx_ok:1; + uint8_t retries:2; + uint8_t channel_busy:1; +} tx_info_t; class Mrf24j { + public: + Mrf24j(int pin_reset, int pin_chip_select, int pin_interrupt); + void reset(void); + void init(void); -public: -Mrf24j(int pin_reset, int pin_chip_select, int pin_interrupt); -void reset(void); -void init(void); + byte read_short(byte address); + byte read_long(word address); -byte read_short(byte address); -byte read_long(word address); + void write_short(byte address, byte data); + void write_long(word address, byte data); -void write_short(byte address, byte data); -void write_long(word address, byte data); + word get_pan(void); + void set_pan(word panid); -word get_pan(void); -void set_pan(word panid); + void address16_write(word address16); + word address16_read(void); -void address16_write(word address16); -word address16_read(void); + void set_interrupts(void); -void set_interrupts(void); + void set_promiscuous(boolean enabled); -void set_promiscuous(boolean enabled); + /** + * Set the channel, using 802.15.4 channel numbers (11..26) + */ + void set_channel(byte channel); -/** - * Set the channel, using 802.15.4 channel numbers (11..26) - */ -void set_channel(byte channel); + void rx_enable(void); + void rx_disable(void); -void rx_enable(void); -void rx_disable(void); + /** If you want to throw away rx data */ + void rx_flush(void); -/** If you want to throw away rx data */ -void rx_flush(void); + rx_info_t * get_rxinfo(void); -void send16(word dest16, byte len, char * data); + tx_info_t * get_txinfo(void); -private: - int _pin_reset; - int _pin_cs; - int _pin_int; + uint8_t * get_rxbuf(void); + int rx_datalength(void); + void send16(word dest16, char * data); + + void interrupt_handler(void); + + void check_flags(void (*rx_handler)(void), void (*tx_handler)(void)); + + private: + int _pin_reset; + int _pin_cs; + int _pin_int; }; -#endif /* LIB_MRF24J_H */ - - +#endif /* LIB_MRF24J_H */ \ No newline at end of file