OpenZWave Library 1.6.1914
Loading...
Searching...
No Matches
Msg.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// Msg.h
4//
5// Represents a Z-Wave message
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 _Msg_H
29#define _Msg_H
30
31#include <cstdio>
32#include <string>
33#include <string.h>
34#include "Defs.h"
35//#include "Driver.h"
36
37namespace OpenZWave
38{
39 class Driver;
40
41 namespace Internal
42 {
43 namespace CC
44 {
45 class CommandClass;
46 }
47
51 {
52 public:
54 {
55 m_MultiChannel = 0x01, // Indicate MultiChannel encapsulation
56 m_MultiInstance = 0x02, // Indicate MultiInstance encapsulation
57 };
58
59 Msg(string const& _logtext, uint8 _targetNodeId, uint8 const _msgType, uint8 const _function, bool const _bCallbackRequired, bool const _bReplyRequired = true, uint8 const _expectedReply = 0, uint8 const _expectedCommandClassId = 0);
61 {
62 }
63
64 void SetInstance(OpenZWave::Internal::CC::CommandClass * _cc, uint8 const _instance); // Used to enable wrapping with MultiInstance/MultiChannel during finalize.
65
66 void Append(uint8 const _data);
67 void AppendArray(const uint8* const _data, const uint8 _length);
68 void Finalize();
69 void UpdateCallbackId();
70
76 {
77 return m_targetNodeId;
78 }
79
86 {
87 return m_callbackId;
88 }
89
99 {
100 return m_expectedReply;
101 }
102
108 {
109 return m_expectedCommandClassId;
110 }
111
118 {
119 return m_instance;
120 }
121
127// uint8 GetExpectedIndex()const{ return m_expectedIndex; }
132 string GetLogText() const
133 {
134 return m_logText;
135 }
136
138 {
139 return m_encrypted == true ? m_length + 20 + 6 : m_length;
140 }
141 uint8* GetBuffer();
142 string GetAsString();
143
145 {
146 return m_sendAttempts;
147 }
149 {
150 m_sendAttempts = _count;
151 }
152
154 {
155 return m_maxSendAttempts;
156 }
158 {
159 if (_count < MAX_MAX_TRIES)
160 m_maxSendAttempts = _count;
161 }
162
164 {
165 return (m_bFinal && (m_length == 11) && (m_buffer[3] == 0x13) && (m_buffer[6] == 0x84) && (m_buffer[7] == 0x08));
166 }
168 {
169 return (m_bFinal && (m_length == 11) && (m_buffer[3] == 0x13) && (m_buffer[6] == 0x00) && (m_buffer[7] == 0x00));
170 }
171
172 bool operator ==(Msg const& _other) const
173 {
174 if (m_bFinal && _other.m_bFinal)
175 {
176 // Do not include the callback Id or checksum in the comparison.
177 uint8 length = m_length - (m_bCallbackRequired ? 2 : 1);
178 return (!memcmp(m_buffer, _other.m_buffer, length));
179 }
180
181 return false;
182 }
184 {
185 if (m_buffer[3] == 0x13)
186 {
187 return m_buffer[6];
188 }
189 return 0;
190 }
192 {
193 return m_encrypted;
194 }
196 {
197 m_encrypted = true;
198 }
200 {
201 return m_noncerecvd;
202 }
203 void setNonce(uint8 nonce[8])
204 {
205 memcpy(m_nonce, nonce, 8);
206 m_noncerecvd = true;
207 UpdateCallbackId();
208 }
210 {
211 memset((m_nonce), '\0', 8);
212 m_noncerecvd = false;
213 }
214 void SetHomeId(uint32 homeId)
215 {
216 m_homeId = homeId;
217 }
219 {
220 m_resendDuetoCANorNAK = true;
221 }
223 {
224 return m_resendDuetoCANorNAK;
225 }
226
230 Driver* GetDriver() const;
231 private:
232
233 void MultiEncap(); // Encapsulate the data inside a MultiInstance/Multicommand message
234 string m_logText;
235 bool m_bFinal;
236 bool m_bCallbackRequired;
237
238 uint8 m_callbackId;
239 uint8 m_expectedReply;
240 uint8 m_expectedCommandClassId;
241 uint8 m_length;
242 uint8 m_buffer[256];
243 uint8 e_buffer[256];
244
245 uint8 m_targetNodeId;
246 uint8 m_sendAttempts;
247 uint8 m_maxSendAttempts;
248
249 uint8 m_instance;
250 uint8 m_endPoint; // Endpoint to use if the message must be wrapped in a multiInstance or multiChannel command class
251 uint8 m_flags;
252
253 bool m_encrypted;
254 bool m_noncerecvd;
255 uint8 m_nonce[8];
256 uint32 m_homeId;
257 static uint8 s_nextCallbackId; // counter to get a unique callback id
258 /* we are resending this message due to CAN or NAK messages */
259 bool m_resendDuetoCANorNAK;
260 };
261 } // namespace Internal
262} // namespace OpenZWave
263
264#endif //_Msg_H
265
unsigned int uint32
Definition: Defs.h:91
#define MAX_MAX_TRIES
Definition: Defs.h:225
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
unsigned char uint8
Definition: Defs.h:85
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:85
Base class for all Z-Wave command classes.
Definition: CommandClass.h:61
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:51
bool isNonceRecieved()
Definition: Msg.h:199
void SetSendAttempts(uint8 _count)
Definition: Msg.h:148
string GetLogText() const
For messages that request a Report for a specified command class, identifies the expected Index for t...
Definition: Msg.h:132
bool IsWakeUpNoMoreInformationCommand()
Definition: Msg.h:163
uint8 GetExpectedInstance() const
For messages that request a Report for a specified command class, identifies the expected Instance fo...
Definition: Msg.h:117
void setResendDuetoCANorNAK()
Definition: Msg.h:218
uint8 GetCallbackId() const
Identifies the Callback ID (if any) for this message. Callback ID is a value (OpenZWave uses sequenti...
Definition: Msg.h:85
uint8 GetMaxSendAttempts() const
Definition: Msg.h:153
MessageFlags
Definition: Msg.h:54
~Msg()
Definition: Msg.h:60
bool isResendDuetoCANorNAK()
Definition: Msg.h:222
uint8 GetExpectedCommandClassId() const
Identifies the expected Command Class ID (if any) for this message.
Definition: Msg.h:107
void setEncrypted()
Definition: Msg.h:195
bool isEncrypted()
Definition: Msg.h:191
uint8 GetTargetNodeId() const
Identifies the Node ID of the "target" node (if any) for this function.
Definition: Msg.h:75
void SetHomeId(uint32 homeId)
Definition: Msg.h:214
void setNonce(uint8 nonce[8])
Definition: Msg.h:203
void SetMaxSendAttempts(uint8 _count)
Definition: Msg.h:157
uint32 GetLength() const
Definition: Msg.h:137
uint8 GetSendAttempts() const
Definition: Msg.h:144
uint8 GetExpectedReply() const
Identifies the expected reply type (if any) for this message. The expected reply is a function code....
Definition: Msg.h:98
uint8 GetSendingCommandClass()
Definition: Msg.h:183
void clearNonce()
Definition: Msg.h:209
bool IsNoOperation()
Definition: Msg.h:167
Definition: Bitfield.cpp:31