Skip to content

Commit a9accd7

Browse files
samples: matter: Add "list" command to bridge shell
The new command lists all bridged devices that are registered in the device. - Disabled LTO and minimal SHELL for nRF54LM20 to improve user experience. Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent a94a14a commit a9accd7

File tree

7 files changed

+101
-5
lines changed

7 files changed

+101
-5
lines changed

applications/matter_bridge/boards/nrf5340dk_nrf5340_cpuapp.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ CONFIG_BT_MAX_PAIRED=9
2222
CONFIG_BRIDGE_MAX_DYNAMIC_ENDPOINTS_NUMBER=18
2323
# 15.4 RX buffers were decreased to save RAM
2424
CONFIG_NRF_802154_RX_BUFFERS=14
25+
26+
# Enable LTO to decrease the flash usage.
27+
CONFIG_LTO=y
28+
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y

applications/matter_bridge/boards/nrf54lm20dk_nrf54lm20a_cpuapp.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ CONFIG_BT_MAX_PAIRED=9
2323

2424
# Assume that every bridged device uses two endpoints, however it can be increased if specific use case requires it.
2525
CONFIG_BRIDGE_MAX_DYNAMIC_ENDPOINTS_NUMBER=18
26+
27+
# Enable full SHELL support to improve user experience
28+
CONFIG_SHELL_MINIMAL=n
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
# Enable LTO to decrease the flash usage.
8+
CONFIG_LTO=y
9+
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y

applications/matter_bridge/prj.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,5 @@ CONFIG_USE_SEGGER_RTT=n
5353
CONFIG_CHIP_FACTORY_DATA=y
5454
CONFIG_CHIP_FACTORY_DATA_BUILD=y
5555

56-
# Enable LTO to decrease the flash usage.
57-
CONFIG_LTO=y
58-
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
59-
6056
# Increase heap size to accommodate the memory required for additional bridged devices.
6157
CONFIG_CHIP_MALLOC_SYS_HEAP_SIZE=16384

applications/matter_bridge/src/bridge_shell.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ static int AddBridgedDeviceHandler(const struct shell *shell, size_t argc, char
6464
CHIP_NO_ERROR) {
6565
shell_fprintf(shell, SHELL_ERROR, "Invalid Bluetooth LE device index.\n");
6666
} else {
67-
shell_fprintf(shell, SHELL_ERROR, "Found device address\n");
67+
shell_fprintf(shell, SHELL_INFO, "Found device address: %02x:%02x:%02x:%02x:%02x:%02x\n",
68+
address.a.val[5], address.a.val[4], address.a.val[3], address.a.val[2], address.a.val[1],
69+
address.a.val[0]);
6870
}
6971

7072
uint16_t uuid;
@@ -125,6 +127,63 @@ static int RemoveBridgedDeviceHandler(const struct shell *shell, size_t argc, ch
125127
return 0;
126128
}
127129

