From 3e1cf1a2a107286645af929c30eaa03c3d65a784 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 11 Dec 2024 12:01:55 +0530 Subject: [PATCH] example: Remove redundant code --- ...diagnostic-logs-provider-delegate-impl.cpp | 24 +++++-------------- .../diagnostic-logs-provider-delegate-impl.h | 7 ++---- .../esp32/main/main.cpp | 16 ++++++------- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp b/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp index 2ff9a50765abf0..0eb21e349c96fe 100644 --- a/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp +++ b/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp @@ -29,10 +29,6 @@ using namespace chip::app::Clusters::DiagnosticLogs; LogProvider LogProvider::sInstance; LogProvider::CrashLogContext LogProvider::sCrashLogContext; -#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE -static uint32_t sIntentSize = CONFIG_END_USER_BUFFER_SIZE; -#endif - namespace { bool IsValidIntent(IntentEnum intent) { @@ -84,7 +80,7 @@ size_t LogProvider::GetSizeForIntent(IntentEnum intent) return CircularDiagnosticBuffer::GetInstance().GetDataSize(); #else return static_cast(endUserSupportLogEnd - endUserSupportLogStart); -#endif +#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE } break; case IntentEnum::kNetworkDiag: @@ -122,25 +118,17 @@ CHIP_ERROR LogProvider::PrepareLogContextForIntent(LogContext * context, IntentE CircularDiagnosticBuffer & diagnosticStorage = CircularDiagnosticBuffer::GetInstance(); MutableByteSpan endUserSupportSpan(endUserBuffer, CONFIG_END_USER_BUFFER_SIZE); - if (diagnosticStorage.IsEmptyBuffer()) - { - ChipLogError(DeviceLayer, "Empty Diagnostic buffer"); - return CHIP_ERROR_NOT_FOUND; - } + VerifyOrReturnError(!diagnosticStorage.IsEmptyBuffer(), CHIP_ERROR_NOT_FOUND, + ChipLogError(DeviceLayer, "Empty Diagnostic buffer")); // Retrieve data from the diagnostic storage CHIP_ERROR err = diagnosticStorage.Retrieve(endUserSupportSpan); - if (err != CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "Failed to retrieve data: %s", chip::ErrorStr(err)); - return err; - } - sIntentSize = endUserSupportSpan.size(); - // Now, assign the span to the EndUserSupport object or whatever is required + VerifyOrReturnError(err == CHIP_NO_ERROR, err, + ChipLogError(DeviceLayer, "Failed to retrieve data: %s", chip::ErrorStr(err))); context->EndUserSupport.span = endUserSupportSpan; #else context->EndUserSupport.span = ByteSpan(&endUserSupportLogStart[0], static_cast(endUserSupportLogEnd - endUserSupportLogStart)); -#endif +#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE } break; diff --git a/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h b/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h index a759aa946b2d3e..b748f4a3a61b5b 100644 --- a/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h +++ b/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h @@ -20,10 +20,6 @@ #include -#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE -#include -#endif - #include #if defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF) @@ -31,9 +27,10 @@ #endif // defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF) #if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE +#include static uint8_t endUserBuffer[CONFIG_END_USER_BUFFER_SIZE]; using namespace chip::Tracing::Diagnostics; -#endif +#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE namespace chip { namespace app { diff --git a/examples/temperature-measurement-app/esp32/main/main.cpp b/examples/temperature-measurement-app/esp32/main/main.cpp index 63673094b35b87..35a385dc3ec74e 100644 --- a/examples/temperature-measurement-app/esp32/main/main.cpp +++ b/examples/temperature-measurement-app/esp32/main/main.cpp @@ -54,7 +54,7 @@ #if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE #include -#endif +#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE namespace { #if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER @@ -79,6 +79,12 @@ static AppDeviceCallbacks EchoCallbacks; static void InitServer(intptr_t context) { Esp32AppServer::Init(); // Init ZCL Data Model and CHIP App Server AND Initialize device attestation config +#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE + CircularDiagnosticBuffer & diagnosticStorage = CircularDiagnosticBuffer::GetInstance(); + diagnosticStorage.Init(endUserBuffer, CONFIG_END_USER_BUFFER_SIZE); + static ESP32Diagnostics diagnosticBackend(diagnosticStorage); + Tracing::Register(diagnosticBackend); +#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE } extern "C" void app_main() @@ -86,14 +92,6 @@ extern "C" void app_main() #if CONFIG_ENABLE_PW_RPC chip::rpc::Init(); #endif - -#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE - CircularDiagnosticBuffer & diagnosticStorage = CircularDiagnosticBuffer::GetInstance(); - diagnosticStorage.Init(endUserBuffer, CONFIG_END_USER_BUFFER_SIZE); - static ESP32Diagnostics diagnosticBackend(diagnosticStorage); - Tracing::Register(diagnosticBackend); -#endif - ESP_LOGI(TAG, "Temperature sensor!"); // Initialize the ESP NVS layer.