got rid of duplicate catalog libmbus/libmbus
This commit is contained in:
18
mbus/Makefile.am
Normal file
18
mbus/Makefile.am
Normal file
@ -0,0 +1,18 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (C) 2010, Raditex AB
|
||||
# All rights reserved.
|
||||
#
|
||||
# rSCADA
|
||||
# http://www.rSCADA.se
|
||||
# info@rscada.se
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
PACKAGE = @PACKAGE@
|
||||
VERSION = @VERSION@
|
||||
|
||||
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)
|
||||
|
||||
pkginclude_HEADERS = mbus.h mbus-protocol.h mbus-tcp.h mbus-serial.h mbus-protocol-aux.h
|
||||
lib_LTLIBRARIES = libmbus.la
|
||||
libmbus_la_SOURCES = mbus.c mbus-protocol.c mbus-tcp.c mbus-serial.c mbus-protocol-aux.c
|
||||
|
557
mbus/Makefile.in
Normal file
557
mbus/Makefile.in
Normal file
@ -0,0 +1,557 @@
|
||||
# Makefile.in generated by automake 1.11.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
|
||||
# Inc.
|
||||
# This Makefile.in 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.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkglibexecdir = $(libexecdir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = mbus
|
||||
DIST_COMMON = $(pkginclude_HEADERS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
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 \
|
||||
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
|
||||
am__install_max = 40
|
||||
am__nobase_strip_setup = \
|
||||
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
|
||||
am__nobase_strip = \
|
||||
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
|
||||
am__nobase_list = $(am__nobase_strip_setup); \
|
||||
for p in $$list; do echo "$$p $$p"; done | \
|
||||
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
|
||||
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
|
||||
if (++n[$$2] == $(am__install_max)) \
|
||||
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
|
||||
END { for (dir in files) print dir, files[dir] }'
|
||||
am__base_list = \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
|
||||
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgincludedir)"
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libmbus_la_LIBADD =
|
||||
am_libmbus_la_OBJECTS = mbus.lo mbus-protocol.lo mbus-tcp.lo \
|
||||
mbus-serial.lo mbus-protocol-aux.lo
|
||||
libmbus_la_OBJECTS = $(am_libmbus_la_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
am__mv = mv -f
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libmbus_la_SOURCES)
|
||||
DIST_SOURCES = $(libmbus_la_SOURCES)
|
||||
HEADERS = $(pkginclude_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
FGREP = @FGREP@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANIFEST_TOOL = @MANIFEST_TOOL@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (C) 2010, Raditex AB
|
||||
# All rights reserved.
|
||||
#
|
||||
# rSCADA
|
||||
# http://www.rSCADA.se
|
||||
# info@rscada.se
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)
|
||||
pkginclude_HEADERS = mbus.h mbus-protocol.h mbus-tcp.h mbus-serial.h mbus-protocol-aux.h
|
||||
lib_LTLIBRARIES = libmbus.la
|
||||
libmbus_la_SOURCES = mbus.c mbus-protocol.c mbus-tcp.c mbus-serial.c mbus-protocol-aux.c
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign mbus/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign mbus/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(am__aclocal_m4_deps):
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
|
||||
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
|
||||
list2=; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
list2="$$list2 $$p"; \
|
||||
else :; fi; \
|
||||
done; \
|
||||
test -z "$$list2" || { \
|
||||
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
|
||||
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
|
||||
}
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
|
||||
for p in $$list; do \
|
||||
$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
|
||||
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
|
||||
done
|
||||
|
||||
clean-libLTLIBRARIES:
|
||||
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
libmbus.la: $(libmbus_la_OBJECTS) $(libmbus_la_DEPENDENCIES)
|
||||
$(LINK) -rpath $(libdir) $(libmbus_la_OBJECTS) $(libmbus_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbus-protocol-aux.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbus-protocol.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbus-serial.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbus-tcp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbus.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
install-pkgincludeHEADERS: $(pkginclude_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
|
||||
@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
|
||||
for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
echo "$$d$$p"; \
|
||||
done | $(am__base_list) | \
|
||||
while read files; do \
|
||||
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \
|
||||
$(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \
|
||||
done
|
||||
|
||||
uninstall-pkgincludeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \
|
||||
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
|
||||
test -n "$$files" || exit 0; \
|
||||
echo " ( cd '$(DESTDIR)$(pkgincludedir)' && rm -f" $$files ")"; \
|
||||
cd "$(DESTDIR)$(pkgincludedir)" && rm -f $$files
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
set x; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
shift; \
|
||||
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
if test $$# -gt 0; then \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
"$$@" $$unique; \
|
||||
else \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$unique; \
|
||||
fi; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& $(am__cd) $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) "$$here"
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d "$(distdir)/$$file"; then \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
|
||||
else \
|
||||
test -f "$(distdir)/$$file" \
|
||||
|| cp -p $$d/$$file "$(distdir)/$$file" \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgincludedir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
html-am:
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-pkgincludeHEADERS
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-dvi-am:
|
||||
|
||||
install-exec-am: install-libLTLIBRARIES
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-html-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-info-am:
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-pdf-am:
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
install-ps-am:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-libLTLIBRARIES uninstall-pkgincludeHEADERS
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libLTLIBRARIES clean-libtool ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-data install-data-am install-dvi \
|
||||
install-dvi-am install-exec install-exec-am install-html \
|
||||
install-html-am install-info install-info-am \
|
||||
install-libLTLIBRARIES install-man install-pdf install-pdf-am \
|
||||
install-pkgincludeHEADERS install-ps install-ps-am \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
|
||||
pdf pdf-am ps ps-am tags uninstall uninstall-am \
|
||||
uninstall-libLTLIBRARIES uninstall-pkgincludeHEADERS
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
1732
mbus/mbus-protocol-aux.c
Normal file
1732
mbus/mbus-protocol-aux.c
Normal file
File diff suppressed because it is too large
Load Diff
360
mbus/mbus-protocol-aux.h
Normal file
360
mbus/mbus-protocol-aux.h
Normal file
@ -0,0 +1,360 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2011, Robert Johansson and contributors, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
// Contributors:
|
||||
// Large parts of this file was contributed by Tomas Menzl.
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @file mbus-protocol-aux.h
|
||||
*
|
||||
* @brief Auxiliary functions to the Freescada libmbus library
|
||||
*
|
||||
* The idea is to simplify the basic task of querying MBus slaves and
|
||||
* the data processing.
|
||||
* Typical use might be (in oversimplified "pseudocode"):
|
||||
* \verbatim
|
||||
* mbus_handle = mbus_connect_serial(device);
|
||||
* or
|
||||
* mbus_handle = mbus_connect_tcp(host, port);
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* mbus_read_slave(mbus_handle, addresses, &reply);
|
||||
* mbus_frame_data_parse(reply, &frameData);
|
||||
* // check the header / record type (fixed/variable)
|
||||
*
|
||||
* // for fixed use mbus_data_fixed_medium and 2x mbus_parse_fixed_record
|
||||
* mbus_data_fixed_medium
|
||||
* mbusRecord = mbus_parse_fixed_record() // first record
|
||||
* // process mbusRecord
|
||||
* mbusRecord = mbus_parse_fixed_record() // second record
|
||||
* // process mbusRecord
|
||||
*
|
||||
* // for variable use mbus_parse_variable_record
|
||||
* for each record
|
||||
* mbusRecord = mbus_parse_variable_record(record)
|
||||
* // process mbusRecord
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* mbus_disconnect(mbus_handle);
|
||||
* \endverbatim
|
||||
*
|
||||
* Note that the quantity values are partially "normalized". For example energy
|
||||
* is in Wh even when originally used "decimal" prefixes like MWh. This seems to
|
||||
* be sensible as it make easier any processing of a dataset with huge
|
||||
* fluctuation (no need to lookup/convert the prefixes). Also the potential
|
||||
* conversion to desired units is pretty easy.
|
||||
*
|
||||
* On the other hand we acknowledge that use of certain units are expected so we
|
||||
* do not convert all units to Si (i.e. no conversion from J to Wh or Bar to Pa.)
|
||||
*/
|
||||
|
||||
#ifndef __MBUS_PROTOCOL_AUX_H__
|
||||
#define __MBUS_PROTOCOL_AUX_H__
|
||||
|
||||
#include <mbus/mbus.h>
|
||||
#include <mbus/mbus-protocol.h>
|
||||
#include <mbus/mbus-serial.h>
|
||||
#include <mbus/mbus-tcp.h>
|
||||
|
||||
#define MBUS_PROBE_NOTHING 0
|
||||
#define MBUS_PROBE_SINGLE 1
|
||||
#define MBUS_PROBE_COLLISION 2
|
||||
#define MBUS_PROBE_ERROR -1
|
||||
|
||||
|
||||
/**
|
||||
* Unified MBus handle type encapsulating either Serial or TCP gateway.
|
||||
*/
|
||||
typedef struct _mbus_handle {
|
||||
char is_serial; /**< _handle type (non zero for serial) */
|
||||
union {
|
||||
mbus_tcp_handle * m_tcp_handle; /**< TCP gateway handle */
|
||||
mbus_serial_handle * m_serial_handle; /**< Serial gateway handle */
|
||||
};
|
||||
} mbus_handle;
|
||||
|
||||
|
||||
/**
|
||||
* MBus slave address type (primary/secodary address)
|
||||
*/
|
||||
typedef struct _mbus_address {
|
||||
char is_primary; /**< Address type (non zero for primary) */
|
||||
union {
|
||||
int primary; /**< Primary address (for slaves shall be from 1 to 250) */
|
||||
char * secondary; /**< Secondary address (shall be 16 digits) */
|
||||
};
|
||||
} mbus_address;
|
||||
|
||||
|
||||
/**
|
||||
* _string type
|
||||
*
|
||||
* In general support binary strings (octet string, non zero terminated)
|
||||
* but so far almost all strings are zero terminated ("texts").
|
||||
*/
|
||||
typedef struct _mbus_string {
|
||||
char * value; /**< Buffer */
|
||||
int size; /**< _size */
|
||||
} mbus_string;
|
||||
|
||||
|
||||
/**
|
||||
* Quantity value type union
|
||||
*/
|
||||
typedef union _mbus_value {
|
||||
double real_val; /**< Numerical */
|
||||
mbus_string str_val; /**< Text/binary */
|
||||
} mbus_value;
|
||||
|
||||
|
||||
/**
|
||||
* Single measured quantity record type
|
||||
*/
|
||||
typedef struct _mbus_record {
|
||||
mbus_value value; /**< Quantity value */
|
||||
char is_numeric; /**< Quantity value type (nonzero is numeric) */
|
||||
char *unit; /**< Quantity unit (e.g. Wh) */
|
||||
char *function_medium; /**< Quantity medium or function (e.g. Electricity) */
|
||||
char *quantity; /**< Quantity type (e.g. Energy) */
|
||||
} mbus_record;
|
||||
|
||||
|
||||
/**
|
||||
* Connects to serial gateway and initializes MBus handle
|
||||
*
|
||||
* @param device Serial device (like /dev/ttyUSB0 or /dev/ttyS0)
|
||||
*
|
||||
* @return Initialized "unified" handler when successful, NULL otherwise;
|
||||
*/
|
||||
mbus_handle * mbus_connect_serial(const char * device);
|
||||
|
||||
/**
|
||||
* Connects to TCP gateway and initializes MBus handle
|
||||
*
|
||||
* @param host Gateway host
|
||||
* @param port Gateway port
|
||||
*
|
||||
* @return Initialized "unified" handler when successful, NULL otherwise;
|
||||
*/
|
||||
mbus_handle * mbus_connect_tcp(const char *host, int port);
|
||||
|
||||
/**
|
||||
* Disconnects the "unified" handle.
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_disconnect(mbus_handle * handle);
|
||||
|
||||
/**
|
||||
* Receives a frame using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param frame Received frame
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_recv_frame(mbus_handle * handle, mbus_frame *frame);
|
||||
|
||||
/**
|
||||
* Sends frame using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param frame Frame to send
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_frame(mbus_handle * handle, mbus_frame *frame);
|
||||
|
||||
/**
|
||||
* Sends secodary address selection frame using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param secondary_addr_str Secondary address
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_select_frame(mbus_handle * handle, const char *secondary_addr_str);
|
||||
|
||||
/**
|
||||
* Sends switch baudrate frame using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
* @param baudrate Baudrate (300,600,1200,2400,4800,9600,19200,38400)
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, int baudrate);
|
||||
|
||||
/**
|
||||
* Sends request frame to given slave using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_request_frame(mbus_handle * handle, int address);
|
||||
|
||||
/**
|
||||
* Sends a request and read replies until no more records available
|
||||
* or limit is reached.
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
* @param reply pointer to an mbus frame for the reply
|
||||
* @param max_frames limit of frames to readout (0 = no limit)
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int max_frames);
|
||||
|
||||
/**
|
||||
* Sends ping frame to given slave using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_ping_frame(mbus_handle *handle, int address);
|
||||
|
||||
/**
|
||||
* Probe/address slave by secondary address using "unified" handle
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param mask Address/mask to probe
|
||||
* @param matching_addr Matched address (the buffer has tobe at least 16 bytes)
|
||||
*
|
||||
* @return See MBUS_PROBE_* constants
|
||||
*/
|
||||
int mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *matching_addr);
|
||||
|
||||
/**
|
||||
* Read data from given slave using "unified" handle and address types
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address of the slave
|
||||
* @param reply Reply from the slave
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_read_slave(mbus_handle *handle, mbus_address *address, mbus_frame *reply);
|
||||
|
||||
|
||||
/**
|
||||
* Allocate new data record. Use #mbus_record_free when finished.
|
||||
*
|
||||
* @return pointer to the new record, NULL when failed
|
||||
*/
|
||||
mbus_record * mbus_record_new();
|
||||
|
||||
/**
|
||||
* Destructor for mbus_record
|
||||
*
|
||||
* @param rec record to be freed
|
||||
*/
|
||||
void mbus_record_free(mbus_record *rec);
|
||||
|
||||
|
||||
/**
|
||||
* Create/parse single counter from the fixed data structure
|
||||
*
|
||||
* @param statusByte status byte
|
||||
* @param medium_unit_byte medium/unit byte
|
||||
* @param data pointer to the data counter (4 bytes)
|
||||
*
|
||||
* @return Newly allocated record if succesful, NULL otherwise. Later on need to use #mbus_record_free
|
||||
*/
|
||||
mbus_record *mbus_parse_fixed_record(char statusByte, char medium_unit_byte, u_char *data);
|
||||
|
||||
|
||||
/**
|
||||
* Create/parse single counter from the variable data structure record
|
||||
*
|
||||
* @param data record data to be parsed
|
||||
*
|
||||
* @return Newly allocated record if succesful, NULL otherwise. Later on need to use #mbus_record_free
|
||||
*/
|
||||
mbus_record * mbus_parse_variable_record(mbus_data_record *record);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get normalized counter value for a fixed counter
|
||||
*
|
||||
* Get "normalized" value and unit of the counter
|
||||
*
|
||||
* @param medium_unit_byte medium/unit byte of the fixed counter
|
||||
* @param medium_value raw counter value
|
||||
* @param unit_out units of the counter - use free when done
|
||||
* @param value_out resulting counter value
|
||||
* @param quantity_out parsed quantity, when done use "free"
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_data_fixed_normalize(int medium_unit_byte, long medium_value, char **unit_out, double *value_out, char **quantity_out);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Decode value of a variable data structure
|
||||
*
|
||||
* @param record record to be decoded
|
||||
* @param value_out_real numerical counter value output (when numerical)
|
||||
* @param value_out_str string counter value output (when string, NULL otherwise), when finished use "free *value_out_str"
|
||||
* @param value_out_str_size string counter value size
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_data_variable_value_decode(mbus_record *record, double *value_out_real, char **value_out_str, int *value_out_str_size);
|
||||
|
||||
/**
|
||||
* Decode units and normalize value using VIF/VIFE (used internally by mbus_vib_unit_normalize)
|
||||
*
|
||||
* @param vif VIF (including standard extensions)
|
||||
* @param value already parsed "raw" numerical value
|
||||
* @param unit_out parsed unit, when done use "free"
|
||||
* @param value_out normalized value
|
||||
* @param quantity_out parsed quantity, when done use "free"
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_vif_unit_normalize(int vif, double value, char **unit_out, double *value_out, char **quantity_out);
|
||||
|
||||
/**
|
||||
* Decode units and normalize value from VIB
|
||||
*
|
||||
* @param vib mbus value information block of the variable record
|
||||
* @param value already parsed "raw" numerical value
|
||||
* @param unit_out parsed unit, when done use "free"
|
||||
* @param value_out normalized value
|
||||
* @param quantity_out parsed quantity, when done use "free"
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_vib_unit_normalize(mbus_value_information_block *vib, double value, char **unit_out, double *value_out, char ** quantity_out);
|
||||
|
||||
/**
|
||||
* Iterate over secondary addresses, send a probe package to all addresses matching
|
||||
* the given addresses mask.
|
||||
*
|
||||
* @param pos current address
|
||||
* @param addr_mask address mask to
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask);
|
||||
|
||||
#endif // __MBUS_PROTOCOL_AUX_H__
|
3221
mbus/mbus-protocol.c
Normal file
3221
mbus/mbus-protocol.c
Normal file
File diff suppressed because it is too large
Load Diff
548
mbus/mbus-protocol.h
Normal file
548
mbus/mbus-protocol.h
Normal file
@ -0,0 +1,548 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2010-2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @file mbus-protocol.h
|
||||
*
|
||||
* @brief Functions and data structures for M-Bus protocol parsing.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _MBUS_PROTOCOL_H_
|
||||
#define _MBUS_PROTOCOL_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
//
|
||||
// Packet formats:
|
||||
//
|
||||
// ACK: size = 1 byte
|
||||
//
|
||||
// byte1: ack = 0xE5
|
||||
//
|
||||
// SHORT: size = 5 byte
|
||||
//
|
||||
// byte1: start = 0x10
|
||||
// byte2: control = ...
|
||||
// byte3: address = ...
|
||||
// byte4: chksum = ...
|
||||
// byte5: stop = 0x16
|
||||
//
|
||||
// CONTROL: size = 9 byte
|
||||
//
|
||||
// byte1: start1 = 0x68
|
||||
// byte2: length1 = ...
|
||||
// byte3: length2 = ...
|
||||
// byte4: start2 = 0x68
|
||||
// byte5: control = ...
|
||||
// byte6: address = ...
|
||||
// byte7: ctl.info= ...
|
||||
// byte8: chksum = ...
|
||||
// byte9: stop = 0x16
|
||||
//
|
||||
// LONG: size = N >= 9 byte
|
||||
//
|
||||
// byte1: start1 = 0x68
|
||||
// byte2: length1 = ...
|
||||
// byte3: length2 = ...
|
||||
// byte4: start2 = 0x68
|
||||
// byte5: control = ...
|
||||
// byte6: address = ...
|
||||
// byte7: ctl.info= ...
|
||||
// byte8: data = ...
|
||||
// ... = ...
|
||||
// byteN-1: chksum = ...
|
||||
// byteN: stop = 0x16
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
typedef struct _mbus_frame {
|
||||
|
||||
u_char start1;
|
||||
u_char length1;
|
||||
u_char length2;
|
||||
u_char start2;
|
||||
u_char control;
|
||||
u_char address;
|
||||
u_char control_information;
|
||||
// variable data field
|
||||
u_char checksum;
|
||||
u_char stop;
|
||||
|
||||
u_char data[252];
|
||||
size_t data_size;
|
||||
|
||||
int type;
|
||||
|
||||
//mbus_frame_data frame_data;
|
||||
|
||||
void *next; // pointer to next mbus_frame for multi-telegram replies
|
||||
|
||||
} mbus_frame;
|
||||
|
||||
typedef struct _mbus_slave_data {
|
||||
|
||||
int state_fcb;
|
||||
int state_acd;
|
||||
|
||||
} mbus_slave_data;
|
||||
|
||||
#define NITEMS(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MBUS FRAME DATA FORMATS
|
||||
//
|
||||
|
||||
// DATA RECORDS
|
||||
#define MBUS_DIB_DIF_EXTENSION_BIT 0x80
|
||||
#define MBUS_DIB_VIF_EXTENSION_BIT 0x80
|
||||
|
||||
typedef struct _mbus_data_information_block {
|
||||
|
||||
u_char dif;
|
||||
u_char dife[10];
|
||||
size_t ndife;
|
||||
|
||||
} mbus_data_information_block;
|
||||
|
||||
typedef struct _mbus_value_information_block {
|
||||
|
||||
u_char vif;
|
||||
u_char vife[10];
|
||||
size_t nvife;
|
||||
|
||||
u_char custom_vif[128];
|
||||
|
||||
} mbus_value_information_block;
|
||||
|
||||
typedef struct _mbus_data_record_header {
|
||||
|
||||
mbus_data_information_block dib;
|
||||
mbus_value_information_block vib;
|
||||
|
||||
} mbus_data_record_header;
|
||||
|
||||
typedef struct _mbus_data_record {
|
||||
|
||||
mbus_data_record_header drh;
|
||||
|
||||
u_char data[234];
|
||||
size_t data_len;
|
||||
|
||||
void *next;
|
||||
|
||||
} mbus_data_record;
|
||||
|
||||
//
|
||||
// HEADER FOR VARIABLE LENGTH DATA FORMAT
|
||||
//
|
||||
typedef struct _mbus_data_variable_header {
|
||||
|
||||
//Ident.Nr. Manufr. Version Medium Access No. Status Signature
|
||||
//4 Byte 2 Byte 1 Byte 1 Byte 1 Byte 1 Byte 2 Byte
|
||||
|
||||
// ex
|
||||
// 88 63 80 09 82 4D 02 04 15 00 00 00
|
||||
|
||||
u_char id_bcd[4]; // 88 63 80 09
|
||||
u_char manufacturer[2]; // 82 4D
|
||||
u_char version; // 02
|
||||
u_char medium; // 04
|
||||
u_char access_no; // 15
|
||||
u_char status; // 00
|
||||
u_char signature[2]; // 00 00
|
||||
|
||||
} mbus_data_variable_header;
|
||||
|
||||
//
|
||||
// VARIABLE LENGTH DATA FORMAT
|
||||
//
|
||||
typedef struct _mbus_data_variable {
|
||||
|
||||
mbus_data_variable_header header;
|
||||
|
||||
mbus_data_record *record;
|
||||
size_t nrecords;
|
||||
|
||||
u_char *data;
|
||||
size_t data_len;
|
||||
|
||||
u_char more_records_follow;
|
||||
|
||||
// are these needed/used?
|
||||
u_char mdh;
|
||||
u_char *mfg_data;
|
||||
size_t mfg_data_len;
|
||||
|
||||
} mbus_data_variable;
|
||||
|
||||
//
|
||||
// FIXED LENGTH DATA FORMAT
|
||||
//
|
||||
typedef struct _mbus_data_fixed {
|
||||
|
||||
// ex
|
||||
// 35 01 00 00 counter 2 = 135 l (historic value)
|
||||
//
|
||||
// e.g.
|
||||
//
|
||||
// 78 56 34 12 identification number = 12345678
|
||||
// 0A transmission counter = 0Ah = 10d
|
||||
// 00 status 00h: counters coded BCD, actual values, no errors
|
||||
// E9 7E Type&Unit: medium water, unit1 = 1l, unit2 = 1l (same, but historic)
|
||||
// 01 00 00 00 counter 1 = 1l (actual value)
|
||||
// 35 01 00 00 counter 2 = 135 l (historic value)
|
||||
|
||||
u_char id_bcd[4];
|
||||
u_char tx_cnt;
|
||||
u_char status;
|
||||
u_char cnt1_type;
|
||||
u_char cnt2_type;
|
||||
u_char cnt1_val[4];
|
||||
u_char cnt2_val[4];
|
||||
|
||||
} mbus_data_fixed;
|
||||
|
||||
//
|
||||
// ABSTRACT DATA FORMAT (either fixed or variable length)
|
||||
//
|
||||
#define MBUS_DATA_TYPE_FIXED 1
|
||||
#define MBUS_DATA_TYPE_VARIABLE 2
|
||||
typedef struct _mbus_frame_data {
|
||||
|
||||
mbus_data_variable data_var;
|
||||
mbus_data_fixed data_fix;
|
||||
|
||||
int type;
|
||||
|
||||
} mbus_frame_data;
|
||||
|
||||
//
|
||||
// HEADER FOR SECONDARY ADDRESSING
|
||||
//
|
||||
typedef struct _mbus_data_secondary_address {
|
||||
|
||||
//Ident.Nr. Manufr. Version Medium
|
||||
//4 Byte 2 Byte 1 Byte 1 Byte
|
||||
|
||||
// ex
|
||||
// 14 49 10 01 10 57 01 06
|
||||
|
||||
u_char id_bcd[4]; // 14 49 10 01
|
||||
u_char manufacturer[2]; // 10 57
|
||||
u_char version; // 01
|
||||
u_char medium; // 06
|
||||
|
||||
} mbus_data_secondary_address;
|
||||
|
||||
|
||||
//
|
||||
// for compatibility with non-gcc compilers:
|
||||
//
|
||||
//#ifndef __PRETTY_FUNCTION__
|
||||
//#define __PRETTY_FUNCTION__ "libmbus"
|
||||
//#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// FRAME types
|
||||
//
|
||||
#define MBUS_FRAME_TYPE_ANY 0x00
|
||||
#define MBUS_FRAME_TYPE_ACK 0x01
|
||||
#define MBUS_FRAME_TYPE_SHORT 0x02
|
||||
#define MBUS_FRAME_TYPE_CONTROL 0x03
|
||||
#define MBUS_FRAME_TYPE_LONG 0x04
|
||||
|
||||
#define MBUS_FRAME_ACK_BASE_SIZE 1
|
||||
#define MBUS_FRAME_SHORT_BASE_SIZE 5
|
||||
#define MBUS_FRAME_CONTROL_BASE_SIZE 9
|
||||
#define MBUS_FRAME_LONG_BASE_SIZE 9
|
||||
|
||||
#define MBUS_FRAME_BASE_SIZE_ACK 1
|
||||
#define MBUS_FRAME_BASE_SIZE_SHORT 5
|
||||
#define MBUS_FRAME_BASE_SIZE_CONTROL 9
|
||||
#define MBUS_FRAME_BASE_SIZE_LONG 9
|
||||
|
||||
#define MBUS_FRAME_FIXED_SIZE_ACK 1
|
||||
#define MBUS_FRAME_FIXED_SIZE_SHORT 5
|
||||
#define MBUS_FRAME_FIXED_SIZE_CONTROL 6
|
||||
#define MBUS_FRAME_FIXED_SIZE_LONG 6
|
||||
|
||||
//
|
||||
// Frame start/stop bits
|
||||
//
|
||||
#define MBUS_FRAME_ACK_START 0xE5
|
||||
#define MBUS_FRAME_SHORT_START 0x10
|
||||
#define MBUS_FRAME_CONTROL_START 0x68
|
||||
#define MBUS_FRAME_LONG_START 0x68
|
||||
#define MBUS_FRAME_STOP 0x16
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
#define MBUS_MAX_PRIMARY_SLAVES 256
|
||||
|
||||
//
|
||||
// Control field
|
||||
//
|
||||
#define MBUS_CONTROL_FIELD_DIRECTION 0x07
|
||||
#define MBUS_CONTROL_FIELD_FCB 0x06
|
||||
#define MBUS_CONTROL_FIELD_ACD 0x06
|
||||
#define MBUS_CONTROL_FIELD_FCV 0x05
|
||||
#define MBUS_CONTROL_FIELD_DFC 0x05
|
||||
#define MBUS_CONTROL_FIELD_F3 0x04
|
||||
#define MBUS_CONTROL_FIELD_F2 0x03
|
||||
#define MBUS_CONTROL_FIELD_F1 0x02
|
||||
#define MBUS_CONTROL_FIELD_F0 0x01
|
||||
|
||||
#define MBUS_CONTROL_MASK_SND_NKE 0x40
|
||||
#define MBUS_CONTROL_MASK_SND_UD 0x53
|
||||
#define MBUS_CONTROL_MASK_REQ_UD2 0x5B
|
||||
#define MBUS_CONTROL_MASK_REQ_UD1 0x5A
|
||||
#define MBUS_CONTROL_MASK_RSP_UD 0x08
|
||||
|
||||
#define MBUS_CONTROL_MASK_FCB 0x20
|
||||
#define MBUS_CONTROL_MASK_FCV 0x10
|
||||
|
||||
#define MBUS_CONTROL_MASK_ACD 0x20
|
||||
#define MBUS_CONTROL_MASK_DFC 0x10
|
||||
|
||||
#define MBUS_CONTROL_MASK_DIR 0x40
|
||||
#define MBUS_CONTROL_MASK_DIR_M2S 0x40
|
||||
#define MBUS_CONTROL_MASK_DIR_S2M 0x00
|
||||
|
||||
//
|
||||
// Address field
|
||||
//
|
||||
#define MBUS_ADDRESS_BROADCAST_REPLY 0xFE
|
||||
#define MBUS_ADDRESS_BROADCAST_NOREPLY 0xFF
|
||||
#define MBUS_ADDRESS_NETWORK_LAYER 0xFD
|
||||
|
||||
//
|
||||
// Control Information field
|
||||
//
|
||||
//Mode 1 Mode 2 Application Definition in
|
||||
// 51h 55h data send EN1434-3
|
||||
// 52h 56h selection of slaves Usergroup July ́93
|
||||
// 50h application reset Usergroup March ́94
|
||||
// 54h synronize action suggestion
|
||||
// B8h set baudrate to 300 baud Usergroup July ́93
|
||||
// B9h set baudrate to 600 baud Usergroup July ́93
|
||||
// BAh set baudrate to 1200 baud Usergroup July ́93
|
||||
// BBh set baudrate to 2400 baud Usergroup July ́93
|
||||
// BCh set baudrate to 4800 baud Usergroup July ́93
|
||||
// BDh set baudrate to 9600 baud Usergroup July ́93
|
||||
// BEh set baudrate to 19200 baud suggestion
|
||||
// BFh set baudrate to 38400 baud suggestion
|
||||
// B1h request readout of complete RAM content Techem suggestion
|
||||
// B2h send user data (not standardized RAM write) Techem suggestion
|
||||
// B3h initialize test calibration mode Usergroup July ́93
|
||||
// B4h EEPROM read Techem suggestion
|
||||
// B6h start software test Techem suggestion
|
||||
// 90h to 97h codes used for hashing longer recommended
|
||||
|
||||
#define MBUS_CONTROL_INFO_DATA_SEND 0x51
|
||||
#define MBUS_CONTROL_INFO_DATA_SEND_MSB 0x55
|
||||
#define MBUS_CONTROL_INFO_SELECT_SLAVE 0x52
|
||||
#define MBUS_CONTROL_INFO_SELECT_SLAVE_MSB 0x56
|
||||
#define MBUS_CONTROL_INFO_APPLICATION_RESET 0x50
|
||||
#define MBUS_CONTROL_INFO_SYNC_ACTION 0x54
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_300 0xB8
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_600 0xB9
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_1200 0xBA
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_2400 0xBB
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_4800 0xBC
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_9600 0xBD
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_19200 0xBE
|
||||
#define MBUS_CONTROL_INFO_SET_BAUDRATE_38400 0xBF
|
||||
#define MBUS_CONTROL_INFO_REQUEST_RAM_READ 0xB1
|
||||
#define MBUS_CONTROL_INFO_SEND_USER_DATA 0xB2
|
||||
#define MBUS_CONTROL_INFO_INIT_TEST_CALIB 0xB3
|
||||
#define MBUS_CONTROL_INFO_EEPROM_READ 0xB4
|
||||
#define MBUS_CONTROL_INFO_SW_TEST_START 0xB6
|
||||
|
||||
#define MBUS_CONTROL_INFO_RESP_FIXED 0x73
|
||||
#define MBUS_CONTROL_INFO_RESP_FIXED_MSB 0x77
|
||||
|
||||
#define MBUS_CONTROL_INFO_RESP_VARIABLE 0x72
|
||||
#define MBUS_CONTROL_INFO_RESP_VARIABLE_MSB 0x76
|
||||
|
||||
//
|
||||
// DATA BITS
|
||||
//
|
||||
#define MBUS_DATA_FIXED_STATUS_FORMAT_MASK 0x80
|
||||
#define MBUS_DATA_FIXED_STATUS_FORMAT_BCD 0x00
|
||||
#define MBUS_DATA_FIXED_STATUS_FORMAT_INT 0x80
|
||||
#define MBUS_DATA_FIXED_STATUS_DATE_MASK 0x40
|
||||
#define MBUS_DATA_FIXED_STATUS_DATE_STORED 0x40
|
||||
#define MBUS_DATA_FIXED_STATUS_DATE_CURRENT 0x00
|
||||
|
||||
|
||||
//
|
||||
// data record fields
|
||||
//
|
||||
#define MBUS_DATA_RECORD_DIF_MASK_INST 0x00
|
||||
#define MBUS_DATA_RECORD_DIF_MASK_MIN 0x10
|
||||
|
||||
#define MBUS_DATA_RECORD_DIF_MASK_TYPE_INT32 0x04
|
||||
#define MBUS_DATA_RECORD_DIF_MASK_STORAGE_NO 0x40
|
||||
#define MBUS_DATA_RECORD_DIF_MASK_EXTENTION 0x80
|
||||
|
||||
|
||||
//
|
||||
// FIXED DATA FLAGS
|
||||
//
|
||||
|
||||
//
|
||||
// VARIABLE DATA FLAGS
|
||||
//
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_OTHER 0x00
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_OIL 0x01
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_ELECTRICITY 0x02
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_GAS 0x03
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT_OUT 0x04
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_STEAM 0x05
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_HOT_WATER 0x06
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_WATER 0x07
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT_COST 0x08
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_COMPR_AIR 0x09
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_COOL_OUT 0x0A
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_COOL_IN 0x0B
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT_IN 0x0C
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT_COOL 0x0D
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_BUS 0x0E
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_UNKNOWN 0x0F
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_COLD_WATER 0x16
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_DUAL_WATER 0x17
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_PRESSURE 0x18
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_ADC 0x19
|
||||
|
||||
|
||||
//
|
||||
// variable length records
|
||||
//
|
||||
mbus_data_record *mbus_data_record_new();
|
||||
void mbus_data_record_free(mbus_data_record *record);
|
||||
void mbus_data_record_append(mbus_data_variable *data, mbus_data_record *record);
|
||||
|
||||
|
||||
// XXX: Add application reset subcodes
|
||||
|
||||
mbus_frame *mbus_frame_new(int frame_type);
|
||||
int mbus_frame_free(mbus_frame *frame);
|
||||
|
||||
mbus_frame_data *mbus_frame_data_new();
|
||||
void mbus_frame_data_free(mbus_frame_data *data);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
int mbus_frame_calc_checksum(mbus_frame *frame);
|
||||
int mbus_frame_calc_length (mbus_frame *frame);
|
||||
|
||||
//
|
||||
// Parse/Pack to bin
|
||||
//
|
||||
int mbus_parse(mbus_frame *frame, u_char *data, size_t data_size);
|
||||
|
||||
int mbus_data_fixed_parse (mbus_frame *frame, mbus_data_fixed *data);
|
||||
int mbus_data_variable_parse(mbus_frame *frame, mbus_data_variable *data);
|
||||
|
||||
int mbus_frame_data_parse (mbus_frame *frame, mbus_frame_data *data);
|
||||
|
||||
int mbus_frame_pack(mbus_frame *frame, u_char *data, size_t data_size);
|
||||
|
||||
int mbus_frame_verify(mbus_frame *frame);
|
||||
|
||||
int mbus_frame_internal_pack(mbus_frame *frame, mbus_frame_data *frame_data);
|
||||
|
||||
//
|
||||
// data parsing
|
||||
//
|
||||
const char *mbus_data_record_function(mbus_data_record *record);
|
||||
const char *mbus_data_fixed_function(int status);
|
||||
|
||||
//
|
||||
// M-Bus frame data struct access/write functions
|
||||
//
|
||||
int mbus_frame_type(mbus_frame *frame);
|
||||
|
||||
//
|
||||
// Slave status data register.
|
||||
//
|
||||
mbus_slave_data *mbus_slave_data_get(size_t i);
|
||||
|
||||
//
|
||||
// XML generating functions
|
||||
//
|
||||
void mbus_str_xml_encode(u_char *dst, const u_char *src, size_t max_len);
|
||||
char *mbus_data_xml(mbus_frame_data *data);
|
||||
char *mbus_data_variable_xml(mbus_data_variable *data);
|
||||
char *mbus_data_fixed_xml(mbus_data_fixed *data);
|
||||
char *mbus_frame_data_xml(mbus_frame_data *data);
|
||||
|
||||
char *mbus_data_variable_header_xml(mbus_data_variable_header *header);
|
||||
|
||||
|
||||
//
|
||||
// Debug/dump
|
||||
//
|
||||
int mbus_frame_print(mbus_frame *frame);
|
||||
int mbus_frame_data_print(mbus_frame_data *data);
|
||||
int mbus_data_fixed_print(mbus_data_fixed *data);
|
||||
int mbus_data_variable_header_print(mbus_data_variable_header *header);
|
||||
int mbus_data_variable_print(mbus_data_variable *data);
|
||||
|
||||
char *mbus_error_str();
|
||||
void mbus_error_str_set(char *message);
|
||||
void mbus_error_reset();
|
||||
|
||||
void mbus_parse_set_debug(int debug);
|
||||
|
||||
//
|
||||
// data encode/decode functions
|
||||
//
|
||||
int mbus_data_manufacturer_encode(u_char *m_data, u_char *m_code);
|
||||
const char *mbus_decode_manufacturer(u_char byte1, u_char byte2);
|
||||
|
||||
int mbus_data_bcd_encode(u_char *bcd_data, size_t bcd_data_size, int value);
|
||||
int mbus_data_int_encode(u_char *int_data, size_t int_data_size, int value);
|
||||
|
||||
long long mbus_data_bcd_decode(u_char *bcd_data, size_t bcd_data_size);
|
||||
int mbus_data_int_decode(u_char *int_data, size_t int_data_size);
|
||||
long mbus_data_long_decode(u_char *int_data, size_t int_data_size);
|
||||
long long mbus_data_long_long_decode(u_char *int_data, size_t int_data_size);
|
||||
|
||||
float mbus_data_float_decode(u_char *float_data);
|
||||
|
||||
void mbus_data_tm_decode(struct tm *t, u_char *t_data, size_t t_data_size);
|
||||
|
||||
void mbus_data_str_decode(u_char *dst, const u_char *src, size_t len);
|
||||
|
||||
void mbus_data_bin_decode(u_char *dst, const u_char *src, size_t len, size_t max_len);
|
||||
|
||||
const char *mbus_data_fixed_medium(mbus_data_fixed *data);
|
||||
const char *mbus_data_fixed_unit(int medium_unit_byte);
|
||||
const char *mbus_data_variable_medium_lookup(u_char medium);
|
||||
const char *mbus_unit_prefix(int exp);
|
||||
|
||||
|
||||
const char *mbus_vib_unit_lookup(mbus_value_information_block *vib);
|
||||
const char *mbus_vif_unit_lookup(u_char vif);
|
||||
|
||||
u_char mbus_dif_datalength_lookup(u_char dif);
|
||||
|
||||
char *mbus_frame_get_secondary_address(mbus_frame *frame);
|
||||
int mbus_frame_select_secondary_pack(mbus_frame *frame, char *address);
|
||||
|
||||
#endif /* _MBUS_PROTOCOL_H_ */
|
||||
|
229
mbus/mbus-serial.c
Normal file
229
mbus/mbus-serial.c
Normal file
@ -0,0 +1,229 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mbus/mbus.h>
|
||||
#include <mbus/mbus-serial.h>
|
||||
|
||||
#define PACKET_BUFF_SIZE 2048
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Set up a serial connection handle.
|
||||
//------------------------------------------------------------------------------
|
||||
mbus_serial_handle *
|
||||
mbus_serial_connect(char *device)
|
||||
{
|
||||
mbus_serial_handle *handle;
|
||||
|
||||
if (device == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((handle = (mbus_serial_handle *)malloc(sizeof(mbus_serial_handle))) == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: failed to allocate memory for handle\n", __PRETTY_FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->device = device; // strdup?
|
||||
|
||||
//
|
||||
// create the SERIAL connection
|
||||
//
|
||||
|
||||
// Use blocking read and handle it by serial port VMIN/VTIME setting
|
||||
if ((handle->fd = open(handle->device, O_RDWR | O_NOCTTY)) < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: failed to open tty.", __PRETTY_FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bzero(&(handle->t), sizeof(handle->t));
|
||||
handle->t.c_cflag |= (CS8|CREAD|CLOCAL);
|
||||
handle->t.c_cflag |= PARENB;
|
||||
|
||||
// No received data still OK
|
||||
handle->t.c_cc[VMIN] = 0;
|
||||
|
||||
// Wait at most 0.2 sec.Note that it starts after first received byte!!
|
||||
// I.e. if CMIN>0 and there are no data we would still wait forever...
|
||||
//
|
||||
// The specification mentions link layer response timeout this way:
|
||||
// The time structure of various link layer communication types is described in EN60870-5-1. The answer time
|
||||
// between the end of a master send telegram and the beginning of the response telegram of the slave shall be
|
||||
// between 11 bit times and (330 bit times + 50ms).
|
||||
//
|
||||
// For 2400Bd this means (330 + 11) / 2400 + 0.05 = 188.75 ms (added 11 bit periods to receive first byte).
|
||||
// I.e. timeout of 0.2s seems appropriate for 2400Bd.
|
||||
|
||||
handle->t.c_cc[VTIME] = 2;
|
||||
|
||||
cfsetispeed(&(handle->t), B2400);
|
||||
cfsetospeed(&(handle->t), B2400);
|
||||
|
||||
#ifdef MBUS_SERIAL_DEBUG
|
||||
printf("%s: t.c_cflag = %x\n", __PRETTY_FUNCTION__, handle->t.c_cflag);
|
||||
printf("%s: t.c_oflag = %x\n", __PRETTY_FUNCTION__, handle->t.c_oflag);
|
||||
printf("%s: t.c_iflag = %x\n", __PRETTY_FUNCTION__, handle->t.c_iflag);
|
||||
printf("%s: t.c_lflag = %x\n", __PRETTY_FUNCTION__, handle->t.c_lflag);
|
||||
#endif
|
||||
|
||||
tcsetattr(handle->fd, TCSANOW, &(handle->t));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_serial_set_baudrate(mbus_serial_handle *handle, int baudrate)
|
||||
{
|
||||
if (handle == NULL)
|
||||
return -1;
|
||||
|
||||
switch (baudrate)
|
||||
{
|
||||
case 300:
|
||||
cfsetispeed(&(handle->t), B300);
|
||||
cfsetospeed(&(handle->t), B300);
|
||||
return 0;
|
||||
|
||||
case 1200:
|
||||
cfsetispeed(&(handle->t), B1200);
|
||||
cfsetospeed(&(handle->t), B1200);
|
||||
return 0;
|
||||
|
||||
case 2400:
|
||||
cfsetispeed(&(handle->t), B2400);
|
||||
cfsetospeed(&(handle->t), B2400);
|
||||
return 0;
|
||||
|
||||
case 9600:
|
||||
cfsetispeed(&(handle->t), B9600);
|
||||
cfsetospeed(&(handle->t), B9600);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return -1; // unsupported baudrate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_serial_disconnect(mbus_serial_handle *handle)
|
||||
{
|
||||
if (handle == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(handle->fd);
|
||||
|
||||
free(handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_serial_send_frame(mbus_serial_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
u_char buff[PACKET_BUFF_SIZE];
|
||||
int len, ret;
|
||||
|
||||
if (handle == NULL || frame == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = mbus_frame_pack(frame, buff, sizeof(buff))) == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: mbus_frame_pack failed\n", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ret = write(handle->fd, buff, len)) != len)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to write frame to socket (ret = %d: %s)\n", __PRETTY_FUNCTION__, ret, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_serial_recv_frame(mbus_serial_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
char buff[PACKET_BUFF_SIZE];
|
||||
int len, remaining, nread;
|
||||
|
||||
bzero((void *)buff, sizeof(buff));
|
||||
|
||||
//
|
||||
// read data until a packet is received
|
||||
//
|
||||
remaining = 1; // start by reading 1 byte
|
||||
len = 0;
|
||||
|
||||
do {
|
||||
//printf("%s: Attempt to read %d bytes [len = %d]\n", __PRETTY_FUNCTION__, remaining, len);
|
||||
|
||||
if ((nread = read(handle->fd, &buff[len], remaining)) == -1)
|
||||
{
|
||||
// fprintf(stderr, "%s: aborting recv frame (remaining = %d, len = %d, nread = %d)\n",
|
||||
// __PRETTY_FUNCTION__, remaining, len, nread);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// printf("%s: Got %d byte [remaining %d, len %d]\n", __PRETTY_FUNCTION__, nread, remaining, len);
|
||||
|
||||
len += nread;
|
||||
|
||||
} while ((remaining = mbus_parse(frame, buff, len)) > 0);
|
||||
|
||||
if(remaining < 0)
|
||||
{
|
||||
// Would be OK when e.g. scanning the bus, otherwise it is a failure.
|
||||
// printf("%s: M-Bus layer failed to receive complete data.\n", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: M-Bus layer failed to parse data.\n", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
42
mbus/mbus-serial.h
Normal file
42
mbus/mbus-serial.h
Normal file
@ -0,0 +1,42 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @file mbus-serial.h
|
||||
*
|
||||
* @brief Functions and data structures for sending M-Bus data via RS232.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MBUS_SERIAL_H
|
||||
#define MBUS_SERIAL_H
|
||||
|
||||
#include <termios.h>
|
||||
#include <mbus/mbus.h>
|
||||
|
||||
typedef struct _mbus_serial_handle {
|
||||
|
||||
char *device;
|
||||
|
||||
int fd;
|
||||
struct termios t;
|
||||
|
||||
} mbus_serial_handle;
|
||||
|
||||
|
||||
mbus_serial_handle *mbus_serial_connect(char *device);
|
||||
int mbus_serial_disconnect(mbus_serial_handle *handle);
|
||||
int mbus_serial_send_frame(mbus_serial_handle *handle, mbus_frame *frame);
|
||||
int mbus_serial_recv_frame(mbus_serial_handle *handle, mbus_frame *frame);
|
||||
int mbus_serial_set_baudrate(mbus_serial_handle *handle, int baudrate);
|
||||
#endif /* MBUS_SERIAL_H */
|
||||
|
||||
|
||||
|
189
mbus/mbus-tcp.c
Normal file
189
mbus/mbus-tcp.c
Normal file
@ -0,0 +1,189 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include <mbus/mbus.h>
|
||||
#include <mbus/mbus-tcp.h>
|
||||
|
||||
#define PACKET_BUFF_SIZE 2048
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Setup a TCP/IP handle.
|
||||
//------------------------------------------------------------------------------
|
||||
mbus_tcp_handle *
|
||||
mbus_tcp_connect(char *host, int port)
|
||||
{
|
||||
mbus_tcp_handle *handle;
|
||||
|
||||
struct hostent *host_addr;
|
||||
struct sockaddr_in s;
|
||||
struct timeval time_out;
|
||||
|
||||
if (host == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((handle = (mbus_tcp_handle *)malloc(sizeof(mbus_tcp_handle))) == NULL)
|
||||
{
|
||||
char error_str[128];
|
||||
snprintf(error_str, sizeof(error_str), "%s: failed to allocate memory for handle\n", __PRETTY_FUNCTION__);
|
||||
mbus_error_str_set(error_str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->host = host; // strdup ?
|
||||
handle->port = port;
|
||||
|
||||
//
|
||||
// create the TCP connection
|
||||
//
|
||||
if ((handle->sock = socket(AF_INET,SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
char error_str[128];
|
||||
snprintf(error_str, sizeof(error_str), "%s: failed to setup a socket.", __PRETTY_FUNCTION__);
|
||||
mbus_error_str_set(error_str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s.sin_family = AF_INET;
|
||||
s.sin_port = htons(port);
|
||||
|
||||
/* resolve hostname */
|
||||
if ((host_addr = gethostbyname(host)) == NULL)
|
||||
{
|
||||
char error_str[128];
|
||||
snprintf(error_str, sizeof(error_str), "%s: unknown host: %s", __PRETTY_FUNCTION__, host);
|
||||
mbus_error_str_set(error_str);
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bcopy((void *)(host_addr->h_addr), (void *)(&s.sin_addr), host_addr->h_length);
|
||||
|
||||
if (connect(handle->sock, (struct sockaddr *)&s, sizeof(s)) < 0)
|
||||
{
|
||||
char error_str[128];
|
||||
snprintf(error_str, sizeof(error_str), "%s: Failed to establish connection to %s:%d", __PRETTY_FUNCTION__, host, port);
|
||||
mbus_error_str_set(error_str);
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Set a timeout
|
||||
time_out.tv_sec = 4; //seconds
|
||||
time_out.tv_usec = 0;
|
||||
setsockopt(handle->sock, SOL_SOCKET, SO_SNDTIMEO, &time_out, sizeof(time_out));
|
||||
setsockopt(handle->sock, SOL_SOCKET, SO_RCVTIMEO, &time_out, sizeof(time_out));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_tcp_disconnect(mbus_tcp_handle *handle)
|
||||
{
|
||||
if (handle == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(handle->sock);
|
||||
|
||||
free(handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_tcp_send_frame(mbus_tcp_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
u_char buff[PACKET_BUFF_SIZE];
|
||||
int len, ret;
|
||||
|
||||
if (handle == NULL || frame == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = mbus_frame_pack(frame, buff, sizeof(buff))) == -1)
|
||||
{
|
||||
char error_str[128];
|
||||
snprintf(error_str, sizeof(error_str), "%s: mbus_frame_pack failed\n", __PRETTY_FUNCTION__);
|
||||
mbus_error_str_set(error_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ret = write(handle->sock, buff, len)) != len)
|
||||
{
|
||||
char error_str[128];
|
||||
snprintf(error_str, sizeof(error_str), "%s: Failed to write frame to socket (ret = %d)\n", __PRETTY_FUNCTION__, ret);
|
||||
mbus_error_str_set(error_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
mbus_tcp_recv_frame(mbus_tcp_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
char buff[PACKET_BUFF_SIZE];
|
||||
int len, remaining, nread;
|
||||
|
||||
bzero((void *)buff, sizeof(buff));
|
||||
|
||||
//
|
||||
// read data until a packet is received
|
||||
//
|
||||
remaining = 1; // start by reading 1 byte
|
||||
len = 0;
|
||||
|
||||
do {
|
||||
|
||||
if ((nread = read(handle->sock, &buff[len], remaining)) == -1)
|
||||
{
|
||||
mbus_error_str_set("M-Bus tcp transport layer failed to read data.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
len += nread;
|
||||
|
||||
} while ((remaining = mbus_parse(frame, buff, len)) > 0);
|
||||
|
||||
if (remaining < 0)
|
||||
{
|
||||
mbus_error_str_set("M-Bus layer failed to parse data.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
41
mbus/mbus-tcp.h
Normal file
41
mbus/mbus-tcp.h
Normal file
@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @file mbus-tcp.h
|
||||
*
|
||||
* @brief Functions and data structures for sending M-Bus data via TCP.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MBUS_TCP_H
|
||||
#define MBUS_TCP_H
|
||||
|
||||
#include <mbus/mbus.h>
|
||||
|
||||
typedef struct _mbus_tcp_handle {
|
||||
|
||||
char *host;
|
||||
|
||||
int port;
|
||||
int sock;
|
||||
|
||||
} mbus_tcp_handle;
|
||||
|
||||
|
||||
mbus_tcp_handle *mbus_tcp_connect(char *host, int port);
|
||||
int mbus_tcp_disconnect(mbus_tcp_handle *handle);
|
||||
int mbus_tcp_send_frame(mbus_tcp_handle *handle, mbus_frame *frame);
|
||||
int mbus_tcp_recv_frame(mbus_tcp_handle *handle, mbus_frame *frame);
|
||||
|
||||
#endif /* MBUS_TCP_H */
|
||||
|
||||
|
||||
|
17
mbus/mbus.c
Normal file
17
mbus/mbus.c
Normal file
@ -0,0 +1,17 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2010, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
int mbus_init() {return 0;}
|
||||
|
46
mbus/mbus.h
Normal file
46
mbus/mbus.h
Normal file
@ -0,0 +1,46 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (C) 2010, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @file mbus.h
|
||||
*
|
||||
* @brief Main include file for the Freescada libmbus library.
|
||||
*
|
||||
* Include this file to access the libmbus API:
|
||||
\verbatim
|
||||
#include <mbus/mbus.h>
|
||||
\endverbatim
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \mainpage libmbus
|
||||
*
|
||||
* These pages contain automatically generated documentation for the libmbus
|
||||
* API. For examples on how to use the libmbus library, see the applications
|
||||
* in the bin directory in the source code distribution.
|
||||
*
|
||||
* For more information, see http://www.rscada.se/libmbus
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _MBUS_H_
|
||||
#define _MBUS_H_
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
#include <mbus/mbus-protocol-aux.h>
|
||||
#include <mbus/mbus-tcp.h>
|
||||
#include <mbus/mbus-serial.h>
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
int mbus_init();
|
||||
|
||||
#endif /* _MBUS_H_ */
|
Reference in New Issue
Block a user