130+
static const char *GetDeviceTypeString(uint16_t deviceType)
131+
{
132+
using DeviceType = Nrf::MatterBridgedDevice::DeviceType;
133+
switch (deviceType) {
134+
case DeviceType::BridgedNode:
135+
return "BridgedNode (0x0013)";
136+
case DeviceType::OnOffLight:
137+
return "OnOffLight (0x0100)";
138+
case DeviceType::OnOffLightSwitch:
139+
return "OnOffLightSwitch (0x0103)";
140+
case DeviceType::TemperatureSensor:
141+
return "TemperatureSensor (0x0302)";
142+
case DeviceType::HumiditySensor:
143+
return "HumiditySensor (0x0307)";
144+
case DeviceType::GenericSwitch:
145+
return "GenericSwitch (0x000F)";
146+
default:
147+
return "Unknown";
148+
}
149+
}
150+
151+
static int ListBridgedDevicesHandler(const struct shell *shell, size_t argc, char **argv)
152+
{
153+
shell_fprintf(shell, SHELL_INFO, "Bridged devices list:\n");
154+
shell_fprintf(shell, SHELL_INFO, "---------------------------------------------------------------------\n");
155+
shell_fprintf(shell, SHELL_INFO, "| Endpoint ID | Name | Type \n");
156+
shell_fprintf(shell, SHELL_INFO, "---------------------------------------------------------------------\n");
157+
158+
uint8_t count = 0;
159+
constexpr uint16_t kMaxEndpointId = CONFIG_BRIDGE_MAX_DYNAMIC_ENDPOINTS_NUMBER;
160+
161+
for (chip::EndpointId endpointId = 1; endpointId <= kMaxEndpointId; endpointId++) {
162+
uint16_t deviceType = 0;
163+
auto *provider = Nrf::BridgeManager().Instance().GetProvider(endpointId, deviceType);
164+
165+
if (provider != nullptr) {
166+
const char *nodeLabel = Nrf::BridgeManager().Instance().GetNodeLabel(endpointId);
167+
if (!nodeLabel || strnlen(nodeLabel, Nrf::MatterBridgedDevice::kNodeLabelSize) == 0) {
168+
nodeLabel = "(no label)";
169+
}
170+
171+
shell_fprintf(shell, SHELL_INFO, "| %-11d | %-18s | %-24s\n", endpointId, nodeLabel,
172+
GetDeviceTypeString(deviceType));
173+
count++;
174+
}
175+
}
176+
177+
if (count == 0) {
178+
shell_fprintf(shell, SHELL_INFO, "| No bridged devices found |\n");
179+
}
180+
181+
shell_fprintf(shell, SHELL_INFO, "---------------------------------------------------------------------\n");
182+
shell_fprintf(shell, SHELL_INFO, "Total: %d device(s)\n", count);
183+
184+
return 0;
185+
}
186+
128187
#ifdef CONFIG_BRIDGED_DEVICE_SIMULATED_ONOFF_SHELL
129188
static int SimulatedBridgedDeviceOnOffWriteHandler(const struct shell *shell, size_t argc, char **argv)
130189
{
@@ -265,6 +324,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
265324
"Usage: remove <bridged_device_endpoint_id>\n"
266325
"* bridged_device_endpoint_id - the bridged device's endpoint on which it was previously created\n",
267326
RemoveBridgedDeviceHandler, 2, 0),
327+
SHELL_CMD_ARG(list, NULL,
328+
"Lists all currently connected bridged devices. \n"
329+
"Usage: list\n"
330+
"Displays endpoint ID, node label (name), and device type for all bridged devices.\n",
331+
ListBridgedDevicesHandler, 1, 0),
268332
#ifdef CONFIG_BRIDGED_DEVICE_SIMULATED_ONOFF_SHELL
269333
SHELL_CMD_ARG(
270334
onoff, NULL,

applications/matter_bridge/src/core/bridge_manager.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,18 @@ BridgedDeviceDataProvider *BridgeManager::GetProvider(EndpointId endpoint, uint1
509509
return nullptr;
510510
}
511511

512+
const char *BridgeManager::GetNodeLabel(EndpointId endpoint)
513+
{
514+
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);
515+
if (Instance().mDevicesMap.Contains(endpointIndex)) {
516+
BridgedDevicePair &bridgedDevices = Instance().mDevicesMap[endpointIndex];
517+
if (bridgedDevices.mDevice) {
518+
return bridgedDevices.mDevice->GetNodeLabel();
519+
}
520+
}
521+
return nullptr;
522+
}
523+
512524
} /* namespace Nrf */
513525

514526
Protocols::InteractionModel::Status

applications/matter_bridge/src/core/bridge_manager.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ class BridgeManager {
109109
*/
110110
BridgedDeviceDataProvider *GetProvider(chip::EndpointId endpoint, uint16_t &deviceType);
111111

112+
/**
113+
* @brief Get the node label of the bridged device on the specified endpoint.
114+
*
115+
* @param endpoint endpoint on which the bridged device is stored
116+
* @return pointer to the node label string, or nullptr if endpoint not found
117+
*/
118+
const char *GetNodeLabel(chip::EndpointId endpoint);
119+
112120
static CHIP_ERROR HandleRead(uint16_t index, chip::ClusterId clusterId,
113121
const EmberAfAttributeMetadata *attributeMetadata, uint8_t *buffer,
114122
uint16_t maxReadLength);

0 commit comments

Comments
 (0)