OpenZWave Library 1.2
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
36namespace OpenZWave
37{
38 class CommandClass;
39
43 {
44 public:
46 {
47 m_MultiChannel = 0x01, // Indicate MultiChannel encapsulation
48 m_MultiInstance = 0x02, // Indicate MultiInstance encapsulation
49 };
50
51 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 );
52 ~Msg(){}
53
54 void SetInstance( CommandClass* _cc, uint8 const _instance ); // Used to enable wrapping with MultiInstance/MultiChannel during finalize.
55
56 void Append( uint8 const _data );
57 void Finalize();
58 void UpdateCallbackId();
59
64 uint8 GetTargetNodeId()const{ return m_targetNodeId; }
65
71 uint8 GetCallbackId()const{ return m_callbackId; }
72
81 uint8 GetExpectedReply()const{ return m_expectedReply; }
82
87 uint8 GetExpectedCommandClassId()const{ return m_expectedCommandClassId; }
88
94 uint8 GetExpectedInstance()const{ return m_instance; }
95
101// uint8 GetExpectedIndex()const{ return m_expectedIndex; }
106 string GetLogText()const{ return m_logText; }
107
108 uint32 GetLength()const{ return m_length; }
109 uint8* GetBuffer(){ return m_buffer; }
110 string GetAsString();
111
112 uint8 GetSendAttempts()const{ return m_sendAttempts; }
113 void SetSendAttempts( uint8 _count ){ m_sendAttempts = _count; }
114
115 uint8 GetMaxSendAttempts()const{ return m_maxSendAttempts; }
116 void SetMaxSendAttempts( uint8 _count ){ if( _count < MAX_MAX_TRIES ) m_maxSendAttempts = _count; }
117
119 {
120 return( m_bFinal && (m_length==11) && (m_buffer[3]==0x13) && (m_buffer[6]==0x84) && (m_buffer[7]==0x08) );
121 }
123 {
124 return( m_bFinal && (m_length==11) && (m_buffer[3]==0x13) && (m_buffer[6]==0x00) && (m_buffer[7]==0x00) );
125 }
126
127 bool operator == ( Msg const& _other )const
128 {
129 if( m_bFinal && _other.m_bFinal )
130 {
131 // Do not include the callback Id or checksum in the comparison.
132 uint8 length = m_length - (m_bCallbackRequired ? 2: 1 );
133 return( !memcmp( m_buffer, _other.m_buffer, length ) );
134 }
135
136 return false;
137 }
139 if (m_buffer[3] == 0x13) {
140 return m_buffer[6];
141 }
142 return 0;
143
144 }
145
146 private:
147 void MultiEncap(); // Encapsulate the data inside a MultiInstance/Multicommand message
148
149 string m_logText;
150 bool m_bFinal;
151 bool m_bCallbackRequired;
152
153 uint8 m_callbackId;
154 uint8 m_expectedReply;
155 uint8 m_expectedCommandClassId;
156 uint8 m_length;
157 uint8 m_buffer[256];
158
159 uint8 m_targetNodeId;
160 uint8 m_sendAttempts;
161 uint8 m_maxSendAttempts;
162
163 uint8 m_instance;
164 uint8 m_endPoint; // Endpoint to use if the message must be wrapped in a multiInstance or multiChannel command class
165 uint8 m_flags;
166
167 static uint8 s_nextCallbackId; // counter to get a unique callback id
168 };
169
170} // namespace OpenZWave
171
172#endif //_Msg_H
173
unsigned int uint32
Definition: Defs.h:69
#define MAX_MAX_TRIES
Definition: Defs.h:178
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
unsigned char uint8
Definition: Defs.h:63
Base class for all Z-Wave command classes.
Definition: CommandClass.h:47
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:43
uint8 GetCallbackId() const
Identifies the Callback ID (if any) for this message. Callback ID is a value (OpenZWave uses sequenti...
Definition: Msg.h:71
uint8 GetExpectedReply() const
Identifies the expected reply type (if any) for this message. The expected reply is a function code....
Definition: Msg.h:81
~Msg()
Definition: Msg.h:52
bool IsWakeUpNoMoreInformationCommand()
Definition: Msg.h:118
void SetMaxSendAttempts(uint8 _count)
Definition: Msg.h:116
string GetLogText() const
For messages that request a Report for a specified command class, identifies the expected Index for t...
Definition: Msg.h:106
uint8 GetMaxSendAttempts() const
Definition: Msg.h:115
uint8 GetExpectedCommandClassId() const
Identifies the expected Command Class ID (if any) for this message.
Definition: Msg.h:87
uint8 GetExpectedInstance() const
For messages that request a Report for a specified command class, identifies the expected Instance fo...
Definition: Msg.h:94
uint8 GetSendingCommandClass()
Definition: Msg.h:138
uint32 GetLength() const
Definition: Msg.h:108
uint8 GetTargetNodeId() const
Identifies the Node ID of the "target" node (if any) for this function.
Definition: Msg.h:64
MessageFlags
Definition: Msg.h:46
bool IsNoOperation()
Definition: Msg.h:122
uint8 * GetBuffer()
Definition: Msg.h:109
uint8 GetSendAttempts() const
Definition: Msg.h:112
void SetSendAttempts(uint8 _count)
Definition: Msg.h:113
Definition: Bitfield.h:35