RF22
RF22Datagram.h
00001 // RF22Datagram.h
00002 // Author: Mike McCauley (mikem@open.com.au)
00003 // Copyright (C) 2011 Mike McCauley
00004 // $Id: RF22Datagram.h,v 1.3 2011/02/15 01:18:03 mikem Exp $
00005 
00006 #ifndef RF22Datagram_h
00007 #define RF22Datagram_h
00008 
00009 #include <RF22.h>
00010 
00011 /////////////////////////////////////////////////////////////////////
00012 /// \class RF22Datagram RF22Datagram.h <RF22Datagram.h>
00013 /// \brief RF22 subclass for addressed, unreliable messages
00014 ///
00015 /// Extends RF22 to define addressed, unreliable datagrams.
00016 /// Every node has an 8 bit address (defaults to 0).
00017 /// Addresses (DEST and SRC) are 8 bit integers with an address of RF22_BROADCAST_ADDRESS (0xff) 
00018 /// reserved for broadcast.
00019 ///
00020 /// Part of the Arduino RF22 library for operating with HopeRF RF22 compatible transceivers 
00021 /// (see http://www.hoperf.com).
00022 class RF22Datagram : public RF22
00023 {
00024 public:
00025     /// Constructor. 
00026     /// \param[in] thisAddress The address to assign to this node. Defaults to 0
00027     /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF22 before
00028     /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega)
00029     /// \param[in] interrupt The interrupt number to use. Default is interrupt 0 (Arduino input pin 2)
00030     RF22Datagram(uint8_t thisAddress = 0, uint8_t slaveSelectPin = SS, uint8_t interrupt = 0);
00031 
00032     /// Initialises this instance and the radio module connected to it.
00033     /// Overrides the init() function in RF22
00034     boolean init();
00035 
00036     /// Sets the address of this node. Defaults to 0. 
00037     /// This will be used to set the FROM address of all messages sent by this node.
00038     /// If all the nodes leave the address unset (ie 0),
00039     /// In a conventional multinode system, all nodes will have a unique address 
00040     /// (which you could store in EEPROM).
00041     /// \param[in] thisAddress The address of this node
00042     void setThisAddress(uint8_t thisAddress);
00043 
00044     /// Sends a message to the node(s) with the given address
00045     /// RF22_BROADCAST_ADDRESS is a valid address which will cause the message
00046     /// to be accepted by all RF22Datagram nodes within range.
00047     /// \param[in] buf Pointer to the binary message to send
00048     /// \param[in] len Number of octets to send (> 0)
00049     /// \param[in] address The address to send the message to.
00050     /// \return true if the message was transmitted.
00051     boolean sendto(uint8_t* buf, uint8_t len, uint8_t address);
00052 
00053     /// Turns the receiver on if it not already on.
00054     /// If there is a valid message available for this node, copy it to buf and return true
00055     /// The SRC address is placed in *from if present and not NULL.
00056     /// The DEST address is placed in *to if present and not NULL.
00057     /// If a message is copied, *len is set to the length.
00058     /// You should be sure to call this function frequently enough to not miss any messages
00059     /// It is recommended that you call it in your main loop.
00060     /// \param[in] buf Location to copy the received message
00061     /// \param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.
00062     /// \param[in] from If present and not NULL, the referenced uint8_t will be set to the FROM address
00063     /// \param[in] to If present and not NULL, the referenced uint8_t will be set to the TO address
00064     /// \param[in] id If present and not NULL, the referenced uint8_t will be set to the ID
00065     /// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS
00066     /// (not just those addressed to this node).
00067     /// \return true if a valid message was copied to buf
00068     boolean recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);
00069 
00070 protected:
00071     /// The address of this node. Defaults to 0.
00072     uint8_t _thisAddress;
00073 
00074 };
00075 
00076 #endif