OpenZWave Library  1.7.0
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 
uint32
unsigned int uint32
Definition: Defs.h:91
OpenZWave::Internal::VC::ValueBitSet::SetBitLabel
bool SetBitLabel(uint8 _idx, string label)
Definition: ValueBitSet.cpp:323
OpenZWave::Internal::VC::ValueBitSet::WriteXML
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: ValueBitSet.cpp:167
OpenZWave::Internal::VC::ValueBitSet::GetBit
bool GetBit(uint8 _idx) const
Definition: ValueBitSet.cpp:82
OpenZWave::Internal::VC::ValueBitSet::ClearBit
bool ClearBit(uint8 const _idx)
Definition: ValueBitSet.cpp:252
OpenZWave::ValueID::ValueGenre
ValueGenre
Definition: ValueID.h:85
uint8
unsigned char uint8
Definition: Defs.h:85
OpenZWave::Internal::VC::ValueBitSet
BitSet value sent to/received from a node.
Definition: ValueBitSet.h:50
Bitfield.h
OpenZWave::Internal::VC::ValueBitSet::SetBitMask
bool SetBitMask(uint32 _bitMask)
Definition: ValueBitSet.cpp:275
OpenZWave::Internal::VC::ValueBitSet::GetAsString
virtual string const GetAsString() const
Definition: ValueBitSet.cpp:59
OpenZWave::Internal::VC::Value::Set
bool Set()
Definition: Value.cpp:276
OpenZWave::Internal::VC::ValueBitSet::SetBitHelp
bool SetBitHelp(uint8 _idx, string help)
Definition: ValueBitSet.cpp:296
OpenZWave::Internal::VC::ValueBitSet::SetSize
void SetSize(uint8 size)
Definition: ValueBitSet.cpp:339
OpenZWave::Internal::VC::ValueBitSet::GetAsBinaryString
virtual string const GetAsBinaryString() const
Definition: ValueBitSet.cpp:66
OpenZWave::Internal::VC::ValueBitSet::GetSize
uint8 GetSize() const
Definition: ValueBitSet.cpp:335
OpenZWave::Internal::VC::Value::OnValueRefreshed
void OnValueRefreshed()
Definition: Value.cpp:338
OpenZWave::Internal::VC::ValueBitSet::ReadXML
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: ValueBitSet.cpp:95
OpenZWave::Internal::VC::ValueBitSet::GetBitHelp
string GetBitHelp(uint8 _idx)
Definition: ValueBitSet.cpp:286
OpenZWave::Internal::VC::ValueBitSet::SetBit
bool SetBit(uint8 const _idx)
Definition: ValueBitSet.cpp:230
OpenZWave::Internal::VC::ValueBitSet::SetFromString
virtual bool SetFromString(string const &_value)
Definition: ValueBitSet.cpp:53
OpenZWave::Internal::VC::ValueBitSet::GetBitLabel
string GetBitLabel(uint8 _idx)
Definition: ValueBitSet.cpp:313
OpenZWave::Internal::VC::ValueBitSet::GetValue
uint32 GetValue() const
Definition: ValueBitSet.cpp:78
OpenZWave::Internal::VC::Value
Base class for values associated with a node.
Definition: Value.h:54
OpenZWave::Internal::Bitfield
Definition: Bitfield.h:40
OpenZWave::Internal::VC::ValueBitSet::~ValueBitSet
virtual ~ValueBitSet()
Definition: ValueBitSet.h:56
OpenZWave::Internal::VC::ValueBitSet::GetBitMask
uint32 GetBitMask() const
Definition: ValueBitSet.cpp:281
Defs.h
OpenZWave::Internal::VC::ValueBitSet::ValueBitSet
ValueBitSet()
Definition: ValueBitSet.h:53
Value.h
uint16
unsigned short uint16
Definition: Defs.h:88
OpenZWave
Definition: Bitfield.cpp:31