Open Lighting Architecture: libs/acn/E131Node.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
47namespace ola {
48namespace acn {
49
50 class E131Node {
51 public:
55 struct Options {
56 public:
57 Options()
58 : use_rev2(false),
59 ignore_preview(true),
60 enable_draft_discovery(false),
61 dscp(0),
62 port(ola::acn::ACN_PORT),
63 source_name(ola::OLA_DEFAULT_INSTANCE_NAME) {
64 }
65
66 bool use_rev2;
67 bool ignore_preview;
68 bool enable_draft_discovery;
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
88 E131Node(ola::thread::SchedulerInterface *ss,
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
219 ola::thread::SchedulerInterface *m_ss;
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,
248 const E131DiscoveryInflator::DiscoveryPage &page);
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
257 E131Node(const E131Node &) = delete;
258 const E131Node &operator=(const E131Node &) = delete;
259};
260} // namespace acn
261} // namespace ola
262#endif // LIBS_ACN_E131NODE_H_
ACNPort.h
The TCP / UDP Ports used for transporting ACN.
CID.h
The ACN component identifier.
Callback.h
Constants.h
Constants used throughout OLA.
DmxBuffer.h
A class used to hold a single universe of DMX data.
Macro.h
Helper macros.
ola::Callback0
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::acn::CID
The ACN component identifier.
Definition CID.h:47
ola::acn::CID::Generate
static CID Generate()
Generate a new CID.
Definition CID.cpp:74
ola::acn::E131Node::StartStream
bool StartStream(uint16_t universe)
Signal that we will start sending on this particular universe. Without sending any DMX data.
Definition E131Node.cpp:220
ola::acn::E131Node::Start
bool Start()
Start this node.
Definition E131Node.cpp:162
ola::acn::E131Node::SetHandler
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:346
ola::acn::E131Node::GetSocket
ola::network::UDPSocket * GetSocket()
Return the UDP socket this node is using.
Definition E131Node.h:200
ola::acn::E131Node::E131Node
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
ola::acn::E131Node::SendDMX
bool SendDMX(uint16_t universe, const ola::DmxBuffer &buffer, uint8_t priority=DEFAULT_PRIORITY, bool preview=false)
Send some DMX data.
Definition E131Node.cpp:242
ola::acn::E131Node::Stop
bool Stop()
Stop this node.
Definition E131Node.cpp:202
ola::acn::E131Node::TerminateStream
bool TerminateStream(uint16_t universe, uint8_t priority=DEFAULT_PRIORITY)
Signal that we will no longer send on this particular universe.
Definition E131Node.cpp:233
ola::acn::E131Node::SetSourceName
bool SetSourceName(uint16_t universe, const std::string &source)
Set the name for a universe.
Definition E131Node.cpp:208
ola::acn::E131Node::SendStreamTerminated
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:302
ola::acn::E131Node::GetInterface
const ola::network::Interface & GetInterface() const
Return the Interface this node is using.
Definition E131Node.h:195
ola::acn::E131Node::GetKnownControllers
void GetKnownControllers(std::vector< KnownController > *controllers)
Return a list of known controllers.
Definition E131Node.cpp:382
ola::acn::E131Node::RemoveHandler
bool RemoveHandler(uint16_t universe)
Remove the handler for a particular universe.
Definition E131Node.cpp:365
ola::acn::E131Node::SendDMXWithSequenceOffset
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:250
ola::network::IPV4Address
Represents a IPv4 Address.
Definition IPV4Address.h:55
ola::network::Interface
Definition Interface.h:35
ola::network::UDPSocket
Definition Socket.h:239
ola::thread::SchedulerInterface
Allows Callbacks to be scheduled to run after a specified interval.
Definition SchedulerInterface.h:46
ola::acn::ACN_PORT
const uint16_t ACN_PORT
The port used for E1.31 & SDT communication.
Definition ACNPort.h:57
ola::acn
ACN related code.
ola::thread::timeout_id
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition SchedulerInterface.h:34
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::OLA_DEFAULT_INSTANCE_NAME
static const char OLA_DEFAULT_INSTANCE_NAME[]
The default instance name for olad.
Definition Constants.h:73
ola::acn::E131Node::KnownController
Definition E131Node.h:74
ola::acn::E131Node::Options
Options for the E131Node.
Definition E131Node.h:55
ola::acn::E131Node::Options::dscp
uint8_t dscp
Definition E131Node.h:69
ola::acn::E131Node::Options::port
uint16_t port
Definition E131Node.h:70
ola::acn::E131Node::Options::source_name
std::string source_name
Definition E131Node.h:71
ola::acn::E131Node::Options::enable_draft_discovery
bool enable_draft_discovery
Definition E131Node.h:68
ola::acn::E131Node::Options::ignore_preview
bool ignore_preview
Definition E131Node.h:67
ola::acn::E131Node::Options::use_rev2
bool use_rev2
Definition E131Node.h:66