Don't use strerror in apps/modbus; Add CONFIG_MB_TERMIOS to enable/suppress use of termios.h interfaces

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4968 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-07-22 17:41:19 +00:00
parent 81d5f42a18
commit ad37fa6505
5 changed files with 260 additions and 215 deletions
+4 -2
View File
@@ -255,5 +255,7 @@
has been added to the NuttX apps/ source tree.
* apps/examples/modbus: A port of the freemodbus-v1.5.0 "demo"
program that will be used to verify the FreeModBus port
* apps/modbus: Don't use strerror(). It is just too big.
* apps/modbus: Add CONFIG_MB_TERMIOS. If the driver doesn't support
termios ioctls, then don't bother trying to configure the baud, parity
etc.
+9
View File
@@ -24,6 +24,15 @@ config MB_TCP_ENABLED
depends on MODBUS
default y
config MB_TERMIOS
bool "Driver TERMIOS supported"
depends on MB_ASCII_ENABLED || MB_RTU_ENABLED
default n
---help---
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
If this is not defined, then the terminal settings (baud, parity, etc).
are not configurable at runtime; serial streams will not be flushed when closed.
config MB_ASCII_TIMEOUT_SEC
int "Character timeout"
depends on MB_ASCII_ENABLED
+4
View File
@@ -60,6 +60,10 @@ The NuttX-named configuration options that are available include:
CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
CONFIG_MB_RTU_ENABLED - Modbus RTU support
CONFIG_MB_TCP_ENABLED - Modbus TCP support
CONFIG_MB_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
tcflush, etc.). If this is not defined, then the terminal settings (baud,
parity, etc.) are not configurable at runtime; serial streams will not be
flushed when closed.
CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
character timeout value is not fixed for Modbus ASCII and is therefore
a configuration option. It should be set to the maximum expected delay
+32 -30
View File
@@ -22,6 +22,7 @@
*/
/* ----------------------- Standard includes --------------------------------*/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,72 +34,73 @@
#include "port.h"
/* ----------------------- Modbus includes ----------------------------------*/
#include <apps/modbus/mb.h>
#include <apps/modbus/mbport.h>
/* ----------------------- Defines ------------------------------------------*/
#define NELEMS( x ) ( sizeof( ( x ) )/sizeof( ( x )[0] ) )
#define NELEMS(x) (sizeof((x))/sizeof((x)[0]))
/* ----------------------- Static variables ---------------------------------*/
static FILE *fLogFile = NULL;
static eMBPortLogLevel eLevelMax = MB_LOG_DEBUG;
static pthread_mutex_t xLock = PTHREAD_MUTEX_INITIALIZER;
/* ----------------------- Start implementation -----------------------------*/
void
vMBPortLogLevel( eMBPortLogLevel eNewLevelMax )
void vMBPortLogLevel(eMBPortLogLevel eNewLevelMax)
{
eLevelMax = eNewLevelMax;
eLevelMax = eNewLevelMax;
}
void
vMBPortLogFile( FILE * fNewLogFile )
void vMBPortLogFile(FILE * fNewLogFile)
{
fLogFile = fNewLogFile;
fLogFile = fNewLogFile;
}
void
vMBPortLog( eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ... )
void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ...)
{
char szBuf[512];
int i;
va_list args;
FILE *fOutput = fLogFile == NULL ? stderr : fLogFile;
char szBuf[512];
int i;
va_list args;
FILE *fOutput = fLogFile == NULL ? stderr : fLogFile;
static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" };
static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" };
i = snprintf( szBuf, NELEMS( szBuf ), "%s: %s: ", arszLevel2Str[eLevel], szModule );
i = snprintf(szBuf, NELEMS(szBuf), "%s: %s: ", arszLevel2Str[eLevel], szModule);
if( i != 0 )
if (i != 0)
{
va_start( args, szFmt );
i += vsnprintf( &szBuf[i], NELEMS( szBuf ) - i, szFmt, args );
va_end( args );
va_start(args, szFmt);
i += vsnprintf(&szBuf[i], NELEMS(szBuf) - i, szFmt, args);
va_end(args);
}
if( i != 0 )
if (i != 0)
{
if( eLevel <= eLevelMax )
if (eLevel <= eLevelMax)
{
fputs( szBuf, fOutput );
fputs(szBuf, fOutput);
}
}
}
void
vMBPortEnterCritical( void )
void vMBPortEnterCritical(void)
{
if( pthread_mutex_lock( &xLock ) != 0 )
int ret = pthread_mutex_lock(&xLock);
if (ret != 0)
{
vMBPortLog( MB_LOG_ERROR, "OTHER", "Locking primitive failed: %s\n", strerror( errno ) );
vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret);
}
}
void
vMBPortExitCritical( void )
void vMBPortExitCritical(void)
{
if( pthread_mutex_unlock( &xLock ) != 0 )
int ret = pthread_mutex_unlock(&xLock);
if (ret != 0)
{
vMBPortLog( MB_LOG_ERROR, "OTHER", "Locking primitive failed: %s\n", strerror( errno ) );
vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret);
}
}
File diff suppressed because it is too large Load Diff