OpenZWave Library: CommandClass.h Source File

| OpenZWave Library 1.6.0

CommandClass.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// CommandClass.h
4//
5// Base class for all Z-Wave Command Classes
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 _CommandClass_H
29#define _CommandClass_H
30
31#include <string>
32#include <vector>
33#include <map>
34#include "Defs.h"
35#include "Bitfield.h"
36#include "Driver.h"
37#include "CompatOptionManager.h"
38
39namespace OpenZWave
40{
41class Msg;
42class Node;
43class Value;
55 class OPENZWAVE_EXPORT CommandClass
56{
57
58public:
59 enum
60 {
61 RequestFlag_Static = 0x00000001,
62 RequestFlag_Session = 0x00000002,
63 RequestFlag_Dynamic = 0x00000004,
64 RequestFlag_AfterMark = 0x00000008
65 };
66
67 CommandClass( uint32 const _homeId, uint8 const _nodeId );
68 virtual ~CommandClass();
69
70 virtual void ReadXML( TiXmlElement const* _ccElement );
71 virtual void WriteXML( TiXmlElement* _ccElement );
72 virtual bool RequestState( uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue ){ return false; }
73 virtual bool RequestValue( uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue ) { return false; }
74 virtual void refreshValuesOnWakeup();
75
76
77 virtual uint8 const GetCommandClassId()const = 0;
78 virtual string const GetCommandClassName()const = 0;
79 string const GetCommandClassLabel();
80 void SetCommandClassLabel(string label);
81 virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 ) = 0;
82 virtual bool HandleIncomingMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 ) { return false; }
83 virtual bool SetValue( Value const& _value ){ return false; }
84 virtual void SetValueBasic( uint8 const _instance, uint8 const _level ){} // Class specific handling of BASIC value mapping
85 virtual void SetVersion( uint8 const _version ); // Made out-of-line to allow checks against downgrade
86
87 bool RequestStateForAllInstances( uint32 const _requestFlags, Driver::MsgQueue const _queue );
88 bool CheckForRefreshValues(Value const* _value );
89
90 // The highest version number of the command class implemented by OpenZWave. We only need
91 // to do version gets on command classes that override this with a number greater than one.
92 virtual uint8 GetMaxVersion(){ return 1; }
93
94 uint8 GetVersion()const{ return m_dom.GetFlagByte(STATE_FLAG_CCVERSION); }
95 Bitfield const* GetInstances()const{ return &m_instances; }
96 uint32 GetHomeId()const{ return m_homeId; }
97 uint8 GetNodeId()const{ return m_nodeId; }
98 Driver* GetDriver()const;
99 Node* GetNodeUnsafe()const;
100 Value* GetValue( uint8 const _instance, uint16 const _index );
101 bool RemoveValue( uint8 const _instance, uint16 const _index );
102 uint8 GetEndPoint( uint8 const _instance )
103 {
104 map<uint8,uint8>::iterator it = m_endPointMap.find( _instance );
105 return( it == m_endPointMap.end() ? 0 : it->second );
106 }
107 uint8 GetInstance( uint8 const _endPoint )
108 {
109 for( map<uint8,uint8>::iterator it = m_endPointMap.begin(); it != m_endPointMap.end(); ++it )
110 {
111 if( _endPoint == it->second )
112 {
113 return it->first;
114 }
115 }
116 return 0;
117 }
118
119 void SetInstances( uint8 const _instances );
120 void SetInstance( uint8 const _endPoint );
121 /* overridden in the MultiInstance CC to set the Global Label for each Instance */
122 virtual void SetInstanceLabel(uint8 const _instance, char *label);
123 string GetInstanceLabel(uint8 const _instance);
124 uint8 GetNumInstances() { return (uint8)m_endPointMap.size(); };
125 void SetAfterMark(){ m_dom.SetFlagBool(STATE_FLAG_AFTERMARK, true); }
126 void SetEndPoint( uint8 const _instance, uint8 const _endpoint){ m_endPointMap[_instance] = _endpoint; }
127 bool IsAfterMark()const{ return m_dom.GetFlagBool(STATE_FLAG_AFTERMARK); }
128 bool IsSecured()const{ return m_dom.GetFlagBool(STATE_FLAG_ENCRYPTED); }
129 void SetSecured(){ m_dom.SetFlagBool(STATE_FLAG_ENCRYPTED, true); }
130 bool IsSecureSupported()const { return m_SecureSupport; }
131 void ClearSecureSupport() { m_SecureSupport = false; }
132 void SetSecureSupport() { m_SecureSupport = true; }
133 void SetInNIF() { m_dom.SetFlagBool(STATE_FLAG_INNIF, true); }
134 bool IsInNIF() { return m_dom.GetFlagBool(STATE_FLAG_INNIF); }
135
136 // Helper methods
137 string ExtractValue( uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset = 1 )const;
138
146 void AppendValue( Msg* _msg, string const& _value, uint8 const _scale )const;
147 uint8 const GetAppendValueSize( string const& _value )const;
148 int32 ValueToInteger( string const& _value, uint8* o_precision, uint8* o_size )const;
149
150 void UpdateMappedClass( uint8 const _instance, uint8 const _classId, uint8 const _value ); // Update mapped class's value from BASIC class
151
152 typedef struct RefreshValue {
153 uint8 cc;
154 uint8 genre;
155 uint8 instance;
156 uint16 index;
157 std::vector<RefreshValue *> RefreshClasses;
158 } RefreshValue;
159
160protected:
161 virtual void CreateVars( uint8 const _instance ){}
162 void ReadValueRefreshXML ( TiXmlElement const* _ccElement );
163 CompatOptionManager m_com;
164 CompatOptionManager m_dom;
165
166
167public:
168 virtual void CreateVars( uint8 const _instance, uint8 const _index ){}
169
170private:
171 uint32 m_homeId;
172 uint8 m_nodeId;
173 Bitfield m_instances;
174 OPENZWAVE_EXPORT_WARNINGS_OFF
175 map<uint8,uint8> m_endPointMap;
176 map<uint8, string> m_instanceLabel;
177 OPENZWAVE_EXPORT_WARNINGS_ON
178 bool m_SecureSupport; // Does this commandclass support secure encryption (eg, the Security CC doesn't encrypt itself, so it doesn't support encryption)
179 std::vector<RefreshValue *> m_RefreshClassValues; // what Command Class Values should we refresh ?
180 string m_commandClassLabel;
181 //-----------------------------------------------------------------------------
182 // Record which items of static data have been read from the device
183 //-----------------------------------------------------------------------------
184public:
185 enum StaticRequest
186 {
187 StaticRequest_Instances = 0x01,
188 StaticRequest_Values = 0x02,
189 StaticRequest_Version = 0x04
190 };
191
192 bool HasStaticRequest( uint8_t _request )const{ return( (m_dom.GetFlagByte(STATE_FLAG_STATIC_REQUESTS) & _request) != 0 ); }
193 void SetStaticRequest( uint8_t _request );
194 void ClearStaticRequest( uint8_t _request );
195
196
197 //-----------------------------------------------------------------------------
198 // Statistics
199 //-----------------------------------------------------------------------------
200public:
201 uint32 GetSentCnt()const{ return m_sentCnt; }
202 uint32 GetReceivedCnt()const{ return m_receivedCnt; }
203 void SentCntIncr(){ m_sentCnt++; }
204 void ReceivedCntIncr(){ m_receivedCnt++; }
205
206private:
207 uint32 m_sentCnt; // Number of messages sent from this command class.
208 uint32 m_receivedCnt; // Number of messages received from this commandclass.
209
210};
212} // namespace OpenZWave
213
214#endif
Bitfield.h
CompatOptionManager.h
Defs.h
uint16
unsigned short uint16
Definition: Defs.h:92
uint32
unsigned int uint32
Definition: Defs.h:95
int32
signed int int32
Definition: Defs.h:94
OPENZWAVE_EXPORT_WARNINGS_ON
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
OPENZWAVE_EXPORT_WARNINGS_OFF
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
uint8
unsigned char uint8
Definition: Defs.h:89
Driver.h
OpenZWave::Bitfield
Definition: Bitfield.h:37
OpenZWave::CommandClass
Base class for all Z-Wave command classes.
Definition: CommandClass.h:56
OpenZWave::CommandClass::SetEndPoint
void SetEndPoint(uint8 const _instance, uint8 const _endpoint)
Definition: CommandClass.h:126
OpenZWave::CommandClass::ReceivedCntIncr
void ReceivedCntIncr()
Definition: CommandClass.h:204
OpenZWave::CommandClass::HandleIncomingMsg
virtual bool HandleIncomingMsg(uint8 const *_data, uint32 const _length, uint32 const _instance=1)
Definition: CommandClass.h:82
OpenZWave::CommandClass::GetSentCnt
uint32 GetSentCnt() const
Definition: CommandClass.h:201
OpenZWave::CommandClass::HasStaticRequest
bool HasStaticRequest(uint8_t _request) const
Definition: CommandClass.h:192
OpenZWave::CommandClass::CreateVars
virtual void CreateVars(uint8 const _instance, uint8 const _index)
Definition: CommandClass.h:168
OpenZWave::CommandClass::GetNodeId
uint8 GetNodeId() const
Definition: CommandClass.h:97
OpenZWave::CommandClass::SetSecureSupport
void SetSecureSupport()
Definition: CommandClass.h:132
OpenZWave::CommandClass::RequestState
virtual bool RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:72
OpenZWave::CommandClass::IsSecureSupported
bool IsSecureSupported() const
Definition: CommandClass.h:130
OpenZWave::CommandClass::GetCommandClassId
virtual uint8 const GetCommandClassId() const =0
OpenZWave::CommandClass::GetMaxVersion
virtual uint8 GetMaxVersion()
Definition: CommandClass.h:92
OpenZWave::CommandClass::GetVersion
uint8 GetVersion() const
Definition: CommandClass.h:94
OpenZWave::CommandClass::SentCntIncr
void SentCntIncr()
Definition: CommandClass.h:203
OpenZWave::CommandClass::IsAfterMark
bool IsAfterMark() const
Definition: CommandClass.h:127
OpenZWave::CommandClass::m_dom
CompatOptionManager m_dom
Definition: CommandClass.h:164
OpenZWave::CommandClass::GetHomeId
uint32 GetHomeId() const
Definition: CommandClass.h:96
OpenZWave::CommandClass::RequestValue
virtual bool RequestValue(uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:73
OpenZWave::CommandClass::GetInstances
Bitfield const * GetInstances() const
Definition: CommandClass.h:95
OpenZWave::CommandClass::GetReceivedCnt
uint32 GetReceivedCnt() const
Definition: CommandClass.h:202
OpenZWave::CommandClass::SetValue
virtual bool SetValue(Value const &_value)
Definition: CommandClass.h:83
OpenZWave::CommandClass::IsSecured
bool IsSecured() const
Definition: CommandClass.h:128
OpenZWave::CommandClass::StaticRequest
StaticRequest
Definition: CommandClass.h:186
OpenZWave::CommandClass::IsInNIF
bool IsInNIF()
Definition: CommandClass.h:134
OpenZWave::CommandClass::HandleMsg
virtual bool HandleMsg(uint8 const *_data, uint32 const _length, uint32 const _instance=1)=0
OpenZWave::CommandClass::SetSecured
void SetSecured()
Definition: CommandClass.h:129
OpenZWave::CommandClass::m_com
CompatOptionManager m_com
Definition: CommandClass.h:163
OpenZWave::CommandClass::SetInNIF
void SetInNIF()
Definition: CommandClass.h:133
OpenZWave::CommandClass::CreateVars
virtual void CreateVars(uint8 const _instance)
Definition: CommandClass.h:161
OpenZWave::CommandClass::GetNumInstances
uint8 GetNumInstances()
Definition: CommandClass.h:124
OpenZWave::CommandClass::SetValueBasic
virtual void SetValueBasic(uint8 const _instance, uint8 const _level)
Definition: CommandClass.h:84
OpenZWave::CommandClass::GetCommandClassName
virtual string const GetCommandClassName() const =0
OpenZWave::CommandClass::ClearSecureSupport
void ClearSecureSupport()
Definition: CommandClass.h:131
OpenZWave::CommandClass::SetAfterMark
void SetAfterMark()
Definition: CommandClass.h:125
OpenZWave::CommandClass::GetEndPoint
uint8 GetEndPoint(uint8 const _instance)
Definition: CommandClass.h:102
OpenZWave::CommandClass::GetInstance
uint8 GetInstance(uint8 const _endPoint)
Definition: CommandClass.h:107
OpenZWave::CompatOptionManager
Definition: CompatOptionManager.h:110
OpenZWave::CompatOptionManager::GetFlagByte
uint8_t GetFlagByte(CompatOptionFlags flag) const
Definition: CompatOptionManager.cpp:284
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:65
OpenZWave::Driver::MsgQueue
MsgQueue
Definition: Driver.h:592
OpenZWave::Msg
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:45
OpenZWave::Node
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:66
OpenZWave::Value
Base class for values associated with a node.
Definition: Value.h:49
OpenZWave
Definition: Bitfield.h:35
OpenZWave::STATE_FLAG_STATIC_REQUESTS
@ STATE_FLAG_STATIC_REQUESTS
Definition: CompatOptionManager.h:60
OpenZWave::STATE_FLAG_INNIF
@ STATE_FLAG_INNIF
Definition: CompatOptionManager.h:63
OpenZWave::STATE_FLAG_AFTERMARK
@ STATE_FLAG_AFTERMARK
Definition: CompatOptionManager.h:61
OpenZWave::STATE_FLAG_CCVERSION
@ STATE_FLAG_CCVERSION
Definition: CompatOptionManager.h:59
OpenZWave::STATE_FLAG_ENCRYPTED
@ STATE_FLAG_ENCRYPTED
Definition: CompatOptionManager.h:62
OpenZWave::CommandClass::RefreshValue
Definition: CommandClass.h:152
OpenZWave::CommandClass::RefreshValue::instance
uint8 instance
Definition: CommandClass.h:155
OpenZWave::CommandClass::RefreshValue::RefreshClasses
std::vector< RefreshValue * > RefreshClasses
Definition: CommandClass.h:157
OpenZWave::CommandClass::RefreshValue::genre
uint8 genre
Definition: CommandClass.h:154
OpenZWave::CommandClass::RefreshValue::index
uint16 index
Definition: CommandClass.h:156
OpenZWave::CommandClass::RefreshValue::cc
uint8 cc
Definition: CommandClass.h:153