CommandClass.h
Go to the documentation of this file.
//-----------------------------------------------------------------------------
//
// CommandClass.h
//
// Base class for all Z-Wave Command Classes
//
// 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 _CommandClass_H
#define _CommandClass_H
#include <string>
#include <vector>
#include <map>
#include "Defs.h"
#include "Bitfield.h"
#include "Driver.h"
namespace OpenZWave
{
class Msg;
class Node;
class Value;
class OPENZWAVE_EXPORT CommandClass
{
public:
enum
{
RequestFlag_Static = 0x00000001,
RequestFlag_Session = 0x00000002,
RequestFlag_Dynamic = 0x00000004,
RequestFlag_AfterMark = 0x00000008
};
CommandClass( uint32 const _homeId, uint8 const _nodeId );
virtual ~CommandClass();
virtual void ReadXML( TiXmlElement const* _ccElement );
virtual void WriteXML( TiXmlElement* _ccElement );
virtual bool RequestState( uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue ){ return false; }
virtual bool RequestValue( uint32 const _requestFlags, uint8 const _index, uint8 const _instance, Driver::MsgQueue const _queue ) { return false; }
virtual uint8 const GetCommandClassId()const = 0;
virtual string const GetCommandClassName()const = 0;
virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 ) = 0;
virtual bool SetValue( Value const& _value ){ return false; }
virtual void SetValueBasic( uint8 const _instance, uint8 const _level ){} // Class specific handling of BASIC value mapping
virtual void SetVersion( uint8 const _version ){ m_version = _version; }
bool RequestStateForAllInstances( uint32 const _requestFlags, Driver::MsgQueue const _queue );
bool CheckForRefreshValues(Value const* _value );
// The highest version number of the command class implemented by OpenZWave. We only need
// to do version gets on command classes that override this with a number greater than one.
virtual uint8 GetMaxVersion(){ return 1; }
uint8 GetVersion()const{ return m_version; }
Bitfield const* GetInstances()const{ return &m_instances; }
uint32 GetHomeId()const{ return m_homeId; }
uint8 GetNodeId()const{ return m_nodeId; }
Driver* GetDriver()const;
Node* GetNodeUnsafe()const;
Value* GetValue( uint8 const _instance, uint8 const _index );
bool RemoveValue( uint8 const _instance, uint8 const _index );
uint8 GetEndPoint( uint8 const _instance )
{
map<uint8,uint8>::iterator it = m_endPointMap.find( _instance );
return( it == m_endPointMap.end() ? 0 : it->second );
}
uint8 GetInstance( uint8 const _endPoint )
{
for( map<uint8,uint8>::iterator it = m_endPointMap.begin(); it != m_endPointMap.end(); ++it )
{
if( _endPoint == it->second )
{
return it->first;
}
}
return 0;
}
void SetInstances( uint8 const _instances );
void SetInstance( uint8 const _endPoint );
void SetAfterMark(){ m_afterMark = true; }
void SetEndPoint( uint8 const _instance, uint8 const _endpoint){ m_endPointMap[_instance] = _endpoint; }
bool IsAfterMark()const{ return m_afterMark; }
bool IsCreateVars()const{ return m_createVars; }
bool IsGetSupported()const{ return m_getSupported; }
bool IsSecured()const{ return m_isSecured; }
void SetSecured(){ m_isSecured = true; }
bool IsSecureSupported()const { return m_SecureSupport; }
void ClearSecureSupport() { m_SecureSupport = false; }
void SetSecureSupport() { m_SecureSupport = true; }
void SetInNIF() { m_inNIF = true; }
bool IsInNIF() { return m_inNIF; }
// Helper methods
string ExtractValue( uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset = 1 )const;
void AppendValue( Msg* _msg, string const& _value, uint8 const _scale )const;
uint8 const GetAppendValueSize( string const& _value )const;
int32 ValueToInteger( string const& _value, uint8* o_precision, uint8* o_size )const;
void UpdateMappedClass( uint8 const _instance, uint8 const _classId, uint8 const _value ); // Update mapped class's value from BASIC class
typedef struct RefreshValue {
uint8 cc;
uint8 genre;
uint8 instance;
uint8 index;
std::vector<RefreshValue *> RefreshClasses;
} RefreshValue;
protected:
virtual void CreateVars( uint8 const _instance ){}
void ReadValueRefreshXML ( TiXmlElement const* _ccElement );
public:
virtual void CreateVars( uint8 const _instance, uint8 const _index ){}
private:
uint32 m_homeId;
uint8 m_nodeId;
uint8 m_version;
Bitfield m_instances;
OPENZWAVE_EXPORT_WARNINGS_OFF
map<uint8,uint8> m_endPointMap;
OPENZWAVE_EXPORT_WARNINGS_ON
bool m_afterMark; // Set to true if the command class is listed after COMMAND_CLASS_MARK, and should not create any values.
bool m_createVars; // Do we want to create variables
int8 m_overridePrecision; // Override precision when writing values if >=0
bool m_getSupported; // Get operation supported
bool m_isSecured; // is this command class secured with the Security Command Class
bool m_SecureSupport; // Does this commandclass support secure encryption (eg, the Security CC doesn't encrypt itself, so it doesn't support encryption)
std::vector<RefreshValue *> m_RefreshClassValues; // what Command Class Values should we refresh ?
bool m_inNIF; // Was this command class present in the NIF Frame we recieved (or was it created from our device_classes.xml file, or because it was in the Security SupportedReport message
//-----------------------------------------------------------------------------
// Record which items of static data have been read from the device
//-----------------------------------------------------------------------------
public:
enum StaticRequest
{
StaticRequest_Instances = 0x01,
StaticRequest_Values = 0x02,
StaticRequest_Version = 0x04
};
bool HasStaticRequest( uint8 _request )const{ return( (m_staticRequests & _request) != 0 ); }
void SetStaticRequest( uint8 _request ){ m_staticRequests |= _request; }
void ClearStaticRequest( uint8 _request );
private:
uint8 m_staticRequests;
//-----------------------------------------------------------------------------
// Statistics
//-----------------------------------------------------------------------------
public:
uint32 GetSentCnt()const{ return m_sentCnt; }
uint32 GetReceivedCnt()const{ return m_receivedCnt; }
void SentCntIncr(){ m_sentCnt++; }
void ReceivedCntIncr(){ m_receivedCnt++; }
private:
uint32 m_sentCnt; // Number of messages sent from this command class.
uint32 m_receivedCnt; // Number of messages received from this commandclass.
};
} // namespace OpenZWave
#endif
OpenZWave::CommandClass::SetValueBasic
virtual void SetValueBasic(uint8 const _instance, uint8 const _level)
Definition: CommandClass.h:70
OpenZWave::CommandClass::GetReceivedCnt
uint32 GetReceivedCnt() const
Definition: CommandClass.h:190
Bitfield.h
OpenZWave::Msg
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:44
OpenZWave
Definition: Bitfield.h:34
OpenZWave::CommandClass::IsGetSupported
bool IsGetSupported() const
Definition: CommandClass.h:111
OpenZWave::Driver::MsgQueue
MsgQueue
Definition: Driver.h:565
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
OpenZWave::CommandClass::SentCntIncr
void SentCntIncr()
Definition: CommandClass.h:191
OPENZWAVE_EXPORT_WARNINGS_ON
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:54
OpenZWave::CommandClass::IsAfterMark
bool IsAfterMark() const
Definition: CommandClass.h:109
OpenZWave::CommandClass::RefreshValue::cc
uint8 cc
Definition: CommandClass.h:137
OpenZWave::CommandClass::ClearSecureSupport
void ClearSecureSupport()
Definition: CommandClass.h:115
OpenZWave::CommandClass::IsCreateVars
bool IsCreateVars() const
Definition: CommandClass.h:110
OpenZWave::CommandClass::GetInstances
Bitfield const * GetInstances() const
Definition: CommandClass.h:81
OpenZWave::CommandClass::RefreshValue::RefreshClasses
std::vector< RefreshValue * > RefreshClasses
Definition: CommandClass.h:141
OpenZWave::CommandClass::CreateVars
virtual void CreateVars(uint8 const _instance, uint8 const _index)
Definition: CommandClass.h:149
OpenZWave::CommandClass::RefreshValue::index
uint8 index
Definition: CommandClass.h:140
OpenZWave::CommandClass::RefreshValue::genre
uint8 genre
Definition: CommandClass.h:138
OpenZWave::CommandClass::GetEndPoint
uint8 GetEndPoint(uint8 const _instance)
Definition: CommandClass.h:88
OpenZWave::CommandClass::RefreshValue
Definition: CommandClass.h:136
OpenZWave::CommandClass::StaticRequest
StaticRequest
Definition: CommandClass.h:171
OpenZWave::CommandClass::RequestValue
virtual bool RequestValue(uint32 const _requestFlags, uint8 const _index, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:64
OPENZWAVE_EXPORT_WARNINGS_OFF
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:53
OpenZWave::CommandClass::GetSentCnt
uint32 GetSentCnt() const
Definition: CommandClass.h:189
OpenZWave::Bitfield
Definition: Bitfield.h:36
OpenZWave::Node
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:64
OpenZWave::CommandClass::GetHomeId
uint32 GetHomeId() const
Definition: CommandClass.h:82
OpenZWave::CommandClass::IsSecured
bool IsSecured() const
Definition: CommandClass.h:112
Defs.h
OpenZWave::CommandClass::CreateVars
virtual void CreateVars(uint8 const _instance)
Definition: CommandClass.h:145
OpenZWave::CommandClass
Base class for all Z-Wave command classes.
Definition: CommandClass.h:46
Driver.h
OpenZWave::CommandClass::SetEndPoint
void SetEndPoint(uint8 const _instance, uint8 const _endpoint)
Definition: CommandClass.h:108
OpenZWave::CommandClass::GetVersion
uint8 GetVersion() const
Definition: CommandClass.h:80
OpenZWave::CommandClass::GetNodeId
uint8 GetNodeId() const
Definition: CommandClass.h:83
OpenZWave::CommandClass::SetSecured
void SetSecured()
Definition: CommandClass.h:113
int8
signed char int8
Definition: Defs.h:73
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:58
int32
signed int int32
Definition: Defs.h:79
uint32
unsigned int uint32
Definition: Defs.h:80
OpenZWave::CommandClass::GetMaxVersion
virtual uint8 GetMaxVersion()
Definition: CommandClass.h:78
OpenZWave::CommandClass::SetSecureSupport
void SetSecureSupport()
Definition: CommandClass.h:116
OpenZWave::CommandClass::IsSecureSupported
bool IsSecureSupported() const
Definition: CommandClass.h:114
OpenZWave::CommandClass::SetInNIF
void SetInNIF()
Definition: CommandClass.h:117
OpenZWave::CommandClass::SetStaticRequest
void SetStaticRequest(uint8 _request)
Definition: CommandClass.h:179
OpenZWave::CommandClass::SetVersion
virtual void SetVersion(uint8 const _version)
Definition: CommandClass.h:71
OpenZWave::CommandClass::RequestState
virtual bool RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:63
OpenZWave::Value
Base class for values associated with a node.
Definition: Value.h:47
OpenZWave::CommandClass::GetInstance
uint8 GetInstance(uint8 const _endPoint)
Definition: CommandClass.h:93
OpenZWave::CommandClass::IsInNIF
bool IsInNIF()
Definition: CommandClass.h:118
OpenZWave::CommandClass::RefreshValue::instance
uint8 instance
Definition: CommandClass.h:139
OpenZWave::CommandClass::HasStaticRequest
bool HasStaticRequest(uint8 _request) const
Definition: CommandClass.h:178
OpenZWave::CommandClass::SetAfterMark
void SetAfterMark()
Definition: CommandClass.h:107
OpenZWave::CommandClass::ReceivedCntIncr
void ReceivedCntIncr()
Definition: CommandClass.h:192
OpenZWave::CommandClass::SetValue
virtual bool SetValue(Value const &_value)
Definition: CommandClass.h:69
uint8
unsigned char uint8
Definition: Defs.h:74