From 1f3e4ede83d95ba150a9f2f7af72f690ac5cfddf Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Wed, 27 Jan 2021 16:53:19 +0100 Subject: [PATCH] Removed logs from the configuration manager getter methods. (#4495) * Removed logs from the configuration manager getter methods. Getter methods of the Configuration Manager contain logs, what results in printing the same logs multiple times on the console. * Removed logs from Configuration Manager getter methods * Added printing information about setup pin code and setup discriminator to the LogDeviceConfig() method * Removed if CHIP_PROGRESS_LOGGING condition before LogDeviceConfig() implementation, as it should be checked before calling it (and is already used there) * Created interface to the LogDeviceConfig() to allow using it in samples * Removed returning setupPinCode from the QRCodeUtil::GetQRCode() method. * Removed printing setup pin code from the PrintQRCode method(). * Aligned nrfconnect, EFR32 and QPG6100 samples, because of the QRCodeUtil API changes. * Restyled by clang-format Co-authored-by: Restyled.io --- examples/lighting-app/efr32/src/AppTask.cpp | 6 +-- .../lighting-app/nrfconnect/main/AppTask.cpp | 4 +- examples/lock-app/efr32/src/AppTask.cpp | 6 +-- examples/lock-app/nrfconnect/main/AppTask.cpp | 4 +- examples/lock-app/qpg6100/src/AppTask.cpp | 1 + src/app/server/QRCodeUtil.cpp | 7 +--- src/app/server/QRCodeUtil.h | 2 +- src/include/platform/ConfigurationManager.h | 8 ++++ .../GenericConfigurationManagerImpl.cpp | 37 +++++++++++-------- .../GenericConfigurationManagerImpl.h | 2 +- 10 files changed, 45 insertions(+), 32 deletions(-) diff --git a/examples/lighting-app/efr32/src/AppTask.cpp b/examples/lighting-app/efr32/src/AppTask.cpp index a90c08d4cc2bde..917571c498dc7d 100644 --- a/examples/lighting-app/efr32/src/AppTask.cpp +++ b/examples/lighting-app/efr32/src/AppTask.cpp @@ -132,14 +132,14 @@ int AppTask::Init() sLightLED.Set(LightMgr().IsLightOn()); UpdateClusterState(); + ConfigurationMgr().LogDeviceConfig(); + // Print setup info on LCD if available #ifdef DISPLAY_ENABLED - uint32_t setupPinCode; std::string QRCode; - if (GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR) + if (GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR) { - EFR32_LOG("SetupPINCode: [%09u]", setupPinCode); LCDWriteQRCode((uint8_t *) QRCode.c_str()); } else diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index c3bc0515138e4e..320bedee55cde1 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -112,6 +112,7 @@ int AppTask::Init() // Init ZCL Data Model and start server InitServer(); + ConfigurationMgr().LogDeviceConfig(); PrintQRCode(chip::RendezvousInformationFlags::kBLE); #ifdef CONFIG_CHIP_NFC_COMMISSIONING @@ -436,10 +437,9 @@ void AppTask::StartTimer(uint32_t aTimeoutInMs) int AppTask::StartNFCTag() { // Get QR Code and emulate its content using NFC tag - uint32_t setupPinCode; std::string QRCode; - int result = GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE); + int result = GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE); VerifyOrExit(!result, ChipLogError(AppServer, "Getting QR code payload failed")); result = sNFC.StartTagEmulation(QRCode.c_str(), QRCode.size()); diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index b02a1c8d21c9c5..866770e100724b 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -132,14 +132,14 @@ int AppTask::Init() sLockLED.Set(!BoltLockMgr().IsUnlocked()); UpdateClusterState(); + ConfigurationMgr().LogDeviceConfig(); + // Print setup info on LCD if available #ifdef DISPLAY_ENABLED - uint32_t setupPinCode; std::string QRCode; - if (GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR) + if (GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR) { - EFR32_LOG("SetupPINCode: [%09u]", setupPinCode); LCDWriteQRCode((uint8_t *) QRCode.c_str()); } else diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index 4b9e87abca082f..8013a83c6d911e 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -104,6 +104,7 @@ int AppTask::Init() // Init ZCL Data Model and start server InitServer(); + ConfigurationMgr().LogDeviceConfig(); PrintQRCode(chip::RendezvousInformationFlags::kBLE); #ifdef CONFIG_CHIP_NFC_COMMISSIONING @@ -438,10 +439,9 @@ void AppTask::StartTimer(uint32_t aTimeoutInMs) int AppTask::StartNFCTag() { // Get QR Code and emulate its content using NFC tag - uint32_t setupPinCode; std::string QRCode; - int result = GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE); + int result = GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE); VerifyOrExit(!result, ChipLogError(AppServer, "Getting QR code payload failed")); result = sNFC.StartTagEmulation(QRCode.c_str(), QRCode.size()); diff --git a/examples/lock-app/qpg6100/src/AppTask.cpp b/examples/lock-app/qpg6100/src/AppTask.cpp index 2f511bda6ad42e..e951258208af91 100644 --- a/examples/lock-app/qpg6100/src/AppTask.cpp +++ b/examples/lock-app/qpg6100/src/AppTask.cpp @@ -104,6 +104,7 @@ int AppTask::Init() InitServer(); UpdateClusterState(); + ConfigurationMgr().LogDeviceConfig(); PrintQRCode(chip::RendezvousInformationFlags::kBLE); return err; diff --git a/src/app/server/QRCodeUtil.cpp b/src/app/server/QRCodeUtil.cpp index 8326e50d5fe2ef..a707718eec365c 100644 --- a/src/app/server/QRCodeUtil.cpp +++ b/src/app/server/QRCodeUtil.cpp @@ -31,16 +31,14 @@ constexpr char specialCharsUnreservedInRfc3986[] = "-._~"; void PrintQRCode(chip::RendezvousInformationFlags rendezvousFlags) { - uint32_t setupPinCode; std::string QRCode; - if (GetQRCode(setupPinCode, QRCode, rendezvousFlags) == CHIP_NO_ERROR) + if (GetQRCode(QRCode, rendezvousFlags) == CHIP_NO_ERROR) { chip::Platform::ScopedMemoryBuffer qrCodeBuffer; const size_t qrCodeBufferMaxSize = 3 * QRCode.size() + 1; qrCodeBuffer.Alloc(qrCodeBufferMaxSize); - ChipLogProgress(AppServer, "SetupPINCode: [%" PRIu32 "]", setupPinCode); ChipLogProgress(AppServer, "SetupQRCode: [%s]", QRCode.c_str()); if (EncodeQRCodeToUrl(QRCode.c_str(), QRCode.size(), &qrCodeBuffer[0], qrCodeBufferMaxSize) == CHIP_NO_ERROR) { @@ -54,7 +52,7 @@ void PrintQRCode(chip::RendezvousInformationFlags rendezvousFlags) } } -CHIP_ERROR GetQRCode(uint32_t & setupPinCode, std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags) +CHIP_ERROR GetQRCode(std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags) { using namespace ::chip::DeviceLayer; @@ -67,7 +65,6 @@ CHIP_ERROR GetQRCode(uint32_t & setupPinCode, std::string & QRCode, chip::Rendez err = ConfigurationMgr().GetSetupPinCode(payload.setUpPINCode); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogProgress(AppServer, "ConfigurationMgr().GetSetupPinCode() failed: %s", chip::ErrorStr(err))); - setupPinCode = payload.setUpPINCode; err = ConfigurationMgr().GetSetupDiscriminator(payload.discriminator); VerifyOrExit(err == CHIP_NO_ERROR, diff --git a/src/app/server/QRCodeUtil.h b/src/app/server/QRCodeUtil.h index a27ead18aa7f70..68aee821738dea 100644 --- a/src/app/server/QRCodeUtil.h +++ b/src/app/server/QRCodeUtil.h @@ -20,7 +20,7 @@ #include void PrintQRCode(chip::RendezvousInformationFlags rendezvousFlags); -CHIP_ERROR GetQRCode(uint32_t & setupPinCode, std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags); +CHIP_ERROR GetQRCode(std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags); /** * Initialize DataModelHandler and start CHIP datamodel server, the server diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 28e2cb9c3ef235..f42cc3ca7d35c5 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -132,6 +132,8 @@ class ConfigurationManager CHIP_ERROR ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize); + void LogDeviceConfig(); + private: // ===== Members for internal use by the following friends. @@ -538,5 +540,11 @@ inline void ConfigurationManager::UseManufacturerCredentialsAsOperational(bool v } #endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + +inline void ConfigurationManager::LogDeviceConfig() +{ + static_cast(this)->_LogDeviceConfig(); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp index 34ddf8ed546830..6335dbf742571e 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp @@ -96,7 +96,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ConfigureChipStack() #if CHIP_PROGRESS_LOGGING - Impl()->LogDeviceConfig(); + Impl()->_LogDeviceConfig(); #if CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH { @@ -193,8 +193,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetSerialNumber(char * b VerifyOrExit(sizeof(CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER) <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(buf, CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER, sizeof(CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER)); serialNumLen = sizeof(CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER) - 1; - ChipLogProgress(DeviceLayer, "Serial Number not found; using default: %s", CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER); - err = CHIP_NO_ERROR; + err = CHIP_NO_ERROR; } #endif // CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER SuccessOrExit(err); @@ -324,7 +323,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceCer certLen = TestDeviceCertLength; VerifyOrExit(buf != NULL, err = CHIP_NO_ERROR); VerifyOrExit(TestDeviceCertLength <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL); - ChipLogProgress(DeviceLayer, "Device certificate not found; using default"); memcpy(buf, TestDeviceCert, TestDeviceCertLength); err = CHIP_NO_ERROR; } @@ -358,7 +356,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceInt certsLen = TestDeviceIntermediateCACertLength; VerifyOrExit(buf != NULL, err = CHIP_NO_ERROR); VerifyOrExit(TestDeviceIntermediateCACertLength <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL); - ChipLogProgress(DeviceLayer, "Device certificate not found; using default"); memcpy(buf, TestDeviceIntermediateCACert, TestDeviceIntermediateCACertLength); err = CHIP_NO_ERROR; } @@ -393,7 +390,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDevicePri keyLen = TestDevicePrivateKeyLength; VerifyOrExit(buf != NULL, err = CHIP_NO_ERROR); VerifyOrExit(TestDevicePrivateKeyLength <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL); - ChipLogProgress(DeviceLayer, "Device private key not found; using default"); memcpy(buf, TestDevicePrivateKey, TestDevicePrivateKeyLength); err = CHIP_NO_ERROR; } @@ -558,8 +554,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetSetupPinCode(uint32_t if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { setupPinCode = CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE; - ChipLogProgress(DeviceLayer, "Setup PIN code not found; using default: %09u", CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE); - err = CHIP_NO_ERROR; + err = CHIP_NO_ERROR; } #endif // defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE SuccessOrExit(err); @@ -585,8 +580,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetSetupDiscriminator(ui if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { val = CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR; - ChipLogProgress(DeviceLayer, "Setup PIN discriminator not found; using default: %03x", - CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR); err = CHIP_NO_ERROR; } #endif // defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR @@ -1025,10 +1018,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::_RunUnitTests() } #endif -#if CHIP_PROGRESS_LOGGING - template -void GenericConfigurationManagerImpl::LogDeviceConfig() +void GenericConfigurationManagerImpl::_LogDeviceConfig() { CHIP_ERROR err; @@ -1072,6 +1063,24 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() ChipLogProgress(DeviceLayer, " Product Revision: %" PRIu16, productRev); } + { + uint32_t setupPINCode; + if (Impl()->_GetSetupPinCode(setupPINCode) != CHIP_NO_ERROR) + { + setupPINCode = 0; + } + ChipLogProgress(DeviceLayer, " Setup Pin Code: %" PRIu32 "", setupPINCode); + } + + { + uint16_t setupDiscriminator; + if (Impl()->_GetSetupDiscriminator(setupDiscriminator) != CHIP_NO_ERROR) + { + setupDiscriminator = 0; + } + ChipLogProgress(DeviceLayer, " Setup Discriminator: %" PRIu16 " (0x%" PRIX16 ")", setupDiscriminator, setupDiscriminator); + } + { uint16_t year; uint8_t month, dayOfMonth; @@ -1100,8 +1109,6 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() #endif // CHIP_CONFIG_ENABLE_FABRIC_STATE } -#endif // CHIP_PROGRESS_LOGGING - // Fully instantiate the generic implementation class in whatever compilation unit includes this file. template class GenericConfigurationManagerImpl; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index 5d6b3dd8933895..b475e4f0ea2b9a 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -114,6 +114,7 @@ class GenericConfigurationManagerImpl bool _OperationalDeviceCredentialsProvisioned(); void _UseManufacturerCredentialsAsOperational(bool val); #endif + void _LogDeviceConfig(); protected: enum @@ -127,7 +128,6 @@ class GenericConfigurationManagerImpl uint8_t mFlags; - void LogDeviceConfig(); CHIP_ERROR PersistProvisioningData(ProvisioningDataSet & provData); private: