Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMPHeader.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  * DMPHeader.h
17  * The DMP Header
18  * Copyright (C) 2007-2009 Simon Newton
19  */
20 
21 #ifndef PLUGINS_E131_E131_DMPHEADER_H_
22 #define PLUGINS_E131_E131_DMPHEADER_H_
23 
24 #include <stdint.h>
25 #include <string>
26 #include "plugins/e131/e131/DMPAddress.h"
27 
28 namespace ola {
29 namespace plugin {
30 namespace e131 {
31 
32 using std::string;
33 
34 /*
35  * Header for the DMP layer
36  */
37 class DMPHeader {
38  public:
39  static const unsigned int DMP_HEADER_SIZE = 1;
40 
41  explicit DMPHeader(uint8_t header = 0): m_header(header) {}
42 
43  DMPHeader(bool is_virtual,
44  bool is_relative,
45  dmp_address_type type,
46  dmp_address_size size) {
47  m_header = (uint8_t) (is_virtual << 7 |
48  is_relative << 6 |
49  type << 4 |
50  size);
51  }
52  ~DMPHeader() {}
53 
54  bool IsVirtual() const { return m_header & VIRTUAL_MASK; }
55  bool IsRelative() const { return m_header & RELATIVE_MASK; }
56 
57  dmp_address_type Type() const {
58  return (dmp_address_type) ((m_header & TYPE_MASK) >> 4);
59  }
60 
61  dmp_address_size Size() const {
62  return (dmp_address_size) (m_header & SIZE_MASK);
63  }
64 
65  unsigned int Bytes() const { return DMPSizeToByteSize(Size()); }
66 
67  bool operator==(const DMPHeader &other) const {
68  return m_header == other.m_header;
69  }
70 
71  bool operator!=(const DMPHeader &other) const {
72  return m_header != other.m_header;
73  }
74 
75  uint8_t Header() const { return m_header; }
76 
77  private:
78  static const uint8_t VIRTUAL_MASK = 0x80;
79  static const uint8_t RELATIVE_MASK = 0x40;
80  static const uint8_t TYPE_MASK = 0x30;
81  static const uint8_t SIZE_MASK = 0x03;
82  uint8_t m_header;
83 };
84 } // namespace e131
85 } // namespace plugin
86 } // namespace ola
87 #endif // PLUGINS_E131_E131_DMPHEADER_H_