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