Skip to content

Commit

Permalink
[darwin-framework-tool] Add bdx commands to darwin-framework-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Jan 23, 2024
1 parent a8216d8 commit 21ff6f7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ executable("darwin-framework-tool") {
"${chip_root}/examples/chip-tool/commands/common/Commands.h",
"${chip_root}/examples/chip-tool/commands/common/HexConversion.h",
"${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp",
"commands/bdx/Commands.h",
"commands/bdx/DownloadLogCommand.mm",
"commands/clusters/ClusterCommandBridge.h",
"commands/clusters/ModelCommandBridge.mm",
"commands/clusters/ReportCommandBridge.h",
Expand Down
32 changes: 32 additions & 0 deletions examples/darwin-framework-tool/commands/bdx/Commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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

#include "commands/bdx/DownloadLogCommand.h"
#include "commands/common/Commands.h"

void registerCommandsBdx(Commands & commands)
{
const char * clusterName = "Bdx";
commands_list clusterCommands = {
make_unique<DownloadLogCommand>(), //
};

commands.RegisterCommandSet(clusterName, clusterCommands, "Commands related to BDX");
}
45 changes: 45 additions & 0 deletions examples/darwin-framework-tool/commands/bdx/DownloadLogCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 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

#include "../common/CHIPCommandBridge.h"

class DownloadLogCommand : public CHIPCommandBridge
{
public:
DownloadLogCommand() : CHIPCommandBridge("download")
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId, "Node to download the logs from.");
AddArgument("log-type", 0, 2, &mLogType,
"The type of log being requested. This should correspond to a value in the enum MTRDiagnosticLogType.");
AddArgument("timeout", 0, UINT16_MAX, &mTimeout,
"The timeout for getting the log. If the timeout expires, completion will be called with whatever has been "
"retrieved by that point (which might be none or a partial log). If the timeout is set to 0, the request will "
"not expire and completion will not be called until the log is fully retrieved or an error occurs.");
}

/////////// CHIPCommandBridge Interface /////////
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); }

private:
chip::NodeId mNodeId;
uint8_t mLogType;
uint16_t mTimeout;
};
58 changes: 58 additions & 0 deletions examples/darwin-framework-tool/commands/bdx/DownloadLogCommand.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 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.
*
*/

#import <Matter/Matter.h>

#import "MTRError_Utils.h"

#include "DownloadLogCommand.h"

CHIP_ERROR DownloadLogCommand::RunCommand()
{
ChipLogProgress(chipTool, "Downloading logs from node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));

MTRDeviceController * commissioner = CurrentCommissioner();
auto * device = [MTRDevice deviceWithNodeID:@(mNodeId) controller:commissioner];

auto logType = static_cast<MTRDiagnosticLogType>(mLogType);
auto queue = dispatch_queue_create("com.chip.bdx.downloader", DISPATCH_QUEUE_SERIAL);

auto * self = this;
auto completion = ^(NSURL * url, NSError * error) {
// A non-nil url indicates the presence of content, which can occur even in error scenarios like timeouts.
if (nil != url) {
NSError * readError = nil;
auto * data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&readError];
VerifyOrReturn(nil == readError, self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(readError)));

auto * content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Content: %@", content);
}

VerifyOrReturn(nil == error, self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error)));

// The url is nil when there are no logs on the target device.
if (nil == url) {
NSLog(@"No logs has been found onto node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
}
self->SetCommandExitStatus(CHIP_NO_ERROR);
};

[device downloadLogOfType:logType timeout:mTimeout queue:queue completion:completion];
return CHIP_NO_ERROR;
}
2 changes: 2 additions & 0 deletions examples/darwin-framework-tool/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#import "logging/logging.h"

#include "commands/bdx/Commands.h"
#include "commands/common/Commands.h"
#include "commands/delay/Commands.h"
#include "commands/discover/Commands.h"
Expand All @@ -38,6 +39,7 @@ int main(int argc, const char * argv[])
dft::logging::Setup();

