1 //-----------------------------------------------------------------------------
2 //
3 // ApplicationStatus.cpp
4 //
5 // Implementation of the Z-Wave COMMAND_CLASS_APPLICATION_STATUS
6 //
7 // Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
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/ApplicationStatus.h"
30 #include "Defs.h"
31 #include "Msg.h"
32 #include "Driver.h"
33 #include "platform/Log.h"
34
35 using namespace OpenZWave;
36
37 enum ApplicationStatusCmd
38 {
39 ApplicationStatusCmd_Busy = 0x01,
40 ApplicationStatusCmd_RejectedRequest = 0x02
41 };
42
43
44 //-----------------------------------------------------------------------------
45 // <ApplicationStatus::HandleMsg>
46 // Handle a message from the Z-Wave network
47 //-----------------------------------------------------------------------------
HandleMsg(uint8 const * _data,uint32 const _length,uint32 const _instance)48 bool ApplicationStatus::HandleMsg
49 (
50 uint8 const* _data,
51 uint32 const _length,
52 uint32 const _instance // = 1
53 )
54 {
55 if( ApplicationStatusCmd_Busy == (ApplicationStatusCmd)_data[0] )
56 {
57 char msg[64];
58 switch( _data[1] )
59 {
60 case 0:
61 {
62 snprintf( msg, sizeof(msg), "Try again later" );
63 break;
64 }
65 case 1:
66 {
67 snprintf( msg, sizeof(msg), "Try again in %d seconds", _data[2] );
68 break;
69 }
70 case 2:
71 {
72 snprintf( msg, sizeof(msg), "Request queued, will be executed later" );
73 break;
74 }
75 default:
76 {
77 // Invalid status
78 snprintf( msg, sizeof(msg), "Unknown status %d", _data[1] );
79 }
80 }
81 Log::Write( LogLevel_Info, GetNodeId(), "Received Application Status Busy: %s", msg );
82 return true;
83 }
84
85 if( ApplicationStatusCmd_RejectedRequest == (ApplicationStatusCmd)_data[0] )
86 {
87 Log::Write( LogLevel_Info, "Received Application Rejected Request: Status=%d", _data[1] );
88 return true;
89 }
90
91 return false;
92 }
93
94