21 #ifndef PLUGINS_ARTNET_ARTNETNODE_H_
22 #define PLUGINS_ARTNET_ARTNETNODE_H_
31 #include "ola/Clock.h"
34 #include "ola/network/Interface.h"
35 #include "ola/io/SelectServerInterface.h"
36 #include "ola/network/Socket.h"
41 #include "ola/timecode/TimeCode.h"
42 #include "plugins/artnet/ArtNetPackets.h"
62 static const uint8_t ARTNET_DISABLE_PORT = 0xf0;
67 : always_broadcast(
false),
68 use_limited_broadcast_address(
false),
70 broadcast_threshold(30),
74 bool always_broadcast;
75 bool use_limited_broadcast_address;
76 unsigned int rdm_queue_size;
77 unsigned int broadcast_threshold;
78 uint8_t input_port_count;
109 bool SetShortName(
const std::string &name);
110 std::string ShortName()
const {
return m_short_name; }
111 bool SetLongName(
const std::string &name);
112 std::string LongName()
const {
return m_long_name; }
114 uint8_t NetAddress()
const {
return m_net_address; }
115 bool SetNetAddress(uint8_t net_address);
117 bool SetSubnetAddress(uint8_t subnet_address);
118 uint8_t SubnetAddress()
const {
119 return m_output_ports[0].universe_address >> 4;
122 uint8_t InputPortCount()
const;
125 void DisableInputPort(uint8_t port_id);
126 bool InputPortState(uint8_t port_id)
const;
128 bool SetOutputPortUniverse(uint8_t port_id, uint8_t universe_id);
129 uint8_t GetOutputPortUniverse(uint8_t port_id);
130 void DisableOutputPort(uint8_t port_id);
131 bool OutputPortState(uint8_t port_id)
const;
133 void SetBroadcastThreshold(
unsigned int threshold) {
134 m_broadcast_threshold = threshold;
137 bool SetMergeMode(uint8_t port_id, artnet_merge_mode merge_mode);
144 void RunFullDiscovery(uint8_t port_id,
146 void RunIncrementalDiscovery(uint8_t port_id,
148 void SendRDMRequest(uint8_t port_id,
151 bool SetUnsolicitedUIDSetHandler(
156 std::vector<ola::network::IPV4Address> *node_addresses);
159 bool SetDMXHandler(uint8_t port_id,
163 bool SetOutputPortRDMHandlers(
176 typedef std::vector<InputPort*> InputPorts;
181 std::pair<ola::network::IPV4Address, uint8_t> > uid_map;
183 enum { MAX_MERGE_SOURCES = 2 };
193 uint8_t universe_address;
194 uint8_t sequence_number;
196 artnet_merge_mode merge_mode;
198 DMXSource sources[MAX_MERGE_SOURCES];
200 std::map<ola::rdm::UID, ola::network::IPV4Address> uid_map;
210 uint8_t m_net_address;
211 bool m_send_reply_on_change;
212 std::string m_short_name;
213 std::string m_long_name;
214 unsigned int m_broadcast_threshold;
215 unsigned int m_unsolicited_replies;
217 bool m_always_broadcast;
218 bool m_use_limited_broadcast_address;
221 bool m_in_configuration_mode;
222 bool m_artpoll_required;
223 bool m_artpollreply_required;
225 InputPorts m_input_ports;
226 OutputPort m_output_ports[ARTNET_MAX_PORTS];
228 std::auto_ptr<ola::network::UDPSocketInterface> m_socket;
234 bool SendPollIfAllowed();
235 bool SendPollReplyIfRequired();
240 unsigned int packet_size);
242 const artnet_poll_t &packet,
243 unsigned int packet_size);
245 const artnet_reply_t &packet,
246 unsigned int packet_size);
248 const artnet_dmx_t &packet,
249 unsigned int packet_size);
251 const artnet_todrequest_t &packet,
252 unsigned int packet_size);
254 const artnet_toddata_t &packet,
255 unsigned int packet_size);
257 const artnet_todcontrol_t &packet,
258 unsigned int packet_size);
260 const artnet_rdm_t &packet,
261 unsigned int packet_size);
264 uint8_t universe_address,
265 ola::rdm::rdm_response_code code,
267 const std::vector<std::string> &packets);
269 const std::string &rdm_data,
272 const artnet_ip_prog_t &packet,
273 unsigned int packet_size);
274 void PopulatePacketHeader(
artnet_packet *packet, uint16_t op_code);
282 void UpdatePortFromSource(OutputPort *port,
const DMXSource &source);
284 const std::string &packet_type,
287 const std::string &packet_type,
288 unsigned int actual_size,
289 unsigned int expected_size);
292 InputPort *GetInputPort(uint8_t port_id,
bool warn =
true);
293 const InputPort *GetInputPort(uint8_t port_id)
const;
294 InputPort *GetEnabledInputPort(uint8_t port_id,
const std::string &action);
296 OutputPort *GetOutputPort(uint8_t port_id);
297 const OutputPort *GetOutputPort(uint8_t port_id)
const;
298 OutputPort *GetEnabledOutputPort(uint8_t port_id,
const std::string &action);
300 void UpdatePortFromTodPacket(
InputPort *port,
302 const artnet_toddata_t &packet,
303 unsigned int packet_size);
305 void ReleaseDiscoveryLock(
InputPort *port);
306 bool StartDiscoveryProcess(
InputPort *port,
311 static const char ARTNET_ID[];
312 static const uint16_t ARTNET_PORT = 6454;
313 static const uint16_t OEM_CODE = 0x0431;
314 static const uint16_t ARTNET_VERSION = 14;
317 static const uint8_t NODE_CODE = 0x00;
318 static const uint16_t MAX_UIDS_PER_UNIVERSE = 0xffff;
319 static const uint8_t RDM_VERSION = 0x01;
320 static const uint8_t TOD_FLUSH_COMMAND = 0x01;
321 static const unsigned int MERGE_TIMEOUT = 10;
323 static const unsigned int NODE_TIMEOUT = 31;
325 static const unsigned int RDM_TOD_TIMEOUT_MS = 4000;
327 static const unsigned int RDM_MISSED_TODDATA_LIMIT = 3;
330 static const unsigned int RDM_REQUEST_QUEUE_LIMIT = 100;
332 static const unsigned int RDM_REQUEST_TIMEOUT_MS = 2000;
351 m_impl->SendRDMRequest(m_port_id, request, on_complete);
355 m_impl->RunFullDiscovery(m_port_id, callback);
359 m_impl->RunIncrementalDiscovery(m_port_id, callback);
363 ArtNetNodeImpl *m_impl;
379 bool Start() {
return m_impl.Start(); }
380 bool Stop() {
return m_impl.Stop(); }
382 bool EnterConfigurationMode() {
385 bool ExitConfigurationMode() {
390 bool SetShortName(
const std::string &name) {
391 return m_impl.SetShortName(name);
394 std::string ShortName()
const {
return m_impl.ShortName(); }
395 bool SetLongName(
const std::string &name) {
396 return m_impl.SetLongName(name);
399 std::string LongName()
const {
return m_impl.LongName(); }
401 uint8_t NetAddress()
const {
return m_impl.NetAddress(); }
402 bool SetNetAddress(uint8_t net_address) {
403 return m_impl.SetNetAddress(net_address);
405 bool SetSubnetAddress(uint8_t subnet_address) {
406 return m_impl.SetSubnetAddress(subnet_address);
408 uint8_t SubnetAddress()
const {
409 return m_impl.SubnetAddress();
412 uint8_t InputPortCount()
const {
413 return m_impl.InputPortCount();
416 bool SetInputPortUniverse(uint8_t port_id, uint8_t universe_id) {
419 uint8_t GetInputPortUniverse(uint8_t port_id)
const {
422 void DisableInputPort(uint8_t port_id) {
423 m_impl.DisableInputPort(port_id);
425 bool InputPortState(uint8_t port_id)
const {
426 return m_impl.InputPortState(port_id);
429 bool SetOutputPortUniverse(uint8_t port_id, uint8_t universe_id) {
430 return m_impl.SetOutputPortUniverse(port_id, universe_id);
432 uint8_t GetOutputPortUniverse(uint8_t port_id) {
433 return m_impl.GetOutputPortUniverse(port_id);
435 void DisableOutputPort(uint8_t port_id) {
436 m_impl.DisableOutputPort(port_id);
438 bool OutputPortState(uint8_t port_id)
const {
439 return m_impl.OutputPortState(port_id);
442 void SetBroadcastThreshold(
unsigned int threshold) {
443 m_impl.SetBroadcastThreshold(threshold);
446 bool SetMergeMode(uint8_t port_id, artnet_merge_mode merge_mode) {
447 return m_impl.SetMergeMode(port_id, merge_mode);
452 return m_impl.SendPoll();
457 return m_impl.SendDMX(port_id, buffer);
471 bool SetUnsolicitedUIDSetHandler(
474 return m_impl.SetUnsolicitedUIDSetHandler(port_id, on_tod);
476 void GetSubscribedNodes(
478 std::vector<ola::network::IPV4Address> *node_addresses) {
483 bool SetDMXHandler(uint8_t port_id,
486 return m_impl.SetDMXHandler(port_id, buffer, handler);
489 return m_impl.SendTod(port_id, uid_set);
491 bool SetOutputPortRDMHandlers(
498 return m_impl.SetOutputPortRDMHandlers(port_id,
511 std::vector<ArtNetNodeImplRDMWrapper*> m_wrappers;
512 std::vector<ola::rdm::DiscoverableQueueingRDMController*> m_controllers;
514 bool CheckInputPortId(uint8_t port_id);
519 #endif // PLUGINS_ARTNET_ARTNETNODE_H_