Open Lighting Architecture  Latest Git
SandNetNode.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  * SandNetNode.h
17  * Header file for the SandNetNode class
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef PLUGINS_SANDNET_SANDNETNODE_H_
22 #define PLUGINS_SANDNET_SANDNETNODE_H_
23 
24 #include <map>
25 #include <string>
26 #include <vector>
27 #include <utility>
28 #include "ola/Callback.h"
29 #include "ola/DmxBuffer.h"
31 #include "ola/network/InterfacePicker.h"
32 #include "ola/network/Socket.h"
34 #include "plugins/sandnet/SandNetPackets.h"
35 
36 namespace ola {
37 namespace plugin {
38 namespace sandnet {
39 
40 
41 class SandNetNode {
42  public:
43  typedef enum {
44  SANDNET_PORT_MODE_DISABLED,
45  SANDNET_PORT_MODE_OUT,
46  SANDNET_PORT_MODE_IN,
47  SANDNET_PORT_MODE_MOUT,
48  SANDNET_PORT_MODE_MIN
49  } sandnet_port_type;
50 
51  explicit SandNetNode(const std::string &preferred_ip);
52  ~SandNetNode();
53 
54  const ola::network::Interface &GetInterface() const {
55  return m_interface;
56  }
57 
58  void SetName(const std::string &name) {
59  m_node_name = name;
60  }
61  bool Start();
62  bool Stop();
63  std::vector<ola::network::UDPSocket*> GetSockets();
64  void SocketReady(ola::network::UDPSocket *socket);
65 
66  bool SetHandler(uint8_t group,
67  uint8_t universe,
68  DmxBuffer *buffer,
69  Callback0<void> *closure);
70  bool RemoveHandler(uint8_t group, uint8_t universe);
71 
72  bool SetPortParameters(uint8_t port_id, sandnet_port_type type,
73  uint8_t group, uint8_t universe);
74  bool SendAdvertisement();
75  bool SendDMX(uint8_t port_id, const DmxBuffer &buffer);
76 
77  private:
78  typedef struct {
79  uint8_t group;
80  uint8_t universe;
81  sandnet_port_type type;
82  } sandnet_port;
83 
84  typedef struct {
85  DmxBuffer *buffer;
86  Callback0<void> *closure;
87  } universe_handler;
88 
89  typedef std::pair<uint8_t, uint8_t> group_universe_pair;
90  typedef std::map<group_universe_pair, universe_handler> universe_handlers;
91 
92  bool InitNetwork();
93 
94  bool HandleCompressedDMX(const sandnet_compressed_dmx &dmx_packet,
95  unsigned int size);
96 
97  bool HandleDMX(const sandnet_dmx &dmx_packet,
98  unsigned int size);
99  bool SendUncompressedDMX(uint8_t port_id, const DmxBuffer &buffer);
100  bool SendPacket(const sandnet_packet &packet,
101  unsigned int size,
102  bool is_control = false);
103 
104  bool m_running;
105  std::string m_node_name;
106  std::string m_preferred_ip;
107 
108  sandnet_port m_ports[SANDNET_MAX_PORTS];
109  universe_handlers m_handlers;
110  ola::network::Interface m_interface;
111  ola::network::UDPSocket m_control_socket;
112  ola::network::UDPSocket m_data_socket;
113  ola::dmx::RunLengthEncoder m_encoder;
114  ola::network::IPV4SocketAddress m_control_addr;
116 
117  static const uint16_t CONTROL_PORT;
118  static const uint16_t DATA_PORT;
119  static const char CONTROL_ADDRESS[];
120  static const char DATA_ADDRESS[];
121  static const char DEFAULT_NODE_NAME[];
122  static const uint32_t FIRMWARE_VERSION = 0x00050501;
123 };
124 } // namespace sandnet
125 } // namespace plugin
126 } // namespace ola
127 #endif // PLUGINS_SANDNET_SANDNETNODE_H_
Definition: Socket.h:238
Encode / Decode DMX data using Run Length Encoding
Definition: RunLengthEncoder.h:39
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
Encode / Decode DMX data using Run Length Encoding
A class used to hold a single universe of DMX data.
Definition: Interface.h:35
Represents an IPv4 Address.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: SandNetNode.h:41
An IPv4 SocketAddress.
Definition: SocketAddress.h:78