Skip to content

Commit 1b5ddd2

Browse files
chulspros-gattiyufengwangca
authored
[Camera] Adds interactive server support for camera-controller (project-chip#38316)
* Adds interactive server support for camera-controller Signed-off-by: s-gatti <s.gatti@samsung.com> * Adds interactive server support for camera-controller This PR adds interactive server support for matter camera controller. Signed-off-by: Sathvik K Gatti <s.gatti@samsung.com> Signed-off-by: Charles Kim <chulspro.kim@samsung.com> * Update examples/camera-controller/commands/delay/WaitForCommissioneeCommand.h Co-authored-by: Yufeng Wang <yufengwang@google.com> * Update examples/camera-controller/commands/delay/WaitForCommissioneeCommand.cpp Co-authored-by: Yufeng Wang <yufengwang@google.com> * Update examples/camera-controller/commands/delay/SleepCommand.h Co-authored-by: Yufeng Wang <yufengwang@google.com> * Update examples/camera-controller/commands/delay/SleepCommand.cpp Co-authored-by: Yufeng Wang <yufengwang@google.com> * Update examples/camera-controller/commands/delay/Commands.h Co-authored-by: Yufeng Wang <yufengwang@google.com> Signed-off-by: Charles Kim <chulspro.kim@samsung.com> * camera-controller: remove duplicated function Signed-off-by: Charles Kim <chulspro.kim@samsung.com> * camera-controller: fix restyled error Signed-off-by: Charles Kim <chulspro.kim@samsung.com> --------- Signed-off-by: s-gatti <s.gatti@samsung.com> Signed-off-by: Sathvik K Gatti <s.gatti@samsung.com> Signed-off-by: Charles Kim <chulspro.kim@samsung.com> Co-authored-by: s-gatti <s.gatti@samsung.com> Co-authored-by: Yufeng Wang <yufengwang@google.com>
1 parent 574cc67 commit 1b5ddd2

10 files changed

Lines changed: 504 additions & 0 deletions

File tree

examples/camera-controller/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ static_library("camera-controller-utils") {
6868
"commands/common/HexConversion.h",
6969
"commands/common/RemoteDataModelLogger.cpp",
7070
"commands/common/RemoteDataModelLogger.h",
71+
"commands/delay/SleepCommand.cpp",
72+
"commands/delay/WaitForCommissioneeCommand.cpp",
7173
"commands/pairing/OpenCommissioningWindowCommand.cpp",
7274
"commands/pairing/OpenCommissioningWindowCommand.h",
7375
"commands/pairing/PairingCommand.cpp",
@@ -86,6 +88,7 @@ static_library("camera-controller-utils") {
8688

8789
sources += [ "commands/interactive/InteractiveCommands.cpp" ]
8890
deps += [
91+
"${chip_root}/examples/common/websocket-server",
8992
"${chip_root}/src/platform/logging:headers",
9093
"${editline_root}:editline",
9194
]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include "commands/common/Commands.h"
22+
#include "commands/delay/SleepCommand.h"
23+
#include "commands/delay/WaitForCommissioneeCommand.h"
24+
25+
void registerCommandsDelay(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
26+
{
27+
const char * clusterName = "Delay";
28+
commands_list clusterCommands = {
29+
make_unique<SleepCommand>(credsIssuerConfig), //
30+
make_unique<WaitForCommissioneeCommand>(credsIssuerConfig), //
31+
};
32+
33+
commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for waiting for something to happen.");
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#include "SleepCommand.h"
20+
#include <chrono>
21+
#include <thread>
22+
23+
CHIP_ERROR SleepCommand::RunCommand()
24+
{
25+
std::this_thread::sleep_for(std::chrono::milliseconds(mDurationInMs));
26+
SetCommandExitStatus(CHIP_NO_ERROR);
27+
return CHIP_NO_ERROR;
28+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include "../common/CHIPCommand.h"
22+
23+
/**
24+
* This command blocks the event loop processing for a given amount of time.
25+
*
26+
* For example when the event loop is blocked the messages coming-in will not be acked,
27+
* forcing a retransmission on the other side.
28+
*
29+
*/
30+
31+
class SleepCommand : public CHIPCommand
32+
{
33+
public:
34+
SleepCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("sleep", credIssuerCommands)
35+
{
36+
AddArgument("duration-in-ms", 0, UINT32_MAX, &mDurationInMs,
37+
"Block the event loop processing for duration-in-ms milliseconds.");
38+
}
39+
40+
/////////// CHIPCommand Interface /////////
41+
CHIP_ERROR RunCommand() override;
42+
chip::System::Clock::Timeout GetWaitDuration() const override
43+
{
44+
// The allowed duration of this method is at least as long as the time specified for blocking the
45+
// event loop. In order to not fail on some small delays in processing some extra time before
46+
// failing is added.
47+
constexpr uint16_t mExtraTimeForFailure = 1000;
48+
49+
return chip::System::Clock::Milliseconds32(mDurationInMs + mExtraTimeForFailure);
50+
}
51+
52+
private:
53+
uint32_t mDurationInMs;
54+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#include "WaitForCommissioneeCommand.h"
20+
21+
using namespace chip;
22+
23+
CHIP_ERROR WaitForCommissioneeCommand::RunCommand()
24+
{
25+
chip::FabricIndex fabricIndex = CurrentCommissioner().GetFabricIndex();
26+
VerifyOrReturnError(fabricIndex != chip::kUndefinedFabricIndex, CHIP_ERROR_INCORRECT_STATE);
27+
28+
if (mExpireExistingSession.ValueOr(true))
29+
{
30+
CurrentCommissioner().SessionMgr()->ExpireAllSessions(chip::ScopedNodeId(mNodeId, fabricIndex));
31+
}
32+
33+
return CurrentCommissioner().GetConnectedDevice(mNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
34+
}
35+
36+
void WaitForCommissioneeCommand::OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr,
37+
const SessionHandle & sessionHandle)
38+
{
39+
auto * command = reinterpret_cast<WaitForCommissioneeCommand *>(context);
40+
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnDeviceConnectedFn: context is null"));
41+
command->SetCommandExitStatus(CHIP_NO_ERROR);
42+
}
43+
44+
void WaitForCommissioneeCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR err)
45+
{
46+
LogErrorOnFailure(err);
47+
48+
auto * command = reinterpret_cast<WaitForCommissioneeCommand *>(context);
49+
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnDeviceConnectionFailureFn: context is null"));
50+
command->SetCommandExitStatus(err);
51+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include "../common/CHIPCommand.h"
22+
#include <app/OperationalSessionSetup.h>
23+
#include <lib/core/CHIPCallback.h>
24+
25+
class WaitForCommissioneeCommand : public CHIPCommand
26+
{
27+
public:
28+
WaitForCommissioneeCommand(CredentialIssuerCommands * credIssuerCommands) :
29+
CHIPCommand("wait-for-commissionee", credIssuerCommands, "Establish a CASE session to the provided node id."),
30+
mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this)
31+
{
32+
AddArgument("nodeId", 0, UINT64_MAX, &mNodeId);
33+
AddArgument("expire-existing-session", 0, 1, &mExpireExistingSession);
34+
AddArgument("timeout", 0, UINT64_MAX, &mTimeoutSecs,
35+
"Time, in seconds, before this command is considered to have timed out.");
36+
}
37+
38+
/////////// CHIPCommand Interface /////////
39+
CHIP_ERROR RunCommand() override;
40+
chip::System::Clock::Timeout GetWaitDuration() const override
41+
{
42+
return chip::System::Clock::Seconds16(mTimeoutSecs.ValueOr(10));
43+
}
44+
45+
private:
46+
chip::NodeId mNodeId;
47+
chip::Optional<uint16_t> mTimeoutSecs;
48+
chip::Optional<bool> mExpireExistingSession;
49+
50+
static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr,
51+
const chip::SessionHandle & sessionHandle);
52+
static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
53+
54+
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
55+
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
56+
};

examples/camera-controller/commands/interactive/Commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void registerCommandsInteractive(Commands & commands, CredentialIssuerCommands *
2828

2929
commands_list clusterCommands = {
3030
make_unique<InteractiveStartCommand>(&commands, credsIssuerConfig),
31+
make_unique<InteractiveServerCommand>(&commands, credsIssuerConfig),
3132
};
3233

3334
commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for starting long-lived interactive modes.");

0 commit comments

Comments
 (0)