Open Lighting Architecture  0.9.1
 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 <stdint.h>
25 #include <string>
26 
27 namespace ola {
28 namespace plugin {
29 namespace e131 {
30 
31 /*
32  * Header for the E131 layer
33  */
34 class E131Header {
35  public:
36  E131Header() {}
37  E131Header(const std::string &source,
38  uint8_t priority,
39  uint8_t sequence,
40  uint16_t universe,
41  bool is_preview = false,
42  bool has_terminated = false,
43  bool is_rev2 = false)
44  : m_source(source),
45  m_priority(priority),
46  m_sequence(sequence),
47  m_universe(universe),
48  m_is_preview(is_preview),
49  m_has_terminated(has_terminated),
50  m_is_rev2(is_rev2) {
51  }
52  ~E131Header() {}
53 
54  const std::string Source() const { return m_source; }
55  uint8_t Priority() const { return m_priority; }
56  uint8_t Sequence() const { return m_sequence; }
57  uint16_t Universe() const { return m_universe; }
58  bool PreviewData() const { return m_is_preview; }
59  bool StreamTerminated() const { return m_has_terminated; }
60 
61  bool UsingRev2() const { return m_is_rev2; }
62 
63  bool operator==(const E131Header &other) const {
64  return m_source == other.m_source &&
65  m_priority == other.m_priority &&
66  m_sequence == other.m_sequence &&
67  m_universe == other.m_universe &&
68  m_is_preview == other.m_is_preview &&
69  m_has_terminated == other.m_has_terminated &&
70  m_is_rev2 == other.m_is_rev2;
71  }
72 
73  enum { SOURCE_NAME_LEN = 64 };
74 
76  char source[SOURCE_NAME_LEN];
77  uint8_t priority;
78  uint16_t reserved;
79  uint8_t sequence;
80  uint8_t options;
81  uint16_t universe;
82  } __attribute__((packed));
83  typedef struct e131_pdu_header_s e131_pdu_header;
84 
85  static const uint8_t PREVIEW_DATA_MASK = 0x80;
86  static const uint8_t STREAM_TERMINATED_MASK = 0x40;
87 
88  private:
89  std::string m_source;
90  uint8_t m_priority;
91  uint8_t m_sequence;
92  uint16_t m_universe;
93  bool m_is_preview;
94  bool m_has_terminated;
95  bool m_is_rev2;
96 };
97 
98 
99 class E131Rev2Header: public E131Header {
100  public:
101  E131Rev2Header(const std::string &source,
102  uint8_t priority,
103  uint8_t sequence,
104  uint16_t universe,
105  bool is_preview = false,
106  bool has_terminated = false)
107  : E131Header(source, priority, sequence, universe, is_preview,
108  has_terminated, true) {
109  }
110 
111  enum { REV2_SOURCE_NAME_LEN = 32 };
112 
113  typedef struct {
114  char source[REV2_SOURCE_NAME_LEN];
115  uint8_t priority;
116  uint8_t sequence;
117  uint16_t universe;
119 };
120 } // namespace e131
121 } // namespace plugin
122 } // namespace ola
123 #endif // PLUGINS_E131_E131_E131HEADER_H_