Skip to content

Commit

Permalink
Make @Fishwaldo happy
Browse files Browse the repository at this point in the history
  • Loading branch information
markruys committed Feb 10, 2021
1 parent bee09a1 commit 39364f7
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 118 deletions.
16 changes: 8 additions & 8 deletions cpp/src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4057,12 +4057,12 @@ void Node::WriteMetaDataXML(TiXmlElement *mdElement)
//-----------------------------------------------------------------------------
uint8 Node::GetSupervisionSessionId(uint8 _command_class_id)
{
if (Internal::CC::CommandClass* cc = GetCommandClass(Internal::CC::Supervision::StaticGetCommandClassId()))
{
return cc->GetSession(_command_class_id);
}
else
{
return Internal::CC::Supervision::StaticNoSessionId();
}
if (Internal::CC::CommandClass* cc = GetCommandClass(Internal::CC::Supervision::StaticGetCommandClassId()))
{
return cc->GetSession(_command_class_id);
}
else
{
return Internal::CC::Supervision::StaticNoSessionId();
}
}
2 changes: 1 addition & 1 deletion cpp/src/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ namespace OpenZWave
map<uint32_t, ChangeLogEntry> m_changeLog;

public:
uint8 GetSupervisionSessionId(uint8 _command_class_id);
uint8 GetSupervisionSessionId(uint8 _command_class_id);
};

} //namespace OpenZWave
Expand Down
70 changes: 31 additions & 39 deletions cpp/src/command_classes/Supervision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,50 @@ namespace OpenZWave
{
namespace CC
{
uint8 Supervision::m_session_id = 0;
uint8 Supervision::m_session_id = 0;

uint8 Supervision::GetSession(uint8 _command_class_id)
{
Supervision::m_session_id++;
Supervision::m_session_id &= 0x3f;
uint8 Supervision::GetSession(uint8 _command_class_id)
{
Supervision::m_session_id++;
Supervision::m_session_id &= 0x3f;

Supervision::m_command_class_id = _command_class_id;
Supervision::m_command_class_id = _command_class_id;

return Supervision::m_session_id;
}
return Supervision::m_session_id;
}

//-----------------------------------------------------------------------------
// <Supervision::HandleSupervisionReport>
// Handle a supervision report message from the Z-Wave network
//-----------------------------------------------------------------------------
void Supervision::HandleSupervisionReport(uint8 const* _data, uint32 const _length, uint32 const _instance)
{
if (Node* node = GetNodeUnsafe())
if (Node* node = GetNodeUnsafe())
{
if ( _length >= 4 ) {
uint8 more_status_updates = _data[1] >> 7;
uint8 session_id = _data[1] & 0x3f;
uint8 status = _data[2];
int duration = _data[3];
if ( _length >= 4 ) {
uint8 more_status_updates = _data[1] >> 7;
uint8 session_id = _data[1] & 0x3f;
uint8 status = _data[2];
int duration = _data[3];

Log::Write(LogLevel_Info, GetNodeId(), "Received SupervisionReport: session id %d, status 0x%02x, duration %d sec, more status updates %d",
session_id, status, decodeDuration(duration), more_status_updates);
Log::Write(LogLevel_Info, GetNodeId(), "Received SupervisionReport: session id %d, status 0x%02x, duration %d sec, more status updates %d",
session_id, status, decodeDuration(duration), more_status_updates);

if ( status == Supervision::SupervisionStatus::SupervisionStatus_Success )
{
if ( Supervision::m_session_id == session_id )
{
if (CommandClass* pCommandClass = node->GetCommandClass(Supervision::m_command_class_id))
{
pCommandClass->SupervisionSessionSuccess(session_id, _instance);
}
}
}
if ( status == Supervision::SupervisionStatus::SupervisionStatus_Success )
{
if ( Supervision::m_session_id == session_id )
{
if (CommandClass* pCommandClass = node->GetCommandClass(Supervision::m_command_class_id))
{
pCommandClass->SupervisionSessionSuccess(session_id, _instance);
}
}
}

if ( more_status_updates == 0 )
{
// Clean up session
}
if ( more_status_updates == 0 )
{
// Clean up session
}
}
}
}
Expand All @@ -98,8 +98,7 @@ namespace OpenZWave
// <Supervision::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool Supervision::HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance // = 1
)
bool Supervision::HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance) // = 1
{
bool handled = false;
Node* node = GetNodeUnsafe();
Expand All @@ -108,11 +107,6 @@ namespace OpenZWave
handled = true;
switch ((SupervisionCmd) _data[0])
{
// case SupervisionCmd_Get:
// {
// HandleSupervisionEncap(_data, _length);
// break;
// }
case SupervisionCmd_Report:
{
HandleSupervisionReport(_data, _length, _instance);
Expand All @@ -127,8 +121,6 @@ namespace OpenZWave
}

return handled;


}
} // namespace CC
} // namespace Internal
Expand Down
43 changes: 19 additions & 24 deletions cpp/src/command_classes/Supervision.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ namespace OpenZWave
class Supervision: public CommandClass
{
public:
enum SupervisionCmd
{
SupervisionCmd_Get = 0x01,
SupervisionCmd_Report = 0x02,
};
enum SupervisionMoreStatusUpdates
{
SupervisionMoreStatusUpdates_LastReport = 0x00,
SupervisionMoreStatusUpdates_MoreReports = 0x80,
};
enum SupervisionStatus
{
SupervisionStatus_NoSupport = 0x00,
SupervisionStatus_Working = 0x01,
SupervisionStatus_Fail = 0x02,
SupervisionStatus_Success = 0xff
};
enum SupervisionCmd
{
SupervisionCmd_Get = 0x01,
SupervisionCmd_Report = 0x02,
};
enum SupervisionMoreStatusUpdates
{
SupervisionMoreStatusUpdates_LastReport = 0x00,
SupervisionMoreStatusUpdates_MoreReports = 0x80,
};
enum SupervisionStatus
{
SupervisionStatus_NoSupport = 0x00,
SupervisionStatus_Working = 0x01,
SupervisionStatus_Fail = 0x02,
SupervisionStatus_Success = 0xff
};

static CommandClass* Create(uint32 const _homeId, uint8 const _nodeId)
{
Expand All @@ -77,11 +77,6 @@ namespace OpenZWave
return "COMMAND_CLASS_SUPERVISION";
}

// virtual uint8 GetMaxVersion() override
// {
// return 2; // TODO support v2 too
// }

uint8 GetSession(uint8 _command_class_id) ;
static uint8 const StaticNoSessionId()
{
Expand All @@ -106,8 +101,8 @@ namespace OpenZWave
{
}

static uint8 m_session_id;
uint8 m_command_class_id; // TODO as implemented now we support only a single concurrent supervision call per CC
static uint8 m_session_id;
uint8 m_command_class_id;

void HandleSupervisionReport(uint8 const* _data, uint32 const _length, uint32 const _instance);
};
Expand Down
70 changes: 35 additions & 35 deletions cpp/src/command_classes/ThermostatSetpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace OpenZWave
// <ThermostatSetpoint::HandleMsg>
// Handle a message from the Z-Wave network
//-----------------------------------------------------------------------------
bool ThermostatSetpoint::HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance // = 1
bool ThermostatSetpoint::HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance // = 1
)
{
if (ThermostatSetpointCmd_Report == (ThermostatSetpointCmd) _data[0])
Expand Down Expand Up @@ -264,20 +264,20 @@ namespace OpenZWave

void ThermostatSetpoint::SupervisionSessionSuccess(uint8 _session_id, uint32 const _instance)
{
if ( m_supervision_session_id == _session_id )
{
if ( m_supervision_session_id == _session_id )
{
if (Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(GetValue(_instance, m_supervision_index)))
{
value->ConfirmNewValue();

Log::Write(LogLevel_Info, GetNodeId(), "Confirmed thermostat setpoint to %s%s",
value->GetValue().c_str(), value->GetUnits().c_str());
}
}
else
{
Log::Write(LogLevel_Info, GetNodeId(), "Ignore unknown supervision session %d", _session_id);
}
Log::Write(LogLevel_Info, GetNodeId(), "Confirmed thermostat setpoint to %s%s",
value->GetValue().c_str(), value->GetUnits().c_str());
}
}
else
{
Log::Write(LogLevel_Info, GetNodeId(), "Ignore unknown supervision session %d", _session_id);
}
}

