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 46 /** \brief BitSet value sent to/received from a node. 47 * \ingroup ValueID 48 */ 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); ValueBitSet()53 ValueBitSet() 54 { 55 } ~ValueBitSet()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 102