-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ChipTool] Add Payload Parse Command #3696
Merged
chrisdecenzo
merged 8 commits into
project-chip:master
from
lijujayakumar:payload-command
Dec 3, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
351058f
[ChipTool] Add Payload Parse Command
lijayaku 13bd7ca
Merge pull request #1 from project-chip/master
lijujayakumar 3f02445
Merge pull request #2 from lijujayakumar/master
lijujayakumar 21f7bd9
[ChipTool] Add Payload Parse Command
lijayaku 3d98865
[ChipTool] Restyle issues resolved
lijujayakumar 4a8180e
Restyled by whitespace
restyled-commits a0eb26f
Merge branch 'master' into payload-command
lijujayakumar 7ce9721
Resolve build errors caused by Command.h schema change
lijujayakumar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,31 @@ | ||
/* | ||
* Copyright (c) 2020 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 "ParseCommand.h" | ||
|
||
void registerCommandsPayload(Commands & commands) | ||
{ | ||
const char * clusterName = "Payload"; | ||
commands_list clusterCommands = { | ||
make_unique<ParseCommand>(), | ||
}; | ||
|
||
commands.Register(clusterName, clusterCommands); | ||
} |
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,104 @@ | ||
/* | ||
* Copyright (c) 2020 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 "ParseCommand.h" | ||
#include <setup_payload/ManualSetupPayloadParser.h> | ||
#include <setup_payload/QRCodeSetupPayloadParser.h> | ||
#include <setup_payload/SetupPayload.h> | ||
|
||
using namespace ::chip; | ||
|
||
CHIP_ERROR ParseCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) | ||
{ | ||
std::string codeString(mCode); | ||
SetupPayload payload; | ||
|
||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
err = Parse(codeString, payload); | ||
SuccessOrExit(err); | ||
|
||
err = Print(payload); | ||
SuccessOrExit(err); | ||
exit: | ||
return err; | ||
} | ||
|
||
CHIP_ERROR ParseCommand::Print(chip::SetupPayload payload) | ||
{ | ||
std::string serialNumber; | ||
std::vector<OptionalQRCodeInfo> optionalVendorData; | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
ChipLogProgress(SetupPayload, "RequiresCustomFlow: %u", payload.requiresCustomFlow); | ||
ChipLogProgress(SetupPayload, "VendorID: %u", payload.vendorID); | ||
ChipLogProgress(SetupPayload, "Version: %u", payload.version); | ||
ChipLogProgress(SetupPayload, "ProductID: %u", payload.productID); | ||
ChipLogProgress(SetupPayload, "Discriminator: %u", payload.discriminator); | ||
ChipLogProgress(SetupPayload, "SetUpPINCode: %u", payload.setUpPINCode); | ||
ChipLogProgress(SetupPayload, "RendezvousInformation: %u", payload.rendezvousInformation); | ||
|
||
if (payload.getSerialNumber(serialNumber) == CHIP_NO_ERROR) | ||
{ | ||
ChipLogProgress(SetupPayload, "SerialNumber: %s", serialNumber.c_str()); | ||
} | ||
|
||
optionalVendorData = payload.getAllOptionalVendorData(); | ||
for (const OptionalQRCodeInfo & info : optionalVendorData) | ||
{ | ||
if (info.type == optionalQRCodeInfoTypeString) | ||
{ | ||
ChipLogProgress(SetupPayload, "OptionalQRCodeInfo: tag=%u,string value=%s", info.tag, info.data.c_str()); | ||
} | ||
else if (info.type == optionalQRCodeInfoTypeInt32) | ||
{ | ||
ChipLogProgress(SetupPayload, "OptionalQRCodeInfo: tag=%u,int value=%u", info.tag, info.int32); | ||
} | ||
else | ||
{ | ||
err = CHIP_ERROR_INVALID_ARGUMENT; | ||
} | ||
lijujayakumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
SuccessOrExit(err); | ||
|
||
exit: | ||
return err; | ||
} | ||
|
||
CHIP_ERROR ParseCommand::Parse(std::string codeString, chip::SetupPayload & payload) | ||
{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove this new line |
||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
if (IsQRCode(codeString)) | ||
{ | ||
ChipLogDetail(SetupPayload, "Parsing base41Representation: %s", codeString.c_str()); | ||
err = QRCodeSetupPayloadParser(codeString).populatePayload(payload); | ||
} | ||
else | ||
{ | ||
ChipLogDetail(SetupPayload, "Parsing decimalRepresentation: %s", codeString.c_str()); | ||
err = ManualSetupPayloadParser(codeString).populatePayload(payload); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
bool ParseCommand::IsQRCode(std::string codeString) | ||
{ | ||
return codeString.rfind(QRCODE_PREFIX) == 0; | ||
} |
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) 2020 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/Command.h" | ||
#include <setup_payload/SetupPayload.h> | ||
|
||
class ParseCommand : public Command | ||
{ | ||
public: | ||
ParseCommand() : Command("parse") { AddArgument("code", &mCode); } | ||
CHIP_ERROR Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) override; | ||
|
||
private: | ||
char * mCode; | ||
CHIP_ERROR Parse(std::string codeString, chip::SetupPayload & payload); | ||
CHIP_ERROR Print(chip::SetupPayload payload); | ||
bool IsQRCode(std::string codeString); | ||
const std::string QRCODE_PREFIX = "CH:"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Prefer static constexpr char QRCODE_PREFIX[] = "CH:"; |
||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a new line