From b5cd04fb860df6b221d752cfd6428a62d1eea4d2 Mon Sep 17 00:00:00 2001 From: Jan Umbach Date: Thu, 7 Sep 2023 15:41:45 +0200 Subject: [PATCH] added cumstom Panic Handler --- include/jannex/jannex.h | 4 +++- src/jannex.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/jannex/jannex.h b/include/jannex/jannex.h index 45b3734..e1d7350 100644 --- a/include/jannex/jannex.h +++ b/include/jannex/jannex.h @@ -38,4 +38,6 @@ static EventGroupHandle_t s_wifi_event_group; static const char *jannexTAG = "JANNEX"; void initJannex(); -void updateJannex(); \ No newline at end of file +void updateJannex(); + +void setCustomPanicHandler(void (*func)()); \ No newline at end of file diff --git a/src/jannex.c b/src/jannex.c index b350b41..e97a6dc 100644 --- a/src/jannex.c +++ b/src/jannex.c @@ -216,12 +216,23 @@ void updateJannex() // Declare the real panic handler function. We'll be able to call it after executing our custom code void __real_esp_panic_handler(void *); +void (*customPanicHandler)() = NULL; + +void setCustomPanicHandler(void (*func)()) +{ + customPanicHandler = func; +} // This function will be considered the esp_panic_handler to call in case a panic occurs void __wrap_esp_panic_handler(panic_info_t *info) { // Custom code, count the number of panics or simply print a message panicRetryCounter++; + if (customPanicHandler != NULL) + { + customPanicHandler(); + } + // Convert the integer to a string // char retryCounterStr[10]; // Adjust the size as needed // snprintf(retryCounterStr, sizeof(retryCounterStr), "%d", panicRetryCounter);