Skip to content

Commit 8c19309

Browse files
Merge branch 'master' into change_android_gradle_kotlin_version
2 parents f6be2ea + fdae1ae commit 8c19309

12 files changed

+9333
-4514
lines changed

.github/workflows/tests.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,22 @@ jobs:
546546
scripts/run_in_python_env.sh out/venv 'src/python_testing/execute_python_tests.py --env-file /tmp/test_env.yaml --search-directory src/python_testing'
547547
scripts/run_in_python_env.sh out/venv 'scripts/tests/TestTimeSyncTrustedTimeSourceRunner.py --all-clusters out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app'
548548
549+
- name: Execute Jupyter Notebooks
550+
run: |
551+
scripts/run_in_build_env.sh './scripts/build_python.sh --jupyter-lab --install_virtual_env out/venv'
552+
./scripts/run_in_build_env.sh \
553+
"./scripts/build/build_examples.py \
554+
--target linux-x64-all-clusters-ipv6only-no-ble-no-wifi-clang-test \
555+
build \
556+
--copy-artifacts-to objdir-clone \
557+
"
558+
scripts/run_in_python_env.sh out/venv \
559+
"jupyter execute docs/development_controllers/chip-repl/Matter_REPL_Intro.ipynb \
560+
docs/development_controllers/chip-repl/Matter_Basic_Interactions.ipynb \
561+
docs/development_controllers/chip-repl/Matter_Access_Control.ipynb \
562+
docs/development_controllers/chip-repl/Matter_Multi_Fabric_Commissioning.ipynb \
563+
"
564+
549565
- name: Uploading core files
550566
uses: actions/upload-artifact@v4
551567
if: ${{ failure() && !env.ACT }}

docs/development_controllers/chip-repl/Matter_Access_Control.ipynb

+510-405
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/Matter_Basic_Interactions.ipynb

+6,325-2,898
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/Matter_Multi_Fabric_Commissioning.ipynb

+563-479
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/Matter_REPL_Intro.ipynb

+1,867-700
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/python_chip_controller_building.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ To build and run the Python CHIP controller:
103103
chip-repl
104104
```
105105
106+
NOTE: To get more verbose logs, pass the debug flag: `chip-repl --debug`
107+
106108
<hr>
107109
108110
## Using Python CHIP Controller REPL for Matter accessory testing
@@ -133,8 +135,8 @@ An uncommissioned accessory device advertises over Bluetooth LE or via mDNS if
133135
already on the network. Run the following command to scan all advertised Matter
134136
devices:
135137
136-
```
137-
devCtrl.DiscoverCommissionableNodes()
138+
```python
139+
await devCtrl.DiscoverCommissionableNodes()
138140
```
139141

140142
### Step 4: Set network pairing credentials
@@ -173,7 +175,7 @@ network interface, such as Thread or Wi-Fi.
173175
2. Set the previously obtained Active Operational Dataset as a byte array using
174176
the following command:
175177
176-
```
178+
```python
177179
thread_dataset = bytes.fromhex("0e080000000000010000000300001335060004001fffe002084fe76e9a8b5edaf50708fde46f999f0698e20510d47f5027a414ffeebaefa92285cc84fa030f4f70656e5468726561642d653439630102e49c0410b92f8c7fbb4f9f3e08492ee3915fbd2f0c0402a0fff8")
178180
devCtrl.SetThreadOperationalDataset(thread_dataset)
179181
```
@@ -183,7 +185,7 @@ network interface, such as Thread or Wi-Fi.
183185
Assuming your Wi-Fi SSID is _TESTSSID_, and your Wi-Fi password is _P455W4RD_,
184186
set the credentials to the controller by executing the following command:
185187
186-
```
188+
```python
187189
devCtrl.SetWiFiCredentials(<ssid>, <password>)
188190
```
189191

@@ -213,8 +215,8 @@ with the following assumptions for the Matter accessory device:
213215
- The setup pin code of the device is _20202021_
214216
- The temporary Node ID is _1234_
215217

216-
```
217-
devCtrl.ConnectBLE(3840, 20202021, 1234)
218+
```python
219+
await devCtrl.ConnectBLE(3840, 20202021, 1234)
218220
```
219221

220222
You can skip the last parameter, the Node ID, in the command. If you skip it,
@@ -230,8 +232,8 @@ CHIP:SVR: SetupQRCode: [MT:-24J0AFN00KA0648G00]
230232

231233
Use the following command to commission the device with the QR code:
232234

233-
```
234-
devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
235+
```python
236+
await devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
235237
```
236238

237239
After connecting the device over Bluetooth LE, the controller will go through
@@ -262,14 +264,14 @@ the following stages:
262264
For the light bulb example, execute the following command to toggle the LED
263265
state:
264266