//-----------------------------------------------------------------------------
Expand All @@ -286,36 +286,36 @@ namespace OpenZWave
//-----------------------------------------------------------------------------
bool ThermostatSetpoint::SetValue(Internal::VC::Value const& _value)
{
if (Node* node = GetNodeUnsafe())
{
if (ValueID::ValueType_Decimal == _value.GetID().GetType())
{
Internal::VC::ValueDecimal const* value = static_cast<Internal::VC::ValueDecimal const*>(&_value);
m_supervision_session_id = node->GetSupervisionSessionId(StaticGetCommandClassId());
m_supervision_index = value->GetID().GetIndex() & 0xFF;
if (Node* node = GetNodeUnsafe())
{
if (ValueID::ValueType_Decimal == _value.GetID().GetType())
{
Internal::VC::ValueDecimal const* value = static_cast<Internal::VC::ValueDecimal const*>(&_value);
m_supervision_session_id = node->GetSupervisionSessionId(StaticGetCommandClassId());
m_supervision_index = value->GetID().GetIndex() & 0xFF;

if (m_supervision_session_id == Internal::CC::Supervision::StaticNoSessionId())
{
Log::Write(LogLevel_Debug, GetNodeId(), "Supervision not supported, fall back to setpoint set/get");
}

uint8 scale = strcmp("C", value->GetUnits().c_str()) ? 1 : 0;

Msg* msg = new Msg("ThermostatSetpointCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
msg->SetInstance(this, _value.GetID().GetInstance());
msg->SetSupervision(m_supervision_session_id);
msg->Append(GetNodeId());
msg->Append(4 + GetAppendValueSize(value->GetValue()));
msg->Append(GetCommandClassId());
msg->Append(ThermostatSetpointCmd_Set);
msg->Append(m_supervision_index);
AppendValue(msg, value->GetValue(), scale);

msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
return true;
}
}
uint8 scale = strcmp("C", value->GetUnits().c_str()) ? 1 : 0;

Msg* msg = new Msg("ThermostatSetpointCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
msg->SetInstance(this, _value.GetID().GetInstance());
msg->SetSupervision(m_supervision_session_id);
msg->Append(GetNodeId());
msg->Append(4 + GetAppendValueSize(value->GetValue()));
msg->Append(GetCommandClassId());
msg->Append(ThermostatSetpointCmd_Set);
msg->Append(m_supervision_index);
AppendValue(msg, value->GetValue(), scale);

msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
return true;
}
}

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/command_classes/ThermostatSetpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace OpenZWave
private:
ThermostatSetpoint(uint32 const _homeId, uint8 const _nodeId);

uint8 m_supervision_session_id;
uint8 m_supervision_session_id;
uint8 m_supervision_index;
};
} // namespace CC
Expand Down
20 changes: 10 additions & 10 deletions cpp/src/value_classes/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ namespace OpenZWave
{
if (m_refreshAfterSet)
{
if (!node->GetCommandClass(Internal::CC::Supervision::StaticGetCommandClassId()))
{
// queue a "RequestValue" message to update the value
cc->RequestValue( 0, m_id.GetIndex(), m_id.GetInstance(), Driver::MsgQueue_Send );
}
if (!node->GetCommandClass(Internal::CC::Supervision::StaticGetCommandClassId()))
{
// queue a "RequestValue" message to update the value
cc->RequestValue( 0, m_id.GetIndex(), m_id.GetInstance(), Driver::MsgQueue_Send );
}
}
}
else
Expand Down Expand Up @@ -499,10 +499,10 @@ namespace OpenZWave
int _targetValueLength // = 0,
)
{
// TODO: this is pretty rough code, but it's reused by each value type. It would be
// TODO: this is pretty rough code, but it's reused by each value type. It would be
// better if the actions were taken (m_value = _value, etc.) in this code rather than
// in the calling routine as a result of the return value. In particular, it's messy
// to be setting these values after the refesh or notification is sent. With some
// in the calling routine as a result of the return value. In particular, it's messy
// to be setting these values after the refesh or notification is sent. With some
// focus on the actual variable storage, we should be able to accomplish this with
// memory functions. It's really the strings that make things complicated(?).
// if this is the first read of a value, assume it is valid (and notify as a change)
Expand Down Expand Up @@ -612,9 +612,9 @@ namespace OpenZWave
bOriginalEqual = (*((bool*) _originalValue) == *((bool*) _newValue));
break;
case ValueID::ValueType_Raw: // raw
bOriginalEqual = (_originalValueLength == _newValueLength); // first check length of arrays
bOriginalEqual = (_originalValueLength == _newValueLength); // first check length of arrays
if (bOriginalEqual)
bOriginalEqual = (memcmp(_originalValue, _newValue, _newValueLength) == 0); // if length is the same, then check content
bOriginalEqual = (memcmp(_originalValue, _newValue, _newValueLength) == 0); // if length is the same, then check content
break;
case ValueID::ValueType_Schedule: // Schedule
/* Should not get here */
Expand Down

0 comments on commit 39364f7

Please sign in to comment.