mbusd 0.2.0:

+ RTS RS-485 transmit/receive control
* RTU response receiving by length
* Standard exception codes for receive error (04) and timeout (0x0B)
This commit is contained in:
kapyar 2015-02-25 10:33:57 +00:00
parent 3ab6be57e9
commit d04736878d
38 changed files with 1181 additions and 276 deletions

View File

@ -3,3 +3,4 @@ config.cache
config.h
config.status
Makefile
*.settings

View File

@ -1 +1,2 @@
Victor Antonovich (avmlink@vlink.ru)
Victor Antonovich (v.antonovich@gmail.com)
Andrew Denysenko <nitr0@seti.kr.ua>

View File

@ -1,7 +1,8 @@
* OpenMODBUS/TCP to RS-232/485 MODBUS gateway license *
Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
Copyright (c) 2002-2003, 2013, 2015 Victor Antonovich (avmlink@vlink.ru)
Copyright (c) 2011 Andrew Denysenko <nitr0@seti.kr.ua>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

View File

@ -16,3 +16,11 @@
* Fixed serial interface initialization under Linux;
* Default RTU client response wait timeout increased to 50 ms;
+ Added Eclipse CDT project files.
0.2.0
-----------
24-feb-2015 Merged changes by Andrew Denysenko <nitr0@seti.kr.ua>:
+ RTS RS-485 transmit/receive control
* RTU response receiving by length
* Standard error codes for receive error (04) and timeout (0x0B)

View File

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.13.4 from Makefile.am.
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
@ -82,8 +82,9 @@ subdir = .
DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \
$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/configure $(am__configure_deps) \
$(srcdir)/config.h.in mkinstalldirs COPYING TODO config.guess \
config.sub depcomp install-sh missing ltmain.sh ltconfig
$(srcdir)/config.h.in mkinstalldirs COPYING TODO compile \
config.guess config.sub depcomp install-sh missing ltmain.sh \
ltconfig
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@ -402,8 +403,8 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps)
$(am__aclocal_m4_deps):
config.h: stamp-h1
@if test ! -f $@; then rm -f stamp-h1; else :; fi
@if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
@test -f $@ || rm -f stamp-h1
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1
stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
@rm -f stamp-h1
@ -636,10 +637,16 @@ dist-xz: distdir
$(am__post_remove_distdir)
dist-tarZ: distdir
@echo WARNING: "Support for shar distribution archives is" \
"deprecated." >&2
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
$(am__post_remove_distdir)
dist-shar: distdir
@echo WARNING: "Support for distribution archives compressed with" \
"legacy program 'compress' is deprecated." >&2
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__post_remove_distdir)
@ -681,9 +688,10 @@ distcheck: dist
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
&& am__cwd=`pwd` \
&& $(am__cd) $(distdir)/_build \
&& ../configure --srcdir=.. --prefix="$$dc_install_base" \
&& ../configure \
$(AM_DISTCHECK_CONFIGURE_FLAGS) \
$(DISTCHECK_CONFIGURE_FLAGS) \
--srcdir=.. --prefix="$$dc_install_base" \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \

2
TODO
View File

@ -3,7 +3,5 @@ To do:
* Configuration file loading
* Signals processing (HUP, USR1, etc).
* Client addresses restriction
* RS-485 transmit/receive control by RTS
* Broadcast MODBUS messaging implementation
* Response receiving by length (currently by timeout)
* SSL secure connection implementation

122
aclocal.m4 vendored
View File

