Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Mar 2, 2023
1 parent ca32f60 commit b586bb5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 3 additions & 2 deletions examples/java-matter-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Command> = ArrayList<Command>()
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<Command> {
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<Command> = ArrayList<Command>()
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<Command> {
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<String>) {
Expand All @@ -88,8 +67,10 @@ fun main(args: Array<String>) {
)
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Command> mCommandMgr = new ArrayList<Command>();
private final Map<String, ArrayList<Command>> mClusters =
new HashMap<String, ArrayList<Command>>();
private final Map<String, List<Command>> mClusters = new HashMap<String, List<Command>>();
private static Logger logger = Logger.getLogger(CommandManager.class.getName());

public final void register(String clusterName, ArrayList<Command> commandsList) {
public final void register(String clusterName, List<Command> commandsList) {
mClusters.put(clusterName, commandsList);
}

Expand All @@ -45,7 +43,7 @@ public final void run(String[] args) throws Exception {
return;
}

ArrayList<Command> commands = mClusters.get(args[0]);
List<Command> commands = mClusters.get(args[0]);
if (commands == null) {
logger.log(Level.INFO, "Unknown cluster: " + args[0]);
showClusters();
Expand Down Expand Up @@ -121,7 +119,7 @@ private boolean isGlobalCommand(String commandName) {
return isAttributeCommand(commandName) || isEventCommand(commandName);
}

private Command getCommand(ArrayList<Command> commands, String commandName) {
private Command getCommand(List<Command> commands, String commandName) {
for (Command command : commands) {
if (commandName.equals(command.getName())) {
return command;
Expand All @@ -132,7 +130,7 @@ private Command getCommand(ArrayList<Command> commands, String commandName) {
}

private Command getGlobalCommand(
ArrayList<Command> commands, String commandName, String attributeName) {
List<Command> commands, String commandName, String attributeName) {
for (Command command : commands) {
if (commandName.equals(command.getName()) && attributeName.equals(command.getAttribute())) {
return command;
Expand Down Expand Up @@ -166,7 +164,7 @@ private void showClusters() {
" +-------------------------------------------------------------------------------------+");
}

private void showCluster(String clusterName, ArrayList<Command> commands) {
private void showCluster(String clusterName, List<Command> commands) {
logger.log(Level.INFO, "Usage:");
logger.log(
Level.INFO,
Expand Down Expand Up @@ -216,7 +214,7 @@ private void showCluster(String clusterName, ArrayList<Command> commands) {
}

private void showClusterAttributes(
String clusterName, String commandName, ArrayList<Command> commands) {
String clusterName, String commandName, List<Command> commands) {
logger.log(Level.INFO, "Usage:");
System.out.printf(
" java-matter-controller %s %s attribute-name [param1 param2 ...]\n",
Expand All @@ -241,8 +239,7 @@ private void showClusterAttributes(
" +-------------------------------------------------------------------------------------+");
}

private void showClusterEvents(
String clusterName, String commandName, ArrayList<Command> commands) {
private void showClusterEvents(String clusterName, String commandName, List<Command> commands) {
logger.log(Level.INFO, "Usage:");
System.out.printf(
" java-matter-controller %s %s event-name [param1 param2 ...]\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}

0 comments on commit b586bb5

Please sign in to comment.