diff --git a/examples/chip-tool/commands/payload/SetupPayloadParseCommand.cpp b/examples/chip-tool/commands/payload/SetupPayloadParseCommand.cpp index 44f51da25e0c9f..5bf65d3976b5a3 100644 --- a/examples/chip-tool/commands/payload/SetupPayloadParseCommand.cpp +++ b/examples/chip-tool/commands/payload/SetupPayloadParseCommand.cpp @@ -17,12 +17,36 @@ */ #include "SetupPayloadParseCommand.h" +#include #include #include #include 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); @@ -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) diff --git a/src/lib/support/StringBuilder.h b/src/lib/support/StringBuilder.h index f16fd760548e6e..85452c217afb9e 100644 --- a/src/lib/support/StringBuilder.h +++ b/src/lib/support/StringBuilder.h @@ -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(mWriter.Buffer()); }