From 20d21e7b6e47d494cf24022af69a7f8312b0db65 Mon Sep 17 00:00:00 2001 From: Douglas Rocha Ferraz Date: Fri, 3 Mar 2023 01:19:26 -0300 Subject: [PATCH 1/6] [chef] linux wpa fix (#25438) * fix: Wi-Fi init on linux target for chef * chg: removed uncessary namespace scoping, restyle --- examples/chef/linux/main.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/chef/linux/main.cpp b/examples/chef/linux/main.cpp index 35cc7a242afcbd..af41f8b6588a1d 100644 --- a/examples/chef/linux/main.cpp +++ b/examples/chef/linux/main.cpp @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include @@ -28,8 +30,21 @@ using namespace chip; using namespace chip::Shell; +using namespace chip::app; -void ApplicationInit() {} +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +namespace { +DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sLinuxWiFiDriver; +Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0, &sLinuxWiFiDriver); +} // namespace +#endif + +void ApplicationInit() +{ +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + sWiFiNetworkCommissioningInstance.Init(); +#endif +} int main(int argc, char * argv[]) { From af3fdc5dd8122f69c4efc40e3ed63f829e876bab Mon Sep 17 00:00:00 2001 From: poyamini <108741504+poyamini@users.noreply.github.com> Date: Fri, 3 Mar 2023 12:19:09 +0530 Subject: [PATCH 2/6] Fixed the improper channel result issue in the scan results of network (#25430) --- examples/platform/silabs/efr32/rs911x/rsi_if.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.c b/examples/platform/silabs/efr32/rs911x/rsi_if.c index acac100f36bfe5..30b175b54efc67 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.c +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.c @@ -737,6 +737,7 @@ void wfx_rsi_task(void * arg) WFX_RSI_LOG("Inside else"); ap.security = scan->security_mode; ap.rssi = (-1) * scan->rssi_val; + ap.chan = scan->rf_channel; memcpy(&ap.bssid[0], &scan->bssid[0], BSSID_MAX_STR_LEN); (*wfx_rsi.scan_cb)(&ap); } 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 3/6] [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 4/6] 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 5/6] [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 6/6] 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++) {