Skip to content

Commit

Permalink
example: Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
pimpalemahesh authored and esp committed Dec 23, 2024
1 parent 4d2d9e2 commit 3e1cf1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -84,7 +80,7 @@ size_t LogProvider::GetSizeForIntent(IntentEnum intent)
return CircularDiagnosticBuffer::GetInstance().GetDataSize();
#else
return static_cast<size_t>(endUserSupportLogEnd - endUserSupportLogStart);
#endif
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
}
break;
case IntentEnum::kNetworkDiag:
Expand Down Expand Up @@ -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<size_t>(endUserSupportLogEnd - endUserSupportLogStart));
#endif
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@

#include <app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h>

#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
#include <tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h>
#endif

#include <map>

#if defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF)
#include <esp_core_dump.h>
#endif // defined(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) && defined(CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF)

#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
#include <tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h>
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 {
Expand Down
16 changes: 7 additions & 9 deletions examples/temperature-measurement-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE
#include <tracing/esp32_diagnostic_trace/DiagnosticTracing.h>
#endif
#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE

namespace {
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
Expand All @@ -79,21 +79,19 @@ 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()
{
#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.
Expand Down

0 comments on commit 3e1cf1a

Please sign in to comment.