MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / Set

Method Set

cpp/src/command_classes/Powerlevel.cpp:326–375  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Set the transmit power of a node for a specified time -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

324// Set the transmit power of a node for a specified time
325//-----------------------------------------------------------------------------
326bool Powerlevel::Set
327(
328 uint8 const _instance
329)
330{
331 PowerLevelEnum powerLevel = PowerLevel_Normal;
332 uint8 timeout;
333
334 if( ValueList* value = static_cast<ValueList*>( GetValue( _instance, PowerlevelIndex_Powerlevel ) ) )
335 {
336 ValueList::Item const *item = value->GetItem();
337 if (item != NULL)
338 powerLevel = (PowerLevelEnum)item->m_value;
339 value->Release();
340 }
341 else
342 {
343 return false;
344 }
345
346 if( ValueByte* value = static_cast<ValueByte*>( GetValue( _instance, PowerlevelIndex_Timeout ) ) )
347 {
348 timeout = value->GetValue();
349 value->Release();
350 }
351 else
352 {
353 return false;
354 }
355 if (powerLevel > 9) /* size of c_powerLevelNames minus Unknown */
356 {
357 Log::Write (LogLevel_Warning, GetNodeId(), "powerLevel Value was greater than range. Dropping");
358 /* Drop it */
359 return false;
360 }
361
362
363 Log::Write( LogLevel_Info, GetNodeId(), "Setting the power level to %s for %d seconds", c_powerLevelNames[powerLevel], timeout );
364 Msg* msg = new Msg( "PowerlevelCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
365 msg->SetInstance( this, _instance );
366 msg->Append( GetNodeId() );
367 msg->Append( 4 );
368 msg->Append( GetCommandClassId() );
369 msg->Append( PowerlevelCmd_Set );
370 msg->Append( (uint8)powerLevel );
371 msg->Append( timeout );
372 msg->Append( GetDriver()->GetTransmitOptions() );
373 GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
374 return true;
375}
376
377//-----------------------------------------------------------------------------
378// <Powerlevel::Test>

Callers

nothing calls this directly

Calls 9

WriteFunction · 0.85
GetCommandClassIdFunction · 0.85
GetItemMethod · 0.80
SendMsgMethod · 0.80
GetNodeIdFunction · 0.70
ReleaseMethod · 0.45
GetValueMethod · 0.45
SetInstanceMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected