-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[darwin-framework-tool] Add discover module to scan and list the disc…
…overed commissionable devices over BLE and Mdns (#27318) * Update the SetUpCodePairer such that additional CommonResolutionData can be added when discovered over the network * [matter framework] Add MTRDeviceControllerFactory::startScan and MTRDeviceControllerFactory::stopScan [matter framework] Add MTRDeviceController::setupCommissiongSessionWithDiscoveredDevice * [darwin-framework-tool] Add discover module to scan and list the discovered commissionable devices over BLE and Mdns [darwin-framework-tool] Add pairing by-index command to commission a discovered device * [Typo] Rename an argument in the documentation of src/lib/dnssd/platform/Dnssd.h from interfaceId to interface
- Loading branch information
1 parent
ebc79e1
commit 1325997
Showing
20 changed files
with
841 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
examples/darwin-framework-tool/commands/discover/Commands.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#import <Matter/Matter.h> | ||
|
||
#include "DiscoverCommissionablesCommand.h" | ||
|
||
void registerCommandsDiscover(Commands & commands) | ||
{ | ||
const char * clusterName = "Discover"; | ||
|
||
commands_list clusterCommands = { | ||
make_unique<DiscoverCommissionablesStartCommand>(), | ||
make_unique<DiscoverCommissionablesStopCommand>(), | ||
make_unique<DiscoverCommissionablesListCommand>(), | ||
}; | ||
|
||
commands.Register(clusterName, clusterCommands); | ||
} |
52 changes: 52 additions & 0 deletions
52
examples/darwin-framework-tool/commands/discover/DiscoverCommissionablesCommand.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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. | ||
* | ||
*/ | ||
|
||
#include "../common/CHIPCommandBridge.h" | ||
|
||
class DiscoverCommissionablesStartCommand : public CHIPCommandBridge | ||
{ | ||
public: | ||
DiscoverCommissionablesStartCommand() : CHIPCommandBridge("start") {} | ||
|
||
protected: | ||
/////////// CHIPCommandBridge Interface ///////// | ||
CHIP_ERROR RunCommand() override; | ||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } | ||
}; | ||
|
||
class DiscoverCommissionablesStopCommand : public CHIPCommandBridge | ||
{ | ||
public: | ||
DiscoverCommissionablesStopCommand() : CHIPCommandBridge("stop") {} | ||
|
||
protected: | ||
/////////// CHIPCommandBridge Interface ///////// | ||
CHIP_ERROR RunCommand() override; | ||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); } | ||
}; | ||
|
||
class DiscoverCommissionablesListCommand : public CHIPCommandBridge | ||
{ | ||
public: | ||
DiscoverCommissionablesListCommand() : CHIPCommandBridge("list") {} | ||
|
||
protected: | ||
/////////// CHIPCommandBridge Interface ///////// | ||
CHIP_ERROR RunCommand() override; | ||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); } | ||
}; |
103 changes: 103 additions & 0 deletions
103
examples/darwin-framework-tool/commands/discover/DiscoverCommissionablesCommand.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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. | ||
* | ||
*/ | ||
#include "DiscoverCommissionablesCommand.h" | ||
|
||
NSMutableArray * gDiscoveredDevices = [[NSMutableArray alloc] init]; | ||
auto gDispatchQueue = dispatch_queue_create("com.chip.discover", DISPATCH_QUEUE_SERIAL); | ||
|
||
@interface DeviceScannerDelegate : NSObject <MTRCommissionableBrowserDelegate> | ||
- (void)didDiscoverCommissionable:(MTRCommissionableBrowserResult *)device; | ||
- (void)commissionableUnavailable:(MTRCommissionableBrowserResult *)device; | ||
@end | ||
|
||
@implementation DeviceScannerDelegate | ||
- (void)didDiscoverCommissionable:(MTRCommissionableBrowserResult *)device | ||
{ | ||
auto serviceName = device.serviceName; | ||
auto vendorId = device.vendorId; | ||
auto productId = device.productId; | ||
auto discriminator = device.discriminator; | ||
[gDiscoveredDevices addObject:device]; | ||
|
||
NSLog(@"Found Device (%@) with discriminator: %@ (vendor: %@, product: %@)", serviceName, discriminator, vendorId, productId); | ||
} | ||
|
||
- (void)commissionableUnavailable:(MTRCommissionableBrowserResult *)device | ||
{ | ||
auto serviceName = device.serviceName; | ||
auto vendorId = device.vendorId; | ||
auto productId = device.productId; | ||
auto discriminator = device.discriminator; | ||
[gDiscoveredDevices removeObjectIdenticalTo:device]; | ||
|
||
NSLog(@"Removed Device (%@) with discriminator: %@ (vendor: %@, product: %@)", serviceName, discriminator, vendorId, productId); | ||
} | ||
@end | ||
|
||
CHIP_ERROR DiscoverCommissionablesStartCommand::RunCommand() | ||
{ | ||
VerifyOrReturnError(IsInteractive(), CHIP_ERROR_INCORRECT_STATE); | ||
|
||
dispatch_sync(gDispatchQueue, ^{ | ||
[gDiscoveredDevices removeAllObjects]; | ||
}); | ||
|
||
auto delegate = [[DeviceScannerDelegate alloc] init]; | ||
auto success = [CurrentCommissioner() startScan:delegate queue:gDispatchQueue]; | ||
VerifyOrReturnError(success, CHIP_ERROR_INTERNAL); | ||
|
||
SetCommandExitStatus(CHIP_NO_ERROR); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR DiscoverCommissionablesStopCommand::RunCommand() | ||
{ | ||
VerifyOrReturnError(IsInteractive(), CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto success = [CurrentCommissioner() stopScan]; | ||
VerifyOrReturnError(success, CHIP_ERROR_INTERNAL); | ||
|
||
SetCommandExitStatus(CHIP_NO_ERROR); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR DiscoverCommissionablesListCommand::RunCommand() | ||
{ | ||
VerifyOrReturnError(IsInteractive(), CHIP_ERROR_INCORRECT_STATE); | ||
|
||
dispatch_sync(gDispatchQueue, ^{ | ||
auto resultsCount = [gDiscoveredDevices count]; | ||
VerifyOrReturn(resultsCount > 0, ChipLogProgress(chipTool, "No device discovered.")); | ||
|
||
uint16_t index = 0; | ||
for (id device in gDiscoveredDevices) { | ||
auto serviceName = [device serviceName]; | ||
auto vendorId = [device vendorId]; | ||
auto productId = [device productId]; | ||
auto discriminator = [device discriminator]; | ||
|
||
NSLog( | ||
@"\t %u %@ - Discriminator: %@ - Vendor: %@ - Product: %@", index, serviceName, discriminator, vendorId, productId); | ||
|
||
index++; | ||
} | ||
}); | ||
|
||
SetCommandExitStatus(CHIP_NO_ERROR); | ||
return CHIP_NO_ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.