----------------------------------------------------------------------------- Set the transmit power of a node for a specified time -----------------------------------------------------------------------------
| 324 | // Set the transmit power of a node for a specified time |
| 325 | //----------------------------------------------------------------------------- |
| 326 | bool 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> |
nothing calls this directly
no test coverage detected