Open Lighting Architecture  Latest Git
E131Node.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * E131Node.h
17  * Header file for the E131Node class, this is the interface between OLA and
18  * the E1.31 library.
19  * Copyright (C) 2007 Simon Newton
20  */
21 
22 #ifndef LIBS_ACN_E131NODE_H_
23 #define LIBS_ACN_E131NODE_H_
24 
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <vector>
29 #include "ola/Callback.h"
30 #include "ola/Constants.h"
31 #include "ola/DmxBuffer.h"
32 #include "ola/acn/ACNPort.h"
33 #include "ola/acn/CID.h"
34 #include "ola/base/Macro.h"
35 #include "ola/io/SelectServerInterface.h"
36 #include "ola/thread/SchedulerInterface.h"
37 #include "ola/network/Interface.h"
38 #include "ola/network/Socket.h"
39 #include "libs/acn/DMPE131Inflator.h"
40 #include "libs/acn/E131DiscoveryInflator.h"
41 #include "libs/acn/E131Inflator.h"
42 #include "libs/acn/E131Sender.h"
43 #include "libs/acn/RootInflator.h"
44 #include "libs/acn/RootSender.h"
45 #include "libs/acn/UDPTransport.h"
46 
47 namespace ola {
48 namespace acn {
49 
50 class E131Node {
51  public:
55  struct Options {
56  public:
57  Options()
58  : use_rev2(false),
59  ignore_preview(true),
61  dscp(0),
64  }
65 
66  bool use_rev2;
69  uint8_t dscp;
70  uint16_t port;
71  std::string source_name;
72  };
73 
74  struct KnownController {
75  acn::CID cid;
76  ola::network::IPV4Address ip_address;
77  std::string source_name;
78  std::set<uint16_t> universes;
79  };
80 
89  const std::string &ip_address,
90  const Options &options,
91  const ola::acn::CID &cid = ola::acn::CID::Generate());
92  ~E131Node();
93 
97  bool Start();
98 
102  bool Stop();
103 
109  bool SetSourceName(uint16_t universe, const std::string &source);
110 
116  bool StartStream(uint16_t universe);
117 
123  bool TerminateStream(uint16_t universe,
124  uint8_t priority = DEFAULT_PRIORITY);
125 
134  bool SendDMX(uint16_t universe,
135  const ola::DmxBuffer &buffer,
136  uint8_t priority = DEFAULT_PRIORITY,
137  bool preview = false);
138 
153  bool SendDMXWithSequenceOffset(uint16_t universe,
154  const ola::DmxBuffer &buffer,
155  int8_t sequence_offset,
156  uint8_t priority = DEFAULT_PRIORITY,
157  bool preview = false);
158 
159 
170  bool SendStreamTerminated(uint16_t universe,
171  const ola::DmxBuffer &buffer = DmxBuffer(),
172  uint8_t priority = DEFAULT_PRIORITY);
173 
182  bool SetHandler(uint16_t universe, ola::DmxBuffer *buffer,
183  uint8_t *priority, ola::Callback0<void> *handler);
184 
190  bool RemoveHandler(uint16_t universe);
191 
195  const ola::network::Interface &GetInterface() const { return m_interface; }
196 
200  ola::network::UDPSocket* GetSocket() { return &m_socket; }
201 
208  void GetKnownControllers(std::vector<KnownController> *controllers);
209 
210  private:
211  struct tx_universe {
212  std::string source;
213  uint8_t sequence;
214  };
215 
216  typedef std::map<uint16_t, tx_universe> ActiveTxUniverses;
217  typedef std::map<acn::CID, class TrackedSource*> TrackedSources;
218 
220  const Options m_options;
221  const std::string m_preferred_ip;
222  const ola::acn::CID m_cid;
223 
224  ola::network::Interface m_interface;
225  ola::network::UDPSocket m_socket;
226  // senders
227  RootSender m_root_sender;
228  E131Sender m_e131_sender;
229  // inflators
230  RootInflator m_root_inflator;
231  E131Inflator m_e131_inflator;
232  E131InflatorRev2 m_e131_rev2_inflator;
233  DMPE131Inflator m_dmp_inflator;
234  E131DiscoveryInflator m_discovery_inflator;
235 
236  IncomingUDPTransport m_incoming_udp_transport;
237  ActiveTxUniverses m_tx_universes;
238  uint8_t *m_send_buffer;
239 
240  // Discovery members
241  ola::thread::timeout_id m_discovery_timeout;
242  TrackedSources m_discovered_sources;
243 
244  tx_universe *SetupOutgoingSettings(uint16_t universe);
245 
246  bool PerformDiscoveryHousekeeping();
247  void NewDiscoveryPage(const HeaderSet &headers,
249  void SendDiscoveryPage(const std::vector<uint16_t> &universes, uint8_t page,
250  uint8_t last_page, uint32_t sequence_number);
251 
252  static const uint16_t DEFAULT_PRIORITY = 100;
253  static const uint16_t UNIVERSE_DISCOVERY_INTERVAL = 10000; // milliseconds
254  static const uint16_t DISCOVERY_UNIVERSE_ID = 64214;
255  static const uint16_t DISCOVERY_PAGE_SIZE = 512;
256 
258 };
259 } // namespace acn
260 } // namespace ola
261 #endif // LIBS_ACN_E131NODE_H_
Definition: E131Sender.h:37
Definition: HeaderSet.h:35
bool TerminateStream(uint16_t universe, uint8_t priority=DEFAULT_PRIORITY)
Signal that we will no longer send on this particular universe.
Definition: E131Node.cpp:235
bool Stop()
Stop this node.
Definition: E131Node.cpp:204
uint16_t port
Definition: E131Node.h:70
bool RemoveHandler(uint16_t universe)
Remove the handler for a particular universe.
Definition: E131Node.cpp:367
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
ola::network::UDPSocket * GetSocket()
Return the UDP socket this node is using.
Definition: E131Node.h:200
bool SetSourceName(uint16_t universe, const std::string &source)
Set the name for a universe.
Definition: E131Node.cpp:210
Definition: Socket.h:238
E131Node(ola::thread::SchedulerInterface *ss, const std::string &ip_address, const Options &options, const ola::acn::CID &cid=ola::acn::CID::Generate())
Create a new E1.31 node.
Definition: E131Node.cpp:110
bool SendStreamTerminated(uint16_t universe, const ola::DmxBuffer &buffer=DmxBuffer(), uint8_t priority=DEFAULT_PRIORITY)
Signal termination of the stream for a universe.
Definition: E131Node.cpp:304
bool enable_draft_discovery
Definition: E131Node.h:68
const ola::network::Interface & GetInterface() const
Return the Interface this node is using.
Definition: E131Node.h:195
Options for the E131Node.
Definition: E131Node.h:55
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
bool SetHandler(uint16_t universe, ola::DmxBuffer *buffer, uint8_t *priority, ola::Callback0< void > *handler)
Set the Callback to be run when we receive data for this universe.
Definition: E131Node.cpp:348
bool Start()
Start this node.
Definition: E131Node.cpp:162
Definition: E131Inflator.h:34
Constants used throughout OLA.
void GetKnownControllers(std::vector< KnownController > *controllers)
Return a list of known controllers.
Definition: E131Node.cpp:384
std::string source_name
Definition: E131Node.h:71
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition: SchedulerInterface.h:34
The ACN component identifier.
uint8_t dscp
Definition: E131Node.h:69
A class used to hold a single universe of DMX data.
static const char OLA_DEFAULT_INSTANCE_NAME[]
The default instance name for olad.
Definition: Constants.h:73
The ACN component identifier.
Definition: CID.h:47
Definition: E131DiscoveryInflator.h:33
Represents a IPv4 Address.
Definition: IPV4Address.h:55
bool SendDMX(uint16_t universe, const ola::DmxBuffer &buffer, uint8_t priority=DEFAULT_PRIORITY, bool preview=false)
Send some DMX data.
Definition: E131Node.cpp:244
Definition: Interface.h:35
bool ignore_preview
Definition: E131Node.h:67
Definition: RootInflator.h:48
bool SendDMXWithSequenceOffset(uint16_t universe, const ola::DmxBuffer &buffer, int8_t sequence_offset, uint8_t priority=DEFAULT_PRIORITY, bool preview=false)
Send some DMX data, allowing finer grained control of parameters.
Definition: E131Node.cpp:252
Definition: E131Inflator.h:63
Definition: RootSender.h:33
Definition: E131Node.h:50
Definition: UDPTransport.h:94
Helper macros.
const uint16_t ACN_PORT
The port used for E1.31 & SDT communication.
Definition: ACNPort.h:57
bool StartStream(uint16_t universe)
Signal that we will start sending on this particular universe. Without sending any DMX data...
Definition: E131Node.cpp:222
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: E131DiscoveryInflator.h:35
Allows Callbacks to be scheduled to run after a specified interval.
Definition: SchedulerInterface.h:46
static CID Generate()
Generate a new CID.
Definition: CID.cpp:74
bool use_rev2
Definition: E131Node.h:66
Definition: DMPE131Inflator.h:35
Definition: E131Node.h:74
The TCP / UDP Ports used for transporting ACN.