uniba-swt / libbidib

A library for communication with a BiDiB (www.bidib.org) system using a serial connection.
GNU General Public License v3.0
10 stars 4 forks source link
bidib modelrailroad modelrailway swtbahn

libbidib

CI/CD Latest release

A library for communication with a BiDiB (www.bidib.org) system using a serial connection. The library was developed to be compatible with BiDiB revision 1.27.

The library was initially developed by Nicolas Gross in a student project at the Software Technologies Research Group (SWT) of the University of Bamberg. Its purpose is to provide an implementation of the BiDiB protocol as a basis for controlling a model railway. The railway should later on support teaching of the upcoming course Reactive Systems Design.

Features

Dependencies

Build

  1. Clone the repository
  2. Adjust CMakeLists.txt according to your installations of the dependencies (libglib-2.0, libpthread, libyaml and cmocka).
  3. Navigate to the directory where the build files should be generated
  4. Execute cmake <path-to-project-root>
  5. Choose static or shared library:
    • Shared: Execute make bidib to create the shared library libbidib.so
    • Static: Execute make bidib_static to create the static library libbidib_static.a

To run the unit tests, execute make test. Each unit test can be executed to display more detailed test results, e.g., ./bidib_config_parser_tests.

To run the physical tests, execute make and afterwards ./testsuite. See the project-root/test/physical/Readme.md for further details.

To generate the documentation, execute doxygen doxygen_config.txt in the root directory of the project. This will create the directory doc which contains the documentation.

To generate the code coverage report, run cmake -DCMAKE_BUILD_TYPE=Debug <path-to-project-root> and afterwards make coverage_test.

Install and Uninstall

To use the library in external applications without needing to specify absolute include and library paths, the required files can be copied to a directory on the system's path by running make install. The copied files are listed in install_manifest.txt inside the build directory.

To uninstall the library, run xargs rm < install_manifest.txt from inside the build directory.

Test

To run the unit tests, execute make test from within the build directory. Each unit test can be executed to display more detailed test results, e.g., ./bidib_config_parser_tests.

To run physical tests on a model railway platform, see the readme in project-root/test/physical

Message handling

Many messages are already handled by the library. The remaining messages are placed either in the message queue or in the error queue. These queues should be checked by the user to react appropriately. Here is an overview on which messages will be put in the respective queues:

Error queue

Message queue

Terminology

For some names/identifiers in the library it's maybe not clear what's meant by them. Here is a short explanation for the most important ones:

For further information have a look at the BiDiB specification.

Usage

Use with care, only parts of the functionality was tested on a real system!

The library logs to LOCAL0, you may have to configure your log daemon accordingly. On systemd-based distros, journalctl -t swtbahn should provide access to the log.

  1. Create the yaml configuration files for your setup, examples can be found in project-root/example/config
    • You must keep the the elements in the configuration files in the same order as in the example files!
    • points-board -> points-dcc -> signals-board -> signals-dcc -> peripherals -> segments
  2. Include bidib.h (project-root/include/bidib.h)
  3. Start the library, with either bidib_start_serial(<params>) or bidib_start_pointer(<params>)
  4. Use the library:
    • Read messages: bidib_read_message() (Queue capacity: 128 messages)
    • Read error messages: bidib_read_error_message() (Queue capacity: 128 messages)
    • Send messages via low level functions: bidib_send_<message>(<params>)
    • Send messages via high level function, e.g.: bidib_set_train_speed(char *train, int speed)
    • Flush the buffer manually: bidib_flush()
  5. Stop the library: bidib_stop()

Calling the functions mentioned in 4. before/while the library is started, while/after it is stopped or while it is reset (bidib_send_sys_reset()) is not allowed and will result in undefined behaviour.

All the public functions of the library are documented in their respective header files, found in the project-root/include folder.

Example Programs

A short program illustrating the use of libbidib can be found in the project-root/example folder. Moreover, the physical test cases in project-root/test/physical for SWTbahn platforms can be consulted for further usage examples.

Example Log

A log file for a short libbidib session can be found in project-root/example/syslog_2020_01_10.txt . Moreover, annotated startup and shutdown log messages can be found in the wiki.

Threadsafety

Once the library is started, you can safely call bidib_read_message(), bidib_read_error_message(), all low level and high level send functions and bidib_flush() in a concurrent manner. If you stop the library or reset the system, you have to ensure that none of these functions are called during the execution of bidib_stop() and bidib_send_sys_reset().

To summarize: It's not supported to call ANY library function concurrently with bidib_start_serial(<params>), bidib_start_pointer(<params>), bidib_stop() and bidib_send_sys_reset().

Licensing

The copyright holder for bidib_messages.h is Wolfgang Kufer and the file is excluded from the GPL3.0 license. The reason behind this is to prevent others from defining alternative message numbers, which would lead to incompatible products. The rest of the library is released under the terms of GPL3.0.