diff --git a/src/cmd.c b/src/cmd.c index 74b14b2..cd35458 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1499,6 +1499,26 @@ static void set_rfpower(atci_param_t *param) } +static void get_loglevel(void) +{ + OK("%d", log_get_level()); +} + + +static void set_loglevel(atci_param_t *param) +{ + (void)param; + uint32_t level; + + if (!atci_param_get_uint(param, &level)) + abort(ERR_PARAM); + + if (level > 5) abort(ERR_PARAM); + + log_set_level(level); + OK_(); +} + static const atci_command_t cmds[] = { {"+UART", NULL, set_uart, get_uart, NULL, "Configure UART interface"}, {"+VER", NULL, NULL, get_version_comp, NULL, "Firmware version and build time"}, @@ -1561,6 +1581,7 @@ static const atci_command_t cmds[] = { {"$RX2", NULL, set_rx2, get_rx2, NULL, "Configure RX2 window frequency and data rate"}, {"$DR", NULL, set_dr, get_dr, NULL, "Configure data rate (DR)"}, {"$RFPOWER", NULL, set_rfpower, get_rfpower, NULL, "Configure RF power"}, + {"$LOGLEVEL", NULL, set_loglevel, get_loglevel, NULL, "Configure logging on USART port"}, ATCI_COMMAND_CLAC, ATCI_COMMAND_HELP}; diff --git a/src/log.c b/src/log.c index f5bf685..20896e9 100644 --- a/src/log.c +++ b/src/log.c @@ -49,6 +49,16 @@ void log_init(log_level_t level, log_timestamp_t timestamp) #endif } +log_level_t log_get_level(void) +{ + return _log.level; +} + +void log_set_level(log_level_t level) +{ + _log.level = level; +} + static void _write(const char *buf, size_t len) { #if LOG_TO_USART != 0 diff --git a/src/log.h b/src/log.h index 5f932af..362a5d7 100644 --- a/src/log.h +++ b/src/log.h @@ -62,6 +62,10 @@ typedef enum void log_init(log_level_t level, log_timestamp_t timestamp); +log_level_t log_get_level(void); + +void log_set_level(log_level_t level); + //! @brief Log DUMP message (annotated in log as ) //! @param[in] buffer Pointer to source buffer //! @param[in] length Number of bytes to be printed diff --git a/src/main.c b/src/main.c index aaebeb0..f1845da 100644 --- a/src/main.c +++ b/src/main.c @@ -24,7 +24,12 @@ int main(void) { system_init(); + +#ifdef DEBUG log_init(LOG_LEVEL_DUMP, LOG_TIMESTAMP_ABS); +#else + log_init(LOG_LEVEL_OFF, LOG_TIMESTAMP_ABS); +#endif #ifdef DEBUG // If we are in debugging mode, delay initialization a bit so that we won't