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

Method SetValue

cpp/src/command_classes/UserCode.cpp:541–678  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Set a User Code value -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

539// Set a User Code value
540//-----------------------------------------------------------------------------
541bool UserCode::SetValue
542(
543 Value const& _value
544)
545{
546 if( (ValueID::ValueType_String == _value.GetID().GetType()) && (_value.GetID().GetIndex() < UserCodeIndex_Refresh) )
547 {
548 ValueString const* value = static_cast<ValueString const*>(&_value);
549 string s = value->GetValue();
550 if (s.length() < 4) {
551 Log::Write( LogLevel_Warning, GetNodeId(), "UserCode is smaller than 4 digits", value->GetID().GetIndex());
552 return false;
553 }
554 if (s.length() > 10) {
555 Log::Write( LogLevel_Warning, GetNodeId(), "UserCode is larger than 10 digits", value->GetID().GetIndex());
556 return false;
557 }
558 uint8 len = (uint8_t)(s.length() & 0xFF);
559 if (value->GetID().GetIndex() == 0 || value->GetID().GetIndex() > m_dom.GetFlagByte(STATE_FLAG_USERCODE_COUNT)) {
560 Log::Write( LogLevel_Warning, GetNodeId(), "Index %d is out of range of UserCodeCount", value->GetID().GetIndex());
561 return false;
562 }
563
564
565 Msg* msg = new Msg( "UserCodeCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
566 msg->SetInstance( this, _value.GetID().GetInstance() );
567 msg->Append( GetNodeId() );
568 msg->Append( 4 + len );
569 msg->Append( GetCommandClassId() );
570 msg->Append( UserCodeCmd_Set );
571 msg->Append( (uint8_t)(value->GetID().GetIndex() & 0xFF) );
572 msg->Append( UserCode_Occupied );
573 for( uint8 i = 0; i < len; i++ )
574 {
575 msg->Append( s[i] );
576 }
577 msg->Append( GetDriver()->GetTransmitOptions() );
578 GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
579
580 return true;
581 }
582 if ( (ValueID::ValueType_Button == _value.GetID().GetType()) && (_value.GetID().GetIndex() == UserCodeIndex_Refresh) )
583 {
584 m_refreshUserCodes = true;
585 m_currentCode = 1;
586 m_queryAll = true;
587 RequestValue( 0, m_currentCode, _value.GetID().GetInstance(), Driver::MsgQueue_Query );
588 return true;
589 }
590 if ( (ValueID::ValueType_Short == _value.GetID().GetType()) && (_value.GetID().GetIndex() == UserCodeIndex_RemoveCode) )
591 {
592 ValueShort const* value = static_cast<ValueShort const*>(&_value);
593 uint8_t index = (uint8_t)(value->GetValue() & 0xFF);
594 if (index == 0 || index > m_dom.GetFlagByte(STATE_FLAG_USERCODE_COUNT)) {
595 Log::Write( LogLevel_Warning, GetNodeId(), "Index %d is out of range of UserCodeCount", index);
596 return false;
597 }
598 Msg* msg = new Msg( "UserCodeCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true );

Callers

nothing calls this directly

Calls 14

WriteFunction · 0.85
GetCommandClassIdFunction · 0.85
RequestValueFunction · 0.85
GetFlagByteMethod · 0.80
GetInstanceMethod · 0.80
SendMsgMethod · 0.80
GetLengthMethod · 0.80
GetNodeIdFunction · 0.70
GetValueMethod · 0.45
lengthMethod · 0.45
SetInstanceMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected