mirror of https://github.com/3cky/mbusd.git
Compare commits
4 Commits
b07681842f
...
68f988051c
Author | SHA1 | Date |
---|---|---|
Victor Antonovich | 68f988051c | |
Victor Antonovich | b03d50b58c | |
Victor Antonovich | 20c87df994 | |
Cían Hughes | 4ee7e8a834 |
35
README.md
35
README.md
|
@ -54,19 +54,19 @@ Usage:
|
||||||
|
|
||||||
mbusd [-h] [-d] [-L logfile] [-v level] [-c cfgfile]
|
mbusd [-h] [-d] [-L logfile] [-v level] [-c cfgfile]
|
||||||
[-p device] [-s speed] [-m mode] [-S]
|
[-p device] [-s speed] [-m mode] [-S]
|
||||||
[-t] [-y sysfsfile] [-Y sysfsfile]
|
[-t] [-r] [-y sysfsfile] [-Y sysfsfile]
|
||||||
[-A address] [-P port] [-C maxconn] [-N retries]
|
[-A address] [-P port] [-C maxconn] [-N retries]
|
||||||
[-R pause] [-W wait] [-T timeout]
|
[-R pause] [-W wait] [-T timeout] [-b]
|
||||||
|
|
||||||
-h Usage help.
|
-h Usage help.
|
||||||
-d Instruct mbusd not to fork itself (non-daemonize).
|
-d Instruct mbusd not to fork itself (non-daemonize).
|
||||||
-L logfile
|
-L logfile
|
||||||
Specifies log file name ('-' for logging to STDOUT only, default is /var/log/mbusd.log).
|
Specifies log file name ('-' for logging to STDOUT only, relative path or bare filename
|
||||||
|
will be stored at /var/log, default is /var/log/mbusd.log).
|
||||||
-v level
|
-v level
|
||||||
Specifies log verbosity level (0 for errors only, 1 for warnings
|
Specifies log verbosity level (0 for errors only, 1 for warnings and 2 for informational
|
||||||
and 2 for also information messages.) If mbusd was compiled in debug mode,
|
messages also). If mbusd was compiled in debug mode, valid log levels are up to 9,
|
||||||
valid log levels are up to 9, where log levels above 2 forces
|
where log levels above 2 adds logging of information about additional internal events.
|
||||||
logging of information about additional internal events.
|
|
||||||
-c cfgfile
|
-c cfgfile
|
||||||
Read configuration from cfgfile.
|
Read configuration from cfgfile.
|
||||||
-p device
|
-p device
|
||||||
|
@ -76,27 +76,28 @@ Usage:
|
||||||
-m mode
|
-m mode
|
||||||
Specifies serial port mode (like 8N1).
|
Specifies serial port mode (like 8N1).
|
||||||
-S Enable RS-485 support for given serial port device (Linux only)
|
-S Enable RS-485 support for given serial port device (Linux only)
|
||||||
-t Enable RTS RS-485 data direction control (if not disabled while compile).
|
-t Enable RTS RS-485 data direction control using RTS, active transmit.
|
||||||
|
-r Enable RTS RS-485 data direction control using RTS, active receive.
|
||||||
-y file
|
-y file
|
||||||
Enable RS-485 direction data direction control by writing '1' to file
|
Enable RS-485 direction data direction control by writing '1' to file
|
||||||
for transmitter enable and '0' to file for transmitter disable
|
for transmitter enable and '0' to file for transmitter disable.
|
||||||
-Y file
|
-Y file
|
||||||
Enable RS-485 direction data direction control by writing '0' to file
|
Enable RS-485 direction data direction control by writing '0' to file
|
||||||
for transmitter enable and '1' to file for transmitter disable
|
for transmitter enable and '1' to file for transmitter disable.
|
||||||
-A address
|
-A address
|
||||||
Specifies TCP address to bind (default 0.0.0.0).
|
Specifies TCP server address to bind (default is 0.0.0.0).
|
||||||
-P port
|
-P port
|
||||||
Specifies TCP port number (default 502).
|
Specifies TCP server port number (default is 502).
|
||||||
-C maxconn
|
-C maxconn
|
||||||
Specifies maximum number of simultaneous TCP connections.
|
Specifies maximum number of simultaneous TCP connections (default is 32).
|
||||||
-N retries
|
-N retries
|
||||||
Specifies maximum number of request retries (0 disables retries).
|
Specifies maximum number of request retries (0 disables retries, default is 3).
|
||||||
-R pause
|
-R pause
|
||||||
Specifies pause between requests in milliseconds.
|
Specifies pause between requests in milliseconds (default is 100ms).
|
||||||
-W wait
|
-W wait
|
||||||
Specifies response wait time in milliseconds.
|
Specifies response wait time in milliseconds (default is 500ms).
|
||||||
-T timeout
|
-T timeout
|
||||||
Specifies connection timeout value in seconds (0 disables timeout).
|
Specifies connection timeout value in seconds (0 disables timeout, default is 60).
|
||||||
-b
|
-b
|
||||||
Instructs mbusd to reply on a broadcast.
|
Instructs mbusd to reply on a broadcast.
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ mode = 8n1
|
||||||
# Enable RS-485 support for given serial port device (Linux only)
|
# Enable RS-485 support for given serial port device (Linux only)
|
||||||
# enable_rs485 = no
|
# enable_rs485 = no
|
||||||
|
|
||||||
# RS-485 data direction control type (addc, rts, sysfs_0, sysfs_1)
|
# RS-485 data direction control type (addc, rts_0, rts/rts_1, sysfs_0, sysfs_1)
|
||||||
trx_control = addc
|
trx_control = addc
|
||||||
|
|
||||||
# Sysfs file to use to control data direction
|
# Sysfs file to use to control data direction
|
||||||
|
|
|
@ -18,6 +18,7 @@ mbusd \- MODBUS/TCP to MODBUS/RTU gateway.
|
||||||
.RB [ -m
|
.RB [ -m
|
||||||
.IR mode ]
|
.IR mode ]
|
||||||
.RB [ -t ]
|
.RB [ -t ]
|
||||||
|
.RB [ -r ]
|
||||||
.RB [ -y
|
.RB [ -y
|
||||||
.IR sysfsfile ]
|
.IR sysfsfile ]
|
||||||
.RB [ -Y
|
.RB [ -Y
|
||||||
|
@ -67,13 +68,15 @@ Specifies TCP address to bind.
|
||||||
.IP "\fB-P \fIport\fR"
|
.IP "\fB-P \fIport\fR"
|
||||||
Specifies TCP port number.
|
Specifies TCP port number.
|
||||||
.IP \fB-t\fR
|
.IP \fB-t\fR
|
||||||
Enable RTS RS-485 data direction control (if not disabled while compile).
|
Enable RTS RS-485 data direction control using RTS, active transmit.
|
||||||
|
.IP \fB-r\fR
|
||||||
|
Enable RTS RS-485 data direction control using RTS, active receive.
|
||||||
.IP "\fB-y \fIfile\fR"
|
.IP "\fB-y \fIfile\fR"
|
||||||
Enable RS-485 direction data direction control by writing '1' to file
|
Enable RS-485 direction data direction control by writing '1' to file
|
||||||
for transmitter enable and '0' to file for transmitter disable
|
for transmitter enable and '0' to file for transmitter disable.
|
||||||
.IP "\fB-Y \fIfile\fR"
|
.IP "\fB-Y \fIfile\fR"
|
||||||
Enable RS-485 direction data direction control by writing '0' to file
|
Enable RS-485 direction data direction control by writing '0' to file
|
||||||
for transmitter enable and '1' to file for transmitter disable
|
for transmitter enable and '1' to file for transmitter disable.
|
||||||
.IP "\fB-C \fImaxconn\fR"
|
.IP "\fB-C \fImaxconn\fR"
|
||||||
Specifies maximum number of simultaneous TCP connections.
|
Specifies maximum number of simultaneous TCP connections.
|
||||||
.IP "\fB-N \fIretries\fR"
|
.IP "\fB-N \fIretries\fR"
|
||||||
|
|
|
@ -200,9 +200,13 @@ cfg_handle_param(char *name, char *value)
|
||||||
{
|
{
|
||||||
cfg.trxcntl = TRX_ADDC;
|
cfg.trxcntl = TRX_ADDC;
|
||||||
}
|
}
|
||||||
else if (CFG_VALUE_MATCH("rts"))
|
else if (CFG_VALUE_MATCH("rts") || CFG_VALUE_MATCH("rts_1"))
|
||||||
{
|
{
|
||||||
cfg.trxcntl = TRX_RTS;
|
cfg.trxcntl = TRX_RTS_1;
|
||||||
|
}
|
||||||
|
else if (CFG_VALUE_MATCH("rts_0"))
|
||||||
|
{
|
||||||
|
cfg.trxcntl = TRX_RTS_0;
|
||||||
}
|
}
|
||||||
else if (CFG_VALUE_MATCH("sysfs_0"))
|
else if (CFG_VALUE_MATCH("sysfs_0"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -251,7 +251,7 @@ conn_write(int d, void *buf, size_t nbytes, int istty)
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
if (istty && cfg.trxcntl != TRX_ADDC)
|
if (istty && cfg.trxcntl != TRX_ADDC)
|
||||||
{
|
{
|
||||||
tty_set_rts(d);
|
tty_set_tx(d);
|
||||||
tty_delay(35000000l/cfg.ttyspeed);
|
tty_delay(35000000l/cfg.ttyspeed);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -267,7 +267,7 @@ conn_write(int d, void *buf, size_t nbytes, int istty)
|
||||||
if (istty && cfg.trxcntl != TRX_ADDC )
|
if (istty && cfg.trxcntl != TRX_ADDC )
|
||||||
{
|
{
|
||||||
tty_delay(DV(nbytes, tty.bpc, cfg.ttyspeed));
|
tty_delay(DV(nbytes, tty.bpc, cfg.ttyspeed));
|
||||||
tty_clr_rts(d);
|
tty_set_rx(d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
34
src/main.c
34
src/main.c
|
@ -113,7 +113,7 @@ usage(char *exename)
|
||||||
#endif
|
#endif
|
||||||
"\n"
|
"\n"
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
" [-t] [-y sysfsfile] [-Y sysfsfile]\n"
|
" [-t] [-r] [-y sysfsfile] [-Y sysfsfile]\n"
|
||||||
#endif
|
#endif
|
||||||
" [-A address] [-P port] [-C maxconn] [-N retries]\n"
|
" [-A address] [-P port] [-C maxconn] [-N retries]\n"
|
||||||
" [-R pause] [-W wait] [-T timeout] [-b]\n\n"
|
" [-R pause] [-W wait] [-T timeout] [-b]\n\n"
|
||||||
|
@ -121,38 +121,39 @@ usage(char *exename)
|
||||||
" -h : this help\n"
|
" -h : this help\n"
|
||||||
" -d : don't daemonize\n"
|
" -d : don't daemonize\n"
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
" -L logfile : set log file name (default %s%s, \n"
|
" -L logfile : set log file name (default is %s%s, \n"
|
||||||
" '-' for logging to STDOUT only)\n"
|
" '-' for logging to STDOUT only)\n"
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
" -v level : set log level (0-9, default %d, 0 - errors only)\n"
|
" -v level : set log level (0-9, default is %d, 0 - errors only)\n"
|
||||||
#else
|
#else
|
||||||
" -v level : set log level (0-2, default %d, 0 - errors only)\n"
|
" -v level : set log level (0-2, default %d, 0 - errors only)\n"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
" -c cfgfile : read configuration from cfgfile\n"
|
" -c cfgfile : read configuration from cfgfile\n"
|
||||||
" -p device : set serial port device name (default %s)\n"
|
" -p device : set serial port device name (default is %s)\n"
|
||||||
" -s speed : set serial port speed (default %d)\n"
|
" -s speed : set serial port speed (default is %d)\n"
|
||||||
" -m mode : set serial port mode (default %s)\n"
|
" -m mode : set serial port mode (default is %s)\n"
|
||||||
#ifdef HAVE_TIOCRS485
|
#ifdef HAVE_TIOCRS485
|
||||||
" -S : enable Linux RS-485 support for given serial port device\n"
|
" -S : enable Linux RS-485 support for given serial port device\n"
|
||||||
#endif
|
#endif
|
||||||
" -A address : set TCP server address to bind (default %s)\n"
|
" -A address : set TCP server address to bind (default is %s)\n"
|
||||||
" -P port : set TCP server port number (default %d)\n"
|
" -P port : set TCP server port number (default is %d)\n"
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
" -t : enable RTS RS-485 data direction control using RTS\n"
|
" -t : enable RTS RS-485 data direction control using RTS, active transmit\n"
|
||||||
|
" -r : enable RTS RS-485 data direction control using RTS, active receive\n"
|
||||||
" -y : enable RTS RS-485 data direction control using sysfs file, active transmit\n"
|
" -y : enable RTS RS-485 data direction control using sysfs file, active transmit\n"
|
||||||
" -Y : enable RTS RS-485 data direction control using sysfs file, active receive\n"
|
" -Y : enable RTS RS-485 data direction control using sysfs file, active receive\n"
|
||||||
#endif
|
#endif
|
||||||
" -C maxconn : set maximum number of simultaneous TCP connections\n"
|
" -C maxconn : set maximum number of simultaneous TCP connections\n"
|
||||||
" (1-%d, default %d)\n"
|
" (1-%d, default is %d)\n"
|
||||||
" -N retries : set maximum number of request retries\n"
|
" -N retries : set maximum number of request retries\n"
|
||||||
" (0-%d, default %d, 0 - without retries)\n"
|
" (0-%d, default is %d, 0 disables retrying)\n"
|
||||||
" -R pause : set pause between requests in milliseconds\n"
|
" -R pause : set pause between requests in milliseconds\n"
|
||||||
" (1-%d, default %lu)\n"
|
" (1-%d, default is %lu)\n"
|
||||||
" -W wait : set response wait time in milliseconds\n"
|
" -W wait : set response wait time in milliseconds\n"
|
||||||
" (1-%d, default %lu)\n"
|
" (1-%d, default is %lu)\n"
|
||||||
" -T timeout : set connection timeout value in seconds\n"
|
" -T timeout : set connection timeout value in seconds\n"
|
||||||
" (0-%d, default %d, 0 - no timeout)\n"
|
" (0-%d, default is %d, 0 disables timeout)\n"
|
||||||
" -b : enable reply on broadcast"
|
" -b : enable reply on broadcast"
|
||||||
"\n", PACKAGE, VERSION, exename,
|
"\n", PACKAGE, VERSION, exename,
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
|
@ -218,7 +219,10 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
case 't':
|
case 't':
|
||||||
cfg.trxcntl = TRX_RTS;
|
cfg.trxcntl = TRX_RTS_1;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
cfg.trxcntl = TRX_RTS_0;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
cfg.trxcntl = TRX_SYSFS_1;
|
cfg.trxcntl = TRX_SYSFS_1;
|
||||||
|
|
22
src/tty.c
22
src/tty.c
|
@ -189,7 +189,7 @@ tty_set_attr(ttydata_t *mod)
|
||||||
return RC_ERR;
|
return RC_ERR;
|
||||||
tcflush(mod->fd, TCIOFLUSH);
|
tcflush(mod->fd, TCIOFLUSH);
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
tty_clr_rts(mod->fd);
|
tty_set_rx(mod->fd);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_TIOCRS485
|
#ifdef HAVE_TIOCRS485
|
||||||
if (mod->rs485)
|
if (mod->rs485)
|
||||||
|
@ -465,27 +465,33 @@ void sysfs_gpio_set(char *filename, char *value) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set RTS line to active state */
|
/* Set tty device into transmit mode */
|
||||||
void
|
void
|
||||||
tty_set_rts(int fd)
|
tty_set_tx(int fd)
|
||||||
{
|
{
|
||||||
if ( TRX_RTS == cfg.trxcntl ) {
|
if ( TRX_RTS_1 == cfg.trxcntl ) {
|
||||||
int mstat = TIOCM_RTS;
|
int mstat = TIOCM_RTS;
|
||||||
ioctl(fd, TIOCMBIS, &mstat);
|
ioctl(fd, TIOCMBIS, &mstat);
|
||||||
} else if ( TRX_SYSFS_1 == cfg.trxcntl) {
|
} else if ( TRX_RTS_0 == cfg.trxcntl ) {
|
||||||
|
int mstat = TIOCM_RTS;
|
||||||
|
ioctl(fd, TIOCMBIC, &mstat);
|
||||||
|
} else if ( TRX_SYSFS_1 == cfg.trxcntl) {
|
||||||
sysfs_gpio_set(cfg.trxcntl_file,"1");
|
sysfs_gpio_set(cfg.trxcntl_file,"1");
|
||||||
} else if ( TRX_SYSFS_0 == cfg.trxcntl) {
|
} else if ( TRX_SYSFS_0 == cfg.trxcntl) {
|
||||||
sysfs_gpio_set(cfg.trxcntl_file,"0");
|
sysfs_gpio_set(cfg.trxcntl_file,"0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set RTS line to passive state */
|
/* Set tty device into receive mode */
|
||||||
void
|
void
|
||||||
tty_clr_rts(int fd)
|
tty_set_rx(int fd)
|
||||||
{
|
{
|
||||||
if ( TRX_RTS == cfg.trxcntl ) {
|
if ( TRX_RTS_1 == cfg.trxcntl ) {
|
||||||
int mstat = TIOCM_RTS;
|
int mstat = TIOCM_RTS;
|
||||||
ioctl(fd, TIOCMBIC, &mstat);
|
ioctl(fd, TIOCMBIC, &mstat);
|
||||||
|
} else if ( TRX_RTS_0 == cfg.trxcntl ) {
|
||||||
|
int mstat = TIOCM_RTS;
|
||||||
|
ioctl(fd, TIOCMBIS, &mstat);
|
||||||
} else if ( TRX_SYSFS_1 == cfg.trxcntl) {
|
} else if ( TRX_SYSFS_1 == cfg.trxcntl) {
|
||||||
sysfs_gpio_set(cfg.trxcntl_file,"0");
|
sysfs_gpio_set(cfg.trxcntl_file,"0");
|
||||||
} else if ( TRX_SYSFS_0 == cfg.trxcntl) {
|
} else if ( TRX_SYSFS_0 == cfg.trxcntl) {
|
||||||
|
|
11
src/tty.h
11
src/tty.h
|
@ -77,9 +77,10 @@
|
||||||
*/
|
*/
|
||||||
#ifdef TRXCTL
|
#ifdef TRXCTL
|
||||||
#define TRX_ADDC 0
|
#define TRX_ADDC 0
|
||||||
#define TRX_RTS 1
|
#define TRX_RTS_1 1
|
||||||
#define TRX_SYSFS_1 2
|
#define TRX_RTS_0 2
|
||||||
#define TRX_SYSFS_0 3
|
#define TRX_SYSFS_1 3
|
||||||
|
#define TRX_SYSFS_0 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -127,8 +128,8 @@ int tty_set_attr(ttydata_t *mod);
|
||||||
speed_t tty_transpeed(int speed);
|
speed_t tty_transpeed(int speed);
|
||||||
int tty_cooked(ttydata_t *mod);
|
int tty_cooked(ttydata_t *mod);
|
||||||
int tty_close(ttydata_t *mod);
|
int tty_close(ttydata_t *mod);
|
||||||
void tty_set_rts(int fd);
|
void tty_set_tx(int fd);
|
||||||
void tty_clr_rts(int fd);
|
void tty_set_rx(int fd);
|
||||||
void tty_delay(int usec);
|
void tty_delay(int usec);
|
||||||
|
|
||||||
#endif /* _TTY_H */
|
#endif /* _TTY_H */
|
||||||
|
|
Loading…
Reference in New Issue