Skip to content

Commit bf1679e

Browse files
authored
Merge branch 'master' into feature/fix-cdc-passcode-cancel
2 parents 0033a12 + c91a779 commit bf1679e

File tree

8 files changed

+865
-13
lines changed

8 files changed

+865
-13
lines changed

.github/workflows/tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ jobs:
577577
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_RVCOPSTATE_2_3.py'
578578
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_RVCOPSTATE_2_4.py'
579579
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_SC_7_1.py'
580+
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_SWTCH.py'
580581
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestConformanceSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
581582
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestMatterTestingSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
582583
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestSpecParsingSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'

examples/all-clusters-app/linux/AllClustersCommandDelegate.cpp

+151
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <app/util/attribute-storage.h>
2929
#include <platform/PlatformManager.h>
3030

31+
#include "ButtonEventsSimulator.h"
3132
#include <air-quality-instance.h>
3233
#include <dishwasher-mode.h>
3334
#include <laundry-washer-mode.h>
@@ -36,13 +37,155 @@
3637
#include <oven-operational-state-delegate.h>
3738
#include <rvc-modes.h>
3839

40+
#include <memory>
3941
#include <string>
42+
#include <utility>
4043

4144
using namespace chip;
4245
using namespace chip::app;
4346
using namespace chip::app::Clusters;
4447
using namespace chip::DeviceLayer;
4548

