From 3a2496975b7b6ed41b1cd9c5ecd331e3ff26b2df Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 26 Jul 2022 02:33:59 -0400 Subject: [PATCH] Ensure we log the full generated setup payload in chip-tool. (#21207) For large payloads we were only logging whatever happened to fit in CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE. --- .../commands/payload/SetupPayloadGenerateCommand.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/chip-tool/commands/payload/SetupPayloadGenerateCommand.cpp b/examples/chip-tool/commands/payload/SetupPayloadGenerateCommand.cpp index 74abe2a0d58d16..34b046896ee4e8 100644 --- a/examples/chip-tool/commands/payload/SetupPayloadGenerateCommand.cpp +++ b/examples/chip-tool/commands/payload/SetupPayloadGenerateCommand.cpp @@ -95,6 +95,15 @@ CHIP_ERROR SetupPayloadGenerateQRCodeCommand::Run() std::string code; ReturnErrorOnFailure(generator.payloadBase38RepresentationWithAutoTLVBuffer(code)); + // CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE includes various prefixes we don't + // control (timestamps, process ids, etc). Let's assume (hope?) that + // those prefixes use up no more than half the total available space. + constexpr size_t chunkSize = CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE / 2; + while (code.size() > chunkSize) + { + ChipLogProgress(chipTool, "QR Code: %s", code.substr(0, chunkSize).c_str()); + code = code.substr(chunkSize); + } ChipLogProgress(chipTool, "QR Code: %s", code.c_str()); return CHIP_NO_ERROR;