コード例 #1
0
ファイル: Alarm.cpp プロジェクト: AeroGirl/ninja-zwave
//-----------------------------------------------------------------------------
// <Alarm::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool Alarm::HandleMsg
(
	uint8 const* _data,
	uint32 const _length,
	uint32 const _instance	// = 1
)
{
	if (AlarmCmd_Report == (AlarmCmd)_data[0])
	{
		// We have received a report from the Z-Wave device
		Log::Write( LogLevel_Info, GetNodeId(), "Received Alarm report: type=%d, level=%d", _data[1], _data[2] );

		ValueByte* value;
		if( (value = static_cast<ValueByte*>( GetValue( _instance, AlarmIndex_Type ) )) )
		{
			value->OnValueRefreshed( _data[1] );
			value->Release();
		}
		if( (value = static_cast<ValueByte*>( GetValue( _instance, AlarmIndex_Level ) )) )
		{
			value->OnValueRefreshed( _data[2] );
			value->Release();
		}
		return true;
	}

	return false;
}
コード例 #2
0
//-----------------------------------------------------------------------------
// <AssociationCommandConfiguration::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool AssociationCommandConfiguration::HandleMsg
(
	uint8 const* _data,
	uint32 const _length,
	uint32 const _instance	// = 1
)
{
	if (AssociationCommandConfigurationCmd_SupportedRecordsReport == (AssociationCommandConfigurationCmd)_data[0])
	{
		uint8 maxCommandLength			=	 _data[1] >> 2;
		bool commandsAreValues			= ( (_data[1] & 0x02) != 0 );
		bool commandsAreConfigurable	= ( (_data[1] & 0x01) != 0 );
		int16 numFreeCommands			= (((int16)_data[2])<<16) | (int16)_data[3];
		int16 maxCommands				= (((int16)_data[4])<<16) | (int16)_data[5];

		Log::Write( LogLevel_Info, GetNodeId(), "Received AssociationCommandConfiguration Supported Records Report:" );
		Log::Write( LogLevel_Info, GetNodeId(), "    Maximum command length = %d bytes", maxCommandLength );
		Log::Write( LogLevel_Info, GetNodeId(), "    Maximum number of commands = %d", maxCommands );
		Log::Write( LogLevel_Info, GetNodeId(), "    Number of free commands = %d", numFreeCommands );
		Log::Write( LogLevel_Info, GetNodeId(), "    Commands are %s and are %s", commandsAreValues ? "values" : "not values", commandsAreConfigurable ? "configurable" : "not configurable" );

		ValueBool* valueBool;
		ValueByte* valueByte;
		ValueShort* valueShort;

		if( (valueByte = static_cast<ValueByte*>( GetValue( _instance, AssociationCommandConfigurationIndex_MaxCommandLength ) )) )
		{
			valueByte->OnValueRefreshed( maxCommandLength );
			valueByte->Release();
		}

		if( (valueBool = static_cast<ValueBool*>( GetValue( _instance, AssociationCommandConfigurationIndex_CommandsAreValues ) )) )
		{
			valueBool->OnValueRefreshed( commandsAreValues );
			valueBool->Release();
		}

		if( (valueBool = static_cast<ValueBool*>( GetValue( _instance, AssociationCommandConfigurationIndex_CommandsAreConfigurable ) )) )
		{
			valueBool->OnValueRefreshed( commandsAreConfigurable );
			valueBool->Release();
		}

		if( (valueShort = static_cast<ValueShort*>( GetValue( _instance, AssociationCommandConfigurationIndex_NumFreeCommands ) )) )
		{
			valueShort->OnValueRefreshed( numFreeCommands );
			valueShort->Release();
		}

		if( (valueShort = static_cast<ValueShort*>( GetValue( _instance, AssociationCommandConfigurationIndex_MaxCommands ) )) )
		{
			valueShort->OnValueRefreshed( maxCommands );
			valueShort->Release();
		}
		return true;
	}
コード例 #3
0
//-----------------------------------------------------------------------------
// <ZWavePlusInfo::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool ZWavePlusInfo::HandleMsg
(
	uint8 const* _data,
	uint32 const _length,
	uint32 const _instance	// = 1
)
{
	if( ZWavePlusInfoCmd_Report == _data[0] )
	{
		uint8 version = _data[1];
		uint8 role    = _data[2];
		uint8 nodeType    = _data[3];
		uint16 installerIcon = (_data[4]<< 8) | _data[5];
		uint16 deviceType		 = (_data[6]<< 8) | _data[7];

		if( Node* node = GetNodeUnsafe() )
		{
			node->SetPlusDeviceClasses(	role, nodeType, deviceType );
		}
		ClearStaticRequest( StaticRequest_Values );

		ValueByte* value;
		if( (value = static_cast<ValueByte*>( GetValue( _instance, ZWavePlusInfoIndex_Version ) )) )
		{
			value->OnValueRefreshed( version );
			value->Release();
		}

		ValueShort* svalue;
		if( (svalue = static_cast<ValueShort*>( GetValue( _instance, ZWavePlusInfoIndex_InstallerIcon ) )) )
		{
			svalue->OnValueRefreshed( installerIcon );
			svalue->Release();
		}

		if( (svalue = static_cast<ValueShort*>( GetValue( _instance, ZWavePlusInfoIndex_UserIcon ) )) )
		{
			svalue->OnValueRefreshed( deviceType );
			svalue->Release();
		}




		return true;
	}
	return false;
}
コード例 #4
0
//-----------------------------------------------------------------------------
// <ManufacturerProprietary::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool ManufacturerProprietary::HandleMsg
(
    uint8 const* _data,
    uint32 const _length,
    uint32 const _instance    // = 1
)
{
    uint8 const* payload = _data+2;
    if( MANUFACTURER_ID_FIBARO[0] == _data[0] &&
        MANUFACTURER_ID_FIBARO[1] == _data[1] )
    {

        if( FIBARO_VENETIEN_BLINDS_REPORT_ID[0] == payload[0] &&
            FIBARO_VENETIEN_BLINDS_REPORT_ID[1] == payload[1] &&
            FIBARO_VENETIEN_BLINDS_REPORT_ID[2] == payload[2] )
        {
        ValueByte* blindsValue = static_cast<ValueByte*>( GetValue( _instance, FibaroVenetianBlindsValueIds_Blinds ) );
        ValueByte* tiltValue   = static_cast<ValueByte*>( GetValue( _instance, FibaroVenetianBlindsValueIds_Tilt ) );

        if( NULL != blindsValue && NULL != tiltValue)
        {
            Log::Write( LogLevel_Info, GetNodeId(), "Received Fibaro proprietary blind/slat position for node %d: Blinds: %d Slats: %d",
                        GetNodeId(), payload[3], payload[4] );
            blindsValue->OnValueRefreshed( payload[3] );
            tiltValue->OnValueRefreshed( payload[4] );
            blindsValue->Release();
            tiltValue->Release();
        }
        else
        {
            Log::Write( LogLevel_Warning, GetNodeId(), "Error setting Fibaro blind/slat position. Values were not found." );      
        }
            return true;
        }
        else
        {
            Log::Write( LogLevel_Warning, GetNodeId(), "Received unknown Fibaro proprietary message for node %d.",
                        GetNodeId());
            return false;
        }
    }
    Log::Write( LogLevel_Warning, GetNodeId(), "Received unknown manufacturer proprietary message for node %d.",
                GetNodeId());
    return false;
}
コード例 #5
0
//-----------------------------------------------------------------------------
// <ClimateControlSchedule::SetValue>
// Set a value in the device
//-----------------------------------------------------------------------------
bool ClimateControlSchedule::SetValue
(
	Value const& _value
)
{
//	bool res = false;
	uint8 instance = _value.GetID().GetInstance();
	uint8 idx = _value.GetID().GetIndex();

	if( idx < 8 )
	{
		// Set a schedule
		ValueSchedule const* value = static_cast<ValueSchedule const*>(&_value);

		Log::Write( LogLevel_Info, GetNodeId(), instance, "Set the climate control schedule for %s", c_dayNames[idx]);

		Msg* msg = new Msg( "ClimateControlScheduleCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
		msg->SetInstance( this, instance );
		msg->Append( GetNodeId() );
		msg->Append( 30 );
		msg->Append( GetCommandClassId() );
		msg->Append( ClimateControlScheduleCmd_Set );
		msg->Append( idx );	// Day of week

		for( uint8 i=0; i<9; ++i )
		{
			uint8 hours;
			uint8 minutes;
			int8 setback;
			if( value->GetSwitchPoint( i, &hours, &minutes, &setback ) )
			{
				msg->Append( hours );
				msg->Append( minutes );
				msg->Append( setback );
			}
			else
			{
				// Unused switch point
				msg->Append( 0 );
				msg->Append( 0 );
				msg->Append( 0x7f );
			}
		}

		msg->Append( GetDriver()->GetTransmitOptions() );
		GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
	}
	else
	{
		// Set an override
		ValueList* state = static_cast<ValueList*>( GetValue( instance, ClimateControlScheduleIndex_OverrideState ) );
		ValueByte* setback = static_cast<ValueByte*>( GetValue( instance, ClimateControlScheduleIndex_OverrideSetback ) );

		if( state && setback )
		{
			ValueList::Item const *item = state->GetItem();
			if (item == NULL) {
			        return false;
            }

			Msg* msg = new Msg( "ClimateControlScheduleCmd_OverrideSet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
			msg->SetInstance( this, instance );
			msg->Append( GetNodeId() );
			msg->Append( 4 );
			msg->Append( GetCommandClassId() );
			msg->Append( ClimateControlScheduleCmd_OverrideSet );
			msg->Append( (uint8)item->m_value );
			msg->Append( setback->GetValue() );
			msg->Append( GetDriver()->GetTransmitOptions() );
			GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
		}
	}

	return true;
}