OpenZWave Library  1.6.989
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  }
218 
219  // Comparison Operators
220  bool operator ==(ValueID const& _other) const
221  {
222  return ((m_homeId == _other.m_homeId) && (m_id == _other.m_id) && (m_id1 == _other.m_id1));
223  }
224  bool operator !=(ValueID const& _other) const
225  {
226  return ((m_homeId != _other.m_homeId) || (m_id != _other.m_id) || (m_id1 != _other.m_id1));
227  }
228  bool operator <(ValueID const& _other) const
229  {
230  if (m_homeId == _other.m_homeId)
231  {
232  if (m_id == _other.m_id)
233  {
234  return (m_id1 < _other.m_id1);
235  }
236  else
237  {
238  return (m_id < _other.m_id);
239  }
240  }
241  else
242  {
243  return (m_homeId < _other.m_homeId);
244  }
245  }
246  bool operator >(ValueID const& _other) const
247  {
248  if (m_homeId == _other.m_homeId)
249  {
250  if (m_id == _other.m_id)
251  {
252  return (m_id1 > _other.m_id1);
253  }
254  else
255  {
256  return (m_id > _other.m_id);
257  }
258  }
259  else
260  {
261  return (m_homeId > _other.m_homeId);
262  }
263  }
264 
279  ValueID(uint32 const _homeId, uint8 const _nodeId, ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex, ValueType const _type) :
280  m_homeId(_homeId)
281  {
282  m_id = (((uint32) _nodeId) << 24) | (((uint32) _genre) << 22) | (((uint32) _commandClassId) << 14) | (((uint32) (_instance & 0xFF)) << 4) | ((uint32) _type);
283  m_id1 = (((uint32) _valueIndex) << 16);
284  }
285 
286  /* construct a ValueID based on the HomeID and the unit64 returned from GetID
287  * \param _homeId - The HomeID
288  * \param id - The ID returned from ValueID::GetID
289  * \see ValueID::GetId
290  */
291  ValueID(uint32 _homeId, uint64 id) :
292  m_homeId(_homeId)
293  {
294  m_id = ((uint32) (id & 0xFFFFFFFF));
295  m_id1 = (uint32) (id >> 32);
296  }
297 
298  // Construct a value id for use in notifications
299  ValueID(uint32 const _homeId, uint8 const _nodeId) :
300  m_id1(0), m_homeId(_homeId)
301  {
302  m_id = ((uint32) _nodeId) << 24;
303  }
304  ValueID(uint32 const _homeId, uint8 const _nodeId, uint32 const _instance) :
305  m_homeId(_homeId)
306  {
307  m_id = (((uint32) _nodeId) << 24) | (((uint32) _instance) << 4);
308  m_id1 = 0;
309  }
310 
311  // Default constructor
313  m_id(0), m_id1(0), m_homeId(0)
314  {
315 
316  }
317 
318  // Not all parts of the ValueID are necessary to uniquely identify the value. In the case of a
319  // Node's ValueStore, we can ignore the home ID, node ID, genre and type and still be left with
320  // a unique integer than can be used as a key to look up values. The two GetValueStoreKey methods
321  // below are helpers to enable command classes to easily access their values from the ValueStore.
322 
323  // Get the key from our own m_id
325  {
326  /* 0xIIIICCii
327  * I = Index
328  * C = CC
329  * i = Instance
330  */
331  /* CC Index Instance */
332  return (((m_id & 0x003fc000) >> 6) | (m_id1 & 0xffff0000) | ((m_id & 0xFF0) >> 4));
333  }
334 
335  // Generate a key from its component parts
336  static uint32 GetValueStoreKey(uint8 const _commandClassId, uint8 const _instance, uint16 const _valueIndex)
337  {
338 
339  uint32 key = (((uint32) _instance)) | (((uint32) _commandClassId) << 8) | (((uint32) (_valueIndex & 0xFFFF)) << 16);
340 
341  return key;
342  }
343 
344  private:
345 
346  // ID Packing:
347  // Bits
348  // 24-31: 8 bits. Node ID of device
349  // 22-23: 2 bits. genre of value (see ValueGenre enum).
350  // 14-21: 8 bits. ID of command class that created and manages this value.
351  // 12-13 Unused.
352  // 04-11: 8 bits. Instance of the Value
353  // 00-03: 4 bits. Type of value (bool, byte, string etc).
354  uint32 m_id;
355 
356  // ID1 Packing:
357  // Bits
358  // 16-31 16 bits. Instance Index of the command class.
359  uint32 m_id1;
360 
361  // Unique PC interface identifier
362  uint32 m_homeId;
363  };
364 
365 } // namespace OpenZWave
366 
367 #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:299
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:336
ValueType GetType() const
Definition: ValueID.h:195
ValueID(uint32 const _homeId, uint8 const _nodeId, uint32 const _instance)
Definition: ValueID.h:304
ValueID()
Definition: ValueID.h:312
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:279
ValueID(uint32 _homeId, uint64 id)
Definition: ValueID.h:291
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:324
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