Skip to content

Commit

Permalink
[chip-tool] Add read-none/subscribe-none commands (#28327)
Browse files Browse the repository at this point in the history
* [chip-tool] Add read-none/subscribe-none commands

* Update __init__.py
  • Loading branch information
vivien-apple authored and pull[bot] committed Mar 20, 2024
1 parent 1516879 commit 2a15ff5
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 10 deletions.
23 changes: 13 additions & 10 deletions examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ class ModelCommand : public CHIPCommand
mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this), mSupportsMultipleEndpoints(supportsMultipleEndpoints)
{}

void AddArguments()
void AddArguments(bool skipEndpoints = false)
{
AddArgument(
"destination-id", 0, UINT64_MAX, &mDestinationId,
"64-bit node or group identifier.\n Group identifiers are detected by being in the 0xFFFF'FFFF'FFFF'xxxx range.");
if (mSupportsMultipleEndpoints)
if (skipEndpoints == false)
{
AddArgument("endpoint-ids", 0, UINT16_MAX, &mEndPointId,
"Comma-separated list of endpoint ids (e.g. \"1\" or \"1,2,3\").\n Allowed to be 0xFFFF to indicate a "
"wildcard endpoint.");
}
else
{
AddArgument("endpoint-id-ignored-for-group-commands", 0, UINT16_MAX, &mEndPointId,
"Endpoint the command is targeted at.");
if (mSupportsMultipleEndpoints)
{
AddArgument("endpoint-ids", 0, UINT16_MAX, &mEndPointId,
"Comma-separated list of endpoint ids (e.g. \"1\" or \"1,2,3\").\n Allowed to be 0xFFFF to indicate a "
"wildcard endpoint.");
}
else
{
AddArgument("endpoint-id-ignored-for-group-commands", 0, UINT16_MAX, &mEndPointId,
"Endpoint the command is targeted at.");
}
}
AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
}
Expand Down
52 changes: 52 additions & 0 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,33 @@ class SubscribeEvent : public SubscribeCommand
std::vector<chip::EventId> mEventIds;
};

class ReadNone : public ReadCommand
{
public:
ReadNone(CredentialIssuerCommands * credsIssuerConfig) : ReadCommand("read-none", credsIssuerConfig)
{
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered,
"Boolean indicating whether to do a fabric-filtered read. Defaults to true.");
AddArgument("data-versions", 0, UINT32_MAX, &mDataVersions,
"Comma-separated list of data versions for the clusters being read.");
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ReadCommand::AddArguments(true /* skipEndpoints */);
}

~ReadNone() {}

void OnDone(chip::app::ReadClient * aReadClient) override
{
InteractionModelReports::CleanupReadClient(aReadClient);
SetCommandExitStatus(mError);
}

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReadCommand::ReadNone(device);
}
};

class ReadAll : public ReadCommand
{
public:
Expand Down Expand Up @@ -456,6 +483,31 @@ class ReadAll : public ReadCommand
std::vector<chip::EventId> mEventIds;
};

class SubscribeNone : public SubscribeCommand
{
public:
SubscribeNone(CredentialIssuerCommands * credsIssuerConfig) : SubscribeCommand("subscribe-none", credsIssuerConfig)
{
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval,
"The requested minimum interval between reports. Sets MinIntervalFloor in the Subscribe Request.");
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval,
"The requested maximum interval between reports. Sets MaxIntervalCeiling in the Subscribe Request.");
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered,
"Boolean indicating whether to do a fabric-filtered read. Defaults to true.");
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions,
"false - Terminate existing subscriptions from initiator.\n true - Leave existing subscriptions in place.");
SubscribeCommand::AddArguments(true /* skipEndpoints */);
}

~SubscribeNone() {}

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return SubscribeCommand::SubscribeNone(device);
}
};

class SubscribeAll : public SubscribeCommand
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
'SubscribeById',
'ReadEventById',
'SubscribeEventById',
'ReadNone',
'ReadAll',
'SubscribeNone',
'SubscribeAll',
]

