Msg.h
Go to the documentation of this file.
//-----------------------------------------------------------------------------
//
// Msg.h
//
// Represents a Z-Wave message
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#ifndef _Msg_H
#define _Msg_H
#include <cstdio>
#include <string>
#include <string.h>
#include "Defs.h"
//#include "Driver.h"
namespace OpenZWave
{
class CommandClass;
class Driver;
class OPENZWAVE_EXPORT Msg
{
public:
enum MessageFlags
{
m_MultiChannel = 0x01, // Indicate MultiChannel encapsulation
m_MultiInstance = 0x02, // Indicate MultiInstance encapsulation
};
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 );
~Msg(){}
void SetInstance( CommandClass* _cc, uint8 const _instance ); // Used to enable wrapping with MultiInstance/MultiChannel during finalize.
void Append( uint8 const _data );
void Finalize();
void UpdateCallbackId();
uint8 GetTargetNodeId()const{ return m_targetNodeId; }
uint8 GetCallbackId()const{ return m_callbackId; }
uint8 GetExpectedReply()const{ return m_expectedReply; }
uint8 GetExpectedCommandClassId()const{ return m_expectedCommandClassId; }
uint8 GetExpectedInstance()const{ return m_instance; }
// uint8 GetExpectedIndex()const{ return m_expectedIndex; }
string GetLogText()const{ return m_logText; }
uint32 GetLength()const{ return m_encrypted == true ? m_length + 20 + 6 : m_length; }
uint8* GetBuffer();
string GetAsString();
uint8 GetSendAttempts()const{ return m_sendAttempts; }
void SetSendAttempts( uint8 _count ){ m_sendAttempts = _count; }
uint8 GetMaxSendAttempts()const{ return m_maxSendAttempts; }
void SetMaxSendAttempts( uint8 _count ){ if( _count < MAX_MAX_TRIES ) m_maxSendAttempts = _count; }
bool IsWakeUpNoMoreInformationCommand()
{
return( m_bFinal && (m_length==11) && (m_buffer[3]==0x13) && (m_buffer[6]==0x84) && (m_buffer[7]==0x08) );
}
bool IsNoOperation()
{
return( m_bFinal && (m_length==11) && (m_buffer[3]==0x13) && (m_buffer[6]==0x00) && (m_buffer[7]==0x00) );
}
bool operator == ( Msg const& _other )const
{
if( m_bFinal && _other.m_bFinal )
{
// Do not include the callback Id or checksum in the comparison.
uint8 length = m_length - (m_bCallbackRequired ? 2: 1 );
return( !memcmp( m_buffer, _other.m_buffer, length ) );
}
return false;
}
uint8 GetSendingCommandClass() {
if (m_buffer[3] == 0x13) {
return m_buffer[6];
}
return 0;
}
bool isEncrypted() {
return m_encrypted;
}
void setEncrypted() {
m_encrypted = true;
}
bool isNonceRecieved() {
return m_noncerecvd;
}
void setNonce(uint8 nonce[8]) {
memcpy(m_nonce, nonce, 8);
m_noncerecvd = true;
UpdateCallbackId();
}
void clearNonce() {
memset((m_nonce), '\0', 8);
m_noncerecvd = false;
}
void SetHomeId(uint32 homeId) { m_homeId = homeId; };
Driver* GetDriver()const;
private:
void MultiEncap(); // Encapsulate the data inside a MultiInstance/Multicommand message
string m_logText;
bool m_bFinal;
bool m_bCallbackRequired;
uint8 m_callbackId;
uint8 m_expectedReply;
uint8 m_expectedCommandClassId;
uint8 m_length;
uint8 m_buffer[256];
uint8 e_buffer[256];
uint8 m_targetNodeId;
uint8 m_sendAttempts;
uint8 m_maxSendAttempts;
uint8 m_instance;
uint8 m_endPoint; // Endpoint to use if the message must be wrapped in a multiInstance or multiChannel command class
uint8 m_flags;
bool m_encrypted;
bool m_noncerecvd;
uint8 m_nonce[8];
uint32 m_homeId;
static uint8 s_nextCallbackId; // counter to get a unique callback id
};
} // namespace OpenZWave
#endif //_Msg_H
OpenZWave::Msg
Message object to be passed to and from devices on the Z-Wave network.
Definition: Msg.h:44
OpenZWave
Definition: Bitfield.h:34
OpenZWave::Msg::GetTargetNodeId
uint8 GetTargetNodeId() const
Identifies the Node ID of the "target" node (if any) for this function.
Definition: Msg.h:66
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
MAX_MAX_TRIES
#define MAX_MAX_TRIES
Definition: Defs.h:213
OpenZWave::Msg::clearNonce
void clearNonce()
Definition: Msg.h:162
OpenZWave::Msg::IsWakeUpNoMoreInformationCommand
bool IsWakeUpNoMoreInformationCommand()
Definition: Msg.h:120
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:96
OpenZWave::Msg::setEncrypted
void setEncrypted()
Definition: Msg.h:151
Defs.h
OpenZWave::CommandClass
Base class for all Z-Wave command classes.
Definition: CommandClass.h:46
OpenZWave::Msg::SetHomeId
void SetHomeId(uint32 homeId)
Definition: Msg.h:166
OpenZWave::Msg::GetMaxSendAttempts
uint8 GetMaxSendAttempts() const
Definition: Msg.h:117
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:83
OpenZWave::Msg::isEncrypted
bool isEncrypted()
Definition: Msg.h:148
OpenZWave::Driver
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:58
OpenZWave::Msg::~Msg
~Msg()
Definition: Msg.h:54
uint32
unsigned int uint32
Definition: Defs.h:80
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:73
OpenZWave::Msg::setNonce
void setNonce(uint8 nonce[8])
Definition: Msg.h:157
OpenZWave::Msg::IsNoOperation
bool IsNoOperation()
Definition: Msg.h:124
OpenZWave::Msg::GetExpectedCommandClassId
uint8 GetExpectedCommandClassId() const
Identifies the expected Command Class ID (if any) for this message.
Definition: Msg.h:89
OpenZWave::Msg::GetSendingCommandClass
uint8 GetSendingCommandClass()
Definition: Msg.h:140
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:108
OpenZWave::Msg::SetSendAttempts
void SetSendAttempts(uint8 _count)
Definition: Msg.h:115
OpenZWave::Msg::GetLength
uint32 GetLength() const
Definition: Msg.h:110
OpenZWave::Msg::isNonceRecieved
bool isNonceRecieved()
Definition: Msg.h:154
OpenZWave::Msg::SetMaxSendAttempts
void SetMaxSendAttempts(uint8 _count)
Definition: Msg.h:118
OpenZWave::Msg::MessageFlags
MessageFlags
Definition: Msg.h:47
OpenZWave::Msg::GetSendAttempts
uint8 GetSendAttempts() const
Definition: Msg.h:114
uint8
unsigned char uint8
Definition: Defs.h:74