OpenZWave Library  1.6.936
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 
34 #include "ValueIDIndexes.h"
35 #include "Defs.h"
36 
37 class TiXmlElement;
38 
39 namespace OpenZWave
40 {
41 
42  namespace Internal
43  {
44  namespace VC
45  {
46  class Value;
47  class ValueStore;
48  }
49  ;
50  }
51  ;
52 
77  {
78  friend class Manager;
79  friend class Driver;
80  friend class Node;
81  friend class Group;
82  friend class Internal::VC::Value;
84  friend class Notification;
85 
86  public:
93  {
94  ValueGenre_Basic = 0,
98  ValueGenre_Count
99  };
100 
107  {
108  ValueType_Bool = 0,
119  ValueType_Max = ValueType_BitSet
120  };
121 
127  {
128  return m_homeId;
129  }
130 
135  uint8 GetNodeId() const
136  {
137  return ((uint8) ((m_id & 0xff000000) >> 24));
138  }
139 
147  {
148  return ((ValueGenre) ((m_id & 0x00c00000) >> 22));
149  }
150 
157  string GetGenreAsString() const;
158 
166  {
167  return ((uint8) ((m_id & 0x003fc000) >> 14));
168  }
169 
179  {
180  return ((uint8) (((m_id & 0xff0)) >> 4));
181  }
182 
191  uint16 GetIndex() const
192  {
193  return ((uint16) ((m_id1 & 0xFFFF0000) >> 16));
194  }
195 
204  {
205  return ((ValueType) (m_id & 0x0000000f));
206  }
207 
215  string GetTypeAsString() const;
216 
222  uint64 GetId() const
223  {
224  return (uint64) (((uint64) m_id1 << 32) | m_id);
225  }
226 
227  // Comparison Operators
228  bool operator ==(ValueID const& _other) const
229  {
230  return ((m_homeId == _other.m_homeId) && (m_id == _other.m_id) && (m_id1 == _other.m_id1));
231  }
232  bool operator !=(ValueID const& _other) const
233  {
234  return ((m_homeId != _other.m_homeId) || (m_id != _other.m_id) || (m_id1 != _other.m_id1));
235  }
236  bool operator <(ValueID const& _other) const
237  {
238  if (m_homeId == _other.m_homeId)
239  {
240  if (m_id == _other.m_id)
241  {
242  return (m_id1 < _other.m_id1);
243  }
244  else
245  {
246  return (m_id < _other.m_id);
247  }
248  }
249  else
250  {
251  return (m_homeId < _other.m_homeId);
252  }
253  }
254  bool operator >(ValueID const& _other) const
255  {
256  if (m_homeId == _other.m_homeId)
257  {
258  if (m_id == _other.m_id)
259  {
260  return (m_id1 > _other.m_id1);
261  }
262  else
263  {
264  return (m_id > _other.m_id);
265  }
266  }
267  else
268  {
269  return (m_homeId > _other.m_homeId);
270  }
271  }
272 
287  ValueID(uint32 const _homeId, uint8 const _nodeId, ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex, ValueType const _type) :
288  m_homeId(_homeId)
289  {
290  m_id = (((uint32) _nodeId) << 24) | (((uint32) _genre) << 22) | (((uint32) _commandClassId) << 14) | (((uint32) (_instance & 0xFF)) << 4) | ((uint32) _type);
291  m_id1 = (((uint32) _valueIndex) << 16);
292  }
293 
294  /* construct a ValueID based on the HomeID and the unit64 returned from GetID
295  * \param _homeId - The HomeID
296  * \param id - The ID returned from ValueID::GetID
297  * \see ValueID::GetId
298  */
299  ValueID(uint32 _homeId, uint64 id) :
300  m_homeId(_homeId)
301  {
302  m_id = ((uint32) (id & 0xFFFFFFFF));
303  m_id1 = (uint32) (id >> 32);
304  }
305  private:
306  // Construct a value id for use in notifications
307  ValueID(uint32 const _homeId, uint8 const _nodeId) :
308  m_id1(0), m_homeId(_homeId)
309  {
310  m_id = ((uint32) _nodeId) << 24;
311  }
312  ValueID(uint32 const _homeId, uint8 const _nodeId, uint32 const _instance) :
313  m_homeId(_homeId)
314  {
315  m_id = (((uint32) _nodeId) << 24) | (((uint32) _instance) << 4);
316  m_id1 = 0;
317  }
318 
319  // Default constructor
320  ValueID() :
321  m_id(0), m_id1(0), m_homeId(0)
322  {
323 
324  }
325 
326  // Not all parts of the ValueID are necessary to uniquely identify the value. In the case of a
327  // Node's ValueStore, we can ignore the home ID, node ID, genre and type and still be left with
328  // a unique integer than can be used as a key to look up values. The two GetValueStoreKey methods
329  // below are helpers to enable command classes to easily access their values from the ValueStore.
330 
331  // Get the key from our own m_id
332  uint32 GetValueStoreKey() const
333  {
334  /* 0xIIIICCii
335  * I = Index
336  * C = CC
337  * i = Instance
338  */
339  /* CC Index Instance */
340  return (((m_id & 0x003fc000) >> 6) | (m_id1 & 0xffff0000) | ((m_id & 0xFF0) >> 4));
341  }
342 
343  // Generate a key from its component parts
344  static uint32 GetValueStoreKey(uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex)
345  {
346 
347  uint32 key = (((uint32) _instance)) | (((uint32) _commandClassId) << 8) | (((uint32) (_valueIndex & 0xFFFF)) << 16);
348 
349  return key;
350  }
351 
352  // ID Packing:
353  // Bits
354  // 24-31: 8 bits. Node ID of device
355  // 22-23: 2 bits. genre of value (see ValueGenre enum).
356  // 14-21: 8 bits. ID of command class that created and manages this value.
357  // 12-13 Unused.
358  // 04-11: 8 bits. Instance of the Value
359  // 00-03: 4 bits. Type of value (bool, byte, string etc).
360  uint32 m_id;
361 
362  // ID1 Packing:
363  // Bits
364  // 16-31 16 bits. Instance Index of the command class.
365  uint32 m_id1;
366 
367  // Unique PC interface identifier
368  uint32 m_homeId;
369  };
370 
371 } // namespace OpenZWave
372 
373 #endif
Definition: Bitfield.cpp:30
uint16 GetIndex() const
Definition: ValueID.h:191
uint32 GetHomeId() const
Definition: ValueID.h:126
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
unsigned short uint16
Definition: Defs.h:88
ValueType
Definition: ValueID.h:106
Definition: ValueID.h:116
Definition: ValueID.h:110
Definition: ValueID.h:95
uint8 GetCommandClassId() const
Definition: ValueID.h:165
The main public interface to OpenZWave.
Definition: Manager.h:108
uint8 GetNodeId() const
Definition: ValueID.h:135
uint8 GetInstance() const
Definition: ValueID.h:178
Definition: ValueID.h:118
ValueGenre GetGenre() const
Definition: ValueID.h:146
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:49
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:81
ValueType GetType() const
Definition: ValueID.h:203
ValueID(uint32 const _homeId, uint8 const _nodeId, ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex, ValueType const _type)
Definition: ValueID.h:287
ValueID(uint32 _homeId, uint64 id)
Definition: ValueID.h:299
Definition: ValueID.h:109
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:84
unsigned int uint32
Definition: Defs.h:91
Manages a group of devices (various nodes associated with each other).
Definition: Group.h:59
uint64 GetId() const
Definition: ValueID.h:222
Provides a container for data sent via the notification callback handler installed by a call to Manag...
Definition: Notification.h:62
Provides a unique ID for a value reported by a Z-Wave device.The ValueID is used to uniquely identify...
Definition: ValueID.h:76
Definition: ValueID.h:111
Definition: ValueID.h:114
Definition: ValueID.h:112
Definition: ValueID.h:117
Definition: ValueID.h:115
ValueGenre
Definition: ValueID.h:92
Base class for values associated with a node.
Definition: Value.h:53
unsigned char uint8
Definition: Defs.h:85