49+
namespace {
50+
51+
std::unique_ptr<ButtonEventsSimulator> sButtonSimulatorInstance{ nullptr };
52+
53+
bool HasNumericField(Json::Value & jsonValue, const std::string & field)
54+
{
55+
return jsonValue.isMember(field) && jsonValue[field].isNumeric();
56+
}
57+
58+
/**
59+
* Named pipe handler for simulated long press on an action switch.
60+
*
61+
* Usage example:
62+
* echo '{"Name": "SimulateActionSwitchLongPress", "EndpointId": 3, "ButtonId": 1, "LongPressDelayMillis": 800,
63+
* "LongPressDurationMillis": 1000}' > /tmp/chip_all_clusters_fifo_1146610
64+
*
65+
* JSON Arguments:
66+
* - "Name": Must be "SimulateActionSwitchLongPress"
67+
* - "EndpointId": number of endpoint having a switch cluster
68+
* - "ButtonId": switch position in the switch cluster for "down" button (not idle)
69+
* - "LongPressDelayMillis": Time in milliseconds before the LongPress
70+
* - "LongPressDurationMillis": Total duration in milliseconds from start of the press to LongRelease
71+
*
72+
* @param jsonValue - JSON payload from named pipe
73+
*/
74+
void HandleSimulateActionSwitchLongPress(Json::Value & jsonValue)
75+
{
76+
if (sButtonSimulatorInstance != nullptr)
77+
{
78+
ChipLogError(NotSpecified, "Button simulation already in progress! Ignoring request.");
79+
return;
80+
}
81+
82+
bool hasEndpointId = HasNumericField(jsonValue, "EndpointId");
83+
bool hasButtonId = HasNumericField(jsonValue, "ButtonId");
84+
bool hasLongPressDelayMillis = HasNumericField(jsonValue, "LongPressDelayMillis");
85+
bool hasLongPressDurationMillis = HasNumericField(jsonValue, "LongPressDurationMillis");
86+
if (!hasEndpointId || !hasButtonId || !hasLongPressDelayMillis || !hasLongPressDurationMillis)
87+
{
88+
std::string inputJson = jsonValue.toStyledString();
89+
ChipLogError(
90+
NotSpecified,
91+
"Missing or invalid value for one of EndpointId, ButtonId, LongPressDelayMillis or LongPressDurationMillis in %s",
92+
inputJson.c_str());
93+
return;
94+
}
95+
96+
EndpointId endpointId = static_cast<EndpointId>(jsonValue["EndpointId"].asUInt());
97+
uint8_t buttonId = static_cast<uint8_t>(jsonValue["ButtonId"].asUInt());
98+
System::Clock::Milliseconds32 longPressDelayMillis{ static_cast<unsigned>(jsonValue["LongPressDelayMillis"].asUInt()) };
99+
System::Clock::Milliseconds32 longPressDurationMillis{ static_cast<unsigned>(jsonValue["LongPressDurationMillis"].asUInt()) };
100+
auto buttonSimulator = std::make_unique<ButtonEventsSimulator>();
101+
102+
bool success = buttonSimulator->SetMode(ButtonEventsSimulator::Mode::kModeLongPress)
103+
.SetLongPressDelayMillis(longPressDelayMillis)
104+
.SetLongPressDurationMillis(longPressDurationMillis)
105+
.SetIdleButtonId(0)
106+
.SetPressedButtonId(buttonId)
107+
.SetEndpointId(endpointId)
108+
.Execute([]() { sButtonSimulatorInstance.reset(); });
109+
110+
if (!success)
111+
{
112+
ChipLogError(NotSpecified, "Failed to start execution of button simulator!");
113+
return;
114+
}
115+
116+
sButtonSimulatorInstance = std::move(buttonSimulator);
117+
}
118+
119+
/**
120+
* Named pipe handler for simulated multi-press on an action switch.
121+
*
122+
* Usage example:
123+
* echo '{"Name": "SimulateActionSwitchMultiPress", "EndpointId": 3, "ButtonId": 1, "MultiPressPressedTimeMillis": 100,
124+
* "MultiPressReleasedTimeMillis": 350, "MultiPressNumPresses": 2}' > /tmp/chip_all_clusters_fifo_1146610
125+
*
126+
* JSON Arguments:
127+
* - "Name": Must be "SimulateActionSwitchMultiPress"
128+
* - "EndpointId": number of endpoint having a switch cluster
129+
* - "ButtonId": switch position in the switch cluster for "down" button (not idle)
130+
* - "MultiPressPressedTimeMillis": Pressed time in milliseconds for each press
131+
* - "MultiPressReleasedTimeMillis": Released time in milliseconds after each press
132+
* - "MultiPressNumPresses": Number of presses to simulate
133+
*
134+
* @param jsonValue - JSON payload from named pipe
135+
*/
136+
void HandleSimulateActionSwitchMultiPress(Json::Value & jsonValue)
137+
{
138+
if (sButtonSimulatorInstance != nullptr)
139+
{
140+
ChipLogError(NotSpecified, "Button simulation already in progress! Ignoring request.");
141+
return;
142+
}
143+
144+
bool hasEndpointId = HasNumericField(jsonValue, "EndpointId");
145+
bool hasButtonId = HasNumericField(jsonValue, "ButtonId");
146+
bool hasMultiPressPressedTimeMillis = HasNumericField(jsonValue, "MultiPressPressedTimeMillis");
147+
bool hasMultiPressReleasedTimeMillis = HasNumericField(jsonValue, "MultiPressReleasedTimeMillis");
148+
bool hasMultiPressNumPresses = HasNumericField(jsonValue, "MultiPressNumPresses");
149+
if (!hasEndpointId || !hasButtonId || !hasMultiPressPressedTimeMillis || !hasMultiPressReleasedTimeMillis ||
150+
!hasMultiPressNumPresses)
151+
{
152+
std::string inputJson = jsonValue.toStyledString();
153+
ChipLogError(NotSpecified,
154+
"Missing or invalid value for one of EndpointId, ButtonId, MultiPressPressedTimeMillis, "
155+
"MultiPressReleasedTimeMillis or MultiPressNumPresses in %s",
156+
inputJson.c_str());
157+
return;
158+
}
159+
160+
EndpointId endpointId = static_cast<EndpointId>(jsonValue["EndpointId"].asUInt());
161+
uint8_t buttonId = static_cast<uint8_t>(jsonValue["ButtonId"].asUInt());
162+
System::Clock::Milliseconds32 multiPressPressedTimeMillis{ static_cast<unsigned>(
163+
jsonValue["MultiPressPressedTimeMillis"].asUInt()) };
164+
System::Clock::Milliseconds32 multiPressReleasedTimeMillis{ static_cast<unsigned>(
165+
jsonValue["MultiPressReleasedTimeMillis"].asUInt()) };
166+
uint8_t multiPressNumPresses = static_cast<uint8_t>(jsonValue["MultiPressNumPresses"].asUInt());
167+
auto buttonSimulator = std::make_unique<ButtonEventsSimulator>();
168+
169+
bool success = buttonSimulator->SetMode(ButtonEventsSimulator::Mode::kModeMultiPress)
170+
.SetMultiPressPressedTimeMillis(multiPressPressedTimeMillis)
171+
.SetMultiPressReleasedTimeMillis(multiPressReleasedTimeMillis)
172+
.SetMultiPressNumPresses(multiPressNumPresses)
173+
.SetIdleButtonId(0)
174+
.SetPressedButtonId(buttonId)
175+
.SetEndpointId(endpointId)
176+
.Execute([]() { sButtonSimulatorInstance.reset(); });
177+
178+
if (!success)
179+
{
180+
ChipLogError(NotSpecified, "Failed to start execution of button simulator!");
181+
return;
182+
}
183+
184+
sButtonSimulatorInstance = std::move(buttonSimulator);
185+
}
186+
187+
} // namespace
188+
46189
AllClustersAppCommandHandler * AllClustersAppCommandHandler::FromJSON(const char * json)
47190
{
48191
Json::Reader reader;
@@ -190,6 +333,14 @@ void AllClustersAppCommandHandler::HandleCommand(intptr_t context)
190333
std::string operation = self->mJsonValue["Operation"].asString();
191334
self->OnOperationalStateChange(device, operation, self->mJsonValue["Param"]);
192335
}
336+
else if (name == "SimulateActionSwitchLongPress")
337+
{
338+
HandleSimulateActionSwitchLongPress(self->mJsonValue);
339+
}
340+
else if (name == "SimulateActionSwitchMultiPress")
341+
{
342+
HandleSimulateActionSwitchMultiPress(self->mJsonValue);
343+
}
193344
else
194345
{
195346
ChipLogError(NotSpecified, "Unhandled command: Should never happens");

examples/all-clusters-app/linux/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ source_set("chip-all-clusters-common") {
6666
"${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp",
6767
"${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp",
6868
"AllClustersCommandDelegate.cpp",
69+
"AllClustersCommandDelegate.h",
6970
"AppOptions.cpp",
71+
"ButtonEventsSimulator.cpp",
72+
"ButtonEventsSimulator.h",
7073
"ValveControlDelegate.cpp",
7174
"WindowCoveringManager.cpp",
7275
"include/tv-callbacks.cpp",

0 commit comments

Comments
 (0)