ValueID.h
Go to the documentation of this file.
//-----------------------------------------------------------------------------
//
// ValueID.h
//
// Unique identifier for a Value object
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#ifndef _ValueID_H
#define _ValueID_H
#include <string>
#include <assert.h>
#include "Defs.h"
class TiXmlElement;
namespace OpenZWave
{
class OPENZWAVE_EXPORT ValueID
{
friend class Manager;
friend class Driver;
friend class Node;
friend class Group;
friend class CommandClass;
friend class Value;
friend class ValueStore;
friend class Notification;
friend class ManufacturerSpecific;
public:
enum ValueGenre
{
ValueGenre_Basic = 0,
ValueGenre_User,
ValueGenre_Config,
ValueGenre_System,
ValueGenre_Count
};
enum ValueType
{
ValueType_Bool = 0,
ValueType_Byte,
ValueType_Decimal,
ValueType_Int,
ValueType_List,
ValueType_Schedule,
ValueType_Short,
ValueType_String,
ValueType_Button,
ValueType_Raw,
ValueType_Max = ValueType_Raw
};
uint32 GetHomeId()const{ return m_homeId; }
uint8 GetNodeId()const{ return( (uint8)( (m_id & 0xff000000) >> 24 ) ); }
ValueGenre GetGenre()const{ return( (ValueGenre)( (m_id & 0x00c00000) >> 22 ) ); }
uint8 GetCommandClassId()const{ return( (uint8)( (m_id & 0x003fc000) >> 14 ) ); }
uint8 GetInstance()const{ return( (uint8)( ( (m_id1 & 0xff000000) ) >> 24 ) ); }
uint8 GetIndex()const{ return( (uint8)( (m_id & 0x00000ff0) >> 4 ) ); }
ValueType GetType()const{ return( (ValueType)( m_id & 0x0000000f ) ); }
uint64 GetId()const{ return (uint64) ( ( (uint64)m_id1 << 32 ) | m_id );}
// Comparison Operators
bool operator == ( ValueID const& _other )const{ return( ( m_homeId == _other.m_homeId ) && ( m_id == _other.m_id ) && ( m_id1 == _other.m_id1 ) ); }
bool operator != ( ValueID const& _other )const{ return( ( m_homeId != _other.m_homeId ) || ( m_id != _other.m_id ) || ( m_id1 != _other.m_id1 ) ); }
bool operator < ( ValueID const& _other )const
{
if( m_homeId == _other.m_homeId )
{
if( m_id == _other.m_id )
{
return( m_id1 < _other.m_id1 );
}
else
{
return( m_id < _other.m_id );
}
}
else
{
return( m_homeId < _other.m_homeId );
}
}
bool operator > ( ValueID const& _other )const
{
if( m_homeId == _other.m_homeId )
{
if( m_id == _other.m_id )
{
return( m_id1 > _other.m_id1 );
}
else
{
return( m_id > _other.m_id );
}
}
else
{
return( m_homeId > _other.m_homeId );
}
}
ValueID
(
uint32 const _homeId,
uint8 const _nodeId,
ValueGenre const _genre,
uint8 const _commandClassId,
uint8 const _instance,
uint8 const _valueIndex,
ValueType const _type
):
m_homeId( _homeId )
{
m_id = (((uint32)_nodeId)<<24)
| (((uint32)_genre)<<22)
| (((uint32)_commandClassId)<<14)
| (((uint32)_valueIndex)<<4)
| ((uint32)_type);
m_id1 = (((uint32)_instance)<<24);
}
/* construct a ValueID based on the HomeID and the unit64 returned from GetID
* \param _homeId - The HomeID
* \param id - The ID returned from ValueID::GetID
* \see ValueID::GetId
*/
ValueID
(
uint32 _homeId,
uint64 id
):
m_homeId(_homeId)
{
m_id = ((uint32)(id & 0xFFFFFFFF));
m_id1 = (uint32)(id >> 32);
}
private:
// Construct a value id for use in notifications
ValueID( uint32 const _homeId, uint8 const _nodeId ): m_id1( 0 ),m_homeId( _homeId ){ m_id = ((uint32)_nodeId)<<24; }
ValueID( uint32 const _homeId, uint8 const _nodeId, uint32 const _instance ):
m_homeId( _homeId )
{
m_id = (((uint32)_nodeId)<<24);
m_id1 = (((uint32)_instance)<<24);
}
// Default constructor
ValueID():m_id(0),m_id1(0),m_homeId(0){}
// Not all parts of the ValueID are necessary to uniquely identify the value. In the case of a
// Node's ValueStore, we can ignore the home ID, node ID, genre and type and still be left with
// a unique integer than can be used as a key to look up values. The two GetValueStoreKey methods
// below are helpers to enable command classes to easily access their values from the ValueStore.
// Get the key from our own m_id
uint32 GetValueStoreKey()const
{
return ( ( m_id & 0x003ffff0 ) | ( m_id1 & 0xff000000 ) );
}
// Generate a key from its component parts
static uint32 GetValueStoreKey( uint8 const _commandClassId, uint8 const _instance, uint8 const _valueIndex )
{
uint32 key = (((uint32)_instance)<<24)
| (((uint32)_commandClassId)<<14)
| (((uint32)_valueIndex)<<4);
return key;
}
// ID Packing:
// Bits
// 24-31: 8 bits. Node ID of device
// 22-23: 2 bits. genre of value (see ValueGenre enum).
// 14-21: 8 bits. ID of command class that created and manages this value.
// 12-13: 2 bits. Unused.
// 04-11: 8 bits. Index of value within all the value created by the command class
// instance (in configuration parameters, this is also the parameter ID).
// 00-03: 4 bits. Type of value (bool, byte, string etc).
uint32 m_id;
// ID1 Packing:
// Bits
// 24-31 8 bits. Instance Index of the command class.
uint32 m_id1;
// Unique PC interface identifier
uint32 m_homeId;
};
} // namespace OpenZWave
#endif
OpenZWave
Definition: Bitfield.h:34
OpenZWave::ValueStore
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:43
OpenZWave::ValueID::GetHomeId
uint32 GetHomeId() const
Definition: ValueID.h:104
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
OpenZWave::ManufacturerSpecific
Implements COMMAND_CLASS_MANUFACTURER_SPECIFIC (0x72), a Z-Wave device command class.
Definition: ManufacturerSpecific.h:38
OpenZWave::ValueID::ValueType
ValueType
Definition: ValueID.h:85
OpenZWave::ValueID::ValueType_Button
Definition: ValueID.h:95
OpenZWave::ValueID::ValueType_Decimal
Definition: ValueID.h:89
OpenZWave::ValueID::ValueGenre_User
Definition: ValueID.h:74
OpenZWave::ValueID::GetCommandClassId
uint8 GetCommandClassId() const
Definition: ValueID.h:126
OpenZWave::Manager
The main public interface to OpenZWave.
Definition: Manager.h:109
OpenZWave::ValueID::GetNodeId
uint8 GetNodeId() const
Definition: ValueID.h:110
OpenZWave::ValueID::GetInstance
uint8 GetInstance() const
Definition: ValueID.h:136
OpenZWave::ValueID::GetGenre
ValueGenre GetGenre() const
Definition: ValueID.h:118
OpenZWave::Node
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:64
OpenZWave::ValueID::GetType
ValueType GetType() const
Definition: ValueID.h:155
Defs.h
OpenZWave::CommandClass
Base class for all Z-Wave command classes.
Definition: CommandClass.h:46
OpenZWave::ValueID::ValueType_Byte
Definition: ValueID.h:88
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:58
uint32
unsigned int uint32
Definition: Defs.h:80
OpenZWave::Group
Manages a group of devices (various nodes associated with each other).
Definition: Group.h:49
OpenZWave::ValueID::GetId
uint64 GetId() const
Definition: ValueID.h:162
OpenZWave::Notification
Provides a container for data sent via the notification callback handler installed by a call to Manag...
Definition: Notification.h:42
OpenZWave::ValueID
Provides a unique ID for a value reported by a Z-Wave device.
Definition: ValueID.h:53
OpenZWave::ValueID::ValueType_Int
Definition: ValueID.h:90
OpenZWave::ValueID::ValueType_Short
Definition: ValueID.h:93
OpenZWave::ValueID::ValueGenre_Config
Definition: ValueID.h:75
OpenZWave::ValueID::ValueGenre_System
Definition: ValueID.h:76
OpenZWave::Value
Base class for values associated with a node.
Definition: Value.h:47
OpenZWave::ValueID::GetIndex
uint8 GetIndex() const
Definition: ValueID.h:146
OpenZWave::ValueID::ValueType_List
Definition: ValueID.h:91
OpenZWave::ValueID::ValueType_Raw
Definition: ValueID.h:96
OpenZWave::ValueID::ValueType_String
Definition: ValueID.h:94
OpenZWave::ValueID::ValueGenre
ValueGenre
Definition: ValueID.h:71
OpenZWave::ValueID::ValueType_Schedule
Definition: ValueID.h:92
uint8
unsigned char uint8
Definition: Defs.h:74