コード例 #1
0
ファイル: Basic.cpp プロジェクト: rainisto/lights-control
//-----------------------------------------------------------------------------
// <Basic::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool Basic::HandleMsg
(
	uint8 const* _data,
	uint32 const _length,
	uint32 const _instance	// = 1
)
{
	if( BasicCmd_Report == (BasicCmd)_data[0] )
	{
		// Level
		Log::Write( LogLevel_Info, GetNodeId(), "Received Basic report from node %d: level=%d", GetNodeId(), _data[1] );
		if( ValueByte* value = static_cast<ValueByte*>( GetValue( _instance, 0 ) ) )
		{
			value->OnValueRefreshed( _data[1] );
			value->Release();
		}
		return true;
	}

	if( BasicCmd_Set == (BasicCmd)_data[0] )
	{
		// Commmand received from the node.  Handle as a notification event
		Log::Write( LogLevel_Info, GetNodeId(), "Received Basic set from node %d: level=%d.  Sending event notification.", GetNodeId(), _data[1] );

		Notification* notification = new Notification( Notification::Type_NodeEvent );
		notification->SetHomeNodeIdAndInstance( GetHomeId(), GetNodeId(), _instance );
		notification->SetEvent( _data[1] );
		GetDriver()->QueueNotification( notification );
		return true;
	}

	return false;
}
コード例 #2
0
ファイル: Basic.cpp プロジェクト: wycc/openzwave-hsc48
//-----------------------------------------------------------------------------
// <Basic::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool Basic::HandleMsg
(
	uint8 const* _data,
	uint32 const _length,
	uint32 const _instance	// = 1
)
{
	if( BasicCmd_Report == (BasicCmd)_data[0] )
	{
		// Level
		Log::Write( LogLevel_Info, GetNodeId(), "Received Basic report from node %d: level=%d instance=%d", GetNodeId(), _data[1],_instance );
		if( !m_ignoreMapping && m_mapping != 0 )
		{
			UpdateMappedClass( _instance, m_mapping, _data[1] );
		}
		else if( ValueByte* value = static_cast<ValueByte*>( GetValue( _instance, 0 ) ) )
		{
			value->OnValueRefreshed( _data[1] );
			value->Release();
		}
		else if( ValueByte* value = static_cast<ValueByte*>( GetValue( 1, 0 ) ) )
		{
			value->OnValueRefreshed( _data[1] );
			value->Release();
		}
		return true;
	}

	if( BasicCmd_Set == (BasicCmd)_data[0] )
	{
		if( m_setAsReport )
		{
			Log::Write( LogLevel_Info, GetNodeId(), "Received Basic set from node %d: level=%d. Treating it as a Basic report. instance=%d", GetNodeId(), _data[1], _instance );
			if( !m_ignoreMapping && m_mapping != 0 )
			{
				UpdateMappedClass( _instance, m_mapping, _data[1] );
			}
			else if( ValueByte* value = static_cast<ValueByte*>( GetValue( _instance, 0 ) ) )
			{
				value->OnValueRefreshed( _data[1] );
				value->Release();
			}
			else if (ValueByte* value = static_cast<ValueByte*>( GetValue( 1, 0 ) ))
			{
				if (_data[1] <16)
					value->OnValueRefreshed( _data[1]+100 );
				value->Release();
			}
		}
		else
		{
			// Commmand received from the node.  Handle as a notification event
			Log::Write( LogLevel_Info, GetNodeId(), "Received Basic set from node %d: level=%d.  Sending event notification.", GetNodeId(), _data[1] );

			Notification* notification = new Notification( Notification::Type_NodeEvent );
			notification->SetHomeNodeIdAndInstance( GetHomeId(), GetNodeId(), _instance );
			notification->SetEvent( _data[1] );
			GetDriver()->QueueNotification( notification );
		}
		return true;
	}

	return false;
}