|
28 | 28 | #include "command_classes/CommandClasses.h" |
29 | 29 | #include "command_classes/SwitchMultilevel.h" |
30 | 30 | #include "command_classes/WakeUp.h" |
| 31 | +#include "command_classes/Supervision.h" |
31 | 32 | #include "Defs.h" |
32 | 33 | #include "Msg.h" |
33 | 34 | #include "Driver.h" |
@@ -226,6 +227,29 @@ namespace OpenZWave |
226 | 227 | return false; |
227 | 228 | } |
228 | 229 |
|
| 230 | + void SwitchMultilevel::SupervisionSessionSuccess(uint8 _session_id, uint32 const _instance) |
| 231 | + { |
| 232 | + if (Node* node = GetNodeUnsafe()) |
| 233 | + { |
| 234 | + uint32 index = node->GetSupervisionIndex(_session_id); |
| 235 | + |
| 236 | + if (index != Internal::CC::Supervision::StaticNoIndex()) |
| 237 | + { |
| 238 | + if (Internal::VC::ValueByte* value = static_cast<Internal::VC::ValueByte*>(GetValue(_instance, ValueID_Index_SwitchMultiLevel::Level))) |
| 239 | + { |
| 240 | + value->ConfirmNewValue(); |
| 241 | + |
| 242 | + Log::Write(LogLevel_Info, GetNodeId(), "Confirmed switch multi level index %d to value=%d", |
| 243 | + index, value->GetValue()); |
| 244 | + } |
| 245 | + } |
| 246 | + else |
| 247 | + { |
| 248 | + Log::Write(LogLevel_Info, GetNodeId(), "Ignore unknown supervision session %d", _session_id); |
| 249 | + } |
| 250 | + } |
| 251 | + } |
| 252 | + |
229 | 253 | //----------------------------------------------------------------------------- |
230 | 254 | // <SwitchMultilevel::SetValue> |
231 | 255 | // Set the level on a device |
@@ -394,40 +418,54 @@ namespace OpenZWave |
394 | 418 | //----------------------------------------------------------------------------- |
395 | 419 | bool SwitchMultilevel::SetLevel(uint8 const _instance, uint8 const _level) |
396 | 420 | { |
397 | | - Log::Write(LogLevel_Info, GetNodeId(), "SwitchMultilevel::Set - Setting to level %d", _level); |
398 | | - Msg* msg = new Msg("SwitchMultilevelCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true); |
399 | | - msg->SetInstance(this, _instance); |
400 | | - msg->Append(GetNodeId()); |
401 | 421 |
|
402 | | - if (GetVersion() >= 2) |
403 | | - { |
404 | | - Internal::VC::ValueInt* durationValue = static_cast<Internal::VC::ValueInt*>(GetValue(_instance, ValueID_Index_SwitchMultiLevel::Duration)); |
405 | | - uint32 duration = durationValue->GetValue(); |
406 | | - durationValue->Release(); |
407 | | - if (duration > 7620) |
408 | | - Log::Write(LogLevel_Info, GetNodeId(), " Duration: Device Default"); |
409 | | - else if (duration > 0x7F) |
410 | | - Log::Write(LogLevel_Info, GetNodeId(), " Rouding to %d Minutes (over 127 seconds)", encodeDuration(duration)-0x79); |
411 | | - else |
412 | | - Log::Write(LogLevel_Info, GetNodeId(), " Duration: %d seconds", duration); |
413 | | - |
414 | | - msg->Append(4); |
415 | | - msg->Append(GetCommandClassId()); |
416 | | - msg->Append(SwitchMultilevelCmd_Set); |
417 | | - msg->Append(_level); |
418 | | - msg->Append(encodeDuration(duration)); |
419 | | - } |
420 | | - else |
| 422 | + if (Node* node = GetNodeUnsafe()) |
421 | 423 | { |
422 | | - msg->Append(3); |
423 | | - msg->Append(GetCommandClassId()); |
424 | | - msg->Append(SwitchMultilevelCmd_Set); |
425 | | - msg->Append(_level); |
426 | | - } |
| 424 | + //add supervision encapsulation if supported |
| 425 | + uint8 index = ValueID_Index_SwitchMultiLevel::Level; |
| 426 | + uint8 supervision_session_id = node->CreateSupervisionSession(StaticGetCommandClassId(), index); |
| 427 | + if (supervision_session_id == Internal::CC::Supervision::StaticNoSessionId()) |
| 428 | + { |
| 429 | + Log::Write(LogLevel_Debug, GetNodeId(), "Supervision not supported, fall back to setpoint set/get"); |
| 430 | + } |
427 | 431 |
|
428 | | - msg->Append(GetDriver()->GetTransmitOptions()); |
429 | | - GetDriver()->SendMsg(msg, Driver::MsgQueue_Send); |
430 | | - return true; |
| 432 | + Log::Write(LogLevel_Info, GetNodeId(), "SwitchMultilevel::Set - Setting to level %d", _level); |
| 433 | + Msg* msg = new Msg("SwitchMultilevelCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true); |
| 434 | + msg->SetInstance(this, _instance); |
| 435 | + msg->SetSupervision(supervision_session_id); |
| 436 | + msg->Append(GetNodeId()); |
| 437 | + |
| 438 | + if (GetVersion() >= 2) |
| 439 | + { |
| 440 | + Internal::VC::ValueInt* durationValue = static_cast<Internal::VC::ValueInt*>(GetValue(_instance, ValueID_Index_SwitchMultiLevel::Duration)); |
| 441 | + uint32 duration = durationValue->GetValue(); |
| 442 | + durationValue->Release(); |
| 443 | + if (duration > 7620) |
| 444 | + Log::Write(LogLevel_Info, GetNodeId(), " Duration: Device Default"); |
| 445 | + else if (duration > 0x7F) |
| 446 | + Log::Write(LogLevel_Info, GetNodeId(), " Rouding to %d Minutes (over 127 seconds)", encodeDuration(duration)-0x79); |
| 447 | + else |
| 448 | + Log::Write(LogLevel_Info, GetNodeId(), " Duration: %d seconds", duration); |
| 449 | + |
| 450 | + msg->Append(4); |
| 451 | + msg->Append(GetCommandClassId()); |
| 452 | + msg->Append(SwitchMultilevelCmd_Set); |
| 453 | + msg->Append(_level); |
| 454 | + msg->Append(encodeDuration(duration)); |
| 455 | + } |
| 456 | + else |
| 457 | + { |
| 458 | + msg->Append(3); |
| 459 | + msg->Append(GetCommandClassId()); |
| 460 | + msg->Append(SwitchMultilevelCmd_Set); |
| 461 | + msg->Append(_level); |
| 462 | + } |
| 463 | + |
| 464 | + msg->Append(GetDriver()->GetTransmitOptions()); |
| 465 | + GetDriver()->SendMsg(msg, Driver::MsgQueue_Send); |
| 466 | + return true; |
| 467 | + } |
| 468 | + return false; |
431 | 469 | } |
432 | 470 |
|
433 | 471 | //----------------------------------------------------------------------------- |
|
0 commit comments