forked from OpenZWave/open-zwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorAlarm.cpp
More file actions
198 lines (180 loc) · 6.63 KB
/
Copy pathSensorAlarm.cpp
File metadata and controls
198 lines (180 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//-----------------------------------------------------------------------------
//
// SensorAlarm.cpp
//
// Implementation of the Z-Wave COMMAND_CLASS_SENSOR_ALARM
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#include "command_classes/CommandClasses.h"
#include "command_classes/SensorAlarm.h"
#include "Defs.h"
#include "Msg.h"
#include "Node.h"
#include "Driver.h"
#include "platform/Log.h"
#include "value_classes/ValueByte.h"
namespace OpenZWave
{
namespace Internal
{
namespace CC
{
enum SensorAlarmCmd
{
SensorAlarmCmd_Get = 0x01,
SensorAlarmCmd_Report = 0x02,
SensorAlarmCmd_SupportedGet = 0x03,
SensorAlarmCmd_SupportedReport = 0x04
};
static char const* c_alarmTypeName[] =
{ "General", "Smoke", "Carbon Monoxide", "Carbon Dioxide", "Heat", "Flood" };
//-----------------------------------------------------------------------------
// <SensorAlarm::SensorAlarm>
// Constructor
//-----------------------------------------------------------------------------
SensorAlarm::SensorAlarm(uint32 const _homeId, uint8 const _nodeId) :
CommandClass(_homeId, _nodeId)
{
SetStaticRequest(StaticRequest_Values);
}
//-----------------------------------------------------------------------------
// <SensorAlarm::RequestState>
// Get the static thermostat setpoint details from the device
//-----------------------------------------------------------------------------
bool SensorAlarm::RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue)
{
bool requests = false;
if ((_requestFlags & RequestFlag_Static) && HasStaticRequest(StaticRequest_Values))
{
requests = RequestValue(_requestFlags, 0xff, _instance, _queue);
}
if (_requestFlags & RequestFlag_Dynamic)
{
for (uint8 i = 0; i < SensorAlarm_Count; ++i)
{
Internal::VC::Value* value = GetValue(1, i);
if (value != NULL)
{
value->Release();
// There is a value for this alarm type, so request it
requests |= RequestValue(_requestFlags, i, _instance, _queue);
}
}
}
return requests;
}
//-----------------------------------------------------------------------------
// <SensorAlarm::RequestValue>
// Get the sensor alarm details from the device
//-----------------------------------------------------------------------------
bool SensorAlarm::RequestValue(uint32 const _requestFlags, uint16 const _alarmType, uint8 const _instance, Driver::MsgQueue const _queue)
{
if (_alarmType == 0xff)
{
// Request the supported alarm types
Msg* msg = new Msg("SensorAlarmCmd_SupportedGet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId());
msg->SetInstance(this, _instance);
msg->Append(GetNodeId());
msg->Append(2);
msg->Append(GetCommandClassId());
msg->Append(SensorAlarmCmd_SupportedGet);
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, _queue);
return true;
}
else
{
// Request the alarm state
if (m_com.GetFlagBool(COMPAT_FLAG_GETSUPPORTED))
{
Msg* msg = new Msg("SensorAlarmCmd_Get", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId());
msg->SetInstance(this, _instance);
msg->Append(GetNodeId());
msg->Append(3);
msg->Append(GetCommandClassId());
msg->Append(SensorAlarmCmd_Get);
msg->Append((_alarmType & 0xFF));
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, _queue);
return true;
}
else
{
Log::Write(LogLevel_Info, GetNodeId(), "SensorAlarmCmd_Get Not Supported on this node");
}
}
return false;
}
//-----------------------------------------------------------------------------
// <SensorAlarm::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool SensorAlarm::HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance // = 1
)
{
if (SensorAlarmCmd_Report == (SensorAlarmCmd) _data[0])
{
// We have received an alarm state report from the Z-Wave device
if (Internal::VC::ValueByte* value = static_cast<Internal::VC::ValueByte*>(GetValue(_instance, _data[2])))
{
uint8 sourceNodeId = _data[1];
uint8 state = _data[3];
// uint16 time = (((uint16)_data[4])<<8) | (uint16)_data[5]; Don't know what to do with this yet.
value->OnValueRefreshed(state);
value->Release();
Log::Write(LogLevel_Info, GetNodeId(), "Received alarm state report from node %d: %s = %d", sourceNodeId, value->GetLabel().c_str(), state);
}
return true;
}
if (SensorAlarmCmd_SupportedReport == (SensorAlarmCmd) _data[0])
{
if (Node* node = GetNodeUnsafe())
{
// We have received the supported alarm types from the Z-Wave device
Log::Write(LogLevel_Info, GetNodeId(), "Received supported alarm types");
// Parse the data for the supported alarm types
uint8 numBytes = _data[1];
for (uint32 i = 0; i < numBytes; ++i)
{
for (int32 bit = 0; bit < 8; ++bit)
{
if ((_data[i + 2] & (1 << bit)) != 0)
{
// Add supported setpoint
int32 index = (int32) (i << 3) + bit;
if (index < SensorAlarm_Count)
{
node->CreateValueByte(ValueID::ValueGenre_User, GetCommandClassId(), _instance, index, c_alarmTypeName[index], "", true, false, 0, 0);
Log::Write(LogLevel_Info, GetNodeId(), " Added alarm type: %s", c_alarmTypeName[index]);
}
}
}
}
}
ClearStaticRequest(StaticRequest_Values);
return true;
}
return false;
}
} // namespace CC
} // namespace Internal
} // namespace OpenZWave