Open Lighting Architecture  Latest Git
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * DMPHeader.h
17  * The DMP Header
18  * Copyright (C) 2007 Simon Newton
19  */
20 
21 #ifndef LIBS_ACN_DMPHEADER_H_
22 #define LIBS_ACN_DMPHEADER_H_
23 
24 #include <stdint.h>
25 #include "libs/acn/DMPAddress.h"
26 
27 namespace ola {
28 namespace acn {
29 
30 /*
31  * Header for the DMP layer
32  */
33 class DMPHeader {
34  public:
35  static const unsigned int DMP_HEADER_SIZE = 1;
36 
37  explicit DMPHeader(uint8_t header = 0): m_header(header) {}
38 
39  DMPHeader(bool is_virtual,
40  bool is_relative,
41  dmp_address_type type,
42  dmp_address_size size) {
43  m_header = (uint8_t) (is_virtual << 7 |
44  is_relative << 6 |
45  type << 4 |
46  size);
47  }
48  ~DMPHeader() {}
49 
50  bool IsVirtual() const { return m_header & VIRTUAL_MASK; }
51  bool IsRelative() const { return m_header & RELATIVE_MASK; }
52 
53  dmp_address_type Type() const {
54  return (dmp_address_type) ((m_header & TYPE_MASK) >> 4);
55  }
56 
57  dmp_address_size Size() const {
58  return (dmp_address_size) (m_header & SIZE_MASK);
59  }
60 
61  unsigned int Bytes() const { return DMPSizeToByteSize(Size()); }
62 
63  bool operator==(const DMPHeader &other) const {
64  return m_header == other.m_header;
65  }
66 
67  bool operator!=(const DMPHeader &other) const {
68  return m_header != other.m_header;
69  }
70 
71  uint8_t Header() const { return m_header; }
72 
73  private:
74  static const uint8_t VIRTUAL_MASK = 0x80;
75  static const uint8_t RELATIVE_MASK = 0x40;
76  static const uint8_t TYPE_MASK = 0x30;
77  static const uint8_t SIZE_MASK = 0x03;
78  uint8_t m_header;
79 };
80 } // namespace acn
81 } // namespace ola
82 #endif // LIBS_ACN_DMPHEADER_H_
Definition: DMPHeader.h:33
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44