@ -1,4 +1,4 @@
# generated automatically by aclocal 1.13.4 -*- Autoconf -*-
# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
@ -32,10 +32,10 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.13'
[am__api_version='1.14'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
m4_if([$1], [1.13.4], [],
m4_if([$1], [1.14.1], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@ -51,7 +51,7 @@ m4_define([_AM_AUTOCONF_VERSION], [])
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
[AM_AUTOMAKE_VERSION([1.13.4])dnl
[AM_AUTOMAKE_VERSION([1.14.1])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
@ -418,6 +418,12 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# This macro actually does too much. Some checks are only needed if
# your package does certain things. But this isn't really a big deal.
dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O.
m4_define([AC_PROG_CC],
m4_defn([AC_PROG_CC])
[_AM_PROG_CC_C_O
])
# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
# AM_INIT_AUTOMAKE([OPTIONS])
# -----------------------------------------------
@ -526,7 +532,48 @@ dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below.
AC_CONFIG_COMMANDS_PRE(dnl
[m4_provide_if([_AM_COMPILER_EXEEXT],
[AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
])
# POSIX will say in a future version that running "rm -f" with no argument
# is OK; and we want to be able to make that assumption in our Makefile
# recipes. So use an aggressive probe to check that the usage we want is
# actually supported "in the wild" to an acceptable degree.
# See automake bug#10828.
# To make any issue more visible, cause the running configure to be aborted
# by default if the 'rm' program in use doesn't match our expectations; the
# user can still override this though.
if rm -f && rm -fr && rm -rf; then : OK; else
cat >&2 <<'END'
Oops!
Your 'rm' program seems unable to run without file operands specified
on the command line, even when the '-f' option is present. This is contrary
to the behaviour of most rm programs out there, and not conforming with
the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
Please tell bug-automake@gnu.org about your system, including the value
of your $PATH and any error possibly output before this message. This
can help us improve future automake versions.
END
if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
echo 'Configuration will proceed anyway, since you have set the' >&2
echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
echo >&2
else
cat >&2 <<'END'
Aborting the configuration process, to ensure you take notice of the issue.
You can download and install GNU coreutils to get an 'rm' implementation
that behaves properly: <http://www.gnu.org/software/coreutils/>.
If you want to complete the configuration process using your problematic
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
to "yes", and re-run configure.
END
AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
fi
fi])
dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not
dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
@ -534,7 +581,6 @@ dnl mangled by Autoconf and run in a shell conditional statement.
m4_define([_AC_COMPILER_EXEEXT],
m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
# When config.status generates a header, we must update the stamp-h file.
# This file resides in the same directory as the config header
# that is generated. The stamp files are numbered to have different names.
@ -745,6 +791,70 @@ AC_DEFUN([_AM_SET_OPTIONS],
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
# Copyright (C) 1999-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# _AM_PROG_CC_C_O
# ---------------
# Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC
# to automatically call this.
AC_DEFUN([_AM_PROG_CC_C_O],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
AC_REQUIRE_AUX_FILE([compile])dnl
AC_LANG_PUSH([C])dnl
AC_CACHE_CHECK(
[whether $CC understands -c and -o together],
[am_cv_prog_cc_c_o],
[AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
# Make sure it works both with $CC and with simple cc.
# Following AC_PROG_CC_C_O, we do the test twice because some
# compilers refuse to overwrite an existing .o file with -o,
# though they will create one.
am_cv_prog_cc_c_o=yes
for am_i in 1 2; do
if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \
&& test -f conftest2.$ac_objext; then
: OK
else
am_cv_prog_cc_c_o=no
break
fi
done
rm -f core conftest*
unset am_i])
if test "$am_cv_prog_cc_c_o" != yes; then
# Losing compiler, so override with the script.
# FIXME: It is wrong to rewrite CC.
# But if we don't then we get into trouble of one sort or another.
# A longer-term fix would be to have automake use am__CC in this case,
# and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
CC="$am_aux_dir/compile $CC"
fi
AC_LANG_POP([C])])
# For backward compatibility.
AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# AM_RUN_LOG(COMMAND)
# -------------------
# Run COMMAND, save the exit status in ac_status, and log it.
# (This has been adapted from Autoconf's _AC_RUN_LOG macro.)
AC_DEFUN([AM_RUN_LOG],
[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
(exit $ac_status); }])
# Check to make sure that the build environment is sane. -*- Autoconf -*-
# Copyright (C) 1996-2013 Free Software Foundation, Inc.

347
compile Executable file
View File

@ -0,0 +1,347 @@
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2012-10-14.11; # UTC
# Copyright (C) 1999-2013 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
nl='
'
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent tools from complaining about whitespace usage.
IFS=" "" $nl"
file_conv=
# func_file_conv build_file lazy
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts. If the determined conversion
# type is listed in (the comma separated) LAZY, no conversion will
# take place.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv/,$2, in
*,$file_conv,*)
;;
mingw/*)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin/*)
file=`cygpath -m "$file" || echo "$file"`
;;
wine/*)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}
# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
if test -f "$dir/lib$lib.a"; then
found=yes
lib=$dir/lib$lib.a
break
fi
done
IFS=$save_IFS
if test "$found" != yes; then
lib=$lib.lib
fi
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
{
# Assume a capable shell
lib_path=
shared=:
linker_opts=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
eat=1
case $2 in
*.o | *.[oO][bB][jJ])
func_file_conv "$2"
set x "$@" -Fo"$file"
shift
;;
*)
func_file_conv "$2"
set x "$@" -Fe"$file"
shift
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_cl_dashL "${1#-L}"
;;
-static)
shared=false
;;
-Wl,*)
arg=${1#-Wl,}
save_ifs="$IFS"; IFS=','
for flag in $arg; do
IFS="$save_ifs"
linker_opts="$linker_opts $flag"
done
IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:

View File

@ -91,5 +91,8 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* "" */
#undef TRXCTL
/* Version number of package */
#undef VERSION

267
configure vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for mbusd 0.1.3.
# Generated by GNU Autoconf 2.69 for mbusd 0.2.0.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@ -587,8 +587,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='mbusd'
PACKAGE_TARNAME='mbusd'
PACKAGE_VERSION='0.1.3'
PACKAGE_STRING='mbusd 0.1.3'
PACKAGE_VERSION='0.2.0'
PACKAGE_STRING='mbusd 0.2.0'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@ -766,6 +766,7 @@ enable_fast_install
with_gnu_ld
with_sysroot
enable_libtool_lock
enable_trxctl
'
ac_precious_vars='build_alias
host_alias
@ -1316,7 +1317,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures mbusd 0.1.3 to adapt to many kinds of systems.
\`configure' configures mbusd 0.2.0 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1386,7 +1387,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of mbusd 0.1.3:";;
short | recursive ) echo "Configuration of mbusd 0.2.0:";;
esac
cat <<\_ACEOF
@ -1405,6 +1406,8 @@ Optional Features:
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
--disable-trxctl Disable RS-232 to RS-485 converter data direction
control support
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -1491,7 +1494,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
mbusd configure 0.1.3
mbusd configure 0.2.0
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@ -1769,7 +1772,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by mbusd $as_me 0.1.3, which was
It was created by mbusd $as_me 0.2.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@ -2117,7 +2120,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
am__api_version='1.13'
am__api_version='1.14'
ac_aux_dir=
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
@ -2632,7 +2635,7 @@ fi
# Define the identity of the package.
PACKAGE='mbusd'
VERSION='0.1.3'
VERSION='0.2.0'
cat >>confdefs.h <<_ACEOF
@ -2683,6 +2686,47 @@ am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
# POSIX will say in a future version that running "rm -f" with no argument
# is OK; and we want to be able to make that assumption in our Makefile
# recipes. So use an aggressive probe to check that the usage we want is
# actually supported "in the wild" to an acceptable degree.
# See automake bug#10828.
# To make any issue more visible, cause the running configure to be aborted
# by default if the 'rm' program in use doesn't match our expectations; the
# user can still override this though.
if rm -f && rm -fr && rm -rf; then : OK; else
cat >&2 <<'END'
Oops!
Your 'rm' program seems unable to run without file operands specified
on the command line, even when the '-f' option is present. This is contrary
to the behaviour of most rm programs out there, and not conforming with
the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
Please tell bug-automake@gnu.org about your system, including the value
of your $PATH and any error possibly output before this message. This
can help us improve future automake versions.
END
if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
echo 'Configuration will proceed anyway, since you have set the' >&2
echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
echo >&2
else
cat >&2 <<'END'
Aborting the configuration process, to ensure you take notice of the issue.
You can download and install GNU coreutils to get an 'rm' implementation
that behaves properly: <http://www.gnu.org/software/coreutils/>.
If you want to complete the configuration process using your problematic
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
to "yes", and re-run configure.
END
as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
fi
fi
ac_config_headers="$ac_config_headers config.h"
@ -3538,6 +3582,65 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5
$as_echo_n "checking whether $CC understands -c and -o together... " >&6; }
if ${am_cv_prog_cc_c_o+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
# Make sure it works both with $CC and with simple cc.
# Following AC_PROG_CC_C_O, we do the test twice because some
# compilers refuse to overwrite an existing .o file with -o,
# though they will create one.
am_cv_prog_cc_c_o=yes
for am_i in 1 2; do
if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5
($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } \
&& test -f conftest2.$ac_objext; then
: OK
else
am_cv_prog_cc_c_o=no
break
fi
done
rm -f core conftest*
unset am_i
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5
$as_echo "$am_cv_prog_cc_c_o" >&6; }
if test "$am_cv_prog_cc_c_o" != yes; then
# Losing compiler, so override with the script.
# FIXME: It is wrong to rewrite CC.
# But if we don't then we get into trouble of one sort or another.
# A longer-term fix would be to have automake use am__CC in this case,
# and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
CC="$am_aux_dir/compile $CC"
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
depcc="$CC" am_compiler_list=
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
@ -4262,6 +4365,65 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5
$as_echo_n "checking whether $CC understands -c and -o together... " >&6; }
if ${am_cv_prog_cc_c_o+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
# Make sure it works both with $CC and with simple cc.
# Following AC_PROG_CC_C_O, we do the test twice because some
# compilers refuse to overwrite an existing .o file with -o,
# though they will create one.
am_cv_prog_cc_c_o=yes
for am_i in 1 2; do
if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5
($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } \
&& test -f conftest2.$ac_objext; then
: OK
else
am_cv_prog_cc_c_o=no
break
fi
done
rm -f core conftest*
unset am_i
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5
$as_echo "$am_cv_prog_cc_c_o" >&6; }
if test "$am_cv_prog_cc_c_o" != yes; then
# Losing compiler, so override with the script.
# FIXME: It is wrong to rewrite CC.
# But if we don't then we get into trouble of one sort or another.
# A longer-term fix would be to have automake use am__CC in this case,
# and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
CC="$am_aux_dir/compile $CC"
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
depcc="$CC" am_compiler_list=
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
@ -4929,6 +5091,65 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5
$as_echo_n "checking whether $CC understands -c and -o together... " >&6; }
if ${am_cv_prog_cc_c_o+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
# Make sure it works both with $CC and with simple cc.
# Following AC_PROG_CC_C_O, we do the test twice because some
# compilers refuse to overwrite an existing .o file with -o,
# though they will create one.
am_cv_prog_cc_c_o=yes
for am_i in 1 2; do
if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5
($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } \
&& test -f conftest2.$ac_objext; then
: OK
else
am_cv_prog_cc_c_o=no
break
fi
done
rm -f core conftest*
unset am_i
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5
$as_echo "$am_cv_prog_cc_c_o" >&6; }
if test "$am_cv_prog_cc_c_o" != yes; then
# Losing compiler, so override with the script.
# FIXME: It is wrong to rewrite CC.
# But if we don't then we get into trouble of one sort or another.
# A longer-term fix would be to have automake use am__CC in this case,
# and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
CC="$am_aux_dir/compile $CC"
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
depcc="$CC" am_compiler_list=
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
@ -7736,10 +7957,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
x86_64-*linux*)
LD="${LD-ld} -m elf_i386"
;;
powerpcle-*linux*)
powerpc64le-*linux*)
LD="${LD-ld} -m elf32lppclinux"
;;
powerpc-*linux*)
powerpc64-*linux*)
LD="${LD-ld} -m elf32ppclinux"
;;
s390x-*linux*)
@ -12697,8 +12918,8 @@ _ACEOF
LIBS="-lutil $LIBS"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"Function uu_lock\(\) is not found in libutil. UUCP locking switched off!\"" >&5
$as_echo "$as_me: WARNING: \"Function uu_lock\(\) is not found in libutil. UUCP locking switched off!\"" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"Function uu_lock() is not found in libutil. UUCP locking switched off!\"" >&5
$as_echo "$as_me: WARNING: \"Function uu_lock() is not found in libutil. UUCP locking switched off!\"" >&2;}
fi
for ac_func in daemon
@ -12730,7 +12951,7 @@ if test "x$ac_cv_func_cfsetispeed" = xyes; then :
_ACEOF
else
as_fn_error $? "\"Both cfsetspeed\(\) and cfsetispeed\(\) functions not found!\"" "$LINENO" 5
as_fn_error $? "\"Both cfsetspeed() and cfsetispeed() functions not found!\"" "$LINENO" 5
fi
done
@ -12820,6 +13041,20 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
# Check whether --enable-trxctl was given.
if test "${enable_trxctl+set}" = set; then :
enableval=$enable_trxctl;
fi
if test "x$enable_trxctl" != "xno"; then :
$as_echo "#define TRXCTL \"\"" >>confdefs.h
fi
ac_config_files="$ac_config_files Makefile src/Makefile doc/Makefile doc/mbusd.8"
cat >confcache <<\_ACEOF
@ -13359,7 +13594,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by mbusd $as_me 0.1.3, which was
This file was extended by mbusd $as_me 0.2.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -13425,7 +13660,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
mbusd config.status 0.1.3
mbusd config.status 0.2.0
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(mbusd, 0.1.3)
AC_INIT(mbusd, 0.2.0)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)
@ -18,12 +18,12 @@ dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_CHECK_LIB(util, uu_lock, ,
AC_MSG_WARN("Function uu_lock\(\) is not found in libutil. UUCP locking switched off!"))
AC_MSG_WARN("Function uu_lock() is not found in libutil. UUCP locking switched off!"))
dnl Checks for Additional stuffs.
AC_CHECK_FUNCS(daemon)
AC_CHECK_FUNCS(cfsetspeed, ,
[AC_CHECK_FUNCS(cfsetispeed, ,
[AC_MSG_ERROR("Both cfsetspeed\(\) and cfsetispeed\(\) functions not found!")])])
[AC_MSG_ERROR("Both cfsetspeed() and cfsetispeed() functions not found!")])])
AC_CHECK_FUNCS(cfmakeraw)
dnl Set PACKAGE SOURCE DIR in config.h.
@ -82,6 +82,13 @@ AC_DEFINE_UNQUOTED(PACKAGE_HELP_DIR, "${packageprefix}/${packagehelpdir}", "")
AC_DEFINE_UNQUOTED(PACKAGE_MENU_DIR, "${packageprefix}/${packagemenudir}", "")
AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}", "")
AC_ARG_ENABLE([trxctl],
AS_HELP_STRING([--disable-trxctl], [Disable RS-232 to RS-485 converter data direction control support]))
AS_IF([test "x$enable_trxctl" != "xno"], [
AC_DEFINE([TRXCTL], "", "")
])
AC_OUTPUT([
Makefile
src/Makefile

View File

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.13.4 from Makefile.am.
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.

View File

@ -1,79 +1,77 @@
.TH "mbusd" 8 "18 November 2013" "mbusd @VERSION@"
.TH "mbusd" 8 "23 February 2015" "mbusd @VERSION@"
.SH NAME
mbusd \- MODBUS/TCP to MODBUS/RTU gateway server
mbusd \- MODBUS/TCP to MODBUS/RTU gateway.
.SH SYNOPSIS
.B mbusd
.RB [ -h ]
.RB [ -d ]
.RB [ -t ]
.RB [ -v
.IR level ]
.RB [ -L
.IR name ]
.IR logfile ]
.RB [ -p
.IR name ]
.IR device ]
.RB [ -s
.IR value ]
.IR speed ]
.RB [ -P
.IR number ]
.IR port ]
.RB [ -C
.IR number ]
.IR maxconn ]
.RB [ -N
.IR number ]
.IR retries ]
.RB [ -R
.IR value ]
.IR pause ]
.RB [ -W
.IR value ]
.IR wait ]
.RB [ -T
.IR value ]
.IR timeout ]
.SH DESCRIPTION
\fImbusd\fR is MODBUS/TCP to MODBUS/RTU gateway server (currently master mode only is supported).
\fImbusd\fR is MODBUS/TCP to MODBUS/RTU gateway. Currently only master mode is implemented.
.SH OPTIONS
.IP \fB-h\fR
Usage help.
.IP \fB-d\fR
Instruct \fImbusd\fR not to fork itself (non-daemonize).
.IP \fB-t\fR
Enable RTS RS-485 data direction control (if not disabled while compile).
.IP "\fB-v \fIlevel\fR"
Specifies log verbosity level. 0 enables logging of errors only,
1 also enables warnings and 2 enables information messages.
If \fImbusd\fR was compiled in debug mode, valid log levels is up to 9,
where log levels above 2 forces logging of information about additional
internal events.
.IP "\fB-L \fIname\fR"
Specifies log file name. Value '-' forces log data output to STDOUT only if \fB-d\fR switch was given.
.IP "\fB-p \fIname\fR"
.IP "\fB-L \fIlogfile\fR"
Specifies log file name ('-' for logging to STDOUT only, default /var/log/mbusd.log).
.IP "\fB-p \fIdevice\fR"
Specifies serial port device name.
.IP "\fB-s \fIvalue\fR"
.IP "\fB-s \fIspeed\fR"
Specifies serial port speed.
.IP "\fB-P \fInumber\fR"
.IP "\fB-P \fIport\fR"
Specifies TCP port number.
.IP "\fB-C \fInumber\fR"
Specifies maximum number of simultaneous connections.
.IP "\fB-N \fInumber\fR"
Specifies maximum number of request retries. 0 - no retries.
.IP "\fB-R \fIvalue\fR"
.IP "\fB-C \fImaxconn\fR"
Specifies maximum number of simultaneous TCP connections.
.IP "\fB-N \fIretries\fR"
Specifies maximum number of request retries (0 - disable retries).
.IP "\fB-R \fIpause\fR"
Specifies pause between requests in milliseconds.
.IP "\fB-W \fIvalue\fR"
.IP "\fB-W \fIwait\fR"
Specifies response wait time in milliseconds.
.IP "\fB-T \fIvalue\fR"
Specifies connection timeout value in seconds. 0 - no timeout.
.IP "\fB-T \fItimeout\fR"
Specifies connection timeout value in seconds (0 - disable timeout).
.SH NOTES
Because MODBUS RTU protocol have situations which can't straightforwardly
translated into MODBUS/TCP protocol entities, \fImbusd\fR extends standard exception codes set.
In case of situation when \fImbusd\fR received response with invalid CRC and can't correct
error by re-request, it return MODBUS/TCP packet with exception code 128. In case of situation
error by re-request, it return MODBUS/TCP packet with exception code 04. In case of situation
when \fImbusd\fR can't receive response from MODBUS RTU device (e.g. addressed controller
is not present on the network), it return MODBUS/TCP packet with exception code 129.
.SH FILES
.PP
The default location of the \fImbusd\fR log file is:
.PP
/var/log/mbusd.log
is not present on the network), it return MODBUS/TCP packet with exception code 0x0B.
.SH BUGS
Broadcast messaging on MODBUS network isn't supported.
Please send bug reports to author.
.SH AUTHOR
Victor Antonovich <avmlink@vlink.ru>.
.SH AUTHORS
Victor Antonovich <v.antonovich@gmail.com>
Andrew Denysenko <nitr0@seti.kr.ua>
.SH LICENSE
This program is distributed under the BSD-like license, included in
each source file. See also COPYING file in the installation directory.

View File

@ -1,7 +1,7 @@
#! /bin/sh
# libtool - Provide generalized library-building support services.
# Generated automatically by config.status (mbusd) 0.1.3
# Generated automatically by config.status (mbusd) 0.2.0
# Libtool was configured on host 3cky.office.mobileap.ru:
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
#
@ -272,10 +272,10 @@ finish_eval=""
hardcode_into_libs=yes
# Compile-time system search path for libraries.
sys_lib_search_path_spec="/usr/lib/gcc/x86_64-redhat-linux/4.8.2 /usr/lib64 /lib64 "
sys_lib_search_path_spec="/usr/lib/gcc/x86_64-redhat-linux/4.9.2 /usr/lib64 /lib64 "
# Run-time system search path for libraries.
sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib /usr/lib64/atlas /usr/lib64/dyninst /usr/lib64/kicad /usr/lib64/iscsi /usr/lib/llvm /usr/lib64/llvm /usr/lib64/mysql /usr/lib64/qt-3.3/lib /opt/Samsung/PSU/share/lib64 /usr/lib64/tcl8.5 /usr/lib64/tracker-0.16 /usr/lib/xulrunner /usr/lib64/xulrunner "
sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib /usr/lib64/R/lib /usr/lib64/atlas /usr/lib64/dyninst /usr/lib64/iscsi /usr/lib/llvm /usr/lib64/llvm /usr/lib64/mysql /usr/lib64/OGRE /usr/lib64/qt-3.3/lib /opt/Samsung/PSU/share/lib64 /usr/lib64/tcl8.6 /usr/lib64/vtk /usr/lib/xulrunner /usr/lib64/xulrunner "
# Whether dlopen is supported.
dlopen_support=unknown

4
m4/libtool.m4 vendored
View File

@ -1326,10 +1326,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
x86_64-*linux*)
LD="${LD-ld} -m elf_i386"
;;
powerpcle-*linux*)
powerpc64le-*linux*)
LD="${LD-ld} -m elf32lppclinux"
;;
powerpc-*linux*)
powerpc64-*linux*)
LD="${LD-ld} -m elf32ppclinux"
;;
s390x-*linux*)

View File

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.13.4 from Makefile.am.
# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
@ -429,14 +429,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

View File

@ -3,7 +3,7 @@
*
* cfg.c - configuration related procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: cfg.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: cfg.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "cfg.h"

View File

@ -3,7 +3,7 @@
*
* cfg.h - configuration related procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: cfg.h,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: cfg.h,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _CFG_H

View File

@ -3,7 +3,8 @@
*
* conn.c - connections management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, 2015 Victor Antonovich (v.antonovich@gmail.com)
* Copyright (c) 2011 Andrew Denysenko <nitr0@seti.kr.ua>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +29,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: conn.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: conn.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "conn.h"
@ -46,13 +47,36 @@ int max_sd; /* major descriptor in the select() sets */
void conn_tty_start(ttydata_t *tty, conn_t *conn);
ssize_t conn_read(int d, void *buf, size_t nbytes);
ssize_t conn_write(int d, void *buf, size_t nbytes);
ssize_t conn_write(int d, void *buf, size_t nbytes, int istty);
int conn_select(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);
#define FD_MSET(d, s) do { FD_SET(d, s); max_sd = MAX(d, max_sd); } while (0);
int tty_reinit()
{
logw(3,"closing tty on error...");
tty_close(&tty);
logw(3, "tty closed, re-opening...");
#ifdef TRXCTL
tty_init(&tty, cfg.ttyport, cfg.ttyspeed, cfg.trxcntl);
#else
tty_init(&tty, cfg.ttyport, cfg.ttyspeed);
#endif
if (tty_open(&tty) != RC_OK)
{
#ifdef LOG
logw(0, "conn_init():"
" can't open tty device %s (%s)",
cfg.ttyport, strerror(errno));
#endif
return RC_ERR;
}
state_tty_set(&tty, TTY_PAUSE);
logw(3, "re-init ok...");
return RC_OK;
}
/*
* Connections startup initialization
* Parameters: none
@ -70,20 +94,20 @@ conn_init(void)
if (tty_open(&tty) != RC_OK)
{
#ifdef LOG
log(0, "conn_init():"
logw(0, "conn_init():"
" can't open tty device %s (%s)",
cfg.ttyport, strerror(errno));
#endif
return RC_ERR;
}
state_tty_set(&tty, TTY_READY);
state_tty_set(&tty, TTY_PAUSE);
/* create server socket */
if ((server_sd =
sock_create_server("", cfg.serverport, TRUE)) < 0)
{
#ifdef LOG
log(0, "conn_init():"
logw(0, "conn_init():"
" can't create listen() socket (%s)",
strerror(errno));
#endif
@ -111,19 +135,19 @@ conn_open(void)
if ((sd = sock_accept(server_sd, &rmt_addr, TRUE)) == RC_ERR)
{ /* error in conn_accept() */
#ifdef LOG
log(0, "conn_open(): error in accept() (%s)", strerror(errno));
logw(0, "conn_open(): error in accept() (%s)", strerror(errno));
#endif
return;
}
#ifdef LOG
log(2, "conn_open(): accepting connection from %s",
logw(2, "conn_open(): accepting connection from %s",
inet_ntoa(rmt_addr.sin_addr));
#endif
/* compare descriptor of connection with FD_SETSIZE */
if (sd >= FD_SETSIZE)
{
#ifdef LOG
log(1, "conn_open(): FD_SETSIZE limit reached,"
logw(1, "conn_open(): FD_SETSIZE limit reached,"
" connection from %s will be dropped",
inet_ntoa(rmt_addr.sin_addr));
#endif
@ -134,7 +158,7 @@ conn_open(void)
if (queue.len == cfg.maxconn)
{
#ifdef LOG
log(1, "conn_open(): number of connections limit reached,"
logw(1, "conn_open(): number of connections limit reached,"
" connection from %s will be dropped",
inet_ntoa(rmt_addr.sin_addr));
#endif
@ -159,7 +183,7 @@ conn_close(conn_t *conn)
{
conn_t *nextconn;
#ifdef LOG
log(2, "conn_close(): closing connection from %s",
logw(2, "conn_close(): closing connection from %s",
inet_ntoa(conn->sockaddr.sin_addr));
#endif
/* close socket */
@ -216,13 +240,49 @@ conn_read(int d, void *buf, size_t nbytes)
* RC_ERR in case of error.
*/
ssize_t
conn_write(int d, void *buf, size_t nbytes)
conn_write(int d, void *buf, size_t nbytes, int istty)
{
int rc;
fd_set fs;
struct timeval ts, tts;
long delay;
#ifdef TRXCTL
if (istty) {
if (cfg.trxcntl == TRX_RTS)
tty_set_rts(d);
usleep(35000000l/cfg.ttyspeed);
}
#endif
FD_ZERO(&fs);
FD_SET(d, &fs);
do
{ /* trying write to descriptor while breaked by signals */
gettimeofday(&ts, NULL);
rc = write(d, buf, nbytes);
} while (rc == -1 && errno == EINTR);
gettimeofday(&ts, NULL);
#ifdef TRXCTL
if (istty) {
#if 1
do {
gettimeofday(&tts, NULL);
delay = DV(nbytes, cfg.ttyspeed) -
((tts.tv_sec * 1000000l + tts.tv_usec) - (ts.tv_sec * 1000000l + ts.tv_usec));
} while (delay > 0);
#else
gettimeofday(&tts, NULL);
delay = DV(nbytes, cfg.ttyspeed) -
((tts.tv_sec * 1000000l + tts.tv_usec) - (ts.tv_sec * 1000000l + ts.tv_usec));
usleep(delay);
#endif
/* tcdrain(d); - hangs sometimes, so make calculated delay */
if (cfg.trxcntl == TRX_RTS) {
tty_clr_rts(d);
}
}
#endif
return (rc < 0) ? RC_ERR : rc;
}
@ -254,10 +314,12 @@ void
conn_loop(void)
{
int rc, max_sd, len, min_timeout;
unsigned int i;
fd_set sdsetrd, sdsetwr;
struct timeval ts, tts, t_out;
unsigned long tval, tout_sec, tout = 0ul;
conn_t *curconn = NULL;
char t[256], v[8];
while (TRUE)
{
@ -311,20 +373,21 @@ conn_loop(void)
(void)gettimeofday(&ts, NULL); /* make timestamp */
#ifdef DEBUG
log(7, "conn_loop(): select(): max_sd = %d, t_out = %06lu:%06lu ",
logw(7, "conn_loop(): select(): max_sd = %d, t_out = %06lu:%06lu ",
max_sd, t_out.tv_sec, t_out.tv_usec);
#endif
rc = select(max_sd + 1, &sdsetrd, &sdsetwr, NULL, &t_out);
#ifdef DEBUG
logw(7, "conn_loop(): select() returns %d ", rc);
#endif
if (rc < 0)
{ /* some error caused while select() */
if (errno == EINTR) continue; /* process signals */
/* unrecoverable error in select(), exiting */
#ifdef LOG
log(0, "conn_loop(): error in select() (%s)", strerror(errno));
logw(0, "conn_loop(): error in select() (%s)", strerror(errno));
#endif
break;
/* break; */
}
/* calculating elapsed time */
@ -348,56 +411,66 @@ conn_loop(void)
state_tty_set(&tty, TTY_READY);
break;
case TTY_RESP:
case TTY_PROC:
/* checking for received data */
if (FD_ISSET(tty.fd, &sdsetrd)) break;
/* response timeout handling */
if (!tty.ptrbuf)
{/* there no bytes received */
#ifdef DEBUG
log(5, "tty: response timeout", tty.ptrbuf);
logw(5, "tty: response timeout", tty.ptrbuf);
#endif
if (!tty.trynum)
modbus_ex_write(actconn->buf, MB_EX_TIMEOUT);
else
{ /* retry request */
#ifdef DEBUG
log(5, "tty: attempt to retry request (%u of %u)",
logw(5, "tty: attempt to retry request (%u of %u)",
cfg.maxtry - tty.trynum + 1, cfg.maxtry);
#endif
state_tty_set(&tty, TTY_RQST);
FD_SET(tty.fd, &sdsetwr);
break;
}
}
else
{ /* some data received */
#ifdef DEBUG
log(5, "tty: response read (total %d bytes)", tty.ptrbuf);
logw(5, "tty: response read (total %d bytes, offset %d bytes)", tty.ptrbuf, tty.rxoffset);
#endif
if (tty.ptrbuf >= MB_MIN_LEN &&
modbus_crc_correct(tty.rxbuf, tty.ptrbuf))
modbus_crc_correct(tty.rxbuf + tty.rxoffset, tty.ptrbuf - tty.rxoffset))
{ /* received response is correct, make OpenMODBUS response */
#ifdef DEBUG
log(5, "tty: response is correct");
logw(5, "tty: response is correct");
#endif
(void)memcpy((void *)(actconn->buf + HDRSIZE),
(void *)tty.rxbuf, tty.ptrbuf - CRCSIZE);
WORD_WR_BE(actconn->buf + MB_LENGTH_H, tty.ptrbuf - CRCSIZE);
(void *)(tty.rxbuf + tty.rxoffset), tty.ptrbuf - CRCSIZE - tty.rxoffset);
WORD_WR_BE(actconn->buf + MB_LENGTH_H, tty.ptrbuf - CRCSIZE - tty.rxoffset);
}
else
{
/* received response is incomplete or CRC failed */
#ifdef DEBUG
log(5, "tty: response is incorrect");
t[0] = '\0';
for (i = 0; i < tty.ptrbuf; i++) {
sprintf(v,"[%2.2x]", tty.rxbuf[i]);
strncat(t, v, 256);
}
logw(5, "tty: response is incorrect (%s)", t);
#endif
if (!tty.trynum)
if (!tty.trynum) {
modbus_ex_write(actconn->buf, MB_EX_CRC);
else
logw(3, "tty: response is incorrect (%d of %d bytes, offset %d), return error", tty.ptrbuf,
tty.rxoffset + tty.rxlen, tty.rxoffset);
} else
{ /* retry request */
#ifdef DEBUG
log(5, "tty: attempt to retry request (%u of %u)",
logw(5, "tty: attempt to retry request (%u of %u)",
cfg.maxtry - tty.trynum + 1, cfg.maxtry);
#endif
state_tty_set(&tty, TTY_RQST);
FD_SET(tty.fd, &sdsetwr);
break;
}
}
@ -407,8 +480,14 @@ conn_loop(void)
/* make inter-request pause */
state_tty_set(&tty, TTY_PAUSE);
break;
case TTY_RQST:
#ifdef DEBUG
logw(5, "tty: TTY_RQST timeout");
#endif
break;
}
else tty.timer -= tval;
else
tty.timer -= tval;
}
if (cfg.conntimeout)
@ -425,16 +504,16 @@ conn_loop(void)
if (curconn->timeout <= 0)
{ /* timeout expired */
if (curconn->state == CONN_TTY)
{ /* deadlock in CONN_TTY state, exiting */
{ /* deadlock in CONN_TTY state, make attempt to reinitialize serial port */
#ifdef LOG
log(0, "conn[%s]: state CONN_TTY deadlock, exiting!",
logw(0, "conn[%s]: state CONN_TTY deadlock.",
inet_ntoa(curconn->sockaddr.sin_addr));
#endif
exit (-1);
tty_reinit();
}
/* purge connection */
#ifdef LOG
log(2, "conn[%s]: timeout, closing connection",
logw(2, "conn[%s]: timeout, closing connection",
inet_ntoa(curconn->sockaddr.sin_addr));
#endif
curconn = conn_close(curconn);
@ -446,9 +525,6 @@ conn_loop(void)
}
}
if (rc == 0)
continue; /* timeout caused, we will do select() again */
/* checking for pending connections */
if (FD_ISSET(server_sd, &sdsetrd)) conn_open();
@ -456,25 +532,53 @@ conn_loop(void)
if (tty.state == TTY_RQST)
if (FD_ISSET(tty.fd, &sdsetwr))
{
tcflush(tty.fd, TCIOFLUSH);
rc = conn_write(tty.fd, tty.txbuf + tty.ptrbuf,
tty.txlen - tty.ptrbuf);
tty.txlen - tty.ptrbuf, 1);
if (rc <= 0)
{ /* error - we can't continue... */
{ /* error - make attempt to reinitialize serial port */
#ifdef LOG
log(0, "tty: error in write() (%s)", strerror(errno));
logw(0, "tty: error in write() (%s)", strerror(errno));
#endif
break; /* exiting... */
tty_reinit();
}
#ifdef DEBUG
log(7, "tty: written %d bytes", rc);
logw(7, "tty: written %d bytes", rc);
#endif
tty.ptrbuf += rc;
if (tty.ptrbuf == tty.txlen)
{ /* request transmitting completed, switch to TTY_RESP */
#ifdef DEBUG
log(7, "tty: request written (total %d bytes)", tty.txlen);
logw(7, "tty: request written (total %d bytes)", tty.txlen);
#endif
state_tty_set(&tty, TTY_RESP);
switch (tty.txbuf[1]) {
case 1:
case 2:
tty.rxlen = 5 + (tty.txbuf[4] * 256 + tty.txbuf[5] + 7)/8;
break;
case 3:
case 4:
tty.rxlen = 5 + tty.txbuf[5] * 2;
break;
case 7:
tty.rxlen = 5;
break;
case 11:
case 15:
case 16:
tty.rxlen = 8;
break;
default:
tty.rxlen = tty.txlen;
break;
}
if (tty.rxlen > TTY_BUFSIZE)
tty.rxlen = TTY_BUFSIZE;
tty.timer += DV(tty.rxlen, tty.speed);
#ifdef DEBUG
logw(5, "tty: estimated %d bytes, waiting %lu usec", tty.rxlen, tty.timer);
#endif
}
}
@ -482,46 +586,122 @@ conn_loop(void)
{
if (tty.state == TTY_RESP)
{
if (tty.rxlen - tty.ptrbuf + tty.rxoffset <= 0) {
tcflush(tty.fd, TCIFLUSH);
state_tty_set(&tty, TTY_PAUSE);
continue;
}
rc = conn_read(tty.fd, tty.rxbuf + tty.ptrbuf,
tty.rxlen - tty.ptrbuf);
if (rc <= 0)
{ /* error - we can't continue... */
tty.rxlen - tty.ptrbuf + tty.rxoffset);
if (rc < 0)
{ /* error - make attempt to reinitialize serial port */
#ifdef LOG
log(0, "tty: error in read() (%s)", strerror(errno));
logw(0, "tty: error in read() (%s)", strerror(errno));
#endif
break; /* exiting... */
tty_reinit();
}
#ifdef DEBUG
log(7, "tty: read %d bytes", rc);
logw(7, "tty: read %d bytes", rc);
#endif
if (tty.ptrbuf - tty.rxoffset < 3 && tty.ptrbuf - tty.rxoffset + rc >= 3) {
/* we received more than 3 bytes from header - address, request id and bytes count */
if (!tty.rxoffset) {
/* offset is unknown */
unsigned char i;
for (i = 0; i < tty.ptrbuf - tty.rxoffset + rc - 1; i++) {
if (tty.rxbuf[i] == tty.txbuf[0] && tty.rxbuf[i+1] == tty.txbuf[1]) {
#ifdef DEBUG
logw(5, "tty: rx offset is %d", i);
#endif
tty.rxoffset = i;
break;
}
}
switch (tty.txbuf[1]) {
case 1:
case 2:
case 3:
case 4:
i = 5 + tty.rxbuf[tty.rxoffset + 2];
break;
}
if (i + tty.rxoffset > TTY_BUFSIZE)
i = TTY_BUFSIZE - tty.rxoffset;
if (i != tty.rxlen) {
#ifdef DEBUG
logw(5, "tty: rx len changed from %d to %d", tty.rxlen, i);
#endif
tty.rxlen = i;
}
}
}
tty.ptrbuf += rc;
if (tty.ptrbuf == tty.rxlen)
{ /* XXX still generating error response */
logw(5, "tty: read %d bytes of %d, offset %d", tty.ptrbuf, tty.rxlen + tty.rxoffset, tty.rxoffset);
if (tty.ptrbuf == tty.rxlen + tty.rxoffset)
state_tty_set(&tty, TTY_PROC);
}
else if (tty.state != TTY_PROC)
{ /* drop unexpected tty data */
if ((rc = conn_read(tty.fd, tty.rxbuf, BUFSIZE)) < 0)
{ /* error - make attempt to reinitialize serial port */
#ifdef LOG
logw(0, "tty: error in read() (%s)", strerror(errno));
#endif
tty_reinit();
}
#ifdef DEBUG
logw(7, "tty: dropped %d bytes", rc);
#endif
}
}
if (tty.state == TTY_PROC) {
#ifdef DEBUG
logw(5, "tty: response read (total %d bytes, offset %d bytes)", tty.ptrbuf, tty.rxoffset);
#endif
if (tty.ptrbuf >= MB_MIN_LEN &&
modbus_crc_correct(tty.rxbuf + tty.rxoffset, tty.ptrbuf - tty.rxoffset))
{ /* received response is correct, make OpenMODBUS response */
#ifdef DEBUG
logw(5, "tty: response is correct");
#endif
(void)memcpy((void *)(actconn->buf + HDRSIZE),
(void *)(tty.rxbuf + tty.rxoffset), tty.ptrbuf - CRCSIZE - tty.rxoffset);
WORD_WR_BE(actconn->buf + MB_LENGTH_H, tty.ptrbuf - CRCSIZE - tty.rxoffset);
/* switch connection to response state */
state_conn_set(actconn, CONN_RESP);
/* make inter-request pause */
state_tty_set(&tty, TTY_PAUSE);
} else {
/* received response is incomplete or CRC failed */
#ifdef DEBUG
t[0] = '\0';
for (i = 0; i < tty.ptrbuf; i++) {
sprintf(v,"[%2.2x]", tty.rxbuf[i]);
strncat(t, v, 256);
}
logw(5, "tty: response is incorrect (%s)", t);
#endif
if (!tty.trynum) {
logw(3, "tty: response is incorrect (%d of %d bytes, offset %d), return error", tty.ptrbuf,
tty.rxoffset + tty.rxlen, tty.rxoffset);
modbus_ex_write(actconn->buf, MB_EX_CRC);
/* switch connection to response state */
state_conn_set(actconn, CONN_RESP);
/* make inter-request pause */
state_tty_set(&tty, TTY_PAUSE);
}
else
/* reset timer */
tty.timer = cfg.respwait * 1000l;
}
else
{ /* drop unexpected tty data */
if ((rc = conn_read(tty.fd, tty.rxbuf, BUFSIZE)) <= 0)
{ /* error - we can't continue... */
#ifdef LOG
log(0, "tty: error in read() (%s)", strerror(errno));
#endif
break; /* exiting... */
}
} else { /* retry request */
#ifdef DEBUG
log(7, "tty: dropped %d bytes", rc);
logw(5, "tty: attempt to retry request (%u of %u)",
cfg.maxtry - tty.trynum + 1, cfg.maxtry);
#endif
state_tty_set(&tty, TTY_RQST);
}
}
}
if (rc == 0)
continue; /* timeout caused, we will do select() again */
/* processing data on the sockets */
len = queue.len;
curconn = queue.beg;
@ -569,7 +749,7 @@ conn_loop(void)
rc = conn_write(curconn->sd,
curconn->buf + curconn->ctr,
MB_HDR(curconn->buf, MB_LENGTH_L) +
HDRSIZE - curconn->ctr);
HDRSIZE - curconn->ctr, 0);
if (rc <= 0)
{ /* error - drop this connection and go to next queue element */
curconn = conn_close(curconn);

View File

@ -3,7 +3,7 @@
*
* conn.h - connections management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: conn.h,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: conn.h,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _CONN_H

View File

@ -3,7 +3,7 @@
*
* crc16.c - Cyclic Redundant Checks calculating
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: crc16.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: crc16.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "crc16.h"

View File

@ -3,7 +3,7 @@
*
* crc16.h - Cyclic Redundant Checks calculating
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: crc16.h,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: crc16.h,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _CRC_H

View File

@ -3,7 +3,7 @@
*
* globals.h - global definitions
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: globals.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: globals.h,v 1.4 2015/02/25 10:33:58 kapyar Exp $
*/
#ifndef _GLOBALS_H

View File

@ -3,19 +3,19 @@
*
* log.c - debug logging facility
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: log.c,v 1.5 2013/11/18 08:57:01 kapyar Exp $
* $Id: log.c,v 1.6 2015/02/25 10:33:57 kapyar Exp $
*/
#include "log.h"
@ -39,7 +39,7 @@
/* log file full name */
char logfullname[INTBUFSIZE + 1];
int
int
log_init(char *logname)
{
FILE *logfile;
@ -48,7 +48,7 @@ log_init(char *logname)
/* checking log file name */
if (*logname == '/')
strncpy(logfullname, logname, maxlen);
else
else
{
if (!*logname)
{
@ -72,7 +72,7 @@ log_init(char *logname)
}
/* Append message STRING to log file LOGNAME */
int
int
log_app(char *logname, char *string)
{
FILE *logfile;
@ -87,8 +87,8 @@ log_app(char *logname, char *string)
}
/* Put message with format FMT with errorlevel LEVEL to log file */
void
log(int level, char *fmt, ...)
void
logw(int level, char *fmt, ...)
{
#ifdef HRDATE
time_t tt;

View File

@ -3,19 +3,19 @@
*
* log.h - debug logging facility
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: log.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: log.h,v 1.4 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _LOG_H
@ -45,7 +45,7 @@ extern int isdaemon;
#ifdef LOG
int log_init(char *logname);
int log_app(char *logname, char *string);
void log(int level, char *fmt, ...);
void logw(int level, char *fmt, ...);
#endif
#endif /* _LOG_H */

View File

@ -3,7 +3,7 @@
*
* main.c - main module
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: main.c,v 1.5 2013/11/18 08:57:01 kapyar Exp $
* $Id: main.c,v 1.6 2015/02/25 10:33:57 kapyar Exp $
*/
#include "globals.h"
@ -99,37 +99,42 @@ daemon(nochdir, noclose)
void
usage(char *exename)
{
printf("%s-%s Copyright (C) 2002-2003, 2013 Victor Antonovich <avmlink@vlink.ru>\n\n"
"Usage: %s [-h] [-d] [-v level] [-L name] [-p name] [-s value] [-P number]\n"
" [-C number] [-N number] [-R value] [-W value] [-T value]\n\n"
" -h this help\n"
" -d don't daemonize\n"
printf("%s-%s Copyright (C) 2002-2003, 2011, 2013, 2015 Victor Antonovich <v.antonovich@gmail.com>, "
"Andrew Denysenko <nitr0@seti.kr.ua>\n\n"
"Usage: %s [-h] [-d] "
#ifdef TRXCTL
"[-t] "
#endif
"[-v level] [-L logfile] [-p device] [-s speed] [-P port]\n"
" [-C maxconn] [-N retries] [-R pause] [-W wait] [-T timeout]\n\n"
"Options:\n"
" -h : this help\n"
" -d : don't daemonize\n"
#ifdef TRXCTL
" -t : enable RTS RS-485 data direction control\n"
#endif
#ifdef LOG
#ifdef DEBUG
" -v<level> set log level (0-9, default %d, 0 - errors only)\n"
" -v level : set log level (0-9, default %d, 0 - errors only)\n"
#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
" -L<name> set log file name (default %s%s, \n"
" value '-' forces log data output to STDOUT only\n"
" if '-d' switch was given)\n"
" -L logfile : set log file name (default %s%s, \n"
" '-' for logging to STDOUT only)\n"
#endif
" -p<name> set serial port device name (default %s)\n"
" -s<value> set serial port speed (default %d)\n"
#ifdef TRXCTL
" -t force RTS RS-485 transmitting/receiving control\n"
#endif
" -P<number> set TCP server port number (default %d)\n"
" -C<number> set maximum number of simultaneous connections\n"
" (1-128, default %d)\n"
" -N<number> set maximum number of request retries\n"
" (0-15, default %d, 0 - without retries)\n"
" -R<value> set pause between requests in milliseconds\n"
" (1-10000, default %lu)\n"
" -W<value> set response wait time in milliseconds\n"
" (1-10000, default %lu)\n"
" -T<value> set connection timeout value in seconds\n"
" (0-1000, default %d, 0 - no timeout)"
" -p device : set serial port device name (default %s)\n"
" -s speed : set serial port speed (default %d)\n"
" -P port : set TCP server port number (default %d)\n"
" -C maxconn : set maximum number of simultaneous TCP connections\n"
" (1-128, default %d)\n"
" -N retries : set maximum number of request retries\n"
" (0-15, default %d, 0 - without retries)\n"
" -R pause : set pause between requests in milliseconds\n"
" (1-10000, default %lu)\n"
" -W wait : set response wait time in milliseconds\n"
" (1-10000, default %lu)\n"
" -T timeout : set connection timeout value in seconds\n"
" (0-1000, default %d, 0 - no timeout)"
"\n", PACKAGE, VERSION, exename,
#ifdef LOG
cfg.dbglvl, LOGPATH, LOGNAME,
@ -198,13 +203,7 @@ main(int argc, char *argv[])
{
if (*optarg == '-')
{
if (isdaemon)
{
printf("%s: -L: '-' value is valid only if "
"-d switch was given\n", exename);
exit(-1);
}
/* logfile isn't needed, doing all output to STDOUT */
/* logging to file disabled */
*cfg.logname = '\0';
}
else
@ -293,14 +292,14 @@ main(int argc, char *argv[])
strerror(errno));
exit(-1);
}
log(2, "%s-%s started...", PACKAGE, VERSION);
logw(2, "%s-%s started...", PACKAGE, VERSION);
#endif
if (conn_init())
{
#ifdef LOG
err = errno;
log(2, "conn_init() failed, exiting...");
logw(2, "conn_init() failed, exiting...");
#endif
exit(err);
}
@ -309,7 +308,7 @@ main(int argc, char *argv[])
if (isdaemon && (rc = daemon(TRUE, FALSE)))
{
#ifdef LOG
log(0, "Can't daemonize (%s), exiting...", strerror(errno));
logw(0, "Can't be daemonized (%s), exiting...", strerror(errno));
#endif
exit(rc);
}
@ -317,7 +316,7 @@ main(int argc, char *argv[])
conn_loop();
err = errno;
#ifdef LOG
log(2, "%s-%s exited...", PACKAGE, VERSION);
logw(2, "%s-%s exited...", PACKAGE, VERSION);
#endif
return (err);
}

View File

@ -3,7 +3,7 @@
*
* modbus.c - MODBUS protocol related procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: modbus.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: modbus.c,v 1.3 2015/02/25 10:33:58 kapyar Exp $
*/
#include "modbus.h"

View File

@ -3,7 +3,7 @@
*
* modbus.h - MODBUS protocol related procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: modbus.h,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: modbus.h,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _MODBUS_H
@ -83,8 +83,8 @@
/*
* Exception codes
*/
#define MB_EX_CRC 128
#define MB_EX_TIMEOUT 129
#define MB_EX_CRC 4
#define MB_EX_TIMEOUT 0x0B
/* Prototypes */
int modbus_crc_correct(unsigned char *frame, unsigned int len);

View File

@ -3,7 +3,7 @@
*
* queue.c - <EFBFBD>onnections queue management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: queue.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: queue.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "queue.h"
@ -54,7 +54,7 @@ queue_new_elem(queue_t *queue)
if (!newconn)
{ /* Aborting program execution */
#ifdef LOG
log(0, "queue_new_elem(): out of memory for new element (%s)",
logw(0, "queue_new_elem(): out of memory for new element (%s)",
strerror(errno));
#endif
exit(errno);
@ -67,7 +67,7 @@ queue_new_elem(queue_t *queue)
queue->end = newconn;
queue->len++;
#ifdef DEBUG
log(5, "queue_new_elem(): length now is %d", queue->len);
logw(5, "queue_new_elem(): length now is %d", queue->len);
#endif
return newconn;
}
@ -81,7 +81,7 @@ queue_delete_elem(queue_t *queue, conn_t *conn)
if (queue->len <= 0)
{ /* queue is empty */
#ifdef LOG
log(1, "queue_delete_elem(): queue empty!");
logw(1, "queue_delete_elem(): queue empty!");
#endif
return;
}
@ -102,7 +102,7 @@ queue_delete_elem(queue_t *queue, conn_t *conn)
queue->len--;
free((void *)conn);
#ifdef DEBUG
log(5, "queue_delete_elem(): length now is %d", queue->len);
logw(5, "queue_delete_elem(): length now is %d", queue->len);
#endif
return;
}

View File

@ -3,7 +3,7 @@
*
* queue.h - <EFBFBD>onnections queue management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: queue.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: queue.h,v 1.4 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _QUEUE_H

View File

@ -3,7 +3,7 @@
*
* sig.c - signals management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sig.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: sig.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "sig.h"
@ -146,7 +146,7 @@ sig_exec(void)
static char *signames[] = {
"", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", "BUS", "FPE",
"KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM" };
log(2, "Terminated by signal: SIG%s", signames[sig_flag]);
logw(2, "Terminated by signal: SIG%s", signames[sig_flag]);
#endif
/* currently simply exit the program */
exit(1);

View File

@ -3,7 +3,7 @@
*
* sig.h - signals management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sig.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: sig.h,v 1.4 2015/02/25 10:33:58 kapyar Exp $
*/
#ifndef _SIG_H

View File

@ -3,7 +3,7 @@
*
* sock.c - socket manipulation routines
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sock.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: sock.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "sock.h"
@ -66,7 +66,7 @@ sock_create(int blkmode)
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
{
#ifdef LOG
log(0, "sock_create(): unable to create socket (%s)",
logw(0, "sock_create(): unable to create socket (%s)",
strerror(errno));
#endif
return RC_ERR;
@ -76,7 +76,7 @@ sock_create(int blkmode)
if (sock_set_blkmode(sock, blkmode) == -1)
{
#ifdef LOG
log(0, "sock_create(): unable to set "
logw(0, "sock_create(): unable to set "
"server socket to nonblocking (%s)",
strerror(errno));
#endif
@ -109,7 +109,7 @@ sock_create_server(char *server_ip,
if (fcntl(server_s, F_SETFD, 1) == -1)
{
#ifdef LOG
log(0, "sock_create_server():"
logw(0, "sock_create_server():"
" can't set close-on-exec on socket (%s)",
strerror(errno));
#endif
@ -121,7 +121,7 @@ sock_create_server(char *server_ip,
sizeof(sock_opt)) == -1)
{
#ifdef LOG
log(0, "sock_create_server():"
logw(0, "sock_create_server():"
" can't set socket to SO_REUSEADDR (%s)",
strerror(errno));
#endif
@ -137,7 +137,7 @@ sock_create_server(char *server_ip,
sizeof(sock_opt)) == -1))
{
#ifdef LOG
log(0, "sock_create_server():"
logw(0, "sock_create_server():"
" can't set socket TRX buffers sizes (%s)",
strerror(errno));
#endif
@ -158,7 +158,7 @@ sock_create_server(char *server_ip,
sizeof(server_sockaddr)) == -1)
{
#ifdef LOG
log(0, "sock_create_server():"
logw(0, "sock_create_server():"
" unable to bind() socket (%s)",
strerror(errno));
#endif
@ -169,7 +169,7 @@ sock_create_server(char *server_ip,
if (listen(server_s, BACKLOG) == -1)
{
#ifdef LOG
log(0, "sock_create_server():"
logw(0, "sock_create_server():"
" unable to listen() on socket (%s)",
strerror(errno));
#endif
@ -199,7 +199,7 @@ sock_accept(int server_sd, struct sockaddr_in *rmt_addr, int blkmode)
if (errno != EAGAIN && errno != EWOULDBLOCK)
/* some errors caused */
#ifdef LOG
log(0, "sock_accept(): error in accept() (%s)", strerror(errno));
logw(0, "sock_accept(): error in accept() (%s)", strerror(errno));
#endif
return RC_ERR;
}
@ -207,7 +207,7 @@ sock_accept(int server_sd, struct sockaddr_in *rmt_addr, int blkmode)
if (sock_set_blkmode(sd, blkmode) == RC_ERR)
{
#ifdef LOG
log(0, "sock_accept(): can't set socket blocking mode (%s)",
logw(0, "sock_accept(): can't set socket blocking mode (%s)",
strerror(errno));
#endif
close(sd);
@ -222,7 +222,7 @@ sock_accept(int server_sd, struct sockaddr_in *rmt_addr, int blkmode)
sizeof(sock_opt)) == -1))
{
#ifdef LOG
log(0, "sock_accept():"
logw(0, "sock_accept():"
" can't set socket TRX buffer sizes (%s)",
strerror(errno));
#endif

View File

@ -3,7 +3,7 @@
*
* sock.h - socket manipulation routines
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sock.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: sock.h,v 1.4 2015/02/25 10:33:57 kapyar Exp $
*/
#ifndef _SOCKUTILS_H

View File

@ -3,7 +3,7 @@
*
* state.c - state management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: state.c,v 1.2 2013/11/18 08:57:01 kapyar Exp $
* $Id: state.c,v 1.3 2015/02/25 10:33:57 kapyar Exp $
*/
#include "state.h"
@ -75,31 +75,31 @@ state_conn_set(conn_t *conn, int state)
case CONN_HEADER:
conn->ctr = 0;
#ifdef DEBUG
log(5, "conn[%s]: state now is CONN_HEADER",
logw(5, "conn[%s]: state now is CONN_HEADER",
inet_ntoa(conn->sockaddr.sin_addr));
#endif
break;
#ifdef DEBUG
case CONN_RQST:
log(5, "conn[%s]: state now is CONN_RQST",
logw(5, "conn[%s]: state now is CONN_RQST",
inet_ntoa(conn->sockaddr.sin_addr));
break;
case CONN_TTY:
log(5, "conn[%s]: state now is CONN_TTY",
logw(5, "conn[%s]: state now is CONN_TTY",
inet_ntoa(conn->sockaddr.sin_addr));
break;
#endif
case CONN_RESP:
conn->ctr = 0;
#ifdef DEBUG
log(5, "conn[%s]: state now is CONN_RESP",
logw(5, "conn[%s]: state now is CONN_RESP",
inet_ntoa(conn->sockaddr.sin_addr));
#endif
break;
default:
/* unknown state, exiting */
#ifdef DEBUG
log(5, "conn_set_state([%s]) - invalid state (%d)",
logw(5, "conn_set_state([%s]) - invalid state (%d)",
inet_ntoa(conn->sockaddr.sin_addr), state);
#endif
exit (-1);
@ -121,14 +121,14 @@ state_tty_set(ttydata_t *mod, int state)
mod->trynum = 0;
mod->timer = (unsigned long)cfg.rqstpause * 1000l;
#ifdef DEBUG
log(5, "tty: state now is TTY_PAUSE");
logw(5, "tty: state now is TTY_PAUSE");
#endif
break;
case TTY_READY:
mod->trynum = 0;
mod->timer = 0l;
#ifdef DEBUG
log(5, "tty: state now is TTY_READY");
logw(5, "tty: state now is TTY_READY");
#endif
break;
case TTY_RQST:
@ -136,7 +136,7 @@ state_tty_set(ttydata_t *mod, int state)
mod->timer = 0l;
mod->trynum = mod->trynum ? mod->trynum - 1 : (unsigned)cfg.maxtry;
#ifdef DEBUG
log(5, "tty: state now is TTY_RQST");
logw(5, "tty: state now is TTY_RQST");
#endif
#ifndef NOSILENT
tty_delay(DV(2, cfg.ttyspeed));
@ -144,17 +144,23 @@ state_tty_set(ttydata_t *mod, int state)
break;
case TTY_RESP:
mod->ptrbuf = 0;
mod->rxoffset = 0;
/* XXX need real recv length? */
mod->rxlen = TTY_BUFSIZE;
mod->timer = cfg.respwait * 1000l + DV(mod->txlen, mod->speed);
#ifdef DEBUG
log(5, "tty: state now is TTY_RESP");
logw(5, "tty: state now is TTY_RESP");
#endif
break;
case TTY_PROC:
#ifdef DEBUG
logw(5, "tty: state now is TTY_PROC");
#endif
break;
default:
/* unknown state, exiting */
#ifdef DEBUG
log(5, "tty_set_state() - invalid state (%d)", state);
logw(5, "tty_set_state() - invalid state (%d)", state);
#endif
exit (-1);
}

View File

@ -3,7 +3,7 @@
*
* state.h - state management procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: state.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: state.h,v 1.4 2015/02/25 10:33:58 kapyar Exp $
*/
#ifndef _STATE_H

View File

@ -3,7 +3,7 @@
*
* tty.c - terminal I/O related procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: tty.c,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: tty.c,v 1.4 2015/02/25 10:33:58 kapyar Exp $
*/
#include "tty.h"
@ -103,14 +103,14 @@ tty_open(ttydata_t *mod)
{
buferr = errno;
#ifdef LOG
log(0, "uu_lock(): can't lock tty device %s (%s)",
logw(0, "uu_lock(): can't lock tty device %s (%s)",
ttyname, uu_lockerr(uuerr));
#endif
errno = buferr;
return RC_ERR;
}
#endif
mod->fd = open(mod->port, O_RDWR | O_NONBLOCK);
mod->fd = open(mod->port, O_RDWR | O_NONBLOCK | O_NOCTTY);
if (mod->fd < 0)
return RC_ERR; /* attempt failed */
return tty_set_attr(mod);
@ -123,6 +123,7 @@ int
tty_set_attr(ttydata_t *mod)
{
int flag;
speed_t tspeed = tty_transpeed(mod->speed);
memset(&mod->savedtios, 0, sizeof(struct termios));
if (tcgetattr(mod->fd, &mod->savedtios))
@ -140,10 +141,10 @@ tty_set_attr(ttydata_t *mod)
mod->tios.c_cc[VTIME] = 0;
mod->tios.c_cc[VMIN] = 1;
#ifdef HAVE_CFSETSPEED
cfsetspeed(&mod->tios, tty_transpeed(mod->speed));
cfsetspeed(&mod->tios, tspeed);
#else
cfsetispeed(&mod->tios, tty_transpeed(mod->speed));
cfsetospeed(&mod->tios, tty_transpeed(mod->speed));
cfsetispeed(&mod->tios, tspeed);
cfsetospeed(&mod->tios, tspeed);
#endif
if (tcsetattr(mod->fd, TCSANOW, &mod->tios))
return RC_ERR;
@ -320,7 +321,7 @@ tty_close(ttydata_t *mod)
{
buferr = errno;
#ifdef LOG
log(0, "uu_lock(): can't unlock tty device %s",
logw(0, "uu_lock(): can't unlock tty device %s",
ttyname);
#endif
errno = buferr;

View File

@ -3,7 +3,7 @@
*
* tty.h - terminal I/O related procedures
*
* Copyright (c) 2002-2003, 2013, Victor Antonovich (avmlink@vlink.ru)
* Copyright (c) 2002-2003, 2013, Victor Antonovich (v.antonovich@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: tty.h,v 1.3 2013/11/18 08:57:01 kapyar Exp $
* $Id: tty.h,v 1.4 2015/02/25 10:33:58 kapyar Exp $
*/
#ifndef _TTY_H
@ -65,8 +65,8 @@
* TRX control types
*/
#ifdef TRXCTL
# define TRX_ADDC 0
# define TRX_RTS !TRX_ADDC
#define TRX_ADDC 0
#define TRX_RTS 1
#endif
/*
@ -76,6 +76,7 @@
#define TTY_READY 1
#define TTY_RQST 2
#define TTY_RESP 3
#define TTY_PROC 4
/*
* TTY related data storage structure
@ -86,7 +87,7 @@ typedef struct
int speed; /* serial port speed */
char *port; /* serial port device name */
#ifdef TRXCTL
int trxcntl; /* trx control type (0 - ADDC, RTS otherwise) */
int trxcntl; /* trx control type (0 - Automatic Data Direction Control (ADDC), 1 - by RTS) */
#endif
struct termios tios; /* working termios structure */
struct termios savedtios; /* saved termios structure */
@ -96,6 +97,7 @@ typedef struct
unsigned int txlen; /* tx data length */
unsigned int rxlen; /* rx data length */
unsigned char ptrbuf; /* ptr in the buffer */
unsigned char rxoffset; /* ptr in the buffer */
unsigned char txbuf[TTY_BUFSIZE]; /* transmitting buffer */
unsigned char rxbuf[TTY_BUFSIZE]; /* receiving buffer */
} ttydata_t;