From cf1444e1c537f504a4017f385b3d395a7c4ca75c Mon Sep 17 00:00:00 2001 From: Matthieu A Date: Thu, 22 Jan 2026 01:05:49 +0100 Subject: [PATCH] Add array logging capability --- include/ulog.h | 8 ++++++++ src/ulog.c | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/ulog.h b/include/ulog.h index 3ead717..f7ffcf9 100644 --- a/include/ulog.h +++ b/include/ulog.h @@ -428,6 +428,14 @@ void ulog_log(ulog_level level, const char *file, /// @brief Clean up all topic, outputs and other dynamic resources ulog_status ulog_cleanup(void); +/* ============================================================================ + Feature: Array logging +============================================================================ */ + +void ulog_array_log(ulog_level level, const char *file, int line, + const uint8_t* array, const size_t array_size, + const char *message, ...); + /* ============================================================================ Optional Feature: Disable ============================================================================ */ diff --git a/src/ulog.c b/src/ulog.c index db1cf1d..f363902 100644 --- a/src/ulog.c +++ b/src/ulog.c @@ -40,6 +40,8 @@ | ULOG_BUILD_CONFIG_HEADER_ENABLED | 0 | - | Configuration header mode| | ULOG_BUILD_CONFIG_HEADER_NAME | "ulog_config.h" | - | Configuration header name| | ULOG_BUILD_DISABLED | 0 | - | Disable ulog completely | +| ULOG_BUILD_ARRAY_LOGGING | 1 | - | Array formating | +| ULOG_BUILD_ARRAY_MAX_SIZE | 4096 | ULOG_BUILD_ARRAY_LOGGING | Maximum array size | ===================================================================================================================== */ @@ -1170,8 +1172,8 @@ ulog_status ulog_topic_config(bool enabled) { // Private // ================ #ifndef ULOG_BUILD_TOPICS_STATIC_NUM - /* If static count not provided, default to 0 */ - #define ULOG_BUILD_TOPICS_STATIC_NUM 0 +/* If static count not provided, default to 0 */ +#define ULOG_BUILD_TOPICS_STATIC_NUM 0 #endif /* Dynamic if mode equals DYNAMIC */ @@ -1867,4 +1869,22 @@ ulog_status ulog_cleanup(void) { return lock_unlock(); } +/* ============================================================================ + Core Feature: Clean up + (`init_*`, depends on: Locking, Outputs, Prefix, Time, Color) +============================================================================ */ + +// Public +// ================ + +void ulog_array_log(ulog_level level, const char *file, int line, + const uint8_t *array, const size_t array_size, + const char *message, ...) { + if (lock_lock() != ULOG_STATUS_OK) { + return; // Failed to acquire lock, drop log + } + + (void)lock_unlock(); +} + #endif // ULOG_BUILD_DISABLED