Skip to content

Commit 5f2b9b5

Browse files
pimpalemaheshesp
authored and
esp
committedJan 28, 2025
temperature-measurement-app: review changes
1 parent d6e27ed commit 5f2b9b5

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed
 

‎examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace chip::app::Clusters::DiagnosticLogs;
2929
LogProvider LogProvider::sInstance;
3030
LogProvider::CrashLogContext LogProvider::sCrashLogContext;
3131

32-
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
32+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
3333
static uint32_t sReadEntries = 0;
3434
static uint8_t retrievalBuffer[CONFIG_RETRIEVAL_BUFFER_SIZE];
3535
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
@@ -80,7 +80,7 @@ size_t LogProvider::GetSizeForIntent(IntentEnum intent)
8080
switch (intent)
8181
{
8282
case IntentEnum::kEndUserSupport: {
83-
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
83+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
8484
VerifyOrReturnError(mStorageInstance != nullptr, 0,
8585
ChipLogError(DeviceLayer, "Diagnostic Storage instance cannot be null."));
8686
return mStorageInstance->GetDataSize();
@@ -120,7 +120,7 @@ CHIP_ERROR LogProvider::PrepareLogContextForIntent(LogContext * context, IntentE
120120
switch (intent)
121121
{
122122
case IntentEnum::kEndUserSupport: {
123-
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
123+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
124124
VerifyOrReturnError(mStorageInstance != nullptr, CHIP_ERROR_INTERNAL,
125125
ChipLogError(DeviceLayer, "Diagnostic Storage instance cannot be null."));
126126
MutableByteSpan endUserSupportSpan(retrievalBuffer, CONFIG_RETRIEVAL_BUFFER_SIZE);
@@ -130,7 +130,7 @@ CHIP_ERROR LogProvider::PrepareLogContextForIntent(LogContext * context, IntentE
130130
CHIP_ERROR err = mStorageInstance->Retrieve(endUserSupportSpan, sReadEntries);
131131
if (err != CHIP_NO_ERROR)
132132
{
133-
ChipLogError(DeviceLayer, "Failed to retrieve data: %s", chip::ErrorStr(err));
133+
ChipLogError(DeviceLayer, "Failed to retrieve data: %" CHIP_ERROR_FORMAT, err.Format());
134134
return err;
135135
}
136136
context->EndUserSupport.span = endUserSupportSpan;
@@ -318,7 +318,7 @@ CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle, CHIP_ER
318318
}
319319
else
320320
{
321-
ChipLogProgress(DeviceLayer, "Cleared all read diagnostics successfully");
321+
ChipLogDetail(DeviceLayer, "Cleared all read diagnostics successfully");
322322
}
323323
}
324324
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE

‎examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <esp_core_dump.h>
2727
#endif // defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF)
2828

29-
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
29+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
3030
#include <tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h>
3131
using namespace chip::Tracing::Diagnostics;
3232
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
@@ -45,16 +45,7 @@ namespace DiagnosticLogs {
4545
class LogProvider : public DiagnosticLogsProviderDelegate
4646
{
4747
public:
48-
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
49-
static inline LogProvider & GetInstance(CircularDiagnosticBuffer * bufferInstance)
50-
{
51-
VerifyOrReturnValue(bufferInstance != nullptr, sInstance);
52-
sInstance.mStorageInstance = bufferInstance;
53-
return sInstance;
54-
}
55-
#else
5648
static inline LogProvider & GetInstance() { return sInstance; }
57-
#endif
5849

5950
/////////// DiagnosticLogsProviderDelegate Interface /////////
6051
CHIP_ERROR StartLogCollection(IntentEnum intent, LogSessionHandle & outHandle, Optional<uint64_t> & outTimeStamp,
@@ -64,6 +55,11 @@ class LogProvider : public DiagnosticLogsProviderDelegate
6455
size_t GetSizeForIntent(IntentEnum intent) override;
6556
CHIP_ERROR GetLogForIntent(IntentEnum intent, MutableByteSpan & outBuffer, Optional<uint64_t> & outTimeStamp,
6657
Optional<uint64_t> & outTimeSinceBoot) override;
58+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
59+
void SetDiagnosticStorageInstance(CircularDiagnosticBuffer * bufferInstance) {
60+
mStorageInstance = bufferInstance;
61+
}
62+
#endif
6763

6864
private:
6965
static LogProvider sInstance;
@@ -74,6 +70,7 @@ class LogProvider : public DiagnosticLogsProviderDelegate
7470
LogProvider & operator=(const LogProvider &) = delete;
7571

7672
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
73+
// If mStorageInstance is nullptr then operations related to diagnostic storage will be skipped.
7774
CircularDiagnosticBuffer * mStorageInstance = nullptr;
7875
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
7976

‎examples/temperature-measurement-app/esp32/main/main.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include <DeviceInfoProviderImpl.h>
5353
#endif // CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER
5454

55-
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
55+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
5656
#include <tracing/esp32_diagnostic_trace/DiagnosticTracing.h>
5757
static uint8_t endUserBuffer[CONFIG_END_USER_BUFFER_SIZE]; // Global static buffer used to store diagnostics
5858
using namespace chip::Tracing::Diagnostics;
@@ -82,8 +82,7 @@ static AppDeviceCallbacks EchoCallbacks;
8282
static void InitServer(intptr_t context)
8383
{
8484
Esp32AppServer::Init(); // Init ZCL Data Model and CHIP App Server AND Initialize device attestation config
85-
#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
86-
diagnosticStorage.Init(endUserBuffer, CONFIG_END_USER_BUFFER_SIZE);
85+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
8786
static ESP32Diagnostics diagnosticBackend(&diagnosticStorage);
8887
Tracing::Register(diagnosticBackend);
8988
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
@@ -144,10 +143,9 @@ extern "C" void app_main()
144143
using namespace chip::app::Clusters::DiagnosticLogs;
145144
void emberAfDiagnosticLogsClusterInitCallback(chip::EndpointId endpoint)
146145
{
147-
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
148-
auto & logProvider = LogProvider::GetInstance(&diagnosticStorage);
149-
#else
150146
auto & logProvider = LogProvider::GetInstance();
147+
#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
148+
logProvider.SetDiagnosticStorageInstance(&diagnosticStorage);
151149
#endif
152150
DiagnosticLogsServer::Instance().SetDiagnosticLogsProviderDelegate(endpoint, &logProvider);
153151
}

0 commit comments

Comments
 (0)