Skip to content

Commit a406232

Browse files
authored
[chip-tool] Add read-none/subscribe-none commands (#28327)
* [chip-tool] Add read-none/subscribe-none commands * Update __init__.py
1 parent 5ac89df commit a406232

9 files changed

Lines changed: 169 additions & 10 deletions

File tree

examples/chip-tool/commands/clusters/ModelCommand.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ class ModelCommand : public CHIPCommand
3333
mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this), mSupportsMultipleEndpoints(supportsMultipleEndpoints)
3434
{}
3535

36-
void AddArguments()
36+
void AddArguments(bool skipEndpoints = false)
3737
{
3838
AddArgument(
3939
"destination-id", 0, UINT64_MAX, &mDestinationId,
4040
"64-bit node or group identifier.\n Group identifiers are detected by being in the 0xFFFF'FFFF'FFFF'xxxx range.");
41-
if (mSupportsMultipleEndpoints)
41+
if (skipEndpoints == false)
4242
{
43-
AddArgument("endpoint-ids", 0, UINT16_MAX, &mEndPointId,
44-
"Comma-separated list of endpoint ids (e.g. \"1\" or \"1,2,3\").\n Allowed to be 0xFFFF to indicate a "
45-
"wildcard endpoint.");
46-
}
47-
else
48-
{
49-
AddArgument("endpoint-id-ignored-for-group-commands", 0, UINT16_MAX, &mEndPointId,
50-
"Endpoint the command is targeted at.");
43+
if (mSupportsMultipleEndpoints)
44+
{
45+
AddArgument("endpoint-ids", 0, UINT16_MAX, &mEndPointId,
46+
"Comma-separated list of endpoint ids (e.g. \"1\" or \"1,2,3\").\n Allowed to be 0xFFFF to indicate a "
47+
"wildcard endpoint.");
48+
}
49+
else
50+
{
51+
AddArgument("endpoint-id-ignored-for-group-commands", 0, UINT16_MAX, &mEndPointId,
52+
"Endpoint the command is targeted at.");
53+
}
5154
}
5255
AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
5356
}

examples/chip-tool/commands/clusters/ReportCommand.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,33 @@ class SubscribeEvent : public SubscribeCommand
415415
std::vector<chip::EventId> mEventIds;
416416
};
417417

418+
class ReadNone : public ReadCommand
419+
{
420+
public:
421+
ReadNone(CredentialIssuerCommands * credsIssuerConfig) : ReadCommand("read-none", credsIssuerConfig)
422+
{
423+
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered,
424+
"Boolean indicating whether to do a fabric-filtered read. Defaults to true.");
425+
AddArgument("data-versions", 0, UINT32_MAX, &mDataVersions,
426+
"Comma-separated list of data versions for the clusters being read.");
427+
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
428+
ReadCommand::AddArguments(true /* skipEndpoints */);
429+
}
430+
431+
~ReadNone() {}
432+
433+
void OnDone(chip::app::ReadClient * aReadClient) override
434+
{
435+
InteractionModelReports::CleanupReadClient(aReadClient);
436+
SetCommandExitStatus(mError);
437+
}
438+
439+
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
440+
{
441+
return ReadCommand::ReadNone(device);
442+
}
443+
};
444+
418445
class ReadAll : public ReadCommand
419446
{
420447
public:
@@ -456,6 +483,31 @@ class ReadAll : public ReadCommand
456483
std::vector<chip::EventId> mEventIds;
457484
};
458485

486+
class SubscribeNone : public SubscribeCommand
487+
{
488+
public:
489+
SubscribeNone(CredentialIssuerCommands * credsIssuerConfig) : SubscribeCommand("subscribe-none", credsIssuerConfig)
490+
{
491+
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval,
492+
"The requested minimum interval between reports. Sets MinIntervalFloor in the Subscribe Request.");
493+
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval,
494+
"The requested maximum interval between reports. Sets MaxIntervalCeiling in the Subscribe Request.");
495+
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered,
496+
"Boolean indicating whether to do a fabric-filtered read. Defaults to true.");
497+
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
498+
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions,
499+
"false - Terminate existing subscriptions from initiator.\n true - Leave existing subscriptions in place.");
500+
SubscribeCommand::AddArguments(true /* skipEndpoints */);
501+
}
502+
503+
~SubscribeNone() {}
504+
505+
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
506+
{
507+
return SubscribeCommand::SubscribeNone(device);
508+
}
509+
};
510+
459511
class SubscribeAll : public SubscribeCommand
460512
{
461513
public:

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/encoder.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
'SubscribeById',
2323
'ReadEventById',
2424
'SubscribeEventById',
25+
'ReadNone',
2526
'ReadAll',
27+
'SubscribeNone',
2628
'SubscribeAll',
2729
]
2830

