diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..caa4fdd8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/_build +/build diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml new file mode 100644 index 00000000..3e040975 --- /dev/null +++ b/.github/workflows/ccpp.yml @@ -0,0 +1,37 @@ +name: CMake + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: build examples and tests + run: sudo apt-get install -y clang-tidy-9 && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + + - name: generate test frames + run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex + + - name: install and run gcovr + run: sudo pip install gcovr && gcovr build/. + + debian: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: build debian package + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_PACKAGE_DEB=ON && cpack .. && sudo dpkg -i *.deb && ls /usr/lib + + doc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: build doxygen documentation + run: sudo apt install -y doxygen + + - name: build doxygen documentation + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_DOCS=ON && cmake --build . --target doc + diff --git a/.gitignore b/.gitignore index 085383d5..1136a1aa 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ test/Makefile.in /compile config.guess config.sub -config.h.in configure /depcomp /install-sh @@ -72,3 +71,9 @@ test/test-frames/*.xml.new test/error-frames/*.xml.new test/unsupported-frames/*.xml.new +/build/ +_build/ + +# IDE +/.vscode/ +CMakeLists.txt.user \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..3b09d88c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,277 @@ +cmake_minimum_required(VERSION 3.8) + +project( + libmbus + LANGUAGES CXX C + VERSION "0.9.0") + +if(CMAKE_BUILD_TYPE STREQUAL "") + message(STATUS "CMAKE_BUILD_TYPE empty setting to Debug") + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# ############################################################################## +# default options -> changed with e.g. cd build && cmake .. +# -DLIBMBUS_BUILD_TESTS=ON +# ############################################################################## + +option(LIBMBUS_BUILD_EXAMPLES "build examples" OFF) +option(LIBMBUS_BUILD_TESTS "build tests" OFF) +option(LIBMBUS_ENABLE_COVERAGE "build with coverage support" ON) +option(LIBMBUS_RUN_CLANG_TIDY "use Clang-Tidy for static analysis" OFF) +option(LIBMBUS_PACKAGE_DEB "build debian package" OFF) +option(LIBMBUS_PACKAGE_RPM "build rpm package" OFF) +option(LIBMBUS_BUILD_DOCS "build documentation" OFF) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_STANDARD 11) + +# Append our module directory to CMake +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) + +# Set the output of the libraries and executables. +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +# ############################################################################## +# static analysis +# ############################################################################## + +if(LIBMBUS_RUN_CLANG_TIDY) + find_program( + CLANG_TIDY_EXE + NAMES "clang-tidy-9" + DOC "/usr/bin/clang-tidy-9") + if(NOT CLANG_TIDY_EXE) + message(WARNING "clang-tidy not found.") + else() + message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}") + endif() +endif(LIBMBUS_RUN_CLANG_TIDY) + +if(LIBMBUS_ENABLE_COVERAGE) + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") + endif() + + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # using Clang + message(STATUS "Not doing coverage...") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # using GCC + message(STATUS "Building with code coverage...") + set(CMAKE_BUILD_TYPE DEBUG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage ") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") + link_libraries(-lgcov) + endif() +endif() + +include(CheckIncludeFile) + +check_include_file(dlfcn.h HAVE_DLFCN_H) +check_include_file(inttypes.h HAVE_INTTYPES_H) +check_include_file(memory.h HAVE_MEMORY_H) +check_include_file(stdlib.h HAVE_STDINT_H) +check_include_file(stdint.h HAVE_STDLIB_H) +check_include_file(strings.h HAVE_STRINGS_H) +check_include_file(string.h HAVE_STRING_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(unistd.h HAVE_UNISTD_H) + +# ############################################################################## +# library +# ############################################################################## + +set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") + +set(PACKAGE_VERSION "${PROJECT_VERSION}") +set(VERSION "${PROJECT_VERSION}") +configure_file(${CMAKE_CURRENT_LIST_DIR}/mbus/config.h.in ${CMAKE_CURRENT_LIST_DIR}/config.h) + +add_library( + ${PROJECT_NAME} + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-tcp.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-tcp.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol-aux.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol-aux.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.h) +target_include_directories( + ${PROJECT_NAME} PUBLIC $ $ + $) +if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android) + target_link_libraries(${PROJECT_NAME} PRIVATE m) +endif() +if(NOT MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-pedantic) +endif() + +if(CLANG_TIDY_EXE) + set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}") +endif() + +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + +# ############################################################################## +# examples +# ############################################################################## + +if(LIBMBUS_BUILD_EXAMPLES) + message(STATUS "building examples") + add_subdirectory(bin) +endif() + +# ############################################################################## +# tests +# ############################################################################## + +if(LIBMBUS_BUILD_TESTS) + message(STATUS "building tests") + enable_testing() + add_subdirectory(test) +endif() + +# ############################################################################## +# install +# ############################################################################## + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(INSTALL_PKGCONFIG_DIR + "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" + CACHE PATH "Installation directory for pkgconfig (.pc) files") +set(INSTALL_INC_DIR + "${CMAKE_INSTALL_PREFIX}/mbus" + CACHE PATH "Installation directory for headers") +set(INSTALL_LIB_DIR + "${CMAKE_INSTALL_PREFIX}/lib" + CACHE PATH "Installation directory for libraries") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libmbus.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libmbus.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmbus.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}") + +set(LIBMBUS_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) +install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT lib) +install( + EXPORT ${PROJECT_NAME}Targets + DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} + NAMESPACE ${PROJECT_NAME}:: + COMPONENT dev) + +configure_package_config_file(cmake/Config.cmake.in ${PROJECT_NAME}Config.cmake INSTALL_DESTINATION + ${LIBMBUS_CONFIG_INSTALL_DIR}) +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} + COMPONENT dev) + +install( + DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/mbus/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mbus/ + COMPONENT dev + FILES_MATCHING + PATTERN "*.h") + +# ############################################################################## +# package +# mkdir build ; cd build ; cmake .. -DLIBMBUS_PACKAGE_DEB=ON ; cpack .. +# ############################################################################## + +include(InstallRequiredSystemLibraries) + +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open source M-bus (Meter-Bus) library.") +set(CPACK_PACKAGE_DESCRIPTION + "libmbus is an open source library for the M-bus (Meter-Bus) protocol. +The Meter-Bus is a standard for reading out meter data from electricity meters, +heat meters, gas meters, etc. The M-bus standard deals with both the electrical +signals on the M-Bus, and the protocol and data format used in transmissions +on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle +the communication with M-Bus devices. + +For more information see http://www.rscada.se/libmbus") + +set(CPACK_PACKAGE_VENDOR "Raditex Control AB") +set(CPACK_PACKAGE_CONTACT "Stefan Wahren ") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/rscada/libmbus/") +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +set(CPACK_PACKAGE_RELEASE 1) +set(CPACK_COMPONENTS_ALL devel libs) +set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) + +set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") +set(CPACK_PACKAGE_FILE_NAME + "${CMAKE_PROJECT_NAME}_${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_COMPONENTS_ALL Libraries ApplicationData) + +if(LIBMBUS_PACKAGE_DEB) + set(CPACK_GENERATOR "DEB") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Stefan Wahren ") + set(CPACK_DEBIAN_PACKAGE_SECTION "Development/Languages/C and C++") + set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + set(CPACK_DEBIAN_PACKAGE_VERSION + "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_PACKAGE_RELEASE}" + ) +endif() + +if(LIBMBUS_PACKAGE_RPM) + set(CPACK_GENERATOR "RPM") + set(CPACK_RPM_PACKAGE_LICENSE "BSD") +endif() + +include(CPack) + +# ############################################################################## +# doc +# mkdir build ; cd build ; cmake .. -DLIBMBUS_BUILD_DOCS=ON ; cmake --build . --target doc +# ############################################################################## + +if(LIBMBUS_BUILD_DOCS) + message(STATUS "building with documentation") + # Generate targets for documentation + # check if Doxygen is installed + find_package(Doxygen) + + if(Doxygen_FOUND) + # set input and output files + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + + # request to configure the file + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + + # note the option ALL which allows to build the docs together with the application + add_custom_target( + doc ALL + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM) + + message(STATUS "Setup up the Doxygen documention build") + + else(Doxygen_FOUND) + message(WARNING "Doxygen need to be installed to generate the doxygen documentation") + endif(Doxygen_FOUND) +endif() diff --git a/Dockerfile.deb b/Dockerfile.deb new file mode 100644 index 00000000..1db6923d --- /dev/null +++ b/Dockerfile.deb @@ -0,0 +1,14 @@ +# docker build . -f Dockerfile.deb -t deb_builder + +FROM ubuntu + +RUN apt update -y && apt install -y cmake gcc g++ make +COPY . /tmp +RUN cd /tmp && \ + mkdir build && \ + cd build && \ + cmake .. -DLIBMBUS_PACKAGE_DEB=ON && \ + cpack .. && \ + ls -al && \ + dpkg -i *.deb + diff --git a/Dockerfile.rpm b/Dockerfile.rpm new file mode 100644 index 00000000..2f70df96 --- /dev/null +++ b/Dockerfile.rpm @@ -0,0 +1,14 @@ +# docker build . -f Dockerfile.rpm -t rpm_builder + +FROM fedora + +RUN dnf install -y cmake gcc g++ make rpm-build +COPY . /tmp +RUN cd /tmp && \ + mkdir build && \ + cd build && \ + cmake .. -DLIBMBUS_PACKAGE_RPM=ON && \ + cpack .. && \ + ls -al && \ + rpm -i *.rpm + diff --git a/doxygen.cfg b/Doxyfile.in similarity index 99% rename from doxygen.cfg rename to Doxyfile.in index ea1b569d..b8393df7 100644 --- a/doxygen.cfg +++ b/Doxyfile.in @@ -25,13 +25,13 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = libmbus +PROJECT_NAME = "@CMAKE_PROJECT_NAME@" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = +PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. @@ -581,7 +581,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = mbus +INPUT = @CMAKE_CURRENT_LIST_DIR@/mbus # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -1628,3 +1628,6 @@ GENERATE_LEGEND = YES # the various graphs. DOT_CLEANUP = YES + + +USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_LIST_DIR@/README.md diff --git a/Makefile-static b/Makefile-static deleted file mode 100644 index 93da7516..00000000 --- a/Makefile-static +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2010 -# Robert Johansson -# Raditex AB. -# All rights reserved. - -LIB = libmbus.so - -CFLAGS = -Wall -W -g -fPIC -I. -HEADERS = mbus.h mbus-protocol.h -OBJS = mbus.o mbus-protocol.o - -$(LIB): $(OBJS) - gcc -shared -o $(LIB) $(OBJS) - -all: $(LIB) - -clean: - rm -rf *.o *core core $(LIB) - -test: - (cd test && make) - -install: all - cp $(LIB) /usr/local/freescada/lib - cp $(HEADERS) /usr/local/freescada/include diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index fd519e14..00000000 --- a/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# -# -# -PACKAGE = @PACKAGE@ -VERSION = @VERSION@ - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libmbus.pc - - -docdir = $(datadir)/doc/$(PACKAGE)-$(VERSION) -dist_docdir = $(DESTDIR)$(docdir) -doc_DATA = README.md \ - COPYING \ - hardware/MBus_USB.pdf \ - hardware/MBus_USB.txt - -SUBDIRS = mbus bin -ACLOCAL = aclocal -I . -ACLOCAL_AMFLAGS = -Werror -I m4 diff --git a/README.md b/README.md index 27d393c0..133c243d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# libmbus: M-bus Library from Raditex Control (http://www.rscada.se) ![Build Status](https://travis-ci.org/rscada/libmbus.svg?branch=master) +# libmbus: M-bus Library from Raditex Control (http://www.rscada.se) + +![Build Status](https://travis-ci.org/rscada/libmbus.svg?branch=master) libmbus is an open source library for the M-bus (Meter-Bus) protocol. @@ -8,4 +10,32 @@ signals on the M-Bus, and the protocol and data format used in transmissions on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle the communication with M-Bus devices. + +## BUILD + +with cmake + +```bash +rm -rf _build +mkdir _build +cd _build +# configure +# e.g. on linux +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON +# e.g. for a target device +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/foo-bar-baz.cmake +# compile +cmake --build . -j +# install - optional +cmake --build . --target install +``` + +## CONSUME + +```cmake +find_package(libmbus) +add_executable(my_app main.cpp) +target_link_libraries(my_app libmbus::libmbus) +``` + For more information see http://www.rscada.se/libmbus diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt new file mode 100644 index 00000000..73e15002 --- /dev/null +++ b/bin/CMakeLists.txt @@ -0,0 +1,19 @@ +function(add_example SRCS) + add_executable(${SRCS} ${CMAKE_CURRENT_LIST_DIR}/${SRCS}.c) + target_link_libraries(${SRCS} PRIVATE libmbus::libmbus) +endfunction() + +add_example(mbus-serial-request-data) +add_example(mbus-serial-request-data-multi-reply) +add_example(mbus-serial-scan) +add_example(mbus-serial-scan-secondary) +add_example(mbus-serial-select-secondary) +add_example(mbus-serial-set-address) +add_example(mbus-serial-switch-baudrate) +add_example(mbus-tcp-application-reset) +add_example(mbus-tcp-raw-send) +add_example(mbus-tcp-request-data) +add_example(mbus-tcp-request-data-multi-reply) +add_example(mbus-tcp-scan) +add_example(mbus-tcp-scan-secondary) +add_example(mbus-tcp-select-secondary) diff --git a/bin/Makefile-static b/bin/Makefile-static deleted file mode 100644 index 2b04b493..00000000 --- a/bin/Makefile-static +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright (C) 2011, Robert Johansson, Raditex AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# -CFLAGS=-Wall -g -I.. -LDFLAGS=-L.. -lm -lmbus - -all: mbus-tcp-scan mbus-tcp-request-data - -%.o: %.c - $(CC) -c $(CFLAGS) $< -o $@ - -mbus-tcp-scan: mbus-tcp-scan.o mbus-tcp.o - gcc -o $@ $^ $(LDFLAGS) - -mbus-tcp-request-data: mbus-tcp-request-data.o mbus-tcp.o - gcc -o $@ $^ $(LDFLAGS) - -clean: - rm -rf mbus-tcp-request-data mbus-tcp-scan *.o *~ diff --git a/bin/Makefile.am b/bin/Makefile.am deleted file mode 100644 index 7c9ce412..00000000 --- a/bin/Makefile.am +++ /dev/null @@ -1,102 +0,0 @@ -# ------------------------------------------------------------------------------ -# 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) -I$(top_srcdir)/src - -noinst_HEADERS = -bin_PROGRAMS = mbus-tcp-scan mbus-tcp-request-data mbus-tcp-request-data-multi-reply \ - mbus-tcp-select-secondary mbus-tcp-scan-secondary \ - mbus-serial-scan mbus-serial-request-data mbus-serial-request-data-multi-reply \ - mbus-serial-select-secondary mbus-serial-scan-secondary \ - mbus-serial-switch-baudrate mbus-tcp-raw-send mbus-tcp-application-reset \ - mbus-serial-set-address - -# tcp -mbus_tcp_scan_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_scan_LDADD = -lmbus -lm -mbus_tcp_scan_SOURCES = mbus-tcp-scan.c - -mbus_tcp_request_data_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_request_data_LDADD = -lmbus -lm -mbus_tcp_request_data_SOURCES = mbus-tcp-request-data.c - -mbus_tcp_request_data_multi_reply_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_request_data_multi_reply_LDADD = -lmbus -lm -mbus_tcp_request_data_multi_reply_SOURCES = mbus-tcp-request-data-multi-reply.c - -mbus_tcp_select_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_select_secondary_LDADD = -lmbus -lm -mbus_tcp_select_secondary_SOURCES = mbus-tcp-select-secondary.c - -mbus_tcp_scan_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_scan_secondary_LDADD = -lmbus -lm -mbus_tcp_scan_secondary_SOURCES = mbus-tcp-scan-secondary.c - -mbus_tcp_raw_send_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_raw_send_LDADD = -lmbus -lm -mbus_tcp_raw_send_SOURCES = mbus-tcp-raw-send.c - -mbus_tcp_application_reset_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_application_reset_LDADD = -lmbus -lm -mbus_tcp_application_reset_SOURCES = mbus-tcp-application-reset.c - -# serial -mbus_serial_scan_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_scan_LDADD = -lmbus -lm -mbus_serial_scan_SOURCES = mbus-serial-scan.c - -mbus_serial_request_data_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_request_data_LDADD = -lmbus -lm -mbus_serial_request_data_SOURCES = mbus-serial-request-data.c - -mbus_serial_request_data_multi_reply_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_request_data_multi_reply_LDADD = -lmbus -lm -mbus_serial_request_data_multi_reply_SOURCES = mbus-serial-request-data-multi-reply.c - -mbus_serial_select_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_select_secondary_LDADD = -lmbus -lm -mbus_serial_select_secondary_SOURCES = mbus-serial-select-secondary.c - -mbus_serial_scan_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_scan_secondary_LDADD = -lmbus -lm -mbus_serial_scan_secondary_SOURCES = mbus-serial-scan-secondary.c - -mbus_serial_switch_baudrate_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_switch_baudrate_LDADD = -lmbus -lm -mbus_serial_switch_baudrate_SOURCES = mbus-serial-switch-baudrate.c - -mbus_serial_set_address_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_set_address_LDADD = -lmbus -lm -mbus_serial_set_address_SOURCES = mbus-serial-set-address.c - -# man pages -dist_man_MANS = libmbus.1 \ - mbus-tcp-scan.1 \ - mbus-tcp-request-data.1 \ - mbus-tcp-request-data-multi-reply.1 \ - mbus-tcp-select-secondary.1 \ - mbus-tcp-scan-secondary.1 \ - mbus-tcp-raw-send.1 \ - mbus-serial-scan.1 \ - mbus-serial-request-data.1 \ - mbus-serial-request-data-multi-reply.1 \ - mbus-serial-select-secondary.1 \ - mbus-serial-scan-secondary.1 \ - mbus-serial-switch-baudrate.1 - -.pod.1: - pod2man --release=$(VERSION) --center=$(PACKAGE) $< \ - >.pod2man.tmp.$$$$ 2>/dev/null && mv -f .pod2man.tmp.$$$$ $@ || true - @if grep '\' $@ >/dev/null 2>&1; \ - then \ - echo "$@ has some POD errors!"; false; \ - fi diff --git a/build-deb.sh b/build-deb.sh deleted file mode 100755 index 77f3a6be..00000000 --- a/build-deb.sh +++ /dev/null @@ -1,25 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (C) 2012, Robert Johansson , Raditex Control AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@raditex.nu -# -# ------------------------------------------------------------------------------ - -if [ ! -f Makefile ]; then - # - # regenerate automake files - # - echo "Running autotools..." - - autoheader \ - && aclocal \ - && libtoolize --ltdl --copy --force \ - && automake --add-missing --copy \ - && autoconf -fi - -debuild -i -us -uc -b -#sudo pbuilder build $(NAME)_$(VERSION)-1.dsc diff --git a/build.sh b/build.sh index 34c2799b..2869e926 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,24 @@ #!/bin/sh -# -if [ -f Makefile ]; then - # use existing automake files - echo >> /dev/null -else - # regenerate automake files - echo "Running autotools..." - autoheader \ - && aclocal \ - && case \ - $(uname) in Darwin*) glibtoolize --ltdl --copy --force ;; \ - *) libtoolize --ltdl --copy --force ;; esac \ - && automake --add-missing --copy \ - && autoconf \ - && ./configure -fi +rm -rf _build +mkdir _build +cd _build +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON +cmake --build . -j -make +# build deb + +# rm -rf _build +# mkdir _build +# cd _build +# cmake .. -DLIBMBUS_PACKAGE_DEB=ON +# cpack .. +# dpkg -i *.deb + +# build doc + +# mkdir build +# cd build +# cmake .. -DLIBMBUS_BUILD_DOCS=ON +# cmake --build . --target doc \ No newline at end of file diff --git a/cmake-format.yaml b/cmake-format.yaml new file mode 100644 index 00000000..60329ed6 --- /dev/null +++ b/cmake-format.yaml @@ -0,0 +1,15 @@ +# https://github.com/cheshirekow/cmake_format + +# How wide to allow formatted cmake files +line_width: 120 + +# How many spaces to tab for indent +tab_size: 2 + +# Format command names consistently as 'lower' or 'upper' case +command_case: "lower" + +first_comment_is_literal: False + +# enable comment markup parsing and reflow +enable_markup: False diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 00000000..9c15f36a --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/configure.ac b/configure.ac deleted file mode 100644 index d14d0e2c..00000000 --- a/configure.ac +++ /dev/null @@ -1,44 +0,0 @@ -dnl ---------------------------------------------------------------------------- -dnl Copyright (C) 2010, Raditex AB -dnl All rights reserved. -dnl -dnl rSCADA -dnl http://www.rSCADA.se -dnl info@rscada.se -dnl -dnl ---------------------------------------------------------------------------- - -LT_CONFIG_LTDL_DIR([libltdl]) - -AC_INIT([libmbus], [0.9.0], [info@rscada.se], [libmbus], [http://www.rscada.se/libmbus/]) -AC_CONFIG_AUX_DIR([libltdl/config]) -AM_INIT_AUTOMAKE([-Wall -Werror foreign]) - -AM_PROG_LIBTOOL -# fix for automake 1.11 & 1.12 -m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) - -LDFLAGS="$LDFLAGS -version-info 0:9:0" - -dnl ---------------------- -dnl -AC_PROG_CC - -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([Makefile mbus/Makefile test/Makefile bin/Makefile libmbus.pc]) -AC_OUTPUT - - -echo \ -"---------------------------------------------------------- -Configuration: - - Source location: ${srcdir} - Compile: ${CC} - Compiler flags: ${CFLAGS} - Linker flags: ${LDFLAGS} - Host system type: ${host} - Install path: ${prefix} - - See config.h for further configuration. -----------------------------------------------------------" diff --git a/libmbus.pc.in b/libmbus.pc.in index 6c1b7d8b..1baf5a3e 100644 --- a/libmbus.pc.in +++ b/libmbus.pc.in @@ -1,12 +1,12 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ Name: libmbus Description: Open source M-bus (Meter-Bus) library. Requires: -Version: @PACKAGE_VERSION@ +Version: @PROJECT_VERSION@ URL: http://www.rscada.se/libmbus/ Libs: -L${libdir} -lmbus -lm -Cflags: -I${includedir} +Cflags: -I${includedir} \ No newline at end of file diff --git a/libmbus.spec b/libmbus.spec deleted file mode 100644 index 06160f75..00000000 --- a/libmbus.spec +++ /dev/null @@ -1,87 +0,0 @@ -# -# spec file for package libmbus -# -# Copyright (c) 2010-2013, Raditex Control AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# - -Summary: Open source M-bus (Meter-Bus) library -Name: libmbus -Version: 0.9.0 -Release: 1 -Source: https://github.com/rscada/%{name}/archive/%{version}.tar.gz -URL: https://github.com/rscada/libmbus/ -License: BSD -Vendor: Raditex Control AB -Packager: Stefan Wahren -Group: Development/Languages/C and C++ -BuildRoot: {_tmppath}/%{name}-%{version}-build -AutoReqProv: on - -%description -libmbus: M-bus Library from Raditex Control (http://www.rscada.se) - -libmbus is an open source library for the M-bus (Meter-Bus) protocol. -The Meter-Bus is a standard for reading out meter data from electricity meters, -heat meters, gas meters, etc. The M-bus standard deals with both the electrical -signals on the M-Bus, and the protocol and data format used in transmissions -on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle -the communication with M-Bus devices. - -For more information see http://www.rscada.se/libmbus - -%package devel -License: BSD -Summary: Development libraries and header files for using the M-bus library -Group: Development/Libraries/C and C++ -AutoReqProv: on -Requires: %{name} = %{version} - -%description devel -This package contains all necessary include files and libraries needed -to compile and link applications which use the M-bus (Meter-Bus) library. - -%prep -q -%setup -q -# workaround to get it's build -autoreconf - -%build -./configure --prefix=/usr -make - -%install -rm -Rf "%buildroot" -mkdir "%buildroot" -make install DESTDIR="%buildroot" - -%clean -rm -rf "%buildroot" - -%files -%defattr (-,root,root) -%doc COPYING README.md -%{_bindir}/mbus-serial-* -%{_bindir}/mbus-tcp-* -%{_libdir}/libmbus.so* -%{_mandir}/man1/libmbus.1 -%{_mandir}/man1/mbus-* - -%files devel -%defattr (-,root,root) -%{_includedir}/mbus -%{_libdir}/libmbus.a -%{_libdir}/libmbus.la -%{_libdir}/pkgconfig/libmbus.pc - -%changelog -* Fri Feb 22 2019 Stefan Wahren - 0.9.0-1 -- switch to github repo -- enable man pages - -* Fri Mar 29 2013 Stefan Wahren - 0.8.0-1 -- Initial package based on the last official release diff --git a/mbus/Makefile.am b/mbus/Makefile.am deleted file mode 100644 index b0749871..00000000 --- a/mbus/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# ------------------------------------------------------------------------------ -# 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) - -includedir = $(prefix)/include/mbus -include_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 - diff --git a/mbus/config.h.in b/mbus/config.h.in new file mode 100644 index 00000000..369c7c80 --- /dev/null +++ b/mbus/config.h.in @@ -0,0 +1,59 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H "@HAVE_DLFCN_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H "@HAVE_INTTYPES_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H "@HAVE_MEMORY_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H "@HAVE_STDINT_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H "@HAVE_STDLIB_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H "@HAVE_STRINGS_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H "@HAVE_STRING_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H "@HAVE_SYS_STAT_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H "@HAVE_SYS_TYPES_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H "@HAVE_UNISTD_H@" + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libmbus" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "info@rscada.se" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libmbus" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libmbus" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "http://www.rscada.se/libmbus/" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Version number of package */ +#cmakedefine VERSION "@PACKAGE_VERSION@" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..cad2f88b --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(mbus_parse ${CMAKE_CURRENT_LIST_DIR}/mbus_parse.c) +target_link_libraries(mbus_parse PRIVATE libmbus::libmbus) + +add_executable(mbus_parse_hex ${CMAKE_CURRENT_LIST_DIR}/mbus_parse_hex.c) +target_link_libraries(mbus_parse_hex PRIVATE libmbus::libmbus) + +add_test(mbus_parse_hex ${CMAKE_BINARY_DIR}/bin/mbus_parse_hex) +add_test(mbus_parse ${CMAKE_BINARY_DIR}/bin/mbus_parse) diff --git a/test/Makefile.am b/test/Makefile.am deleted file mode 100644 index c373fa48..00000000 --- a/test/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -# ------------------------------------------------------------------------------ -# 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) -I$(top_srcdir)/mbus - -noinst_HEADERS = -noinst_PROGRAMS = mbus_parse mbus_parse_hex - -mbus_parse_LDFLAGS = -L$(top_builddir)/mbus -mbus_parse_LDADD = -lmbus -lm -mbus_parse_SOURCES = mbus_parse.c - -mbus_parse_hex_LDFLAGS = -L$(top_builddir)/mbus -mbus_parse_hex_LDADD = -lmbus -lm -mbus_parse_hex_SOURCES = mbus_parse_hex.c - diff --git a/test/generate-xml.sh b/test/generate-xml.sh index d03aa1fe..8fe43d75 100755 --- a/test/generate-xml.sh +++ b/test/generate-xml.sh @@ -12,26 +12,28 @@ # #------------------------------------------------------------------------------ -# Check if mbus_parse_hex exists -if [ ! -x ./mbus_parse_hex ]; then - echo "mbus_parse_hex not found" - exit 3 -fi - # Check commandline parameter -if [ $# -ne 1 ]; then +if [ $# -ne 2 ]; then echo "usage: $0 directory" exit 3 fi directory="$1" -# Check directory -if [ ! -d "$directory" ]; then - echo "usage: $0 directory" +# Check if mbus_parse_hex exists +if [ ! -x $2 ]; then + echo "mbus_parse_hex not found" exit 3 fi +mbus_parse_hex="$2" + +# # Check directory +# if [ ! -d "$directory" ]; then +# echo "usage: $0 directory" +# exit 3 +# fi + for hexfile in "$directory"/*.hex; do if [ ! -f "$hexfile" ]; then continue @@ -40,7 +42,7 @@ for hexfile in "$directory"/*.hex; do filename=`basename $hexfile .hex` # Parse hex file and write XML in file - ./mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new" + $mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new" result=$? # Check parsing result