Open Lighting Architecture
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * E131Header.h
17  * The E1.31 Header
18  * Copyright (C) 2007-2009 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 using std::string;
32 
33 /*
34  * Header for the E131 layer
35  */
36 class E131Header {
37  public:
38  E131Header() {}
39  E131Header(const 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 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 
78  char source[SOURCE_NAME_LEN];
79  uint8_t priority;
80  uint16_t reserved;
81  uint8_t sequence;
82  uint8_t options;
83  uint16_t universe;
84  } __attribute__((packed));
85  typedef struct e131_pdu_header_s e131_pdu_header;
86 
87  static const uint8_t PREVIEW_DATA_MASK = 0x80;
88  static const uint8_t STREAM_TERMINATED_MASK = 0x40;
89 
90  private:
91  string m_source;
92  uint8_t m_priority;
93  uint8_t m_sequence;
94  uint16_t m_universe;
95  bool m_is_preview;
96  bool m_has_terminated;
97  bool m_is_rev2;
98 };
99 
100 
101 class E131Rev2Header: public E131Header {
102  public:
103  E131Rev2Header(const string &source,
104  uint8_t priority,
105  uint8_t sequence,
106  uint16_t universe,
107  bool is_preview = false,
108  bool has_terminated = false)
109  : E131Header(source, priority, sequence, universe, is_preview,
110  has_terminated, true) {
111  }
112 
113  enum { REV2_SOURCE_NAME_LEN = 32 };
114 
115  typedef struct {
116  char source[REV2_SOURCE_NAME_LEN];
117  uint8_t priority;
118  uint8_t sequence;
119  uint16_t universe;
121 };
122 } // namespace e131
123 } // namespace plugin
124 } // namespace ola
125 #endif // PLUGINS_E131_E131_E131HEADER_H_