Skip to content

Commit

Permalink
[chip-tool] Support LIT ICD in chip-tool for subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Jan 30, 2024
1 parent d46f426 commit e4827b7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CHIP_ERROR ModelCommand::RunCommand()
}

ChipLogProgress(chipTool, "Sending command to node 0x%" PRIx64, mDestinationId);
CheckPeerICDType();

CommissioneeDeviceProxy * commissioneeDeviceProxy = nullptr;
if (CHIP_NO_ERROR == CurrentCommissioner().GetDeviceBeingCommissioned(mDestinationId, &commissioneeDeviceProxy))
Expand Down Expand Up @@ -73,3 +74,26 @@ void ModelCommand::Shutdown()

CHIPCommand::Shutdown();
}

void ModelCommand::CheckPeerICDType()
{
if (mIsPeerLITCLI.HasValue())
{
ChipLogProgress(chipTool, "Peer is ICD type set to %s", mIsPeerLITCLI.Value() == 1 ? "LIT-ICD" : "non LIT-ICD");
return;
}

app::ICDClientInfo info;
auto destinationPeerId = chip::ScopedNodeId(mDestinationId, CurrentCommissioner().GetFabricIndex());
auto iter = CHIPCommand::sICDClientStorage.IterateICDClientInfo();

while (iter->Next(info))
{
if (ScopedNodeId(info.peer_node.GetNodeId(), info.peer_node.GetFabricIndex()) == destinationPeerId)
{
ChipLogProgress(chipTool, "Peer is a registered LIT ICD.");
mIsPeerLITCLI.SetValue(true);
return;
}
}
}
6 changes: 6 additions & 0 deletions examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ModelCommand : public CHIPCommand
"Endpoint the command is targeted at.");
}
}
AddArgument("lit-icd-peer", 0, 1, &mIsPeerLITCLI,
"Whether to treat the peer as a LIT ICD. 0: Always no, 1: Always yes, (not set): Yes if the peer is registered "
"to this controller.");
AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
}

Expand All @@ -67,11 +70,14 @@ class ModelCommand : public CHIPCommand

protected:
chip::Optional<uint16_t> mTimeout;
chip::Optional<int> mIsPeerLITCLI;

private:
chip::NodeId mDestinationId;
std::vector<chip::EndpointId> mEndPointId;

void CheckPeerICDType();

static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr,
const chip::SessionHandle & sessionHandle);
static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
Expand Down
3 changes: 3 additions & 0 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class SubscribeAttribute : public SubscribeCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
SubscribeCommand::SetPeerLIT(mIsPeerLITCLI.ValueOr(0));
return SubscribeCommand::SubscribeAttribute(device, endpointIds, mClusterIds, mAttributeIds);
}

Expand Down Expand Up @@ -407,6 +408,7 @@ class SubscribeEvent : public SubscribeCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
SubscribeCommand::SetPeerLIT(mIsPeerLITCLI.ValueOr(0));
return SubscribeCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds);
}

Expand Down Expand Up @@ -538,6 +540,7 @@ class SubscribeAll : public SubscribeCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
SubscribeCommand::SetPeerLIT(mIsPeerLITCLI.ValueOr(0));
return SubscribeCommand::SubscribeAll(device, endpointIds, mClusterIds, mAttributeIds, mEventIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ CHIP_ERROR InteractionModelReports::ReportAttribute(DeviceProxy * device, std::v
{
params.mKeepSubscriptions = mKeepSubscriptions.Value();
}
params.mIsPeerLIT = mIsPeerLIT.ValueOr(false);
}

auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
Expand Down Expand Up @@ -479,6 +480,7 @@ CHIP_ERROR InteractionModelReports::ReportEvent(DeviceProxy * device, std::vecto
{
params.mKeepSubscriptions = mKeepSubscriptions.Value();
}
params.mIsPeerLIT = mIsPeerLIT.ValueOr(false);
}

auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
Expand Down Expand Up @@ -652,6 +654,7 @@ CHIP_ERROR InteractionModelReports::ReportAll(chip::DeviceProxy * device, std::v
{
params.mKeepSubscriptions = mKeepSubscriptions.Value();
}
params.mIsPeerLIT = mIsPeerLIT.ValueOr(false);
}

auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
Expand Down
14 changes: 14 additions & 0 deletions src/app/tests/suites/commands/interaction_model/InteractionModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ class InteractionModelReports
return *this;
}

InteractionModelReports & SetPeerLIT(bool isPeerLIT)
{
mIsPeerLIT.SetValue(isPeerLIT);
return *this;
}

InteractionModelReports & SetPeerLIT(const chip::Optional<bool> & isPeerLIT)
{
mIsPeerLIT = isPeerLIT;
return *this;
}

void ResetOptions()
{
mDataVersions = chip::NullOptional;
Expand All @@ -213,6 +225,7 @@ class InteractionModelReports
mFabricFiltered = chip::Optional<bool>(true);
mKeepSubscriptions = chip::NullOptional;
mAutoResubscribe = chip::NullOptional;
mIsPeerLIT = chip::NullOptional;
mMinInterval = 0;
mMaxInterval = 0;
}
Expand All @@ -223,6 +236,7 @@ class InteractionModelReports
chip::Optional<bool> mFabricFiltered;
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<bool> mAutoResubscribe;
chip::Optional<bool> mIsPeerLIT;
uint16_t mMinInterval;
uint16_t mMaxInterval;
};
Expand Down

0 comments on commit e4827b7

Please sign in to comment.