Skip to content

Commit

Permalink
Implement command to discover commissionable devices (#23729)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Nov 8, 2023
1 parent da0b96b commit 3581471
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,46 @@
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() {}
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.format("\tDiscriminator: %ld", device.discriminator);
System.out.format("\tIP Address : %s", device.ipAddress);
}
}

0 comments on commit 3581471

Please sign in to comment.