| OpenZWave Library 1.6.0

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
37 namespace OpenZWave
38 {
39 class CommandClass;
40 class Driver;
41
44 class OPENZWAVE_EXPORT Msg
45 {
46 public:
47 enum MessageFlags
48 {
49 m_MultiChannel = 0x01, // Indicate MultiChannel encapsulation
50 m_MultiInstance = 0x02, // Indicate MultiInstance encapsulation
51 };
52
53 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 );
54 ~Msg(){}
55
56 void SetInstance( CommandClass* _cc, uint8 const _instance ); // Used to enable wrapping with MultiInstance/MultiChannel during finalize.
57
58 void Append( uint8 const _data );
59 void AppendArray( const uint8* const _data, const uint8 _length );
60 void Finalize();
61 void UpdateCallbackId();
62
67 uint8 GetTargetNodeId()const{ return m_targetNodeId; }
68
74 uint8 GetCallbackId()const{ return m_callbackId; }
75
84 uint8 GetExpectedReply()const{ return m_expectedReply; }
85
90 uint8 GetExpectedCommandClassId()const{ return m_expectedCommandClassId; }
91
97 uint8 GetExpectedInstance()const{ return m_instance; }
98
104 // uint8 GetExpectedIndex()const{ return m_expectedIndex; }
109 string GetLogText()const{ return m_logText; }
110
111 uint32 GetLength()const{ return m_encrypted == true ? m_length + 20 + 6 : m_length; }
112 uint8* GetBuffer();
113 string GetAsString();
114
115 uint8 GetSendAttempts()const{ return m_sendAttempts; }
116 void SetSendAttempts( uint8 _count ){ m_sendAttempts = _count; }
117
118 uint8 GetMaxSendAttempts()const{ return m_maxSendAttempts; }
119 void SetMaxSendAttempts( uint8 _count ){ if( _count < MAX_MAX_TRIES ) m_maxSendAttempts = _count; }
120
121 bool IsWakeUpNoMoreInformationCommand()
122 {
123 return( m_bFinal && (m_length==11) && (m_buffer[3]==0x13) && (m_buffer[6]==0x84) && (m_buffer[7]==0x08) );
124 }
125 bool IsNoOperation()
126 {
127 return( m_bFinal && (m_length==11) && (m_buffer[3]==0x13) && (m_buffer[6]==0x00) && (m_buffer[7]==0x00) );
128 }
129
130 bool operator == ( Msg const& _other )const
131 {
132 if( m_bFinal && _other.m_bFinal )
133 {
134 // Do not include the callback Id or checksum in the comparison.
135 uint8 length = m_length - (m_bCallbackRequired ? 2: 1 );
136 return( !memcmp( m_buffer, _other.m_buffer, length ) );
137 }
138
139 return false;
140 }
141 uint8 GetSendingCommandClass() {
142 if (m_buffer[3] == 0x13) {
143 return m_buffer[6];
144 }
145 return 0;
146 }
147 bool isEncrypted() {
148 return m_encrypted;
149 }
150 void setEncrypted() {
151 m_encrypted = true;
152 }
153 bool isNonceRecieved() {
154 return m_noncerecvd;
155 }
156 void setNonce(uint8 nonce[8]) {
157 memcpy(m_nonce, nonce, 8);
158 m_noncerecvd = true;
159 UpdateCallbackId();
160 }
161 void clearNonce() {
162 memset((m_nonce), '\0', 8);
163 m_noncerecvd = false;
164 }
165 void SetHomeId(uint32 homeId) { m_homeId = homeId; };
166
170 Driver* GetDriver()const;
171 private:
172
173
174 void MultiEncap(); // Encapsulate the data inside a MultiInstance/Multicommand message
175
176 string m_logText;
177 bool m_bFinal;
178 bool m_bCallbackRequired;
179
180 uint8 m_callbackId;
181 uint8 m_expectedReply;
182 uint8 m_expectedCommandClassId;
183 uint8 m_length;
184 uint8 m_buffer[256];
185 uint8 e_buffer[256];
186
187 uint8 m_targetNodeId;
188 uint8 m_sendAttempts;
189 uint8 m_maxSendAttempts;
190
191 uint8 m_instance;
192 uint8 m_endPoint; // Endpoint to use if the message must be wrapped in a multiInstance or multiChannel command class
193 uint8 m_flags;
194
195 bool m_encrypted;
196 bool m_noncerecvd;
197 uint8 m_nonce[8];
198 uint32 m_homeId;
199 static uint8 s_nextCallbackId; // counter to get a unique callback id
200 };
201
202 } // namespace OpenZWave
203
204 #endif //_Msg_H
205
uint32
unsigned int uint32
Definition: Defs.h:95
OpenZWave::Msg::SetHomeId
void SetHomeId(uint32 homeId)
Definition: Msg.h:165
OpenZWave::Msg::GetTargetNodeId
uint8 GetTargetNodeId() const
Identifies the Node ID of the "target" node (if any) for this function.
Definition: Msg.h:67
OpenZWave::Msg::GetSendingCommandClass
uint8 GetSendingCommandClass()
Definition: Msg.h:141
OpenZWave::CommandClass
Base class for all Z-Wave command classes.
Definition: CommandClass.h:56
OpenZWave::Msg::setEncrypted
void setEncrypted()
Definition: Msg.h:150
uint8
unsigned char uint8
Definition: Defs.h:89
OpenZWave::Msg::isEncrypted
bool isEncrypted()
Definition: Msg.h:147
OpenZWave::Msg::GetLength
uint32 GetLength() const
Definition: Msg.h:111
OpenZWave::Msg::clearNonce
void clearNonce()
Definition: Msg.h:161
OpenZWave::Msg::IsWakeUpNoMoreInformationCommand
bool IsWakeUpNoMoreInformationCommand()
Definition: Msg.h:121
OpenZWave::Msg::setNonce
void setNonce(uint8 nonce[8])
Definition: Msg.h:156
OpenZWave::Msg::GetSendAttempts
uint8 GetSendAttempts() const
Definition: Msg.h:115
OpenZWave::Msg::~Msg
~Msg()
Definition: Msg.h:54
OpenZWave::Msg::GetMaxSendAttempts
uint8 GetMaxSendAttempts() const
Definition: Msg.h:118
OpenZWave::Msg::IsNoOperation
bool IsNoOperation()
Definition: Msg.h:125
MAX_MAX_TRIES
#define MAX_MAX_TRIES
Definition: Defs.h:230
OpenZWave::Msg::GetExpectedReply
uint8 GetExpectedReply() const
Identifies the expected reply type (if any) for this message. The expected reply is a function code....
Definition: Msg.h:84
OpenZWave::Msg::SetSendAttempts
void SetSendAttempts(uint8 _count)
Definition: Msg.h:116
OpenZWave::Msg::GetExpectedInstance
uint8 GetExpectedInstance() const
For messages that request a Report for a specified command class, identifies the expected Instance fo...
Definition: Msg.h:97
OpenZWave::Msg::GetExpectedCommandClassId
uint8 GetExpectedCommandClassId() const
Identifies the expected Command Class ID (if any) for this message.
Definition: Msg.h:90
OpenZWave::Msg
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:45
OpenZWave::Msg::GetLogText
string GetLogText() const
For messages that request a Report for a specified command class, identifies the expected Index for t...
Definition: Msg.h:109
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
OpenZWave::Msg::GetCallbackId
uint8 GetCallbackId() const
Identifies the Callback ID (if any) for this message. Callback ID is a value (OpenZWave uses sequenti...
Definition: Msg.h:74
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:65
OpenZWave::Msg::SetMaxSendAttempts
void SetMaxSendAttempts(uint8 _count)
Definition: Msg.h:119
Defs.h
OpenZWave::Msg::MessageFlags
MessageFlags
Definition: Msg.h:48
OpenZWave
Definition: Bitfield.h:35
OpenZWave::Msg::isNonceRecieved
bool isNonceRecieved()
Definition: Msg.h:153