1 //-----------------------------------------------------------------------------
2 //
3 //	DeviceResetLocally.cpp
4 //
5 //	Implementation of the Z-Wave COMMAND_CLASS_DEVICE_RESET_LOCALLY
6 //
7 //	Copyright (c) 2015
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 #include "command_classes/CommandClasses.h"
29 #include "command_classes/DeviceResetLocally.h"
30 #include "command_classes/NoOperation.h"
31 #include "Defs.h"
32 #include "Manager.h"
33 #include "platform/Log.h"
34 
35 using namespace OpenZWave;
36 
37 enum DeviceResetLocallyCmd
38 {
39 	DeviceResetLocallyCmd_Notification = 1
40 };
41 
42 
43 //-----------------------------------------------------------------------------
44 // <DeviceResetLocally::HandleMsg>
45 // Handle a message from the Z-Wave network
46 //-----------------------------------------------------------------------------
HandleMsg(uint8 const * _data,uint32 const _length,uint32 const _instance)47 bool DeviceResetLocally::HandleMsg
48 (
49 	uint8 const* _data,
50 	uint32 const _length,
51 	uint32 const _instance	// = 1
52 )
53 {
54 	if( DeviceResetLocallyCmd_Notification == _data[0] )
55 	{
56 		// device has been reset
57 		Log::Write( LogLevel_Info, GetNodeId(), "Received Device Reset Locally from node %d", GetNodeId() );
58 
59 		// send a NoOperation message to the node, this will fail since the node is no longer included in the network
60 		// we must do this because the Controller will only remove failed nodes
61 		if( Node* node = GetNodeUnsafe() )
62 		{
63 			if( NoOperation* noop = static_cast<NoOperation*>( node->GetCommandClass( NoOperation::StaticGetCommandClassId() ) ) )
64 			{
65 				noop->Set( true );
66 			}
67 		}
68 		// the Controller now knows the node has failed
69 		Manager::Get()->HasNodeFailed( GetHomeId(), GetNodeId() );
70 		m_deviceReset = true;
71 
72 		return true;
73 	}
74 	return false;
75 }
76 
77