RCKit
EthernetTransceiver.h
1 // EthernetTransceiver.h
2 //
3 // Base class for an RCRx transceiver device
4 // Copyright (C) 2010 Mike McCauley
5 // $Id: EthernetTransceiver.h,v 1.1 2012/09/23 21:55:57 mikem Exp $
6 
7 #ifndef EthernetTransceiver_h
8 #define EthernetTransceiver_h
9 
10 #include "Transceiver.h"
11 #include <Ethernet.h>
12 #include <EthernetUdp.h>
13 #include <IPAddress.h>
14 #include "RCOIP.h"
15 
16 /////////////////////////////////////////////////////////////////////
17 /// \class EthernetTransceiver EthernetTransceiver.h <EthernetTransceiver.h>
18 /// \brief Defines an Ethernet RCOIP Transceiver.
19 ///
20 /// This is one of several types of Transceiver that RCRx can use to communicate with
21 /// an RCOIP transmitter.
22 /// It works with the standard Arduino Ethernet library, and with the following hardware:
23 /// - EthernetShield
24 ///
26 {
27 public:
28  /// Constructor.
29  /// Creates a new EthernetTransceiver object with the given addresses.
30  /// The addresses should be unique in your network.
31  /// \param[in] macaddress The MAC address for this hsot, an array of 6 bytes
32  /// \param[in] ipaddress The IPv4 IP address for this host
33  /// \param[in] port The UDP port to listen for RCOIP requests, defaults to RCOIP_DEFAULT_RECEIVER_UDP_PORT (9048)
34  EthernetTransceiver(byte* macaddress, IPAddress* ipaddress, unsigned int port = RCOIP_DEFAULT_RECEIVER_UDP_PORT);
35 
36  /// Initialise the object.
37  /// Call this once before using the Transceiver
38  virtual void init();
39 
40  /// Poll the object for activity.
41  /// This is expected to be called frequently in the main loop
42  /// It processes the Ethernet stack, checking for received messages.
43  /// During processing, and RCOIP message receibed by the preconfigured port and address
44  /// will be given to the RCRx object pointed to by _delegate
45  virtual void run();
46 
47  /// Send an RCOIP reply message to the sender of the current received message.
48  /// \param[in] msg Pointer to the RCOP message.
49  /// \param[in] len Length of the RCOIP message in bytes.
50  virtual void sendReply(uint8_t* msg, uint16_t len);
51 
52 private:
53 
54  /// The MAC address of this node as passed to the constructor
55  byte _thisMACaddress[6];
56 
57  /// The IPv$ IP address of this node as passed to the constructor
58  IPAddress _thisIpAddress;
59 
60  /// The UDP port to listen on as passed to the constructor
61  unsigned int _thisPort;
62 
63  /// Buffer for receiving UDP packets
64  char _packetBuffer[UDP_TX_PACKET_MAX_SIZE];
65 
66  /// Instance of the EthernetUDP instance to let us send and receive packets over UDP
67  EthernetUDP _udp;
68 };
69 
70 #endif
RCOIP_DEFAULT_RECEIVER_UDP_PORT
#define RCOIP_DEFAULT_RECEIVER_UDP_PORT
Definition: RCOIP.h:180
EthernetTransceiver
Defines an Ethernet RCOIP Transceiver.
Definition: EthernetTransceiver.h:25
RCOIP.h
EthernetTransceiver::init
virtual void init()
Definition: EthernetTransceiver.cpp:24
EthernetTransceiver::EthernetTransceiver
EthernetTransceiver(byte *macaddress, IPAddress *ipaddress, unsigned int port=RCOIP_DEFAULT_RECEIVER_UDP_PORT)
Definition: EthernetTransceiver.cpp:16
EthernetTransceiver::sendReply
virtual void sendReply(uint8_t *msg, uint16_t len)
Definition: EthernetTransceiver.cpp:46
Transceiver
Abstract base class for a transceiver device that will send and receive messages on behalf of RCRx cl...
Definition: Transceiver.h:25
Transceiver::receivedRequest
virtual void receivedRequest(uint8_t *msg, uint16_t len, uint16_t rssi=0)
Definition: Transceiver.cpp:18
EthernetTransceiver::run
virtual void run()
Definition: EthernetTransceiver.cpp:32