Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
E131Header.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  * E131Header.h
17  * The E1.31 Header
18  * Copyright (C) 2007 Simon Newton
19  */
20 
21 #ifndef PLUGINS_E131_E131_E131HEADER_H_
22 #define PLUGINS_E131_E131_E131HEADER_H_
23 
24 #include <ola/base/Macro.h>
25 
26 #include <stdint.h>
27 #include <string>
28 
29 namespace ola {
30 namespace plugin {
31 namespace e131 {
32 
33 /*
34  * Header for the E131 layer
35  */
36 class E131Header {
37  public:
38  E131Header()
39  : m_priority(0),
40  m_sequence(0),
41  m_universe(0),
42  m_is_preview(false),
43  m_has_terminated(false),
44  m_is_rev2(false) {
45  }
46  E131Header(const std::string &source,
47  uint8_t priority,
48  uint8_t sequence,
49  uint16_t universe,
50  bool is_preview = false,
51  bool has_terminated = false,
52  bool is_rev2 = false)
53  : m_source(source),
54  m_priority(priority),
55  m_sequence(sequence),
56  m_universe(universe),
57  m_is_preview(is_preview),
58  m_has_terminated(has_terminated),
59  m_is_rev2(is_rev2) {
60  }
61  ~E131Header() {}
62 
63  const std::string Source() const { return m_source; }
64  uint8_t Priority() const { return m_priority; }
65  uint8_t Sequence() const { return m_sequence; }
66  uint16_t Universe() const { return m_universe; }
67  bool PreviewData() const { return m_is_preview; }
68  bool StreamTerminated() const { return m_has_terminated; }
69 
70  bool UsingRev2() const { return m_is_rev2; }
71 
72  bool operator==(const E131Header &other) const {
73  return m_source == other.m_source &&
74  m_priority == other.m_priority &&
75  m_sequence == other.m_sequence &&
76  m_universe == other.m_universe &&
77  m_is_preview == other.m_is_preview &&
78  m_has_terminated == other.m_has_terminated &&
79  m_is_rev2 == other.m_is_rev2;
80  }
81 
82  enum { SOURCE_NAME_LEN = 64 };
83 
84  PACK(
85  struct e131_pdu_header_s {
86  char source[SOURCE_NAME_LEN];
87  uint8_t priority;
88  uint16_t reserved;
89  uint8_t sequence;
90  uint8_t options;
91  uint16_t universe;
92  });
93  typedef struct e131_pdu_header_s e131_pdu_header;
94 
95  static const uint8_t PREVIEW_DATA_MASK = 0x80;
96  static const uint8_t STREAM_TERMINATED_MASK = 0x40;
97 
98  private:
99  std::string m_source;
100  uint8_t m_priority;
101  uint8_t m_sequence;
102  uint16_t m_universe;
103  bool m_is_preview;
104  bool m_has_terminated;
105  bool m_is_rev2;
106 };
107 
108 
109 class E131Rev2Header: public E131Header {
110  public:
111  E131Rev2Header(const std::string &source,
112  uint8_t priority,
113  uint8_t sequence,
114  uint16_t universe,
115  bool is_preview = false,
116  bool has_terminated = false)
117  : E131Header(source, priority, sequence, universe, is_preview,
118  has_terminated, true) {
119  }
120 
121  enum { REV2_SOURCE_NAME_LEN = 32 };
122 
123  typedef struct {
124  char source[REV2_SOURCE_NAME_LEN];
125  uint8_t priority;
126  uint8_t sequence;
127  uint16_t universe;
129 };
130 } // namespace e131
131 } // namespace plugin
132 } // namespace ola
133 #endif // PLUGINS_E131_E131_E131HEADER_H_