1 //-----------------------------------------------------------------------------
2 //
3 // SceneActivation.cpp
4 //
5 // Implementation of the Z-Wave COMMAND_CLASS_SCENE_ACTIVATION
6 //
7 // Copyright (c) 2012 Greg Satz <satz@iranger.com>
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/SceneActivation.h"
30 #include "Defs.h"
31 #include "Msg.h"
32 #include "Node.h"
33 #include "Driver.h"
34 #include "Notification.h"
35 #include "platform/Log.h"
36
37 using namespace OpenZWave;
38
39 enum SceneActivationCmd
40 {
41 SceneActivationCmd_Set = 0x01
42 };
43
44
45 //-----------------------------------------------------------------------------
46 // <SceneActivation::HandleMsg>
47 // Handle a message from the Z-Wave network
48 //-----------------------------------------------------------------------------
HandleMsg(uint8 const * _data,uint32 const _length,uint32 const _instance)49 bool SceneActivation::HandleMsg
50 (
51 uint8 const* _data,
52 uint32 const _length,
53 uint32 const _instance // = 1
54 )
55 {
56 if( SceneActivationCmd_Set == (SceneActivationCmd)_data[0] )
57 {
58 // Scene Activation Set received so send notification
59 char msg[64];
60 if( _data[2] == 0 )
61 snprintf( msg, sizeof(msg), "now" );
62 else if( _data[2] <= 0x7F )
63 snprintf( msg, sizeof(msg), "%d seconds", _data[2] );
64 else if( _data[2] <= 0xFE )
65 snprintf( msg, sizeof(msg), "%d minutes", _data[2] );
66 else
67 snprintf( msg, sizeof(msg), "via configuration" );
68 Log::Write( LogLevel_Info, GetNodeId(), "Received Scene Activation set from node %d: scene id=%d %s. Sending event notification.", GetNodeId(), _data[1], msg );
69 Notification* notification = new Notification( Notification::Type_SceneEvent );
70 notification->SetHomeAndNodeIds( GetHomeId(), GetNodeId() );
71 notification->SetSceneId( _data[1] );
72 GetDriver()->QueueNotification( notification );
73 return true;
74 }
75
76 return false;
77 }
78
79