forked from OpenZWave/open-zwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleAV.cpp
More file actions
188 lines (174 loc) · 5.91 KB
/
Copy pathSimpleAV.cpp
File metadata and controls
188 lines (174 loc) · 5.91 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
//-----------------------------------------------------------------------------
//
// SimpleAVCommandItem.h
//
// Implementation of the Z-Wave COMMAND_CLASS_SIMPLE_AV_CONTROL
//
// Copyright (c) 2018
//
// 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/MultiInstance.h"
#include "command_classes/SimpleAV.h"
#include "command_classes/SimpleAVCommandItem.h"
#include "Defs.h"
#include "Msg.h"
#include "Node.h"
#include "Driver.h"
#include "platform/Log.h"
#include <vector>
#include "value_classes/ValueShort.h"
#include "value_classes/ValueList.h"
namespace OpenZWave
{
namespace Internal
{
namespace CC
{
uint8 m_sequence;
enum SimpleAVCmd
{
SimpleAVCmd_Set = 0x01
};
//-----------------------------------------------------------------------------
// <SimpleAV::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool SimpleAV::HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance)
{
return true;
}
//-----------------------------------------------------------------------------
// <SimpleAV::SetValue>
// Set a value in the Z-Wave device
//-----------------------------------------------------------------------------
bool SimpleAV::SetValue(Internal::VC::Value const& _value)
{
uint16 shortval;
if (ValueID::ValueType_Short == _value.GetID().GetType())
{
Internal::VC::ValueShort const* value = static_cast<Internal::VC::ValueShort const*>(&_value);
shortval = value->GetValue();
}
else if (ValueID::ValueType_List == _value.GetID().GetType())
{
Internal::VC::ValueList const* value = static_cast<Internal::VC::ValueList const*>(&_value);
shortval = value->GetItem()->m_value;
}
else
return false;
uint8 instance = _value.GetID().GetInstance();
Msg* msg = new Msg("SimpleAVCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
msg->SetInstance(this, instance);
msg->Append(GetNodeId());
msg->Append(8); // Length
msg->Append(GetCommandClassId());
msg->Append(SimpleAVCmd_Set);
msg->Append(m_sequence++); // Crutch
msg->Append(0);
msg->Append(0);
msg->Append(0);
msg->Append(shortval >> 8);
msg->Append(shortval & 0xff);
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
if (m_sequence == 255)
m_sequence = 0;
return true;
}
//-----------------------------------------------------------------------------
// <SimpleAV::CreateVars>
// Create the values managed by this command class
//-----------------------------------------------------------------------------
void SimpleAV::CreateVars(uint8 const _instance)
{
if (Node* node = GetNodeUnsafe())
{
// Create list value
vector<Internal::VC::ValueList::Item> items;
vector<SimpleAVCommandItem> commands = SimpleAVCommandItem::GetCommands();
vector<SimpleAVCommandItem>::iterator iterator;
string helpList = "Possible values: \n";
string helpNumeric = "Possible values: \n";
for (iterator = commands.begin(); iterator != commands.end(); iterator++)
{
SimpleAVCommandItem command = *iterator;
if (command.GetVersion() <= GetVersion())
{
Internal::VC::ValueList::Item item;
item.m_value = command.GetCode();
item.m_label = command.GetName();
items.push_back(item);
#if 0
// ValueList - create command description for help
string codeStr = string("ZWave command number: ").append(std::to_string(command.GetCode()));
string descriptionFull = "";
if (command.GetDescription() == "")
{
descriptionFull =
command
.GetName()
.append(" (")
.append(codeStr)
.append(")\n");
}
else
{
descriptionFull =
command
.GetName()
.append(" (")
.append(command.GetDescription())
.append("; ")
.append(codeStr)
.append(")\n");
}
helpList += descriptionFull;
// ValueShort - create command description for help
if (command.GetDescription() == "")
{
descriptionFull =
std::to_string(command.GetCode())
.append(" (")
.append(command.GetName())
.append(")\n");
}
else
{
descriptionFull =
std::to_string(command.GetCode())
.append(" (")
.append(command.GetName())
.append("; ")
.append(command.GetDescription())
.append(")\n");
}
helpNumeric += descriptionFull;
#endif
}
}
node->CreateValueList(ValueID::ValueGenre_User, GetCommandClassId(), _instance, ValueID_Index_SimpleAV::Command, string("OutputAVCommand_").append(std::to_string(_instance)), "", false, true, 2, items, 0, 0);
// Create a similar numeric value
// node->CreateValueShort(ValueID::ValueGenre_User, GetCommandClassId(), _instance, 0, string("OutputAVCommandNumber_").append(std::to_string(_instance)), "", false, true, 0, 0, helpNumeric);
}
}
} // namespace CC
} // namespace Internal
} // namespace OpenZWave