@@ -79,6 +81,9 @@
7981
'EventId': 'event-id',
8082
},
8183
},
84+
'ReadNone': {
85+
'alias': 'read-none',
86+
},
8287
'ReadAll': {
8388
'alias': 'read-all',
8489
'arguments': {
@@ -87,6 +92,9 @@
8792
'EventId': 'event-ids',
8893
},
8994
},
95+
'SubscribeNone': {
96+
'alias': 'subscribe-none',
97+
},
9098
'SubscribeAll': {
9199
'alias': 'subscribe-all',
92100
'arguments': {
@@ -99,6 +107,14 @@
99107
},
100108
'AnyCommands': {
101109
'alias': 'any',
110+
'commands': {
111+
'ReadNone': {
112+
'has_endpoint': False,
113+
},
114+
'SubscribeNone': {
115+
'has_endpoint': False,
116+
}
117+
}
102118
},
103119
'CommissionerCommands': {
104120
'alias': 'pairing',

examples/chip-tool/templates/commands.zapt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss
132132
make_unique<SubscribeAttribute>(credsIssuerConfig), //
133133
make_unique<ReadEvent>(credsIssuerConfig), //
134134
make_unique<SubscribeEvent>(credsIssuerConfig), //
135+
make_unique<ReadNone>(credsIssuerConfig), //
135136
make_unique<ReadAll>(credsIssuerConfig), //
137+
make_unique<SubscribeNone>(credsIssuerConfig), //
136138
make_unique<SubscribeAll>(credsIssuerConfig), //
137139
};
138140

scripts/tests/chiptest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def _GetInDevelopmentTests() -> Set[str]:
138138
"TestAttributesById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
139139
"TestCommandsById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
140140
"TestEventsById.yaml", # chip-repl does not support AnyCommands (06/06/2023)
141+
"TestReadNoneSubscribeNone.yaml", # chip-repl does not support AnyCommands (07/27/2023)
141142
"Test_TC_DRLK_2_8.yaml", # Test fails only in chip-repl: Refer--> https://github.com/project-chip/connectedhomeip/pull/27011#issuecomment-1593339855
142143
"Test_TC_ACE_1_6.yaml", # Test fails only in chip-repl: Refer--> https://github.com/project-chip/connectedhomeip/pull/27910#issuecomment-1632485584
143144
"Test_TC_PSCFG_1_1.yaml", # Power source configuration cluster is deprecated and removed from all-clusters
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: ReadNone/SuscribeNone Tests
16+
17+
config:
18+
nodeId: 0x12344321
19+
cluster: "Unit Testing"
20+
21+
tests:
22+
- label: "Wait for the commissioned device to be retrieved"
23+
cluster: "DelayCommands"
24+
command: "WaitForCommissionee"
25+
arguments:
26+
values:
27+
- name: "nodeId"
28+
value: nodeId
29+
30+
- label: "Read Request Message with no paths."
31+
cluster: "AnyCommands"
32+
command: "ReadNone"
33+
34+
- label: "Subscribe Request Message with no paths."
35+
cluster: "AnyCommands"
36+
command: "SubscribeNone"
37+
minInterval: 1
38+
maxInterval: 2
39+
response:
40+
error: INVALID_ACTION

src/app/tests/suites/commands/interaction_model/InteractionModel.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,40 @@ void InteractionModelReports::CleanupReadClient(ReadClient * aReadClient)
503503
mReadClients.end());
504504
}
505505

506+
CHIP_ERROR InteractionModelReports::ReportNone(chip::DeviceProxy * device, chip::app::ReadClient::InteractionType interactionType)
507+
{
508+
AttributePathParams attributePathParams[kMaxAllowedPaths];
509+
EventPathParams eventPathParams[kMaxAllowedPaths];
510+
511+
ReadPrepareParams params(device->GetSecureSession().Value());
512+
params.mpEventPathParamsList = eventPathParams;
513+
params.mEventPathParamsListSize = 0;
514+
params.mEventNumber = mEventNumber;
515+
params.mpAttributePathParamsList = attributePathParams;
516+
params.mAttributePathParamsListSize = 0;
517+
518+
if (mFabricFiltered.HasValue())
519+
{
520+
params.mIsFabricFiltered = mFabricFiltered.Value();
521+
}
522+
523+
if (interactionType == ReadClient::InteractionType::Subscribe)
524+
{
525+
params.mMinIntervalFloorSeconds = mMinInterval;
526+
params.mMaxIntervalCeilingSeconds = mMaxInterval;
527+
if (mKeepSubscriptions.HasValue())
528+
{
529+
params.mKeepSubscriptions = mKeepSubscriptions.Value();
530+
}
531+
}
532+
533+
auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
534+
mBufferedReadAdapter, interactionType);
535+
ReturnErrorOnFailure(client->SendRequest(params));
536+
mReadClients.push_back(std::move(client));
537+
return CHIP_NO_ERROR;
538+
}
539+
506540
CHIP_ERROR InteractionModelReports::ReportAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
507541
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
508542
std::vector<chip::EventId> eventIds,

src/app/tests/suites/commands/interaction_model/InteractionModel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,20 @@ class InteractionModelReports
9090
std::vector<chip::ClusterId> clusterIds, std::vector<chip::EventId> eventIds,
9191
chip::app::ReadClient::InteractionType interactionType);
9292

93+
CHIP_ERROR ReadNone(chip::DeviceProxy * device) { return ReportNone(device, chip::app::ReadClient::InteractionType::Read); }
94+
9395
CHIP_ERROR ReadAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
9496
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
9597
std::vector<chip::EventId> eventIds)
9698
{
9799
return ReportAll(device, endpointIds, clusterIds, attributeIds, eventIds, chip::app::ReadClient::InteractionType::Read);
98100
}
99101

102+
CHIP_ERROR SubscribeNone(chip::DeviceProxy * device)
103+
{
104+
return ReportNone(device, chip::app::ReadClient::InteractionType::Subscribe);
105+
}
106+
100107
CHIP_ERROR SubscribeAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
101108
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
102109
std::vector<chip::EventId> eventIds)
@@ -105,6 +112,8 @@ class InteractionModelReports
105112
chip::app::ReadClient::InteractionType::Subscribe);
106113
}
107114

115+
CHIP_ERROR ReportNone(chip::DeviceProxy * device, chip::app::ReadClient::InteractionType interactionType);
116+
108117
CHIP_ERROR ReportAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
109118
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds,
110119
std::vector<chip::EventId> eventIds, chip::app::ReadClient::InteractionType interactionType);

zzz_generated/chip-tool/zap-generated/cluster/Commands.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)