OpenZWave Library  1.6.887
ValueBitSet.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // ValueBitSet.h
4 //
5 // Represents a Range of Bits
6 //
7 // Copyright (c) 2017 Justin Hammond <justin@dynam.ac>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _ValueBitSet_H
29 #define _ValueBitSet_H
30 
31 #include <string>
32 #include <map>
33 #include "Defs.h"
34 #include "value_classes/Value.h"
35 #include "Bitfield.h"
36 
37 class TiXmlElement;
38 
39 namespace OpenZWave
40 {
41  namespace Internal
42  {
43  namespace VC
44  {
45 
49  class ValueBitSet: public Value
50  {
51  public:
52  ValueBitSet(uint32 const _homeId, uint8 const _nodeId, ValueID::ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _index, string const& _label, string const& _units, bool const _readOnly, bool const _writeOnly, uint32 const _value, uint8 const _pollIntensity);
54  {
55  }
56  virtual ~ValueBitSet()
57  {
58  }
59 
60  bool Set(uint32 const _value);
61  uint32 GetValue() const;
62 
63  bool SetBit(uint8 const _idx);
64  bool ClearBit(uint8 const _idx);
65  bool GetBit(uint8 _idx) const;
66 
67  bool SetBitMask(uint32 _bitMask);
68  uint32 GetBitMask() const;
69 
70  void OnValueRefreshed(uint32 const _value);
71 
72  // From Value
73  virtual string const GetAsString() const;
74  virtual string const GetAsBinaryString() const;
75  virtual bool SetFromString(string const& _value);
76  virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement);
77  virtual void WriteXML(TiXmlElement* _valueElement);
78 
79  string GetBitHelp(uint8 _idx);
80  bool SetBitHelp(uint8 _idx, string help);
81  string GetBitLabel(uint8 _idx);
82  bool SetBitLabel(uint8 _idx, string label);
83 
84  uint8 GetSize() const;
85  void SetSize(uint8 size);
86 
87  private:
88  bool isValidBit(uint8 _idx) const;
89  Bitfield m_value; // the current index in the m_items vector
90  Bitfield m_valueCheck; // the previous value (used for double-checking spurious value reads)
91  Bitfield m_newValue; // a new value to be set on the appropriate device
92  uint32 m_BitMask; // Valid Bits
93  uint8 m_size; // Number of bytes in size
94  vector<int32> m_bits;
95  };
96  } // namespace VC
97  } // namespace Internal
98 } // namespace OpenZWave
99 
100 #endif
101 
virtual string const GetAsString() const
Definition: ValueBitSet.cpp:59
virtual string const GetAsBinaryString() const
Definition: ValueBitSet.cpp:66
uint32 GetValue() const
Definition: ValueBitSet.cpp:78
virtual ~ValueBitSet()
Definition: ValueBitSet.h:56
Definition: Bitfield.cpp:30
string GetBitHelp(uint8 _idx)
Definition: ValueBitSet.cpp:286
bool Set()
Definition: Value.cpp:276
unsigned short uint16
Definition: Defs.h:89
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: ValueBitSet.cpp:167
void SetSize(uint8 size)
Definition: ValueBitSet.cpp:340
void OnValueRefreshed()
Definition: Value.cpp:336
uint8 GetSize() const
Definition: ValueBitSet.cpp:336
bool SetBitMask(uint32 _bitMask)
Definition: ValueBitSet.cpp:275
virtual bool SetFromString(string const &_value)
Definition: ValueBitSet.cpp:53
bool SetBitHelp(uint8 _idx, string help)
Definition: ValueBitSet.cpp:296
bool GetBit(uint8 _idx) const
Definition: ValueBitSet.cpp:82
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: ValueBitSet.cpp:95
unsigned int uint32
Definition: Defs.h:92
bool SetBit(uint8 const _idx)
Definition: ValueBitSet.cpp:230
ValueBitSet()
Definition: ValueBitSet.h:53
bool SetBitLabel(uint8 _idx, string label)
Definition: ValueBitSet.cpp:324
Definition: Bitfield.h:39
BitSet value sent to/received from a node.
Definition: ValueBitSet.h:49
bool ClearBit(uint8 const _idx)
Definition: ValueBitSet.cpp:252
string GetBitLabel(uint8 _idx)
Definition: ValueBitSet.cpp:314
uint32 GetBitMask() const
Definition: ValueBitSet.cpp:281
ValueGenre
Definition: ValueID.h:92
Base class for values associated with a node.
Definition: Value.h:53
unsigned char uint8
Definition: Defs.h:86