diff --git a/src/darwin/CHIPTool/CHIPTool.xcodeproj/project.pbxproj b/src/darwin/CHIPTool/CHIPTool.xcodeproj/project.pbxproj index 04a4ac77eab565..8efc153410d354 100644 --- a/src/darwin/CHIPTool/CHIPTool.xcodeproj/project.pbxproj +++ b/src/darwin/CHIPTool/CHIPTool.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ 2C21071525D1A8F200DDA4AD /* MultiAdminViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C21071325D1A8F200DDA4AD /* MultiAdminViewController.m */; }; 2C460C2425D7594B000512D6 /* DeviceSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C460C2325D7594B000512D6 /* DeviceSelector.m */; }; 2C460C3225D97CB3000512D6 /* UnpairDevicesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C460C3025D97CB3000512D6 /* UnpairDevicesViewController.m */; }; - 991DC091247747F500C13860 /* EchoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 991DC090247747F500C13860 /* EchoViewController.m */; }; + 991DC091247747F500C13860 /* EnumerateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 991DC090247747F500C13860 /* EnumerateViewController.m */; }; 997A639C253F93F7005C64E6 /* CHIP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 997A639B253F93F7005C64E6 /* CHIP.framework */; }; 997A639D253F93F7005C64E6 /* CHIP.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 997A639B253F93F7005C64E6 /* CHIP.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B204A621244E1D0600C7C0E1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B204A620244E1D0600C7C0E1 /* AppDelegate.m */; }; @@ -62,8 +62,8 @@ 2C460C2325D7594B000512D6 /* DeviceSelector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DeviceSelector.m; sourceTree = ""; }; 2C460C3025D97CB3000512D6 /* UnpairDevicesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UnpairDevicesViewController.m; sourceTree = ""; }; 2C460C3125D97CB3000512D6 /* UnpairDevicesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnpairDevicesViewController.h; sourceTree = ""; }; - 991DC08F247747F500C13860 /* EchoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EchoViewController.h; sourceTree = ""; }; - 991DC090247747F500C13860 /* EchoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EchoViewController.m; sourceTree = ""; }; + 991DC08F247747F500C13860 /* EnumerateViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EnumerateViewController.h; sourceTree = ""; }; + 991DC090247747F500C13860 /* EnumerateViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EnumerateViewController.m; sourceTree = ""; }; 997A639B253F93F7005C64E6 /* CHIP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CHIP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B204A61C244E1D0600C7C0E1 /* CHIPTool.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CHIPTool.app; sourceTree = BUILT_PRODUCTS_DIR; }; B204A61F244E1D0600C7C0E1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -123,13 +123,13 @@ path = QRCode; sourceTree = ""; }; - 0C79937924858B4F0047A373 /* Echo client */ = { + 0C79937924858B4F0047A373 /* Enumeration */ = { isa = PBXGroup; children = ( - 991DC08F247747F500C13860 /* EchoViewController.h */, - 991DC090247747F500C13860 /* EchoViewController.m */, + 991DC08F247747F500C13860 /* EnumerateViewController.h */, + 991DC090247747F500C13860 /* EnumerateViewController.m */, ); - path = "Echo client"; + path = Enumeration; sourceTree = ""; }; 0CA0E0D0248599C4009087B9 /* OnOffCluster */ = { @@ -236,7 +236,7 @@ B2946A3F24C99D21005C87D0 /* WiFi */, 0C79937824858B3B0047A373 /* QRCode */, B2C22672262892D7009DAB8B /* Fabric */, - 0C79937924858B4F0047A373 /* Echo client */, + 0C79937924858B4F0047A373 /* Enumeration */, 0CA0E0D0248599C4009087B9 /* OnOffCluster */, ); path = "View Controllers"; @@ -393,7 +393,7 @@ 2C460C3225D97CB3000512D6 /* UnpairDevicesViewController.m in Sources */, B232D8BA2514BD0800792CB4 /* CHIPUIViewUtils.m in Sources */, B2946A9B24C9A7BF005C87D0 /* DefaultsUtils.m in Sources */, - 991DC091247747F500C13860 /* EchoViewController.m in Sources */, + 991DC091247747F500C13860 /* EnumerateViewController.m in Sources */, B2C2267526289324009DAB8B /* FabricUIViewController.m in Sources */, B2B0209225C9C1AC00A4C220 /* BindingsViewController.m in Sources */, B204A621244E1D0600C7C0E1 /* AppDelegate.m in Sources */, diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Bindings/BindingsViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Bindings/BindingsViewController.m index 15c639d87b0c63..bbd69810d05499 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Bindings/BindingsViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Bindings/BindingsViewController.m @@ -132,25 +132,12 @@ - (IBAction)bind:(id)sender uint64_t nodeId; NSScanner * scanner = [NSScanner scannerWithString:_nodeIDTextField.text]; [scanner scanUnsignedLongLong:&nodeId]; - int endpointId = [_endpointIDTextField.text intValue]; - int groupId = [_groupIDTextField.text intValue]; - int clusterId = [_clusterIDTextField.text intValue]; + // TODO Binding Support was removed from ObjC Clusters.h if (CHIPGetConnectedDevice(^(CHIPDevice * _Nullable chipDevice, NSError * _Nullable error) { if (chipDevice) { - CHIPBinding * cluster = [[CHIPBinding alloc] initWithDevice:chipDevice endpoint:0 queue:dispatch_get_main_queue()]; - __auto_type * params = [[CHIPBindingClusterBindParams alloc] init]; - params.nodeId = @(nodeId); - params.groupId = @(groupId); - params.endpointId = @(endpointId); - params.clusterId = @(clusterId); - [cluster bindWithParams:params - completionHandler:^(NSError * _Nullable error) { - NSString * resultString = (error == nil) - ? @"Bind command: success!" - : [NSString stringWithFormat:@"An error occurred: 0x%02lx", error.code]; - NSLog(resultString, nil); - }]; + NSString * resultString = [NSString stringWithFormat:@"Not Supported"]; + NSLog(resultString, nil); } else { NSLog(@"Status: Failed to establish a connection with the device"); } @@ -163,26 +150,10 @@ - (IBAction)bind:(id)sender - (IBAction)unbind:(id)sender { - int nodeId = [_nodeIDTextField.text intValue]; - int endpointId = [_endpointIDTextField.text intValue]; - int groupId = [_groupIDTextField.text intValue]; - int clusterId = [_clusterIDTextField.text intValue]; - if (CHIPGetConnectedDevice(^(CHIPDevice * _Nullable chipDevice, NSError * _Nullable error) { if (chipDevice) { - CHIPBinding * cluster = [[CHIPBinding alloc] initWithDevice:chipDevice endpoint:0 queue:dispatch_get_main_queue()]; - __auto_type * params = [[CHIPBindingClusterUnbindParams alloc] init]; - params.nodeId = @(nodeId); - params.groupId = @(groupId); - params.endpointId = @(endpointId); - params.clusterId = @(clusterId); - [cluster unbindWithParams:params - completionHandler:^(NSError * _Nullable error) { - NSString * resultString = (error == nil) - ? @"Unbind command: success!" - : [NSString stringWithFormat:@"An error occurred: 0x%02lx", error.code]; - NSLog(resultString, nil); - }]; + NSString * resultString = [NSString stringWithFormat:@"Not Supported"]; + NSLog(resultString, nil); } else { NSLog(@"Status: Failed to establish a connection with the device"); } diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Echo client/EchoViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Echo client/EchoViewController.m deleted file mode 100644 index 69364376a602a5..00000000000000 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Echo client/EchoViewController.m +++ /dev/null @@ -1,117 +0,0 @@ -/** - * - * Copyright (c) 2020 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. - * 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. - */ - -#import "EchoViewController.h" - -#import "CHIPUIViewUtils.h" -#import "DefaultsUtils.h" - -@interface EchoViewController () - -@property (strong, nonatomic) UITextField * messageTextField; -@property (strong, nonatomic) UIButton * sendButton; - -@property (nonatomic, strong) UILabel * resultLabel; -@property (nonatomic, strong) UIStackView * stackView; - -@end - -@implementation EchoViewController - -// MARK: UIViewController methods - -- (void)viewDidLoad -{ - [super viewDidLoad]; - [self setupUIElements]; - - // listen for taps to dismiss the keyboard - UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; - [self.view addGestureRecognizer:tap]; -} - -- (void)dismissKeyboard -{ - [self.messageTextField resignFirstResponder]; -} - -// MARK: UI Setup - -- (void)setupUIElements -{ - self.view.backgroundColor = UIColor.whiteColor; - - // Title - UILabel * titleLabel = [CHIPUIViewUtils addTitle:@"Echo client" toView:self.view]; - - // stack view - _stackView = [UIStackView new]; - _stackView.axis = UILayoutConstraintAxisVertical; - _stackView.distribution = UIStackViewDistributionEqualSpacing; - _stackView.alignment = UIStackViewAlignmentLeading; - _stackView.spacing = 30; - [self.view addSubview:_stackView]; - - _stackView.translatesAutoresizingMaskIntoConstraints = false; - [_stackView.topAnchor constraintEqualToAnchor:titleLabel.bottomAnchor constant:30].active = YES; - [_stackView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:30].active = YES; - [_stackView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-30].active = YES; - - // Send message - _messageTextField = [UITextField new]; - _messageTextField.placeholder = @"Hello from iOS!"; - _sendButton = [UIButton new]; - [_sendButton setTitle:@"Send" forState:UIControlStateNormal]; - [_sendButton addTarget:self action:@selector(sendMessage:) forControlEvents:UIControlEventTouchUpInside]; - UIView * sendMessageView = [CHIPUIViewUtils viewWithUITextField:_messageTextField button:_sendButton]; - [_stackView addArrangedSubview:sendMessageView]; - sendMessageView.translatesAutoresizingMaskIntoConstraints = false; - [sendMessageView.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; - - // Result message - _resultLabel = [UILabel new]; - _resultLabel.hidden = YES; - _resultLabel.font = [UIFont systemFontOfSize:17]; - _resultLabel.textColor = UIColor.systemBlueColor; - _resultLabel.lineBreakMode = NSLineBreakByWordWrapping; - _resultLabel.numberOfLines = 0; - [_stackView addArrangedSubview:_resultLabel]; - - _resultLabel.translatesAutoresizingMaskIntoConstraints = false; - [_resultLabel.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; - _resultLabel.adjustsFontSizeToFitWidth = YES; -} - -- (void)updateResult:(NSString *)result -{ - _resultLabel.hidden = NO; - _resultLabel.text = result; -} - -// MARK: UIButton actions - -- (IBAction)sendMessage:(id)sender -{ - NSString * msg = [self.messageTextField text]; - if (msg.length == 0) { - msg = [self.messageTextField placeholder]; - } - - [self updateResult:@"Not Supported"]; -} - -@end diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Echo client/EchoViewController.h b/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.h similarity index 93% rename from src/darwin/CHIPTool/CHIPTool/View Controllers/Echo client/EchoViewController.h rename to src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.h index 898401965278bb..3f4f487a2130ce 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Echo client/EchoViewController.h +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.h @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface EchoViewController : UIViewController +@interface EnumerateViewController : UIViewController @end NS_ASSUME_NONNULL_END diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m new file mode 100644 index 00000000000000..92cd4e822bafda --- /dev/null +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m @@ -0,0 +1,168 @@ +/** + * + * Copyright (c) 2020 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. + * 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. + */ + +#import "EnumerateViewController.h" + +#import "CHIPUIViewUtils.h" +#import "DefaultsUtils.h" + +@interface EnumerateViewController () + +@property (strong, nonatomic) UIButton * sendButton; + +@property (nonatomic, strong) UILabel * resultLabel; +@property (nonatomic, strong) UIStackView * stackView; + +@end + +@implementation EnumerateViewController + +// MARK: UIViewController methods + +- (void)viewDidLoad +{ + [super viewDidLoad]; + [self setupUIElements]; +} + +// MARK: UI Setup + +- (void)setupUIElements +{ + self.view.backgroundColor = UIColor.whiteColor; + + // Title + UILabel * titleLabel = [CHIPUIViewUtils addTitle:@"Enumeration" toView:self.view]; + + // stack view + _stackView = [UIStackView new]; + _stackView.axis = UILayoutConstraintAxisVertical; + _stackView.distribution = UIStackViewDistributionEqualSpacing; + _stackView.alignment = UIStackViewAlignmentLeading; + _stackView.spacing = 30; + [self.view addSubview:_stackView]; + + _stackView.translatesAutoresizingMaskIntoConstraints = false; + [_stackView.topAnchor constraintEqualToAnchor:titleLabel.bottomAnchor constant:30].active = YES; + [_stackView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:30].active = YES; + [_stackView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-30].active = YES; + + // Send message + _sendButton = [UIButton new]; + [_sendButton setTitle:@"Start" forState:UIControlStateNormal]; + [_sendButton addTarget:self action:@selector(sendMessage:) forControlEvents:UIControlEventTouchUpInside]; + UIView * startView = [CHIPUIViewUtils stackViewWithButtons:@[ _sendButton ]]; + [_stackView addArrangedSubview:startView]; + startView.translatesAutoresizingMaskIntoConstraints = false; + [startView.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; + + // Result message + _resultLabel = [UILabel new]; + _resultLabel.hidden = YES; + _resultLabel.font = [UIFont systemFontOfSize:17]; + _resultLabel.textColor = UIColor.systemBlueColor; + _resultLabel.lineBreakMode = NSLineBreakByWordWrapping; + _resultLabel.numberOfLines = 0; + [_stackView addArrangedSubview:_resultLabel]; + + _resultLabel.translatesAutoresizingMaskIntoConstraints = false; + [_resultLabel.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; + _resultLabel.adjustsFontSizeToFitWidth = YES; +} + +- (void)updateResult:(NSString *)result +{ + NSLog(@"UpdatingUIResult: %@", result); + _resultLabel.hidden = NO; + _resultLabel.text = result; +} + +// MARK: UIButton actions + +- (IBAction)sendMessage:(id)sender +{ + [self updateResult:@"Enumerating..."]; + [self enumerate]; +} + +// MARK: Enumeration Implementation + +// This API just walks over the accessory and tries to display its information. +// 1. Get the endpoint list +// 2. Get the device list on each endpoint +// 3. Get the clusters in use on each endpoint +// 4. Success? +- (void)enumerate +{ + CHIPGetConnectedDevice(^(CHIPDevice * _Nullable device, NSError * _Nullable error) { + if (error) { + NSString * resultLog = [[NSString alloc] initWithFormat:@"Unable to get connected device: Error: %@", error]; + [self updateResult:resultLog]; + return; + } + + CHIPDescriptor * descriptorCluster = [[CHIPDescriptor alloc] initWithDevice:device + endpoint:0 + queue:dispatch_get_main_queue()]; + NSLog(@"Reading parts list to get list of endpoints in use..."); + [descriptorCluster readAttributePartsListWithCompletionHandler:^( + NSArray * _Nullable endpointsInUse, NSError * _Nullable error) { + if (error) { + NSString * resultLog = [[NSString alloc] initWithFormat:@"Unable to read parts list: Error: %@", error]; + [self updateResult:resultLog]; + return; + } + + NSString * resultLog = [[NSString alloc] initWithFormat:@"Got list of endpoints in Use: %@", endpointsInUse]; + [self updateResult:resultLog]; + + for (NSNumber * endpoint in endpointsInUse) { + CHIPDescriptor * descriptorCluster = [[CHIPDescriptor alloc] initWithDevice:device + endpoint:[endpoint unsignedShortValue] + queue:dispatch_get_main_queue()]; + [descriptorCluster readAttributeDeviceListWithCompletionHandler:^( + NSArray * _Nullable value, NSError * _Nullable error) { + if (error) { + NSString * resultLog = [[NSString alloc] + initWithFormat:@"Unable to read device list for Endpoint:%@ Error: %@", endpoint, error]; + [self updateResult:resultLog]; + return; + } + + NSString * resultLog = [[NSString alloc] initWithFormat:@"Got device list for endpoint:%@ %@", endpoint, value]; + [self updateResult:resultLog]; + + [descriptorCluster + readAttributeServerListWithCompletionHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + if (error) { + NSString * resultLog = [[NSString alloc] + initWithFormat:@"Unable to read server list for Endpoint:%@ Error: %@", endpoint, error]; + [self updateResult:resultLog]; + return; + } + + NSString * resultLog = + [[NSString alloc] initWithFormat:@"Got server list for endpoint:%@ %@", endpoint, value]; + [self updateResult:resultLog]; + }]; + }]; + } + }]; + }); +} + +@end diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/RootViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/RootViewController.m index 707b8cc1e8287d..4f40582ae8f295 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/RootViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/RootViewController.m @@ -17,7 +17,7 @@ #import "RootViewController.h" #import "BindingsViewController.h" -#import "EchoViewController.h" +#import "EnumerateViewController.h" #import "FabricUIViewController.h" #import "MultiAdminViewController.h" #import "OnOffViewController.h" @@ -42,7 +42,7 @@ - (void)setUpTableView self.tableView.dataSource = self; [self.view addSubview:self.tableView]; self.options = @[ - @"QRCode scanner", @"Echo client", @"Light on / off cluster", @"Temperature Sensor", @"Bindings", @"WiFi Configuration", + @"QRCode scanner", @"Enumeration", @"Light on / off cluster", @"Temperature Sensor", @"Bindings", @"WiFi Configuration", @"Enable Pairing", @"Unpair Devices", @"Fabric Management" ]; } @@ -73,7 +73,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [self pushQRCodeScanner]; break; case 1: - [self pushEchoClient]; + [self pushEnumeration]; break; case 2: [self pushLightOnOffCluster]; @@ -131,9 +131,9 @@ - (void)pushQRCodeScanner [self.navigationController pushViewController:controller animated:YES]; } -- (void)pushEchoClient +- (void)pushEnumeration { - EchoViewController * controller = [EchoViewController new]; + EnumerateViewController * controller = [EnumerateViewController new]; [self.navigationController pushViewController:controller animated:YES]; }