Open Lighting Architecture: plugins/shownet/ShowNetNode.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
ShowNetNode.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 * ShowNetNode.h
17 * Header file for the ShowNetNode class
18 * Copyright (C) 2005 Simon Newton
19 */
20
21#ifndef PLUGINS_SHOWNET_SHOWNETNODE_H_
22#define PLUGINS_SHOWNET_SHOWNETNODE_H_
23
24#include <string>
25#include <map>
26#include "ola/Callback.h"
27#include "ola/DmxBuffer.h"
28#include "ola/base/Macro.h"
29#include "ola/dmx/RunLengthEncoder.h"
30#include "ola/network/InterfacePicker.h"
31#include "ola/network/Socket.h"
32#include "plugins/shownet/ShowNetPackets.h"
33
34namespace ola {
35namespace plugin {
36namespace shownet {
37
38 class ShowNetNode {
39 public:
40 explicit ShowNetNode(const std::string &ip_address);
41 virtual ~ShowNetNode();
42
43 bool Start();
44 bool Stop();
45 void SetName(const std::string &name);
46
47 bool SendDMX(unsigned int universe, const ola::DmxBuffer &buffer);
48 bool SetHandler(unsigned int universe,
49 DmxBuffer *buffer,
50 ola::Callback0<void> *handler);
51 bool RemoveHandler(unsigned int universe);
52
53 const ola::network::Interface &GetInterface() const {
54 return m_interface;
55 }
56
57 ola::network::UDPSocket* GetSocket() { return m_socket; }
58 void SocketReady();
59
60 static const uint16_t SHOWNET_MAX_UNIVERSES = 8;
61
62 friend class ShowNetNodeTest;
63
64 private:
65 typedef struct {
66 DmxBuffer *buffer;
67 Callback0<void> *closure;
68 } universe_handler;
69
70 bool m_running;
71 uint16_t m_packet_count;
72 std::string m_node_name;
73 std::string m_preferred_ip;
74 std::map<unsigned int, universe_handler> m_handlers;
75 ola::network::Interface m_interface;
76 ola::dmx::RunLengthEncoder m_encoder;
77 ola::network::UDPSocket *m_socket;
78
79 bool HandlePacket(const shownet_packet *packet, unsigned int size);
80 bool HandleCompressedPacket(const shownet_compressed_dmx *packet,
81 unsigned int packet_size);
82 unsigned int BuildCompressedPacket(shownet_packet *packet,
83 unsigned int universe,
84 const DmxBuffer &buffer);
85 bool InitNetwork();
86
87 static const uint16_t SHOWNET_PORT = 2501;
88 // In the shownet spec, the pass(2) and name(9) fields are combined with the
89 // compressed data. This means the indices referenced in indexBlocks are
90 // off by 11.
91 static const uint16_t MAGIC_INDEX_OFFSET = 11;
92
93 ShowNetNode(const ShowNetNode &) = delete;
94 const ShowNetNode &operator=(const ShowNetNode &) = delete;
95};
96} // namespace shownet
97} // namespace plugin
98} // namespace ola
99#endif // PLUGINS_SHOWNET_SHOWNETNODE_H_
Callback.h
DmxBuffer.h
A class used to hold a single universe of DMX data.
Macro.h
Helper macros.
RunLengthEncoder.h
Encode / Decode DMX data using Run Length Encoding.
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::dmx::RunLengthEncoder
Encode / Decode DMX data using Run Length Encoding.
Definition RunLengthEncoder.h:39
ola::network::Interface
Definition Interface.h:35
ola::network::UDPSocket
Definition Socket.h:239
ola::plugin::shownet
Code for the Strand ShowNet protocol.
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::plugin::shownet::shownet_packet
Definition ShowNetPackets.h:88