Skip to content

Commit

Permalink
add tests & fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gjc13 committed Feb 16, 2022
1 parent 3331331 commit 0996dc8
Show file tree
Hide file tree
Showing 62 changed files with 1,461 additions and 790 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ server cluster BinaryInputBasic = 15 {

server cluster Binding = 30 {
struct TargetStruct {
FABRIC_IDX fabricIdx = 0;
optional NODE_ID nodeId = 1;
optional GROUP_ID groupId = 2;
optional ENDPOINT_NO endpointId = 3;
optional CLUSTER_ID clusterId = 4;
FABRIC_IDX fabricIndex = 0;
optional NODE_ID node = 1;
optional GROUP_ID group = 2;
optional ENDPOINT_NO endpoint = 3;
optional CLUSTER_ID cluster = 4;
}

attribute TargetStruct bindingList[] = 0;
attribute TargetStruct binding[] = 0;
readonly global attribute int16u clusterRevision = 65533;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ static void RegisterSwitchCommands()
}
#endif // defined(ENABLE_CHIP_SHELL)

static void BoundDeviceChangedHandler(const EmberBindingTableEntry * binding, chip::DeviceProxy * peer_device, void * context)
static void BoundDeviceChangedHandler(const EmberBindingTableEntry & binding, chip::DeviceProxy * peer_device, void * context)
{
using namespace chip;
using namespace chip::app;

if (binding->type == EMBER_MULTICAST_BINDING)
if (binding.type == EMBER_MULTICAST_BINDING)
{
ChipLogError(NotSpecified, "Group binding is not supported now");
return;
}

if (binding->type == EMBER_UNICAST_BINDING && binding->local == 1 && binding->clusterId.HasValue() &&
binding->clusterId.Value() == Clusters::OnOff::Id)
if (binding.type == EMBER_UNICAST_BINDING && binding.local == 1 &&
(!binding.clusterId.HasValue() || binding.clusterId.Value() == Clusters::OnOff::Id))
{
auto onSuccess = [](const ConcreteCommandPath & commandPath, const StatusIB & status, const auto & dataResponse) {
ChipLogProgress(NotSpecified, "OnOff command succeeds");
Expand All @@ -91,13 +91,13 @@ static void BoundDeviceChangedHandler(const EmberBindingTableEntry * binding, ch
{
Clusters::OnOff::Commands::On::Type onCommand;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding->remote, onCommand, onSuccess, onFailure);
binding.remote, onCommand, onSuccess, onFailure);
}
else
{
Clusters::OnOff::Commands::Off::Type offCommand;
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(),
binding->remote, offCommand, onSuccess, onFailure);
binding.remote, offCommand, onSuccess, onFailure);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function getTests()
'TestOperationalCredentialsCluster',
'TestModeSelectCluster',
'TestSystemCommands',
'TestBinding',
];

const SoftwareDiagnostics = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ server cluster Basic = 40 {

server cluster Binding = 30 {
struct TargetStruct {
FABRIC_IDX fabricIdx = 0;
optional NODE_ID nodeId = 1;
optional GROUP_ID groupId = 2;
optional ENDPOINT_NO endpointId = 3;
optional CLUSTER_ID clusterId = 4;
FABRIC_IDX fabricIndex = 0;
optional NODE_ID node = 1;
optional GROUP_ID group = 2;
optional ENDPOINT_NO endpoint = 3;
optional CLUSTER_ID cluster = 4;
}

attribute TargetStruct bindingList[] = 0;
attribute TargetStruct binding[] = 0;
readonly global attribute int16u clusterRevision = 65533;
}

Expand Down
12 changes: 6 additions & 6 deletions examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ server cluster Basic = 40 {

server cluster Binding = 30 {
struct TargetStruct {
FABRIC_IDX fabricIdx = 0;
optional NODE_ID nodeId = 1;
optional GROUP_ID groupId = 2;
optional ENDPOINT_NO endpointId = 3;
optional CLUSTER_ID clusterId = 4;
FABRIC_IDX fabricIndex = 0;
optional NODE_ID node = 1;
optional GROUP_ID group = 2;
optional ENDPOINT_NO endpoint = 3;
optional CLUSTER_ID cluster = 4;
}

attribute TargetStruct bindingList[] = 0;
attribute TargetStruct binding[] = 0;
readonly global attribute int16u clusterRevision = 65533;
}

Expand Down
24 changes: 12 additions & 12 deletions examples/tv-app/tv-common/tv-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -278,27 +278,27 @@ server cluster Basic = 40 {

client cluster Binding = 30 {
struct TargetStruct {
FABRIC_IDX fabricIdx = 0;
optional NODE_ID nodeId = 1;
optional GROUP_ID groupId = 2;
optional ENDPOINT_NO endpointId = 3;
optional CLUSTER_ID clusterId = 4;
FABRIC_IDX fabricIndex = 0;
optional NODE_ID node = 1;
optional GROUP_ID group = 2;
optional ENDPOINT_NO endpoint = 3;
optional CLUSTER_ID cluster = 4;
}

attribute TargetStruct bindingList[] = 0;
attribute TargetStruct binding[] = 0;
readonly global attribute int16u clusterRevision = 65533;
}

server cluster Binding = 30 {
struct TargetStruct {
FABRIC_IDX fabricIdx = 0;
optional NODE_ID nodeId = 1;
optional GROUP_ID groupId = 2;
optional ENDPOINT_NO endpointId = 3;
optional CLUSTER_ID clusterId = 4;
FABRIC_IDX fabricIndex = 0;
optional NODE_ID node = 1;
optional GROUP_ID group = 2;
optional ENDPOINT_NO endpoint = 3;
optional CLUSTER_ID cluster = 4;
}

attribute TargetStruct bindingList[] = 0;
attribute TargetStruct binding[] = 0;
readonly global attribute int16u clusterRevision = 65533;
}

Expand Down
12 changes: 6 additions & 6 deletions examples/tv-casting-app/tv-casting-common/tv-casting-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ server cluster BinaryInputBasic = 15 {

server cluster Binding = 30 {
struct TargetStruct {
FABRIC_IDX fabricIdx = 0;
optional NODE_ID nodeId = 1;
optional GROUP_ID groupId = 2;
optional ENDPOINT_NO endpointId = 3;
optional CLUSTER_ID clusterId = 4;
FABRIC_IDX fabricIndex = 0;
optional NODE_ID node = 1;
optional GROUP_ID group = 2;
optional ENDPOINT_NO endpoint = 3;
optional CLUSTER_ID cluster = 4;
}

attribute TargetStruct bindingList[] = 0;
attribute TargetStruct binding[] = 0;
readonly global attribute int16u clusterRevision = 65533;
}

Expand Down
98 changes: 17 additions & 81 deletions src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,101 +393,37 @@ CHIP_ERROR ContentAppPlatform::CreateBindingWithCallback(OperationalDeviceProxy
ClusterId bindingClusterId,
Controller::WriteResponseSuccessCallback successCb,
Controller::WriteResponseFailureCallback failureCb)
{
if (mBindingDevice != nullptr)
{
return CHIP_ERROR_INCORRECT_STATE;
}
mBindingDevice = device;
mDeviceEndpointId = deviceEndpointId;
mBindingNodeId = bindingNodeId;
mBindingGroupId = bindingGroupId;
mBindingEndpointId = bindingEndpointId;
mBindingClusterId = bindingClusterId;
mBindingSucessCallback = successCb;
mBindingFailureCallback = failureCb;

CHIP_ERROR error = ReadFabricsList(device);
if (error != CHIP_NO_ERROR)
{
mBindingDevice = nullptr;
}
ChipLogDetail(Controller, "CreateBindingWithCallback: Sent read fabrics list request, waiting for response");
return error;
}

CHIP_ERROR ContentAppPlatform::ReadFabricsList(OperationalDeviceProxy * device)
{
chip::Controller::OperationalCredentialsCluster cluster;
cluster.Associate(device, 0);
return cluster.ReadAttribute<FabricsListDecodableType>(this, OperationalCredentials::Id,
OperationalCredentials::Attributes::FabricsList::Id,
OnReadFabricsListSuccess, OnReadFabricsListFailure);
}

void ContentAppPlatform::OnReadFabricsListSuccess(void * context, const FabricsListDecodableType & data)
{
ContentAppPlatform * obj = static_cast<ContentAppPlatform *>(context);
auto iter = data.begin();
FabricInfo * fabric =
Server::GetInstance().GetFabricTable().FindFabricWithCompressedId(obj->mBindingDevice->GetPeerId().GetCompressedFabricId());

if (fabric == nullptr)
{
obj->NotifyBindingFailed(CHIP_ERROR_NOT_FOUND);
}

while (iter.Next())
{
PeerId peer;
fabric->GetCompressedId(iter.GetValue().fabricId, iter.GetValue().nodeId, &peer);
if (peer == obj->mBindingDevice->GetPeerId())
{
obj->SendBindingWriteRequest(iter.GetValue().fabricIndex);
return;
}
}
obj->NotifyBindingFailed(CHIP_ERROR_NOT_FOUND);
}

void ContentAppPlatform::OnReadFabricsListFailure(void * context, CHIP_ERROR error)
{
ContentAppPlatform * obj = static_cast<ContentAppPlatform *>(context);
obj->NotifyBindingFailed(error);
}

void ContentAppPlatform::NotifyBindingFailed(CHIP_ERROR error)
{
mBindingDevice = nullptr;
mBindingFailureCallback(nullptr, error);
}

void ContentAppPlatform::SendBindingWriteRequest(FabricIndex fabricIndex)
{
chip::Controller::BindingCluster cluster;
cluster.Associate(mBindingDevice, mDeviceEndpointId);
cluster.Associate(device, deviceEndpointId);
Binding::Structs::TargetStruct::Type entries[1];

if (mBindingNodeId != kUndefinedNodeId)
if (bindingNodeId != kUndefinedNodeId)
{
entries[0] = Binding::Structs::TargetStruct::Type{
fabricIndex,
Optional<NodeId>(mBindingNodeId),
NullOptional,
Optional<EndpointId>(mBindingEndpointId),
Optional<ClusterId>(mBindingClusterId),
.fabricIndex = kUndefinedFabricIndex,
.node = MakeOptional(bindingNodeId),
.group = NullOptional,
.endpoint = MakeOptional(bindingEndpointId),
.cluster = MakeOptional(bindingClusterId),
};
}
else
{
entries[0] = Binding::Structs::TargetStruct::Type{
fabricIndex, NullOptional, Optional<GroupId>(mBindingGroupId), NullOptional, Optional<ClusterId>(mBindingClusterId),
.fabricIndex = kUndefinedFabricIndex,
.node = NullOptional,
.group = MakeOptional(bindingGroupId),
.endpoint = NullOptional,
.cluster = MakeOptional(bindingClusterId),
};
}
Binding::Attributes::BindingList::TypeInfo::Type bindingList(entries);
cluster.WriteAttribute(bindingList, nullptr, Binding::Id, Binding::Attributes::BindingList::Id, mBindingSucessCallback,
mBindingFailureCallback, NullOptional);
Binding::Attributes::Binding::TypeInfo::Type bindingList(entries);
CHIP_ERROR error = cluster.WriteAttribute(bindingList, nullptr, Binding::Id, Binding::Attributes::Binding::Id, successCb,
failureCb, NullOptional);
ChipLogDetail(Controller, "CreateBindingWithCallback: Sent write request, waiting for response");

return error;
}

} // namespace AppPlatform
Expand Down
19 changes: 0 additions & 19 deletions src/app/app-platform/ContentAppPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,6 @@ class DLL_EXPORT ContentAppPlatform
EndpointId mCurrentEndpointId;
EndpointId mFirstDynamicEndpointId;
ContentApp * mContentApps[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];

private:
using FabricsListDecodableType = app::Clusters::OperationalCredentials::Attributes::FabricsList::TypeInfo::DecodableType;

static void OnReadFabricsListSuccess(void * context, const FabricsListDecodableType & data);
static void OnReadFabricsListFailure(void * context, CHIP_ERROR error);
void NotifyBindingFailed(CHIP_ERROR error);
void SendBindingWriteRequest(FabricIndex fabricIndex);

CHIP_ERROR ReadFabricsList(OperationalDeviceProxy * device);

OperationalDeviceProxy * mBindingDevice = nullptr;
EndpointId mDeviceEndpointId;
NodeId mBindingNodeId;
GroupId mBindingGroupId;
EndpointId mBindingEndpointId;
ClusterId mBindingClusterId;
Controller::WriteResponseSuccessCallback mBindingSucessCallback;
Controller::WriteResponseFailureCallback mBindingFailureCallback;
};

} // namespace AppPlatform
Expand Down
Loading

0 comments on commit 0996dc8

Please sign in to comment.