/** MIT License Copyright (c) 2024 KPI Rover Project This file contains modifications and extensions to the original uLog library. Original uLog library: Copyright (c) 2019 R. Dunbar Poor Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * \file ulog.c * * \brief uLog: lightweight logging for embedded systems * * See ulog.h for sparse documentation. */ #include "ulog.h" #ifdef ULOG_ENABLED // whole file... #include #include #include // ============================================================================= // types and definitions typedef struct { ulog_function_t fn; ulog_level_t threshold; } subscriber_t; static ulog_level_t ulog_lowest_log_level(); // ============================================================================= // local storage static subscriber_t s_subscribers[ULOG_MAX_SUBSCRIBERS]; static char s_message[ULOG_MAX_MESSAGE_LENGTH]; static ulog_level_t s_lowest_log_level; // ============================================================================= // user-visible code void ulog_init() { memset(s_subscribers, 0, sizeof(s_subscribers)); s_lowest_log_level = ulog_lowest_log_level(); } // search the s_subscribers table to install or update fn ulog_err_t ulog_subscribe(ulog_function_t fn, ulog_level_t threshold) { int available_slot = -1; int i; for (i=0; i= s_subscribers[i].threshold) { s_subscribers[i].fn(severity, filename, s_message); } } } } // ============================================================================= // private code static ulog_level_t ulog_lowest_log_level(){ ulog_level_t lowest_log_level = ULOG_ALWAYS_LEVEL; int i; for (i=0; i