Open Lighting Architecture  0.9.0
 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 "plugins/e131/e131/DMPAddress.h"
26 
27 namespace ola {
28 namespace plugin {
29 namespace e131 {
30 
31 /*
32  * Header for the DMP layer
33  */
34 class DMPHeader {
35  public:
36  static const unsigned int DMP_HEADER_SIZE = 1;
37 
38  explicit DMPHeader(uint8_t header = 0): m_header(header) {}
39 
40  DMPHeader(bool is_virtual,
41  bool is_relative,
42  dmp_address_type type,
43  dmp_address_size size) {
44  m_header = (uint8_t) (is_virtual << 7 |
45  is_relative << 6 |
46  type << 4 |
47  size);
48  }
49  ~DMPHeader() {}
50 
51  bool IsVirtual() const { return m_header & VIRTUAL_MASK; }
52  bool IsRelative() const { return m_header & RELATIVE_MASK; }
53 
54  dmp_address_type Type() const {
55  return (dmp_address_type) ((m_header & TYPE_MASK) >> 4);
56  }
57 
58  dmp_address_size Size() const {
59  return (dmp_address_size) (m_header & SIZE_MASK);
60  }
61 
62  unsigned int Bytes() const { return DMPSizeToByteSize(Size()); }
63 
64  bool operator==(const DMPHeader &other) const {
65  return m_header == other.m_header;
66  }
67 
68  bool operator!=(const DMPHeader &other) const {
69  return m_header != other.m_header;
70  }
71 
72  uint8_t Header() const { return m_header; }
73 
74  private:
75  static const uint8_t VIRTUAL_MASK = 0x80;
76  static const uint8_t RELATIVE_MASK = 0x40;
77  static const uint8_t TYPE_MASK = 0x30;
78  static const uint8_t SIZE_MASK = 0x03;
79  uint8_t m_header;
80 };
81 } // namespace e131
82 } // namespace plugin
83 } // namespace ola
84 #endif // PLUGINS_E131_E131_DMPHEADER_H_