Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PathportNode.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * PathportNode.h
17  * Header file for the PathportNode class
18  * Copyright (C) 2005-2009 Simon Newton
19  */
20 
21 #ifndef PLUGINS_PATHPORT_PATHPORTNODE_H_
22 #define PLUGINS_PATHPORT_PATHPORTNODE_H_
23 
24 #include <map>
25 #include <string>
26 #include "ola/Callback.h"
27 #include "ola/DmxBuffer.h"
28 #include "ola/network/IPV4Address.h"
29 #include "ola/network/InterfacePicker.h"
30 #include "ola/network/Socket.h"
31 #include "plugins/pathport/PathportPackets.h"
32 
33 namespace ola {
34 namespace plugin {
35 namespace pathport {
36 
39 
40 class PathportNode {
41  public:
42  explicit PathportNode(const string &preferred_ip, uint32_t device_id,
43  uint8_t dscp);
44  ~PathportNode();
45 
46  bool Start();
47  bool Stop();
48  const ola::network::Interface &GetInterface() const {
49  return m_interface;
50  }
51  UDPSocket *GetSocket() { return &m_socket; }
52  void SocketReady(UDPSocket *socket);
53 
54  bool SetHandler(uint8_t universe,
55  DmxBuffer *buffer,
56  Callback0<void> *closure);
57  bool RemoveHandler(uint8_t universe);
58 
59  bool SendArpReply();
60  bool SendDMX(unsigned int universe, const DmxBuffer &buffer);
61 
62  // apparently pathport supports up to 128 universes, the spec only says 64
63  static const uint8_t MAX_UNIVERSES = 127;
64 
65  private:
66  typedef struct {
67  DmxBuffer *buffer;
68  Callback0<void> *closure;
69  } universe_handler;
70 
71  enum {
72  XDMX_DATA_FLAT = 0x0101,
73  XDMX_DATA_RELEASE = 0x0103
74  };
75 
76  enum {
77  NODE_MANUF_PATHWAY_CONNECTIVITY = 0,
78  NODE_MANUF_INTERACTIVE_TECH = 0x10,
79  NODE_MANUF_ENTERTAINMENT_TECH = 0x11,
80  NODE_MANUF_MA_LIGHTING = 0x12,
81  NODE_MANUF_HIGH_END_SYSTEMS = 0x13,
82  NODE_MANUF_CRESTRON_ELECTRONICS = 0x14,
83  NODE_MANUF_LEVITON = 0x15,
84  NODE_MANUF_FLYING_PIG = 0x16,
85  NODE_MANUF_HORIZON = 0x17,
86  NODE_MANUF_ZP_TECH = 0x28, // ola
87  };
88 
89  enum {
90  NODE_CLASS_DMX_NODE = 0,
91  NODE_CLASS_MANAGER = 1,
92  NODE_CLASS_DIMMER = 2,
93  NODE_CLASS_CONTROLLER = 3,
94  NODE_CLASS_FIXTURE = 4,
95  NODE_CLASS_EFFECTS_UNIT = 5,
96  };
97 
98  enum {
99  NODE_DEVICE_PATHPORT = 0,
100  NODE_DEVICE_DMX_MANAGER_PLUS = 1,
101  NODE_DEVICE_ONEPORT = 2,
102  };
103 
104  typedef std::map<uint8_t, universe_handler> universe_handlers;
105 
106  bool InitNetwork();
107  void PopulateHeader(pathport_packet_header *header, uint32_t destination);
108  bool ValidateHeader(const pathport_packet_header &header);
109  void HandleDmxData(const pathport_pdu_data &packet,
110  unsigned int size);
111  bool SendArpRequest(uint32_t destination = PATHPORT_ID_BROADCAST);
112  bool SendPacket(const pathport_packet_s &packet,
113  unsigned int size,
114  IPV4Address dest);
115 
116  bool m_running;
117  uint8_t m_dscp;
118  string m_preferred_ip;
119  uint32_t m_device_id; // the pathport device id
120  uint16_t m_sequence_number;
121 
122  universe_handlers m_handlers;
123  ola::network::Interface m_interface;
124  UDPSocket m_socket;
125  IPV4Address m_config_addr;
126  IPV4Address m_status_addr;
127  IPV4Address m_data_addr;
128 
129  static const uint16_t PATHPORT_PORT = 0xed0;
130  static const uint16_t PATHPORT_PROTOCOL = 0xed01;
131  static const uint32_t PATHPORT_CONFIG_GROUP = 0xefffed02;
132  static const uint32_t PATHPORT_DATA_GROUP = 0xefffed01;
133  static const uint32_t PATHPORT_ID_BROADCAST = 0xffffffff;
134  static const uint32_t PATHPORT_STATUS_GROUP = 0xefffedff;
135  static const uint8_t MAJOR_VERSION = 2;
136  static const uint8_t MINOR_VERSION = 0;
137 };
138 } // namespace pathport
139 } // namespace plugin
140 } // namespace ola
141 #endif // PLUGINS_PATHPORT_PATHPORTNODE_H_