|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Logging and console I/O implementation with optional hook transports. More...
#include "cdc_log.h"#include <string.h>#include <fcntl.h>#include <unistd.h>#include "sdkconfig.h"#include "esp_timer.h"#include "esp_attr.h"#include "freertos/FreeRTOS.h"#include "freertos/task.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_MODE 1 |
Functions | |
| static void | error_log_add (log_level_t level, const char *message) |
| Adds warning/error entry to PSRAM-backed ring log. | |
| size_t | error_log_get_entries (error_log_entry_t *entries, size_t max_entries) |
| Copies stored error-log entries in chronological order. | |
| size_t | error_log_get_count (void) |
| Returns number of buffered error-log entries. | |
| void | error_log_clear (void) |
| Clears error-log ring buffer state. | |
| void | error_log_dump (void) |
| Dumps buffered error-log entries to console. | |
| void | log_init (void) |
| Logging API implementation. | |
| void | log_set_level (log_level_t level) |
| Sets runtime log verbosity threshold. | |
| log_level_t | log_get_level (void) |
| Returns current log verbosity threshold. | |
| void | log_write (log_level_t level, const char *tag, const char *fmt,...) |
| Writes formatted tagged log line with optional suppression. | |
| void | log_raw (const char *fmt,...) |
| Writes untagged raw formatted text to console. | |
| void | log_hex (const char *tag, const char *label, const uint8_t *data, size_t len) |
| Logs binary buffer as grouped hexadecimal bytes. | |
| void | console_init (void) |
| Initializes console I/O transport state. | |
| bool | console_available (void) |
| Returns whether any console input source has pending data. | |
| int | console_getchar (void) |
| Reads one character from available console input source. | |
| void | console_print (const char *str) |
| Writes string to active console outputs. | |
| void | console_printf (const char *fmt,...) |
| Formatted write helper for console output. | |
| void | console_putchar (char c) |
| Writes single character to active console outputs. | |
| void | console_flush (void) |
| Flushes buffered console output transports. | |
| void | console_register_output_hook (console_output_hook_t hook) |
| Console hook registration API. | |
| void | console_register_input_hook (console_input_available_hook_t avail_hook, console_input_getchar_hook_t getchar_hook) |
| Registers optional additional input transport hooks. | |
| void | log_register_authgate_hook (log_authgate_hook_t hook) |
| Installs the auth-gate hook used to suppress INFO/DEBUG/VERBOSE output while a session is unauthenticated. | |
Variables | |
| static log_level_t | s_log_level = CDC_LOG_LEVEL_DEBUG |
| static bool | s_initialized = false |
| static console_output_hook_t | s_output_hook = nullptr |
| Optional console hooks for additional I/O transports (for example BLE). | |
| static console_input_available_hook_t | s_input_avail_hook = nullptr |
| static log_authgate_hook_t | s_authgate_hook = nullptr |
| static console_input_getchar_hook_t | s_input_getchar_hook = nullptr |
| static const char * | level_str [] |
| static error_log_entry_t | s_error_log [ERROR_LOG_MAX_ENTRIES] |
| PSRAM-backed error/warn ring log storage (no heap allocation). | |
| static size_t | s_error_log_head = 0 |
| static size_t | s_error_log_count = 0 |
Logging and console I/O implementation with optional hook transports.
Definition in file cdc_log.cpp.
| #define DEBUG_MODE 1 |
Definition at line 20 of file cdc_log.cpp.
| bool console_available | ( | void | ) |
Returns whether any console input source has pending data.
Definition at line 261 of file cdc_log.cpp.
References s_initialized, and s_input_avail_hook.
Referenced by cdc::serial::Console::available().
| void console_flush | ( | void | ) |
Flushes buffered console output transports.
Definition at line 393 of file cdc_log.cpp.
References s_initialized.
Referenced by cdc::hal::WifiController::enable(), cdc::serial::Console::flush(), and cdc::hal::WifiController::onWifiEvent().
| int console_getchar | ( | void | ) |
Reads one character from available console input source.
Definition at line 282 of file cdc_log.cpp.
References s_initialized, and s_input_getchar_hook.
Referenced by cdc::serial::Console::getchar().
| void console_init | ( | void | ) |
Initializes console I/O transport state.
Definition at line 245 of file cdc_log.cpp.
References flags, and s_initialized.
Referenced by log_init().
| void console_print | ( | const char * | str | ) |
Writes string to active console outputs.
| str | Null-terminated string. |
Definition at line 312 of file cdc_log.cpp.
References s_initialized, and s_output_hook.
Referenced by console_printf(), log_hex(), log_raw(), and cdc::serial::Console::print().
| void console_printf | ( | const char * | fmt, |
| ... ) |
Formatted write helper for console output.
| fmt | Printf-style format string. |
Definition at line 358 of file cdc_log.cpp.
References console_print().
Referenced by error_log_dump(), log_hex(), and log_write().
| void console_putchar | ( | char | c | ) |
Writes single character to active console outputs.
| c | Character to output. |
Definition at line 373 of file cdc_log.cpp.
References s_initialized, and s_output_hook.
Referenced by log_hex(), and cdc::serial::Console::putchar().
| void console_register_input_hook | ( | console_input_available_hook_t | avail_hook, |
| console_input_getchar_hook_t | getchar_hook ) |
Registers optional additional input transport hooks.
Registers the console input hooks (only one set supported at a time).
| avail_hook | Input-available callback. |
| getchar_hook | Character-read callback. |
Definition at line 416 of file cdc_log.cpp.
References s_input_avail_hook, and s_input_getchar_hook.
| void console_register_output_hook | ( | console_output_hook_t | hook | ) |
Console hook registration API.
Registers the console output hook (only one supported at a time).
Registers optional additional output transport hook.
| hook | Output callback. |
Definition at line 407 of file cdc_log.cpp.
References s_output_hook.
|
static |
Adds warning/error entry to PSRAM-backed ring log.
| level | Log level. |
| message | Formatted message text. |
Definition at line 55 of file cdc_log.cpp.
References ERROR_LOG_LINE_LEN, ERROR_LOG_MAX_ENTRIES, s_error_log, s_error_log_count, and s_error_log_head.
Referenced by log_write().
| void error_log_clear | ( | void | ) |
Clears error-log ring buffer state.
Definition at line 104 of file cdc_log.cpp.
References s_error_log_count, and s_error_log_head.
Referenced by cdc::serial::cmdErrorLog().
| void error_log_dump | ( | void | ) |
Dumps buffered error-log entries to console.
Definition at line 112 of file cdc_log.cpp.
References console_printf(), ERROR_LOG_MAX_ENTRIES, s_error_log, s_error_log_count, and s_error_log_head.
Referenced by cdc::serial::cmdErrorLog().
| size_t error_log_get_count | ( | void | ) |
Returns number of buffered error-log entries.
Definition at line 97 of file cdc_log.cpp.
References s_error_log_count.
| size_t error_log_get_entries | ( | error_log_entry_t * | entries, |
| size_t | max_entries ) |
Copies stored error-log entries in chronological order.
| entries | Output entry buffer. |
| max_entries | Maximum writable entries. |
Definition at line 79 of file cdc_log.cpp.
References ERROR_LOG_MAX_ENTRIES, s_error_log, s_error_log_count, and s_error_log_head.
| log_level_t log_get_level | ( | void | ) |
Returns current log verbosity threshold.
Definition at line 161 of file cdc_log.cpp.
References s_log_level.
| void log_hex | ( | const char * | tag, |
| const char * | label, | ||
| const uint8_t * | data, | ||
| size_t | len ) |
Logs binary buffer as grouped hexadecimal bytes.
| tag | Log tag. |
| label | Data label. |
| data | Input byte buffer. |
| len | Buffer length. |
Definition at line 224 of file cdc_log.cpp.
References console_print(), console_printf(), and console_putchar().
| void log_init | ( | void | ) |
Logging API implementation.
Initializes logging subsystem and console backend.
Definition at line 140 of file cdc_log.cpp.
References console_init(), and s_log_level.
Referenced by initCoreServices().
| void log_raw | ( | const char * | fmt, |
| ... ) |
Writes untagged raw formatted text to console.
| fmt | Printf-style format string. |
Definition at line 208 of file cdc_log.cpp.
References console_print().
| void log_register_authgate_hook | ( | log_authgate_hook_t | hook | ) |
Installs the auth-gate hook used to suppress INFO/DEBUG/VERBOSE output while a session is unauthenticated.
Registers (or clears) the auth-gate hook for INFO/DEBUG/VERBOSE.
| hook | Callback returning true when the gate is open, false to drop the line. NULL disables gating. |
Definition at line 428 of file cdc_log.cpp.
References s_authgate_hook.
Referenced by cdc::serial::SerialCmd::init().
| void log_set_level | ( | log_level_t | level | ) |
Sets runtime log verbosity threshold.
| level | New log level. |
Definition at line 153 of file cdc_log.cpp.
References s_log_level.
Referenced by cdc::serial::SerialCmd::authenticate(), cdc::serial::SerialCmd::init(), cdc::serial::SerialCmd::isAuthenticated(), and cdc::serial::SerialCmd::logout().
| void log_write | ( | log_level_t | level, |
| const char * | tag, | ||
| const char * | fmt, | ||
| ... ) |
Writes formatted tagged log line with optional suppression.
| level | Log level. |
| tag | Log tag. |
| fmt | Printf-style format string. |
Definition at line 171 of file cdc_log.cpp.
References console_printf(), error_log_add(), level_str, s_authgate_hook, and s_log_level.
|
static |
Definition at line 36 of file cdc_log.cpp.
Referenced by log_write().
|
static |
Definition at line 33 of file cdc_log.cpp.
Referenced by log_register_authgate_hook(), and log_write().
|
static |
PSRAM-backed error/warn ring log storage (no heap allocation).
Definition at line 46 of file cdc_log.cpp.
Referenced by error_log_add(), error_log_dump(), and error_log_get_entries().
|
static |
Definition at line 48 of file cdc_log.cpp.
Referenced by error_log_add(), error_log_clear(), error_log_dump(), error_log_get_count(), and error_log_get_entries().
|
static |
Definition at line 47 of file cdc_log.cpp.
Referenced by error_log_add(), error_log_clear(), error_log_dump(), and error_log_get_entries().
|
static |
Definition at line 28 of file cdc_log.cpp.
Referenced by cdc::mod_gpg::ble_gpg_xsig_init(), console_available(), console_flush(), console_getchar(), console_init(), console_print(), and console_putchar().
|
static |
Definition at line 32 of file cdc_log.cpp.
Referenced by console_available(), and console_register_input_hook().
|
static |
Definition at line 34 of file cdc_log.cpp.
Referenced by console_getchar(), and console_register_input_hook().
|
static |
Definition at line 24 of file cdc_log.cpp.
Referenced by log_get_level(), log_init(), log_set_level(), and log_write().
|
static |
Optional console hooks for additional I/O transports (for example BLE).
Definition at line 31 of file cdc_log.cpp.
Referenced by console_print(), console_putchar(), and console_register_output_hook().