265-
```
267+
```python
266268
await devCtrl.SendCommand(1234, 1, Clusters.OnOff.Commands.Toggle())
267269
```
268270

269271
To change the brightness of the LED, use the following command, with the level
270272
value somewhere between 0 and 255.
271273

272-
```
274+
```python
273275
commandToSend = LevelControl.Commands.MoveToLevel(level=50, transitionTime=Null, optionsMask=0, optionsOverride=0)
274276
await devCtrl.SendCommand(1234, 1, commandToSend)
275277
```
@@ -281,7 +283,7 @@ maintains collection of attributes that a controller can obtain from a device,
281283
such as the vendor name, the product name, or software version. Use
282284
`ReadAttribute()` command to read those values from the device:
283285

284-
```
286+
```python
285287
attributes = [
286288
(0, Clusters.BasicInformation.Attributes.VendorName),
287289
(0, Clusters.BasicInformation.Attributes.ProductName),
@@ -309,7 +311,7 @@ the full list of available commands.
309311
Provides the controller with Thread network credentials that will be used in the
310312
device commissioning procedure to configure the device with a Thread interface.
311313

312-
```
314+
```python
313315
thread_dataset = bytes.fromhex("0e080000000000010000000300001335060004001fffe002084fe76e9a8b5edaf50708fde46f999f0698e20510d47f5027a414ffeebaefa92285cc84fa030f4f70656e5468726561642d653439630102e49c0410b92f8c7fbb4f9f3e08492ee3915fbd2f0c0402a0fff8")
314316
devCtrl.SetThreadOperationalDataset(thread_dataset)
315317
```
@@ -319,7 +321,7 @@ devCtrl.SetThreadOperationalDataset(thread_dataset)
319321
Provides the controller with Wi-Fi network credentials that will be used in the
320322
device commissioning procedure to configure the device with a Wi-Fi interface.
321323

322-
```
324+
```python
323325
devCtrl.SetWiFiCredentials('TESTSSID', 'P455W4RD')
324326
```
325327

@@ -328,8 +330,8 @@ devCtrl.SetWiFiCredentials('TESTSSID', 'P455W4RD')
328330
Commission with the given nodeid from the setupPayload. setupPayload may be a QR
329331
or the manual setup code.
330332

331-
```
332-
devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
333+
```python
334+
await devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
333335
```
334336

335337
### `SendCommand(<nodeid>: int, <endpoint>: int, Clusters.<cluster>.Commands.<command>(<arguments>))`

scripts/jupyterlab_requirements.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
# jupyter-lab
55
#
66
# --------------------------------------
7-
# import chip.native
8-
# import pkgutil
9-
# module = pkgutil.get_loader('chip.ChipReplStartup')
10-
# %run {module.path}
7+
# %reset -f
8+
# import importlib.util
9+
# spec = importlib.util.find_spec('chip.ChipReplStartup')
10+
# %run {spec.origin}
1111
# --------------------------------------
1212
#
1313

1414
jupyterlab
1515
ipykernel
1616
jupyterlab-lsp
1717
python-lsp-server
18+
jupyterlab-git

src/app/data-model-provider/MetadataList.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ CHIP_ERROR GenericAppendOnlyBuffer::EnsureAppendCapacity(size_t numElements)
8282

8383
if (mBuffer == nullptr)
8484
{
85-
mBuffer = static_cast<uint8_t *>(Platform::MemoryCalloc(numElements, mElementSize));
85+
mBuffer = static_cast<uint8_t *>(Platform::MemoryCalloc(numElements, mElementSize));
86+
VerifyOrReturnError(mBuffer != nullptr, CHIP_ERROR_NO_MEMORY);
8687
mCapacity = numElements;
8788
mBufferIsAllocated = true;
88-
return mBuffer != nullptr ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY;
89+
return CHIP_NO_ERROR;
8990
}
9091

9192
// we already have the data in buffer. we have two choices:
@@ -100,9 +101,9 @@ CHIP_ERROR GenericAppendOnlyBuffer::EnsureAppendCapacity(size_t numElements)
100101
else
101102
{
102103
// this is NOT an allocated buffer, but it should become one
103-
auto new_buffer = static_cast<uint8_t *>(Platform::MemoryCalloc(mElementCount + numElements, mElementSize));
104-
mBufferIsAllocated = true;
104+
auto new_buffer = static_cast<uint8_t *>(Platform::MemoryCalloc(mElementCount + numElements, mElementSize));
105105
VerifyOrReturnError(new_buffer != nullptr, CHIP_ERROR_NO_MEMORY);
106+
mBufferIsAllocated = true;
106107
memcpy(new_buffer, mBuffer, mElementCount * mElementSize);
107108
mBuffer = new_buffer;
108109
}
@@ -119,7 +120,7 @@ CHIP_ERROR GenericAppendOnlyBuffer::AppendSingleElementRaw(const void * buffer)
119120
return CHIP_NO_ERROR;
120121
}
121122

122-
CHIP_ERROR GenericAppendOnlyBuffer::AppendElementArrayRaw(const void * buffer, size_t numElements)
123+
CHIP_ERROR GenericAppendOnlyBuffer::AppendElementArrayRaw(const void * __restrict__ buffer, size_t numElements)
123124
{
124125
ReturnErrorOnFailure(EnsureAppendCapacity(numElements));
125126

src/app/data-model-provider/MetadataList.h

+14-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GenericAppendOnlyBuffer
4747
/// Ensure that at least the specified number of elements
4848
/// can be appended to the internal buffer;
4949
///
50-
/// This will cause the internal buffer to become and allocated buffer
50+
/// This will cause the internal buffer to become an allocated buffer
5151
CHIP_ERROR EnsureAppendCapacity(size_t numElements);
5252

5353
bool IsEmpty() const { return mElementCount == 0; }
@@ -66,7 +66,10 @@ class GenericAppendOnlyBuffer
6666
///
6767
/// This ALWAYS COPIES the elements internally.
6868
/// Additional capacity is AUTOMATICALLY ADDED.
69-
CHIP_ERROR AppendElementArrayRaw(const void * buffer, size_t numElements);
69+
///
70+
/// buffer MUST NOT point inside "own" buffer as mBuffer may be reallocated
71+
/// as part of the appending.
72+
CHIP_ERROR AppendElementArrayRaw(const void * __restrict__ buffer, size_t numElements);
7073

7174
/// Appends a list of elements from a raw array.
7275
///
@@ -93,7 +96,11 @@ class GenericAppendOnlyBuffer
9396

9497
/// Represents a RAII instance owning a buffer.
9598
///
96-
/// It auto-frees the owned buffer on destruction
99+
/// It auto-frees the owned buffer on destruction via `Platform::MemoryFree`.
100+
///
101+
/// This class is designed to be a storage class for `GenericAppendOnlyBuffer` and
102+
/// its subclasses (i.e. GenericAppendOnlyBuffer uses PlatformMemory and this class
103+
/// does the same. They MUST be kept in sync.)
97104
class ScopedBuffer
98105
{
99106
public:
@@ -165,6 +172,10 @@ class ListBuilder : public detail::GenericAppendOnlyBuffer
165172
///
166173
/// Automatically attempts to allocate sufficient space to fulfill the element
167174
/// requirements.
175+
///
176+
/// `span` MUST NOT point inside "own" buffer (and generally will not
177+
/// as this class does not expose buffer access except by releasing ownership
178+
/// via `Take`)
168179
CHIP_ERROR AppendElements(SpanType span) { return AppendElementArrayRaw(span.data(), span.size()); }
169180

170181
/// Append a single element.

src/app/data-model-provider/ProviderMetadataTree.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ class ProviderMetadataTree
8383
virtual void Temporary_ReportAttributeChanged(const AttributePathParams & path) = 0;
8484

8585
// "convenience" functions that just return the data and ignore the error
86-
// This returns the builder as-is even after the error (e.g. not found would return empty data)
86+
// This returns the `ListBuilder<..>::TakeBuffer` from their equivalent fuctions as-is,
87+
// even after an error (e.g. not found would return empty data).
88+
//
89+
// Usage of these indicates no error handling (not even logging) and code should
90+
// consider handling errors instead.
8791
ReadOnlyBuffer<EndpointEntry> EndpointsIgnoreError();
8892
ReadOnlyBuffer<ServerClusterEntry> ServerClustersIgnoreError(EndpointId endpointId);
8993
ReadOnlyBuffer<AttributeEntry> AttributesIgnoreError(const ConcreteClusterPath & path);

src/controller/python/chip-repl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
def main():
2727
c = Config()
2828
c.InteractiveShellApp.exec_lines = [
29-
"import pkgutil",
30-
"module = pkgutil.get_loader('chip.ChipReplStartup')",
31-
"%run {module.path} " + " ".join(sys.argv[1:])
29+
"import importlib.util",
30+
"spec = importlib.util.find_spec('chip.ChipReplStartup')",
31+
"%run {spec.origin} " + " ".join(sys.argv[1:])
3232
]
3333

3434
sys.argv = [sys.argv[0]]

src/controller/python/chip/ChipReplStartup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pathlib
77

88
import chip.CertificateAuthority
9+
import chip.clusters as Clusters # noqa: F401
910
import chip.FabricAdmin
1011
import chip.logging
1112
import chip.native
@@ -163,7 +164,7 @@ def main():
163164
console.print(
164165
'''\t[red]certificateAuthorityManager[blue]:\tManages a list of CertificateAuthority instances.
165166
\t[red]caList[blue]:\t\t\t\tThe list of CertificateAuthority instances.
166-
\t[red]caList[n][m][blue]:\t\t\tA specific FabricAdmin object at index m for the nth CertificateAuthority instance.''')
167+
\t[red]caList\[n].adminList\[m][blue]:\t\tA specific FabricAdmin object at index m for the nth CertificateAuthority instance.''')
167168

168169
console.print(
169170
f'\n\n[blue]Default CHIP Device Controller (NodeId: {devCtrl.nodeId}): '

0 commit comments

Comments
 (0)