OpenZWave Library  1.5.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 
38 namespace OpenZWave
39 {
40  class Msg;
41  class Node;
42  class Value;
55  {
56 
57  public:
58  enum
59  {
60  RequestFlag_Static = 0x00000001,
61  RequestFlag_Session = 0x00000002,
62  RequestFlag_Dynamic = 0x00000004,
63  RequestFlag_AfterMark = 0x00000008
64  };
65 
66  CommandClass( uint32 const _homeId, uint8 const _nodeId );
67  virtual ~CommandClass();
68 
69  virtual void ReadXML( TiXmlElement const* _ccElement );
70  virtual void WriteXML( TiXmlElement* _ccElement );
71  virtual bool RequestState( uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue ){ return false; }
72  virtual bool RequestValue( uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue ) { return false; }
73 
74  virtual uint8 const GetCommandClassId()const = 0;
75  virtual string const GetCommandClassName()const = 0;
76  virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 ) = 0;
77  virtual bool HandleIncomingMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 ) { return false; }
78  virtual bool SetValue( Value const& _value ){ return false; }
79  virtual void SetValueBasic( uint8 const _instance, uint8 const _level ){} // Class specific handling of BASIC value mapping
80  virtual void SetVersion( uint8 const _version ){ m_version = _version; }
81 
82  bool RequestStateForAllInstances( uint32 const _requestFlags, Driver::MsgQueue const _queue );
83  bool CheckForRefreshValues(Value const* _value );
84 
85  // The highest version number of the command class implemented by OpenZWave. We only need
86  // to do version gets on command classes that override this with a number greater than one.
87  virtual uint8 GetMaxVersion(){ return 1; }
88 
89  uint8 GetVersion()const{ return m_version; }
90  Bitfield const* GetInstances()const{ return &m_instances; }
91  uint32 GetHomeId()const{ return m_homeId; }
92  uint8 GetNodeId()const{ return m_nodeId; }
93  Driver* GetDriver()const;
94  Node* GetNodeUnsafe()const;
95  Value* GetValue( uint8 const _instance, uint16 const _index );
96  bool RemoveValue( uint8 const _instance, uint16 const _index );
97  uint8 GetEndPoint( uint8 const _instance )
98  {
99  map<uint8,uint8>::iterator it = m_endPointMap.find( _instance );
100  return( it == m_endPointMap.end() ? 0 : it->second );
101  }
102  uint8 GetInstance( uint8 const _endPoint )
103  {
104  for( map<uint8,uint8>::iterator it = m_endPointMap.begin(); it != m_endPointMap.end(); ++it )
105  {
106  if( _endPoint == it->second )
107  {
108  return it->first;
109  }
110  }
111  return 0;
112  }
113 
114  void SetInstances( uint8 const _instances );
115  void SetInstance( uint8 const _endPoint );
116  void SetAfterMark(){ m_afterMark = true; }
117  void SetEndPoint( uint8 const _instance, uint8 const _endpoint){ m_endPointMap[_instance] = _endpoint; }
118  bool IsAfterMark()const{ return m_afterMark; }
119  bool IsCreateVars()const{ return m_createVars; }
120  bool IsGetSupported()const{ return m_getSupported; }
121  bool IsSecured()const{ return m_isSecured; }
122  void SetSecured(){ m_isSecured = true; }
123  bool IsSecureSupported()const { return m_SecureSupport; }
124  void ClearSecureSupport() { m_SecureSupport = false; }
125  void SetSecureSupport() { m_SecureSupport = true; }
126  void SetInNIF() { m_inNIF = true; }
127  bool IsInNIF() { return m_inNIF; }
128 
129  // Helper methods
130  string ExtractValue( uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset = 1 )const;
131 
139  void AppendValue( Msg* _msg, string const& _value, uint8 const _scale )const;
140  uint8 const GetAppendValueSize( string const& _value )const;
141  int32 ValueToInteger( string const& _value, uint8* o_precision, uint8* o_size )const;
142 
143  void UpdateMappedClass( uint8 const _instance, uint8 const _classId, uint8 const _value ); // Update mapped class's value from BASIC class
144 
145  typedef struct RefreshValue {
150  std::vector<RefreshValue *> RefreshClasses;
151  } RefreshValue;
152 
153  protected:
154  virtual void CreateVars( uint8 const _instance ){}
155  void ReadValueRefreshXML ( TiXmlElement const* _ccElement );
156 
157  public:
158  virtual void CreateVars( uint8 const _instance, uint8 const _index ){}
159 
160  private:
161  uint32 m_homeId;
162  uint8 m_nodeId;
163  uint8 m_version;
164  Bitfield m_instances;
166  map<uint8,uint8> m_endPointMap;
168  bool m_afterMark; // Set to true if the command class is listed after COMMAND_CLASS_MARK, and should not create any values.
169  bool m_createVars; // Do we want to create variables
170  int8 m_overridePrecision; // Override precision when writing values if >=0
171  bool m_getSupported; // Get operation supported
172  bool m_isSecured; // is this command class secured with the Security Command Class
173  bool m_SecureSupport; // Does this commandclass support secure encryption (eg, the Security CC doesn't encrypt itself, so it doesn't support encryption)
174  std::vector<RefreshValue *> m_RefreshClassValues; // what Command Class Values should we refresh ?
175  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
176  //-----------------------------------------------------------------------------
177  // Record which items of static data have been read from the device
178  //-----------------------------------------------------------------------------
179  public:
181  {
182  StaticRequest_Instances = 0x01,
183  StaticRequest_Values = 0x02,
184  StaticRequest_Version = 0x04
185  };
186 
187  bool HasStaticRequest( uint8 _request )const{ return( (m_staticRequests & _request) != 0 ); }
188  void SetStaticRequest( uint8 _request ){ m_staticRequests |= _request; }
189  void ClearStaticRequest( uint8 _request );
190 
191  private:
192  uint8 m_staticRequests;
193 
194  //-----------------------------------------------------------------------------
195  // Statistics
196  //-----------------------------------------------------------------------------
197  public:
198  uint32 GetSentCnt()const{ return m_sentCnt; }
199  uint32 GetReceivedCnt()const{ return m_receivedCnt; }
200  void SentCntIncr(){ m_sentCnt++; }
201  void ReceivedCntIncr(){ m_receivedCnt++; }
202 
203  private:
204  uint32 m_sentCnt; // Number of messages sent from this command class.
205  uint32 m_receivedCnt; // Number of messages received from this commandclass.
206  };
208 } // namespace OpenZWave
209 
210 #endif
virtual void SetValueBasic(uint8 const _instance, uint8 const _level)
Definition: CommandClass.h:79
virtual bool HandleIncomingMsg(uint8 const *_data, uint32 const _length, uint32 const _instance=1)
Definition: CommandClass.h:77
uint32 GetReceivedCnt() const
Definition: CommandClass.h:199
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:44
Definition: Bitfield.h:34
bool IsGetSupported() const
Definition: CommandClass.h:120
MsgQueue
Definition: Driver.h:575
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
void SentCntIncr()
Definition: CommandClass.h:200
unsigned short uint16
Definition: Defs.h:93
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:54
bool IsAfterMark() const
Definition: CommandClass.h:118
uint8 cc
Definition: CommandClass.h:146
void ClearSecureSupport()
Definition: CommandClass.h:124
bool IsCreateVars() const
Definition: CommandClass.h:119
Bitfield const * GetInstances() const
Definition: CommandClass.h:90
std::vector< RefreshValue * > RefreshClasses
Definition: CommandClass.h:150
virtual void CreateVars(uint8 const _instance, uint8 const _index)
Definition: CommandClass.h:158
uint8 genre
Definition: CommandClass.h:147
uint8 GetEndPoint(uint8 const _instance)
Definition: CommandClass.h:97
Definition: CommandClass.h:145
StaticRequest
Definition: CommandClass.h:180
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:53
uint32 GetSentCnt() const
Definition: CommandClass.h:198
Definition: Bitfield.h:36
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:65
uint32 GetHomeId() const
Definition: CommandClass.h:91
bool IsSecured() const
Definition: CommandClass.h:121
virtual void CreateVars(uint8 const _instance)
Definition: CommandClass.h:154
Base class for all Z-Wave command classes.
Definition: CommandClass.h:54
void SetEndPoint(uint8 const _instance, uint8 const _endpoint)
Definition: CommandClass.h:117
uint8 GetVersion() const
Definition: CommandClass.h:89
uint8 GetNodeId() const
Definition: CommandClass.h:92
uint16 index
Definition: CommandClass.h:149
void SetSecured()
Definition: CommandClass.h:122
signed char int8
Definition: Defs.h:89
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:63
signed int int32
Definition: Defs.h:95
unsigned int uint32
Definition: Defs.h:96
virtual uint8 GetMaxVersion()
Definition: CommandClass.h:87
void SetSecureSupport()
Definition: CommandClass.h:125
bool IsSecureSupported() const
Definition: CommandClass.h:123
void SetInNIF()
Definition: CommandClass.h:126
void SetStaticRequest(uint8 _request)
Definition: CommandClass.h:188
virtual void SetVersion(uint8 const _version)
Definition: CommandClass.h:80
virtual bool RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:71
Base class for values associated with a node.
Definition: Value.h:48
uint8 GetInstance(uint8 const _endPoint)
Definition: CommandClass.h:102
bool IsInNIF()
Definition: CommandClass.h:127
uint8 instance
Definition: CommandClass.h:148
bool HasStaticRequest(uint8 _request) const
Definition: CommandClass.h:187
void SetAfterMark()
Definition: CommandClass.h:116
void ReceivedCntIncr()
Definition: CommandClass.h:201
virtual bool SetValue(Value const &_value)
Definition: CommandClass.h:78
virtual bool RequestValue(uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:72
unsigned char uint8
Definition: Defs.h:90