Skip to content

Commit

Permalink
Reorder setup payload output, align and add human friendly capabiliti…
Browse files Browse the repository at this point in the history
…es (#18803)

* Reorder setup payload output, align and add human friendly capabilities

* Add human friendly output for custom flow as well

* Restyle

* Ensure comma separated human friendly values

* add local function ifdef guards, to avoid compiler warning when progress loggging is disabled

* Revert unintended change

* Revert unintended change
  • Loading branch information
andy31415 authored and pull[bot] committed Jan 3, 2024
1 parent 02a3dd0 commit 1017655
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
69 changes: 63 additions & 6 deletions examples/chip-tool/commands/payload/SetupPayloadParseCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,36 @@
*/

#include "SetupPayloadParseCommand.h"
#include <lib/support/StringBuilder.h>
#include <setup_payload/ManualSetupPayloadParser.h>
#include <setup_payload/QRCodeSetupPayloadParser.h>
#include <setup_payload/SetupPayload.h>

using namespace ::chip;

namespace {

#if CHIP_PROGRESS_LOGGING

const char * CustomFlowString(CommissioningFlow flow)
{
switch (flow)
{
case CommissioningFlow::kStandard:
return "STANDARD";
case CommissioningFlow::kUserActionRequired:
return "USER ACTION REQUIRED";
case CommissioningFlow::kCustom:
return "CUSTOM";
}

return "???";
}

#endif // CHIP_PROGRESS_LOGGING

} // namespace

CHIP_ERROR SetupPayloadParseCommand::Run()
{
std::string codeString(mCode);
Expand All @@ -46,13 +70,46 @@ CHIP_ERROR SetupPayloadParseCommand::Parse(std::string codeString, chip::SetupPa

CHIP_ERROR SetupPayloadParseCommand::Print(chip::SetupPayload payload)
{
ChipLogProgress(SetupPayload, "CommissioningFlow: %u", to_underlying(payload.commissioningFlow));
ChipLogProgress(SetupPayload, "VendorID: %u", payload.vendorID);
ChipLogProgress(SetupPayload, "Version: %u", payload.version);
ChipLogProgress(SetupPayload, "ProductID: %u", payload.productID);
ChipLogProgress(SetupPayload, "Version: %u", payload.version);
ChipLogProgress(SetupPayload, "VendorID: %u", payload.vendorID);
ChipLogProgress(SetupPayload, "ProductID: %u", payload.productID);
ChipLogProgress(SetupPayload, "Custom flow: %u (%s)", to_underlying(payload.commissioningFlow),
CustomFlowString(payload.commissioningFlow));
{
StringBuilder<128> humanFlags;

if (payload.rendezvousInformation.HasAny())
{
if (payload.rendezvousInformation.Has(RendezvousInformationFlag::kSoftAP))
{
humanFlags.Add("Soft-AP");
}
if (payload.rendezvousInformation.Has(RendezvousInformationFlag::kBLE))
{
if (!humanFlags.Empty())
{
humanFlags.Add(", ");
}
humanFlags.Add("BLE");
}
if (payload.rendezvousInformation.Has(RendezvousInformationFlag::kOnNetwork))
{
if (!humanFlags.Empty())
{
humanFlags.Add(", ");
}
humanFlags.Add("On IP network");
}
}
else
{
humanFlags.Add("NONE");
}

ChipLogProgress(SetupPayload, "Capabilities: 0x%02X (%s)", payload.rendezvousInformation.Raw(), humanFlags.c_str());
}
ChipLogProgress(SetupPayload, "Discriminator: %u", payload.discriminator);
ChipLogProgress(SetupPayload, "SetUpPINCode: %u", payload.setUpPINCode);
ChipLogProgress(SetupPayload, "RendezvousInformation: %u", payload.rendezvousInformation.Raw());
ChipLogProgress(SetupPayload, "Passcode: %u", payload.setUpPINCode);

std::string serialNumber;
if (payload.getSerialNumber(serialNumber) == CHIP_NO_ERROR)
Expand Down
3 changes: 3 additions & 0 deletions src/lib/support/StringBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class StringBuilderBase
/// did all the values fit?
bool Fit() const { return mWriter.Fit(); }

/// Was nothing written yet?
bool Empty() const { return mWriter.Needed() == 0; }

/// access the underlying value
const char * c_str() const { return reinterpret_cast<const char *>(mWriter.Buffer()); }

Expand Down

0 comments on commit 1017655

Please sign in to comment.