diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 27cd5c003a9d0e..07c9f8447177fa 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -531,7 +531,7 @@ jobs: runs-on: ubuntu-latest container: - image: connectedhomeip/chip-build-java:0.6.44 + image: connectedhomeip/chip-build-java:0.6.46 options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=0 net.ipv6.conf.all.forwarding=0" diff --git a/examples/java-matter-controller/README.md b/examples/java-matter-controller/README.md index 3431be3039bc5c..3b67056eceba90 100644 --- a/examples/java-matter-controller/README.md +++ b/examples/java-matter-controller/README.md @@ -68,11 +68,12 @@ run the following command: sudo apt-get purge kotlin ``` -Install kotlin compiler 1.8.10 +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 https://github.com/JetBrains/kotlin/releases/download/v1.8.10/kotlin-compiler-1.8.10.zip \ +&& 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 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 49509de3491ae2..51d68ad5f8902c 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 @@ -22,60 +22,39 @@ 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 -private fun registerCommandsDiscover( +private fun getDiscoveryCommands( controller: ChipDeviceController, - commandManager: CommandManager, credentialsIssuer: CredentialsIssuer -) { - val clusterCommands: ArrayList = ArrayList() - val discoverCommand = DiscoverCommand(controller, credentialsIssuer) - val discoverCommissionablesCommand = DiscoverCommissionablesCommand(controller, credentialsIssuer) - val discoverCommissionersCommand = DiscoverCommissionersCommand(controller, credentialsIssuer) - clusterCommands.add(discoverCommand) - clusterCommands.add(discoverCommissionablesCommand) - clusterCommands.add(discoverCommissionersCommand) - commandManager.register("discover", clusterCommands) +): List { + return listOf( + DiscoverCommand(controller, credentialsIssuer), + DiscoverCommissionablesCommand(controller, credentialsIssuer), + DiscoverCommissionersCommand(controller, credentialsIssuer), + ) } -private fun registerCommandsPairing( +private fun getPairingCommands( controller: ChipDeviceController, - commandManager: CommandManager, credentialsIssuer: CredentialsIssuer -) { - val clusterCommands: ArrayList = ArrayList() - val unpairCommand = UnpairCommand(controller, credentialsIssuer) - val pairCodeCommand = PairCodeCommand(controller, credentialsIssuer) - val pairCodePaseCommand = PairCodePaseCommand(controller, credentialsIssuer) - val pairCodeWifiCommand = PairCodeWifiCommand(controller, credentialsIssuer) - val pairCodeThreadCommand = PairCodeThreadCommand(controller, credentialsIssuer) - val pairAddressPaseCommand = PairAddressPaseCommand(controller, credentialsIssuer) - val pairAlreadyDiscoveredCommand = PairAlreadyDiscoveredCommand(controller, credentialsIssuer) - val pairOnNetworkCommand = PairOnNetworkCommand(controller, credentialsIssuer) - val pairOnNetworkShortCommand = PairOnNetworkShortCommand(controller, credentialsIssuer) - val pairOnNetworkLongCommand = PairOnNetworkLongCommand(controller, credentialsIssuer) - val pairOnNetworkVendorCommand = PairOnNetworkVendorCommand(controller, credentialsIssuer) - val pairOnNetworkCommissioningModeCommand = PairOnNetworkCommissioningModeCommand(controller, credentialsIssuer) - val pairOnNetworkCommissionerCommand = PairOnNetworkCommissionerCommand(controller, credentialsIssuer) - val pairOnNetworkDeviceTypeCommand = PairOnNetworkDeviceTypeCommand(controller, credentialsIssuer) - val pairOnNetworkInstanceNameCommand = 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) +): 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) { @@ -88,8 +67,10 @@ fun main(args: Array) { ) val credentialsIssuer = CredentialsIssuer() val commandManager = CommandManager() - registerCommandsDiscover(controller, commandManager, credentialsIssuer) - registerCommandsPairing(controller, commandManager, credentialsIssuer) + + commandManager.register("discover", getDiscoveryCommands(controller, credentialsIssuer)) + commandManager.register("pairing", getPairingCommands(controller, credentialsIssuer)) + try { commandManager.run(args) } catch (e: Exception) { 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.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommand.kt index 941d527191d6cc..2d570a6eb0ef7a 100644 --- 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 @@ -24,12 +24,12 @@ import java.util.concurrent.atomic.AtomicLong class DiscoverCommand(controller: ChipDeviceController, credsIssuer: CredentialsIssuer?) : MatterCommand(controller, "resolve", credsIssuer) { - private val mNodeId: AtomicLong = AtomicLong() - private val mFabricId: AtomicLong = AtomicLong() + private val nodeId: AtomicLong = AtomicLong() + private val fabricId: AtomicLong = AtomicLong() init { - addArgument("nodeid", 0, Long.MAX_VALUE, mNodeId, null, false) - addArgument("fabricid", 0, Long.MAX_VALUE, mFabricId, null, false) + 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.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt index d5f7b156eccebb..865a8dda0d39f4 100644 --- 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 @@ -21,18 +21,19 @@ 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 class DiscoverCommissionablesCommand( controller: ChipDeviceController, credsIssuer: CredentialsIssuer? ) : MatterCommand(controller, "commissionables", credsIssuer) { private val MAX_DISCOVERED_DEVICES = 10 + private val TIME_TO_WAIT_FOR_RESULTS_SECONDS: Long = 7 override fun runCommand() { currentCommissioner().discoverCommissionableNodes() - // Pause for 7 seconds try { - Thread.sleep(7000) + TimeUnit.SECONDS.sleep(TIME_TO_WAIT_FOR_RESULTS_SECONDS) } catch (e: InterruptedException) { throw RuntimeException(e) } 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 index efdd7573c86609..ebc0ec1343a9eb 100644 --- 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 @@ -24,7 +24,5 @@ import com.matter.controller.commands.common.MatterCommand class DiscoverCommissionersCommand( controller: ChipDeviceController, credsIssuer: CredentialsIssuer? ) : MatterCommand(controller, "commissioners", credsIssuer) { - override fun runCommand() { - // mCommissionableNodeController.DiscoverCommissioners(); - } + override fun runCommand() {} }