OpenZWave Library 1.2
ValueID.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// ValueID.h
4//
5// Unique identifier for a Value object
6//
7// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
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 _ValueID_H
29#define _ValueID_H
30
31#include <string>
32#include <assert.h>
33#include "Defs.h"
34
35class TiXmlElement;
36
37namespace OpenZWave
38{
54 {
55 friend class Manager;
56 friend class Driver;
57 friend class Node;
58 friend class Group;
59 friend class CommandClass;
60 friend class Value;
61 friend class ValueStore;
62 friend class Notification;
64
65 public:
72 {
73 ValueGenre_Basic = 0,
77 ValueGenre_Count
78 };
79
86 {
87 ValueType_Bool = 0,
97 ValueType_Max = ValueType_Raw
98 };
99
104 uint32 GetHomeId()const{ return m_homeId; }
105
110 uint8 GetNodeId()const{ return( (uint8)( (m_id & 0xff000000) >> 24 ) ); }
111
118 ValueGenre GetGenre()const{ return( (ValueGenre)( (m_id & 0x00c00000) >> 22 ) ); }
119
126 uint8 GetCommandClassId()const{ return( (uint8)( (m_id & 0x003fc000) >> 14 ) ); }
127
136 uint8 GetInstance()const{ return( (uint8)( ( (m_id1 & 0xff000000) ) >> 24 ) ); }
137
146 uint8 GetIndex()const{ return( (uint8)( (m_id & 0x00000ff0) >> 4 ) ); }
147
155 ValueType GetType()const{ return( (ValueType)( m_id & 0x0000000f ) ); }
156
162 uint64 GetId()const{ return (uint64) ( ( (uint64)m_id1 << 32 ) | m_id );}
163
164 // Comparison Operators
165 bool operator == ( ValueID const& _other )const{ return( ( m_homeId == _other.m_homeId ) && ( m_id == _other.m_id ) && ( m_id1 == _other.m_id1 ) ); }
166 bool operator != ( ValueID const& _other )const{ return( ( m_homeId != _other.m_homeId ) || ( m_id != _other.m_id ) || ( m_id1 != _other.m_id1 ) ); }
167 bool operator < ( ValueID const& _other )const
168 {
169 if( m_homeId == _other.m_homeId )
170 {
171 if( m_id == _other.m_id )
172 {
173 return( m_id1 < _other.m_id1 );
174 }
175 else
176 {
177 return( m_id < _other.m_id );
178 }
179 }
180 else
181 {
182 return( m_homeId < _other.m_homeId );
183 }
184 }
185 bool operator > ( ValueID const& _other )const
186 {
187 if( m_homeId == _other.m_homeId )
188 {
189 if( m_id == _other.m_id )
190 {
191 return( m_id1 > _other.m_id1 );
192 }
193 else
194 {
195 return( m_id > _other.m_id );
196 }
197 }
198 else
199 {
200 return( m_homeId > _other.m_homeId );
201 }
202 }
203
219 (
220 uint32 const _homeId,
221 uint8 const _nodeId,
222 ValueGenre const _genre,
223 uint8 const _commandClassId,
224 uint8 const _instance,
225 uint8 const _valueIndex,
226 ValueType const _type
227 ):
228 m_homeId( _homeId )
229 {
230 m_id = (((uint32)_nodeId)<<24)
231 | (((uint32)_genre)<<22)
232 | (((uint32)_commandClassId)<<14)
233 | (((uint32)_valueIndex)<<4)
234 | ((uint32)_type);
235 m_id1 = (((uint32)_instance)<<24);
236 }
237
238 /* construct a ValueID based on the HomeID and the unit64 returned from GetID
239 * \param _homeId - The HomeID
240 * \param id - The ID returned from ValueID::GetID
241 * \see ValueID::GetId
242 */
244 (
245 uint32 _homeId,
246 uint64 id
247 ):
248 m_homeId(_homeId)
249 {
250 m_id = ((uint32)(id & 0xFFFFFFFF));
251 m_id1 = (uint32)(id >> 32);
252 }
253 private:
254 // Construct a value id for use in notifications
255 ValueID( uint32 const _homeId, uint8 const _nodeId ): m_id1( 0 ),m_homeId( _homeId ){ m_id = ((uint32)_nodeId)<<24; }
256 ValueID( uint32 const _homeId, uint8 const _nodeId, uint32 const _instance ):
257 m_homeId( _homeId )
258 {
259 m_id = (((uint32)_nodeId)<<24);
260 m_id1 = (((uint32)_instance)<<24);
261 }
262
263 // Default constructor
264 ValueID():m_id(0),m_id1(0),m_homeId(0){}
265
266 // Not all parts of the ValueID are necessary to uniquely identify the value. In the case of a
267 // Node's ValueStore, we can ignore the home ID, node ID, genre and type and still be left with
268 // a unique integer than can be used as a key to look up values. The two GetValueStoreKey methods
269 // below are helpers to enable command classes to easily access their values from the ValueStore.
270
271 // Get the key from our own m_id
272 uint32 GetValueStoreKey()const
273 {
274 return ( ( m_id & 0x003ffff0 ) | ( m_id1 & 0xff000000 ) );
275 }
276
277 // Generate a key from its component parts
278 static uint32 GetValueStoreKey( uint8 const _commandClassId, uint8 const _instance, uint8 const _valueIndex )
279 {
280
281 uint32 key = (((uint32)_instance)<<24)
282 | (((uint32)_commandClassId)<<14)
283 | (((uint32)_valueIndex)<<4);
284
285 return key;
286 }
287
288 // ID Packing:
289 // Bits
290 // 24-31: 8 bits. Node ID of device
291 // 22-23: 2 bits. genre of value (see ValueGenre enum).
292 // 14-21: 8 bits. ID of command class that created and manages this value.
293 // 12-13: 2 bits. Unused.
294 // 04-11: 8 bits. Index of value within all the value created by the command class
295 // instance (in configuration parameters, this is also the parameter ID).
296 // 00-03: 4 bits. Type of value (bool, byte, string etc).
297 uint32 m_id;
298
299 // ID1 Packing:
300 // Bits
301 // 24-31 8 bits. Instance Index of the command class.
302 uint32 m_id1;
303
304 // Unique PC interface identifier
305 uint32 m_homeId;
306 };
307
308} // namespace OpenZWave
309
310#endif
unsigned int uint32
Definition: Defs.h:69
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
unsigned char uint8
Definition: Defs.h:63
Base class for all Z-Wave command classes.
Definition: CommandClass.h:47
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:57
Manages a group of devices (various nodes associated with each other).
Definition: Group.h:45
The main public interface to OpenZWave.
Definition: Manager.h:109
Implements COMMAND_CLASS_MANUFACTURER_SPECIFIC (0x72), a Z-Wave device command class.
Definition: ManufacturerSpecific.h:39
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:64
Provides a container for data sent via the notification callback handler installed by a call to Manag...
Definition: Notification.h:43
Provides a unique ID for a value reported by a Z-Wave device.
Definition: ValueID.h:54
uint8 GetIndex() const
Definition: ValueID.h:146
ValueType
Definition: ValueID.h:86
@ ValueType_Button
Definition: ValueID.h:95
@ ValueType_Raw
Definition: ValueID.h:96
@ ValueType_Int
Definition: ValueID.h:90
@ ValueType_String
Definition: ValueID.h:94
@ ValueType_List
Definition: ValueID.h:91
@ ValueType_Schedule
Definition: ValueID.h:92
@ ValueType_Short
Definition: ValueID.h:93
@ ValueType_Byte
Definition: ValueID.h:88
@ ValueType_Decimal
Definition: ValueID.h:89
uint32 GetHomeId() const
Definition: ValueID.h:104
ValueID(uint32 const _homeId, uint8 const _nodeId, ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint8 const _valueIndex, ValueType const _type)
Definition: ValueID.h:219
ValueType GetType() const
Definition: ValueID.h:155
uint8 GetCommandClassId() const
Definition: ValueID.h:126
uint8 GetInstance() const
Definition: ValueID.h:136
ValueID(uint32 _homeId, uint64 id)
Definition: ValueID.h:244
ValueGenre GetGenre() const
Definition: ValueID.h:118
uint64 GetId() const
Definition: ValueID.h:162
uint8 GetNodeId() const
Definition: ValueID.h:110
ValueGenre
Definition: ValueID.h:72
@ ValueGenre_Config
Definition: ValueID.h:75
@ ValueGenre_System
Definition: ValueID.h:76
@ ValueGenre_User
Definition: ValueID.h:74
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:44
Base class for values associated with a node.
Definition: Value.h:45
Definition: Bitfield.h:35