-
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 bdx commands to darwin-framework-tool
- Loading branch information
1 parent
a8216d8
commit 21ff6f7
Showing
6 changed files
with
159 additions
and
0 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
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,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
45
examples/darwin-framework-tool/commands/bdx/DownloadLogCommand.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,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
58
examples/darwin-framework-tool/commands/bdx/DownloadLogCommand.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,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; | ||
} |
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