From e280e9bdb45f93b45ef2ae7d6f9c75cea722ec17 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Fri, 14 Mar 2025 14:10:46 +0100 Subject: [PATCH] modbus: add an option to disable log Introduce new configuration option that allow disable all logging functionality for FreeModBus. This option is useful for small systems when we don't use any logging features. Signed-off-by: raiden00pl --- modbus/Kconfig | 9 +++++++++ modbus/nuttx/port.h | 4 ++++ modbus/nuttx/portother.c | 2 ++ 3 files changed, 15 insertions(+) diff --git a/modbus/Kconfig b/modbus/Kconfig index 8da277fdf..d891d181c 100644 --- a/modbus/Kconfig +++ b/modbus/Kconfig @@ -251,4 +251,13 @@ config MB_MASTER_FUNC_READWRITE_HOLDING_ENABLED endif # MB_ASCII_MASTER || MB_RTU_MASTER endif # MODBUS + +config MODBUS_DISABLE_LOG + bool "Disable logging for FreeModBus" + default !FILE_STREAM + ---help--- + Disable all logging features for FreeModBus which can be useful + for small optimized systems without console or log file support. + This also must be enabled when fputs() is not supported. + endmenu # FreeModBus diff --git a/modbus/nuttx/port.h b/modbus/nuttx/port.h index aada110ed..c79dcdd98 100644 --- a/modbus/nuttx/port.h +++ b/modbus/nuttx/port.h @@ -79,8 +79,12 @@ typedef enum void vMBPortEnterCritical(void); void vMBPortExitCritical(void); +#ifndef CONFIG_MODBUS_DISABLE_LOG void vMBPortLog(eMBPortLogLevel eLevel, const char *szModule, const char *szFmt, ...) printf_like(3, 4); +#else +# define vMBPortLog(l, m, c, ...) +#endif void vMBPortTimerPoll(void); bool xMBPortSerialPoll(void); bool xMBPortSerialSetTimeout(uint32_t dwTimeoutMs); diff --git a/modbus/nuttx/portother.c b/modbus/nuttx/portother.c index 797ede0dc..3de2a38b5 100644 --- a/modbus/nuttx/portother.c +++ b/modbus/nuttx/portother.c @@ -73,6 +73,7 @@ void vMBPortLogFile(FILE * fNewLogFile) fLogFile = fNewLogFile; } +#ifndef CONFIG_MODBUS_DISABLE_LOG void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ...) { @@ -103,6 +104,7 @@ void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, } } } +#endif void vMBPortEnterCritical(void) {