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 <raiden00@railab.me>
This commit is contained in:
raiden00pl 2025-03-14 14:10:46 +01:00 committed by CeDeROM
parent 494554618e
commit e280e9bdb4
3 changed files with 15 additions and 0 deletions

View file

@ -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

View file

@ -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);

View file

@ -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)
{