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;
143 std::string ShortName()
const {
return m_short_name; }
150 std::string LongName()
const {
return m_long_name; }
157 uint8_t NetAddress()
const {
return m_net_address; }
164 uint8_t SubnetAddress()
const {
165 return m_output_ports[0].universe_address >> 4;
231 void SetBroadcastThreshold(
unsigned int threshold) {
232 m_broadcast_threshold = threshold;
240 bool SetMergeMode(uint8_t port_id, artnet_merge_mode merge_mode);
317 std::vector<ola::network::IPV4Address> *node_addresses);
356 typedef std::vector<InputPort*> InputPorts;
361 std::pair<ola::network::IPV4Address, uint8_t> > uid_map;
363 enum { MAX_MERGE_SOURCES = 2 };
373 uint8_t universe_address;
374 uint8_t sequence_number;
376 artnet_merge_mode merge_mode;
378 DMXSource sources[MAX_MERGE_SOURCES];
380 std::map<ola::rdm::UID, ola::network::IPV4Address> uid_map;
390 uint8_t m_net_address;
391 bool m_send_reply_on_change;
392 std::string m_short_name;
393 std::string m_long_name;
394 unsigned int m_broadcast_threshold;
395 unsigned int m_unsolicited_replies;
397 bool m_always_broadcast;
398 bool m_use_limited_broadcast_address;
401 bool m_in_configuration_mode;
402 bool m_artpoll_required;
403 bool m_artpollreply_required;
405 InputPorts m_input_ports;
406 OutputPort m_output_ports[ARTNET_MAX_PORTS];
408 std::auto_ptr<ola::network::UDPSocketInterface> m_socket;
420 bool SendPollIfAllowed();
429 bool SendPollReplyIfRequired();
446 unsigned int packet_size);
452 const artnet_poll_t &packet,
453 unsigned int packet_size);
459 const artnet_reply_t &packet,
460 unsigned int packet_size);
466 const artnet_dmx_t &packet,
467 unsigned int packet_size);
473 const artnet_todrequest_t &packet,
474 unsigned int packet_size);
480 const artnet_toddata_t &packet,
481 unsigned int packet_size);
487 const artnet_todcontrol_t &packet,
488 unsigned int packet_size);
494 const artnet_rdm_t &packet,
495 unsigned int packet_size);
502 uint8_t universe_address,
503 ola::rdm::rdm_response_code code,
505 const std::vector<std::string> &packets);
517 const std::string &rdm_data,
524 const artnet_ip_prog_t &packet,
525 unsigned int packet_size);
530 void PopulatePacketHeader(
artnet_packet *packet, uint16_t op_code);
558 void UpdatePortFromSource(OutputPort *port,
const DMXSource &source);
564 const std::string &packet_type,
571 const std::string &packet_type,
572 unsigned int actual_size,
573 unsigned int expected_size);
579 InputPort *GetInputPort(uint8_t port_id,
bool warn =
true);
584 const InputPort *GetInputPort(uint8_t port_id)
const;
589 InputPort *GetEnabledInputPort(uint8_t port_id,
const std::string &action);
594 OutputPort *GetOutputPort(uint8_t port_id);
599 const OutputPort *GetOutputPort(uint8_t port_id)
const;
604 OutputPort *GetEnabledOutputPort(uint8_t port_id,
const std::string &action);
609 void UpdatePortFromTodPacket(
InputPort *port,
611 const artnet_toddata_t &packet,
612 unsigned int packet_size);
617 void ReleaseDiscoveryLock(
InputPort *port);
625 bool StartDiscoveryProcess(
InputPort *port,
633 static const char ARTNET_ID[];
634 static const uint16_t ARTNET_PORT = 6454;
635 static const uint16_t OEM_CODE = 0x0431;
636 static const uint16_t ARTNET_VERSION = 14;
639 static const uint8_t NODE_CODE = 0x00;
640 static const uint16_t MAX_UIDS_PER_UNIVERSE = 0xffff;
641 static const uint8_t RDM_VERSION = 0x01;
642 static const uint8_t TOD_FLUSH_COMMAND = 0x01;
643 static const unsigned int MERGE_TIMEOUT = 10;
645 static const unsigned int NODE_TIMEOUT = 31;
647 static const unsigned int RDM_TOD_TIMEOUT_MS = 4000;
649 static const unsigned int RDM_MISSED_TODDATA_LIMIT = 3;
652 static const unsigned int RDM_REQUEST_QUEUE_LIMIT = 100;
654 static const unsigned int RDM_REQUEST_TIMEOUT_MS = 2000;
687 ArtNetNodeImpl *m_impl;
690 DISALLOW_COPY_AND_ASSIGN(ArtNetNodeImplRDMWrapper);
705 bool Start() {
return m_impl.
Start(); }
706 bool Stop() {
return m_impl.
Stop(); }
708 bool EnterConfigurationMode() {
711 bool ExitConfigurationMode() {
716 bool SetShortName(
const std::string &name) {
720 std::string ShortName()
const {
return m_impl.ShortName(); }
721 bool SetLongName(
const std::string &name) {
725 std::string LongName()
const {
return m_impl.LongName(); }
727 uint8_t NetAddress()
const {
return m_impl.NetAddress(); }
728 bool SetNetAddress(uint8_t net_address) {
731 bool SetSubnetAddress(uint8_t subnet_address) {
734 uint8_t SubnetAddress()
const {
735 return m_impl.SubnetAddress();
738 uint8_t InputPortCount()
const {
742 bool SetInputPortUniverse(uint8_t port_id, uint8_t universe_id) {
745 uint8_t GetInputPortUniverse(uint8_t port_id)
const {
748 void DisableInputPort(uint8_t port_id) {
751 bool InputPortState(uint8_t port_id)
const {
755 bool SetOutputPortUniverse(uint8_t port_id, uint8_t universe_id) {
758 uint8_t GetOutputPortUniverse(uint8_t port_id) {
761 void DisableOutputPort(uint8_t port_id) {
764 bool OutputPortState(uint8_t port_id)
const {
768 void SetBroadcastThreshold(
unsigned int threshold) {
769 m_impl.SetBroadcastThreshold(threshold);
772 bool SetMergeMode(uint8_t port_id, artnet_merge_mode merge_mode) {
783 return m_impl.
SendDMX(port_id, buffer);
809 bool SetUnsolicitedUIDSetHandler(
814 void GetSubscribedNodes(
816 std::vector<ola::network::IPV4Address> *node_addresses) {
821 bool SetDMXHandler(uint8_t port_id,
827 return m_impl.
SendTod(port_id, uid_set);
829 bool SetOutputPortRDMHandlers(
849 std::vector<ArtNetNodeImplRDMWrapper*> m_wrappers;
850 std::vector<ola::rdm::DiscoverableQueueingRDMController*> m_controllers;
856 bool CheckInputPortId(uint8_t port_id);
863 #endif // PLUGINS_ARTNET_ARTNETNODE_H_