OpenZWave Library  1.6.1280
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  void SetTargetValue(uint32 const _target, uint32 _duration = 0);
64 
65  bool SetBit(uint8 const _idx);
66  bool ClearBit(uint8 const _idx);
67  bool GetBit(uint8 _idx) const;
68 
69  bool SetBitMask(uint32 _bitMask);
70  uint32 GetBitMask() const;
71 
72  void OnValueRefreshed(uint32 const _value);
73 
74  // From Value
75  virtual string const GetAsString() const;
76  virtual string const GetAsBinaryString() const;
77  virtual bool SetFromString(string const& _value);
78  virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement);
79  virtual void WriteXML(TiXmlElement* _valueElement);
80 
81  string GetBitHelp(uint8 _idx);
82  bool SetBitHelp(uint8 _idx, string help);
83  string GetBitLabel(uint8 _idx);
84  bool SetBitLabel(uint8 _idx, string label);
85 
86  uint8 GetSize() const;
87  void SetSize(uint8 size);
88 
89  private:
90  bool isValidBit(uint8 _idx) const;
91  Bitfield m_value; // the current index in the m_items vector
92  Bitfield m_valueCheck; // the previous value (used for double-checking spurious value reads)
93  Bitfield m_newValue; // a new value to be set on the appropriate device
94  uint32 m_BitMask; // Valid Bits
95  uint8 m_size; // Number of bytes in size
96  vector<int32> m_bits;
97  uint32 m_targetValue; // Target Value, if Supported;
98  };
99  } // namespace VC
100  } // namespace Internal
101 } // namespace OpenZWave
102 
103 #endif
104 
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:289
unsigned short uint16
Definition: Defs.h:88
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: ValueBitSet.cpp:167
void SetSize(uint8 size)
Definition: ValueBitSet.cpp:339
void OnValueRefreshed()
Definition: Value.cpp:351
uint8 GetSize() const
Definition: ValueBitSet.cpp:335
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:91
bool SetBit(uint8 const _idx)
Definition: ValueBitSet.cpp:230
void SetTargetValue(uint32 const _target, uint32 _duration=0)
Definition: ValueBitSet.cpp:348
ValueBitSet()
Definition: ValueBitSet.h:53
bool SetBitLabel(uint8 _idx, string label)
Definition: ValueBitSet.cpp:323
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:313
uint32 GetBitMask() const
Definition: ValueBitSet.cpp:281
ValueGenre
Definition: ValueID.h:84
Base class for values associated with a node.
Definition: Value.h:54
unsigned char uint8
Definition: Defs.h:85