OpenZWave Library  1.5.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  class Msg;
42  class Node;
43  class CommandClass;
44 
48  class ValueBitSet: public Value
49  {
50  public:
51  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 );
53  virtual ~ValueBitSet(){}
54 
55  bool Set( uint32 const _value );
56  uint32 GetValue() const;
57 
58  bool SetBit( uint8 const _idx);
59  bool ClearBit(uint8 const _idx);
60  bool GetBit(uint8 _idx) const;
61 
62  bool SetBitMask(uint32 _bitMask);
63  uint32 GetBitMask() const;
64 
65  void OnValueRefreshed( uint32 const _value );
66 
67  // From Value
68  virtual string const GetAsString() const;
69  virtual string const GetAsBinaryString() const;
70  virtual bool SetFromString( string const& _value );
71  virtual void ReadXML( uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement );
72  virtual void WriteXML( TiXmlElement* _valueElement );
73 
74  string GetBitHelp(uint8 _idx);
75  bool SetBitHelp(uint8 _idx, string help);
76  string GetBitLabel(uint8 _idx);
77  bool SetBitLabel(uint8 _idx, string label);
78 
79  uint8 GetSize() const;
80  void SetSize(uint8 size);
81 
82  private:
83  bool isValidBit(uint8 _idx) const;
84  Bitfield m_value; // the current index in the m_items vector
85  Bitfield m_valueCheck; // the previous value (used for double-checking spurious value reads)
86  Bitfield m_newValue; // a new value to be set on the appropriate device
87  uint32 m_BitMask; // Valid Bits
88  std::map<uint8, string> m_BitHelpString; // Help Strings for each Bit
89  std::map<uint8, string> m_BitLabelString; // Labels for each Bit
90  uint8 m_size; // Number of bytes in size
91  };
92 
93 } // namespace OpenZWave
94 
95 #endif
96 
97 
98 
bool SetBitLabel(uint8 _idx, string label)
Definition: ValueBitSet.cpp:365
Definition: Bitfield.h:34
unsigned short uint16
Definition: Defs.h:93
string GetBitHelp(uint8 _idx)
Definition: ValueBitSet.cpp:313
uint32 GetBitMask() const
Definition: ValueBitSet.cpp:306
virtual bool SetFromString(string const &_value)
Definition: ValueBitSet.cpp:68
void SetSize(uint8 size)
Definition: ValueBitSet.cpp:386
Definition: Bitfield.h:36
BitSet value sent to/received from a node.
Definition: ValueBitSet.h:48
uint8 GetSize() const
Definition: ValueBitSet.cpp:380
void OnValueRefreshed()
Definition: Value.cpp:415
unsigned int uint32
Definition: Defs.h:96
bool GetBit(uint8 _idx) const
Definition: ValueBitSet.cpp:102
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: ValueBitSet.cpp:120
virtual string const GetAsString() const
Definition: ValueBitSet.cpp:77
string GetBitLabel(uint8 _idx)
Definition: ValueBitSet.cpp:349
bool ClearBit(uint8 const _idx)
Definition: ValueBitSet.cpp:272
bool SetBit(uint8 const _idx)
Definition: ValueBitSet.cpp:248
virtual ~ValueBitSet()
Definition: ValueBitSet.h:53
Base class for values associated with a node.
Definition: Value.h:48
bool SetBitMask(uint32 _bitMask)
Definition: ValueBitSet.cpp:297
ValueBitSet()
Definition: ValueBitSet.h:52
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: ValueBitSet.cpp:189
uint32 GetValue() const
Definition: ValueBitSet.cpp:96
bool Set()
Definition: Value.cpp:353
ValueGenre
Definition: ValueID.h:80
virtual string const GetAsBinaryString() const
Definition: ValueBitSet.cpp:86
bool SetBitHelp(uint8 _idx, string help)
Definition: ValueBitSet.cpp:325
unsigned char uint8
Definition: Defs.h:90