RF22
RF22Datagram.h
1 // RF22Datagram.h
2 // Author: Mike McCauley (mikem@airspayce.com)
3 // Copyright (C) 2011 Mike McCauley
4 // $Id: RF22Datagram.h,v 1.5 2014/04/01 05:06:44 mikem Exp mikem $
5 
6 #ifndef RF22Datagram_h
7 #define RF22Datagram_h
8 
9 #include <RF22.h>
10 
11 /////////////////////////////////////////////////////////////////////
12 /// \class RF22Datagram RF22Datagram.h <RF22Datagram.h>
13 /// \brief RF22 subclass for addressed, unreliable messages
14 ///
15 /// Extends RF22 to define addressed, unreliable datagrams.
16 /// Every node has an 8 bit address (defaults to 0).
17 /// Addresses (DEST and SRC) are 8 bit integers with an address of RF22_BROADCAST_ADDRESS (0xff)
18 /// reserved for broadcast.
19 ///
20 /// Part of the Arduino RF22 library for operating with HopeRF RF22 compatible transceivers
21 /// (see http://www.hoperf.com).
22 class RF22Datagram : public RF22
23 {
24 public:
25  /// Constructor.
26  /// \param[in] thisAddress The address to assign to this node. Defaults to 0
27  /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF22 before
28  /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega)
29  /// \param[in] interrupt The interrupt number to use. Default is interrupt 0 (Arduino input pin 2)
30  RF22Datagram(uint8_t thisAddress = 0, uint8_t slaveSelectPin = SS, uint8_t interrupt = 0);
31 
32  /// Initialises this instance and the radio module connected to it.
33  /// Overrides the init() function in RF22
34  boolean init();
35 
36  /// Sets the address of this node. Defaults to 0.
37  /// This will be used to set the FROM address of all messages sent by this node.
38  /// If all the nodes leave the address unset (ie 0),
39  /// In a conventional multinode system, all nodes will have a unique address
40  /// (which you could store in EEPROM).
41  /// \param[in] thisAddress The address of this node
42  void setThisAddress(uint8_t thisAddress);
43 
44  /// Sends a message to the node(s) with the given address
45  /// RF22_BROADCAST_ADDRESS is a valid address which will cause the message
46  /// to be accepted by all RF22Datagram nodes within range.
47  /// \param[in] buf Pointer to the binary message to send
48  /// \param[in] len Number of octets to send (> 0)
49  /// \param[in] address The address to send the message to.
50  /// \return true if the message was transmitted.
51  boolean sendto(uint8_t* buf, uint8_t len, uint8_t address);
52 
53  /// Turns the receiver on if it not already on.
54  /// If there is a valid message available for this node, copy it to buf and return true
55  /// The SRC address is placed in *from if present and not NULL.
56  /// The DEST address is placed in *to if present and not NULL.
57  /// If a message is copied, *len is set to the length.
58  /// You should be sure to call this function frequently enough to not miss any messages
59  /// It is recommended that you call it in your main loop.
60  /// \param[in] buf Location to copy the received message
61  /// \param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.
62  /// \param[in] from If present and not NULL, the referenced uint8_t will be set to the FROM address
63  /// \param[in] to If present and not NULL, the referenced uint8_t will be set to the TO address
64  /// \param[in] id If present and not NULL, the referenced uint8_t will be set to the ID
65  /// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS
66  /// (not just those addressed to this node).
67  /// \return true if a valid message was copied to buf
68  boolean recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);
69 
70 protected:
71  /// The address of this node. Defaults to 0.
72  uint8_t _thisAddress;
73 
74 };
75 
76 #endif
RF22Datagram(uint8_t thisAddress=0, uint8_t slaveSelectPin=SS, uint8_t interrupt=0)
Definition: RF22Datagram.cpp:9
uint8_t _thisAddress
The address of this node. Defaults to 0.
Definition: RF22Datagram.h:72
boolean init()
Definition: RF22Datagram.cpp:17
void setThisAddress(uint8_t thisAddress)
Definition: RF22Datagram.cpp:25
RF22 subclass for addressed, unreliable messages.
Definition: RF22Datagram.h:22
boolean sendto(uint8_t *buf, uint8_t len, uint8_t address)
Definition: RF22Datagram.cpp:36
boolean recvfrom(uint8_t *buf, uint8_t *len, uint8_t *from=NULL, uint8_t *to=NULL, uint8_t *id=NULL, uint8_t *flags=NULL)
Definition: RF22Datagram.cpp:42
Send and receive unaddressed, unreliable datagrams.
Definition: RF22.h:848