Expand Down Expand Up @@ -79,6 +81,9 @@
'EventId': 'event-id',
},
},
'ReadNone': {
'alias': 'read-none',
},
'ReadAll': {
'alias': 'read-all',
'arguments': {
Expand All @@ -87,6 +92,9 @@
'EventId': 'event-ids',
},
},
'SubscribeNone': {
'alias': 'subscribe-none',
},
'SubscribeAll': {
'alias': 'subscribe-all',
'arguments': {
Expand All @@ -99,6 +107,14 @@
},
'AnyCommands': {
'alias': 'any',
'commands': {
'ReadNone': {
'has_endpoint': False,
},
'SubscribeNone': {
'has_endpoint': False,
}
}
},
'CommissionerCommands': {
'alias': 'pairing',
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss
make_unique<SubscribeAttribute>(credsIssuerConfig), //
make_unique<ReadEvent>(credsIssuerConfig), //
make_unique<SubscribeEvent>(credsIssuerConfig), //
make_unique<ReadNone>(credsIssuerConfig), //
make_unique<ReadAll>(credsIssuerConfig), //
make_unique<SubscribeNone>(credsIssuerConfig), //
make_unique<SubscribeAll>(credsIssuerConfig), //
};

Expand Down
1 change: 1 addition & 0 deletions scripts/tests/chiptest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def _GetInDevelopmentTests() -> Set[str]:
"TestAttributesById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
"TestCommandsById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
"TestEventsById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
"TestReadNoneSubscribeNone.yaml", # chip-repl does not support AnyCommands (07/27/2023)
"Test_TC_DRLK_2_8.yaml", # Test fails only in chip-repl: Refer--> https://github.com/project-chip/connectedhomeip/pull/27011#issuecomment-1593339855
"Test_TC_ACE_1_6.yaml", # Test fails only in chip-repl: Refer--> https://github.com/project-chip/connectedhomeip/pull/27910#issuecomment-1632485584
"Test_TC_PSCFG_1_1.yaml", # Power source configuration cluster is deprecated and removed from all-clusters
Expand Down
40 changes: 40 additions & 0 deletions src/app/tests/suites/TestReadNoneSubscribeNone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: ReadNone/SuscribeNone Tests

config:
nodeId: 0x12344321
cluster: "Unit Testing"

tests:
- label: "Wait for the commissioned device to be retrieved"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Read Request Message with no paths."
cluster: "AnyCommands"
command: "ReadNone"

- label: "Subscribe Request Message with no paths."
cluster: "AnyCommands"
command: "SubscribeNone"
minInterval: 1
maxInterval: 2
response:
error: INVALID_ACTION
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,40 @@ void InteractionModelReports::CleanupReadClient(ReadClient * aReadClient)
mReadClients.end());
}

CHIP_ERROR InteractionModelReports::ReportNone(chip::DeviceProxy * device, chip::app::ReadClient::InteractionType interactionType)
{
AttributePathParams attributePathParams[kMaxAllowedPaths];
EventPathParams eventPathParams[kMaxAllowedPaths];

ReadPrepareParams params(device->GetSecureSession().Value());
params.mpEventPathParamsList = eventPathParams;
params.mEventPathParamsListSize = 0;
params.mEventNumber = mEventNumber;
params.mpAttributePathParamsList = attributePathParams;
params.mAttributePathParamsListSize = 0;

if (mFabricFiltered.HasValue())
{
params.mIsFabricFiltered = mFabricFiltered.Value();
}

if (interactionType == ReadClient::InteractionType::Subscribe)
{
params.mMinIntervalFloorSeconds = mMinInterval;
params.mMaxIntervalCeilingSeconds = mMaxInterval;
if (mKeepSubscriptions.HasValue())
{
params.mKeepSubscriptions = mKeepSubscriptions.Value();
}
}

auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
mBufferedReadAdapter, interactionType);
ReturnErrorOnFailure(client->SendRequest(params));
mReadClients.push_back(std::move(client));
return CHIP_NO_ERROR;
}

CHIP_ERROR InteractionModelReports::ReportAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
std::vector<chip::EventId> eventIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ class InteractionModelReports
std::vector<chip::ClusterId> clusterIds, std::vector<chip::EventId> eventIds,
chip::app::ReadClient::InteractionType interactionType);

CHIP_ERROR ReadNone(chip::DeviceProxy * device) { return ReportNone(device, chip::app::ReadClient::InteractionType::Read); }

CHIP_ERROR ReadAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
std::vector<chip::EventId> eventIds)
{
return ReportAll(device, endpointIds, clusterIds, attributeIds, eventIds, chip::app::ReadClient::InteractionType::Read);
}

CHIP_ERROR SubscribeNone(chip::DeviceProxy * device)
{
return ReportNone(device, chip::app::ReadClient::InteractionType::Subscribe);
}

CHIP_ERROR SubscribeAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
std::vector<chip::EventId> eventIds)
Expand All @@ -105,6 +112,8 @@ class InteractionModelReports
chip::app::ReadClient::InteractionType::Subscribe);
}

CHIP_ERROR ReportNone(chip::DeviceProxy * device, chip::app::ReadClient::InteractionType interactionType);

CHIP_ERROR ReportAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
std::vector<chip::EventId> eventIds, chip::app::ReadClient::InteractionType interactionType);
Expand Down
2 changes: 2 additions & 0 deletions zzz_generated/chip-tool/zap-generated/cluster/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a15ff5

Please sign in to comment.