OpenZWave Library  1.6.885
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 
39 namespace OpenZWave
40 {
41 
42  class Msg;
43  class Node;
44  class Value;
45 
46  namespace Internal
47  {
48  namespace CC
49  {
61  {
63  public:
64  enum
65  {
66  RequestFlag_Static = 0x00000001,
67  RequestFlag_Session = 0x00000002,
68  RequestFlag_Dynamic = 0x00000004,
69  RequestFlag_AfterMark = 0x00000008
70  };
71 
72  CommandClass(uint32 const _homeId, uint8 const _nodeId);
73  virtual ~CommandClass();
74 
75  virtual void ReadXML(TiXmlElement const* _ccElement);
76  virtual void WriteXML(TiXmlElement* _ccElement);
77  virtual bool RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue)
78  {
79  return false;
80  }
81  virtual bool RequestValue(uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue)
82  {
83  return false;
84  }
85  virtual void refreshValuesOnWakeup();
86 
87  virtual uint8 const GetCommandClassId() const = 0;
88  virtual string const GetCommandClassName() const = 0;
89  string const GetCommandClassLabel();
90  void SetCommandClassLabel(string label);
91  virtual bool HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance = 1) = 0;
92  virtual bool HandleIncomingMsg(uint8 const* _data, uint32 const _length, uint32 const _instance = 1);
93  virtual bool SetValue(Internal::VC::Value const& _value)
94  {
95  return false;
96  }
97  virtual void SetValueBasic(uint8 const _instance, uint8 const _level)
98  {
99  } // Class specific handling of BASIC value mapping
100  virtual void SetVersion(uint8 const _version); // Made out-of-line to allow checks against downgrade
101 
102  bool RequestStateForAllInstances(uint32 const _requestFlags, Driver::MsgQueue const _queue);
103  bool CheckForRefreshValues(Internal::VC::Value const* _value);
104 
105  // The highest version number of the command class implemented by OpenZWave. We only need
106  // to do version gets on command classes that override this with a number greater than one.
108  {
109  return 1;
110  }
111 
113  {
114  return m_dom.GetFlagByte(STATE_FLAG_CCVERSION);
115  }
116  Bitfield const* GetInstances() const
117  {
118  return &m_instances;
119  }
121  {
122  return m_homeId;
123  }
124  uint8 GetNodeId() const
125  {
126  return m_nodeId;
127  }
128  Driver* GetDriver() const;
129  Node* GetNodeUnsafe() const;
130  Internal::VC::Value* GetValue(uint8 const _instance, uint16 const _index);
131  bool RemoveValue(uint8 const _instance, uint16 const _index);
132  uint8 GetEndPoint(uint8 const _instance)
133  {
134  map<uint8, uint8>::iterator it = m_endPointMap.find(_instance);
135  return (it == m_endPointMap.end() ? 0 : it->second);
136  }
137  uint8 GetInstance(uint8 const _endPoint)
138  {
139  for (map<uint8, uint8>::iterator it = m_endPointMap.begin(); it != m_endPointMap.end(); ++it)
140  {
141  if (_endPoint == it->second)
142  {
143  return it->first;
144  }
145  }
146  return 0;
147  }
148 
149  void SetInstances(uint8 const _instances);
150  void SetInstance(uint8 const _endPoint);
151  /* overridden in the MultiInstance CC to set the Global Label for each Instance */
152  virtual void SetInstanceLabel(uint8 const _instance, char *label);
153  string GetInstanceLabel(uint8 const _instance);
155  {
156  return (uint8) m_endPointMap.size();
157  }
158  ;
160  {
161  m_dom.SetFlagBool(STATE_FLAG_AFTERMARK, true);
162  }
163  void SetEndPoint(uint8 const _instance, uint8 const _endpoint)
164  {
165  m_endPointMap[_instance] = _endpoint;
166  }
167  bool IsAfterMark() const
168  {
169  return m_dom.GetFlagBool(STATE_FLAG_AFTERMARK);
170  }
171  bool IsSecured() const
172  {
173  return m_dom.GetFlagBool(STATE_FLAG_ENCRYPTED);
174  }
175  void SetSecured()
176  {
177  m_dom.SetFlagBool(STATE_FLAG_ENCRYPTED, true);
178  }
179  bool IsSecureSupported() const
180  {
181  return m_SecureSupport;
182  }
184  {
185  m_SecureSupport = false;
186  }
188  {
189  m_SecureSupport = true;
190  }
191  void SetInNIF()
192  {
193  m_dom.SetFlagBool(STATE_FLAG_INNIF, true);
194  }
195  bool IsInNIF()
196  {
197  return m_dom.GetFlagBool(STATE_FLAG_INNIF);
198  }
199 
200  // Helper methods
201  string ExtractValue(uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset = 1) const;
202 
210  void AppendValue(Msg* _msg, string const& _value, uint8 const _scale) const;
211  uint8 const GetAppendValueSize(string const& _value) const;
212  int32 ValueToInteger(string const& _value, uint8* o_precision, uint8* o_size) const;
213 
214  void UpdateMappedClass(uint8 const _instance, uint8 const _classId, uint8 const _value); // Update mapped class's value from BASIC class
215 
216  typedef struct RefreshValue
217  {
222  std::vector<RefreshValue *> RefreshClasses;
223  } RefreshValue;
224 
225  protected:
226  virtual void CreateVars(uint8 const _instance)
227  {
228  }
229  void ReadValueRefreshXML(TiXmlElement const* _ccElement);
232 
233  public:
234  virtual void CreateVars(uint8 const _instance, uint8 const _index)
235  {
236  }
237 
238  private:
239  uint32 m_homeId;
240  uint8 m_nodeId;
242  map<uint8, uint8> m_endPointMap;
243  map<uint8, string> m_instanceLabel;OPENZWAVE_EXPORT_WARNINGS_ON
244  bool m_SecureSupport; // Does this commandclass support secure encryption (eg, the Security CC doesn't encrypt itself, so it doesn't support encryption)
245  std::vector<RefreshValue *> m_RefreshClassValues; // what Command Class Values should we refresh ?
246  string m_commandClassLabel;
247  //-----------------------------------------------------------------------------
248  // Record which items of static data have been read from the device
249  //-----------------------------------------------------------------------------
250  public:
252  {
253  StaticRequest_Instances = 0x01,
254  StaticRequest_Values = 0x02,
255  StaticRequest_Version = 0x04
256  };
257 
258  bool HasStaticRequest(uint8_t _request) const
259  {
260  return ((m_dom.GetFlagByte(STATE_FLAG_STATIC_REQUESTS) & _request) != 0);
261  }
262  void SetStaticRequest(uint8_t _request);
263  void ClearStaticRequest(uint8_t _request);
264 
265  //-----------------------------------------------------------------------------
266  // Statistics
267  //-----------------------------------------------------------------------------
268  public:
270  {
271  return m_sentCnt;
272  }
274  {
275  return m_receivedCnt;
276  }
277  void SentCntIncr()
278  {
279  m_sentCnt++;
280  }
282  {
283  m_receivedCnt++;
284  }
285 
286  private:
287  uint32 m_sentCnt; // Number of messages sent from this command class.
288  uint32 m_receivedCnt; // Number of messages received from this commandclass.
289 
290  };
292  }// namespace CC
293  } // namespace Internal
294 } // namespace OpenZWave
295 
296 #endif
Definition: CompatOptionManager.h:72
CompatOptionManager m_dom
Definition: CommandClass.h:231
uint8 GetVersion() const
Definition: CommandClass.h:112
Definition: Bitfield.cpp:30
MsgQueue
Definition: Driver.h:658
uint32 GetSentCnt() const
Definition: CommandClass.h:269
Definition: CompatOptionManager.h:70
uint8 instance
Definition: CommandClass.h:220
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
virtual bool RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:77
unsigned short uint16
Definition: Defs.h:89
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
std::vector< RefreshValue * > RefreshClasses
Definition: CommandClass.h:222
bool HasStaticRequest(uint8_t _request) const
Definition: CommandClass.h:258
uint8 GetEndPoint(uint8 const _instance)
Definition: CommandClass.h:132
void ReceivedCntIncr()
Definition: CommandClass.h:281
virtual void SetValueBasic(uint8 const _instance, uint8 const _level)
Definition: CommandClass.h:97
virtual void CreateVars(uint8 const _instance, uint8 const _index)
Definition: CommandClass.h:234
uint8 GetNumInstances()
Definition: CommandClass.h:154
virtual void CreateVars(uint8 const _instance)
Definition: CommandClass.h:226
bool IsSecured() const
Definition: CommandClass.h:171
void SetEndPoint(uint8 const _instance, uint8 const _endpoint)
Definition: CommandClass.h:163
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
uint8 GetInstance(uint8 const _endPoint)
Definition: CommandClass.h:137
Container that holds all of the values associated with a given node.
Definition: ValueStore.h:49
void SetInNIF()
Definition: CommandClass.h:191
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition: Node.h:81
Base class for all Z-Wave command classes.
Definition: CommandClass.h:60
uint8 genre
Definition: CommandClass.h:219
void SentCntIncr()
Definition: CommandClass.h:277
uint8 GetNodeId() const
Definition: CommandClass.h:124
Definition: CompatOptionManager.h:69
uint32 GetReceivedCnt() const
Definition: CommandClass.h:273
bool IsSecureSupported() const
Definition: CommandClass.h:179
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:84
bool IsAfterMark() const
Definition: CommandClass.h:167
Definition: CompatOptionManager.h:73
signed int int32
Definition: Defs.h:91
unsigned int uint32
Definition: Defs.h:92
virtual bool RequestValue(uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue)
Definition: CommandClass.h:81
uint8 cc
Definition: CommandClass.h:218
virtual bool SetValue(Internal::VC::Value const &_value)
Definition: CommandClass.h:93
virtual uint8 GetMaxVersion()
Definition: CommandClass.h:107
Definition: CompatOptionManager.h:71
StaticRequest
Definition: CommandClass.h:251
Definition: CompatOptionManager.h:138
CompatOptionManager m_com
Definition: CommandClass.h:230
uint16 index
Definition: CommandClass.h:221
Definition: Bitfield.h:39
void SetSecured()
Definition: CommandClass.h:175
uint8_t GetFlagByte(CompatOptionFlags flag, uint32_t index=-1) const
Definition: CompatOptionManager.cpp:464
uint32 GetHomeId() const
Definition: CommandClass.h:120
Bitfield const * GetInstances() const
Definition: CommandClass.h:116
void SetSecureSupport()
Definition: CommandClass.h:187
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:50
Base class for values associated with a node.
Definition: Value.h:53
void SetAfterMark()
Definition: CommandClass.h:159
bool IsInNIF()
Definition: CommandClass.h:195
void ClearSecureSupport()
Definition: CommandClass.h:183
unsigned char uint8
Definition: Defs.h:86