OpenZWave Library  1.6.0
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 
35 class TiXmlElement;
36 
37 namespace OpenZWave
38 {
63  {
64  friend class Manager;
65  friend class Driver;
66  friend class Node;
67  friend class Group;
68  friend class CommandClass;
69  friend class Value;
70  friend class ValueStore;
71  friend class Notification;
72  friend class ManufacturerSpecific;
73 
74  public:
81  {
82  ValueGenre_Basic = 0,
86  ValueGenre_Count
87  };
88 
94  enum ValueType
95  {
96  ValueType_Bool = 0,
107  ValueType_Max = ValueType_BitSet
108  };
109 
115  {
116  return m_homeId;
117  }
118 
124  {
125  return( (uint8)( (m_id & 0xff000000) >> 24 ) );
126  }
127 
135  {
136  return( (ValueGenre)( (m_id & 0x00c00000) >> 22 ) );
137  }
138 
146  {
147  return( (uint8)( (m_id & 0x003fc000) >> 14 ) );
148  }
149 
159  {
160  return( (uint8)( ( (m_id & 0xff0) ) >> 4 ) );
161  }
162 
172  {
173  return( (uint16)( (m_id1 & 0xFFFF0000) >> 16 ) );
174  }
175 
184  {
185  return( (ValueType)( m_id & 0x0000000f ) );
186  }
187 
193  uint64 GetId()const
194  {
195  return (uint64) ( ( (uint64)m_id1 << 32 ) | m_id );
196  }
197 
198  // Comparison Operators
199  bool operator == ( ValueID const& _other )const{ return( ( m_homeId == _other.m_homeId ) && ( m_id == _other.m_id ) && ( m_id1 == _other.m_id1 ) ); }
200  bool operator != ( ValueID const& _other )const{ return( ( m_homeId != _other.m_homeId ) || ( m_id != _other.m_id ) || ( m_id1 != _other.m_id1 ) ); }
201  bool operator < ( ValueID const& _other )const
202  {
203  if( m_homeId == _other.m_homeId )
204  {
205  if( m_id == _other.m_id )
206  {
207  return( m_id1 < _other.m_id1 );
208  }
209  else
210  {
211  return( m_id < _other.m_id );
212  }
213  }
214  else
215  {
216  return( m_homeId < _other.m_homeId );
217  }
218  }
219  bool operator > ( ValueID const& _other )const
220  {
221  if( m_homeId == _other.m_homeId )
222  {
223  if( m_id == _other.m_id )
224  {
225  return( m_id1 > _other.m_id1 );
226  }
227  else
228  {
229  return( m_id > _other.m_id );
230  }
231  }
232  else
233  {
234  return( m_homeId > _other.m_homeId );
235  }
236  }
237 
252  ValueID
253  (
254  uint32 const _homeId,
255  uint8 const _nodeId,
256  ValueGenre const _genre,
257  uint8 const _commandClassId,
258  uint8 const _instance,
259  uint16 const _valueIndex,
260  ValueType const _type
261  ):
262  m_homeId( _homeId )
263  {
264  m_id = (((uint32)_nodeId)<<24)
265  | (((uint32)_genre)<<22)
266  | (((uint32)_commandClassId)<<14)
267  | (((uint32)(_instance & 0xFF))<<4)
268  | ((uint32)_type);
269  m_id1 = (((uint32)_valueIndex)<<16);
270  }
271 
272  /* construct a ValueID based on the HomeID and the unit64 returned from GetID
273  * \param _homeId - The HomeID
274  * \param id - The ID returned from ValueID::GetID
275  * \see ValueID::GetId
276  */
277  ValueID
278  (
279  uint32 _homeId,
280  uint64 id
281  ):
282  m_homeId(_homeId)
283  {
284  m_id = ((uint32)(id & 0xFFFFFFFF));
285  m_id1 = (uint32)(id >> 32);
286  }
287  private:
288  // Construct a value id for use in notifications
289  ValueID( uint32 const _homeId, uint8 const _nodeId ):
290  m_id1( 0 ),
291  m_homeId( _homeId )
292  {
293  m_id = ((uint32)_nodeId)<<24;
294  }
295  ValueID( uint32 const _homeId, uint8 const _nodeId, uint32 const _instance ):
296  m_homeId( _homeId )
297  {
298  m_id = (((uint32)_nodeId)<<24) | (((uint32)_instance) << 4);
299  m_id1 = 0;
300  }
301 
302  // Default constructor
303  ValueID():
304  m_id(0),
305  m_id1(0),
306  m_homeId(0)
307  {
308 
309  }
310 
311  // Not all parts of the ValueID are necessary to uniquely identify the value. In the case of a
312  // Node's ValueStore, we can ignore the home ID, node ID, genre and type and still be left with
313  // a unique integer than can be used as a key to look up values. The two GetValueStoreKey methods
314  // below are helpers to enable command classes to easily access their values from the ValueStore.
315 
316  // Get the key from our own m_id
317  uint32 GetValueStoreKey()const
318  {
319  /* 0xIIIICCii
320  * I = Index
321  * C = CC
322  * i = Instance
323  */
324  /* CC Index Instance */
325  return ( ( ( m_id & 0x003fc000 ) >> 6) | ( m_id1 & 0xffff0000 ) | ( ( m_id & 0xFF0) >> 4 ) );
326  }
327 
328  // Generate a key from its component parts
329  static uint32 GetValueStoreKey( uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex )
330  {
331 
332  uint32 key = (((uint32)_instance))
333  | (((uint32)_commandClassId)<<8)
334  | (((uint32)(_valueIndex & 0xFFFF))<<16);
335 
336  return key;
337  }
338 
339  // ID Packing:
340  // Bits
341  // 24-31: 8 bits. Node ID of device
342  // 22-23: 2 bits. genre of value (see ValueGenre enum).
343  // 14-21: 8 bits. ID of command class that created and manages this value.
344  // 12-13 Unused.
345  // 04-11: 8 bits. Instance of the Value
346  // 00-03: 4 bits. Type of value (bool, byte, string etc).
347  uint32 m_id;
348 
349  // ID1 Packing:
350  // Bits
351  // 16-31 16 bits. Instance Index of the command class.
352  uint32 m_id1;
353 
354  // Unique PC interface identifier
355  uint32 m_homeId;
356  };
357 
358 } // namespace OpenZWave
359 
360 #endif
Definition: Bitfield.h:34
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:44
uint16 GetIndex() const
Definition: ValueID.h:171
uint32 GetHomeId() const
Definition: ValueID.h:114
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
Implements COMMAND_CLASS_MANUFACTURER_SPECIFIC (0x72), a Z-Wave device command class.
Definition: ManufacturerSpecific.h:39
unsigned short uint16
Definition: Defs.h:92
ValueType
Definition: ValueID.h:94
Definition: ValueID.h:104
Definition: ValueID.h:83
uint8 GetCommandClassId() const
Definition: ValueID.h:145
The main public interface to OpenZWave.
Definition: Manager.h:110
uint8 GetNodeId() const
Definition: ValueID.h:123
uint8 GetInstance() const
Definition: ValueID.h:158
Definition: ValueID.h:106
ValueGenre GetGenre() const
Definition: ValueID.h:134
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:65
ValueType GetType() const
Definition: ValueID.h:183
Base class for all Z-Wave command classes.
Definition: CommandClass.h:55
Definition: ValueID.h:97
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:64
unsigned int uint32
Definition: Defs.h:95
Manages a group of devices (various nodes associated with each other).
Definition: Group.h:49
uint64 GetId() const
Definition: ValueID.h:193
Provides a container for data sent via the notification callback handler installed by a call to Manag...
Definition: Notification.h:44
Provides a unique ID for a value reported by a Z-Wave device.The ValueID is used to uniquely identify...
Definition: ValueID.h:62
Definition: ValueID.h:99
Definition: ValueID.h:102
Base class for values associated with a node.
Definition: Value.h:48
Definition: ValueID.h:100
Definition: ValueID.h:105
Definition: ValueID.h:103
ValueGenre
Definition: ValueID.h:80
unsigned char uint8
Definition: Defs.h:89