From 7bf8ceb5e73032b12aa100595fa1d93e28dfbf01 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Fri, 3 Mar 2023 06:47:28 -0800 Subject: [PATCH 01/10] [Android] Fallback to BLE Notification when Indication unsupported (#25444) To support devices based on older revisions of the SDK that did not include the GATT Server Characteristic property change (from Notification to Indication), the GATT Characteristic properties are queried to determine if Indication and/or Notification is supported. When available, Indication is preferred. --- .../java/chip/platform/AndroidBleManager.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/platform/android/java/chip/platform/AndroidBleManager.java b/src/platform/android/java/chip/platform/AndroidBleManager.java index 20b51ee008683e..3bc484985d231d 100644 --- a/src/platform/android/java/chip/platform/AndroidBleManager.java +++ b/src/platform/android/java/chip/platform/AndroidBleManager.java @@ -157,6 +157,9 @@ public void onDescriptorWrite( if (desc.getValue() == BluetoothGattDescriptor.ENABLE_INDICATION_VALUE) { mPlatform.handleSubscribeComplete( connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS); + } else if (desc.getValue() == BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) { + mPlatform.handleSubscribeComplete( + connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS); } else if (desc.getValue() == BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE) { mPlatform.handleUnsubscribeComplete( connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS); @@ -283,10 +286,18 @@ public boolean onSubscribeCharacteristic(int connId, byte[] svcId, byte[] charId BluetoothGattDescriptor descriptor = subscribeChar.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG)); - descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); - if (!bluetoothGatt.writeDescriptor(descriptor)) { - Log.e(TAG, "writeDescriptor failed"); - return false; + if ((subscribeChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) { + descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); + if (!bluetoothGatt.writeDescriptor(descriptor)) { + Log.e(TAG, "writeDescriptor failed"); + return false; + } + } else if ((subscribeChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) { + descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); + if (!bluetoothGatt.writeDescriptor(descriptor)) { + Log.e(TAG, "writeDescriptor failed"); + return false; + } } return true; } From 21a423f57045eba38b3f1b0262ef00d1b85e1e50 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 3 Mar 2023 06:48:30 -0800 Subject: [PATCH 02/10] Update docker image to the latest for all android related builds (#25443) --- .github/workflows/full-android.yaml | 2 +- integrations/cloudbuild/smoke-test.yaml | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/full-android.yaml b/.github/workflows/full-android.yaml index b8f3802f334c0e..d28d3fb1679b2d 100644 --- a/.github/workflows/full-android.yaml +++ b/.github/workflows/full-android.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: connectedhomeip/chip-build-android:0.6.44 + image: connectedhomeip/chip-build-android:0.6.47 volumes: - "/tmp/log_output:/tmp/test_logs" diff --git a/integrations/cloudbuild/smoke-test.yaml b/integrations/cloudbuild/smoke-test.yaml index 5b2a39ae9322a2..1ee1aa7b7cc431 100644 --- a/integrations/cloudbuild/smoke-test.yaml +++ b/integrations/cloudbuild/smoke-test.yaml @@ -1,5 +1,5 @@ steps: - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" entrypoint: "bash" args: - "-c" @@ -7,7 +7,7 @@ steps: git config --global --add safe.directory "*" git submodule update --init --recursive id: Submodules - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" env: - PW_ENVIRONMENT_ROOT=/pwenv args: @@ -22,7 +22,7 @@ steps: path: /pwenv timeout: 900s - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" id: ESP32 env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -40,7 +40,7 @@ steps: volumes: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" id: NRFConnect env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -61,7 +61,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" id: EFR32 env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -83,7 +83,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" id: Linux env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -143,7 +143,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.44" + - name: "connectedhomeip/chip-build-vscode:0.6.47" id: Android env: - PW_ENVIRONMENT_ROOT=/pwenv From 0573c9416ba35b24ae82cf0fe0751757268aac77 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 3 Mar 2023 08:02:43 -0800 Subject: [PATCH 03/10] [java-matter-controller] Convert from java to kotlin phase I (#25384) * [java-matter-controller] Convert from java to kotlin phase I * Address review comments * Move constants outside the class instance --- examples/java-matter-controller/BUILD.gn | 25 +++- examples/java-matter-controller/Manifest.txt | 4 +- examples/java-matter-controller/README.md | 53 +++++++- .../java/src/com/matter/controller/Main.java | 125 ------------------ .../java/src/com/matter/controller/Main.kt | 81 ++++++++++++ .../commands/common/CommandManager.java | 21 ++- .../commands/discover/DiscoverCommand.java | 42 ------ .../commands/discover/DiscoverCommand.kt | 36 +++++ .../DiscoverCommissionablesCommand.java | 65 --------- .../DiscoverCommissionablesCommand.kt | 58 ++++++++ .../DiscoverCommissionersCommand.java | 35 ----- .../discover/DiscoverCommissionersCommand.kt | 28 ++++ 12 files changed, 281 insertions(+), 292 deletions(-) delete mode 100644 examples/java-matter-controller/java/src/com/matter/controller/Main.java create mode 100644 examples/java-matter-controller/java/src/com/matter/controller/Main.kt delete mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.java create mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.kt delete mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.java create mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt delete mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.java create mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index f27a63dd19d8f2..a8d426cc48f92d 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -18,8 +18,8 @@ import("//build_overrides/chip.gni") import("${chip_root}/build/chip/java/rules.gni") import("${chip_root}/build/chip/tools.gni") -java_binary("java-matter-controller") { - output_name = "java-matter-controller" +java_library("java") { + output_name = "JavaMatterController.jar" deps = [ "${chip_root}/src/controller/java", "${chip_root}/src/setup_payload/java", @@ -27,7 +27,6 @@ java_binary("java-matter-controller") { ] sources = [ - "java/src/com/matter/controller/Main.java", "java/src/com/matter/controller/commands/common/Argument.java", "java/src/com/matter/controller/commands/common/ArgumentType.java", "java/src/com/matter/controller/commands/common/Command.java", @@ -37,9 +36,6 @@ java_binary("java-matter-controller") { "java/src/com/matter/controller/commands/common/IPAddress.java", "java/src/com/matter/controller/commands/common/MatterCommand.java", "java/src/com/matter/controller/commands/common/RealResult.java", - "java/src/com/matter/controller/commands/discover/DiscoverCommand.java", - "java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.java", - "java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.java", "java/src/com/matter/controller/commands/pairing/CloseSessionCommand.java", "java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.java", "java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.java", @@ -66,6 +62,23 @@ java_binary("java-matter-controller") { javac_flags = [ "-Xlint:deprecation" ] } +kotlin_binary("java-matter-controller") { + output_name = "java-matter-controller" + deps = [ + ":java", + "${chip_root}/third_party/java_deps:kotlin-stdlib", + ] + + sources = [ + "java/src/com/matter/controller/Main.kt", + "java/src/com/matter/controller/commands/discover/DiscoverCommand.kt", + "java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt", + "java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt", + ] + + kotlinc_flags = [ "-Xlint:deprecation" ] +} + group("default") { deps = [ ":java-matter-controller" ] } diff --git a/examples/java-matter-controller/Manifest.txt b/examples/java-matter-controller/Manifest.txt index ebdd1a402677f7..d221d20b748873 100644 --- a/examples/java-matter-controller/Manifest.txt +++ b/examples/java-matter-controller/Manifest.txt @@ -1,3 +1,3 @@ -Main-Class: com.matter.controller.Main -Class-Path: ../lib/third_party/connectedhomeip/src/controller/java/CHIPController.jar ../lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar ../lib/third_party/connectedhomeip/third_party/java_deps/stub_src/Android.jar ../lib/third_party/connectedhomeip/third_party/java_deps/json-20220924.jar ../lib/third_party/connectedhomeip/third_party/java_deps/jsr305-3.0.2.jar +Main-Class: com.matter.controller.MainKt +Class-Path: ../lib/third_party/connectedhomeip/src/controller/java/CHIPController.jar ../lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar ../lib/third_party/connectedhomeip/third_party/java_deps/stub_src/Android.jar ../lib/third_party/connectedhomeip/third_party/java_deps/json-20220924.jar ../lib/third_party/connectedhomeip/third_party/java_deps/jsr305-3.0.2.jar ../lib/third_party/connectedhomeip/third_party/java_deps/kotlin-stdlib-1.8.10.jar diff --git a/examples/java-matter-controller/README.md b/examples/java-matter-controller/README.md index fae126f8b7af10..3b67056eceba90 100644 --- a/examples/java-matter-controller/README.md +++ b/examples/java-matter-controller/README.md @@ -21,7 +21,7 @@ You need to have the following two software installed on your Ubuntu system: 1. Java Runtime Environment (JRE) 2. Java Development Kit (JDK) -``` +```shell java -version ``` @@ -36,20 +36,63 @@ sudo apt install default-jre Install Java default JRE After installing the JRE, let us check if we have the Java Development Kit installed on our system or not. -``` +```shell javac -version ``` The above output shows that I need to install the Java compiler or the JDK on my system. You can install it through the following command as root: -``` +```shell sudo apt install default-jdk ``` -### Linux +You also need to install kotlin compiler on your Ubuntu system: + +kotlin compiler version 1.8.10 or above is needed to compile +java-matter-controller, if you already have lower version kotlin compiler +installed on your Ubuntu from apt, +you need to remove the Kotlin compiler package, run the following command: +```shell +sudo apt-get remove kotlin ``` + +Wait for the removal process to complete. Once it's done, the Kotlin compiler +will be removed from your system. + +(Optional) If you want to remove any configuration files associated with Kotlin, +run the following command: + +```shell +sudo apt-get purge kotlin +``` + +Install kotlin compiler 1.8.10 or above, such as +[kotlin-compiler-1.8.10-url](https://github.com/JetBrains/kotlin/releases/download/v1.8.10/kotlin-compiler-1.8.10.zip) + +```shell +cd /usr/lib \ +&& sudo wget -q [kotlin-compiler-1.8.10-url] \ +&& sudo unzip kotlin-compiler-*.zip \ +&& sudo rm kotlin-compiler-*.zip \ +&& sudo rm -f kotlinc/bin/*.bat +``` + +Add a directory to PATH permanently by editing the `.bashrc` file located in the +Home directory. Follow these steps: + +1. Open the `.bashrc` file using a text editor. +2. Go to the end of the file. +3. Paste the export syntax at the end of the file. + +```shell +export PATH="/usr/lib/kotlinc/bin:$PATH" +``` + +### Linux + +```shell export JAVA_PATH=[JDK path] ``` @@ -81,6 +124,6 @@ The Java executable file `java-matter-controller` will be generated at Run the java-matter-controller -``` +```shell java -Djava.library.path=../lib/jni -jar java-matter-controller ``` diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.java b/examples/java-matter-controller/java/src/com/matter/controller/Main.java deleted file mode 100644 index 59c2e666589365..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/Main.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2022-2023 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.matter.controller; - -import chip.devicecontroller.ChipDeviceController; -import chip.devicecontroller.ControllerParams; -import com.matter.controller.commands.common.*; -import com.matter.controller.commands.discover.*; -import com.matter.controller.commands.pairing.*; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class Main { - private static Logger logger = Logger.getLogger(Main.class.getName()); - - private static void registerCommandsDiscover( - ChipDeviceController controller, - CommandManager commandManager, - CredentialsIssuer credentialsIssuer) { - ArrayList clusterCommands = new ArrayList(); - DiscoverCommand discoverCommand = new DiscoverCommand(controller, credentialsIssuer); - DiscoverCommissionablesCommand discoverCommissionablesCommand = - new DiscoverCommissionablesCommand(controller, credentialsIssuer); - DiscoverCommissionersCommand discoverCommissionersCommand = - new DiscoverCommissionersCommand(controller, credentialsIssuer); - clusterCommands.add(discoverCommand); - clusterCommands.add(discoverCommissionablesCommand); - clusterCommands.add(discoverCommissionersCommand); - - commandManager.register("discover", clusterCommands); - } - - private static void registerCommandsPairing( - ChipDeviceController controller, - CommandManager commandManager, - CredentialsIssuer credentialsIssuer) { - ArrayList clusterCommands = new ArrayList(); - UnpairCommand unpairCommand = new UnpairCommand(controller, credentialsIssuer); - PairCodeCommand pairCodeCommand = new PairCodeCommand(controller, credentialsIssuer); - PairCodePaseCommand pairCodePaseCommand = - new PairCodePaseCommand(controller, credentialsIssuer); - PairCodeWifiCommand pairCodeWifiCommand = - new PairCodeWifiCommand(controller, credentialsIssuer); - PairCodeThreadCommand pairCodeThreadCommand = - new PairCodeThreadCommand(controller, credentialsIssuer); - PairAddressPaseCommand pairAddressPaseCommand = - new PairAddressPaseCommand(controller, credentialsIssuer); - PairAlreadyDiscoveredCommand pairAlreadyDiscoveredCommand = - new PairAlreadyDiscoveredCommand(controller, credentialsIssuer); - PairOnNetworkCommand pairOnNetworkCommand = - new PairOnNetworkCommand(controller, credentialsIssuer); - PairOnNetworkShortCommand pairOnNetworkShortCommand = - new PairOnNetworkShortCommand(controller, credentialsIssuer); - PairOnNetworkLongCommand pairOnNetworkLongCommand = - new PairOnNetworkLongCommand(controller, credentialsIssuer); - PairOnNetworkVendorCommand pairOnNetworkVendorCommand = - new PairOnNetworkVendorCommand(controller, credentialsIssuer); - PairOnNetworkCommissioningModeCommand pairOnNetworkCommissioningModeCommand = - new PairOnNetworkCommissioningModeCommand(controller, credentialsIssuer); - PairOnNetworkCommissionerCommand pairOnNetworkCommissionerCommand = - new PairOnNetworkCommissionerCommand(controller, credentialsIssuer); - PairOnNetworkDeviceTypeCommand pairOnNetworkDeviceTypeCommand = - new PairOnNetworkDeviceTypeCommand(controller, credentialsIssuer); - PairOnNetworkInstanceNameCommand pairOnNetworkInstanceNameCommand = - new PairOnNetworkInstanceNameCommand(controller, credentialsIssuer); - clusterCommands.add(unpairCommand); - clusterCommands.add(pairCodeCommand); - clusterCommands.add(pairCodePaseCommand); - clusterCommands.add(pairCodeWifiCommand); - clusterCommands.add(pairCodeThreadCommand); - clusterCommands.add(pairAddressPaseCommand); - clusterCommands.add(pairAlreadyDiscoveredCommand); - clusterCommands.add(pairOnNetworkCommand); - clusterCommands.add(pairOnNetworkShortCommand); - clusterCommands.add(pairOnNetworkLongCommand); - clusterCommands.add(pairOnNetworkVendorCommand); - clusterCommands.add(pairOnNetworkCommissioningModeCommand); - clusterCommands.add(pairOnNetworkCommissionerCommand); - clusterCommands.add(pairOnNetworkDeviceTypeCommand); - clusterCommands.add(pairOnNetworkInstanceNameCommand); - - commandManager.register("pairing", clusterCommands); - } - - public static void main(String[] args) { - ChipDeviceController controller = - new ChipDeviceController( - ControllerParams.newBuilder() - .setUdpListenPort(0) - .setControllerVendorId(0xFFF1) - .setCountryCode("US") - .build()); - - CredentialsIssuer credentialsIssuer = new CredentialsIssuer(); - CommandManager commandManager = new CommandManager(); - - registerCommandsDiscover(controller, commandManager, credentialsIssuer); - registerCommandsPairing(controller, commandManager, credentialsIssuer); - - try { - commandManager.run(args); - } catch (Exception e) { - logger.log(Level.INFO, "Run command failed with exception: " + e.getMessage()); - System.exit(1); - } - controller.shutdownCommissioning(); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt new file mode 100644 index 00000000000000..51d68ad5f8902c --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.matter.controller + +import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.ControllerParams +import com.matter.controller.commands.common.* +import com.matter.controller.commands.discover.* +import com.matter.controller.commands.pairing.* + +private fun getDiscoveryCommands( + controller: ChipDeviceController, + credentialsIssuer: CredentialsIssuer +): List { + return listOf( + DiscoverCommand(controller, credentialsIssuer), + DiscoverCommissionablesCommand(controller, credentialsIssuer), + DiscoverCommissionersCommand(controller, credentialsIssuer), + ) +} + +private fun getPairingCommands( + controller: ChipDeviceController, + credentialsIssuer: CredentialsIssuer +): List { + return listOf( + UnpairCommand(controller, credentialsIssuer), + PairCodeCommand(controller, credentialsIssuer), + PairCodePaseCommand(controller, credentialsIssuer), + PairCodeWifiCommand(controller, credentialsIssuer), + PairCodeThreadCommand(controller, credentialsIssuer), + PairAddressPaseCommand(controller, credentialsIssuer), + PairAlreadyDiscoveredCommand(controller, credentialsIssuer), + PairOnNetworkCommand(controller, credentialsIssuer), + PairOnNetworkShortCommand(controller, credentialsIssuer), + PairOnNetworkLongCommand(controller, credentialsIssuer), + PairOnNetworkVendorCommand(controller, credentialsIssuer), + PairOnNetworkCommissioningModeCommand(controller, credentialsIssuer), + PairOnNetworkCommissionerCommand(controller, credentialsIssuer), + PairOnNetworkDeviceTypeCommand(controller, credentialsIssuer), + PairOnNetworkInstanceNameCommand(controller, credentialsIssuer), + ) +} + +fun main(args: Array) { + val controller = ChipDeviceController( + ControllerParams.newBuilder() + .setUdpListenPort(0) + .setControllerVendorId(0xFFF1) + .setCountryCode("US") + .build() + ) + val credentialsIssuer = CredentialsIssuer() + val commandManager = CommandManager() + + commandManager.register("discover", getDiscoveryCommands(controller, credentialsIssuer)) + commandManager.register("pairing", getPairingCommands(controller, credentialsIssuer)) + + try { + commandManager.run(args) + } catch (e: Exception) { + println("Run command failed with exception: " + e.message) + System.exit(1) + } + controller.shutdownCommissioning() +} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java index 47e184ec3ae4d7..202c6763a2187e 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java @@ -18,21 +18,19 @@ package com.matter.controller.commands.common; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; public final class CommandManager { - private final ArrayList mCommandMgr = new ArrayList(); - private final Map> mClusters = - new HashMap>(); + private final Map> mClusters = new HashMap>(); private static Logger logger = Logger.getLogger(CommandManager.class.getName()); - public final void register(String clusterName, ArrayList commandsList) { + public final void register(String clusterName, List commandsList) { mClusters.put(clusterName, commandsList); } @@ -45,7 +43,7 @@ public final void run(String[] args) throws Exception { return; } - ArrayList commands = mClusters.get(args[0]); + List commands = mClusters.get(args[0]); if (commands == null) { logger.log(Level.INFO, "Unknown cluster: " + args[0]); showClusters(); @@ -121,7 +119,7 @@ private boolean isGlobalCommand(String commandName) { return isAttributeCommand(commandName) || isEventCommand(commandName); } - private Command getCommand(ArrayList commands, String commandName) { + private Command getCommand(List commands, String commandName) { for (Command command : commands) { if (commandName.equals(command.getName())) { return command; @@ -132,7 +130,7 @@ private Command getCommand(ArrayList commands, String commandName) { } private Command getGlobalCommand( - ArrayList commands, String commandName, String attributeName) { + List commands, String commandName, String attributeName) { for (Command command : commands) { if (commandName.equals(command.getName()) && attributeName.equals(command.getAttribute())) { return command; @@ -166,7 +164,7 @@ private void showClusters() { " +-------------------------------------------------------------------------------------+"); } - private void showCluster(String clusterName, ArrayList commands) { + private void showCluster(String clusterName, List commands) { logger.log(Level.INFO, "Usage:"); logger.log( Level.INFO, @@ -216,7 +214,7 @@ private void showCluster(String clusterName, ArrayList commands) { } private void showClusterAttributes( - String clusterName, String commandName, ArrayList commands) { + String clusterName, String commandName, List commands) { logger.log(Level.INFO, "Usage:"); System.out.printf( " java-matter-controller %s %s attribute-name [param1 param2 ...]\n", @@ -241,8 +239,7 @@ private void showClusterAttributes( " +-------------------------------------------------------------------------------------+"); } - private void showClusterEvents( - String clusterName, String commandName, ArrayList commands) { + private void showClusterEvents(String clusterName, String commandName, List commands) { logger.log(Level.INFO, "Usage:"); System.out.printf( " java-matter-controller %s %s event-name [param1 param2 ...]\n", diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.java deleted file mode 100644 index 988e97bb23c3b8..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.matter.controller.commands.discover; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; -import com.matter.controller.commands.common.MatterCommand; -import java.util.concurrent.atomic.AtomicLong; - -public final class DiscoverCommand extends MatterCommand { - private final AtomicLong mNodeId = new AtomicLong(); - private final AtomicLong mFabricId = new AtomicLong(); - - public DiscoverCommand(ChipDeviceController controller, CredentialsIssuer credsIssuer) { - super(controller, "resolve", credsIssuer); - addArgument("nodeid", 0, Long.MAX_VALUE, mNodeId, null, false); - addArgument("fabricid", 0, Long.MAX_VALUE, mFabricId, null, false); - } - - @Override - protected final void runCommand() { - runCommand(mNodeId.get(), mFabricId.get()); - } - - private final void runCommand(long remoteId, long fabricId) {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.kt new file mode 100644 index 00000000000000..2d570a6eb0ef7a --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.matter.controller.commands.discover + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer +import com.matter.controller.commands.common.MatterCommand +import java.util.concurrent.atomic.AtomicLong + +class DiscoverCommand(controller: ChipDeviceController, credsIssuer: CredentialsIssuer?) : + MatterCommand(controller, "resolve", credsIssuer) { + private val nodeId: AtomicLong = AtomicLong() + private val fabricId: AtomicLong = AtomicLong() + + init { + addArgument("nodeid", 0, Long.MAX_VALUE, nodeId, null, false) + addArgument("fabricid", 0, Long.MAX_VALUE, fabricId, null, false) + } + + override fun runCommand() {} +} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.java deleted file mode 100644 index 2ba38307554fbd..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.matter.controller.commands.discover; - -import chip.devicecontroller.ChipDeviceController; -import chip.devicecontroller.DiscoveredDevice; -import com.matter.controller.commands.common.CredentialsIssuer; -import com.matter.controller.commands.common.MatterCommand; - -public final class DiscoverCommissionablesCommand extends MatterCommand { - private static final int MAX_DISCOVERED_DEVICES = 10; - - public DiscoverCommissionablesCommand( - ChipDeviceController controller, CredentialsIssuer credsIssuer) { - super(controller, "commissionables", credsIssuer); - } - - @Override - protected final void runCommand() { - currentCommissioner().discoverCommissionableNodes(); - - // Pause for 7 seconds - try { - Thread.sleep(7000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - getDiscoveredDevice(); - } - - private final void getDiscoveredDevice() { - // Log at most MAX_DISCOVERED_DEVICES discovered devices - for (int i = 0; i < MAX_DISCOVERED_DEVICES; i++) { - DiscoveredDevice device = currentCommissioner().getDiscoveredDevice(i); - if (device == null) { - break; - } - - logDevice(device); - } - } - - private final void logDevice(DiscoveredDevice device) { - System.out.println("Discovered node:"); - System.out.format("\tDiscriminator: %d", device.discriminator); - System.out.format("\tIP Address : %s%n", device.ipAddress); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt new file mode 100644 index 00000000000000..6eef21ba8c01e0 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.matter.controller.commands.discover + +import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.DiscoveredDevice +import com.matter.controller.commands.common.CredentialsIssuer +import com.matter.controller.commands.common.MatterCommand +import java.util.concurrent.TimeUnit + +private const val MAX_DISCOVERED_DEVICES = 10 +private const val TIME_TO_WAIT_FOR_RESULTS_SECONDS = 7L + +class DiscoverCommissionablesCommand( + controller: ChipDeviceController, credsIssuer: CredentialsIssuer? +) : MatterCommand(controller, "commissionables", credsIssuer) { + + override fun runCommand() { + currentCommissioner().discoverCommissionableNodes() + + try { + TimeUnit.SECONDS.sleep(TIME_TO_WAIT_FOR_RESULTS_SECONDS) + } catch (e: InterruptedException) { + throw RuntimeException(e) + } + + logDiscoveredDevice() + } + + private fun logDiscoveredDevice() { + // Log at most MAX_DISCOVERED_DEVICES discovered devices + for (i in 0 until MAX_DISCOVERED_DEVICES) { + val device: DiscoveredDevice = currentCommissioner().getDiscoveredDevice(i) ?: break + logDevice(device) + } + } + + private fun logDevice(device: DiscoveredDevice) { + println("Discovered node:") + System.out.format("\tDiscriminator: %d", device.discriminator) + System.out.format("\tIP Address : %s%n", device.ipAddress) + } +} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.java deleted file mode 100644 index ed5eca264a6106..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.matter.controller.commands.discover; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; -import com.matter.controller.commands.common.MatterCommand; - -public final class DiscoverCommissionersCommand extends MatterCommand { - public DiscoverCommissionersCommand( - ChipDeviceController controller, CredentialsIssuer credsIssuer) { - super(controller, "commissioners", credsIssuer); - } - - @Override - protected final void runCommand() { - // mCommissionableNodeController.DiscoverCommissioners(); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt new file mode 100644 index 00000000000000..ebc0ec1343a9eb --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.matter.controller.commands.discover + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer +import com.matter.controller.commands.common.MatterCommand + +class DiscoverCommissionersCommand( + controller: ChipDeviceController, credsIssuer: CredentialsIssuer? +) : MatterCommand(controller, "commissioners", credsIssuer) { + override fun runCommand() {} +} From f62853ebb7a731ae9c54a2ba41c01a0bbb83f86e Mon Sep 17 00:00:00 2001 From: cliffamzn Date: Mon, 27 Feb 2023 17:03:26 -0800 Subject: [PATCH 04/10] Fix encoding for device name We should be using UTF8 encoding rather than ASCII encoding --- .../MatterTvCastingBridge/ConversionUtils.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm index 3f98f96d2286c3..74f41c5203d022 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2023 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -120,16 +120,16 @@ + (DiscoveredNodeData *)convertToObjCDiscoveredNodeDataFrom:(const chip::Dnssd:: objCDiscoveredNodeData.commissioningMode = cppDiscoveredNodedata->commissionData.commissioningMode; objCDiscoveredNodeData.pairingHint = cppDiscoveredNodedata->commissionData.pairingHint; objCDiscoveredNodeData.deviceName = [NSString stringWithCString:cppDiscoveredNodedata->commissionData.deviceName - encoding:NSASCIIStringEncoding]; + encoding:NSUTF8StringEncoding]; objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->commissionData.rotatingIdLen; objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->commissionData.rotatingId; objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->commissionData.instanceName - encoding:NSASCIIStringEncoding]; + encoding:NSUTF8StringEncoding]; // from CommonResolutionData objCDiscoveredNodeData.port = cppDiscoveredNodedata->resolutionData.port; objCDiscoveredNodeData.hostName = [NSString stringWithCString:cppDiscoveredNodedata->resolutionData.hostName - encoding:NSASCIIStringEncoding]; + encoding:NSUTF8StringEncoding]; objCDiscoveredNodeData.platformInterface = cppDiscoveredNodedata->resolutionData.interfaceId.GetPlatformInterface(); objCDiscoveredNodeData.numIPs = cppDiscoveredNodedata->resolutionData.numIPs; if (cppDiscoveredNodedata->resolutionData.numIPs > 0) { @@ -154,7 +154,7 @@ + (VideoPlayer *)convertToObjCVideoPlayerFrom:(TargetVideoPlayerInfo * _Nonnull) objCVideoPlayer.deviceType = cppTargetVideoPlayerInfo->GetDeviceType(); objCVideoPlayer.isConnected = (cppTargetVideoPlayerInfo->GetOperationalDeviceProxy() != nil); objCVideoPlayer.deviceName = [NSString stringWithCString:cppTargetVideoPlayerInfo->GetDeviceName() - encoding:NSASCIIStringEncoding]; + encoding:NSUTF8StringEncoding]; objCVideoPlayer.contentApps = [NSMutableArray new]; TargetEndpointInfo * cppTargetEndpointInfos = cppTargetVideoPlayerInfo->GetEndpoints(); for (size_t i = 0; i < kMaxNumberOfEndpoints && cppTargetEndpointInfos[i].IsInitialized(); i++) { From da5eec6a5bafdc9886da30a7a74b4c98076b1b5a Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Fri, 3 Mar 2023 12:06:16 -0800 Subject: [PATCH 05/10] use right error callback for java/jni im read/subscribe (#25453) --- src/controller/java/CHIPDeviceController-JNI.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 966b84533ecf46..5da3d86ff4be04 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1295,8 +1295,7 @@ JNI_METHOD(void, subscribe) err = readClient->SendRequest(params); if (err != CHIP_NO_ERROR) { - chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback->mReportCallbackRef, ErrorStr(err), - err); + callback->OnError(err); delete readClient; delete callback; return; @@ -1347,8 +1346,7 @@ JNI_METHOD(void, read) err = readClient->SendRequest(params); if (err != CHIP_NO_ERROR) { - chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback->mReportCallbackRef, ErrorStr(err), - err); + callback->OnError(err); delete readClient; delete callback; return; From 738d6f3588d1ffbe6124d4d493d6d55038f92068 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 3 Mar 2023 15:37:35 -0500 Subject: [PATCH 06/10] Correct copied path for kotlinc for vscode image (#25462) Co-authored-by: Andrei Litvin --- integrations/docker/images/chip-build-vscode/Dockerfile | 2 +- integrations/docker/images/chip-build/version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/docker/images/chip-build-vscode/Dockerfile b/integrations/docker/images/chip-build-vscode/Dockerfile index d601d348295c57..6049021dfacc3d 100644 --- a/integrations/docker/images/chip-build-vscode/Dockerfile +++ b/integrations/docker/images/chip-build-vscode/Dockerfile @@ -28,7 +28,7 @@ COPY --from=nrf /opt/NordicSemiconductor/nrfconnect /opt/NordicSemiconductor/nrf COPY --from=android /opt/android/sdk /opt/android/sdk COPY --from=android /opt/android/android-ndk-r21b /opt/android/android-ndk-r21b -COPY --from=android /usr/lib/kotlinc/bin /usr/lib/kotlinc/bin +COPY --from=android /usr/lib/kotlinc /usr/lib/kotlinc COPY --from=mbedos /opt/openocd/ /opt/openocd/ diff --git a/integrations/docker/images/chip-build/version b/integrations/docker/images/chip-build/version index f67413177a7d0d..fb0739078dea26 100644 --- a/integrations/docker/images/chip-build/version +++ b/integrations/docker/images/chip-build/version @@ -1 +1 @@ -0.6.47 Version bump reason: [nrfconnect] Update nRF Connect SDK version. +0.6.48 Version bump reason: [android] Correct kotlinc path for vscode image From 50af118fa60504b51d654d8452036f8be0f75b1d Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Fri, 3 Mar 2023 14:02:25 -0800 Subject: [PATCH 07/10] Add JAVA/JNI IM Write API (#25445) * Add JAVA/JNI IM Write API -- Add generic IM write API which takes a list of AttributeWrites, in each write it would have concrete attribue path and tlv blob. -- Add initial IM write test in java matter controller test example, next step is to integrate kotlin tlvwriter/tlvreader, and refactor this test command to accept the customized paratmeters for attribute path and data. --- examples/java-matter-controller/BUILD.gn | 1 + .../java/src/com/matter/controller/Main.kt | 11 +- .../commands/common/FutureResult.java | 5 +- .../commands/common/MatterCommand.java | 10 +- .../PairOnNetworkLongImWriteCommand.java | 99 +++++++++++++ src/controller/java/AndroidCallbacks-JNI.cpp | 15 ++ src/controller/java/AndroidCallbacks.cpp | 116 ++++++++++++++- src/controller/java/AndroidCallbacks.h | 28 +++- src/controller/java/BUILD.gn | 3 + .../java/CHIPDeviceController-JNI.cpp | 129 +++++++++++++++++ .../ChipDeviceController.java | 35 +++++ .../WriteAttributesCallback.java | 47 +++++++ .../WriteAttributesCallbackJni.java | 48 +++++++ .../model/AttributeWriteRequest.java | 132 ++++++++++++++++++ 14 files changed, 669 insertions(+), 10 deletions(-) create mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java create mode 100644 src/controller/java/src/chip/devicecontroller/WriteAttributesCallback.java create mode 100644 src/controller/java/src/chip/devicecontroller/WriteAttributesCallbackJni.java create mode 100644 src/controller/java/src/chip/devicecontroller/model/AttributeWriteRequest.java diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index a8d426cc48f92d..6314b71fc0f960 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -51,6 +51,7 @@ java_library("java") { "java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.java", "java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.java", "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.java", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java", "java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.java", "java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.java", "java/src/com/matter/controller/commands/pairing/PairingCommand.java", diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt index 51d68ad5f8902c..34167a469cfc79 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt @@ -57,6 +57,15 @@ private fun getPairingCommands( ) } +private fun getImCommands( + controller: ChipDeviceController, + credentialsIssuer: CredentialsIssuer +): List { + return listOf( + PairOnNetworkLongImWriteCommand(controller, credentialsIssuer), + ) +} + fun main(args: Array) { val controller = ChipDeviceController( ControllerParams.newBuilder() @@ -70,7 +79,7 @@ fun main(args: Array) { commandManager.register("discover", getDiscoveryCommands(controller, credentialsIssuer)) commandManager.register("pairing", getPairingCommands(controller, credentialsIssuer)) - + commandManager.register("im", getImCommands(controller, credentialsIssuer)) try { commandManager.run(args) } catch (e: Exception) { diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java index a5ee564e6bec9b..e501ec1afe81a4 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java @@ -56,10 +56,13 @@ public synchronized void waitResult() { } catch (InterruptedException e) { } } - if (!realResult.get().getResult()) { logger.log(Level.INFO, "error: %s", realResult.get().getError()); throw new RuntimeException("received failure test result"); } } + + public synchronized void clear() { + realResult = Optional.empty(); + } } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.java index 4d958c47e2f316..6af420375e2f8c 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.java @@ -102,16 +102,20 @@ public void run() throws Exception { protected abstract void runCommand(); - public void setSuccess() { + public final void setSuccess() { mFutureResult.setRealResult(RealResult.Success()); } - public void setFailure(String error) { + public final void setFailure(String error) { mFutureResult.setRealResult(RealResult.Error(error)); } - public void waitCompleteMs(long timeoutMs) { + public final void waitCompleteMs(long timeoutMs) { mFutureResult.setTimeoutMs(timeoutMs); mFutureResult.waitResult(); } + + public final void clear() { + mFutureResult.clear(); + } } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java new file mode 100644 index 00000000000000..f63b995610ec38 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java @@ -0,0 +1,99 @@ +package com.matter.controller.commands.pairing; + +import chip.devicecontroller.ChipDeviceController; +import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback; +import chip.devicecontroller.WriteAttributesCallback; +import chip.devicecontroller.model.AttributeWriteRequest; +import chip.devicecontroller.model.ChipAttributePath; +import com.matter.controller.commands.common.CredentialsIssuer; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +public final class PairOnNetworkLongImWriteCommand extends PairingCommand { + private static final int MATTER_PORT = 5540; + private long devicePointer; + private static final int CLUSTER_ID_BASIC = 0x0028; + private static final int ATTR_ID_LOCAL_CONFIG_DISABLED = 16; + private static Logger logger = Logger.getLogger(PairOnNetworkLongImWriteCommand.class.getName()); + + private void setDevicePointer(long devicePointer) { + this.devicePointer = devicePointer; + } + + private class InternalWriteAttributesCallback implements WriteAttributesCallback { + @Override + public void onError(@Nullable ChipAttributePath attributePath, Exception e) { + logger.log(Level.INFO, "Write receive onError on "); + if (attributePath != null) { + logger.log(Level.INFO, attributePath.toString()); + } + + setFailure("write failure"); + } + + @Override + public void onResponse(ChipAttributePath attributePath) { + logger.log(Level.INFO, "Write receve OnResponse on "); + if (attributePath != null) { + logger.log(Level.INFO, attributePath.toString()); + } + setSuccess(); + } + } + + private class InternalGetConnectedDeviceCallback implements GetConnectedDeviceCallback { + @Override + public void onDeviceConnected(long devicePointer) { + setDevicePointer(devicePointer); + logger.log(Level.INFO, "onDeviceConnected"); + } + + @Override + public void onConnectionFailure(long nodeId, Exception error) { + logger.log(Level.INFO, "onConnectionFailure"); + } + } + + public PairOnNetworkLongImWriteCommand( + ChipDeviceController controller, CredentialsIssuer credsIssue) { + super( + controller, + "onnetwork-long-im-write", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + DiscoveryFilterType.LONG_DISCRIMINATOR); + } + + @Override + protected void runCommand() { + // boolean true for tlv + byte[] booleanTLV = {0x09}; + AttributeWriteRequest attribute = + AttributeWriteRequest.newInstance( + /* endpointId= */ 0, CLUSTER_ID_BASIC, ATTR_ID_LOCAL_CONFIG_DISABLED, booleanTLV); + ArrayList attributeList = new ArrayList<>(); + attributeList.add(attribute); + + currentCommissioner() + .pairDeviceWithAddress( + getNodeId(), + getRemoteAddr().getHostAddress(), + MATTER_PORT, + getDiscriminator(), + getSetupPINCode(), + null); + currentCommissioner().setCompletionListener(this); + waitCompleteMs(getTimeoutMillis()); + currentCommissioner() + .getConnectedDevicePointer(getNodeId(), new InternalGetConnectedDeviceCallback()); + clear(); + + currentCommissioner() + .write(new InternalWriteAttributesCallback(), devicePointer, attributeList, 0, 0); + + waitCompleteMs(getTimeoutMillis()); + } +} diff --git a/src/controller/java/AndroidCallbacks-JNI.cpp b/src/controller/java/AndroidCallbacks-JNI.cpp index 63b2a6306b9810..c3f1dbeaee675d 100644 --- a/src/controller/java/AndroidCallbacks-JNI.cpp +++ b/src/controller/java/AndroidCallbacks-JNI.cpp @@ -70,3 +70,18 @@ JNI_METHOD(void, ReportEventCallbackJni, deleteCallback)(JNIEnv * env, jobject s VerifyOrReturn(reportCallback != nullptr, ChipLogError(Controller, "ReportCallback handle is nullptr")); delete reportCallback; } + +JNI_METHOD(jlong, WriteAttributesCallbackJni, newCallback) +(JNIEnv * env, jobject self, jobject writeAttributesCallbackJava) +{ + WriteAttributesCallback * writeAttributesCallback = + chip::Platform::New(self, writeAttributesCallbackJava); + return reinterpret_cast(writeAttributesCallback); +} + +JNI_METHOD(void, WriteAttributesCallbackJni, deleteCallback)(JNIEnv * env, jobject self, jlong callbackHandle) +{ + WriteAttributesCallback * writeAttributesCallback = reinterpret_cast(callbackHandle); + VerifyOrReturn(writeAttributesCallback != nullptr, ChipLogError(Controller, "WriteAttributesCallback handle is nullptr")); + delete writeAttributesCallback; +} diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index 17635bae335d09..573ed47a4535b9 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -83,6 +83,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectedFn(void * context, Messaging:: OperationalDeviceProxy * device = new OperationalDeviceProxy(&exchangeMgr, sessionHandle); DeviceLayer::StackUnlock unlock; env->CallVoidMethod(javaCallback, successMethod, reinterpret_cast(device)); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); } void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) @@ -118,6 +119,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, con DeviceLayer::StackUnlock unlock; env->CallVoidMethod(javaCallback, failureMethod, peerId.GetNodeId(), exception); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); } ReportCallback::ReportCallback(jobject wrapperCallback, jobject subscriptionEstablishedCallback, jobject reportCallback, @@ -200,6 +202,7 @@ void ReportCallback::OnReportEnd() DeviceLayer::StackUnlock unlock; env->CallVoidMethod(mReportCallbackRef, onReportMethod, mNodeStateObj); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); } void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, @@ -398,7 +401,7 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); } -CHIP_ERROR ReportCallback::CreateChipAttributePath(const app::ConcreteDataAttributePath & aPath, jobject & outObj) +CHIP_ERROR CreateChipAttributePath(const app::ConcreteDataAttributePath & aPath, jobject & outObj) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); CHIP_ERROR err = CHIP_NO_ERROR; @@ -455,7 +458,7 @@ void ReportCallback::OnDone(app::ReadClient *) DeviceLayer::StackUnlock unlock; env->CallVoidMethod(mReportCallbackRef, onDoneMethod); - + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); JniReferences::GetInstance().GetEnvForCurrentThread()->DeleteGlobalRef(mWrapperCallbackRef); } @@ -479,7 +482,7 @@ CHIP_ERROR ReportCallback::OnResubscriptionNeeded(app::ReadClient * apReadClient DeviceLayer::StackUnlock unlock; env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, aTerminationCause.AsInteger(), apReadClient->ComputeTimeTillNextSubscription()); - + VerifyOrReturnError(!env->ExceptionCheck(), CHIP_JNI_ERROR_EXCEPTION_THROWN); return CHIP_NO_ERROR; } @@ -512,6 +515,7 @@ void ReportCallback::ReportError(jobject attributePath, jobject eventPath, const DeviceLayer::StackUnlock unlock; env->CallVoidMethod(mReportCallbackRef, onErrorMethod, attributePath, eventPath, exception); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); } ReportEventCallback::ReportEventCallback(jobject wrapperCallback, jobject subscriptionEstablishedCallback, jobject reportCallback, @@ -762,5 +766,111 @@ void ReportEventCallback::ReportError(jobject eventPath, const char * message, C env->CallVoidMethod(mReportCallbackRef, onErrorMethod, eventPath, exception); } +WriteAttributesCallback::WriteAttributesCallback(jobject wrapperCallback, jobject javaCallback) : mChunkedWriteCallback(this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); + + mWrapperCallbackRef = env->NewGlobalRef(wrapperCallback); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); + if (mWrapperCallbackRef == nullptr) + { + ChipLogError(Controller, "Could not create global reference for Wrapper WriteAttributesCallback"); + } + mJavaCallbackRef = env->NewGlobalRef(javaCallback); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); + if (mJavaCallbackRef == nullptr) + { + ChipLogError(Controller, "Could not create global reference for Java WriteAttributesCallback"); + } +} + +WriteAttributesCallback::~WriteAttributesCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); + env->DeleteGlobalRef(mJavaCallbackRef); + if (mWriteClient != nullptr) + { + Platform::Delete(mWriteClient); + } +} + +void WriteAttributesCallback::OnResponse(const app::WriteClient * apWriteClient, const app::ConcreteDataAttributePath & aPath, + app::StatusIB aStatus) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject attributePathObj = nullptr; + err = CreateChipAttributePath(aPath, attributePathObj); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create Java ChipAttributePath: %s", ErrorStr(err))); + + if (aStatus.mStatus != Protocols::InteractionModel::Status::Success) + { + ReportError(attributePathObj, aStatus.mStatus); + return; + } + + jmethodID onResponseMethod; + err = JniReferences::GetInstance().FindMethod(env, mJavaCallbackRef, "onResponse", + "(Lchip/devicecontroller/model/ChipAttributePath;)V", &onResponseMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to find onError method: %s", ErrorStr(err))); + + DeviceLayer::StackUnlock unlock; + env->CallVoidMethod(mJavaCallbackRef, onResponseMethod, attributePathObj); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); +} + +void WriteAttributesCallback::OnError(const app::WriteClient * apWriteClient, CHIP_ERROR aError) +{ + ReportError(nullptr, aError); +} + +void WriteAttributesCallback::OnDone(app::WriteClient *) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + + jmethodID onDoneMethod; + err = JniReferences::GetInstance().FindMethod(env, mJavaCallbackRef, "onDone", "()V", &onDoneMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onDone method")); + + DeviceLayer::StackUnlock unlock; + env->CallVoidMethod(mJavaCallbackRef, onDoneMethod); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); + JniReferences::GetInstance().GetEnvForCurrentThread()->DeleteGlobalRef(mWrapperCallbackRef); +} + +void WriteAttributesCallback::ReportError(jobject attributePath, CHIP_ERROR err) +{ + ReportError(attributePath, ErrorStr(err), err.AsInteger()); +} + +void WriteAttributesCallback::ReportError(jobject attributePath, Protocols::InteractionModel::Status status) +{ + ReportError(attributePath, "IM Status", static_cast>(status)); +} + +void WriteAttributesCallback::ReportError(jobject attributePath, const char * message, ChipError::StorageType errorCode) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + + ChipLogError(Controller, "ReportError is called"); + jthrowable exception; + err = AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, message, errorCode, exception); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create IllegalStateException: %s", ErrorStr(err))); + + jmethodID onErrorMethod; + err = JniReferences::GetInstance().FindMethod(env, mJavaCallbackRef, "onError", + "(Lchip/devicecontroller/model/ChipAttributePath;Ljava/lang/Exception;)V", + &onErrorMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to find onError method: %s", ErrorStr(err))); + + DeviceLayer::StackUnlock unlock; + env->CallVoidMethod(mJavaCallbackRef, onErrorMethod, attributePath, exception); + VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe()); +} + } // namespace Controller } // namespace chip diff --git a/src/controller/java/AndroidCallbacks.h b/src/controller/java/AndroidCallbacks.h index cd7fdfd201265b..8d6c44e7c5a55d 100644 --- a/src/controller/java/AndroidCallbacks.h +++ b/src/controller/java/AndroidCallbacks.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,8 @@ namespace chip { namespace Controller { +CHIP_ERROR CreateChipAttributePath(const app::ConcreteDataAttributePath & aPath, jobject & outObj); + // Callback for success and failure cases of GetConnectedDevice(). struct GetConnectedDeviceCallback { @@ -70,8 +73,6 @@ struct ReportCallback : public app::ClusterStateCache::Callback void ReportError(jobject attributePath, jobject eventPath, Protocols::InteractionModel::Status status); void ReportError(jobject attributePath, jobject eventPath, const char * message, ChipError::StorageType errorCode); - CHIP_ERROR CreateChipAttributePath(const app::ConcreteDataAttributePath & aPath, jobject & outObj); - CHIP_ERROR CreateChipEventPath(const app::ConcreteEventPath & aPath, jobject & outObj); void UpdateClusterDataVersion(); @@ -128,5 +129,28 @@ struct ReportEventCallback : public app::ReadClient::Callback jclass mNodeStateCls = nullptr; }; +struct WriteAttributesCallback : public app::WriteClient::Callback +{ + WriteAttributesCallback(jobject wrapperCallback, jobject javaCallback); + ~WriteAttributesCallback(); + app::WriteClient::Callback * GetChunkedWriteCallback() { return &mChunkedWriteCallback; } + + void OnResponse(const app::WriteClient * apWriteClient, const app::ConcreteDataAttributePath & aPath, + app::StatusIB aStatus) override; + /** Report errors back to Java layer. attributePath may be nullptr for general errors. */ + void OnError(const app::WriteClient * apWriteClient, CHIP_ERROR aProtocolError) override; + + void OnDone(app::WriteClient * apWriteClient) override; + + void ReportError(jobject attributePath, CHIP_ERROR err); + void ReportError(jobject attributePath, Protocols::InteractionModel::Status status); + void ReportError(jobject attributePath, const char * message, ChipError::StorageType errorCode); + + app::WriteClient * mWriteClient = nullptr; + app::ChunkedWriteCallback mChunkedWriteCallback; + jobject mWrapperCallbackRef = nullptr; + jobject mJavaCallbackRef = nullptr; +}; + } // namespace Controller } // namespace chip diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 840d468ba7a597..017696c7f6d95a 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -196,7 +196,10 @@ android_library("java") { "src/chip/devicecontroller/ResubscriptionAttemptCallback.java", "src/chip/devicecontroller/SubscriptionEstablishedCallback.java", "src/chip/devicecontroller/UnpairDeviceCallback.java", + "src/chip/devicecontroller/WriteAttributesCallback.java", + "src/chip/devicecontroller/WriteAttributesCallbackJni.java", "src/chip/devicecontroller/model/AttributeState.java", + "src/chip/devicecontroller/model/AttributeWriteRequest.java", "src/chip/devicecontroller/model/ChipAttributePath.java", "src/chip/devicecontroller/model/ChipEventPath.java", "src/chip/devicecontroller/model/ChipPathId.java", diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 5da3d86ff4be04..1c15204c6f394a 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1355,6 +1356,131 @@ JNI_METHOD(void, read) callback->mReadClient = readClient; } +JNI_METHOD(void, write) +(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributeList, jint timedRequestTimeoutMs, + jint imTimeoutMs) +{ + chip::DeviceLayer::StackLock lock; + CHIP_ERROR err = CHIP_NO_ERROR; + jint listSize = 0; + auto callback = reinterpret_cast(callbackHandle); + app::WriteClient * writeClient; + + ChipLogDetail(Controller, "IM write() called"); + + DeviceProxy * device = reinterpret_cast(devicePtr); + VerifyOrExit(device != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrExit(device->GetSecureSession().HasValue(), err = CHIP_ERROR_MISSING_SECURE_SESSION); + VerifyOrExit(attributeList != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + SuccessOrExit(JniReferences::GetInstance().GetListSize(attributeList, listSize)); + + writeClient = Platform::New(device->GetExchangeManager(), callback->GetChunkedWriteCallback(), + timedRequestTimeoutMs != 0 ? Optional(timedRequestTimeoutMs) + : Optional::Missing()); + + for (uint8_t i = 0; i < listSize; i++) + { + jobject attributeItem = nullptr; + uint32_t endpointId = 0; + uint32_t clusterId = 0; + uint32_t attributeId = 0; + jmethodID getEndpointIdMethod = nullptr; + jmethodID getClusterIdMethod = nullptr; + jmethodID getAttributeIdMethod = nullptr; + jmethodID hasDataVersionMethod = nullptr; + jmethodID getDataVersionMethod = nullptr; + jmethodID getTlvByteArrayMethod = nullptr; + jobject endpointIdObj = nullptr; + jobject clusterIdObj = nullptr; + jobject attributeIdObj = nullptr; + jbyteArray tlvBytesObj = nullptr; + bool hasDataVersion = false; + Optional dataVersion = Optional(); + ; + jbyte * tlvBytesObjBytes = nullptr; + jsize length = 0; + TLV::TLVReader reader; + + SuccessOrExit(JniReferences::GetInstance().GetListItem(attributeList, i, attributeItem)); + SuccessOrExit(JniReferences::GetInstance().FindMethod(env, attributeItem, "getEndpointId", + "()Lchip/devicecontroller/model/ChipPathId;", &getEndpointIdMethod)); + SuccessOrExit(JniReferences::GetInstance().FindMethod(env, attributeItem, "getClusterId", + "()Lchip/devicecontroller/model/ChipPathId;", &getClusterIdMethod)); + SuccessOrExit(JniReferences::GetInstance().FindMethod(env, attributeItem, "getAttributeId", + "()Lchip/devicecontroller/model/ChipPathId;", &getAttributeIdMethod)); + SuccessOrExit(JniReferences::GetInstance().FindMethod(env, attributeItem, "hasDataVersion", "()Z", &hasDataVersionMethod)); + SuccessOrExit(JniReferences::GetInstance().FindMethod(env, attributeItem, "getDataVersion", "()I", &getDataVersionMethod)); + SuccessOrExit( + JniReferences::GetInstance().FindMethod(env, attributeItem, "getTlvByteArray", "()[B", &getTlvByteArrayMethod)); + + endpointIdObj = env->CallObjectMethod(attributeItem, getEndpointIdMethod); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VerifyOrExit(endpointIdObj != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + + clusterIdObj = env->CallObjectMethod(attributeItem, getClusterIdMethod); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VerifyOrExit(clusterIdObj != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + + attributeIdObj = env->CallObjectMethod(attributeItem, getAttributeIdMethod); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VerifyOrExit(attributeIdObj != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + + SuccessOrExit(GetChipPathIdValue(endpointIdObj, kInvalidEndpointId, endpointId)); + SuccessOrExit(GetChipPathIdValue(clusterIdObj, kInvalidClusterId, clusterId)); + SuccessOrExit(GetChipPathIdValue(attributeIdObj, kInvalidAttributeId, attributeId)); + + hasDataVersion = static_cast(env->CallBooleanMethod(attributeItem, hasDataVersionMethod)); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + if (hasDataVersion) + { + DataVersion dataVersionVal = static_cast(env->CallIntMethod(attributeItem, getDataVersionMethod)); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + dataVersion.SetValue(dataVersionVal); + } + + tlvBytesObj = static_cast(env->CallObjectMethod(attributeItem, getTlvByteArrayMethod)); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + VerifyOrExit(tlvBytesObj != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + + tlvBytesObjBytes = env->GetByteArrayElements(tlvBytesObj, nullptr); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + length = env->GetArrayLength(tlvBytesObj); + VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN); + + reader.Init(reinterpret_cast(tlvBytesObjBytes), static_cast(length)); + reader.Next(); + SuccessOrExit( + err = writeClient->PutPreencodedAttribute( + chip::app::ConcreteDataAttributePath(static_cast(endpointId), static_cast(clusterId), + static_cast(attributeId), dataVersion), + reader)); + } + + err = writeClient->SendWriteRequest(device->GetSecureSession().Value(), + imTimeoutMs != 0 ? System::Clock::Milliseconds32(imTimeoutMs) : System::Clock::kZero); + if (err != CHIP_NO_ERROR) + { + callback->OnError(writeClient, err); + delete writeClient; + delete callback; + return; + } + + callback->mWriteClient = writeClient; + +exit: + if (err == CHIP_JNI_ERROR_EXCEPTION_THROWN) + { + ChipLogError(DeviceLayer, "Java exception in IM Write JNI"); + env->ExceptionDescribe(); + env->ExceptionClear(); + } + if (err != CHIP_NO_ERROR) + { + JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err); + } +} + /** * Takes objects in attributePathList, converts them to app:AttributePathParams, and appends them to outAttributePathParamsList. */ @@ -1520,13 +1646,16 @@ CHIP_ERROR IsWildcardChipPathId(jobject chipPathId, bool & isWildcard) env, chipPathId, "getType", "()Lchip/devicecontroller/model/ChipPathId$IdType;", &getTypeMethod)); jobject idType = env->CallObjectMethod(chipPathId, getTypeMethod); + VerifyOrReturnError(!env->ExceptionCheck(), CHIP_JNI_ERROR_EXCEPTION_THROWN); VerifyOrReturnError(idType != nullptr, CHIP_JNI_ERROR_NULL_OBJECT); jmethodID nameMethod = nullptr; ReturnErrorOnFailure(JniReferences::GetInstance().FindMethod(env, idType, "name", "()Ljava/lang/String;", &nameMethod)); jstring typeNameString = static_cast(env->CallObjectMethod(idType, nameMethod)); + VerifyOrReturnError(!env->ExceptionCheck(), CHIP_JNI_ERROR_EXCEPTION_THROWN); VerifyOrReturnError(typeNameString != nullptr, CHIP_JNI_ERROR_NULL_OBJECT); + JniUtfString typeNameJniString(env, typeNameString); isWildcard = strncmp(typeNameJniString.c_str(), "WILDCARD", 8) == 0; diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 8775e687f3f0f5..fbe2f172d8786c 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -20,6 +20,7 @@ import android.bluetooth.BluetoothGatt; import android.util.Log; import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback; +import chip.devicecontroller.model.AttributeWriteRequest; import chip.devicecontroller.model.ChipAttributePath; import chip.devicecontroller.model.ChipEventPath; import java.util.ArrayList; @@ -599,6 +600,32 @@ public void readPath( isFabricFiltered); } + /** + * @brief Write a list of attributes into target device + * @param WriteAttributesCallback Callback when a write response has been received and processed + * for the given path. + * @param devicePtr connected device pointer + * @param attributeList a list of attributes + * @param timedRequestTimeoutMs this is timed request if this value is larger than 0 + * @param imTimeoutMs im interaction time out value, it would override the default value in c++ im + * layer if this value is non-zero. + */ + public void write( + WriteAttributesCallback callback, + long devicePtr, + List attributeList, + int timedRequestTimeoutMs, + int imTimeoutMs) { + WriteAttributesCallbackJni jniCallback = new WriteAttributesCallbackJni(callback); + write( + deviceControllerPtr, + jniCallback.getCallbackHandle(), + devicePtr, + attributeList, + timedRequestTimeoutMs, + imTimeoutMs); + } + /** * Converts a given X.509v3 certificate into a Matter certificate. * @@ -646,6 +673,14 @@ private native void read( List eventPaths, boolean isFabricFiltered); + private native void write( + long deviceControllerPtr, + long callbackHandle, + long devicePtr, + List attributeList, + int timedRequestTimeoutMs, + int imTimeoutMs); + private native long newDeviceController(ControllerParams params); private native void setDeviceAttestationDelegate( diff --git a/src/controller/java/src/chip/devicecontroller/WriteAttributesCallback.java b/src/controller/java/src/chip/devicecontroller/WriteAttributesCallback.java new file mode 100644 index 00000000000000..4e469ab0e58245 --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/WriteAttributesCallback.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package chip.devicecontroller; + +import chip.devicecontroller.model.ChipAttributePath; +import javax.annotation.Nullable; + +/** An interface for receiving write response. */ +public interface WriteAttributesCallback { + + /** + * OnError will be called when an error occurs after failing to write + * + * @param attributePath The attribute path field + * @param Exception The IllegalStateException which encapsulated the error message, the possible + * chip error could be CHIP_ERROR_TIMEOUT: A response was not received within the expected + * response timeout. - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from + * the server. - CHIP_ERROR encapsulating the converted error from the StatusIB: If we got a + * non-path-specific status response from the server. CHIP_ERROR*: All other cases. + */ + void onError(@Nullable ChipAttributePath attributePath, Exception e); + + /** + * OnResponse will be called when a write response has been received and processed for the given + * path. + * + * @param attributePath The attribute path field in write response. + */ + void onResponse(ChipAttributePath attributePath); + + default void onDone() {} +} diff --git a/src/controller/java/src/chip/devicecontroller/WriteAttributesCallbackJni.java b/src/controller/java/src/chip/devicecontroller/WriteAttributesCallbackJni.java new file mode 100644 index 00000000000000..fb7d7136ed0572 --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/WriteAttributesCallbackJni.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package chip.devicecontroller; + +/** JNI wrapper callback class for {@link WriteAttributesCallback}. */ +public class WriteAttributesCallbackJni { + private final WriteAttributesCallback wrappedWriteAttributesCallback; + private long callbackHandle; + + public WriteAttributesCallbackJni(WriteAttributesCallback wrappedWriteAttributesCallback) { + this.wrappedWriteAttributesCallback = wrappedWriteAttributesCallback; + this.callbackHandle = newCallback(wrappedWriteAttributesCallback); + } + + long getCallbackHandle() { + return callbackHandle; + } + + private native long newCallback(WriteAttributesCallback wrappedCallback); + + private native void deleteCallback(long callbackHandle); + + // TODO(#8578): Replace finalizer with PhantomReference. + @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + + if (callbackHandle != 0) { + deleteCallback(callbackHandle); + callbackHandle = 0; + } + } +} diff --git a/src/controller/java/src/chip/devicecontroller/model/AttributeWriteRequest.java b/src/controller/java/src/chip/devicecontroller/model/AttributeWriteRequest.java new file mode 100644 index 00000000000000..b479076e13e40a --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/model/AttributeWriteRequest.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package chip.devicecontroller.model; + +import java.util.Locale; +import java.util.Objects; +import java.util.Optional; + +/** An attribute write request that should be used for interaction model write interaction. */ +public final class AttributeWriteRequest { + private final ChipPathId endpointId, clusterId, attributeId; + private final Optional dataVersion; + private final byte[] tlv; + + private AttributeWriteRequest( + ChipPathId endpointId, + ChipPathId clusterId, + ChipPathId attributeId, + byte[] tlv, + Optional dataVersion) { + this.endpointId = endpointId; + this.clusterId = clusterId; + this.attributeId = attributeId; + this.tlv = tlv.clone(); + this.dataVersion = dataVersion; + } + + public ChipPathId getEndpointId() { + return endpointId; + } + + public ChipPathId getClusterId() { + return clusterId; + } + + public ChipPathId getAttributeId() { + return attributeId; + } + + public int getDataVersion() { + return dataVersion.orElse(0); + } + + public boolean hasDataVersion() { + return dataVersion.isPresent(); + } + + public byte[] getTlvByteArray() { + return tlv.clone(); + } + + // check whether the current AttributeWriteRequest has same path as others. + @Override + public boolean equals(Object object) { + if (object instanceof AttributeWriteRequest) { + AttributeWriteRequest that = (AttributeWriteRequest) object; + return Objects.equals(this.endpointId, that.endpointId) + && Objects.equals(this.clusterId, that.clusterId) + && Objects.equals(this.attributeId, that.attributeId); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(endpointId, clusterId, attributeId); + } + + @Override + public String toString() { + return String.format( + Locale.ENGLISH, + "Endpoint %s, cluster %s, attribute %s", + endpointId, + clusterId, + attributeId); + } + + public static AttributeWriteRequest newInstance( + ChipPathId endpointId, ChipPathId clusterId, ChipPathId attributeId, byte[] tlv) { + return new AttributeWriteRequest(endpointId, clusterId, attributeId, tlv, Optional.empty()); + } + + public static AttributeWriteRequest newInstance( + ChipPathId endpointId, + ChipPathId clusterId, + ChipPathId attributeId, + byte[] tlv, + Optional dataVersion) { + return new AttributeWriteRequest(endpointId, clusterId, attributeId, tlv, dataVersion); + } + + /** Create a new {@link AttributeWriteRequest} with only concrete ids. */ + public static AttributeWriteRequest newInstance( + long endpointId, long clusterId, long attributeId, byte[] tlv) { + return new AttributeWriteRequest( + ChipPathId.forId(endpointId), + ChipPathId.forId(clusterId), + ChipPathId.forId(attributeId), + tlv, + Optional.empty()); + } + + public static AttributeWriteRequest newInstance( + long endpointId, + long clusterId, + long attributeId, + byte[] tlv, + Optional dataVersion) { + return new AttributeWriteRequest( + ChipPathId.forId(endpointId), + ChipPathId.forId(clusterId), + ChipPathId.forId(attributeId), + tlv, + dataVersion); + } +} From 105b98b99e3ed92f9e294c23cb876c83ff37085d Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 3 Mar 2023 17:08:29 -0500 Subject: [PATCH 08/10] Switch back to 6.44 for cloudbuild as nrf NCS revision is not matching (#25469) --- integrations/cloudbuild/smoke-test.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/integrations/cloudbuild/smoke-test.yaml b/integrations/cloudbuild/smoke-test.yaml index 1ee1aa7b7cc431..5b2a39ae9322a2 100644 --- a/integrations/cloudbuild/smoke-test.yaml +++ b/integrations/cloudbuild/smoke-test.yaml @@ -1,5 +1,5 @@ steps: - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" entrypoint: "bash" args: - "-c" @@ -7,7 +7,7 @@ steps: git config --global --add safe.directory "*" git submodule update --init --recursive id: Submodules - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" env: - PW_ENVIRONMENT_ROOT=/pwenv args: @@ -22,7 +22,7 @@ steps: path: /pwenv timeout: 900s - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" id: ESP32 env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -40,7 +40,7 @@ steps: volumes: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" id: NRFConnect env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -61,7 +61,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" id: EFR32 env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -83,7 +83,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" id: Linux env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -143,7 +143,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.6.47" + - name: "connectedhomeip/chip-build-vscode:0.6.44" id: Android env: - PW_ENVIRONMENT_ROOT=/pwenv From aa99d09ed087a38c11ce251a2079ab14fdfdd75f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 3 Mar 2023 22:10:46 -0500 Subject: [PATCH 09/10] Restore the ability to turn off event UTC timestamps at compile time. (#25281) * Adds CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS and sets it when CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS used to be set. * Removes src/lib/core/CHIPEventLoggingConfig.h, which only contains unused (never read) defines, and places where those defines are set. * Enables CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS on Darwin and Linux. --- config/python/CHIPProjectConfig.h | 2 - config/standalone/CHIPProjectConfig.h | 2 - .../nxp/mw320/include/CHIPProjectConfig.h | 7 ++ .../chef/efr32/include/CHIPProjectConfig.h | 7 ++ .../chip-tool/include/CHIPProjectAppConfig.h | 2 - .../include/CHIPProjectAppConfig.h | 2 - .../genio/include/CHIPProjectConfig.h | 7 ++ .../SiWx917/include/CHIPProjectConfig.h | 7 ++ .../silabs/efr32/include/CHIPProjectConfig.h | 7 ++ .../bouffalolab/bl702/CHIPProjectConfig.h | 7 ++ .../genio/include/CHIPProjectConfig.h | 7 ++ .../psoc6/include/CHIPProjectConfig.h | 7 ++ .../SiWx917/include/CHIPProjectConfig.h | 7 ++ .../silabs/efr32/include/CHIPProjectConfig.h | 7 ++ .../cc32xx/main/include/CHIPProjectConfig.h | 7 ++ .../genio/include/CHIPProjectConfig.h | 7 ++ .../SiWx917/include/CHIPProjectConfig.h | 7 ++ .../silabs/efr32/include/CHIPProjectConfig.h | 7 ++ .../genio/include/CHIPProjectConfig.h | 7 ++ .../psoc6/include/CHIPProjectConfig.h | 7 ++ .../shell/genio/include/CHIPProjectConfig.h | 7 ++ .../genio/include/CHIPProjectConfig.h | 7 ++ .../silabs/efr32/include/CHIPProjectConfig.h | 7 ++ .../SiWx917/include/CHIPProjectConfig.h | 7 ++ .../silabs/efr32/include/CHIPProjectConfig.h | 7 ++ src/app/EventManagement.cpp | 4 +- src/app/EventManagement.h | 7 +- src/include/platform/CHIPDeviceConfig.h | 10 +++ src/lib/core/BUILD.gn | 5 +- src/lib/core/CHIPEventLoggingConfig.h | 70 ------------------- src/lib/support/CHIPFaultInjection.h | 1 - .../Darwin/CHIPDevicePlatformConfig.h | 4 ++ src/platform/Linux/CHIPDevicePlatformConfig.h | 4 ++ .../efr32/include/CHIPProjectConfig.h | 7 ++ 34 files changed, 182 insertions(+), 85 deletions(-) delete mode 100644 src/lib/core/CHIPEventLoggingConfig.h diff --git a/config/python/CHIPProjectConfig.h b/config/python/CHIPProjectConfig.h index c9bb77021fa1e4..87940a900ce991 100644 --- a/config/python/CHIPProjectConfig.h +++ b/config/python/CHIPProjectConfig.h @@ -25,8 +25,6 @@ #define CHIP_CONFIG_EVENT_LOGGING_NUM_EXTERNAL_CALLBACKS 2 -#define CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT 1 - // Uncomment this for a large Tunnel MTU. //#define CHIP_CONFIG_TUNNEL_INTERFACE_MTU (9000) diff --git a/config/standalone/CHIPProjectConfig.h b/config/standalone/CHIPProjectConfig.h index 101bdec25e1cd4..27abcbb247b322 100644 --- a/config/standalone/CHIPProjectConfig.h +++ b/config/standalone/CHIPProjectConfig.h @@ -26,8 +26,6 @@ #define CHIP_CONFIG_EVENT_LOGGING_NUM_EXTERNAL_CALLBACKS 2 -#define CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT 1 - // Uncomment this for a large Tunnel MTU. // #define CHIP_CONFIG_TUNNEL_INTERFACE_MTU (9000) diff --git a/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h b/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h index 952693439ea5a5..a966f6407dba3a 100644 --- a/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h +++ b/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h @@ -174,6 +174,13 @@ */ #define CHIP_CONFIG_EVENT_LOGGING_WDM_OFFLOAD 1 +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/chef/efr32/include/CHIPProjectConfig.h b/examples/chef/efr32/include/CHIPProjectConfig.h index 7bd7de17f4293e..75c8d194f8f319 100644 --- a/examples/chef/efr32/include/CHIPProjectConfig.h +++ b/examples/chef/efr32/include/CHIPProjectConfig.h @@ -94,6 +94,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/chip-tool/include/CHIPProjectAppConfig.h b/examples/chip-tool/include/CHIPProjectAppConfig.h index 31c4db024b9117..36ce69c2007feb 100644 --- a/examples/chip-tool/include/CHIPProjectAppConfig.h +++ b/examples/chip-tool/include/CHIPProjectAppConfig.h @@ -27,8 +27,6 @@ #define CHIP_CONFIG_EVENT_LOGGING_NUM_EXTERNAL_CALLBACKS 2 -#define CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT 1 - // Uncomment this for a large Tunnel MTU. //#define CHIP_CONFIG_TUNNEL_INTERFACE_MTU (9000) diff --git a/examples/java-matter-controller/include/CHIPProjectAppConfig.h b/examples/java-matter-controller/include/CHIPProjectAppConfig.h index 7b8128a9dd2f76..dd3a009f81d785 100644 --- a/examples/java-matter-controller/include/CHIPProjectAppConfig.h +++ b/examples/java-matter-controller/include/CHIPProjectAppConfig.h @@ -27,8 +27,6 @@ #define CHIP_CONFIG_EVENT_LOGGING_NUM_EXTERNAL_CALLBACKS 2 -#define CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT 1 - // Enable support functions for parsing command-line arguments #define CHIP_CONFIG_ENABLE_ARG_PARSER 1 diff --git a/examples/light-switch-app/genio/include/CHIPProjectConfig.h b/examples/light-switch-app/genio/include/CHIPProjectConfig.h index 88176747684340..c314ebba41e617 100644 --- a/examples/light-switch-app/genio/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/genio/include/CHIPProjectConfig.h @@ -103,6 +103,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/light-switch-app/silabs/SiWx917/include/CHIPProjectConfig.h b/examples/light-switch-app/silabs/SiWx917/include/CHIPProjectConfig.h index 7bd7de17f4293e..75c8d194f8f319 100644 --- a/examples/light-switch-app/silabs/SiWx917/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/silabs/SiWx917/include/CHIPProjectConfig.h @@ -94,6 +94,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/light-switch-app/silabs/efr32/include/CHIPProjectConfig.h b/examples/light-switch-app/silabs/efr32/include/CHIPProjectConfig.h index 7bd7de17f4293e..75c8d194f8f319 100644 --- a/examples/light-switch-app/silabs/efr32/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/silabs/efr32/include/CHIPProjectConfig.h @@ -94,6 +94,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h index 23833bd5699f94..022ce8fa592e7a 100644 --- a/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h @@ -116,6 +116,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lighting-app/genio/include/CHIPProjectConfig.h b/examples/lighting-app/genio/include/CHIPProjectConfig.h index 7bb42a233fc0fa..dbdd8fcdbe350d 100644 --- a/examples/lighting-app/genio/include/CHIPProjectConfig.h +++ b/examples/lighting-app/genio/include/CHIPProjectConfig.h @@ -97,6 +97,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h b/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h index 23a5963fb48f87..fe4ba5c8fe87e4 100644 --- a/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h +++ b/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h @@ -110,6 +110,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h b/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h index 9131e8b89e4497..ff01045a6c6707 100644 --- a/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h +++ b/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h @@ -105,6 +105,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lighting-app/silabs/efr32/include/CHIPProjectConfig.h b/examples/lighting-app/silabs/efr32/include/CHIPProjectConfig.h index 177c41672f9da9..751ebfcff265f2 100644 --- a/examples/lighting-app/silabs/efr32/include/CHIPProjectConfig.h +++ b/examples/lighting-app/silabs/efr32/include/CHIPProjectConfig.h @@ -94,6 +94,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h b/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h index bf6cd7696b4ad5..4268330033b485 100644 --- a/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h +++ b/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h @@ -112,6 +112,13 @@ */ #define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0 +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lock-app/genio/include/CHIPProjectConfig.h b/examples/lock-app/genio/include/CHIPProjectConfig.h index 20c49c739b4108..65333f8b2b82d7 100644 --- a/examples/lock-app/genio/include/CHIPProjectConfig.h +++ b/examples/lock-app/genio/include/CHIPProjectConfig.h @@ -105,6 +105,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lock-app/silabs/SiWx917/include/CHIPProjectConfig.h b/examples/lock-app/silabs/SiWx917/include/CHIPProjectConfig.h index 9561c80fedd4a7..9ebace80dd06d2 100644 --- a/examples/lock-app/silabs/SiWx917/include/CHIPProjectConfig.h +++ b/examples/lock-app/silabs/SiWx917/include/CHIPProjectConfig.h @@ -95,6 +95,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/lock-app/silabs/efr32/include/CHIPProjectConfig.h b/examples/lock-app/silabs/efr32/include/CHIPProjectConfig.h index 9561c80fedd4a7..9ebace80dd06d2 100644 --- a/examples/lock-app/silabs/efr32/include/CHIPProjectConfig.h +++ b/examples/lock-app/silabs/efr32/include/CHIPProjectConfig.h @@ -95,6 +95,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h b/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h index 70fd19acbc284d..79395c5bb88a32 100644 --- a/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h +++ b/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h @@ -105,6 +105,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h b/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h index 7c949a6ee9cdec..900b0d10ef8ca6 100644 --- a/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h +++ b/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h @@ -87,6 +87,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/shell/genio/include/CHIPProjectConfig.h b/examples/shell/genio/include/CHIPProjectConfig.h index 9803c720557ab4..013d86f0b00708 100644 --- a/examples/shell/genio/include/CHIPProjectConfig.h +++ b/examples/shell/genio/include/CHIPProjectConfig.h @@ -92,6 +92,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/thermostat/genio/include/CHIPProjectConfig.h b/examples/thermostat/genio/include/CHIPProjectConfig.h index 60f6220c85ba9d..60b57de0cd7ae7 100644 --- a/examples/thermostat/genio/include/CHIPProjectConfig.h +++ b/examples/thermostat/genio/include/CHIPProjectConfig.h @@ -113,6 +113,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/thermostat/silabs/efr32/include/CHIPProjectConfig.h b/examples/thermostat/silabs/efr32/include/CHIPProjectConfig.h index abf9982a548b5c..8b26f650aa07a6 100644 --- a/examples/thermostat/silabs/efr32/include/CHIPProjectConfig.h +++ b/examples/thermostat/silabs/efr32/include/CHIPProjectConfig.h @@ -102,6 +102,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h b/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h index cb1464d4465a70..dbf46f0e39e6d7 100644 --- a/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h +++ b/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h @@ -93,6 +93,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/examples/window-app/silabs/efr32/include/CHIPProjectConfig.h b/examples/window-app/silabs/efr32/include/CHIPProjectConfig.h index cb1464d4465a70..dbf46f0e39e6d7 100644 --- a/examples/window-app/silabs/efr32/include/CHIPProjectConfig.h +++ b/examples/window-app/silabs/efr32/include/CHIPProjectConfig.h @@ -93,6 +93,13 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index e48d6d8037d782..e6abcc8b5721ad 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -428,7 +427,9 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c CircularTLVWriter checkpoint = writer; EventLoadOutContext ctxt = EventLoadOutContext(writer, aEventOptions.mPriority, mLastEventNumber); EventOptions opts; + Timestamp timestamp; +#if CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS System::Clock::Milliseconds64 utc_time; err = System::SystemClock().GetClock_RealTimeMS(utc_time); if (err == CHIP_NO_ERROR) @@ -436,6 +437,7 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c timestamp = Timestamp::Epoch(utc_time); } else +#endif // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS { auto systemTimeMs = System::SystemClock().GetMonotonicMilliseconds64() - mMonotonicStartupTime; timestamp = Timestamp::System(systemTimeMs); diff --git a/src/app/EventManagement.h b/src/app/EventManagement.h index 0622780195af39..fdaff6cd393fbc 100644 --- a/src/app/EventManagement.h +++ b/src/app/EventManagement.h @@ -36,6 +36,7 @@ #include #include #include +#include #include /** @@ -397,7 +398,11 @@ class EventManagement int mFieldsToRead = 0; /* PriorityLevel and DeltaTime are there if that is not first event when putting events in report*/ - Timestamp mCurrentTime = Timestamp::System(System::Clock::kZero); +#if CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + Timestamp mCurrentTime = Timestamp::System(System::Clock::kZero); +#else // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + Timestamp mCurrentTime = Timestamp::Epoch(System::Clock::kZero); +#endif // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS PriorityLevel mPriority = PriorityLevel::First; ClusterId mClusterId = 0; EndpointId mEndpointId = 0; diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 45db2624e773e7..e5a3b721869f07 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -1010,6 +1010,16 @@ #define CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH (0x10000) #endif +/** + * @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * @brief + * By default, don't record UTC timestamps. + */ +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 0 +#endif + // -------------------- Software Update Manager Configuration -------------------- /** diff --git a/src/lib/core/BUILD.gn b/src/lib/core/BUILD.gn index ef690b9bfbab5b..edff299efd8ea6 100644 --- a/src/lib/core/BUILD.gn +++ b/src/lib/core/BUILD.gn @@ -68,10 +68,7 @@ buildconfig_header("chip_buildconfig") { } source_set("chip_config_header") { - sources = [ - "CHIPConfig.h", - "CHIPEventLoggingConfig.h", - ] + sources = [ "CHIPConfig.h" ] public_configs = [ "${chip_root}/src:includes" ] diff --git a/src/lib/core/CHIPEventLoggingConfig.h b/src/lib/core/CHIPEventLoggingConfig.h deleted file mode 100644 index 1967728730a8e7..00000000000000 --- a/src/lib/core/CHIPEventLoggingConfig.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2016-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file defines compile time configuration of the Event Logging profile - */ - -#pragma once - -/** - * @def CHIP_CONFIG_EVENT_SIZE_RESERVE - * - * @brief - * Initial size to reserve for event. The logging subsystem ensures - * this space is available in the buffer before attempting to store - * the event. - */ -#ifndef CHIP_CONFIG_EVENT_SIZE_RESERVE -#define CHIP_CONFIG_EVENT_SIZE_RESERVE 196 -#endif /* CHIP_CONFIG_EVENT_SIZE_RESERVE */ - -/** - * @def CHIP_CONFIG_EVENT_SIZE_INCREMENT - * - * @brief - * When the initial reserved size proves insufficient, clean out the - * buffer in following increments. - */ -#ifndef CHIP_CONFIG_EVENT_SIZE_INCREMENT -#define CHIP_CONFIG_EVENT_SIZE_INCREMENT 8 -#endif /* CHIP_CONFIG_EVENT_SIZE_INCREMENT */ - -/** - * @def CHIP_CONFIG_EVENT_LOGGING_MAXIMUM_UPLOAD_SECONDS - * - * @brief - * The maximum time (in seconds) between log uploads. The - * system is guaranteed to attempt to offload the log buffer at - * least this often. The value is used to initialize chip - * LoggingConfiguration. This is only relevant for BDX uploads. - */ -#ifndef CHIP_CONFIG_EVENT_LOGGING_MAXIMUM_UPLOAD_SECONDS -#define CHIP_CONFIG_EVENT_LOGGING_MAXIMUM_UPLOAD_SECONDS 86400 -#endif - -/** - * @def CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT - * - * @brief - * Enable or disable support for externally managed event storage - */ -#ifndef CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT -#define CHIP_CONFIG_EVENT_LOGGING_EXTERNAL_EVENT_SUPPORT 0 -#endif diff --git a/src/lib/support/CHIPFaultInjection.h b/src/lib/support/CHIPFaultInjection.h index 06d94e2d9ed5ff..9fe78aed8c9ac9 100644 --- a/src/lib/support/CHIPFaultInjection.h +++ b/src/lib/support/CHIPFaultInjection.h @@ -24,7 +24,6 @@ #pragma once #include -#include #if CHIP_WITH_NLFAULTINJECTION diff --git a/src/platform/Darwin/CHIPDevicePlatformConfig.h b/src/platform/Darwin/CHIPDevicePlatformConfig.h index e63a0ac2f8bedc..8b4ee23eb78c9f 100644 --- a/src/platform/Darwin/CHIPDevicePlatformConfig.h +++ b/src/platform/Darwin/CHIPDevicePlatformConfig.h @@ -53,6 +53,10 @@ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 +#endif // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + // Reserve a single dynamic endpoint that we can use to host things like OTA // Provider server. #if !defined(CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) || CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT == 0 diff --git a/src/platform/Linux/CHIPDevicePlatformConfig.h b/src/platform/Linux/CHIPDevicePlatformConfig.h index 4e4c8ca0ec7d32..9a316d4832348b 100644 --- a/src/platform/Linux/CHIPDevicePlatformConfig.h +++ b/src/platform/Linux/CHIPDevicePlatformConfig.h @@ -64,6 +64,10 @@ #define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 #endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 +#endif // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 diff --git a/src/test_driver/efr32/include/CHIPProjectConfig.h b/src/test_driver/efr32/include/CHIPProjectConfig.h index 2c3645e1f556d4..1ab7ef5879b3f5 100644 --- a/src/test_driver/efr32/include/CHIPProjectConfig.h +++ b/src/test_driver/efr32/include/CHIPProjectConfig.h @@ -80,6 +80,13 @@ */ #define CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER "DUMMY_SN" +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + /** * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE * From 32fb896f3075418f1dc6d920a90376a1aa3cf239 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Sat, 4 Mar 2023 12:20:16 -0800 Subject: [PATCH 10/10] add invoke request in java controoler (#25470) --- src/controller/java/BUILD.gn | 1 + .../devicecontroller/model/InvokeElement.java | 89 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/controller/java/src/chip/devicecontroller/model/InvokeElement.java diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 017696c7f6d95a..9e2faa6ef2a9ce 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -206,6 +206,7 @@ android_library("java") { "src/chip/devicecontroller/model/ClusterState.java", "src/chip/devicecontroller/model/EndpointState.java", "src/chip/devicecontroller/model/EventState.java", + "src/chip/devicecontroller/model/InvokeElement.java", "src/chip/devicecontroller/model/NodeState.java", "zap-generated/chip/devicecontroller/ChipClusters.java", "zap-generated/chip/devicecontroller/ChipEventStructs.java", diff --git a/src/controller/java/src/chip/devicecontroller/model/InvokeElement.java b/src/controller/java/src/chip/devicecontroller/model/InvokeElement.java new file mode 100644 index 00000000000000..c14a1b4a9f57b6 --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/model/InvokeElement.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package chip.devicecontroller.model; + +import java.util.Locale; +import java.util.Objects; + +/** An invoke element that should be used for interaction model invoke request and response. */ +public final class InvokeElement { + private final ChipPathId endpointId, clusterId, commandId; + private final byte[] tlv; + + private InvokeElement( + ChipPathId endpointId, ChipPathId clusterId, ChipPathId commandId, byte[] tlv) { + this.endpointId = endpointId; + this.clusterId = clusterId; + this.commandId = commandId; + this.tlv = tlv.clone(); + } + + public ChipPathId getEndpointId() { + return endpointId; + } + + public ChipPathId getClusterId() { + return clusterId; + } + + public ChipPathId getCommandId() { + return commandId; + } + + public byte[] getTlvByteArray() { + return tlv.clone(); + } + + // check whether the current InvokeElement has same path as others. + @Override + public boolean equals(Object object) { + if (object instanceof InvokeElement) { + InvokeElement that = (InvokeElement) object; + return Objects.equals(this.endpointId, that.endpointId) + && Objects.equals(this.clusterId, that.clusterId) + && Objects.equals(this.commandId, that.commandId); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(endpointId, clusterId, commandId); + } + + @Override + public String toString() { + return String.format( + Locale.ENGLISH, "Endpoint %s, cluster %s, command %s", endpointId, clusterId, commandId); + } + + public static InvokeElement newInstance( + ChipPathId endpointId, ChipPathId clusterId, ChipPathId commandId, byte[] tlv) { + return new InvokeElement(endpointId, clusterId, commandId, tlv); + } + + /** Create a new {@link InvokeElement} with only concrete ids. */ + public static InvokeElement newInstance( + long endpointId, long clusterId, long commandId, byte[] tlv) { + return new InvokeElement( + ChipPathId.forId(endpointId), + ChipPathId.forId(clusterId), + ChipPathId.forId(commandId), + tlv); + } +}