Commands commands;
registerCommandsBdx(commands);
registerCommandsPairing(commands);
registerCommandsDelay(commands);
registerCommandsDiscover(commands);
Expand Down
20 changes: 20 additions & 0 deletions src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@
B4E2621B2AA0D02000DBA5BC /* SleepCommand.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4E262192AA0D01D00DBA5BC /* SleepCommand.mm */; };
B4E2621E2AA0D02D00DBA5BC /* WaitForCommissioneeCommand.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4E2621C2AA0D02A00DBA5BC /* WaitForCommissioneeCommand.mm */; };
B4FCD56A2B5EDBD300832859 /* MTRDiagnosticLogsType.h in Headers */ = {isa = PBXBuildFile; fileRef = B4FCD5692B5EDBD300832859 /* MTRDiagnosticLogsType.h */; settings = {ATTRIBUTES = (Public, ); }; };
B4FCD5702B603A6300832859 /* Commands.h in Headers */ = {isa = PBXBuildFile; fileRef = B4FCD56D2B603A6300832859 /* Commands.h */; };
B4FCD5712B603A6300832859 /* DownloadLogCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B4FCD56E2B603A6300832859 /* DownloadLogCommand.h */; };
B4FCD5722B603A6300832859 /* DownloadLogCommand.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4FCD56F2B603A6300832859 /* DownloadLogCommand.mm */; };
BA09EB43247477BA00605257 /* libCHIP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BA09EB3F2474762900605257 /* libCHIP.a */; };
D4772A46285AE98400383630 /* MTRClusterConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = D4772A45285AE98300383630 /* MTRClusterConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -678,6 +681,9 @@
B4E262192AA0D01D00DBA5BC /* SleepCommand.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SleepCommand.mm; sourceTree = "<group>"; };
B4E2621C2AA0D02A00DBA5BC /* WaitForCommissioneeCommand.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WaitForCommissioneeCommand.mm; sourceTree = "<group>"; };
B4FCD5692B5EDBD300832859 /* MTRDiagnosticLogsType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRDiagnosticLogsType.h; sourceTree = "<group>"; };
B4FCD56D2B603A6300832859 /* Commands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Commands.h; sourceTree = "<group>"; };
B4FCD56E2B603A6300832859 /* DownloadLogCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadLogCommand.h; sourceTree = "<group>"; };
B4FCD56F2B603A6300832859 /* DownloadLogCommand.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadLogCommand.mm; sourceTree = "<group>"; };
BA09EB3F2474762900605257 /* libCHIP.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libCHIP.a; path = lib/libCHIP.a; sourceTree = BUILT_PRODUCTS_DIR; };
BA107AEE2470CFBB004287EB /* chip_xcode_build_connector.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = chip_xcode_build_connector.sh; sourceTree = "<group>"; };
D437613E285BDC0D0051FEA2 /* MTRErrorTestUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRErrorTestUtils.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -746,6 +752,7 @@
037C3D7B2991BD4F00B7EEE2 /* commands */ = {
isa = PBXGroup;
children = (
B4FCD56C2B603A6300832859 /* bdx */,
B4E262182AA0CFFE00DBA5BC /* delay */,
03FB93DA2A46200A0048CB35 /* discover */,
037C3D7C2991BD4F00B7EEE2 /* pairing */,
Expand Down Expand Up @@ -1347,6 +1354,16 @@
path = delay;
sourceTree = "<group>";
};
B4FCD56C2B603A6300832859 /* bdx */ = {
isa = PBXGroup;
children = (
B4FCD56D2B603A6300832859 /* Commands.h */,
B4FCD56E2B603A6300832859 /* DownloadLogCommand.h */,
B4FCD56F2B603A6300832859 /* DownloadLogCommand.mm */,
);
path = bdx;
sourceTree = "<group>";
};
BA09EB3E2474762900605257 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1376,6 +1393,7 @@
037C3DCE2991BD5100B7EEE2 /* CHIPCommandBridge.h in Headers */,
037C3DD22991BD5200B7EEE2 /* InteractiveCommands.h in Headers */,
037C3DAF2991BD4F00B7EEE2 /* DeviceControllerDelegateBridge.h in Headers */,
B4FCD5712B603A6300832859 /* DownloadLogCommand.h in Headers */,
037C3DC32991BD5100B7EEE2 /* Commands.h in Headers */,
037C3DB82991BD5000B7EEE2 /* ClusterCommandBridge.h in Headers */,
037C3DC82991BD5100B7EEE2 /* CHIPToolKeypair.h in Headers */,
Expand All @@ -1388,6 +1406,7 @@
037C3DB92991BD5000B7EEE2 /* ReportCommandBridge.h in Headers */,
037C3DBE2991BD5000B7EEE2 /* OTASoftwareUpdateInteractive.h in Headers */,
037C3DBD2991BD5000B7EEE2 /* OTAProviderDelegate.h in Headers */,
B4FCD5702B603A6300832859 /* Commands.h in Headers */,
037C3DB02991BD4F00B7EEE2 /* Commands.h in Headers */,
037C3DC02991BD5100B7EEE2 /* Commands.h in Headers */,
B4E262172AA0CF2000DBA5BC /* RemoteDataModelLogger.h in Headers */,
Expand Down Expand Up @@ -1652,6 +1671,7 @@
B45373C12A9FEA9100807602 /* close.c in Sources */,
039546A62991E151006D42A8 /* InteractionModel.cpp in Sources */,
B45373E72A9FEBA400807602 /* parsers.c in Sources */,
B4FCD5722B603A6300832859 /* DownloadLogCommand.mm in Sources */,
B45373BF2A9FEA9100807602 /* adopt.c in Sources */,
B45373F32A9FEC1A00807602 /* server-ws.c in Sources */,
03F430AA2994113500166449 /* sysunix.c in Sources */,
Expand Down

0 comments on commit 21ff6f7

Please sign in to comment.