Skip to content

Commit 1f3e4ed

Browse files
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 <[email protected]>
1 parent 9318d13 commit 1f3e4ed

File tree

10 files changed

+45
-32
lines changed

10 files changed

+45
-32
lines changed

examples/lighting-app/efr32/src/AppTask.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ int AppTask::Init()
132132
sLightLED.Set(LightMgr().IsLightOn());
133133
UpdateClusterState();
134134

135+
ConfigurationMgr().LogDeviceConfig();
136+
135137
// Print setup info on LCD if available
136138
#ifdef DISPLAY_ENABLED
137-
uint32_t setupPinCode;
138139
std::string QRCode;
139140

140-
if (GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
141+
if (GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
141142
{
142-
EFR32_LOG("SetupPINCode: [%09u]", setupPinCode);
143143
LCDWriteQRCode((uint8_t *) QRCode.c_str());
144144
}
145145
else

examples/lighting-app/nrfconnect/main/AppTask.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ int AppTask::Init()
112112

113113
// Init ZCL Data Model and start server
114114
InitServer();
115+
ConfigurationMgr().LogDeviceConfig();
115116
PrintQRCode(chip::RendezvousInformationFlags::kBLE);
116117

117118
#ifdef CONFIG_CHIP_NFC_COMMISSIONING
@@ -436,10 +437,9 @@ void AppTask::StartTimer(uint32_t aTimeoutInMs)
436437
int AppTask::StartNFCTag()
437438
{
438439
// Get QR Code and emulate its content using NFC tag
439-
uint32_t setupPinCode;
440440
std::string QRCode;
441441

442-
int result = GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE);
442+
int result = GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE);
443443
VerifyOrExit(!result, ChipLogError(AppServer, "Getting QR code payload failed"));
444444

445445
result = sNFC.StartTagEmulation(QRCode.c_str(), QRCode.size());

examples/lock-app/efr32/src/AppTask.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ int AppTask::Init()
132132
sLockLED.Set(!BoltLockMgr().IsUnlocked());
133133
UpdateClusterState();
134134

135+
ConfigurationMgr().LogDeviceConfig();
136+
135137
// Print setup info on LCD if available
136138
#ifdef DISPLAY_ENABLED
137-
uint32_t setupPinCode;
138139
std::string QRCode;
139140

140-
if (GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
141+
if (GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
141142
{
142-
EFR32_LOG("SetupPINCode: [%09u]", setupPinCode);
143143
LCDWriteQRCode((uint8_t *) QRCode.c_str());
144144
}
145145
else

examples/lock-app/nrfconnect/main/AppTask.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ int AppTask::Init()
104104

105105
// Init ZCL Data Model and start server
106106
InitServer();
107+
ConfigurationMgr().LogDeviceConfig();
107108
PrintQRCode(chip::RendezvousInformationFlags::kBLE);
108109

109110
#ifdef CONFIG_CHIP_NFC_COMMISSIONING
@@ -438,10 +439,9 @@ void AppTask::StartTimer(uint32_t aTimeoutInMs)
438439
int AppTask::StartNFCTag()
439440
{
440441
// Get QR Code and emulate its content using NFC tag
441-
uint32_t setupPinCode;
442442
std::string QRCode;
443443

444-
int result = GetQRCode(setupPinCode, QRCode, chip::RendezvousInformationFlags::kBLE);
444+
int result = GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE);
445445
VerifyOrExit(!result, ChipLogError(AppServer, "Getting QR code payload failed"));
446446

447447
result = sNFC.StartTagEmulation(QRCode.c_str(), QRCode.size());

examples/lock-app/qpg6100/src/AppTask.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ int AppTask::Init()
104104
InitServer();
105105
UpdateClusterState();
106106

107+
ConfigurationMgr().LogDeviceConfig();
107108
PrintQRCode(chip::RendezvousInformationFlags::kBLE);
108109

109110
return err;

src/app/server/QRCodeUtil.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ constexpr char specialCharsUnreservedInRfc3986[] = "-._~";
3131

3232
void PrintQRCode(chip::RendezvousInformationFlags rendezvousFlags)
3333
{
34-
uint32_t setupPinCode;
3534
std::string QRCode;
3635

37-
if (GetQRCode(setupPinCode, QRCode, rendezvousFlags) == CHIP_NO_ERROR)
36+
if (GetQRCode(QRCode, rendezvousFlags) == CHIP_NO_ERROR)
3837
{
3938
chip::Platform::ScopedMemoryBuffer<char> qrCodeBuffer;
4039
const size_t qrCodeBufferMaxSize = 3 * QRCode.size() + 1;
4140
qrCodeBuffer.Alloc(qrCodeBufferMaxSize);
4241

43-
ChipLogProgress(AppServer, "SetupPINCode: [%" PRIu32 "]", setupPinCode);
4442
ChipLogProgress(AppServer, "SetupQRCode: [%s]", QRCode.c_str());
4543
if (EncodeQRCodeToUrl(QRCode.c_str(), QRCode.size(), &qrCodeBuffer[0], qrCodeBufferMaxSize) == CHIP_NO_ERROR)
4644
{
@@ -54,7 +52,7 @@ void PrintQRCode(chip::RendezvousInformationFlags rendezvousFlags)
5452
}
5553
}
5654

57-
CHIP_ERROR GetQRCode(uint32_t & setupPinCode, std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags)
55+
CHIP_ERROR GetQRCode(std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags)
5856
{
5957
using namespace ::chip::DeviceLayer;
6058

@@ -67,7 +65,6 @@ CHIP_ERROR GetQRCode(uint32_t & setupPinCode, std::string & QRCode, chip::Rendez
6765
err = ConfigurationMgr().GetSetupPinCode(payload.setUpPINCode);
6866
VerifyOrExit(err == CHIP_NO_ERROR,
6967
ChipLogProgress(AppServer, "ConfigurationMgr().GetSetupPinCode() failed: %s", chip::ErrorStr(err)));
70-
setupPinCode = payload.setUpPINCode;
7168

7269
err = ConfigurationMgr().GetSetupDiscriminator(payload.discriminator);
7370
VerifyOrExit(err == CHIP_NO_ERROR,

src/app/server/QRCodeUtil.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <setup_payload/SetupPayload.h>
2121

2222
void PrintQRCode(chip::RendezvousInformationFlags rendezvousFlags);
23-
CHIP_ERROR GetQRCode(uint32_t & setupPinCode, std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags);
23+
CHIP_ERROR GetQRCode(std::string & QRCode, chip::RendezvousInformationFlags rendezvousFlags);
2424

2525
/**
2626
* Initialize DataModelHandler and start CHIP datamodel server, the server

src/include/platform/ConfigurationManager.h

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class ConfigurationManager
132132

133133
CHIP_ERROR ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize);
134134

135+
void LogDeviceConfig();
136+
135137
private:
136138
// ===== Members for internal use by the following friends.
137139

@@ -538,5 +540,11 @@ inline void ConfigurationManager::UseManufacturerCredentialsAsOperational(bool v
538540
}
539541

540542
#endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
543+
544+
inline void ConfigurationManager::LogDeviceConfig()
545+
{
546+
static_cast<ImplClass *>(this)->_LogDeviceConfig();
547+
}
548+
541549
} // namespace DeviceLayer
542550
} // namespace chip

src/include/platform/internal/GenericConfigurationManagerImpl.cpp

+22-15
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_ConfigureChipStack()
9696

9797
#if CHIP_PROGRESS_LOGGING
9898

99-
Impl()->LogDeviceConfig();
99+
Impl()->_LogDeviceConfig();
100100

101101
#if CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH
102102
{
@@ -193,8 +193,7 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetSerialNumber(char * b
193193
VerifyOrExit(sizeof(CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER) <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL);
194194
memcpy(buf, CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER, sizeof(CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER));
195195
serialNumLen = sizeof(CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER) - 1;
196-
ChipLogProgress(DeviceLayer, "Serial Number not found; using default: %s", CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER);
197-
err = CHIP_NO_ERROR;
196+
err = CHIP_NO_ERROR;
198197
}
199198
#endif // CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER
200199
SuccessOrExit(err);
@@ -324,7 +323,6 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetManufacturerDeviceCer
324323
certLen = TestDeviceCertLength;
325324
VerifyOrExit(buf != NULL, err = CHIP_NO_ERROR);
326325
VerifyOrExit(TestDeviceCertLength <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL);
327-
ChipLogProgress(DeviceLayer, "Device certificate not found; using default");
328326
memcpy(buf, TestDeviceCert, TestDeviceCertLength);
329327
err = CHIP_NO_ERROR;
330328
}
@@ -358,7 +356,6 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetManufacturerDeviceInt
358356
certsLen = TestDeviceIntermediateCACertLength;
359357
VerifyOrExit(buf != NULL, err = CHIP_NO_ERROR);
360358
VerifyOrExit(TestDeviceIntermediateCACertLength <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL);
361-
ChipLogProgress(DeviceLayer, "Device certificate not found; using default");
362359
memcpy(buf, TestDeviceIntermediateCACert, TestDeviceIntermediateCACertLength);
363360
err = CHIP_NO_ERROR;
364361
}
@@ -393,7 +390,6 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetManufacturerDevicePri
393390
keyLen = TestDevicePrivateKeyLength;
394391
VerifyOrExit(buf != NULL, err = CHIP_NO_ERROR);
395392
VerifyOrExit(TestDevicePrivateKeyLength <= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL);
396-
ChipLogProgress(DeviceLayer, "Device private key not found; using default");
397393
memcpy(buf, TestDevicePrivateKey, TestDevicePrivateKeyLength);
398394
err = CHIP_NO_ERROR;
399395
}
@@ -558,8 +554,7 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetSetupPinCode(uint32_t
558554
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
559555
{
560556
setupPinCode = CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE;
561-
ChipLogProgress(DeviceLayer, "Setup PIN code not found; using default: %09u", CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE);
562-
err = CHIP_NO_ERROR;
557+
err = CHIP_NO_ERROR;
563558
}
564559
#endif // defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
565560
SuccessOrExit(err);
@@ -585,8 +580,6 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetSetupDiscriminator(ui
585580
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
586581
{
587582
val = CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR;
588-
ChipLogProgress(DeviceLayer, "Setup PIN discriminator not found; using default: %03x",
589-
CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR);
590583
err = CHIP_NO_ERROR;
591584
}
592585
#endif // defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
@@ -1025,10 +1018,8 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_RunUnitTests()
10251018
}
10261019
#endif
10271020

1028-
#if CHIP_PROGRESS_LOGGING
1029-
10301021
template <class ImplClass>
1031-
void GenericConfigurationManagerImpl<ImplClass>::LogDeviceConfig()
1022+
void GenericConfigurationManagerImpl<ImplClass>::_LogDeviceConfig()
10321023
{
10331024
CHIP_ERROR err;
10341025

@@ -1072,6 +1063,24 @@ void GenericConfigurationManagerImpl<ImplClass>::LogDeviceConfig()
10721063
ChipLogProgress(DeviceLayer, " Product Revision: %" PRIu16, productRev);
10731064
}
10741065

1066+
{
1067+
uint32_t setupPINCode;
1068+
if (Impl()->_GetSetupPinCode(setupPINCode) != CHIP_NO_ERROR)
1069+
{
1070+
setupPINCode = 0;
1071+
}
1072+
ChipLogProgress(DeviceLayer, " Setup Pin Code: %" PRIu32 "", setupPINCode);
1073+
}
1074+
1075+
{
1076+
uint16_t setupDiscriminator;
1077+
if (Impl()->_GetSetupDiscriminator(setupDiscriminator) != CHIP_NO_ERROR)
1078+
{
1079+
setupDiscriminator = 0;
1080+
}
1081+
ChipLogProgress(DeviceLayer, " Setup Discriminator: %" PRIu16 " (0x%" PRIX16 ")", setupDiscriminator, setupDiscriminator);
1082+
}
1083+
10751084
{
10761085
uint16_t year;
10771086
uint8_t month, dayOfMonth;
@@ -1100,8 +1109,6 @@ void GenericConfigurationManagerImpl<ImplClass>::LogDeviceConfig()
11001109
#endif // CHIP_CONFIG_ENABLE_FABRIC_STATE
11011110
}
11021111

1103-
#endif // CHIP_PROGRESS_LOGGING
1104-
11051112
// Fully instantiate the generic implementation class in whatever compilation unit includes this file.
11061113
template class GenericConfigurationManagerImpl<ConfigurationManagerImpl>;
11071114

src/include/platform/internal/GenericConfigurationManagerImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class GenericConfigurationManagerImpl
114114
bool _OperationalDeviceCredentialsProvisioned();
115115
void _UseManufacturerCredentialsAsOperational(bool val);
116116
#endif
117+
void _LogDeviceConfig();
117118

118119
protected:
119120
enum
@@ -127,7 +128,6 @@ class GenericConfigurationManagerImpl
127128

128129
uint8_t mFlags;
129130

130-
void LogDeviceConfig();
131131
CHIP_ERROR PersistProvisioningData(ProvisioningDataSet & provData);
132132

133133
private:

0 commit comments

Comments
 (0)