OpenZWave Library  1.6.1545
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  public:
85  {
86  ValueGenre_Basic = 0,
90  ValueGenre_Count
91  };
92 
98  enum ValueType
99  {
100  ValueType_Bool = 0,
111  ValueType_Max = ValueType_BitSet
112  };
113 
119  {
120  return m_homeId;
121  }
122 
127  uint8 GetNodeId() const
128  {
129  return ((uint8) ((m_id & 0xff000000) >> 24));
130  }
131 
139  {
140  return ((ValueGenre) ((m_id & 0x00c00000) >> 22));
141  }
142 
149  string GetGenreAsString() const;
150 
158  {
159  return ((uint8) ((m_id & 0x003fc000) >> 14));
160  }
161 
171  {
172  return ((uint8) (((m_id & 0xff0)) >> 4));
173  }
174 
183  uint16 GetIndex() const
184  {
185  return ((uint16) ((m_id1 & 0xFFFF0000) >> 16));
186  }
187 
196  {
197  return ((ValueType) (m_id & 0x0000000f));
198  }
199 
207  string GetTypeAsString() const;
208 
214  uint64 GetId() const
215  {
216  return (uint64) (((uint64) m_id1 << 32) | m_id);
217  }
222  string const GetAsString() const;
223 
224  // Comparison Operators
225  bool operator ==(ValueID const& _other) const
226  {
227  return ((m_homeId == _other.m_homeId) && (m_id == _other.m_id) && (m_id1 == _other.m_id1));
228  }
229  bool operator !=(ValueID const& _other) const
230  {
231  return ((m_homeId != _other.m_homeId) || (m_id != _other.m_id) || (m_id1 != _other.m_id1));
232  }
233  bool operator <(ValueID const& _other) const
234  {
235  if (m_homeId == _other.m_homeId)
236  {
237  if (m_id == _other.m_id)
238  {
239  return (m_id1 < _other.m_id1);
240  }
241  else
242  {
243  return (m_id < _other.m_id);
244  }
245  }
246  else
247  {
248  return (m_homeId < _other.m_homeId);
249  }
250  }
251  bool operator >(ValueID const& _other) const
252  {
253  if (m_homeId == _other.m_homeId)
254  {
255  if (m_id == _other.m_id)
256  {
257  return (m_id1 > _other.m_id1);
258  }
259  else
260  {
261  return (m_id > _other.m_id);
262  }
263  }
264  else
265  {
266  return (m_homeId > _other.m_homeId);
267  }
268  }
269 
284  ValueID(uint32 const _homeId, uint8 const _nodeId, ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex, ValueType const _type) :
285  m_homeId(_homeId)
286  {
287  m_id = (((uint32) _nodeId) << 24) | (((uint32) _genre) << 22) | (((uint32) _commandClassId) << 14) | (((uint32) (_instance & 0xFF)) << 4) | ((uint32) _type);
288  m_id1 = (((uint32) _valueIndex) << 16);
289  }
290 
291  /* construct a ValueID based on the HomeID and the unit64 returned from GetID
292  * \param _homeId - The HomeID
293  * \param id - The ID returned from ValueID::GetID
294  * \see ValueID::GetId
295  */
296  ValueID(uint32 _homeId, uint64 id) :
297  m_homeId(_homeId)
298  {
299  m_id = ((uint32) (id & 0xFFFFFFFF));
300  m_id1 = (uint32) (id >> 32);
301  }
302 
303  // Construct a value id for use in notifications
304  ValueID(uint32 const _homeId, uint8 const _nodeId) :
305  m_id1(0), m_homeId(_homeId)
306  {
307  m_id = ((uint32) _nodeId) << 24;
308  }
309  ValueID(uint32 const _homeId, uint8 const _nodeId, uint32 const _instance) :
310  m_homeId(_homeId)
311  {
312  m_id = (((uint32) _nodeId) << 24) | (((uint32) _instance) << 4);
313  m_id1 = 0;
314  }
315 
316  // Default constructor
318  m_id(0), m_id1(0), m_homeId(0)
319  {
320 
321  }
322 
323  // Not all parts of the ValueID are necessary to uniquely identify the value. In the case of a
324  // Node's ValueStore, we can ignore the home ID, node ID, genre and type and still be left with
325  // a unique integer than can be used as a key to look up values. The two GetValueStoreKey methods
326  // below are helpers to enable command classes to easily access their values from the ValueStore.
327 
328  // Get the key from our own m_id
330  {
331  /* 0xIIIICCii
332  * I = Index
333  * C = CC
334  * i = Instance
335  */
336  /* CC Index Instance */
337  return (((m_id & 0x003fc000) >> 6) | (m_id1 & 0xffff0000) | ((m_id & 0xFF0) >> 4));
338  }
339 
340  // Generate a key from its component parts
341  static uint32 GetValueStoreKey(uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex)
342  {
343 
344  uint32 key = (((uint32) _instance)) | (((uint32) _commandClassId) << 8) | (((uint32) (_valueIndex & 0xFFFF)) << 16);
345 
346  return key;
347  }
348 
349  private:
350 
351  // ID Packing:
352  // Bits
353  // 24-31: 8 bits. Node ID of device
354  // 22-23: 2 bits. genre of value (see ValueGenre enum).
355  // 14-21: 8 bits. ID of command class that created and manages this value.
356  // 12-13 Unused.
357  // 04-11: 8 bits. Instance of the Value
358  // 00-03: 4 bits. Type of value (bool, byte, string etc).
359  uint32 m_id;
360 
361  // ID1 Packing:
362  // Bits
363  // 16-31 16 bits. Instance Index of the command class.
364  uint32 m_id1;
365 
366  // Unique PC interface identifier
367  uint32 m_homeId;
368  };
369 
370 } // namespace OpenZWave
371 
372 #endif
Definition: Bitfield.cpp:30
uint16 GetIndex() const
Definition: ValueID.h:183
uint32 GetHomeId() const
Definition: ValueID.h:118
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
unsigned short uint16
Definition: Defs.h:88
ValueType
Definition: ValueID.h:98
ValueID(uint32 const _homeId, uint8 const _nodeId)
Definition: ValueID.h:304
Definition: ValueID.h:108
Definition: ValueID.h:102
Definition: ValueID.h:87
uint8 GetCommandClassId() const
Definition: ValueID.h:157
uint8 GetNodeId() const
Definition: ValueID.h:127
uint8 GetInstance() const
Definition: ValueID.h:170
Definition: ValueID.h:110
ValueGenre GetGenre() const
Definition: ValueID.h:138
static uint32 GetValueStoreKey(uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex)
Definition: ValueID.h:341
ValueType GetType() const
Definition: ValueID.h:195
ValueID(uint32 const _homeId, uint8 const _nodeId, uint32 const _instance)
Definition: ValueID.h:309
ValueID()
Definition: ValueID.h:317
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:284
ValueID(uint32 _homeId, uint64 id)
Definition: ValueID.h:296
Definition: ValueID.h:101
unsigned int uint32
Definition: Defs.h:91
uint64 GetId() const
Definition: ValueID.h:214
Provides a unique ID for a value reported by a Z-Wave device.The ValueID is used to uniquely identify...
Definition: ValueID.h:76
uint32 GetValueStoreKey() const
Definition: ValueID.h:329
Definition: ValueID.h:103
Definition: ValueID.h:106
Definition: ValueID.h:104
Definition: ValueID.h:109
Definition: ValueID.h:107
ValueGenre
Definition: ValueID.h:84
unsigned char uint8
Definition: Defs.h:85