├── .clang-format ├── .clang-format.c ├── .clang-format.cpp ├── .cquery ├── .flake8 ├── .gcc-flags.json ├── .gitignore ├── .gitlab-ci.yml ├── .lgtm.yml ├── .sonar └── sonarcloud-rules-htmlreport.py ├── .vscode ├── c_cpp_properties.json └── settings.json ├── CPPLINT.cfg ├── LICENSE ├── Makefile.am ├── NOTICE ├── README.md ├── configure.ac ├── doc ├── Doxyfile.in └── Makefile.am ├── docker ├── README.md ├── arm-none-eabi │ └── bullseye │ │ └── Dockerfile ├── build │ └── bullseye │ │ └── Dockerfile ├── clang-format │ └── bullseye │ │ └── Dockerfile ├── coverity │ └── gcc9 │ │ └── Dockerfile ├── cppcheck-unix64 │ └── bullseye │ │ └── Dockerfile ├── cppcheck-win64 │ └── bullseye │ │ └── Dockerfile ├── cpplint │ └── bullseye │ │ └── Dockerfile ├── crossbuild │ └── buster │ │ └── Dockerfile ├── doc │ └── bullseye │ │ └── Dockerfile ├── gcc │ └── Dockerfile ├── lcov │ └── bullseye │ │ └── Dockerfile ├── mingw-w64 │ └── bullseye │ │ └── Dockerfile ├── python-checks │ └── 3.8-slim │ │ └── Dockerfile ├── scan-build │ └── bullseye │ │ └── Dockerfile ├── sonarcloud │ └── bullseye │ │ └── Dockerfile └── valgrind │ └── bullseye │ └── Dockerfile ├── exec-wrapper.sh.in ├── include ├── Makefile.am └── lely │ ├── can │ ├── buf.h │ ├── buf.hpp │ ├── err.h │ ├── msg.h │ ├── net.h │ ├── net.hpp │ ├── socket.h │ └── vci.h │ ├── co │ ├── co.h │ ├── crc.h │ ├── csdo.h │ ├── csdo.hpp │ ├── dcf.h │ ├── dcf.hpp │ ├── def │ │ ├── array.def │ │ ├── basic.def │ │ ├── cxx.def │ │ ├── time.def │ │ └── type.def │ ├── detail │ │ ├── dev.h │ │ └── obj.h │ ├── dev.h │ ├── dev.hpp │ ├── emcy.h │ ├── emcy.hpp │ ├── gw.h │ ├── gw.hpp │ ├── gw_txt.h │ ├── gw_txt.hpp │ ├── lss.h │ ├── lss.hpp │ ├── nmt.h │ ├── nmt.hpp │ ├── obj.h │ ├── obj.hpp │ ├── pdo.h │ ├── rpdo.h │ ├── rpdo.hpp │ ├── sdev.h │ ├── sdev.hpp │ ├── sdo.h │ ├── ssdo.h │ ├── ssdo.hpp │ ├── sync.h │ ├── sync.hpp │ ├── time.h │ ├── time.hpp │ ├── tpdo.h │ ├── tpdo.hpp │ ├── type.h │ ├── type.hpp │ ├── val.h │ ├── val.hpp │ ├── wtm.h │ └── wtm.hpp │ ├── coapp │ ├── device.hpp │ ├── driver.hpp │ ├── fiber_driver.hpp │ ├── logical_driver.hpp │ ├── loop_driver.hpp │ ├── lss_master.hpp │ ├── master.hpp │ ├── node.hpp │ ├── sdo.hpp │ ├── sdo_error.hpp │ ├── slave.hpp │ └── type_traits.hpp │ ├── ev │ ├── co_task.hpp │ ├── ev.h │ ├── exec.h │ ├── exec.hpp │ ├── fiber_exec.h │ ├── fiber_exec.hpp │ ├── future.h │ ├── future.hpp │ ├── loop.h │ ├── loop.hpp │ ├── poll.h │ ├── poll.hpp │ ├── std_exec.h │ ├── strand.h │ ├── strand.hpp │ ├── task.h │ ├── task.hpp │ ├── thrd_loop.h │ └── thrd_loop.hpp │ ├── features.h │ ├── io │ ├── addr.h │ ├── attr.h │ ├── can.h │ ├── can.hpp │ ├── file.h │ ├── file.hpp │ ├── if.h │ ├── io.h │ ├── io.hpp │ ├── pipe.h │ ├── pipe.hpp │ ├── poll.h │ ├── poll.hpp │ ├── serial.h │ ├── serial.hpp │ ├── sock.h │ └── sock.hpp │ ├── io2 │ ├── can.h │ ├── can.hpp │ ├── can │ │ ├── err.h │ │ ├── err.hpp │ │ ├── msg.h │ │ └── msg.hpp │ ├── can_net.h │ ├── can_net.hpp │ ├── can_rt.h │ ├── can_rt.hpp │ ├── clock.h │ ├── clock.hpp │ ├── co_can.hpp │ ├── co_can_rt.hpp │ ├── co_sigset.hpp │ ├── co_timer.hpp │ ├── co_tqueue.hpp │ ├── ctx.h │ ├── ctx.hpp │ ├── dev.h │ ├── dev.hpp │ ├── event.h │ ├── event.hpp │ ├── io2.h │ ├── linux │ │ ├── can.h │ │ └── can.hpp │ ├── posix │ │ ├── poll.h │ │ └── poll.hpp │ ├── sigset.h │ ├── sigset.hpp │ ├── sys │ │ ├── clock.h │ │ ├── clock.hpp │ │ ├── io.h │ │ ├── io.hpp │ │ ├── sigset.h │ │ ├── sigset.hpp │ │ ├── timer.h │ │ └── timer.hpp │ ├── timer.h │ ├── timer.hpp │ ├── tqueue.h │ ├── tqueue.hpp │ ├── user │ │ ├── can.h │ │ ├── can.hpp │ │ ├── timer.h │ │ └── timer.hpp │ ├── vcan.h │ ├── vcan.hpp │ └── win32 │ │ ├── ixxat.h │ │ ├── ixxat.hpp │ │ ├── poll.h │ │ └── poll.hpp │ ├── libc │ ├── chrono.hpp │ ├── functional.hpp │ ├── stdatomic.h │ ├── stddef.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── strings.h │ ├── sys │ │ └── types.h │ ├── threads.h │ ├── time.h │ ├── type_traits.hpp │ ├── uchar.h │ ├── unistd.h │ └── utility.hpp │ ├── tap │ └── tap.h │ └── util │ ├── bimap.h │ ├── bits.h │ ├── bitset.h │ ├── c_call.hpp │ ├── c_type.hpp │ ├── chrono.hpp │ ├── cmp.h │ ├── config.h │ ├── coroutine.h │ ├── coroutine.hpp │ ├── daemon.h │ ├── def │ └── type.def │ ├── diag.h │ ├── dllist.h │ ├── endian.h │ ├── errnum.h │ ├── error.hpp │ ├── exception.hpp │ ├── fiber.h │ ├── fiber.hpp │ ├── float.h │ ├── frbuf.h │ ├── fwbuf.h │ ├── invoker.hpp │ ├── lex.h │ ├── membuf.h │ ├── mkjmp.h │ ├── mutex.hpp │ ├── pheap.h │ ├── print.h │ ├── rbtree.h │ ├── result.hpp │ ├── sllist.h │ ├── spscring.h │ ├── stop.h │ ├── stop.hpp │ ├── time.h │ ├── ustring.h │ └── util.h ├── lcov-wrapper.sh.in ├── m4 ├── ax_check_python.m4 ├── ax_code_coverage.m4 ├── ax_cxx_compile_stdcxx.m4 ├── ax_pthread.m4 └── ax_valgrind_check.m4 ├── pkgconfig ├── Makefile.am ├── liblely-can.pc.in ├── liblely-co.pc.in ├── liblely-coapp.pc.in ├── liblely-ev.pc.in ├── liblely-io.pc.in ├── liblely-io2.pc.in ├── liblely-libc.pc.in ├── liblely-libc_rt.pc.in ├── liblely-tap.pc.in └── liblely-util.pc.in ├── python ├── Makefile.am ├── can │ ├── Makefile.am │ ├── lely_can │ │ ├── __init__.pxd │ │ ├── __init__.py │ │ ├── err.pxd │ │ ├── err.pyx │ │ ├── msg.pxd │ │ └── msg.pyx │ └── setup.py ├── dcf-tools │ ├── Makefile.am │ ├── dcf │ │ ├── __init__.py │ │ ├── cli.py │ │ ├── device.py │ │ ├── lint.py │ │ ├── parse.py │ │ └── print.py │ ├── dcf2dev │ │ ├── __init__.py │ │ ├── cdevice.py │ │ ├── cli.py │ │ └── data │ │ │ ├── dev.c.em │ │ │ └── dev.h.em │ ├── dcfgen │ │ ├── __init__.py │ │ ├── cli.py │ │ └── data │ │ │ └── master.dcf.em │ └── setup.py └── io │ ├── Makefile.am │ ├── lely_io │ ├── __init__.pxd │ ├── __init__.py │ ├── addr.pxd │ ├── addr.pyx │ ├── attr.pxd │ ├── attr.pyx │ ├── can.pxd │ ├── can.pyx │ ├── file.pxd │ ├── file.pyx │ ├── io.pxd │ ├── io.pyx │ ├── pipe.pxd │ ├── pipe.pyx │ ├── poll.pxd │ ├── poll.pyx │ ├── serial.pxd │ ├── serial.pyx │ ├── sock.pxd │ └── sock.pyx │ └── setup.py ├── src ├── Makefile.am ├── can │ ├── Makefile.am │ ├── buf.c │ ├── can.h │ ├── msg.c │ ├── net.c │ ├── socket.c │ ├── vci.c │ └── version.rc ├── co │ ├── Makefile.am │ ├── co.h │ ├── crc.c │ ├── csdo.c │ ├── dcf.c │ ├── dev.c │ ├── emcy.c │ ├── gw.c │ ├── gw_txt.c │ ├── lss.c │ ├── nmt.c │ ├── nmt_boot.c │ ├── nmt_boot.h │ ├── nmt_cfg.c │ ├── nmt_cfg.h │ ├── nmt_hb.c │ ├── nmt_hb.h │ ├── nmt_srv.c │ ├── nmt_srv.h │ ├── obj.c │ ├── pdo.c │ ├── rpdo.c │ ├── sdev.c │ ├── sdo.c │ ├── sdo.h │ ├── ssdo.c │ ├── sync.c │ ├── time.c │ ├── tpdo.c │ ├── type.c │ ├── val.c │ ├── version.rc.in │ └── wtm.c ├── coapp │ ├── Makefile.am │ ├── coapp.hpp │ ├── device.cpp │ ├── driver.cpp │ ├── fiber_driver.cpp │ ├── logical_driver.cpp │ ├── loop_driver.cpp │ ├── lss_master.cpp │ ├── master.cpp │ ├── node.cpp │ ├── sdo.cpp │ ├── sdo_error.cpp │ ├── slave.cpp │ ├── type_traits.cpp │ └── version.rc.in ├── ev │ ├── Makefile.am │ ├── ev.h │ ├── exec.c │ ├── fiber_exec.c │ ├── future.c │ ├── loop.c │ ├── poll.c │ ├── std_exec.c │ ├── strand.c │ ├── task.c │ ├── thrd_loop.c │ └── version.rc.in ├── io │ ├── Makefile.am │ ├── addr.c │ ├── attr.c │ ├── attr.h │ ├── can.c │ ├── default.h │ ├── file.c │ ├── handle.c │ ├── handle.h │ ├── if.c │ ├── io.c │ ├── io.h │ ├── pipe.c │ ├── poll.c │ ├── rtnl.c │ ├── rtnl.h │ ├── serial.c │ ├── sock.c │ └── version.rc ├── io2 │ ├── Makefile.am │ ├── can.c │ ├── can.h │ ├── can │ │ └── msg.c │ ├── can_net.c │ ├── can_rt.c │ ├── clock.c │ ├── ctx.c │ ├── dev.c │ ├── io2.h │ ├── linux │ │ ├── can_attr.h │ │ ├── can_chan.c │ │ ├── can_ctrl.c │ │ ├── can_err.h │ │ ├── can_msg.h │ │ ├── if.h │ │ ├── ifreq.h │ │ ├── io.h │ │ ├── poll.c │ │ ├── rtnl.h │ │ └── timer.c │ ├── posix │ │ ├── fd.c │ │ ├── fd.h │ │ ├── io.c │ │ ├── io.h │ │ ├── poll.c │ │ ├── sigset.c │ │ └── timer.c │ ├── sigset.c │ ├── sigset.h │ ├── sys │ │ ├── clock.c │ │ ├── io.c │ │ └── io.h │ ├── timer.c │ ├── timer.h │ ├── tqueue.c │ ├── user │ │ ├── can.c │ │ └── timer.c │ ├── vcan.c │ ├── version.rc.in │ └── win32 │ │ ├── io.c │ │ ├── io.h │ │ ├── ixxat.c │ │ ├── ixxat.inc │ │ ├── poll.c │ │ ├── sigset.c │ │ └── timer.c ├── libc │ ├── Makefile.am │ ├── clock.c │ ├── getopt.c │ ├── libc.h │ ├── sleep.c │ ├── stdatomic.c │ ├── stdio.c │ ├── stdlib.c │ ├── string.c │ ├── strings.c │ ├── threads-pthread.c │ ├── threads-win32.c │ ├── time.c │ └── version.rc.in ├── tap │ ├── Makefile.am │ ├── tap.c │ ├── tap.h │ └── version.rc.in └── util │ ├── Makefile.am │ ├── bimap.c │ ├── bits.c │ ├── bitset.c │ ├── cmp.c │ ├── config.c │ ├── config_ini.c │ ├── daemon.c │ ├── diag.c │ ├── dllist.c │ ├── endian.c │ ├── errnum.c │ ├── exception.cpp │ ├── fiber.c │ ├── frbuf.c │ ├── fwbuf.c │ ├── lex.c │ ├── membuf.c │ ├── mkjmp.c │ ├── pheap.c │ ├── print.c │ ├── rbtree.c │ ├── sllist.c │ ├── spscring.c │ ├── stop.c │ ├── time.c │ ├── ustring.c │ ├── util.h │ └── version.rc.in ├── suppressions.txt ├── test ├── Makefile.am ├── can-net.c ├── co-cxx.cpp ├── co-emcy.c ├── co-emcy.dcf ├── co-gw_txt-master.dcf ├── co-gw_txt-slave.dcf ├── co-gw_txt.c ├── co-nmt-master.dat ├── co-nmt-master.dcf.in ├── co-nmt-slave.dcf ├── co-nmt.c ├── co-pdo-receive.dcf ├── co-pdo-transmit.dcf ├── co-pdo.c ├── co-sdev.c ├── co-sdev.dcf ├── co-sdo-client.dcf ├── co-sdo-server.dcf ├── co-sdo.c ├── co-sync.c ├── co-sync.dcf ├── co-test.h ├── co-time.c ├── co-time.dcf ├── coapp-fiber-master.dcf ├── coapp-fiber-slave.dcf ├── coapp-fiber.cpp ├── coapp-lss-master.dcf ├── coapp-lss-slave.dcf ├── coapp-lss.cpp ├── ev-fiber.cpp ├── ev-future.cpp ├── ev-loop.cpp ├── io-cxx.cpp ├── io-poll.c ├── io2-can_rt.cpp ├── io2-sigset.cpp ├── io2-timer.cpp ├── io2-tqueue.cpp ├── io2-vcan.cpp ├── tap.c ├── test.h ├── util-config.c ├── util-config.ini ├── util-endian.c ├── util-fbuf.c ├── util-fiber.cpp ├── util-spscring.c └── util-stop.cpp ├── tools ├── Makefile.am ├── can2udp.c ├── cocat.c ├── cocatd.c ├── cocatd.dcf ├── coctl.c ├── coctl.dcf ├── dcf2c.c └── version.dcf2c.rc.in └── unit-tests ├── .clang-format ├── Makefile.am ├── can ├── test-buf.cpp ├── test-msg.cpp └── test-net.cpp ├── co ├── holder │ ├── array-init.hpp │ ├── dev.hpp │ ├── holder.hpp │ ├── obj.hpp │ └── sub.hpp ├── test-crc.cpp ├── test-dev.cpp ├── test-obj.cpp ├── test-rpdo.cpp ├── test-type.cpp └── test-val.cpp ├── lely-cpputest-ext.hpp ├── lely-unit-test.hpp ├── override ├── call-wrapper.hpp ├── defs.hpp ├── lely-defs.hpp ├── lelyco-val.cpp ├── lelyco-val.hpp ├── libc-defs.hpp ├── libc-stdio.hpp ├── override-test-plugin.cpp └── override-test-plugin.hpp ├── test-cpputest.cpp ├── tests-shared-main.cpp └── util ├── test-bits.cpp ├── test-bitset.cpp ├── test-cmp.cpp ├── test-diag.cpp ├── test-dllist.cpp ├── test-endian.cpp ├── test-membuf.cpp ├── test-mutex.cpp ├── test-pheap.cpp ├── test-rbtree.cpp ├── test-sllist.cpp ├── test-spscring.cpp ├── test-time.cpp ├── test-ustring.cpp └── test-util.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | .clang-format.c -------------------------------------------------------------------------------- /.clang-format.c: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | AlignAfterOpenBracket: DontAlign 5 | AlignEscapedNewlines: DontAlign 6 | AlignOperands: false 7 | AlignTrailingComments: false 8 | AllowShortCaseLabelsOnASingleLine: true 9 | AlwaysBreakAfterReturnType: AllDefinitions 10 | BreakBeforeBinaryOperators: NonAssignment 11 | BreakBeforeBraces: Linux 12 | BreakStringLiterals: false 13 | ContinuationIndentWidth: 16 14 | Cpp11BracedListStyle: false 15 | ForEachMacros: 16 | - binode_foreach_by_key 17 | - binode_foreach_by_value 18 | - co_reenter 19 | - dllist_foreach 20 | - dlnode_foreach 21 | - pheap_foreach 22 | - pnode_foreach 23 | - rbnode_foreach 24 | - rbtree_foreach 25 | - sllist_foreach 26 | - slnode_foreach 27 | IndentCaseLabels: false 28 | IndentWidth: 8 29 | KeepEmptyLinesAtTheStartOfBlocks: false 30 | ReflowComments: false 31 | SpacesInContainerLiterals: false 32 | UseTab: Always 33 | ... 34 | -------------------------------------------------------------------------------- /.clang-format.cpp: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | AlignEscapedNewlines: DontAlign 5 | AlwaysBreakAfterReturnType: AllDefinitions 6 | DerivePointerAlignment: false 7 | ForEachMacros: 8 | - co_reenter 9 | PointerAlignment: Left 10 | ReflowComments: false 11 | SortIncludes: false 12 | Standard: Cpp11 13 | ... 14 | -------------------------------------------------------------------------------- /.cquery: -------------------------------------------------------------------------------- 1 | %clang 2 | %c -std=gnu11 3 | %cpp -std=gnu++11 4 | 5 | # Includes 6 | -Iinclude 7 | 8 | -DHAVE_CONFIG_H 9 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = E203, E266, E501, W503 3 | select = B,C,E,F,W,T4,B9 4 | 5 | -------------------------------------------------------------------------------- /.gcc-flags.json: -------------------------------------------------------------------------------- 1 | { 2 | "execPath": "/usr/bin/g++", 3 | "gccDefaultCFlags": "-c -x c -std=gnu11 -Wall -Wextra -pedantic -fsyntax-only -DHAVE_CONFIG_H", 4 | "gccDefaultCppFlags": "-c -std=gnu++11 -Wall -Wextra -pedantic -fsyntax-only -DHAVE_CONFIG_H", 5 | "gccIncludePaths": ".,./include", 6 | "gccSuppressWarnings": false 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /autom4te.cache/ 2 | /cov-int/ 3 | /coverage/ 4 | /doc/html/ 5 | /doc/Doxyfile 6 | /doc/doxygen_sqlite3.db 7 | /m4/libtool.m4 8 | /m4/lt~obsolete.m4 9 | /m4/ltoptions.m4 10 | /m4/ltsugar.m4 11 | /m4/ltversion.m4 12 | /python/*/build/ 13 | /python/*/dist/ 14 | /python/*/*.egg-info/ 15 | /python/*/*/*.c 16 | /test/co-nmt-master.dcf 17 | /tools/can2udp 18 | /tools/cocat 19 | /tools/cocatd 20 | /tools/coctl 21 | /tools/dcf2c 22 | /aclocal.m4 23 | /compile 24 | /compile_commands.json 25 | /config.guess 26 | /config.h 27 | /config.h.in 28 | /config.log 29 | /config.status 30 | /config.sub 31 | /configure 32 | /coverage.info 33 | /depcomp 34 | /exec-wrapper.sh 35 | /lcov-wrapper.sh 36 | /install-sh 37 | /libtool 38 | /ltmain.sh 39 | /missing 40 | /stamp-h1 41 | /tap-driver.sh 42 | /.cache/ 43 | /.vscode/ 44 | !/.vscode/c_cpp_properties.json 45 | !/.vscode/settings.json 46 | .deps 47 | .dirstamp 48 | .libs 49 | Makefile 50 | Makefile.in 51 | *~ 52 | *.dat 53 | *.def 54 | *.exe 55 | *.gcda 56 | *.gcno 57 | *.la 58 | *.lo 59 | *.o 60 | *.pc 61 | *.rc 62 | test-* 63 | unit-test-* 64 | -------------------------------------------------------------------------------- /.lgtm.yml: -------------------------------------------------------------------------------- 1 | extraction: 2 | cpp: 3 | after_prepare: 4 | - pip install --upgrade --user cython setuptools wheel 5 | - pip3 install --upgrade --user cython setuptools wheel 6 | index: 7 | build_command: 8 | - make check 9 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "defaultIncludePath": [ 4 | "${workspaceFolder}", 5 | "${workspaceFolder}/include" 6 | ] 7 | }, 8 | "configurations": [ 9 | { 10 | "name": "Linux", 11 | "intelliSenseMode": "clang-x64", 12 | "includePath": [ 13 | "${defaultIncludePath}" 14 | ], 15 | "defines": [ 16 | "HAVE_CONFIG_H", 17 | "_POSIX_C_SOURCE=200809L", 18 | "_POSIX_MAPPED_FILES=200809L" 19 | ], 20 | "compilerPath": "/usr/bin/clang", 21 | "cStandard": "c11", 22 | "cppStandard": "c++11", 23 | "browse": { 24 | "path": [ 25 | "${workspaceFolder}" 26 | ], 27 | "limitSymbolsToIncludedHeaders": true 28 | } 29 | } 30 | ], 31 | "version": 4 32 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.tabSize": 8, 3 | "editor.insertSpaces": false, 4 | "files.associations": { 5 | "*.h": "c" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | set noparent 2 | filter=-build/c++11,-build/header_guard,-build/include_order,-runtime/explicit,-runtime/references 3 | root=include 4 | headers=hpp 5 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | SUBDIRS = doc include src python pkgconfig 4 | if !NO_TOOLS 5 | SUBDIRS += tools 6 | endif 7 | if !NO_TESTS 8 | SUBDIRS += test 9 | endif 10 | if !NO_UNIT_TESTS 11 | SUBDIRS += unit-tests 12 | endif 13 | 14 | EXTRA_DIST = 15 | EXTRA_DIST += CPPLINT.cfg 16 | EXTRA_DIST += LICENSE 17 | EXTRA_DIST += NOTICE 18 | EXTRA_DIST += README.md 19 | EXTRA_DIST += suppressions.txt 20 | EXTRA_DIST += .clang-format.c 21 | EXTRA_DIST += .clang-format.cpp 22 | EXTRA_DIST += .cquery 23 | EXTRA_DIST += .gcc-flags.json 24 | 25 | if CODE_COVERAGE_ENABLED 26 | @CODE_COVERAGE_RULES@ 27 | CODE_COVERAGE_OUTPUT_FILE = coverage.info 28 | CODE_COVERAGE_OUTPUT_DIRECTORY = coverage 29 | CODE_COVERAGE_BRANCH_COVERAGE = 1 30 | CODE_COVERAGE_GENHTML_OPTIONS = $(CODE_COVERAGE_GENHTML_OPTIONS_DEFAULT) 31 | CODE_COVERAGE_GENHTML_OPTIONS += -p $(realpath $(abs_top_srcdir)) 32 | CODE_COVERAGE_GENHTML_OPTIONS += --show-details 33 | CODE_COVERAGE_GENHTML_OPTIONS += --rc genhtml_hi_limit=100 34 | CODE_COVERAGE_GENHTML_OPTIONS += --rc genhtml_med_limit=80 35 | CODE_COVERAGE_IGNORE_PATTERN = "/usr/*" "$(realpath $(abs_top_srcdir))/test/*" "$(realpath $(abs_top_srcdir))/unit-tests/*" 36 | # some options are duplicated in lcov-wrapper.sh.in 37 | endif 38 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Lely core libraries 2 | Copyright 2013-2020 Lely Industries N.V. 3 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | if HAVE_DOXYGEN 2 | 3 | html-local: Doxyfile 4 | $(DOXYGEN) 5 | 6 | install-data-local: install-html-local 7 | 8 | install-html-local: html-local 9 | if test -e html/index.html; then \ 10 | $(INSTALL) -d $(DESTDIR)$(htmldir)/html; \ 11 | $(INSTALL_DATA) -t $(DESTDIR)$(htmldir)/html html/*; \ 12 | fi 13 | 14 | clean-local: 15 | rm -rf doxygen_sqlite3.db html 16 | 17 | uninstall-local: 18 | if test -d $(DESTDIR)$(htmldir)/html; then \ 19 | rm -rf $(DESTDIR)$(htmldir)/html; \ 20 | fi 21 | 22 | endif 23 | -------------------------------------------------------------------------------- /docker/arm-none-eabi/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | gcc-arm-none-eabi \ 8 | libstdc++-arm-none-eabi-newlib \ 9 | && rm -rf /var/lib/apt/lists/* 10 | -------------------------------------------------------------------------------- /docker/build/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye 2 | 3 | RUN apt-get update -q \ 4 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 5 | build-essential \ 6 | ca-certificates \ 7 | git \ 8 | && rm -rf /var/lib/apt/lists/* 9 | 10 | RUN apt-get update -q \ 11 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 12 | python3 \ 13 | python3-empy \ 14 | python3-setuptools \ 15 | python3-wheel \ 16 | python3-yaml \ 17 | && rm -rf /var/lib/apt/lists/* 18 | 19 | RUN apt-get update -q \ 20 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 21 | libbluetooth-dev \ 22 | && rm -rf /var/lib/apt/lists/* 23 | 24 | RUN apt-get update -q \ 25 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 26 | automake \ 27 | libtool \ 28 | pkg-config \ 29 | && rm -rf /var/lib/apt/lists/* 30 | 31 | RUN git clone --branch v4.0 --depth 1 https://github.com/cpputest/cpputest.git \ 32 | && cd cpputest/cpputest_build \ 33 | && autoreconf .. -i \ 34 | && ../configure --disable-memory-leak-detection \ 35 | && make \ 36 | && make install \ 37 | && cd - \ 38 | && rm -rf cpputest 39 | -------------------------------------------------------------------------------- /docker/clang-format/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | clang-format \ 8 | && rm -rf /var/lib/apt/lists/* 9 | -------------------------------------------------------------------------------- /docker/coverity/gcc9/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/gcc:9 4 | 5 | ARG COVERITY_PROJECT 6 | ARG COVERITY_TOKEN 7 | 8 | RUN apt-get update -q \ 9 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 10 | ca-certificates \ 11 | curl \ 12 | wget \ 13 | && rm -rf /var/lib/apt/lists/* 14 | 15 | RUN wget https://scan.coverity.com/download/linux64 \ 16 | --post-data "token=$COVERITY_TOKEN&project=$COVERITY_PROJECT" \ 17 | --no-verbose \ 18 | -O coverity_tool.tgz \ 19 | && wget https://scan.coverity.com/download/linux64 \ 20 | --post-data "token=$COVERITY_TOKEN&project=$COVERITY_PROJECT&md5=1" \ 21 | --no-verbose \ 22 | -O coverity_tool.md5 \ 23 | && echo " coverity_tool.tgz" >> coverity_tool.md5 \ 24 | && md5sum -c coverity_tool.md5 \ 25 | && rm -f coverity_tool.md5 \ 26 | && tar xf coverity_tool.tgz -C /usr/local --strip-components 1 \ 27 | && rm -f coverity_tool.tgz 28 | -------------------------------------------------------------------------------- /docker/cppcheck-unix64/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | cppcheck \ 8 | && rm -rf /var/lib/apt/lists/* 9 | -------------------------------------------------------------------------------- /docker/cppcheck-win64/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/x86_64-w64-mingw32:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | cppcheck \ 8 | && rm -rf /var/lib/apt/lists/* 9 | -------------------------------------------------------------------------------- /docker/cpplint/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye 2 | 3 | RUN apt-get update -q \ 4 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 5 | ca-certificates \ 6 | git \ 7 | python2 \ 8 | && rm -rf /var/lib/apt/lists/* 9 | 10 | RUN git clone https://github.com/google/styleguide.git \ 11 | && cp styleguide/cpplint/cpplint.py /usr/local/bin \ 12 | && rm -rf styleguide 13 | -------------------------------------------------------------------------------- /docker/crossbuild/buster/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:buster 2 | 3 | ARG ARCH 4 | ARG NAME 5 | 6 | RUN apt-get update -q \ 7 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 8 | build-essential \ 9 | ca-certificates \ 10 | git \ 11 | && rm -rf /var/lib/apt/lists/* 12 | 13 | RUN dpkg --add-architecture ${ARCH} \ 14 | && apt-get update -q \ 15 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 16 | crossbuild-essential-${ARCH} \ 17 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 18 | libstdc++-8-dev:${ARCH} \ 19 | qemu-user-static \ 20 | && rm -rf /var/lib/apt/lists/* 21 | 22 | RUN apt-get update -q \ 23 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 24 | cython \ 25 | libpython-dev:${ARCH} \ 26 | python \ 27 | python-setuptools \ 28 | python-wheel \ 29 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 30 | cython3 \ 31 | libpython3-dev:${ARCH} \ 32 | python3 \ 33 | python3-empy \ 34 | python3-setuptools \ 35 | python3-wheel \ 36 | python3-yaml \ 37 | && rm -rf /var/lib/apt/lists/* 38 | 39 | RUN apt-get update -q \ 40 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 41 | libbluetooth-dev:${ARCH} \ 42 | && rm -rf /var/lib/apt/lists/* 43 | 44 | RUN apt-get update -q \ 45 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 46 | automake \ 47 | libtool \ 48 | pkg-config \ 49 | && rm -rf /var/lib/apt/lists/* 50 | 51 | RUN git clone --branch v4.0 --depth 1 https://github.com/cpputest/cpputest.git \ 52 | && cd cpputest/cpputest_build \ 53 | && autoreconf .. -i \ 54 | && ../configure --prefix=/usr/local/$NAME --host=$NAME \ 55 | && make \ 56 | && make install \ 57 | && cd - \ 58 | && rm -rf cpputest 59 | -------------------------------------------------------------------------------- /docker/doc/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | doxygen \ 8 | graphviz \ 9 | && rm -rf /var/lib/apt/lists/* 10 | -------------------------------------------------------------------------------- /docker/gcc/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG __GNUC__ 2 | 3 | FROM gcc:${__GNUC__} 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | cython3 \ 8 | libpython3-dev \ 9 | python3 \ 10 | python3-empy \ 11 | python3-setuptools \ 12 | python3-wheel \ 13 | python3-yaml \ 14 | && rm -rf /var/lib/apt/lists/* 15 | 16 | RUN apt-get update -q \ 17 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 18 | libbluetooth-dev \ 19 | && rm -rf /var/lib/apt/lists/* 20 | 21 | RUN apt-get update -q \ 22 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 23 | automake \ 24 | libtool \ 25 | pkg-config \ 26 | && rm -rf /var/lib/apt/lists/* 27 | 28 | RUN git clone --branch v4.0 --depth 1 https://github.com/cpputest/cpputest.git \ 29 | && cd cpputest/cpputest_build \ 30 | && autoreconf .. -i \ 31 | && ../configure \ 32 | && make \ 33 | && make install \ 34 | && cd - \ 35 | && rm -rf cpputest 36 | -------------------------------------------------------------------------------- /docker/lcov/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | lcov \ 8 | && rm -rf /var/lib/apt/lists/* 9 | -------------------------------------------------------------------------------- /docker/mingw-w64/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye 2 | 3 | ARG ARCH 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | apt-transport-https \ 8 | build-essential \ 9 | curl \ 10 | gnupg \ 11 | software-properties-common \ 12 | ca-certificates \ 13 | git \ 14 | && rm -rf /var/lib/apt/lists/* 15 | 16 | RUN apt-get update -q \ 17 | && curl -L https://dl.winehq.org/wine-builds/winehq.key | apt-key add - \ 18 | && apt-add-repository 'deb https://dl.winehq.org/wine-builds/debian/ bullseye main' \ 19 | && dpkg --add-architecture i386 \ 20 | && apt-get update -q \ 21 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 22 | libc6:i386 \ 23 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 24 | mingw-w64 \ 25 | winehq-stable \ 26 | && rm -rf /var/lib/apt/lists/* 27 | 28 | ENV WINEPATH Z:\\usr\\lib\\gcc\\${ARCH}-w64-mingw32\\10-posix\;Z:\\usr\\${ARCH}-w64-mingw32\\lib 29 | 30 | RUN wineboot -i 31 | 32 | RUN apt-get update -q \ 33 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 34 | automake \ 35 | libtool \ 36 | pkg-config \ 37 | && rm -rf /var/lib/apt/lists/* 38 | 39 | RUN git clone --branch v4.0 --depth 1 https://github.com/cpputest/cpputest.git \ 40 | && cd cpputest/cpputest_build \ 41 | && autoreconf .. -i \ 42 | && ../configure --host=$ARCH-w64-mingw32 --disable-memory-leak-detection \ 43 | && make \ 44 | && make install \ 45 | && cd - \ 46 | && rm -rf cpputest 47 | -------------------------------------------------------------------------------- /docker/python-checks/3.8-slim/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8-slim 2 | 3 | RUN pip install \ 4 | black \ 5 | flake8 6 | -------------------------------------------------------------------------------- /docker/scan-build/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | clang-tools \ 8 | && rm -rf /var/lib/apt/lists/* 9 | -------------------------------------------------------------------------------- /docker/sonarcloud/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | ARG SONAR_HOST_URL 6 | ARG SONAR_TOKEN 7 | ARG SONAR_SCANNER_VERSION=4.6.0.2311-linux 8 | 9 | RUN apt-get update -q \ 10 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 11 | ca-certificates \ 12 | curl \ 13 | git \ 14 | wget \ 15 | unzip \ 16 | python3 \ 17 | python3-requests \ 18 | && rm -rf /var/lib/apt/lists/* 19 | 20 | # Download sonar-scanner 21 | RUN curl -sSLo ./sonar-scanner.zip "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}.zip" \ 22 | && unzip -o sonar-scanner.zip \ 23 | && mv sonar-scanner-${SONAR_SCANNER_VERSION} /opt/sonar-scanner \ 24 | && rm sonar-scanner.zip 25 | 26 | # Download build-wrapper 27 | RUN curl -sSLo ./build-wrapper-linux-x86.zip "${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip" \ 28 | && unzip -oj build-wrapper-linux-x86.zip -d /opt/sonar-build-wrapper \ 29 | && rm build-wrapper-linux-x86.zip 30 | -------------------------------------------------------------------------------- /docker/valgrind/bullseye/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGISTRY 2 | 3 | FROM ${REGISTRY}/build:bullseye 4 | 5 | RUN apt-get update -q \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -qy --no-install-recommends \ 7 | valgrind \ 8 | && rm -rf /var/lib/apt/lists/* 9 | -------------------------------------------------------------------------------- /exec-wrapper.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SCRIPT_EXEC=@SCRIPT_EXEC@ 4 | BINFMT_EXEC=@BINFMT_EXEC@ 5 | 6 | [ -x "$1" ] || exit $? 7 | if [ "$(head -c 2 $1)" = "#!" ]; then 8 | exec $SCRIPT_EXEC "$@" 9 | else 10 | exec $BINFMT_EXEC "$@" 11 | fi 12 | 13 | -------------------------------------------------------------------------------- /include/lely/can/err.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the CAN library; it contains CAN bus error 3 | * definitions. 4 | * 5 | * @copyright 2015-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_CAN_ERR_H_ 23 | #define LELY_CAN_ERR_H_ 24 | 25 | #include 26 | 27 | /// The states of a CAN node, depending on the TX/RX error count. 28 | enum can_state { 29 | /// The error active state (TX/RX error count < 128). 30 | CAN_STATE_ACTIVE, 31 | /// The error passive state (TX/RX error count < 256). 32 | CAN_STATE_PASSIVE, 33 | /// The bus off state (TX/RX error count >= 256). 34 | CAN_STATE_BUSOFF, 35 | /// The device is in sleep mode. 36 | CAN_STATE_SLEEPING, 37 | /// The device is stopped. 38 | CAN_STATE_STOPPED 39 | }; 40 | 41 | /// The error flags of a CAN bus, which are not mutually exclusive. 42 | enum can_error { 43 | /// A single bit error. 44 | CAN_ERROR_BIT = 1u << 0, 45 | /// A bit stuffing error. 46 | CAN_ERROR_STUFF = 1u << 1, 47 | /// A CRC sequence error. 48 | CAN_ERROR_CRC = 1u << 2, 49 | /// A form error. 50 | CAN_ERROR_FORM = 1u << 3, 51 | /// An acknowledgment error. 52 | CAN_ERROR_ACK = 1u << 4, 53 | /// One or more other errors. 54 | CAN_ERROR_OTHER = 1u << 5 55 | }; 56 | 57 | #endif // !LELY_CAN_ERR_H_ 58 | -------------------------------------------------------------------------------- /include/lely/co/crc.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the CANopen library; it contains the Cyclic 3 | * Redundancy Check (CRC) declarations. 4 | * 5 | * @copyright 2016-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_CO_CRC_H_ 23 | #define LELY_CO_CRC_H_ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * Computes a CRC-16 checksum. This is an implementation of the CRC16-CCITT 36 | * specification based on the 0x1021 generator polynomial. It uses a table with 37 | * precomputed values for efficiency. 38 | * 39 | * As per section 7.2.4.3.16 in CiA 301 version 4.2.0, the CRC of "123456789" 40 | * (with an initial value of 0x0000) is 0x31c3. 41 | * 42 | * @param crc the initial value. 43 | * @param bp a pointer to the bytes to be hashed. 44 | * @param n the number of bytes to hash. 45 | * 46 | * @returns the updated CRC. 47 | */ 48 | uint_least16_t co_crc(uint_least16_t crc, const uint_least8_t *bp, size_t n); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif // !LELY_CO_CRC_H_ 55 | -------------------------------------------------------------------------------- /include/lely/co/dcf.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the CANopen library; it contains the C++ 3 | * interface of the Electronic Data Sheet (EDS) and Device Configuration File 4 | * (DCF) functions. See lely/co/dcf.h for the C interface. 5 | * 6 | * @copyright 2016-2020 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_CO_DCF_HPP_ 24 | #define LELY_CO_DCF_HPP_ 25 | 26 | #if !defined(__cplusplus) || LELY_NO_CXX 27 | #error "include for the C interface" 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | namespace lely { 34 | 35 | inline typename c_type_traits<__co_dev>::pointer 36 | c_type_traits<__co_dev>::init(pointer p, const char* filename) noexcept { 37 | return __co_dev_init_from_dcf_file(p, filename); 38 | } 39 | 40 | inline typename c_type_traits<__co_dev>::pointer 41 | c_type_traits<__co_dev>::init(pointer p, const char* begin, const char* end, 42 | floc* at) noexcept { 43 | return __co_dev_init_from_dcf_text(p, begin, end, at); 44 | } 45 | 46 | } // namespace lely 47 | 48 | #endif // !LELY_CO_DCF_HPP_ 49 | -------------------------------------------------------------------------------- /include/lely/co/def/array.def: -------------------------------------------------------------------------------- 1 | // LCOV_EXCL_START 2 | // An array of visible characters. 3 | LELY_CO_DEFINE_TYPE(VISIBLE_STRING, visible_string, vs, char *) 4 | // An array of octets. 5 | LELY_CO_DEFINE_TYPE(OCTET_STRING, octet_string, os, uint_least8_t *) 6 | // An array of (16-bit) Unicode characters. 7 | LELY_CO_DEFINE_TYPE(UNICODE_STRING, unicode_string, us, char16_t *) 8 | // An arbitrary large block of data. 9 | LELY_CO_DEFINE_TYPE(DOMAIN, domain, dom, void *) 10 | // LCOV_EXCL_STOP 11 | -------------------------------------------------------------------------------- /include/lely/co/def/basic.def: -------------------------------------------------------------------------------- 1 | // LCOV_EXCL_START 2 | // A boolean truth value. 3 | #ifdef __cplusplus 4 | LELY_CO_DEFINE_TYPE(BOOLEAN, boolean, b, bool) 5 | #else 6 | LELY_CO_DEFINE_TYPE(BOOLEAN, boolean, b, _Bool) 7 | #endif 8 | // An 8-bit signed integer. 9 | LELY_CO_DEFINE_TYPE(INTEGER8, integer8, i8, int_least8_t) 10 | // A 16-bit signed integer. 11 | LELY_CO_DEFINE_TYPE(INTEGER16, integer16, i16, int_least16_t) 12 | // A 32-bit signed integer. 13 | LELY_CO_DEFINE_TYPE(INTEGER32, integer32, i32, int_least32_t) 14 | // An 8-bit unsigned integer. 15 | LELY_CO_DEFINE_TYPE(UNSIGNED8, unsigned8, u8, uint_least8_t) 16 | // A 16-bit unsigned integer. 17 | LELY_CO_DEFINE_TYPE(UNSIGNED16, unsigned16, u16, uint_least16_t) 18 | // A 32-bit unsigned integer. 19 | LELY_CO_DEFINE_TYPE(UNSIGNED32, unsigned32, u32, uint_least32_t) 20 | // A 32-bit IEEE-754 floating-point number. 21 | LELY_CO_DEFINE_TYPE(REAL32, real32, r32, flt32_t) 22 | // A 24-bit signed integer. 23 | LELY_CO_DEFINE_TYPE(INTEGER24, integer24, i24, int_least32_t) 24 | // A 64-bit IEEE-754 floating-point number. 25 | LELY_CO_DEFINE_TYPE(REAL64, real64, r64, flt64_t) 26 | // A 40-bit signed integer. 27 | LELY_CO_DEFINE_TYPE(INTEGER40, integer40, i40, int_least64_t) 28 | // A 48-bit signed integer. 29 | LELY_CO_DEFINE_TYPE(INTEGER48, integer48, i48, int_least64_t) 30 | // A 56-bit signed integer. 31 | LELY_CO_DEFINE_TYPE(INTEGER56, integer56, i56, int_least64_t) 32 | // A 64-bit signed integer. 33 | LELY_CO_DEFINE_TYPE(INTEGER64, integer64, i64, int_least64_t) 34 | // A 24-bit unsigned integer. 35 | LELY_CO_DEFINE_TYPE(UNSIGNED24, unsigned24, u24, uint_least32_t) 36 | // A 40-bit unsigned integer. 37 | LELY_CO_DEFINE_TYPE(UNSIGNED40, unsigned40, u40, uint_least64_t) 38 | // A 48-bit unsigned integer. 39 | LELY_CO_DEFINE_TYPE(UNSIGNED48, unsigned48, u48, uint_least64_t) 40 | // A 56-bit unsigned integer. 41 | LELY_CO_DEFINE_TYPE(UNSIGNED56, unsigned56, u56, uint_least64_t) 42 | // A 64-bit unsigned integer. 43 | LELY_CO_DEFINE_TYPE(UNSIGNED64, unsigned64, u64, uint_least64_t) 44 | // LCOV_EXCL_STOP 45 | -------------------------------------------------------------------------------- /include/lely/co/def/cxx.def: -------------------------------------------------------------------------------- 1 | // LCOV_EXCL_START 2 | // A boolean truth value. 3 | LELY_CO_DEFINE_TYPE(BOOLEAN, boolean, b, bool) 4 | // An 8-bit signed integer. 5 | LELY_CO_DEFINE_TYPE(INTEGER8, integer8, i8, int_least8_t) 6 | // A 16-bit signed integer. 7 | LELY_CO_DEFINE_TYPE(INTEGER16, integer16, i16, int_least16_t) 8 | // A 32-bit signed integer. 9 | LELY_CO_DEFINE_TYPE(INTEGER32, integer32, i32, int_least32_t) 10 | // An 8-bit unsigned integer. 11 | LELY_CO_DEFINE_TYPE(UNSIGNED8, unsigned8, u8, uint_least8_t) 12 | // A 16-bit unsigned integer. 13 | LELY_CO_DEFINE_TYPE(UNSIGNED16, unsigned16, u16, uint_least16_t) 14 | // A 32-bit unsigned integer. 15 | LELY_CO_DEFINE_TYPE(UNSIGNED32, unsigned32, u32, uint_least32_t) 16 | // A 32-bit IEEE-754 floating-point number. 17 | LELY_CO_DEFINE_TYPE(REAL32, real32, r32, float) 18 | // An array of visible characters. 19 | LELY_CO_DEFINE_TYPE(VISIBLE_STRING, visible_string, vs, char*) 20 | LELY_CO_DEFINE_TYPE(VISIBLE_STRING, visible_string, vs, ::std::string) 21 | // An array of octets. 22 | LELY_CO_DEFINE_TYPE(OCTET_STRING, octet_string, os, uint_least8_t*) 23 | LELY_CO_DEFINE_TYPE(OCTET_STRING, octet_string, os, 24 | ::std::vector) 25 | // An array of (16-bit) Unicode characters. 26 | LELY_CO_DEFINE_TYPE(UNICODE_STRING, unicode_string, us, char16_t*) 27 | LELY_CO_DEFINE_TYPE(UNICODE_STRING, unicode_string, us, 28 | ::std::basic_string) 29 | // An absolute time (with respect to January 1, 1984). 30 | LELY_CO_DEFINE_TYPE(TIME_OF_DAY, time_of_day, t, co_time_of_day_t) 31 | // A time difference. 32 | LELY_CO_DEFINE_TYPE(TIME_DIFF, time_diff, td, co_time_diff_t) 33 | // An arbitrary large block of data. 34 | LELY_CO_DEFINE_TYPE(DOMAIN, domain, dom, void*) 35 | // A 64-bit IEEE-754 floating-point number. 36 | LELY_CO_DEFINE_TYPE(REAL64, real64, r64, double) 37 | // A 64-bit signed integer. 38 | LELY_CO_DEFINE_TYPE(INTEGER64, integer64, i64, int_least64_t) 39 | // A 64-bit unsigned integer. 40 | LELY_CO_DEFINE_TYPE(UNSIGNED64, unsigned64, u64, uint_least64_t) 41 | // LCOV_EXCL_STOP 42 | -------------------------------------------------------------------------------- /include/lely/co/def/time.def: -------------------------------------------------------------------------------- 1 | // LCOV_EXCL_START 2 | // An absolute time (with respect to January 1, 1984). 3 | LELY_CO_DEFINE_TYPE(TIME_OF_DAY, time_of_day, t, struct __co_time_of_day) 4 | // A time difference. 5 | LELY_CO_DEFINE_TYPE(TIME_DIFF, time_diff, td, struct __co_time_diff) 6 | // LCOV_EXCL_STOP 7 | -------------------------------------------------------------------------------- /include/lely/co/def/type.def: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /include/lely/co/sdev.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the CANopen library; it contains the C++ 3 | * interface of the static device description. See lely/co/sdev.h for the C 4 | * interface. 5 | * 6 | * @copyright 2016-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_CO_SDEV_HPP_ 24 | #define LELY_CO_SDEV_HPP_ 25 | 26 | #if !defined(__cplusplus) || LELY_NO_CXX 27 | #error "include for the C interface" 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | namespace lely { 34 | 35 | inline typename c_type_traits<__co_dev>::pointer 36 | c_type_traits<__co_dev>::init(pointer p, const co_sdev* sdev) noexcept { 37 | return __co_dev_init_from_sdev(p, sdev); 38 | } 39 | 40 | } // namespace lely 41 | 42 | #endif // !LELY_CO_SDEV_HPP_ 43 | -------------------------------------------------------------------------------- /include/lely/ev/co_task.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the event library; it contains the base class for 3 | * stackless coroutine tasks. 4 | * 5 | * @see lely/util/coroutine.hpp, lely/ev/task.h 6 | * 7 | * @copyright 2018-2020 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef LELY_EV_CO_TASK_HPP_ 25 | #define LELY_EV_CO_TASK_HPP_ 26 | 27 | #include 28 | #include 29 | 30 | namespace lely { 31 | namespace ev { 32 | 33 | /// A stackless coroutine which can be submitted to an executor as a task. 34 | class CoTask : public ev_task, public util::Coroutine { 35 | public: 36 | /// Constructs a coroutine task with an associated executor (can be nullptr). 37 | explicit CoTask(ev_exec_t* exec) noexcept 38 | : ev_task EV_TASK_INIT(exec, [](ev_task* task) noexcept { 39 | auto self = static_cast(task); 40 | (*self)(); 41 | }) {} 42 | 43 | /// Constructs a coroutine task. 44 | CoTask() noexcept : CoTask(nullptr) {} 45 | 46 | virtual ~CoTask() = default; 47 | 48 | /// Returns the executor to which the task is (to be) submitted. 49 | Executor 50 | get_executor() const noexcept { 51 | return Executor(exec); 52 | } 53 | 54 | /// The coroutine to be executed when the task is run. 55 | virtual void operator()() noexcept = 0; 56 | }; 57 | 58 | } // namespace ev 59 | } // namespace lely 60 | 61 | #endif // !LELY_EV_CO_TASK_HPP_ 62 | -------------------------------------------------------------------------------- /include/lely/ev/ev.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the public header file of the event library. 3 | * 4 | * @copyright 2018-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_EV_EV_H_ 22 | #define LELY_EV_EV_H_ 23 | 24 | #include 25 | 26 | struct ev_task; 27 | 28 | /// An abstract task executor. 29 | typedef const struct ev_exec_vtbl *const ev_exec_t; 30 | 31 | #endif // !LELY_EV_EV_H_ 32 | -------------------------------------------------------------------------------- /include/lely/ev/poll.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the event library; it contains the C++ interface 3 | * for the abstract polling interface. 4 | * 5 | * @see lely/ev/poll.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef LELY_EV_POLL_HPP_ 25 | #define LELY_EV_POLL_HPP_ 26 | 27 | #include 28 | #include 29 | 30 | namespace lely { 31 | namespace ev { 32 | 33 | /** 34 | * The abstract polling interface. This class is a wrapper around `#ev_poll_t*`. 35 | */ 36 | class Poll { 37 | public: 38 | explicit Poll(ev_poll_t* poll) noexcept : poll_(poll) {} 39 | 40 | operator ev_poll_t*() const noexcept { return poll_; } 41 | 42 | /// @see ev_poll_self() 43 | void* 44 | self() const noexcept { 45 | return ev_poll_self(*this); 46 | } 47 | 48 | /// @see ev_poll_wait() 49 | void 50 | wait(int timeout) { 51 | if (ev_poll_wait(*this, timeout) == -1) util::throw_errc("wait"); 52 | } 53 | 54 | /// @see ev_poll_kill() 55 | void 56 | kill(void* thr) { 57 | if (ev_poll_kill(*this, thr) == -1) util::throw_errc("kill"); 58 | } 59 | 60 | protected: 61 | ev_poll_t* poll_{nullptr}; 62 | }; 63 | 64 | } // namespace ev 65 | } // namespace lely 66 | 67 | #endif // !LELY_EV_POLL_HPP_ 68 | -------------------------------------------------------------------------------- /include/lely/io/pipe.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains the pipe 3 | * declarations. 4 | * 5 | * @copyright 2017-2018 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_IO_PIPE_H_ 23 | #define LELY_IO_PIPE_H_ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * Opens a pipe. 33 | * 34 | * @param handle_vector a 2-value array which, on success, contains the device 35 | * handles of the pipe. `handle_vector[0]` corresponds to 36 | * the read end and `handle_vector[1]` to the write end. 37 | * 38 | * @returns 0 on success, or -1 on error. In the latter case, the error number 39 | * can be obtained with get_errc(). 40 | */ 41 | int io_open_pipe(io_handle_t handle_vector[2]); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // !LELY_IO_PIPE_H_ 48 | -------------------------------------------------------------------------------- /include/lely/io2/can/err.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains CAN bus error 3 | * definitions. 4 | * 5 | * @copyright 2015-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_IO2_CAN_ERR_H_ 23 | #define LELY_IO2_CAN_ERR_H_ 24 | 25 | #include 26 | 27 | /// A CAN error frame. 28 | struct can_err { 29 | /** 30 | * The state of the CAN node (one of #CAN_STATE_ACTIVE, 31 | * #CAN_STATE_PASSIVE or #CAN_STATE_BUSOFF). 32 | */ 33 | int state; 34 | /** 35 | * The error flags of the CAN bus (any combination of #CAN_ERROR_BIT, 36 | * #CAN_ERROR_STUFF, #CAN_ERROR_CRC, #CAN_ERROR_FORM, #CAN_ERROR_ACK and 37 | * #CAN_ERROR_OTHER). 38 | */ 39 | int error; 40 | }; 41 | 42 | /// The static initializer for a #can_err struct. 43 | #define CAN_ERR_INIT \ 44 | { \ 45 | 0, 0 \ 46 | } 47 | 48 | #endif // !LELY_IO2_CAN_ERR_H_ 49 | -------------------------------------------------------------------------------- /include/lely/io2/can/msg.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains the CAN frame 3 | * declarations. 4 | * 5 | * @copyright 2015-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_IO2_CAN_MSG_H_ 23 | #define LELY_IO2_CAN_MSG_H_ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * Compares two CAN or CAN FD format frames. 33 | * 34 | * @returns an integer greater than, equal to, or less than 0 if the frame at 35 | * p1 is greater than, equal to, or less than the frame at p2. 36 | */ 37 | int can_msg_cmp(const void *p1, const void *p2); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif // !LELY_IO2_CAN_MSG_H_ 44 | -------------------------------------------------------------------------------- /include/lely/io2/io2.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the public header file of the I/O library. 3 | * 4 | * @copyright 2018-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_IO2_IO2_H_ 22 | #define LELY_IO2_IO2_H_ 23 | 24 | #include 25 | 26 | /// An I/O context. 27 | typedef struct io_ctx io_ctx_t; 28 | 29 | #ifndef LELY_IO_RX_TIMEOUT 30 | /// The default timeout (in milliseconds) for I/O read operations. 31 | #define LELY_IO_RX_TIMEOUT 100 32 | #endif 33 | 34 | #ifndef LELY_IO_TX_TIMEOUT 35 | /// The default timeout (in milliseconds) for I/O write operations. 36 | #define LELY_IO_TX_TIMEOUT 10 37 | #endif 38 | 39 | #endif // !LELY_IO2_IO2_H_ 40 | -------------------------------------------------------------------------------- /include/lely/io2/sys/clock.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains the standard system 3 | * clock definitions. 4 | * 5 | * @copyright 2018-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_IO2_SYS_CLOCK_H_ 23 | #define LELY_IO2_SYS_CLOCK_H_ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern const struct io_clock_realtime { 32 | const struct io_clock_vtbl *vptr; 33 | } io_clock_realtime; 34 | 35 | /// The #io_clock_t pointer representing the POSIX realtime clock. 36 | #define IO_CLOCK_REALTIME (&io_clock_realtime.vptr) 37 | 38 | extern const struct io_clock_monotonic { 39 | const struct io_clock_vtbl *vptr; 40 | } io_clock_monotonic; 41 | 42 | /// The #io_clock_t pointer representing the POSIX monotonic clock. 43 | #define IO_CLOCK_MONOTONIC (&io_clock_monotonic.vptr) 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif // !LELY_IO2_SYS_CLOCK_H_ 50 | -------------------------------------------------------------------------------- /include/lely/io2/sys/clock.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains the standard C++ 3 | * system clock definitions. 4 | * 5 | * @see lely/io2/sys/clock.h, lely/io2/clock.hpp 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef LELY_IO2_SYS_CLOCK_HPP_ 25 | #define LELY_IO2_SYS_CLOCK_HPP_ 26 | 27 | #include 28 | #include 29 | 30 | namespace lely { 31 | namespace io { 32 | 33 | /// @see IO_CLOCK_REALTIME 34 | constexpr Clock clock_realtime{IO_CLOCK_REALTIME}; 35 | 36 | /// @see IO_CLOCK_MONOTONIC 37 | constexpr Clock clock_monotonic{IO_CLOCK_MONOTONIC}; 38 | 39 | } // namespace io 40 | } // namespace lely 41 | 42 | #endif // !LELY_IO2_SYS_CLOCK_HPP_ 43 | -------------------------------------------------------------------------------- /include/lely/io2/sys/io.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains system-dependent I/O 3 | * initialization/finalization function declarations. 4 | * 5 | * @copyright 2018-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_IO2_SYS_IO_H_ 23 | #define LELY_IO2_SYS_IO_H_ 24 | 25 | #include 26 | 27 | /// The system-dependent I/O polling interface. 28 | typedef struct io_poll io_poll_t; 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * Initializes the I/O library and makes the I/O functions available for use. 36 | * This function is not thread-safe, but can be invoked multiple times, as long 37 | * as it is matched by an equal number of calls to io_fini(). 38 | * 39 | * @returns 0 on success, or -1 on error. In the latter case, the error number 40 | * can be obtained with get_errc(). 41 | */ 42 | int io_init(void); 43 | 44 | /** 45 | * Finalizes the I/O library and terminates the availability of the I/O 46 | * functions. Note that this function MUST be invoked once for each call to 47 | * io_init(). Only the last invocation will finalize the library. 48 | */ 49 | void io_fini(void); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif // !LELY_IO2_SYS_IO_H_ 56 | -------------------------------------------------------------------------------- /include/lely/io2/sys/io.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains the C++ interface 3 | * for the initialization/finalization functions. 4 | * 5 | * @see lely/io2/sys/io.h 6 | * 7 | * @copyright 2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef LELY_IO2_SYS_IO_HPP_ 25 | #define LELY_IO2_SYS_IO_HPP_ 26 | 27 | #include 28 | #include 29 | 30 | namespace lely { 31 | namespace io { 32 | 33 | /// A RAII-style wrapper around io_init() and io_fini(). 34 | class IoGuard { 35 | public: 36 | IoGuard() { 37 | if (io_init() == -1) util::throw_errc("IoGuard"); 38 | } 39 | 40 | IoGuard(const IoGuard&) = delete; 41 | IoGuard& operator=(const IoGuard&) = delete; 42 | 43 | ~IoGuard() noexcept { io_fini(); } 44 | }; 45 | 46 | } // namespace io 47 | } // namespace lely 48 | 49 | #endif // !LELY_IO2_SYS_IO_HPP_ 50 | -------------------------------------------------------------------------------- /include/lely/io2/sys/timer.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the I/O library; it contains the C++ interface 3 | * for the I/O system timer. 4 | * 5 | * @see lely/io2/sys/timer.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef LEYL_IO2_SYS_TIMER_HPP_ 25 | #define LEYL_IO2_SYS_TIMER_HPP_ 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | namespace lely { 33 | namespace io { 34 | 35 | /// An I/O system timer. 36 | class Timer : public TimerBase { 37 | public: 38 | /// @see io_timer_create() 39 | Timer(io_poll_t* poll, ev_exec_t* exec, clockid_t clockid) 40 | : TimerBase(io_timer_create(poll, exec, clockid)) { 41 | if (!timer) util::throw_errc("Timer"); 42 | } 43 | 44 | Timer(const Timer&) = delete; 45 | 46 | Timer(Timer&& other) noexcept : TimerBase(other.timer) { 47 | other.timer = nullptr; 48 | other.dev = nullptr; 49 | } 50 | 51 | Timer& operator=(const Timer&) = delete; 52 | 53 | Timer& 54 | operator=(Timer&& other) noexcept { 55 | using ::std::swap; 56 | swap(timer, other.timer); 57 | swap(dev, other.dev); 58 | return *this; 59 | } 60 | 61 | /// @see io_timer_destroy() 62 | ~Timer() { io_timer_destroy(*this); } 63 | }; 64 | 65 | } // namespace io 66 | } // namespace lely 67 | 68 | #endif // !LEYL_IO2_SYS_TIMER_HPP_ 69 | -------------------------------------------------------------------------------- /include/lely/libc/functional.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the compatibility library; it includes 3 | * `` and defines any missing functionality. 4 | * 5 | * @copyright 2018-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_LIBC_FUNCTIONAL_HPP_ 23 | #define LELY_LIBC_FUNCTIONAL_HPP_ 24 | 25 | #include 26 | #if __cplusplus <= 201703L 27 | #include 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | namespace lely { 34 | namespace compat { 35 | 36 | #if __cplusplus >= 201703L 37 | 38 | using ::std::invoke; 39 | 40 | #else // __cplusplus < 201703L 41 | 42 | /** 43 | * Invokes f with the arguments args... as if by 44 | * `INVOKE(forward(f), forward(args)...)`. 45 | */ 46 | template 47 | inline invoke_result_t 48 | invoke(F&& f, Args&&... args) { 49 | return detail::invoke(::std::forward(f), ::std::forward(args)...); 50 | } 51 | 52 | #endif // __cplusplus < 201703L 53 | 54 | } // namespace compat 55 | } // namespace lely 56 | 57 | #endif // !LELY_LIBC_FUNCTIONAL_HPP_ 58 | -------------------------------------------------------------------------------- /include/lely/libc/stddef.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the C11 and POSIX compatibility library; it 3 | * includes `` and defines any missing functionality. 4 | * 5 | * @copyright 2013-2018 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_LIBC_STDDEF_H_ 23 | #define LELY_LIBC_STDDEF_H_ 24 | 25 | #include 26 | 27 | #include 28 | 29 | #if !(__STDC_VERSION__ >= 201112L) && !(__cplusplus >= 201103L) 30 | /** 31 | * An object type whose alignment is as great as is supported by the 32 | * implementation in all contexts. 33 | */ 34 | typedef union { 35 | long long _ll; 36 | long double _ld; 37 | void *_ptr; 38 | int (*_fptr)(void); 39 | } max_align_t; 40 | #endif 41 | 42 | #endif // !LELY_LIBC_STDDEF_H_ 43 | -------------------------------------------------------------------------------- /include/lely/libc/stdint.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the C11 and POSIX compatibility library; it 3 | * includes `` and defines any missing functionality. 4 | * 5 | * @copyright 2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_LIBC_STDINT_H_ 23 | #define LELY_LIBC_STDINT_H_ 24 | 25 | #include 26 | 27 | #include 28 | 29 | #ifndef SSIZE_MAX 30 | #if __WORDSIZE == 64 31 | #define SSIZE_MAX INT_LEAST64_MAX 32 | #else 33 | #define SSIZE_MAX INT_LEAST32_MAX 34 | #endif 35 | #endif 36 | 37 | #endif // !LELY_LIBC_STDINT_H_ 38 | -------------------------------------------------------------------------------- /include/lely/libc/sys/types.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the C11 and POSIX compatibility library; it 3 | * includes ``, if it exists, and defines any missing 4 | * functionality. 5 | * 6 | * @copyright 2014-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_LIBC_SYS_TYPES_H_ 24 | #define LELY_LIBC_SYS_TYPES_H_ 25 | 26 | #include 27 | 28 | #ifndef LELY_HAVE_SYS_TYPES_H 29 | #if defined(_POSIX_C_SOURCE) || defined(__MINGW32__) || defined(__NEWLIB__) 30 | #define LELY_HAVE_SYS_TYPES_H 1 31 | #endif 32 | #endif 33 | 34 | #if LELY_HAVE_SYS_TYPES_H 35 | #include 36 | #else // !LELY_HAVE_SYS_TYPES_H 37 | #include 38 | 39 | /// Used for clock ID type in the clock and timer functions. 40 | typedef int clockid_t; 41 | 42 | /// Used for a count of bytes or an error indication. 43 | typedef ptrdiff_t ssize_t; 44 | 45 | #endif // !LELY_HAVE_SYS_TYPES_H 46 | 47 | #endif // !LELY_LIBC_SYS_TYPES_H_ 48 | -------------------------------------------------------------------------------- /include/lely/libc/uchar.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This header file is part of the C11 and POSIX compatibility library; it 3 | * includes ``, if it exists, and defines any missing functionality. 4 | * 5 | * @copyright 2014-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_LIBC_UCHAR_H_ 23 | #define LELY_LIBC_UCHAR_H_ 24 | 25 | #include 26 | 27 | #ifndef LELY_HAVE_UCHAR_H 28 | #if (__STDC_VERSION__ >= 201112L || __cplusplus >= 201103L) \ 29 | && !defined(__NEWLIB__) 30 | #define LELY_HAVE_UCHAR_H 1 31 | #endif 32 | #endif 33 | 34 | #if LELY_HAVE_UCHAR_H 35 | #include 36 | #else 37 | 38 | #include 39 | 40 | #if __cplusplus >= 201103L 41 | // char16_t and char32_t are built-in types in C++11 and later. 42 | #else 43 | 44 | #include 45 | 46 | typedef uint_least16_t char16_t; 47 | typedef uint_least32_t char32_t; 48 | 49 | #endif 50 | 51 | #endif // !LELY_HAVE_UCHAR_H 52 | 53 | #endif // !LELY_LIBC_UCHAR_H_ 54 | -------------------------------------------------------------------------------- /include/lely/util/def/type.def: -------------------------------------------------------------------------------- 1 | // Boolean truth value: 2 | #ifdef __cplusplus 3 | LELY_UTIL_DEFINE_TYPE(bool, bool) 4 | #else 5 | LELY_UTIL_DEFINE_TYPE(bool, _Bool) 6 | #endif 7 | // Integers: 8 | LELY_UTIL_DEFINE_TYPE(char, char) 9 | LELY_UTIL_DEFINE_TYPE(schar, signed char) 10 | LELY_UTIL_DEFINE_TYPE(uchar, unsigned char) 11 | LELY_UTIL_DEFINE_TYPE(shrt, short) 12 | LELY_UTIL_DEFINE_TYPE(ushrt, unsigned short) 13 | LELY_UTIL_DEFINE_TYPE(int, int) 14 | LELY_UTIL_DEFINE_TYPE(uint, unsigned int) 15 | LELY_UTIL_DEFINE_TYPE(long, long) 16 | LELY_UTIL_DEFINE_TYPE(ulong, unsigned long) 17 | LELY_UTIL_DEFINE_TYPE(llong, long long) 18 | LELY_UTIL_DEFINE_TYPE(ullong, unsigned long long) 19 | // Floating-point numbers: 20 | LELY_UTIL_DEFINE_TYPE(flt, float) 21 | LELY_UTIL_DEFINE_TYPE(dbl, double) 22 | LELY_UTIL_DEFINE_TYPE(ldbl, long double) 23 | // From stddef.h: 24 | LELY_UTIL_DEFINE_TYPE(ptrdiff, ptrdiff_t) 25 | LELY_UTIL_DEFINE_TYPE(size, size_t) 26 | LELY_UTIL_DEFINE_TYPE(wchar, wchar_t) 27 | // From stdint.h: 28 | LELY_UTIL_DEFINE_TYPE(int8, int_least8_t) 29 | LELY_UTIL_DEFINE_TYPE(uint8, uint_least8_t) 30 | LELY_UTIL_DEFINE_TYPE(int16, int_least16_t) 31 | LELY_UTIL_DEFINE_TYPE(uint16, uint_least16_t) 32 | LELY_UTIL_DEFINE_TYPE(int32, int_least32_t) 33 | LELY_UTIL_DEFINE_TYPE(uint32, uint_least32_t) 34 | LELY_UTIL_DEFINE_TYPE(int64, int_least64_t) 35 | LELY_UTIL_DEFINE_TYPE(uint64, uint_least64_t) 36 | LELY_UTIL_DEFINE_TYPE(intptr, intptr_t) 37 | LELY_UTIL_DEFINE_TYPE(uintptr, uintptr_t) 38 | LELY_UTIL_DEFINE_TYPE(intmax, intmax_t) 39 | LELY_UTIL_DEFINE_TYPE(uintmax, uintmax_t) 40 | // From uchar.h: 41 | LELY_UTIL_DEFINE_TYPE(char16, char16_t) 42 | LELY_UTIL_DEFINE_TYPE(char32, char32_t) 43 | // From wchar.h: 44 | LELY_UTIL_DEFINE_TYPE(wint, wint_t) 45 | -------------------------------------------------------------------------------- /lcov-wrapper.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LCOV=@LCOV@ 4 | GCOV=@GCOV@ 5 | DIR=@abs_top_srcdir@ 6 | 7 | VERBOSITY=--quiet 8 | 9 | DIRECTORY="--directory ${DIR}" 10 | OPTIONS=" --no-checksum --compat-libtool --rc lcov_branch_coverage=1 --gcov-tool ${GCOV}" 11 | 12 | coverage_dir="${DIR}/coverage" 13 | mkdir -p "${coverage_dir}" 14 | 15 | test_name="${TEST_NAME:-$1}" 16 | 17 | ${LCOV} ${VERBOSITY} ${DIRECTORY} --zerocounters 18 | ${EXEC_WRAPPER} $@ 19 | result=$? 20 | ${LCOV} ${VERBOSITY} ${DIRECTORY} --capture --output-file "${coverage_dir}/${test_name}.info" --test-name "${test_name}" ${OPTIONS} 21 | 22 | exit ${result} 23 | -------------------------------------------------------------------------------- /m4/ax_check_python.m4: -------------------------------------------------------------------------------- 1 | # SYNOPSIS 2 | # 3 | # AX_CHECK_PYTHON(MAJOR-VERSION[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 4 | # 5 | # DESCRIPTION 6 | # 7 | # This macro checks if the specified Python version is available. If 8 | # found, the PYTHON2 or PYTHON3 output variable points to the 9 | # corresponding interpreter binary. 10 | # 11 | # LICENSE 12 | # 13 | # Copyright (c) 2018-2020 Lely Industries N.V. 14 | # 15 | # Licensed under the Apache License, Version 2.0 (the "License"); 16 | # you may not use this file except in compliance with the License. 17 | # You may obtain a copy of the License at 18 | # 19 | # http://www.apache.org/licenses/LICENSE-2.0 20 | # 21 | # Unless required by applicable law or agreed to in writing, software 22 | # distributed under the License is distributed on an "AS IS" BASIS, 23 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | # See the License for the specific language governing permissions and 25 | # limitations under the License. 26 | 27 | AC_DEFUN([AX_CHECK_PYTHON], [ 28 | ax_python_ok=no 29 | 30 | AC_CHECK_PROGS([PYTHON$1], [python$1 python]) 31 | 32 | AS_IF([test -n "${PYTHON$1}"], [ 33 | AC_MSG_CHECKING([whether ${PYTHON$1} is version $1]) 34 | ax_python_version=$(${PYTHON$1} -V 2>&1 | grep -o 'Python @<:@0-9@:>@' | grep -o '@<:@0-9@:>@') 35 | AS_IF([test "$ax_python_version" = "$1"], [ax_python_ok=yes]) 36 | AC_MSG_RESULT([$ax_python_ok]) 37 | ]) 38 | 39 | AS_IF([test "$ax_python_ok" = "yes"], [ 40 | m4_default([$2], [:]) 41 | ], [ 42 | PYTHON$1= 43 | m4_default([$3], [:]) 44 | ]) 45 | AC_SUBST([PYTHON$1]) 46 | ]) 47 | -------------------------------------------------------------------------------- /pkgconfig/Makefile.am: -------------------------------------------------------------------------------- 1 | pkgconfigdir = $(libdir)/pkgconfig 2 | pkgconfig_DATA = 3 | pkgconfig_DATA += liblely-can.pc 4 | pkgconfig_DATA += liblely-co.pc 5 | if !ECSS_COMPLIANCE 6 | if !NO_CXX 7 | pkgconfig_DATA += liblely-coapp.pc 8 | endif 9 | pkgconfig_DATA += liblely-ev.pc 10 | pkgconfig_DATA += liblely-io.pc 11 | pkgconfig_DATA += liblely-io2.pc 12 | endif 13 | pkgconfig_DATA += liblely-libc.pc 14 | if !NO_RT 15 | pkgconfig_DATA += liblely-libc_rt.pc 16 | endif 17 | pkgconfig_DATA += liblely-tap.pc 18 | pkgconfig_DATA += liblely-util.pc 19 | -------------------------------------------------------------------------------- /pkgconfig/liblely-can.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-can 7 | Description: Lely CAN library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: 1.9.2 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ liblely-util >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-can 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-co.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-co 7 | Description: Lely CANopen library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ liblely-util >= @PACKAGE_VERSION@ liblely-can >= 1.9.2 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-co 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-coapp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-coapp 7 | Description: C++ CANopen application library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ liblely-io2 >= @PACKAGE_VERSION@ liblely-co >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-coapp 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-ev.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-ev 7 | Description: Lely event library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ liblely-util >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-ev 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-io.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-io 7 | Description: Lely I/O library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: 1.9.2 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ liblely-util >= @PACKAGE_VERSION@ liblely-can >= 1.9.2 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-io 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-io2.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-io2 7 | Description: Lely I/O library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ liblely-util >= @PACKAGE_VERSION@ liblely-can >= 1.9.2 liblely-ev >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-io2 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-libc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-libc 7 | Description: Lely C11 and POSIX compatibility library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc_rt >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-libc 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-libc_rt.pc.in: -------------------------------------------------------------------------------- 1 | Name: liblely-libc_rt 2 | Description: Realtime Extensions for the Lely C11 and POSIX compatibility library 3 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 4 | Version: @PACKAGE_VERSION@ 5 | Libs: @RT_LIBS@ 6 | -------------------------------------------------------------------------------- /pkgconfig/liblely-tap.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-tap 7 | Description: Lely Test Anything Protocol (TAP) library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-tap 13 | -------------------------------------------------------------------------------- /pkgconfig/liblely-util.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: liblely-util 7 | Description: Lely Utilities library 8 | URL: https://gitlab.com/lely_industries/@PACKAGE@ 9 | Version: @PACKAGE_VERSION@ 10 | Requires: liblely-libc >= @PACKAGE_VERSION@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -llely-util 13 | -------------------------------------------------------------------------------- /python/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = dcf-tools 2 | if !NO_CYTHON 3 | SUBDIRS += can io 4 | endif 5 | -------------------------------------------------------------------------------- /python/can/lely_can/__init__.pxd: -------------------------------------------------------------------------------- 1 | from lely_can.err cimport * 2 | from lely_can.msg cimport * 3 | 4 | -------------------------------------------------------------------------------- /python/can/lely_can/__init__.py: -------------------------------------------------------------------------------- 1 | """Python bindings for the Lely CAN library.""" 2 | 3 | __copyright__ = '2020 Lely Industries N.V.' 4 | __author__ = 'J. S. Seldenthuis ' 5 | __version__ = '2.4.0' 6 | __license__ = 'Apache-2.0' 7 | 8 | from lely_can.err import * 9 | from lely_can.msg import * 10 | -------------------------------------------------------------------------------- /python/can/lely_can/err.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "lely/can/err.h": 2 | enum can_state: 3 | _CAN_STATE_ACTIVE "CAN_STATE_ACTIVE" 4 | _CAN_STATE_PASSIVE "CAN_STATE_PASSIVE" 5 | _CAN_STATE_BUSOFF "CAN_STATE_BUSOFF" 6 | _CAN_STATE_SLEEPING "CAN_STATE_SLEEPING" 7 | _CAN_STATE_STOPPED "CAN_STATE_STOPPED" 8 | 9 | enum can_error: 10 | _CAN_ERROR_BIT "CAN_ERROR_BIT" 11 | _CAN_ERROR_STUFF "CAN_ERROR_STUFF" 12 | _CAN_ERROR_CRC "CAN_ERROR_CRC" 13 | _CAN_ERROR_FORM "CAN_ERROR_FORM" 14 | _CAN_ERROR_ACK "CAN_ERROR_ACK" 15 | _CAN_ERROR_OTHER "CAN_ERROR_OTHER" 16 | 17 | -------------------------------------------------------------------------------- /python/can/lely_can/err.pyx: -------------------------------------------------------------------------------- 1 | CAN_STATE_ACTIVE = _CAN_STATE_ACTIVE 2 | CAN_STATE_PASSIVE = _CAN_STATE_PASSIVE 3 | CAN_STATE_BUSOFF = _CAN_STATE_BUSOFF 4 | CAN_STATE_SLEEPING = _CAN_STATE_SLEEPING 5 | CAN_STATE_STOPPED = _CAN_STATE_STOPPED 6 | 7 | CAN_ERROR_BIT = _CAN_ERROR_BIT 8 | CAN_ERROR_STUFF = _CAN_ERROR_STUFF 9 | CAN_ERROR_CRC = _CAN_ERROR_CRC 10 | CAN_ERROR_FORM = _CAN_ERROR_FORM 11 | CAN_ERROR_ACK = _CAN_ERROR_ACK 12 | CAN_ERROR_OTHER = _CAN_ERROR_OTHER 13 | 14 | -------------------------------------------------------------------------------- /python/can/lely_can/msg.pxd: -------------------------------------------------------------------------------- 1 | from libc.stdint cimport * 2 | 3 | cdef extern from "lely/can/msg.h": 4 | enum: 5 | _CAN_MASK_BID "CAN_MASK_BID" 6 | _CAN_MASK_EID "CAN_MASK_EID" 7 | _CAN_FLAG_IDE "CAN_FLAG_IDE" 8 | _CAN_FLAG_RTR "CAN_FLAG_RTR" 9 | _CAN_FLAG_FDF "CAN_FLAG_FDF" 10 | _CAN_FLAG_EDL "CAN_FLAG_EDL" 11 | _CAN_FLAG_BRS "CAN_FLAG_BRS" 12 | _CAN_FLAG_ESI "CAN_FLAG_ESI" 13 | _CAN_MAX_LEN "CAN_MAX_LEN" 14 | _CANFD_MAX_LEN "CANFD_MAX_LEN" 15 | _CAN_MSG_MAX_LEN "CAN_MSG_MAX_LEN" 16 | 17 | cdef struct can_msg: 18 | uint32_t id 19 | uint8_t flags 20 | uint8_t len 21 | uint8_t data[_CAN_MSG_MAX_LEN] 22 | 23 | enum can_msg_bits_mode: 24 | _CAN_MSG_BITS_MODE_NO_STUFF "CAN_MSG_BITS_MODE_NO_STUFF" 25 | _CAN_MSG_BITS_MODE_WORST "CAN_MSG_BITS_MODE_WORST" 26 | _CAN_MSG_BITS_MODE_EXACT "CAN_MSG_BITS_MODE_EXACT" 27 | 28 | int can_msg_bits(const can_msg* msg, can_msg_bits_mode mode) nogil 29 | 30 | 31 | cdef class CANMsg(object): 32 | cdef can_msg _c_msg 33 | 34 | 35 | cdef CANMsg CANMsg_new(const can_msg* msg) 36 | 37 | -------------------------------------------------------------------------------- /python/can/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | from setuptools.extension import Extension 3 | 4 | try: 5 | from Cython.Distutils import build_ext 6 | USE_CYTHON = True 7 | except ImportError: 8 | USE_CYTHON = False 9 | 10 | import os 11 | 12 | packages = ['lely_can'] 13 | package_data = {} 14 | package_dir = {} 15 | for pkg in packages: 16 | package_data[pkg] = ['*.pxd'] 17 | package_dir[pkg] = os.path.join(*pkg.split('.')) 18 | 19 | ext = '.pyx' if USE_CYTHON else '.c' 20 | ext_modules = [] 21 | for pkg in packages: 22 | ext_modules.append(Extension( 23 | pkg + '.*', 24 | [os.path.join(*[os.path.dirname(__file__), package_dir[pkg], '*' + ext])], 25 | language='c', libraries=['lely-can'] 26 | )) 27 | 28 | if USE_CYTHON: 29 | from Cython.Build import cythonize 30 | ext_modules = cythonize(ext_modules) 31 | 32 | setup( 33 | name='lely_can', 34 | version='2.4.0', 35 | description='Python bindings for the Lely CAN library.', 36 | url='https://gitlab.com/lely_industries/lely-core', 37 | author='J. S. Seldenthuis', 38 | author_email='jseldenthuis@lely.com', 39 | license='Apache-2.0', 40 | packages=find_packages(), 41 | package_data=package_data, 42 | package_dir=package_dir, 43 | ext_modules=ext_modules 44 | ) 45 | -------------------------------------------------------------------------------- /python/dcf-tools/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | 3 | src += dcf/__init__.py 4 | src += dcf/cli.py 5 | src += dcf/device.py 6 | src += dcf/lint.py 7 | src += dcf/parse.py 8 | src += dcf/print.py 9 | 10 | src += dcf2dev/data/dev.c.em 11 | src += dcf2dev/data/dev.h.em 12 | src += dcf2dev/__init__.py 13 | src += dcf2dev/cdevice.py 14 | src += dcf2dev/cli.py 15 | 16 | src += dcfgen/data/master.dcf.em 17 | src += dcfgen/__init__.py 18 | src += dcfgen/cli.py 19 | 20 | EXTRA_DIST = $(src) 21 | EXTRA_DIST += setup.py 22 | 23 | build_base = $(realpath $(builddir))/build 24 | dist_dir = $(realpath $(builddir))/dist 25 | 26 | all-local: python-sdist python-bdist_wheel 27 | 28 | clean-local: 29 | rm -rf $(build_base) $(dist_dir) $(srcdir)/*.egg-info $(builddir)/*.egg-info 30 | 31 | install-exec-local: python-install 32 | 33 | .PHONY: python-bdist_wheel 34 | python-bdist_wheel: 35 | if HAVE_PYTHON3 36 | @$(PYTHON3_ENV) $(PYTHON3) $(srcdir)/setup.py \ 37 | bdist_wheel --dist-dir $(dist_dir) 38 | endif 39 | 40 | .PHONY: python-install 41 | python-install: 42 | if HAVE_PYTHON3 43 | @$(PYTHON3_ENV) $(PYTHON3) $(srcdir)/setup.py \ 44 | install --prefix $(DESTDIR)$(prefix) --root / 45 | endif 46 | 47 | .PHONY: python-sdist 48 | python-sdist: 49 | if HAVE_PYTHON3 50 | @cd $(srcdir); $(PYTHON3_ENV) $(PYTHON3) setup.py \ 51 | sdist --dist-dir $(dist_dir) 52 | endif 53 | -------------------------------------------------------------------------------- /python/dcf-tools/dcf/__init__.py: -------------------------------------------------------------------------------- 1 | from .device import ( # noqa: F401 2 | Device, 3 | Object, 4 | SubObject, 5 | AccessType, 6 | DataType, 7 | Value, 8 | PDO, 9 | ) 10 | from .lint import lint # noqa: F401 11 | from .parse import parse_file # noqa: F401 12 | from .print import print_rpdo, print_tpdo # noqa: F401 13 | 14 | BOOLEAN = DataType(0x0001) 15 | INTEGER8 = DataType(0x0002) 16 | INTEGER16 = DataType(0x0003) 17 | INTEGER2 = DataType(0x0004) 18 | UNSIGNED8 = DataType(0x0005) 19 | UNSIGNED16 = DataType(0x0006) 20 | UNSIGNED32 = DataType(0x0007) 21 | REAL32 = DataType(0x0008) 22 | INTEGER24 = DataType(0x0010) 23 | REAL64 = DataType(0x0011) 24 | INTEGER40 = DataType(0x0012) 25 | INTEGER48 = DataType(0x0013) 26 | INTEGER56 = DataType(0x0014) 27 | INTEGER64 = DataType(0x0015) 28 | UNSIGNED24 = DataType(0x0016) 29 | UNSIGNED40 = DataType(0x0018) 30 | UNSIGNED48 = DataType(0x0019) 31 | UNSIGNED56 = DataType(0x001A) 32 | UNSIGNED64 = DataType(0x001B) 33 | -------------------------------------------------------------------------------- /python/dcf-tools/dcf/cli.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import sys 3 | 4 | from .device import Device 5 | from .lint import lint 6 | from .parse import parse_file 7 | from .print import print_rpdo, print_tpdo 8 | 9 | 10 | def main(): 11 | parser = argparse.ArgumentParser( 12 | description="Check the validity of an EDS/DCF file." 13 | ) 14 | parser.add_argument( 15 | "-n", "--node_id", metavar="ID", type=int, default=255, help="the node-ID" 16 | ) 17 | parser.add_argument( 18 | "-p", "--print", action="store_true", help="print the PDO mappings" 19 | ) 20 | parser.add_argument( 21 | "filename", nargs=1, help="the name of the EDS/DCF file to be checked" 22 | ) 23 | args = parser.parse_args() 24 | 25 | cfg = parse_file(args.filename[0]) 26 | if not lint(cfg): 27 | sys.exit(1) 28 | 29 | env = {} 30 | if args.node_id != 255: 31 | env["NODEID"] = args.node_id 32 | dev = Device(cfg, env) 33 | 34 | if args.print: 35 | print_rpdo(dev) 36 | print_tpdo(dev) 37 | 38 | 39 | if __name__ == "__main__": 40 | main() 41 | -------------------------------------------------------------------------------- /python/dcf-tools/dcf2dev/__init__.py: -------------------------------------------------------------------------------- 1 | from .cdevice import CDevice, CObject, CSubObject, CValue # noqa: F401 2 | -------------------------------------------------------------------------------- /python/dcf-tools/dcf2dev/data/dev.h.em: -------------------------------------------------------------------------------- 1 | #ifndef @(name.upper())_H_GENERATED_ 2 | #define @(name.upper())_H_GENERATED_ 3 | 4 | #if !LELY_NO_MALLOC 5 | #error Static object dictionaries are only supported when dynamic memory allocation is disabled. 6 | #endif 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | co_dev_t * @(name)_init(void); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif // @(name.upper())_H_GENERATED_ 21 | -------------------------------------------------------------------------------- /python/dcf-tools/dcfgen/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lely-industries/lely-core/620d1858eb8520dbc3dc5e1a7314565becd54199/python/dcf-tools/dcfgen/__init__.py -------------------------------------------------------------------------------- /python/dcf-tools/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name="dcf-tools", 5 | version="2.4.0", 6 | packages=find_packages(), 7 | entry_points={ 8 | "console_scripts": [ 9 | "dcf2dev = dcf2dev.cli:main", 10 | "dcfchk = dcf.cli:main", 11 | "dcfgen = dcfgen.cli:main", 12 | ] 13 | }, 14 | install_requires=["PyYAML>=3.08", "empy>=3.3.2"], 15 | package_data={"": ["data/*"]}, 16 | author="J. S. Seldenthuis", 17 | author_email="jseldenthuis@lely.com", 18 | description="Tools to generate and manipulate DCF files", 19 | url="https://gitlab.com/lely_industries/lely-core", 20 | classifiers=["License :: OSI Approved :: Apache Software License"], 21 | ) 22 | -------------------------------------------------------------------------------- /python/io/lely_io/__init__.pxd: -------------------------------------------------------------------------------- 1 | from lely_io.addr cimport * 2 | from lely_io.attr cimport * 3 | from lely_io.can cimport * 4 | from lely_io.file cimport * 5 | from lely_io.io cimport * 6 | from lely_io.poll cimport * 7 | from lely_io.serial cimport * 8 | from lely_io.sock cimport * 9 | 10 | -------------------------------------------------------------------------------- /python/io/lely_io/__init__.py: -------------------------------------------------------------------------------- 1 | """Python bindings for the Lely I/O library.""" 2 | 3 | __copyright__ = '2020 Lely Industries N.V.' 4 | __author__ = 'J. S. Seldenthuis ' 5 | __version__ = '2.4.0' 6 | __license__ = 'Apache-2.0' 7 | 8 | from lely_io.addr import * 9 | from lely_io.attr import * 10 | from lely_io.can import * 11 | from lely_io.file import * 12 | from lely_io.io import * 13 | from lely_io.poll import * 14 | from lely_io.serial import * 15 | from lely_io.sock import * 16 | -------------------------------------------------------------------------------- /python/io/lely_io/attr.pxd: -------------------------------------------------------------------------------- 1 | from lely_io.io cimport * 2 | 3 | cdef extern from "lely/io/attr.h": 4 | enum: 5 | _IO_PARITY_NONE "IO_PARITY_NONE" 6 | _IO_PARITY_ODD "IO_PARITY_ODD" 7 | _IO_PARITY_EVEN "IO_PARITY_EVEN" 8 | 9 | int io_attr_get_speed(const io_attr_t* attr) nogil 10 | int io_attr_set_speed(io_attr_t* attr, int speed) nogil 11 | 12 | int io_attr_get_flow_control(const io_attr_t* attr) nogil 13 | int io_attr_set_flow_control(io_attr_t* attr, int flow_control) nogil 14 | 15 | int io_attr_get_parity(const io_attr_t* attr) nogil 16 | int io_attr_set_parity(io_attr_t* attr, int parity) nogil 17 | 18 | int io_attr_get_stop_bits(const io_attr_t* attr) nogil 19 | int io_attr_set_stop_bits(io_attr_t* attr, int stop_bits) nogil 20 | 21 | int io_attr_get_char_size(const io_attr_t* attr) nogil 22 | int io_attr_set_char_size(io_attr_t* attr, int char_size) nogil 23 | 24 | 25 | cdef class IOAttr(object): 26 | cdef io_attr_t _c_attr 27 | 28 | 29 | cdef IOAttr IOAttr_new(const io_attr_t* attr) 30 | 31 | -------------------------------------------------------------------------------- /python/io/lely_io/can.pxd: -------------------------------------------------------------------------------- 1 | from lely_can.err cimport * 2 | from lely_can.msg cimport * 3 | from lely_io.io cimport * 4 | 5 | cdef extern from "lely/io/can.h": 6 | io_handle_t io_open_can(const char* path) nogil 7 | 8 | int io_can_read(io_handle_t handle, can_msg* msg) nogil 9 | int io_can_write(io_handle_t handle, const can_msg* msg) nogil 10 | 11 | int io_can_start(io_handle_t handle) nogil 12 | int io_can_stop(io_handle_t handle) nogil 13 | 14 | int io_can_get_state(io_handle_t handle) nogil 15 | int io_can_get_error(io_handle_t handle, int* perror) nogil 16 | int io_can_get_ec(io_handle_t handle, uint16_t* ptxec, 17 | uint16_t* prxec) nogil 18 | 19 | int io_can_get_bitrate(io_handle_t handle, uint32_t* pbitrate) nogil 20 | int io_can_set_bitrate(io_handle_t handle, uint32_t bitrate) nogil 21 | 22 | int io_can_get_txqlen(io_handle_t handle, size_t* ptxqlen) nogil 23 | int io_can_set_txqlen(io_handle_t handle, size_t txqlen) nogil 24 | 25 | 26 | cdef class IOCAN(IOHandle): 27 | pass 28 | 29 | 30 | cdef IOCAN IOCAN_new(io_handle_t handle) 31 | 32 | -------------------------------------------------------------------------------- /python/io/lely_io/file.pxd: -------------------------------------------------------------------------------- 1 | from lely_io.io cimport * 2 | 3 | cdef extern from "lely/io/file.h": 4 | enum: 5 | _IO_FILE_READ "IO_FILE_READ" 6 | _IO_FILE_WRITE "IO_FILE_WRITE" 7 | _IO_FILE_APPEND "IO_FILE_APPEND" 8 | _IO_FILE_CREATE "IO_FILE_CREATE" 9 | _IO_FILE_NO_EXIST "IO_FILE_NO_EXIST" 10 | _IO_FILE_TRUNCATE "IO_FILE_TRUNCATE" 11 | 12 | enum: 13 | _IO_SEEK_BEGIN "IO_SEEK_BEGIN" 14 | _IO_SEEK_CURRENT "IO_SEEK_CURRENT" 15 | _IO_SEEK_END "IO_SEEK_END" 16 | 17 | io_handle_t io_open_file(const char* path, int flags) nogil 18 | 19 | io_off_t io_seek(io_handle_t handle, io_off_t offset, int whence) nogil 20 | 21 | ssize_t io_pread(io_handle_t handle, void* buf, size_t nbytes, 22 | io_off_t offset) nogil 23 | ssize_t io_pwrite(io_handle_t handle, const void* buf, size_t nbytes, 24 | io_off_t offset) nogil 25 | 26 | 27 | cdef class IOFile(IOHandle): 28 | pass 29 | 30 | 31 | cdef IOFile IOFile_new(io_handle_t handle) 32 | 33 | -------------------------------------------------------------------------------- /python/io/lely_io/io.pxd: -------------------------------------------------------------------------------- 1 | from libc.stdint cimport * 2 | 3 | cdef void io_error() except * 4 | 5 | cdef extern from "lely/io/io.h": 6 | cdef struct io_handle: 7 | pass 8 | 9 | ctypedef io_handle* io_handle_t 10 | 11 | enum: 12 | _IO_HANDLE_ERROR "IO_HANDLE_ERROR" 13 | 14 | ctypedef int64_t io_off_t 15 | 16 | cdef union __io_attr: 17 | pass 18 | 19 | ctypedef __io_attr io_attr_t 20 | 21 | cdef struct __io_addr: 22 | pass 23 | 24 | ctypedef __io_addr io_addr_t 25 | 26 | enum: 27 | _IO_TYPE_CAN "IO_TYPE_CAN" 28 | _IO_TYPE_FILE "IO_TYPE_FILE" 29 | _IO_TYPE_SERIAL "IO_TYPE_SERIAL" 30 | _IO_TYPE_SOCK "IO_TYPE_SOCK" 31 | 32 | enum: 33 | _IO_FLAG_NO_CLOSE "IO_FLAG_NO_CLOSE" 34 | _IO_FLAG_NONBLOCK "IO_FLAG_NONBLOCK" 35 | _IO_FLAG_LOOPBACK "IO_FLAG_LOOPBACK" 36 | 37 | int lely_io_init() nogil 38 | void lely_io_fini() nogil 39 | 40 | io_handle_t io_handle_acquire(io_handle_t handle) nogil 41 | void io_handle_release(io_handle_t handle) nogil 42 | int io_handle_unique(io_handle_t handle) nogil 43 | 44 | int io_close(io_handle_t handle) nogil 45 | 46 | int io_get_type(io_handle_t handle) nogil 47 | 48 | int io_get_flags(io_handle_t handle) nogil 49 | int io_set_flags(io_handle_t handle, int flags) nogil 50 | 51 | ssize_t io_read(io_handle_t handle, void* buf, size_t nbytes) nogil 52 | ssize_t io_write(io_handle_t handle, const void* buf, size_t nbytes) nogil 53 | 54 | int io_flush(io_handle_t handle) nogil 55 | 56 | 57 | cdef class IOHandle(object): 58 | cdef io_handle_t _c_handle 59 | 60 | 61 | cdef IOHandle IOHandle_new(io_handle_t handle) 62 | 63 | -------------------------------------------------------------------------------- /python/io/lely_io/pipe.pxd: -------------------------------------------------------------------------------- 1 | from lely_io.io cimport * 2 | 3 | cdef extern from "lely/io/pipe.h": 4 | int io_open_pipe(io_handle_t handle_vector[2]) nogil 5 | 6 | 7 | cdef class IOPipe(IOHandle): 8 | pass 9 | 10 | 11 | cdef IOPipe IOPipe_new(io_handle_t handle) 12 | 13 | -------------------------------------------------------------------------------- /python/io/lely_io/pipe.pyx: -------------------------------------------------------------------------------- 1 | cimport cython 2 | 3 | 4 | cdef class IOPipe(IOHandle): 5 | @staticmethod 6 | def open_pipe(): 7 | cdef io_handle_t handle_vector[2] 8 | cdef int result 9 | with nogil: 10 | result = io_open_pipe(handle_vector) 11 | if result == -1: 12 | io_error() 13 | try: 14 | return [IOPipe_new(handle_vector[0]), IOPipe_new(handle_vector[1])] 15 | except: 16 | with nogil: 17 | io_handle_release(handle_vector[1]) 18 | io_handle_release(handle_vector[0]) 19 | raise 20 | 21 | 22 | cdef IOPipe IOPipe_new(io_handle_t handle): 23 | cdef IOPipe obj = IOPipe() 24 | obj._c_handle = handle 25 | return obj 26 | 27 | -------------------------------------------------------------------------------- /python/io/lely_io/poll.pxd: -------------------------------------------------------------------------------- 1 | from lely_io.io cimport * 2 | 3 | cdef extern from "lely/io/poll.h": 4 | enum: 5 | _IO_EVENT_SIGNAL "IO_EVENT_SIGNAL" 6 | _IO_EVENT_ERROR "IO_EVENT_ERROR" 7 | _IO_EVENT_READ "IO_EVENT_READ" 8 | _IO_EVENT_WRITE "IO_EVENT_WRITE" 9 | 10 | struct io_event: 11 | int events 12 | unsigned char sig "u.sig" 13 | io_handle_t handle "u.handle" 14 | 15 | struct __io_poll: 16 | pass 17 | 18 | ctypedef __io_poll io_poll_t 19 | 20 | io_poll_t* io_poll_create() nogil 21 | void io_poll_destroy(io_poll_t* poll) nogil 22 | 23 | int io_poll_watch(io_poll_t* poll, io_handle_t handle, io_event* event, 24 | int keep) nogil 25 | int io_poll_wait(io_poll_t* poll, int maxevents, io_event* events, 26 | int timeout) nogil 27 | int io_poll_signal(io_poll_t* poll, unsigned char sig) nogil 28 | 29 | 30 | cdef class __IOEvent(object): 31 | cdef io_event* _c_event 32 | 33 | 34 | cdef __IOEvent __IOEvent_new(io_event* event) 35 | 36 | 37 | cdef class IOEvent(__IOEvent): 38 | cdef io_event __event 39 | 40 | 41 | cdef IOEvent IOEvent_new(const io_event* event) 42 | 43 | 44 | cdef class IOPoll(object): 45 | cdef io_poll_t* _c_poll 46 | 47 | -------------------------------------------------------------------------------- /python/io/lely_io/serial.pxd: -------------------------------------------------------------------------------- 1 | from lely_io.io cimport * 2 | 3 | cdef extern from "lely/io/serial.h": 4 | enum: 5 | _IO_PURGE_RX "IO_PURGE_RX" 6 | _IO_PURGE_TX "IO_PURGE_TX" 7 | 8 | io_handle_t io_open_serial(const char* path, io_attr_t* attr) nogil 9 | 10 | int io_purge(io_handle_t handle, int flags) nogil 11 | 12 | int io_serial_get_attr(io_handle_t handle, io_attr_t* attr) nogil 13 | int io_serial_set_attr(io_handle_t handle, const io_attr_t* attr) nogil 14 | 15 | 16 | cdef class IOSerial(IOHandle): 17 | pass 18 | 19 | 20 | cdef IOSerial IOSerial_new(io_handle_t handle) 21 | 22 | -------------------------------------------------------------------------------- /python/io/lely_io/serial.pyx: -------------------------------------------------------------------------------- 1 | from lely_io.attr cimport * 2 | 3 | IO_PURGE_RX = _IO_PURGE_RX 4 | IO_PURGE_TX = _IO_PURGE_TX 5 | 6 | 7 | cdef class IOSerial(IOHandle): 8 | @staticmethod 9 | def open(str path, IOAttr attr = None): 10 | cdef bytes _path = path.encode('UTF-8') 11 | cdef char* __path = _path 12 | cdef io_attr_t* _attr = NULL 13 | if attr is not None: 14 | _attr = &attr._c_attr 15 | cdef io_handle_t handle 16 | with nogil: 17 | handle = io_open_serial(__path, _attr) 18 | if handle is NULL: 19 | io_error() 20 | try: 21 | return IOSerial_new(handle) 22 | except: 23 | with nogil: 24 | io_handle_release(handle) 25 | raise 26 | 27 | def purge(self, int flags = _IO_PURGE_RX | _IO_PURGE_TX): 28 | cdef int result 29 | with nogil: 30 | result = io_purge(self._c_handle, flags) 31 | if result == -1: 32 | io_error() 33 | 34 | property attr: 35 | def __get__(self): 36 | cdef IOAttr value = IOAttr() 37 | cdef int result 38 | with nogil: 39 | result = io_serial_get_attr(self._c_handle, &value._c_attr) 40 | if result == -1: 41 | io_error() 42 | return value 43 | 44 | def __set__(self, IOAttr value not None): 45 | cdef int result 46 | with nogil: 47 | result = io_serial_set_attr(self._c_handle, &value._c_attr) 48 | if result == -1: 49 | io_error() 50 | 51 | 52 | cdef IOSerial IOSerial_new(io_handle_t handle): 53 | cdef IOSerial obj = IOSerial() 54 | obj._c_handle = handle 55 | return obj 56 | 57 | -------------------------------------------------------------------------------- /python/io/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | from setuptools.extension import Extension 3 | 4 | try: 5 | from Cython.Distutils import build_ext 6 | USE_CYTHON = True 7 | except ImportError: 8 | USE_CYTHON = False 9 | 10 | import os 11 | 12 | packages = ['lely_io'] 13 | package_data = {} 14 | package_dir = {} 15 | for pkg in packages: 16 | package_data[pkg] = ['*.pxd'] 17 | package_dir[pkg] = os.path.join(*pkg.split('.')) 18 | 19 | ext = '.pyx' if USE_CYTHON else '.c' 20 | ext_modules = [] 21 | for pkg in packages: 22 | ext_modules.append(Extension( 23 | pkg + '.*', 24 | [os.path.join(*[os.path.dirname(__file__), package_dir[pkg], '*' + ext])], 25 | language='c', libraries=['lely-io'] 26 | )) 27 | 28 | if USE_CYTHON: 29 | from Cython.Build import cythonize 30 | ext_modules = cythonize(ext_modules, include_path=['../can']) 31 | 32 | setup( 33 | name='lely_io', 34 | version='2.4.0', 35 | description='Python bindings for the Lely I/O library.', 36 | url='https://gitlab.com/lely_industries/lely-core', 37 | author='J. S. Seldenthuis', 38 | author_email='jseldenthuis@lely.com', 39 | license='Apache-2.0', 40 | packages=find_packages(), 41 | package_data=package_data, 42 | package_dir=package_dir, 43 | ext_modules=ext_modules 44 | ) 45 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = 2 | SUBDIRS += libc 3 | if !ECSS_COMPLIANCE 4 | SUBDIRS += tap 5 | endif 6 | SUBDIRS += util 7 | SUBDIRS += can 8 | SUBDIRS += co 9 | if !NO_STDIO 10 | if PLATFORM_LINUX 11 | SUBDIRS += io 12 | endif 13 | if PLATFORM_WIN32 14 | SUBDIRS += io 15 | endif 16 | endif # !NO_STDIO 17 | if !ECSS_COMPLIANCE 18 | SUBDIRS += ev 19 | SUBDIRS += io2 20 | if !NO_CXX 21 | SUBDIRS += coapp 22 | endif 23 | endif # !ECSS_COMPLIANCE 24 | -------------------------------------------------------------------------------- /src/can/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | src += buf.c 3 | src += can.h 4 | src += msg.c 5 | src += net.c 6 | if !NO_STDIO 7 | if HAVE_SOCKET_CAN 8 | src += socket.c 9 | endif 10 | if HAVE_VCI 11 | src += vci.c 12 | endif 13 | endif # !NO_STDIO 14 | if PLATFORM_WIN32 15 | src += version.rc 16 | endif 17 | 18 | lib_LTLIBRARIES = liblely-can.la 19 | liblely_can_la_CPPFLAGS = -I$(top_srcdir)/include 20 | if CODE_COVERAGE_ENABLED 21 | liblely_can_la_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS) 22 | endif 23 | liblely_can_la_CFLAGS = 24 | if CODE_COVERAGE_ENABLED 25 | liblely_can_la_CFLAGS += $(CODE_COVERAGE_CFLAGS) 26 | endif 27 | liblely_can_la_LDFLAGS = -no-undefined -version-number 1:9:2 28 | if PLATFORM_WIN32 29 | liblely_can_la_LDFLAGS += -Wl,--output-def,liblely-can-1.def 30 | endif 31 | liblely_can_la_LDFLAGS += -Wl,--as-needed 32 | liblely_can_la_LIBADD = 33 | liblely_can_la_LIBADD += $(top_builddir)/src/libc/liblely-libc.la 34 | liblely_can_la_LIBADD += $(top_builddir)/src/util/liblely-util.la 35 | if CODE_COVERAGE_ENABLED 36 | liblely_can_la_LIBADD += $(CODE_COVERAGE_LIBS) 37 | endif 38 | liblely_can_la_SOURCES = $(src) 39 | 40 | if PLATFORM_WIN32 41 | .rc.lo: 42 | $(AM_V_GEN) $(LIBTOOL) --silent --tag=RC --mode=compile $(RC) $< -o $@ 43 | if ENABLE_SHARED 44 | defdir = $(libdir) 45 | def_DATA = liblely-can-1.def 46 | MOSTLYCLEANFILES = $(def_DATA) 47 | endif 48 | endif 49 | -------------------------------------------------------------------------------- /src/can/can.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the CAN library. 3 | * 4 | * @copyright 2015-2018 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_CAN_INTERN_CAN_H_ 22 | #define LELY_CAN_INTERN_CAN_H_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | LELY_INGORE_EMPTY_TRANSLATION_UNIT 31 | 32 | #endif // !LELY_CAN_INTERN_CAN_H_ 33 | -------------------------------------------------------------------------------- /src/can/version.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,1,0,9 5 | PRODUCTVERSION 0,1,0,9 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely CAN library" 18 | VALUE "FileVersion", "1.9.2" 19 | VALUE "InternalName", "liblely-can" 20 | VALUE "LegalCopyright", "2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-can-1.dll" 22 | VALUE "ProductName", "Lely CAN library" 23 | VALUE "ProductVersion", "1.9.2" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/co/type.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen library; it contains the implementation of 3 | * the CANopen type functions. 4 | * 5 | * @see lely/co/type.h 6 | * 7 | * @copyright 2016-2018 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "co.h" 25 | #include 26 | 27 | int 28 | co_type_is_basic(co_unsigned16_t type) 29 | { 30 | switch (type) { 31 | #define LELY_CO_DEFINE_TYPE(a, b, c, d) case CO_DEFTYPE_##a: 32 | #include 33 | #undef LELY_CO_DEFINE_TYPE 34 | return 1; 35 | default: return 0; 36 | } 37 | } 38 | 39 | int 40 | co_type_is_array(co_unsigned16_t type) 41 | { 42 | switch (type) { 43 | case CO_DEFTYPE_VISIBLE_STRING: 44 | case CO_DEFTYPE_OCTET_STRING: 45 | case CO_DEFTYPE_UNICODE_STRING: 46 | case CO_DEFTYPE_DOMAIN: return 1; 47 | default: return 0; 48 | } 49 | } 50 | 51 | size_t 52 | co_type_sizeof(co_unsigned16_t type) 53 | { 54 | switch (type) { 55 | #define LELY_CO_DEFINE_TYPE(a, b, c, d) \ 56 | case CO_DEFTYPE_##a: \ 57 | return sizeof(co_##b##_t); 58 | #include 59 | #undef LELY_CO_DEFINE_TYPE 60 | default: return 0; 61 | } 62 | } 63 | 64 | size_t 65 | co_type_alignof(co_unsigned16_t type) 66 | { 67 | switch (type) { 68 | #define LELY_CO_DEFINE_TYPE(a, b, c, d) \ 69 | case CO_DEFTYPE_##a: \ 70 | return _Alignof(co_##b##_t); 71 | #include 72 | #undef LELY_CO_DEFINE_TYPE 73 | default: return 1; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/co/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely CANopen library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-co" 20 | VALUE "LegalCopyright", "2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-co-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "Lely CANopen library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | 32 | -------------------------------------------------------------------------------- /src/coapp/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | src += coapp.hpp 3 | src += device.cpp 4 | if !NO_COAPP_MASTER 5 | src += driver.cpp 6 | src += fiber_driver.cpp 7 | src += logical_driver.cpp 8 | src += loop_driver.cpp 9 | if !NO_CO_LSS 10 | src += lss_master.cpp 11 | endif 12 | src += master.cpp 13 | endif 14 | src += node.cpp 15 | src += sdo.cpp 16 | src += sdo_error.cpp 17 | if !NO_COAPP_SLAVE 18 | src += slave.cpp 19 | endif 20 | src += type_traits.cpp 21 | 22 | lib_LTLIBRARIES = liblely-coapp.la 23 | liblely_coapp_la_CPPFLAGS = -I$(top_srcdir)/include 24 | if CODE_COVERAGE_ENABLED 25 | liblely_coapp_la_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS) 26 | endif 27 | liblely_coapp_la_CXXFLAGS = 28 | if CODE_COVERAGE_ENABLED 29 | liblely_coapp_la_CXXFLAGS += $(CODE_COVERAGE_CXXFLAGS) 30 | endif 31 | liblely_coapp_la_LDFLAGS = -no-undefined -version-number $(VERSION_MAJOR):$(VERSION_MINOR):$(VERSION_PATCH) 32 | if PLATFORM_WIN32 33 | liblely_coapp_la_LDFLAGS += -Wl,--output-def,liblely-coapp-$(VERSION_MAJOR).def 34 | endif 35 | liblely_coapp_la_LDFLAGS += -Wl,--as-needed 36 | liblely_coapp_la_LIBADD = 37 | liblely_coapp_la_LIBADD += $(top_builddir)/src/libc/liblely-libc.la 38 | liblely_coapp_la_LIBADD += $(top_builddir)/src/util/liblely-util.la 39 | liblely_coapp_la_LIBADD += $(top_builddir)/src/can/liblely-can.la 40 | liblely_coapp_la_LIBADD += $(top_builddir)/src/ev/liblely-ev.la 41 | liblely_coapp_la_LIBADD += $(top_builddir)/src/io2/liblely-io2.la 42 | liblely_coapp_la_LIBADD += $(top_builddir)/src/co/liblely-co.la 43 | if CODE_COVERAGE_ENABLED 44 | liblely_coapp_la_LIBADD += $(CODE_COVERAGE_LIBS) 45 | endif 46 | liblely_coapp_la_SOURCES = $(src) 47 | if PLATFORM_WIN32 48 | nodist_liblely_coapp_la_SOURCES = version.rc 49 | endif 50 | 51 | if PLATFORM_WIN32 52 | .rc.lo: 53 | $(AM_V_GEN) $(LIBTOOL) --silent --tag=RC --mode=compile $(RC) $< -o $@ 54 | if ENABLE_SHARED 55 | defdir = $(libdir) 56 | def_DATA = liblely-coapp-$(VERSION_MAJOR).def 57 | MOSTLYCLEANFILES = $(def_DATA) 58 | endif 59 | endif 60 | -------------------------------------------------------------------------------- /src/coapp/coapp.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the C++ CANopen application library. 3 | * 4 | * @copyright 2018-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_COAPP_INTERN_COAPP_HPP_ 22 | #define LELY_COAPP_INTERN_COAPP_HPP_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | // Force the use of the C interface of the CANopen library. 31 | #undef LELY_NO_CXX 32 | #define LELY_NO_CXX 1 33 | 34 | #if LELY_NO_ERRNO || LELY_NO_MALLOC 35 | #error This file requires errno and/or dynamic memory allocation. 36 | #endif 37 | 38 | namespace lely { 39 | /// The namespace for the C++ CANopen application library. 40 | namespace canopen { 41 | /** 42 | * The namespace for implementation details of the C++ CANopen application 43 | * library. 44 | */ 45 | namespace detail {} 46 | } // namespace canopen 47 | } // namespace lely 48 | 49 | LELY_INGORE_EMPTY_TRANSLATION_UNIT 50 | 51 | #endif // LELY_COAPP_INTERN_COAPP_HPP_ 52 | -------------------------------------------------------------------------------- /src/coapp/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "C++ CANopen application library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-coapp" 20 | VALUE "LegalCopyright", "2018-2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-coapp-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "C++ CANopen application library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/ev/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | src += ev.h 3 | src += exec.c 4 | if !NO_MALLOC 5 | src += fiber_exec.c 6 | src += future.c 7 | src += loop.c 8 | endif 9 | src += poll.c 10 | if !NO_MALLOC 11 | src += std_exec.c 12 | src += strand.c 13 | endif 14 | src += task.c 15 | src += thrd_loop.c 16 | 17 | lib_LTLIBRARIES = liblely-ev.la 18 | liblely_ev_la_CPPFLAGS = -I$(top_srcdir)/include 19 | if CODE_COVERAGE_ENABLED 20 | liblely_ev_la_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS) 21 | endif 22 | liblely_ev_la_CFLAGS = 23 | if CODE_COVERAGE_ENABLED 24 | liblely_ev_la_CFLAGS += $(CODE_COVERAGE_CFLAGS) 25 | endif 26 | liblely_ev_la_CXXFLAGS = 27 | if CODE_COVERAGE_ENABLED 28 | liblely_ev_la_CXXFLAGS += $(CODE_COVERAGE_CXXFLAGS) 29 | endif 30 | liblely_ev_la_LDFLAGS = -no-undefined -version-number $(VERSION_MAJOR):$(VERSION_MINOR):$(VERSION_PATCH) 31 | if PLATFORM_WIN32 32 | liblely_ev_la_LDFLAGS += -Wl,--output-def,liblely-ev-$(VERSION_MAJOR).def 33 | endif 34 | liblely_ev_la_LDFLAGS += -Wl,--as-needed 35 | liblely_ev_la_LIBADD = 36 | liblely_ev_la_LIBADD += $(top_builddir)/src/libc/liblely-libc.la 37 | liblely_ev_la_LIBADD += $(top_builddir)/src/util/liblely-util.la 38 | if CODE_COVERAGE_ENABLED 39 | liblely_ev_la_LIBADD += $(CODE_COVERAGE_LIBS) 40 | endif 41 | liblely_ev_la_SOURCES = $(src) 42 | if PLATFORM_WIN32 43 | nodist_liblely_ev_la_SOURCES = version.rc 44 | endif 45 | 46 | if PLATFORM_WIN32 47 | .rc.lo: 48 | $(AM_V_GEN) $(LIBTOOL) --silent --tag=RC --mode=compile $(RC) $< -o $@ 49 | if ENABLE_SHARED 50 | defdir = $(libdir) 51 | def_DATA = liblely-ev-$(VERSION_MAJOR).def 52 | MOSTLYCLEANFILES = $(def_DATA) 53 | endif 54 | endif 55 | -------------------------------------------------------------------------------- /src/ev/ev.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the event library. 3 | * 4 | * @copyright 2018-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_EV_INTERN_EV_H_ 22 | #define LELY_EV_INTERN_EV_H_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | // clang-format off 32 | namespace lely { 33 | /// The global namespace for the event library. 34 | namespace ev {} 35 | } // namespace lely 36 | // clang-format on 37 | #endif 38 | 39 | LELY_INGORE_EMPTY_TRANSLATION_UNIT 40 | 41 | #endif // !LELY_EV_INTERN_EV_H_ 42 | -------------------------------------------------------------------------------- /src/ev/exec.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the event library; it exposes the abstract executor 3 | * functions. 4 | * 5 | * @see lely/ev/exec.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "ev.h" 25 | #define LELY_EV_EXEC_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/ev/poll.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the event library; it exposes the abstract polling 3 | * functions. 4 | * 5 | * @see lely/ev/poll.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "ev.h" 25 | #define LELY_EV_POLL_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/ev/task.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the event library; it contains the implementation of the 3 | * task functions. 4 | * 5 | * @see lely/ev/task.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "ev.h" 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | struct ev_task * 32 | ev_task_from_node(struct slnode *node) 33 | { 34 | return node ? structof(node, struct ev_task, _node) : NULL; 35 | } 36 | 37 | size_t 38 | ev_task_queue_post(struct sllist *queue) 39 | { 40 | size_t n = 0; 41 | 42 | struct slnode *node; 43 | while ((node = sllist_pop_front(queue))) { 44 | struct ev_task *task = ev_task_from_node(node); 45 | ev_exec_t *exec = task->exec; 46 | ev_exec_post(exec, task); 47 | ev_exec_on_task_fini(exec); 48 | n += n < SIZE_MAX; 49 | } 50 | 51 | return n; 52 | } 53 | 54 | size_t 55 | ev_task_queue_abort(struct sllist *queue) 56 | { 57 | size_t n = 0; 58 | 59 | struct slnode *node; 60 | while ((node = sllist_pop_front(queue))) { 61 | struct ev_task *task = ev_task_from_node(node); 62 | ev_exec_on_task_fini(task->exec); 63 | n += n < SIZE_MAX; 64 | } 65 | 66 | return n; 67 | } 68 | -------------------------------------------------------------------------------- /src/ev/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely event library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-ev" 20 | VALUE "LegalCopyright", "2018-2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-ev-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "Lely event library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/io/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | src += addr.c 3 | src += attr.c 4 | src += attr.h 5 | src += can.c 6 | src += default.h 7 | src += file.c 8 | src += handle.c 9 | src += handle.h 10 | src += if.c 11 | src += io.c 12 | src += io.h 13 | src += pipe.c 14 | src += poll.c 15 | if PLATFORM_LINUX 16 | src += rtnl.c 17 | src += rtnl.h 18 | endif 19 | src += serial.c 20 | src += sock.c 21 | if PLATFORM_WIN32 22 | src += version.rc 23 | endif 24 | 25 | lib_LTLIBRARIES = liblely-io.la 26 | liblely_io_la_CPPFLAGS = -I$(top_srcdir)/include 27 | if CODE_COVERAGE_ENABLED 28 | liblely_io_la_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS) 29 | endif 30 | liblely_io_la_CFLAGS = 31 | if CODE_COVERAGE_ENABLED 32 | liblely_io_la_CFLAGS += $(CODE_COVERAGE_CFLAGS) 33 | endif 34 | liblely_io_la_LDFLAGS = -no-undefined -version-number 1:9:2 35 | if PLATFORM_WIN32 36 | liblely_io_la_LDFLAGS += -Wl,--output-def,liblely-io-1.def 37 | endif 38 | liblely_io_la_LDFLAGS += -Wl,--as-needed 39 | liblely_io_la_LIBADD = 40 | liblely_io_la_LIBADD += $(top_builddir)/src/libc/liblely-libc.la 41 | liblely_io_la_LIBADD += $(top_builddir)/src/util/liblely-util.la 42 | liblely_io_la_LIBADD += $(top_builddir)/src/can/liblely-can.la 43 | if CODE_COVERAGE_ENABLED 44 | liblely_io_la_LIBADD += $(CODE_COVERAGE_LIBS) 45 | endif 46 | liblely_io_la_SOURCES = $(src) 47 | 48 | if PLATFORM_WIN32 49 | .rc.lo: 50 | $(AM_V_GEN) $(LIBTOOL) --silent --tag=RC --mode=compile $(RC) $< -o $@ 51 | if ENABLE_SHARED 52 | defdir = $(libdir) 53 | def_DATA = liblely-io-1.def 54 | MOSTLYCLEANFILES = $(def_DATA) 55 | endif 56 | endif 57 | -------------------------------------------------------------------------------- /src/io/attr.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the serial I/O attributes declarations. 3 | * 4 | * @see lely/io/attr.h 5 | * 6 | * @copyright 2016-2020 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_IO_INTERN_ATTR_H_ 24 | #define LELY_IO_INTERN_ATTR_H_ 25 | 26 | #include "io.h" 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #if _WIN32 34 | 35 | static inline LPDCB io_attr_lpDCB(const io_attr_t *attr); 36 | static inline LPCOMMTIMEOUTS io_attr_lpCommTimeouts(const io_attr_t *attr); 37 | 38 | static inline LPDCB 39 | io_attr_lpDCB(const io_attr_t *attr) 40 | { 41 | struct io_attr { 42 | DCB DCB; 43 | COMMTIMEOUTS CommTimeouts; 44 | }; 45 | 46 | return &((struct io_attr *)attr)->DCB; 47 | } 48 | 49 | static inline LPCOMMTIMEOUTS 50 | io_attr_lpCommTimeouts(const io_attr_t *attr) 51 | { 52 | struct io_attr { 53 | DCB DCB; 54 | COMMTIMEOUTS CommTimeouts; 55 | }; 56 | 57 | return &((struct io_attr *)attr)->CommTimeouts; 58 | } 59 | 60 | #endif // _WIN32 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif // !LELY_IO_INTERN_ATTR_H_ 67 | -------------------------------------------------------------------------------- /src/io/version.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,1,0,9 5 | PRODUCTVERSION 0,1,0,9 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely I/O library" 18 | VALUE "FileVersion", "1.9.2" 19 | VALUE "InternalName", "liblely-io" 20 | VALUE "LegalCopyright", "2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-io-1.dll" 22 | VALUE "ProductName", "Lely I/O library" 23 | VALUE "ProductVersion", "1.9.2" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/io2/can/msg.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the I/O library; it contains the implementation of the 3 | * CAN frame functions. 4 | * 5 | * @see lely/io2/can/msg.h 6 | * 7 | * @copyright 2015-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "../io2.h" 25 | #include 26 | 27 | #include 28 | 29 | int 30 | can_msg_cmp(const void *p1, const void *p2) 31 | { 32 | if (p1 == p2) 33 | return 0; 34 | 35 | if (!p1) 36 | return -1; 37 | if (!p2) 38 | return 1; 39 | 40 | const struct can_msg *m1 = p1; 41 | const struct can_msg *m2 = p2; 42 | 43 | int cmp; 44 | if ((cmp = (m2->id < m1->id) - (m1->id < m2->id))) 45 | return cmp; 46 | if ((cmp = (m2->flags < m1->flags) - (m1->flags < m2->flags))) 47 | return cmp; 48 | if ((cmp = (m2->len < m1->len) - (m1->len < m2->len))) 49 | return cmp; 50 | 51 | return memcmp(m1->data, m2->data, m1->len); 52 | } 53 | -------------------------------------------------------------------------------- /src/io2/clock.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the I/O library; it exposes the abstract clock 3 | * functions. 4 | * 5 | * @see lely/io2/clock.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "io2.h" 25 | #define LELY_IO_CLOCK_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/io2/dev.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the I/O library; it exposes the abstract I/O device 3 | * functions. 4 | * 5 | * @see lely/io2/dev.h 6 | * 7 | * @copyright 2018-2019 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "io2.h" 25 | #define LELY_IO_DEV_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/io2/io2.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the I/O library. 3 | * 4 | * @copyright 2018-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_IO2_INTERN_IO2_H_ 22 | #define LELY_IO2_INTERN_IO2_H_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | // clang-format off 32 | namespace lely { 33 | /// The global namespace for the I/O library. 34 | namespace io {} 35 | } // namespace lely 36 | // clang-format on 37 | #endif 38 | 39 | LELY_INGORE_EMPTY_TRANSLATION_UNIT 40 | 41 | #endif // !LELY_IO2_INTERN_IO2_H_ 42 | -------------------------------------------------------------------------------- /src/io2/linux/io.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the Linux-specific I/O declarations. 3 | * 4 | * @copyright 2018-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_IO2_INTERN_LINUX_IO_H_ 22 | #define LELY_IO2_INTERN_LINUX_IO_H_ 23 | 24 | #include "../posix/io.h" 25 | 26 | #endif // !LELY_IO2_INTERN_LINUX_IO_H_ 27 | -------------------------------------------------------------------------------- /src/io2/posix/io.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the I/O library; it contains the POSIX implementation of 3 | * the I/O initialization/finalization functions. 4 | * 5 | * @see lely/io2/sys/io.h 6 | * 7 | * @copyright 2018-2020 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "io.h" 25 | 26 | #if !LELY_NO_STDIO && defined(_POSIX_C_SOURCE) 27 | 28 | #include 29 | 30 | int 31 | io_init(void) 32 | { 33 | // POSIX platforms do not require initialization or finalization. 34 | return 0; 35 | } 36 | 37 | void 38 | io_fini(void) 39 | { 40 | // POSIX platforms do not require initialization or finalization. 41 | } 42 | 43 | #endif // !LELY_NO_STDIO && _POSIX_C_SOURCE 44 | -------------------------------------------------------------------------------- /src/io2/posix/io.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the POSIX-specific I/O declarations. 3 | * 4 | * @copyright 2018-2020 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_IO2_INTERN_POSIX_IO_H_ 22 | #define LELY_IO2_INTERN_POSIX_IO_H_ 23 | 24 | #include "../sys/io.h" 25 | 26 | #endif // !LELY_IO2_INTERN_POSIX_IO_H_ 27 | -------------------------------------------------------------------------------- /src/io2/sigset.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the signal wait operation queue 3 | * functions. 4 | * 5 | * @copyright 2018-2019 Lely Industries N.V. 6 | * 7 | * @author J. S. Seldenthuis 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef LELY_IO2_INTERN_SIGSET_H_ 23 | #define LELY_IO2_INTERN_SIGSET_H_ 24 | 25 | #include "io2.h" 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | static void io_sigset_wait_post(struct io_sigset_wait *wait, int signo); 36 | static size_t io_sigset_wait_queue_post(struct sllist *queue, int signo); 37 | 38 | static inline void 39 | io_sigset_wait_post(struct io_sigset_wait *wait, int signo) 40 | { 41 | wait->signo = signo; 42 | 43 | ev_exec_t *exec = wait->task.exec; 44 | ev_exec_post(exec, &wait->task); 45 | ev_exec_on_task_fini(exec); 46 | } 47 | 48 | static inline size_t 49 | io_sigset_wait_queue_post(struct sllist *queue, int signo) 50 | { 51 | size_t n = 0; 52 | 53 | struct slnode *node; 54 | while ((node = sllist_pop_front(queue))) { 55 | struct ev_task *task = ev_task_from_node(node); 56 | struct io_sigset_wait *wait = io_sigset_wait_from_task(task); 57 | io_sigset_wait_post(wait, signo); 58 | n += n < SIZE_MAX; 59 | } 60 | 61 | return n; 62 | } 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif // !LELY_IO2_INTERN_SIGSET_H_ 69 | -------------------------------------------------------------------------------- /src/io2/sys/io.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the I/O library; it contains the standard system 3 | * implementation of the I/O initialization/finalization functions. 4 | * 5 | * @see lely/io2/sys/io.h 6 | * 7 | * @copyright 2020 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "io.h" 25 | 26 | #if LELY_NO_STDIO || (!_WIN32 && !defined(_POSIX_C_SOURCE)) 27 | 28 | #include 29 | 30 | int 31 | io_init(void) 32 | { 33 | return 0; 34 | } 35 | 36 | void 37 | io_fini(void) 38 | { 39 | } 40 | 41 | #endif // LELY_NO_STDIO || (!_WIN32 && !_POSIX_C_SOURCE) 42 | -------------------------------------------------------------------------------- /src/io2/sys/io.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the standard system I/O declarations. 3 | * 4 | * @copyright 2020 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_IO2_INTERN_SYS_IO_H_ 22 | #define LELY_IO2_INTERN_SYS_IO_H_ 23 | 24 | #include "../io2.h" 25 | 26 | #endif // !LELY_IO2_INTERN_SYS_IO_H_ 27 | -------------------------------------------------------------------------------- /src/io2/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely I/O library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-io2" 20 | VALUE "LegalCopyright", "2018-2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-io2-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "Lely I/O library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/io2/win32/io.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the Windows-specific I/O declarations. 3 | * 4 | * @copyright 2018-2020 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_IO2_INTERN_WIN32_IO_H_ 22 | #define LELY_IO2_INTERN_WIN32_IO_H_ 23 | 24 | #include "../sys/io.h" 25 | 26 | #if _WIN32 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | typedef ULONG(NTAPI *LPFN_RTLNTSTATUSTODOSERROR)(NTSTATUS Status); 35 | extern LPFN_RTLNTSTATUSTODOSERROR lpfnRtlNtStatusToDosError; 36 | 37 | int io_win32_ntdll_init(void); 38 | void io_win32_ntdll_fini(void); 39 | 40 | int io_win32_sigset_init(void); 41 | void io_win32_sigset_fini(void); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // _WIN32 48 | 49 | #endif // LELY_IO2_INTERN_WIN32_IO_H_ 50 | -------------------------------------------------------------------------------- /src/io2/win32/ixxat.inc: -------------------------------------------------------------------------------- 1 | LELY_IO_DEFINE_IXXAT(canChannelActivate) 2 | LELY_IO_DEFINE_IXXAT(canChannelClose) 3 | LELY_IO_DEFINE_IXXAT(canChannelGetStatus) 4 | LELY_IO_DEFINE_IXXAT(canChannelInitialize) 5 | LELY_IO_DEFINE_IXXAT(canChannelOpen) 6 | LELY_IO_DEFINE_IXXAT(canChannelReadMessage) 7 | LELY_IO_DEFINE_IXXAT(canChannelSendMessage) 8 | LELY_IO_DEFINE_IXXAT(canControlClose) 9 | LELY_IO_DEFINE_IXXAT(canControlGetCaps) 10 | LELY_IO_DEFINE_IXXAT(canControlGetStatus) 11 | LELY_IO_DEFINE_IXXAT(canControlInitialize) 12 | LELY_IO_DEFINE_IXXAT(canControlOpen) 13 | LELY_IO_DEFINE_IXXAT(canControlStart) 14 | LELY_IO_DEFINE_IXXAT(vciDeviceClose) 15 | LELY_IO_DEFINE_IXXAT(vciDeviceOpen) 16 | LELY_IO_DEFINE_IXXAT(vciEnumDeviceClose) 17 | LELY_IO_DEFINE_IXXAT(vciEnumDeviceNext) 18 | LELY_IO_DEFINE_IXXAT(vciEnumDeviceOpen) 19 | -------------------------------------------------------------------------------- /src/libc/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | if !NO_RT 3 | src += clock.c 4 | endif 5 | src += getopt.c 6 | src += libc.h 7 | src += stdatomic.c 8 | if !NO_STDIO 9 | src += stdio.c 10 | endif 11 | if !NO_MALLOC 12 | if !NO_STDIO 13 | src += stdlib.c 14 | endif 15 | endif 16 | src += string.c 17 | src += strings.c 18 | if !NO_RT 19 | src += sleep.c 20 | endif 21 | if !NO_THREADS 22 | if HAVE_PTHREAD 23 | src += threads-pthread.c 24 | endif 25 | if PLATFORM_WIN32 26 | src += threads-win32.c 27 | endif 28 | endif 29 | if !NO_RT 30 | src += time.c 31 | endif 32 | 33 | lib_LTLIBRARIES = liblely-libc.la 34 | liblely_libc_la_CPPFLAGS = -I$(top_srcdir)/include 35 | if CODE_COVERAGE_ENABLED 36 | liblely_libc_la_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS) 37 | endif 38 | liblely_libc_la_CFLAGS = 39 | if CODE_COVERAGE_ENABLED 40 | liblely_libc_la_CFLAGS += $(CODE_COVERAGE_CFLAGS) 41 | endif 42 | liblely_libc_la_LDFLAGS = -no-undefined -version-number $(VERSION_MAJOR):$(VERSION_MINOR):$(VERSION_PATCH) 43 | if PLATFORM_WIN32 44 | liblely_libc_la_LDFLAGS += -Wl,--output-def,liblely-libc-$(VERSION_MAJOR).def 45 | endif 46 | liblely_libc_la_LDFLAGS += -Wl,--as-needed 47 | liblely_libc_la_LIBADD = $(RT_LIBS) 48 | if CODE_COVERAGE_ENABLED 49 | liblely_libc_la_LIBADD += $(CODE_COVERAGE_LIBS) 50 | endif 51 | liblely_libc_la_SOURCES = $(src) 52 | if PLATFORM_WIN32 53 | nodist_liblely_libc_la_SOURCES = version.rc 54 | endif 55 | 56 | if PLATFORM_WIN32 57 | .rc.lo: 58 | $(AM_V_GEN) $(LIBTOOL) --silent --tag=RC --mode=compile $(RC) $< -o $@ 59 | if ENABLE_SHARED 60 | defdir = $(libdir) 61 | def_DATA = liblely-libc-$(VERSION_MAJOR).def 62 | MOSTLYCLEANFILES = $(def_DATA) 63 | endif 64 | endif 65 | -------------------------------------------------------------------------------- /src/libc/libc.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the C11 and POSIX compatibility library. 3 | * 4 | * @copyright 2013-2019 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_LIBC_INTERN_LIBC_H_ 22 | #define LELY_LIBC_INTERN_LIBC_H_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | // clang-format off 32 | namespace lely { 33 | /// The global namespace for the compatibility library. 34 | namespace compat {} 35 | } // namespace lely 36 | // clang-format on 37 | #endif 38 | 39 | LELY_INGORE_EMPTY_TRANSLATION_UNIT 40 | 41 | #if _WIN32 42 | 43 | /** 44 | * The maximum number of milliseconds to be spent in `SleepEx()` and 45 | * `SleepConditionVariableCS()`. This value MUST be smaller than `INFINITE`, to 46 | * prevent an infinite sleep. 47 | */ 48 | #define MAX_SLEEP_MS (ULONG_MAX - 1) 49 | 50 | #endif // _WIN32 51 | 52 | #endif // !LELY_LIBC_INTERN_LIBC_H_ 53 | -------------------------------------------------------------------------------- /src/libc/sleep.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the C11 and POSIX compatibility library. 3 | * 4 | * @see lely/libc/time.h 5 | * 6 | * @copyright 2013-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include "libc.h" 24 | 25 | #include 26 | #include 27 | 28 | #if !LELY_NO_RT 29 | 30 | #if _WIN32 && !defined(__MINGW32__) 31 | 32 | #include 33 | 34 | int 35 | nanosleep(const struct timespec *rqtp, struct timespec *rmtp) 36 | { 37 | int errsv = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp); 38 | if (errsv) { 39 | errno = errsv; 40 | return -1; 41 | } 42 | return 0; 43 | } 44 | 45 | unsigned 46 | sleep(unsigned seconds) 47 | { 48 | struct timespec rqtp = { seconds, 0 }; 49 | struct timespec rmtp = { 0, 0 }; 50 | int errsv = errno; 51 | if (nanosleep(&rqtp, &rmtp) == -1) { 52 | errno = errsv; 53 | return (unsigned)rmtp.tv_sec; 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | #endif // _WIN32 && !__MINGW32__ 60 | 61 | #endif // !LELY_NO_RT 62 | -------------------------------------------------------------------------------- /src/libc/stdatomic.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the C11 and POSIX compatibility library. 3 | * 4 | * @see lely/libc/stdatomic.h 5 | * 6 | * @copyright 2013-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include "libc.h" 24 | #define LELY_LIBC_STDATOMIC_INLINE extern inline 25 | #include 26 | -------------------------------------------------------------------------------- /src/libc/string.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the C11 and POSIX compatibility library. 3 | * 4 | * @see lely/libc/string.h 5 | * 6 | * @copyright 2015-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include "libc.h" 24 | #include 25 | 26 | #if !LELY_NO_MALLOC 27 | 28 | #include 29 | 30 | #if !(_MSC_VER >= 1400) && !(_POSIX_C_SOURCE >= 200809L) \ 31 | && !defined(__MINGW32__) 32 | char * 33 | strdup(const char *s) 34 | { 35 | size_t size = strlen(s) + 1; 36 | char *dup = malloc(size); 37 | if (!dup) 38 | return NULL; 39 | return memcpy(dup, s, size); 40 | } 41 | #endif 42 | 43 | #if !(_POSIX_C_SOURCE >= 200809L) 44 | char * 45 | strndup(const char *s, size_t size) 46 | { 47 | size = strnlen(s, size); 48 | char *dup = malloc(size + 1); 49 | if (!dup) 50 | return NULL; 51 | dup[size] = '\0'; 52 | return memcpy(dup, s, size); 53 | } 54 | #endif 55 | 56 | #endif // !LELY_NO_MALLOC 57 | 58 | #if !(_MSC_VER >= 1400) && !(_POSIX_C_SOURCE >= 200809L) \ 59 | && !defined(__MINGW32__) 60 | size_t 61 | strnlen(const char *s, size_t maxlen) 62 | { 63 | size_t size = 0; 64 | while (size < maxlen && *s++) 65 | size++; 66 | return size; 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /src/libc/time.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the C11 and POSIX compatibility library. 3 | * 4 | * @see lely/libc/time.h 5 | * 6 | * @copyright 2013-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include "libc.h" 24 | 25 | #if !LELY_NO_RT 26 | 27 | #include 28 | 29 | #if !LELY_HAVE_TIMESPEC_GET 30 | 31 | int 32 | timespec_get(struct timespec *ts, int base) 33 | { 34 | if (base != TIME_UTC || clock_gettime(CLOCK_REALTIME, ts) == -1) 35 | return 0; 36 | return base; 37 | } 38 | 39 | #endif // !LELY_HAVE_TIMESPEC_GET 40 | 41 | #endif // !LELY_NO_RT 42 | -------------------------------------------------------------------------------- /src/libc/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely C11 and POSIX compatibility library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-libc" 20 | VALUE "LegalCopyright", "2013-2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-libc-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "Lely C11 and POSIX compatibility library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/tap/Makefile.am: -------------------------------------------------------------------------------- 1 | src = 2 | src += tap.c 3 | src += tap.h 4 | 5 | lib_LTLIBRARIES = liblely-tap.la 6 | liblely_tap_la_CPPFLAGS = -I$(top_srcdir)/include 7 | if CODE_COVERAGE_ENABLED 8 | liblely_tap_la_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS) 9 | endif 10 | liblely_tap_la_CFLAGS = 11 | if CODE_COVERAGE_ENABLED 12 | liblely_tap_la_CFLAGS += $(CODE_COVERAGE_CFLAGS) 13 | endif 14 | liblely_tap_la_LDFLAGS = -no-undefined -version-number $(VERSION_MAJOR):$(VERSION_MINOR):$(VERSION_PATCH) 15 | if PLATFORM_WIN32 16 | liblely_tap_la_LDFLAGS += -Wl,--output-def,liblely-tap-$(VERSION_MAJOR).def 17 | endif 18 | liblely_tap_la_LDFLAGS += -Wl,--as-needed 19 | liblely_tap_la_LIBADD = 20 | liblely_tap_la_LIBADD += $(top_builddir)/src/libc/liblely-libc.la 21 | if CODE_COVERAGE_ENABLED 22 | liblely_tap_la_LIBADD += $(CODE_COVERAGE_LIBS) 23 | endif 24 | liblely_tap_la_SOURCES = $(src) 25 | if PLATFORM_WIN32 26 | nodist_liblely_tap_la_SOURCES = version.rc 27 | endif 28 | 29 | if PLATFORM_WIN32 30 | .rc.lo: 31 | $(AM_V_GEN) $(LIBTOOL) --silent --tag=RC --mode=compile $(RC) $< -o $@ 32 | if ENABLE_SHARED 33 | defdir = $(libdir) 34 | def_DATA = liblely-tap-$(VERSION_MAJOR).def 35 | MOSTLYCLEANFILES = $(def_DATA) 36 | endif 37 | endif 38 | -------------------------------------------------------------------------------- /src/tap/tap.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the Test Anything Protocol (TAP) library. 3 | * 4 | * @copyright 2013-2018 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_TAP_INTERN_TAP_H_ 22 | #define LELY_TAP_INTERN_TAP_H_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | LELY_INGORE_EMPTY_TRANSLATION_UNIT 31 | 32 | #endif // !LELY_TAP_INTERN_TAP_H_ 33 | -------------------------------------------------------------------------------- /src/tap/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely Test Anything Protocol (TAP) library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-tap" 20 | VALUE "LegalCopyright", "2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-tap-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "Lely Test Anything Protocol (TAP) library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /src/util/bimap.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the utilities library; it exposes the bidirectional map 3 | * functions. 4 | * 5 | * @see lely/util/bimap.h 6 | * 7 | * @copyright 2016-2018 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "util.h" 25 | #define LELY_UTIL_BIMAP_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/util/cmp.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the utilities library; it exposes thecomparison 3 | * functions. 4 | * 5 | * @see lely/util/cmp.h 6 | * 7 | * @copyright 2016-2018 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "util.h" 25 | #define LELY_UTIL_CMP_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/util/dllist.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the utilities library; it exposes the doubly-linked list 3 | * functions. 4 | * 5 | * @see lely/util/dllist.h 6 | * 7 | * @copyright 2013-2020 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "util.h" 25 | #define LELY_UTIL_DLLIST_INLINE extern inline 26 | #include 27 | 28 | #include 29 | 30 | int 31 | dllist_contains(const struct dllist *list, const struct dlnode *node) 32 | { 33 | assert(list); 34 | 35 | if (!node) 36 | return 0; 37 | 38 | dllist_foreach (list, node_) { 39 | if (node_ == node) 40 | return 1; 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/util/exception.cpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the utilities library; it contains the implementation of 3 | * the C++ exception functions. 4 | * 5 | * @see lely/util/exception.hpp 6 | * 7 | * @copyright 2016-2020 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | // NOLINTNEXTLINE(build/include) 25 | #include "util.h" 26 | 27 | #if !LELY_NO_CXX 28 | 29 | #include 30 | 31 | #include 32 | 33 | extern "C" { 34 | 35 | _Noreturn void 36 | __throw_or_abort(const char* what) noexcept { 37 | (void)what; 38 | 39 | ::std::abort(); 40 | } 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/util/time.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the utilities library; it exposes the time functions. 3 | * 4 | * @see lely/util/time.h 5 | * 6 | * @copyright 2013-2018 Lely Industries N.V. 7 | * 8 | * @author J. S. Seldenthuis 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include "util.h" 24 | #define LELY_UTIL_TIME_INLINE extern inline 25 | #include 26 | -------------------------------------------------------------------------------- /src/util/ustring.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the utilities library; it exposes the (16-bit) Unicode 3 | * string functions. 4 | * 5 | * @see lely/util/ustring.h 6 | * 7 | * @copyright 2020 Lely Industries N.V. 8 | * 9 | * @author J. S. Seldenthuis 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #include "util.h" 25 | #define LELY_UTIL_USTRING_INLINE extern inline 26 | #include 27 | -------------------------------------------------------------------------------- /src/util/util.h: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This is the internal header file of the utilities library. 3 | * 4 | * @copyright 2013-2020 Lely Industries N.V. 5 | * 6 | * @author J. S. Seldenthuis 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef LELY_UTIL_INTERN_UTIL_H_ 22 | #define LELY_UTIL_INTERN_UTIL_H_ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #if _WIN32 31 | #include 32 | #elif defined(_POSIX_C_SOURCE) 33 | #include 34 | #endif 35 | 36 | #ifndef ALIGNED_ALLOC_BITS 37 | /** 38 | * The minimum alignment (in bits) of heap-allocated objects. This corresponds 39 | * to the number of least-significant bits in a pointer guaranteed to be zero. 40 | */ 41 | #if __WORDSIZE == 64 42 | #define ALIGNED_ALLOC_BITS 4 43 | #else 44 | #define ALIGNED_ALLOC_BITS 3 45 | #endif 46 | #endif 47 | 48 | #ifndef ALIGNED_ALLOC_SIZE 49 | /// The minimum alignment (in bytes) of heap-allocated objects. 50 | #define ALIGNED_ALLOC_SIZE ((size_t)(1 << (ALIGNED_ALLOC_BITS))) 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | // clang-format off 55 | namespace lely { 56 | /// The global namespace for the utilities library. 57 | namespace util {} 58 | } // namespace lely 59 | // clang-format on 60 | #endif 61 | 62 | #endif // !LELY_UTIL_INTERN_UTIL_H_ 63 | -------------------------------------------------------------------------------- /src/util/version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "Lely Utilities library" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "liblely-util" 20 | VALUE "LegalCopyright", "2020 Lely Industries N.V." 21 | VALUE "OriginalFilename", "liblely-util-@VERSION_MAJOR@.dll" 22 | VALUE "ProductName", "Lely Utilities library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | -------------------------------------------------------------------------------- /suppressions.txt: -------------------------------------------------------------------------------- 1 | *:/usr/* 2 | *:include/lely/co/def/* 3 | shadowArgument 4 | shadowVariable 5 | unreadVariable 6 | missingIncludeSystem 7 | -------------------------------------------------------------------------------- /test/can-net.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | 4 | #define MSG_ID 0x123 5 | 6 | int can_recv(const struct can_msg *msg, void *data); 7 | 8 | int 9 | main(void) 10 | { 11 | tap_plan(8); 12 | 13 | can_net_t *net = can_net_create(); 14 | tap_assert(net); 15 | 16 | can_recv_t *r1 = can_recv_create(); 17 | tap_assert(r1); 18 | can_recv_set_func(r1, &can_recv, (void *)(uintptr_t)1); 19 | 20 | can_recv_t *r2 = can_recv_create(); 21 | tap_assert(r2); 22 | can_recv_set_func(r2, &can_recv, (void *)(uintptr_t)2); 23 | 24 | struct can_msg msg = CAN_MSG_INIT; 25 | msg.id = MSG_ID; 26 | 27 | can_recv_start(r1, net, MSG_ID, 0); 28 | can_net_recv(net, &msg); 29 | 30 | can_recv_start(r2, net, MSG_ID, 0); 31 | can_net_recv(net, &msg); 32 | 33 | can_recv_stop(r2); 34 | can_net_recv(net, &msg); 35 | 36 | can_recv_stop(r1); 37 | can_net_recv(net, &msg); 38 | 39 | can_recv_start(r1, net, MSG_ID, 0); 40 | can_net_recv(net, &msg); 41 | 42 | can_recv_start(r2, net, MSG_ID, 0); 43 | can_net_recv(net, &msg); 44 | 45 | can_recv_stop(r1); 46 | can_net_recv(net, &msg); 47 | 48 | can_recv_stop(r2); 49 | can_net_recv(net, &msg); 50 | 51 | can_recv_destroy(r2); 52 | can_recv_destroy(r1); 53 | 54 | can_net_destroy(net); 55 | 56 | return 0; 57 | } 58 | 59 | int 60 | can_recv(const struct can_msg *msg, void *data) 61 | { 62 | tap_pass("#%d received 0x%03x", (int)(uintptr_t)data, msg->id); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /test/co-cxx.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #if !LELY_NO_CO_CSDO 3 | #include 4 | #endif 5 | #if !LELY_NO_CO_DCF 6 | #include 7 | #endif 8 | #include 9 | #if !LELY_NO_CO_EMCY 10 | #include 11 | #endif 12 | #if !LELY_NO_CO_GW 13 | #include 14 | #endif 15 | #if !LELY_NO_CO_GW_TXT 16 | #include 17 | #endif 18 | #if !LELY_NO_CO_LSS 19 | #include 20 | #endif 21 | #include 22 | #include 23 | #if !LELY_NO_CO_RPDO 24 | #include 25 | #endif 26 | #if !LELY_NO_CO_SDEV 27 | #include 28 | #endif 29 | #include 30 | #if !LELY_NO_CO_SYNC 31 | #include 32 | #endif 33 | #if !LELY_NO_CO_TIME 34 | #include 35 | #endif 36 | #if !LELY_NO_CO_RPDO 37 | #include 38 | #endif 39 | #include 40 | #include 41 | #if !LELY_NO_CO_WTM 42 | #include 43 | #endif 44 | 45 | int 46 | main() { 47 | tap_plan(0); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /test/co-emcy.c: -------------------------------------------------------------------------------- 1 | #include "co-test.h" 2 | #include 3 | #include 4 | 5 | void emcy_ind(co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t ec, 6 | co_unsigned8_t er, co_unsigned8_t msef[5], void *data); 7 | 8 | int 9 | main(void) 10 | { 11 | tap_plan(10); 12 | 13 | #if !LELY_NO_STDIO && !LELY_NO_DIAG 14 | diag_set_handler(&co_test_diag_handler, NULL); 15 | diag_at_set_handler(&co_test_diag_at_handler, NULL); 16 | #endif 17 | 18 | can_net_t *net = can_net_create(); 19 | tap_assert(net); 20 | struct co_test test; 21 | co_test_init(&test, net, 0); 22 | 23 | co_dev_t *dev = co_dev_create_from_dcf_file(TEST_SRCDIR "/co-emcy.dcf"); 24 | tap_assert(dev); 25 | co_emcy_t *emcy = co_emcy_create(net, dev); 26 | tap_assert(emcy); 27 | 28 | co_emcy_set_ind(emcy, &emcy_ind, &test); 29 | 30 | co_emcy_push(emcy, 0x1000, 0x00, NULL); 31 | co_test_wait(&test); 32 | co_emcy_push(emcy, 0x2000, 0x02, NULL); 33 | co_test_wait(&test); 34 | co_emcy_push(emcy, 0x3000, 0x04, NULL); 35 | co_test_wait(&test); 36 | co_emcy_push(emcy, 0x4000, 0x08, NULL); 37 | co_test_wait(&test); 38 | co_emcy_push(emcy, 0x8100, 0x10, NULL); 39 | co_test_wait(&test); 40 | 41 | co_emcy_pop(emcy, NULL, NULL); 42 | co_test_wait(&test); 43 | co_emcy_pop(emcy, NULL, NULL); 44 | co_test_wait(&test); 45 | co_emcy_pop(emcy, NULL, NULL); 46 | co_test_wait(&test); 47 | co_emcy_pop(emcy, NULL, NULL); 48 | co_test_wait(&test); 49 | co_emcy_pop(emcy, NULL, NULL); 50 | co_test_wait(&test); 51 | 52 | co_emcy_destroy(emcy); 53 | co_dev_destroy(dev); 54 | 55 | co_test_fini(&test); 56 | can_net_destroy(net); 57 | 58 | return 0; 59 | } 60 | 61 | void 62 | emcy_ind(co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t ec, 63 | co_unsigned8_t er, co_unsigned8_t msef[5], void *data) 64 | { 65 | (void)emcy; 66 | (void)msef; 67 | struct co_test *test = data; 68 | 69 | tap_pass("received EMCY [%d: %04X (%02X)]", id, ec, er); 70 | 71 | co_test_done(test); 72 | } 73 | -------------------------------------------------------------------------------- /test/co-emcy.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName=Lely Industries N.V. 3 | VendorNumber=0x00000360 4 | BaudRate_10=1 5 | BaudRate_20=1 6 | BaudRate_50=1 7 | BaudRate_125=1 8 | BaudRate_250=1 9 | BaudRate_500=1 10 | BaudRate_800=1 11 | BaudRate_1000=1 12 | 13 | [DeviceComissioning] 14 | NodeID=0x01 15 | 16 | [MandatoryObjects] 17 | SupportedObjects=3 18 | 1=0x1000 19 | 2=0x1001 20 | 3=0x1018 21 | 22 | [OptionalObjects] 23 | SupportedObjects=4 24 | 1=0x1003 25 | 2=0x1014 26 | 3=0x1015 27 | 4=0x1028 28 | 29 | [ManufacturerObjects] 30 | SupportedObjects=0 31 | 32 | [1000] 33 | ParameterName=Device type 34 | DataType=0x0007 35 | AccessType=ro 36 | 37 | [1001] 38 | ParameterName=Error register 39 | DataType=0x0005 40 | AccessType=ro 41 | 42 | [1003] 43 | ParameterName=Pre-defined error field 44 | ObjectType=0x08 45 | DataType=0x0007 46 | AccessType=rw 47 | CompactSubObj=10 48 | 49 | [1014] 50 | ParameterName=COB-ID EMCY 51 | DataType=0x0007 52 | AccessType=rw 53 | DefaultValue=$NODEID+0x80 54 | 55 | [1015] 56 | ParameterName=Inhibit time EMCY 57 | DataType=0x0006 58 | AccessType=rw 59 | DefaultValue=1000 60 | 61 | [1018] 62 | SubNumber=5 63 | ParameterName=Identity object 64 | ObjectType=0x09 65 | 66 | [1018sub0] 67 | ParameterName=Highest sub-index supported 68 | DataType=0x0005 69 | AccessType=const 70 | DefaultValue=0x4 71 | 72 | [1018sub1] 73 | ParameterName=Vendor-ID 74 | DataType=0x0007 75 | AccessType=ro 76 | DefaultValue=0x00000360 77 | 78 | [1018sub2] 79 | ParameterName=Product code 80 | DataType=0x0007 81 | AccessType=ro 82 | 83 | [1018sub3] 84 | ParameterName=Revision number 85 | DataType=0x0007 86 | AccessType=ro 87 | 88 | [1018sub4] 89 | ParameterName=Serial number 90 | DataType=0x0007 91 | AccessType=ro 92 | 93 | [1028] 94 | ParameterName=Emergency consumer object 95 | ObjectType=0x08 96 | DataType=0x0007 97 | AccessType=rw 98 | CompactSubObj=127 99 | DefaultValue=0x80000000 100 | 101 | [1028Value] 102 | NrOfEntries=1 103 | 1=0x00000081 104 | 105 | -------------------------------------------------------------------------------- /test/co-nmt-master.dat: -------------------------------------------------------------------------------- 1 | Hello, world! 2 | -------------------------------------------------------------------------------- /test/co-pdo.c: -------------------------------------------------------------------------------- 1 | #include "co-test.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define VAL_2000 0x01234567u 7 | #define VAL_2001 0x89abcdefu 8 | 9 | int 10 | main(void) 11 | { 12 | tap_plan(6); 13 | 14 | #if !LELY_NO_STDIO && !LELY_NO_DIAG 15 | diag_set_handler(&co_test_diag_handler, NULL); 16 | diag_at_set_handler(&co_test_diag_at_handler, NULL); 17 | #endif 18 | 19 | can_net_t *net = can_net_create(); 20 | tap_assert(net); 21 | struct co_test test; 22 | co_test_init(&test, net, 0); 23 | 24 | co_dev_t *rdev = co_dev_create_from_dcf_file( 25 | TEST_SRCDIR "/co-pdo-receive.dcf"); 26 | tap_assert(rdev); 27 | co_rpdo_t *rpdo = co_rpdo_create(net, rdev, 1); 28 | tap_assert(rpdo); 29 | 30 | co_dev_t *tdev = co_dev_create_from_dcf_file( 31 | TEST_SRCDIR "/co-pdo-transmit.dcf"); 32 | tap_assert(tdev); 33 | co_tpdo_t *tpdo = co_tpdo_create(net, tdev, 1); 34 | tap_assert(tpdo); 35 | 36 | tap_test(co_dev_set_val_u32(tdev, 0x2000, 0x00, VAL_2000), 37 | "store object 2000"); 38 | tap_test(co_dev_set_val_u32(tdev, 0x2001, 0x00, VAL_2001), 39 | "store object 2001"); 40 | 41 | tap_test(!co_tpdo_sync(tpdo, 0), "transmit PDOs"); 42 | co_test_step(&test); 43 | tap_test(!co_rpdo_sync(rpdo, 0), "process received PDOs"); 44 | 45 | tap_test(co_dev_get_val_u32(rdev, 0x2000, 0x00) == VAL_2000, 46 | "check value of object 2000"); 47 | tap_test(co_dev_get_val_u32(rdev, 0x2001, 0x00) == VAL_2001, 48 | "check value of object 2001"); 49 | 50 | co_tpdo_destroy(tpdo); 51 | co_dev_destroy(tdev); 52 | 53 | co_rpdo_destroy(rpdo); 54 | co_dev_destroy(rdev); 55 | 56 | co_test_fini(&test); 57 | can_net_destroy(net); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /test/co-sdo-client.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName=Lely Industries N.V. 3 | VendorNumber=0x00000360 4 | BaudRate_10=1 5 | BaudRate_20=1 6 | BaudRate_50=1 7 | BaudRate_125=1 8 | BaudRate_250=1 9 | BaudRate_500=1 10 | BaudRate_800=1 11 | BaudRate_1000=1 12 | 13 | [DeviceComissioning] 14 | NodeID=0x02 15 | 16 | [MandatoryObjects] 17 | SupportedObjects=3 18 | 1=0x1000 19 | 2=0x1001 20 | 3=0x1018 21 | 22 | [OptionalObjects] 23 | SupportedObjects=1 24 | 1=0x1280 25 | 26 | [ManufacturerObjects] 27 | SupportedObjects=0 28 | 29 | [1000] 30 | ParameterName=Device type 31 | DataType=0x0007 32 | AccessType=ro 33 | DefaultValue=0x00000000 34 | 35 | [1001] 36 | ParameterName=Error register 37 | DataType=0x0005 38 | AccessType=ro 39 | 40 | [1018] 41 | SubNumber=5 42 | ParameterName=Identity object 43 | ObjectType=0x09 44 | 45 | [1018sub0] 46 | ParameterName=Highest sub-index supported 47 | DataType=0x0005 48 | AccessType=const 49 | DefaultValue=0x4 50 | 51 | [1018sub1] 52 | ParameterName=Vendor-ID 53 | DataType=0x0007 54 | AccessType=ro 55 | DefaultValue=0x00000360 56 | 57 | [1018sub2] 58 | ParameterName=Product code 59 | DataType=0x0007 60 | AccessType=ro 61 | 62 | [1018sub3] 63 | ParameterName=Revision number 64 | DataType=0x0007 65 | AccessType=ro 66 | 67 | [1018sub4] 68 | ParameterName=Serial number 69 | DataType=0x0007 70 | AccessType=ro 71 | 72 | [1280] 73 | SubNumber=4 74 | ParameterName=SDO client parameter 75 | ObjectType=0x09 76 | 77 | [1280sub0] 78 | ParameterName=Highest sub-index supported 79 | DataType=0x0005 80 | AccessType=const 81 | DefaultValue=0x03 82 | 83 | [1280sub1] 84 | ParameterName=COB-ID client -> server (tx) 85 | DataType=0x0007 86 | AccessType=rw 87 | DefaultValue=0x800006E0 88 | ParameterValue=0x601 89 | 90 | [1280sub2] 91 | ParameterName=COB-ID server -> client (rx) 92 | DataType=0x0007 93 | AccessType=rw 94 | DefaultValue=0x800006E0 95 | ParameterValue=0x581 96 | 97 | [1280sub3] 98 | ParameterName=Node-ID of the SDO server 99 | DataType=0x0005 100 | AccessType=rw 101 | ParameterValue=0x01 102 | 103 | -------------------------------------------------------------------------------- /test/co-sdo-server.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName=Lely Industries N.V. 3 | VendorNumber=0x00000360 4 | BaudRate_10=1 5 | BaudRate_20=1 6 | BaudRate_50=1 7 | BaudRate_125=1 8 | BaudRate_250=1 9 | BaudRate_500=1 10 | BaudRate_800=1 11 | BaudRate_1000=1 12 | 13 | [DeviceComissioning] 14 | NodeID=0x01 15 | 16 | [MandatoryObjects] 17 | SupportedObjects=3 18 | 1=0x1000 19 | 2=0x1001 20 | 3=0x1018 21 | 22 | [OptionalObjects] 23 | SupportedObjects=0 24 | 25 | [ManufacturerObjects] 26 | SupportedObjects=1 27 | 1=0x2000 28 | 29 | [1000] 30 | ParameterName=Device type 31 | DataType=0x0007 32 | AccessType=ro 33 | 34 | [1001] 35 | ParameterName=Error register 36 | DataType=0x0005 37 | AccessType=ro 38 | 39 | [1018] 40 | SubNumber=5 41 | ParameterName=Identity object 42 | ObjectType=0x09 43 | 44 | [1018sub0] 45 | ParameterName=Highest sub-index supported 46 | DataType=0x0005 47 | AccessType=const 48 | DefaultValue=0x4 49 | 50 | [1018sub1] 51 | ParameterName=Vendor-ID 52 | DataType=0x0007 53 | AccessType=ro 54 | DefaultValue=0x00000360 55 | 56 | [1018sub2] 57 | ParameterName=Product code 58 | DataType=0x0007 59 | AccessType=ro 60 | 61 | [1018sub3] 62 | ParameterName=Revision number 63 | DataType=0x0007 64 | AccessType=ro 65 | 66 | [1018sub4] 67 | ParameterName=Serial number 68 | DataType=0x0007 69 | AccessType=ro 70 | 71 | [2000] 72 | ParameterName=Test 73 | DataType=0x0009 74 | AccessType=rw 75 | 76 | -------------------------------------------------------------------------------- /test/co-sync.c: -------------------------------------------------------------------------------- 1 | #include "co-test.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define NUM_TEST 8 7 | 8 | void sync_ind(co_sync_t *sync, co_unsigned8_t cnt, void *data); 9 | 10 | int 11 | main(void) 12 | { 13 | tap_plan(NUM_TEST); 14 | 15 | #if !LELY_NO_STDIO && !LELY_NO_DIAG 16 | diag_set_handler(&co_test_diag_handler, NULL); 17 | diag_at_set_handler(&co_test_diag_at_handler, NULL); 18 | #endif 19 | 20 | can_net_t *net = can_net_create(); 21 | tap_assert(net); 22 | struct co_test test; 23 | co_test_init(&test, net, 0); 24 | 25 | co_dev_t *dev = co_dev_create_from_dcf_file(TEST_SRCDIR "/co-sync.dcf"); 26 | tap_assert(dev); 27 | co_sync_t *sync = co_sync_create(net, dev); 28 | tap_assert(sync); 29 | 30 | co_sync_set_ind(sync, &sync_ind, &test); 31 | 32 | for (int i = 0; i < NUM_TEST; i++) 33 | co_test_wait(&test); 34 | 35 | co_sync_destroy(sync); 36 | co_dev_destroy(dev); 37 | 38 | co_test_fini(&test); 39 | can_net_destroy(net); 40 | 41 | return 0; 42 | } 43 | 44 | void 45 | sync_ind(co_sync_t *sync, co_unsigned8_t cnt, void *data) 46 | { 47 | (void)sync; 48 | struct co_test *test = data; 49 | static uint32_t call = 0; 50 | 51 | if (call++ < NUM_TEST) 52 | tap_pass("received SYNC [%d]", cnt); 53 | else 54 | tap_diag("received extra SYNC [%d]", cnt); 55 | 56 | co_test_done(test); 57 | } 58 | -------------------------------------------------------------------------------- /test/co-sync.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName= 3 | VendorNumber=0 4 | ProductName= 5 | ProductNumber=0 6 | RevisionNumber=0 7 | OrderCode= 8 | BaudRate_10=0 9 | BaudRate_20=0 10 | BaudRate_50=0 11 | BaudRate_125=0 12 | BaudRate_250=0 13 | BaudRate_500=0 14 | BaudRate_800=0 15 | BaudRate_1000=0 16 | 17 | [MandatoryObjects] 18 | SupportedObjects=3 19 | 1=0x1000 20 | 2=0x1001 21 | 3=0x1018 22 | 23 | [OptionalObjects] 24 | SupportedObjects=3 25 | 1=0x1005 26 | 2=0x1006 27 | 3=0x1019 28 | 29 | [ManufacturerObjects] 30 | SupportedObjects=0 31 | 32 | [1000] 33 | ParameterName=Device type 34 | DataType=0x0007 35 | AccessType=ro 36 | 37 | [1001] 38 | ParameterName=Error register 39 | DataType=0x0005 40 | AccessType=ro 41 | 42 | [1005] 43 | ParameterName=COB-ID SYNC message 44 | DataType=0x0007 45 | AccessType=rw 46 | DefaultValue=0x40000080 47 | 48 | [1006] 49 | ParameterName=Communication cycle period 50 | DataType=0x0007 51 | AccessType=rw 52 | DefaultValue=100000 53 | 54 | [1018] 55 | SubNumber=5 56 | ParameterName=Identity object 57 | ObjectType=0x09 58 | 59 | [1018sub0] 60 | ParameterName=Highest sub-index supported 61 | DataType=0x0005 62 | AccessType=const 63 | DefaultValue=0x4 64 | 65 | [1018sub1] 66 | ParameterName=Vendor-ID 67 | DataType=0x0007 68 | AccessType=ro 69 | 70 | [1018sub2] 71 | ParameterName=Product code 72 | DataType=0x0007 73 | AccessType=ro 74 | 75 | [1018sub3] 76 | ParameterName=Revision number 77 | DataType=0x0007 78 | AccessType=ro 79 | 80 | [1018sub4] 81 | ParameterName=Serial number 82 | DataType=0x0007 83 | AccessType=ro 84 | 85 | [1019] 86 | ParameterName=Synchronous counter overflow value 87 | DataType=0x0005 88 | AccessType=rw 89 | DefaultValue=4 90 | 91 | -------------------------------------------------------------------------------- /test/co-time.c: -------------------------------------------------------------------------------- 1 | #include "co-test.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define NUM_TEST 8 7 | #define MSEC 100 8 | 9 | void time_ind(co_time_t *time, const struct timespec *tp, void *data); 10 | 11 | int 12 | main(void) 13 | { 14 | tap_plan(NUM_TEST); 15 | 16 | #if !LELY_NO_STDIO && !LELY_NO_DIAG 17 | diag_set_handler(&co_test_diag_handler, NULL); 18 | diag_at_set_handler(&co_test_diag_at_handler, NULL); 19 | #endif 20 | 21 | can_net_t *net = can_net_create(); 22 | tap_assert(net); 23 | struct co_test test; 24 | co_test_init(&test, net, 0); 25 | 26 | co_dev_t *dev = co_dev_create_from_dcf_file(TEST_SRCDIR "/co-time.dcf"); 27 | tap_assert(dev); 28 | co_time_t *time = co_time_create(net, dev); 29 | tap_assert(time); 30 | 31 | co_time_set_ind(time, &time_ind, &test); 32 | 33 | struct timespec interval = { 0, 1000000 * MSEC }; 34 | co_time_start_prod(time, NULL, &interval); 35 | 36 | for (int i = 0; i < NUM_TEST; i++) 37 | co_test_wait(&test); 38 | 39 | co_time_destroy(time); 40 | co_dev_destroy(dev); 41 | 42 | co_test_fini(&test); 43 | can_net_destroy(net); 44 | 45 | return 0; 46 | } 47 | 48 | void 49 | time_ind(co_time_t *time, const struct timespec *tp, void *data) 50 | { 51 | (void)time; 52 | tap_assert(tp); 53 | struct co_test *test = data; 54 | 55 | tap_pass("received TIME [%ld.%09ld]", (long)tp->tv_sec, tp->tv_nsec); 56 | 57 | co_test_done(test); 58 | } 59 | -------------------------------------------------------------------------------- /test/co-time.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName=Lely Industries N.V. 3 | VendorNumber=0x00000360 4 | BaudRate_10=1 5 | BaudRate_20=1 6 | BaudRate_50=1 7 | BaudRate_125=1 8 | BaudRate_250=1 9 | BaudRate_500=1 10 | BaudRate_800=1 11 | BaudRate_1000=1 12 | 13 | [DeviceComissioning] 14 | NodeID=0x01 15 | 16 | [MandatoryObjects] 17 | SupportedObjects=3 18 | 1=0x1000 19 | 2=0x1001 20 | 3=0x1018 21 | 22 | [OptionalObjects] 23 | SupportedObjects=2 24 | 1=0x1012 25 | 2=0x1013 26 | 27 | [ManufacturerObjects] 28 | SupportedObjects=0 29 | 30 | [1000] 31 | ParameterName=Device type 32 | DataType=0x0007 33 | AccessType=ro 34 | 35 | [1001] 36 | ParameterName=Error register 37 | DataType=0x0005 38 | AccessType=ro 39 | 40 | [1012] 41 | ParameterName=COB-ID time stamp object 42 | DataType=0x0007 43 | AccessType=rw 44 | DefaultValue=0xc0000100 45 | 46 | [1013] 47 | ParameterName=High resolution time stamp 48 | DataType=0x0007 49 | AccessType=rw 50 | 51 | [1018] 52 | SubNumber=5 53 | ParameterName=Identity object 54 | ObjectType=0x09 55 | 56 | [1018sub0] 57 | ParameterName=Highest sub-index supported 58 | DataType=0x0005 59 | AccessType=const 60 | DefaultValue=0x4 61 | 62 | [1018sub1] 63 | ParameterName=Vendor-ID 64 | DataType=0x0007 65 | AccessType=ro 66 | DefaultValue=0x00000360 67 | 68 | [1018sub2] 69 | ParameterName=Product code 70 | DataType=0x0007 71 | AccessType=ro 72 | 73 | [1018sub3] 74 | ParameterName=Revision number 75 | DataType=0x0007 76 | AccessType=ro 77 | 78 | [1018sub4] 79 | ParameterName=Serial number 80 | DataType=0x0007 81 | AccessType=ro 82 | 83 | -------------------------------------------------------------------------------- /test/coapp-lss-master.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName=Lely Industries N.V. 3 | VendorNumber=0x00000360 4 | BaudRate_10=1 5 | BaudRate_20=1 6 | BaudRate_50=1 7 | BaudRate_125=1 8 | BaudRate_250=1 9 | BaudRate_500=1 10 | BaudRate_800=1 11 | BaudRate_1000=1 12 | LSS_Supported=1 13 | 14 | [MandatoryObjects] 15 | SupportedObjects=3 16 | 1=0x1000 17 | 2=0x1001 18 | 3=0x1018 19 | 20 | [OptionalObjects] 21 | SupportedObjects=1 22 | 1=0x1F80 23 | 24 | [ManufacturerObjects] 25 | SupportedObjects=0 26 | 27 | [1000] 28 | ParameterName=Device type 29 | DataType=0x0007 30 | AccessType=ro 31 | 32 | [1001] 33 | ParameterName=Error register 34 | DataType=0x0005 35 | AccessType=ro 36 | 37 | [1018] 38 | SubNumber=5 39 | ParameterName=Identity object 40 | ObjectType=0x09 41 | 42 | [1018sub0] 43 | ParameterName=Highest sub-index supported 44 | DataType=0x0005 45 | AccessType=const 46 | DefaultValue=4 47 | 48 | [1018sub1] 49 | ParameterName=Vendor-ID 50 | DataType=0x0007 51 | AccessType=ro 52 | DefaultValue=0x00000360 53 | 54 | [1018sub2] 55 | ParameterName=Product code 56 | DataType=0x0007 57 | AccessType=ro 58 | 59 | [1018sub3] 60 | ParameterName=Revision number 61 | DataType=0x0007 62 | AccessType=ro 63 | 64 | [1018sub4] 65 | ParameterName=Serial number 66 | DataType=0x0007 67 | AccessType=ro 68 | 69 | [1F80] 70 | ParameterName=NMT startup 71 | DataType=0x0007 72 | AccessType=rw 73 | ParameterValue=0x00000001 74 | -------------------------------------------------------------------------------- /test/coapp-lss-slave.dcf: -------------------------------------------------------------------------------- 1 | [DeviceInfo] 2 | VendorName=Lely Industries N.V. 3 | VendorNumber=0x00000360 4 | BaudRate_10=1 5 | BaudRate_20=1 6 | BaudRate_50=1 7 | BaudRate_125=1 8 | BaudRate_250=1 9 | BaudRate_500=1 10 | BaudRate_800=1 11 | BaudRate_1000=1 12 | LSS_Supported=1 13 | 14 | [MandatoryObjects] 15 | SupportedObjects=3 16 | 1=0x1000 17 | 2=0x1001 18 | 3=0x1018 19 | 20 | [OptionalObjects] 21 | SupportedObjects=0 22 | 23 | [ManufacturerObjects] 24 | SupportedObjects=0 25 | 26 | [1000] 27 | ParameterName=Device type 28 | DataType=0x0007 29 | AccessType=ro 30 | 31 | [1001] 32 | ParameterName=Error register 33 | DataType=0x0005 34 | AccessType=ro 35 | 36 | [1018] 37 | SubNumber=5 38 | ParameterName=Identity object 39 | ObjectType=0x09 40 | 41 | [1018sub0] 42 | ParameterName=Highest sub-index supported 43 | DataType=0x0005 44 | AccessType=const 45 | DefaultValue=4 46 | 47 | [1018sub1] 48 | ParameterName=Vendor-ID 49 | DataType=0x0007 50 | AccessType=ro 51 | DefaultValue=0x00000360 52 | 53 | [1018sub2] 54 | ParameterName=Product code 55 | DataType=0x0007 56 | AccessType=ro 57 | DefaultValue=0x00000002 58 | 59 | [1018sub3] 60 | ParameterName=Revision number 61 | DataType=0x0007 62 | AccessType=ro 63 | DefaultValue=0x00000003 64 | 65 | [1018sub4] 66 | ParameterName=Serial number 67 | DataType=0x0007 68 | AccessType=ro 69 | DefaultValue=0x00000004 70 | -------------------------------------------------------------------------------- /test/ev-future.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | 5 | using namespace lely::ev; 6 | 7 | int 8 | main() { 9 | tap_plan(8); 10 | 11 | auto exec = ThreadLoop::get_executor(); 12 | 13 | Promise p; 14 | 15 | auto f1 = p.get_future(); 16 | tap_test(!f1.is_ready()); 17 | 18 | auto f2 = when_any(exec, f1); 19 | tap_test(!f2.is_ready()); 20 | 21 | p.set(42); 22 | tap_test(f1.is_ready()); 23 | tap_test(f1.get().has_value()); 24 | tap_test(f1.get().value() == 42); 25 | 26 | ThreadLoop::run(); 27 | tap_test(ThreadLoop::stopped()); 28 | 29 | tap_test(f2.is_ready()); 30 | tap_test(f2.get().value() == 0); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /test/ev-loop.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | 5 | using namespace lely::ev; 6 | 7 | #define NUM_OP (16 * 1024 * 1024) 8 | 9 | class MyOp : public CoTask { 10 | public: 11 | virtual void 12 | operator()() noexcept override { 13 | co_reenter (*this) { 14 | for (; n < NUM_OP; n++) co_yield get_executor().post((ev_task&)(*this)); 15 | } 16 | } 17 | 18 | private: 19 | ::std::size_t n{0}; 20 | }; 21 | 22 | int 23 | main() { 24 | tap_plan(3); 25 | 26 | Loop loop; 27 | tap_test(!loop.stopped()); 28 | 29 | MyOp op; 30 | loop.get_executor().post(op); 31 | 32 | auto t1 = ::std::chrono::high_resolution_clock::now(); 33 | auto nop = loop.run(); 34 | auto t2 = ::std::chrono::high_resolution_clock::now(); 35 | 36 | tap_test(nop == NUM_OP + 1); 37 | tap_test(loop.stopped()); 38 | 39 | auto ns = ::std::chrono::nanoseconds(t2 - t1).count(); 40 | tap_diag("%f ns per op", double(ns) / nop); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/io-cxx.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lely; 10 | 11 | int 12 | main() { 13 | tap_plan(0); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/io-poll.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #if _WIN32 3 | #include 4 | #else 5 | #include 6 | #endif 7 | #include 8 | 9 | #define TIMEOUT 1000 10 | 11 | int 12 | main(void) 13 | { 14 | tap_plan(16); 15 | 16 | tap_assert(!lely_io_init()); 17 | 18 | io_poll_t *poll = io_poll_create(); 19 | tap_assert(poll); 20 | 21 | io_handle_t pipe[2]; 22 | #if _WIN32 23 | tap_test(!io_open_socketpair(IO_SOCK_IPV4, IO_SOCK_STREAM, pipe)); 24 | #else 25 | tap_test(!io_open_pipe(pipe)); 26 | #endif 27 | tap_test(!io_set_flags(pipe[0], IO_FLAG_NONBLOCK)); 28 | tap_test(!io_set_flags(pipe[1], IO_FLAG_NONBLOCK)); 29 | 30 | struct io_event event = IO_EVENT_INIT; 31 | 32 | int sig = 13; 33 | tap_test(!io_poll_signal(poll, sig)); 34 | tap_test(io_poll_wait(poll, 1, &event, TIMEOUT) == 1); 35 | tap_test(event.events == IO_EVENT_SIGNAL); 36 | tap_test(event.u.sig == sig); 37 | 38 | struct io_event revent = { .events = IO_EVENT_READ, 39 | .u.handle = pipe[0] }; 40 | tap_assert(!io_poll_watch(poll, pipe[0], &revent, 0)); 41 | 42 | struct io_event sevent = { .events = IO_EVENT_WRITE, 43 | .u.handle = pipe[1] }; 44 | tap_assert(!io_poll_watch(poll, pipe[1], &sevent, 0)); 45 | 46 | tap_test(io_poll_wait(poll, 1, &event, TIMEOUT) == 1); 47 | tap_test(event.events == IO_EVENT_WRITE); 48 | tap_test(event.u.handle == pipe[1]); 49 | 50 | int sval = 13; 51 | tap_test(io_write(pipe[1], &sval, sizeof(sval)) == sizeof(sval)); 52 | 53 | tap_test(io_poll_wait(poll, 1, &event, TIMEOUT) == 1); 54 | tap_test(event.events == IO_EVENT_READ); 55 | tap_test(event.u.handle == pipe[0]); 56 | 57 | int rval = 0; 58 | tap_test(io_read(pipe[0], &rval, sizeof(rval)) == sizeof(rval)); 59 | 60 | tap_test(rval == sval); 61 | 62 | io_close(pipe[1]); 63 | io_close(pipe[0]); 64 | io_poll_destroy(poll); 65 | 66 | lely_io_fini(); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /test/io2-can_rt.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace lely::ev; 8 | using namespace lely::io; 9 | 10 | #define NUM_OP 4 11 | 12 | int 13 | main() { 14 | tap_plan(NUM_OP + 1); 15 | 16 | IoGuard io_guard; 17 | Context ctx; 18 | Loop loop; 19 | UserCanChannel chan(ctx, loop.get_executor()); 20 | CanRouter rt(chan, loop.get_executor()); 21 | 22 | for (uint_least32_t i = 0; i < NUM_OP; i++) 23 | rt.submit_read_frame(i, CanFlag::NONE, 24 | [=](const can_msg* msg, ::std::error_code ec) { 25 | if (!ec) tap_test(msg->id == i, "%03x", i); 26 | }); 27 | 28 | for (uint_least32_t i = 0; i < NUM_OP; i++) { 29 | can_msg msg CAN_MSG_INIT; 30 | msg.id = i; 31 | chan.on_read(&msg); 32 | } 33 | 34 | loop.run(); 35 | tap_test(loop.stopped()); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/io2-sigset.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #if _POSIX_C_SOURCE >= 200112L 4 | #include 5 | #else 6 | #error This file requires POSIX. 7 | #endif 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace lely::ev; 13 | using namespace lely::io; 14 | 15 | #define NUM_OP 4 16 | 17 | struct MyOp : public CoSignalSetWait { 18 | MyOp(SignalSetBase& sigset_) : sigset(sigset_) {} 19 | 20 | void 21 | operator()(int signo) noexcept override { 22 | co_reenter (*this) { 23 | for (; n < NUM_OP; n++) { 24 | tap_pass(); 25 | raise(signo); 26 | co_yield sigset.submit_wait(*this); 27 | } 28 | } 29 | } 30 | 31 | SignalSetBase& sigset; 32 | ::std::size_t n{0}; 33 | }; 34 | 35 | int 36 | main() { 37 | tap_plan(1 + NUM_OP); 38 | 39 | IoGuard io_guard; 40 | Context ctx; 41 | lely::io::Poll poll(ctx); 42 | Loop loop(poll.get_poll()); 43 | SignalSet sigset(poll, loop.get_executor()); 44 | 45 | sigset.insert(SIGRTMIN); 46 | raise(SIGRTMIN); 47 | 48 | MyOp op(sigset); 49 | sigset.submit_wait(op); 50 | 51 | loop.run(); 52 | tap_test(loop.stopped()); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /test/io2-timer.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #if _WIN32 4 | #include 5 | #elif _POSIX_C_SOURCE >= 200112L 6 | #include 7 | #else 8 | #error This file requires Windows or POSIX. 9 | #endif 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace lely::ev; 15 | using namespace lely::io; 16 | 17 | #define NUM_OP 4 18 | 19 | struct MyOp : public CoTimerWait { 20 | MyOp(TimerBase& timer_) : timer(timer_) {} 21 | 22 | void 23 | operator()(int overrun, ::std::error_code ec) noexcept override { 24 | co_reenter (*this) { 25 | for (; n < NUM_OP; n++) { 26 | if (!ec) { 27 | auto s = ::std::chrono::duration( 28 | timer.get_clock().gettime().time_since_epoch()) 29 | .count(); 30 | tap_pass("%f s (%d)", s, overrun); 31 | } 32 | co_yield timer.submit_wait(*this); 33 | } 34 | } 35 | } 36 | 37 | TimerBase& timer; 38 | ::std::size_t n{0}; 39 | }; 40 | 41 | int 42 | main() { 43 | tap_plan(NUM_OP + 1); 44 | 45 | IoGuard io_guard; 46 | Context ctx; 47 | lely::io::Poll poll(ctx); 48 | #if _WIN32 49 | // GetQueuedCompletionStatusEx() is not implemented in Wine. Since the Windows 50 | // timer does not use I/O completion ports, we do not need to use the polling 51 | // instance in the event loop. 52 | Loop loop; 53 | #else 54 | Loop loop(poll.get_poll()); 55 | #endif 56 | Timer timer(poll, loop.get_executor(), CLOCK_MONOTONIC); 57 | 58 | timer.settime(::std::chrono::seconds(1), ::std::chrono::seconds(1)); 59 | 60 | MyOp op(timer); 61 | timer.submit_wait(op); 62 | 63 | loop.run(); 64 | tap_test(loop.stopped()); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /test/io2-tqueue.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #if _WIN32 4 | #include 5 | #elif _POSIX_C_SOURCE >= 200112L 6 | #include 7 | #else 8 | #error This file requires Windows or POSIX. 9 | #endif 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace lely::ev; 15 | using namespace lely::io; 16 | 17 | #define NUM_OP 4 18 | 19 | int 20 | main() { 21 | tap_plan(NUM_OP + 1); 22 | 23 | IoGuard io_guard; 24 | Context ctx; 25 | lely::io::Poll poll(ctx); 26 | #if _WIN32 27 | // GetQueuedCompletionStatusEx() is not implemented in Wine < 4.0. Since the 28 | // Windows timer does not use I/O completion ports, we do not need to use the 29 | // polling instance in the event loop. 30 | Loop loop; 31 | #else 32 | Loop loop(poll.get_poll()); 33 | #endif 34 | Timer timer(poll, loop.get_executor(), CLOCK_MONOTONIC); 35 | TimerQueue tq(timer, loop.get_executor()); 36 | 37 | for (int i = 0; i < NUM_OP; i++) 38 | tq.submit_wait(::std::chrono::seconds(i), [&](::std::error_code ec) { 39 | if (!ec) { 40 | auto s = ::std::chrono::duration( 41 | timer.get_clock().gettime().time_since_epoch()) 42 | .count(); 43 | tap_pass("%f s", s); 44 | } 45 | }); 46 | 47 | loop.run(); 48 | tap_test(loop.stopped()); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /test/io2-vcan.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace lely::ev; 9 | using namespace lely::io; 10 | 11 | #define NUM_OP 4 12 | 13 | struct MyOp : public CoCanChannelRead { 14 | MyOp(CanChannelBase& chan_, uint_least8_t id_) 15 | : CoCanChannelRead(&msg, &err), chan(chan_), id(id_) {} 16 | 17 | void 18 | operator()(int result, ::std::error_code ec) noexcept override { 19 | co_reenter (*this) { 20 | tap_test(result == 0 && err.state == CAN_STATE_ACTIVE, "error frame"); 21 | for (; n < NUM_OP; n++) { 22 | msg.id = id; 23 | chan.write(msg); 24 | co_yield chan.submit_read(*this); 25 | tap_test(result == 1 && !ec && msg.id != id, "CAN frame"); 26 | } 27 | } 28 | } 29 | 30 | can_msg msg CAN_MSG_INIT; 31 | can_err err CAN_ERR_INIT; 32 | CanChannelBase& chan; 33 | uint_least8_t id{0}; 34 | ::std::size_t n{0}; 35 | }; 36 | 37 | int 38 | main() { 39 | tap_plan(4 + 2 * (NUM_OP + 1) + 1); 40 | 41 | IoGuard io_guard; 42 | Context ctx; 43 | Loop loop; 44 | VirtualCanController ctrl(clock_monotonic); 45 | VirtualCanChannel chan1(ctx, loop.get_executor()); 46 | VirtualCanChannel chan2(ctx, loop.get_executor()); 47 | 48 | chan1.open(ctrl); 49 | tap_test(chan1.is_open()); 50 | 51 | chan2.open(ctrl); 52 | tap_test(chan2.is_open()); 53 | 54 | ctrl.stop(); 55 | tap_test(ctrl.stopped()); 56 | ctrl.restart(); 57 | tap_test(!ctrl.stopped()); 58 | 59 | MyOp op1(chan1, 1); 60 | chan1.submit_read(op1); 61 | 62 | MyOp op2(chan2, 2); 63 | chan2.submit_read(op2); 64 | 65 | loop.run(); 66 | tap_test(loop.stopped()); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /test/tap.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | int 4 | main(void) 5 | { 6 | tap_plan(7); 7 | 8 | tap_assert(1 == 1); 9 | 10 | tap_test(1 == 1); 11 | tap_test(1 == 1, "with\nmultiline\ncomment"); 12 | 13 | tap_pass(); 14 | 15 | tap_todo(1 == 0); 16 | tap_todo(1 == 0, "with\nmultiline\ncomment"); 17 | 18 | tap_skip(1 == 1); 19 | tap_skip(1 == 0, "with\nmultiline\ncomment"); 20 | 21 | tap_diag("all done"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/test.h: -------------------------------------------------------------------------------- 1 | #ifndef LELY_TEST_INTERN_TEST_H_ 2 | #define LELY_TEST_INTERN_TEST_H_ 3 | 4 | #ifdef HAVE_CONFIG_H 5 | #include 6 | #endif 7 | 8 | #include 9 | 10 | #endif // !LELY_TEST_INTERN_TEST_H_ 11 | -------------------------------------------------------------------------------- /test/util-config.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | tap_plan(3); 9 | 10 | config_t *config = config_create(0); 11 | tap_assert(config); 12 | 13 | tap_test(config_parse_ini_file(config, TEST_SRCDIR "/util-config.ini")); 14 | 15 | tap_test(!str_cmp(config_get(config, "", "key"), "value")); 16 | tap_test(!str_cmp(config_get(config, "section", "key"), "")); 17 | 18 | config_destroy(config); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/util-config.ini: -------------------------------------------------------------------------------- 1 | ; Comment 2 | 3 | key = value 4 | 5 | [section] 6 | key = "value" 7 | key = "" 8 | 9 | -------------------------------------------------------------------------------- /test/util-fbuf.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #define FILENAME "util-fbuf.dat" 9 | 10 | #define SIZE 1024 11 | 12 | #define TXT1 FILENAME 13 | #define POS 32 14 | #define TXT2 "Hello, world!" 15 | 16 | void test_frbuf(void); 17 | void test_fwbuf(void); 18 | 19 | int 20 | main(void) 21 | { 22 | tap_plan(18); 23 | 24 | test_fwbuf(); 25 | test_frbuf(); 26 | 27 | return 0; 28 | } 29 | 30 | void 31 | test_frbuf(void) 32 | { 33 | frbuf_t *buf = frbuf_create(FILENAME); 34 | tap_assert(buf); 35 | 36 | char txt1[sizeof(TXT1)] = { '\0' }; 37 | tap_test(frbuf_read(buf, txt1, sizeof(TXT1)) != -1); 38 | tap_test(!strncmp(txt1, TXT1, sizeof(TXT1))); 39 | 40 | intmax_t pos = frbuf_get_pos(buf); 41 | tap_test(pos == (intmax_t)sizeof(TXT1)); 42 | 43 | size_t size = 0; 44 | const void *map = frbuf_map(buf, POS, &size); 45 | tap_assert(map); 46 | tap_test(size == SIZE - POS); 47 | 48 | char txt2[sizeof(TXT2)] = { '\0' }; 49 | tap_test(frbuf_pread(buf, txt2, sizeof(TXT2), POS) != -1); 50 | tap_test(!strncmp(txt2, TXT2, sizeof(TXT2))); 51 | 52 | tap_test(!strncmp(map, TXT2, sizeof(TXT2))); 53 | 54 | tap_test(!frbuf_unmap(buf)); 55 | 56 | tap_test(frbuf_get_pos(buf) == pos); 57 | 58 | frbuf_destroy(buf); 59 | } 60 | 61 | void 62 | test_fwbuf(void) 63 | { 64 | fwbuf_t *buf = fwbuf_create(FILENAME); 65 | tap_assert(buf); 66 | 67 | tap_test(!fwbuf_set_size(buf, SIZE)); 68 | 69 | tap_test(fwbuf_write(buf, TXT1, sizeof(TXT1)) != -1); 70 | 71 | intmax_t pos = fwbuf_get_pos(buf); 72 | tap_test(pos == (intmax_t)sizeof(TXT1)); 73 | 74 | size_t size = 0; 75 | void *map = fwbuf_map(buf, POS, &size); 76 | tap_assert(map); 77 | tap_test(size == SIZE - POS); 78 | 79 | tap_test(fwbuf_pwrite(buf, TXT2, sizeof(TXT2), POS) != -1); 80 | 81 | tap_test(!strcmp(map, TXT2)); 82 | 83 | tap_test(!fwbuf_unmap(buf)); 84 | 85 | tap_test(fwbuf_get_pos(buf) == pos); 86 | 87 | tap_test(!fwbuf_commit(buf)); 88 | 89 | fwbuf_destroy(buf); 90 | } 91 | -------------------------------------------------------------------------------- /test/util-fiber.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | 4 | using namespace lely::util; 5 | 6 | int 7 | main() { 8 | tap_plan(3); 9 | 10 | #if __MINGW32__ && !_WIN64 11 | // On 32-bit platforms, either MinGW or Wine causes terminate to be called if 12 | // an exception is thrown from Fiber::resume(). This prevents the use of 13 | // fiber_unwind and therefore the proper destruction of fibers. 14 | for (int i = 0; i < 3; i++) tap_skip(); 15 | #else 16 | FiberThread thrd; 17 | 18 | Fiber f1, f2, f3; 19 | f3 = Fiber{[&](Fiber&& f) -> Fiber { 20 | f2 = ::std::move(f); 21 | for (;;) { 22 | tap_pass("in f3"); 23 | f2 = ::std::move(f1).resume(); 24 | } 25 | return {}; 26 | }}; 27 | f2 = Fiber{[&](Fiber&& f) -> Fiber { 28 | f1 = ::std::move(f); 29 | for (;;) { 30 | tap_pass("in f2"); 31 | f1 = ::std::move(f3).resume(); 32 | } 33 | return {}; 34 | }}; 35 | f1 = Fiber{[&](Fiber&& f) -> Fiber { 36 | tap_pass("in f1"); 37 | f3 = ::std::move(f2).resume(); 38 | tap_diag("exiting f1"); 39 | return ::std::move(f); 40 | }}; 41 | ::std::move(f1).resume(); 42 | tap_diag("back in main()"); 43 | #endif 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/util-stop.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace lely::util; 11 | 12 | int 13 | main() { 14 | tap_plan(7); 15 | 16 | StopSource source; 17 | tap_test(source.stop_possible()); 18 | tap_test(!source.stop_requested()); 19 | 20 | auto token = source.get_token(); 21 | tap_test(token.stop_possible()); 22 | tap_test(!token.stop_requested()); 23 | #if __MINGW32__ 24 | // Threads are not supported on MinGW. 25 | tap_skip(); 26 | #else 27 | ::std::mutex mtx; 28 | ::std::condition_variable cond; 29 | 30 | ::std::thread thr([token, &mtx, &cond]() { 31 | ::std::unique_lock<::std::mutex> lock(mtx); 32 | while (!token.stop_requested()) cond.wait(lock); 33 | }); 34 | 35 | { 36 | StopCallback<::std::function> callback( 37 | token, [source, &mtx, &cond]() mutable { 38 | tap_test(source.stop_requested()); 39 | ::std::lock_guard<::std::mutex> lock(mtx); 40 | cond.notify_one(); 41 | }); 42 | #endif 43 | // clang-format off 44 | token = {}; 45 | tap_test(!token.stop_possible()); 46 | #if !__MINGW32__ 47 | ::std::this_thread::sleep_for(::std::chrono::seconds(1)); 48 | #endif 49 | source.request_stop(); 50 | tap_test(source.stop_requested()); 51 | #if !__MINGW32__ 52 | } 53 | thr.join(); 54 | // clang-format on 55 | #endif 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /tools/version.dcf2c.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 5 | PRODUCTVERSION 0,@VERSION_MAJOR@,0,@VERSION_MINOR@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | FILEFLAGS 0 8 | FILEOS VOS_NT 9 | FILETYPE VFT_APP 10 | FILESUBTYPE VFT2_UNKNOWN 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904b0" 15 | BEGIN 16 | VALUE "CompanyName", "Lely Industries N.V." 17 | VALUE "FileDescription", "CANopen EDS/DCF to C conversion tool" 18 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 19 | VALUE "InternalName", "dcf2c" 20 | VALUE "LegalCopyright", "2019 Lely Industries N.V." 21 | VALUE "OriginalFilename", "dcf2c.exe" 22 | VALUE "ProductName", "Lely CANopen library" 23 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x409, 1200 29 | END 30 | END 31 | 32 | -------------------------------------------------------------------------------- /unit-tests/.clang-format: -------------------------------------------------------------------------------- 1 | ../.clang-format.cpp -------------------------------------------------------------------------------- /unit-tests/co/holder/dev.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_UNIT_TESTS_CO_DEV_HOLDER_HPP_ 24 | #define LELY_UNIT_TESTS_CO_DEV_HOLDER_HPP_ 25 | 26 | #include 27 | 28 | #if LELY_NO_MALLOC 29 | #include 30 | #endif 31 | 32 | #include "holder.hpp" 33 | 34 | class CoDevTHolder : public Holder { 35 | #if LELY_NO_MALLOC 36 | public: 37 | explicit CoDevTHolder(co_unsigned8_t id) { __co_dev_init(Get(), id); } 38 | #else // !LELY_NO_MALLOC 39 | public: 40 | explicit CoDevTHolder(co_unsigned8_t id) 41 | : Holder(co_dev_create(id)) {} 42 | 43 | ~CoDevTHolder() { 44 | if (!taken) co_dev_destroy(Get()); 45 | } 46 | #endif // LELY_NO_MALLOC 47 | }; // class CoDevTHolder 48 | 49 | #endif // LELY_UNIT_TESTS_CO_DEV_HOLDER_HPP_ 50 | -------------------------------------------------------------------------------- /unit-tests/co/holder/holder.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_UNIT_TESTS_CO_HOLDER_HPP_ 24 | #define LELY_UNIT_TESTS_CO_HOLDER_HPP_ 25 | 26 | #include 27 | 28 | template 29 | class Holder { 30 | #if LELY_NO_MALLOC 31 | 32 | protected: 33 | Holder() : item({}) {} 34 | 35 | public: 36 | Item* 37 | Get() { 38 | return &item; 39 | } 40 | 41 | Item* 42 | Take() { 43 | return Get(); 44 | } 45 | 46 | private: 47 | Item item; 48 | #else // !LELY_NO_MALLOC 49 | 50 | protected: 51 | explicit Holder(Item* item_) : item(item_) {} 52 | 53 | public: 54 | Item* 55 | Get() { 56 | return item; 57 | } 58 | 59 | Item* 60 | Take() { 61 | assert(taken == false); 62 | taken = true; 63 | return item; 64 | } 65 | 66 | protected: 67 | bool taken = false; 68 | 69 | private: 70 | Item* item = nullptr; 71 | #endif // LELY_NO_MALLOC 72 | }; // class Holder 73 | 74 | #endif // LELY_UNIT_TESTS_CO_HOLDER_HPP_ 75 | -------------------------------------------------------------------------------- /unit-tests/co/holder/sub.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_UNIT_TESTS_CO_SUB_HOLDER_HPP_ 24 | #define LELY_UNIT_TESTS_CO_SUB_HOLDER_HPP_ 25 | 26 | #include 27 | 28 | #if LELY_NO_MALLOC 29 | #include 30 | #endif 31 | 32 | #include "holder.hpp" 33 | 34 | class CoSubTHolder : public Holder { 35 | #if LELY_NO_MALLOC 36 | 37 | public: 38 | explicit CoSubTHolder(co_unsigned8_t subidx, co_unsigned16_t type) 39 | : value({}) { 40 | if (co_type_is_array(type)) { 41 | co_val_init_array(&value, &array); 42 | __co_sub_init(Get(), subidx, type, &value); 43 | } else { 44 | __co_sub_init(Get(), subidx, type, nullptr); 45 | } 46 | } 47 | 48 | private: 49 | co_val value; 50 | co_array array = CO_ARRAY_INIT; 51 | #else // !LELY_NO_MALLOC 52 | 53 | public: 54 | explicit CoSubTHolder(co_unsigned8_t subidx, co_unsigned16_t type) 55 | : Holder(co_sub_create(subidx, type)) {} 56 | 57 | ~CoSubTHolder() { 58 | if (!taken) co_sub_destroy(Get()); 59 | } 60 | #endif // LELY_NO_MALLOC 61 | }; // class CoSubTHolder 62 | 63 | #endif // LELY_UNIT_TESTS_CO_SUB_HOLDER_HPP_ 64 | -------------------------------------------------------------------------------- /unit-tests/lely-cpputest-ext.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_UNIT_TESTS_CPPUTEST_EXT_HPP_ 24 | #define LELY_UNIT_TESTS_CPPUTEST_EXT_HPP_ 25 | 26 | /** 27 | * A group of handy CppUTest-style macros to handle calling base test group's 28 | * setup() and teardown() functions. To utilize them one should first put 29 | * TEST_BASE_SETUP() in a base group with the group name as a parameter. Then 30 | * in sub-groups TEST_BASE_SETUP() and TEST_BASE_TEARDOWN() can be used to 31 | * call respective functions. 32 | */ 33 | #define TEST_BASE_SUPER(base) using super = base 34 | #define TEST_BASE_SETUP() super::setup() 35 | #define TEST_BASE_TEARDOWN() super::teardown() 36 | 37 | #endif // LELY_UNIT_TESTS_CPPUTEST_EXT_HPP_ 38 | -------------------------------------------------------------------------------- /unit-tests/lely-unit-test.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | #ifndef LELY_UNIT_TEST_HPP_ 23 | #define LELY_UNIT_TEST_HPP_ 24 | 25 | #include 26 | 27 | namespace LelyUnitTest { 28 | /** 29 | * Set empty handlers for all diagnostic messages from lely-core library. 30 | * 31 | * @see diag_set_handler(), diag_at_set_handler() 32 | */ 33 | inline void 34 | DisableDiagnosticMessages() { 35 | #if LELY_NO_DIAG 36 | // enforce coverage in NO_DIAG mode 37 | diag(DIAG_DEBUG, 0, "Message suppressed"); 38 | diag_if(DIAG_DEBUG, 0, nullptr, "Message suppressed"); 39 | #else 40 | diag_set_handler(nullptr, nullptr); 41 | diag_at_set_handler(nullptr, nullptr); 42 | #endif 43 | } 44 | } // namespace LelyUnitTest 45 | 46 | #endif // LELY_UNIT_TEST_HPP_ 47 | -------------------------------------------------------------------------------- /unit-tests/override/defs.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_OVERRIDE_DEFS_HPP_ 24 | #define LELY_OVERRIDE_DEFS_HPP_ 25 | 26 | namespace Override { 27 | /** 28 | * Enumeration of function override parameters. 29 | */ 30 | enum : int { AllCallsValid = -1, NoneCallsValid = 0 }; 31 | 32 | } // namespace Override 33 | 34 | #endif // !LELY_OVERRIDE_DEFS_HPP_ 35 | -------------------------------------------------------------------------------- /unit-tests/override/lely-defs.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_OVERRIDE_LELY_DEFS_HPP_ 24 | #define LELY_OVERRIDE_LELY_DEFS_HPP_ 25 | 26 | #if defined(__GNUC__) && !defined(__MINGW32__) 27 | /* Override library uses GCC-only features. At the same time MinGW-w64 tests 28 | * won't link properly - neither overriding with "strong" symbol nor using 29 | * --wrap linker option works. 30 | */ 31 | #define HAVE_LELY_OVERRIDE 1 32 | 33 | #include "defs.hpp" 34 | #endif 35 | 36 | #endif // !LELY_OVERRIDE_LELY_DEFS_HPP_ 37 | -------------------------------------------------------------------------------- /unit-tests/override/lelyco-val.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_OVERRIDE_LELY_CO_VAL_H_ 24 | #define LELY_OVERRIDE_LELY_CO_VAL_H_ 25 | 26 | #include "override/lely-defs.hpp" 27 | 28 | #ifdef HAVE_LELY_OVERRIDE 29 | 30 | /* 0. Declare valid calls counter for the overridden function. */ 31 | namespace LelyOverride { 32 | /** 33 | * Setups number of valid calls to co_val_read(). 34 | */ 35 | void co_val_read(int valid_calls); 36 | 37 | /** 38 | * Setups number of valid calls to co_val_write(). 39 | */ 40 | void co_val_write(int valid_calls); 41 | 42 | /** 43 | * Setups number of valid calls to co_val_make(). 44 | */ 45 | void co_val_make(int valid_calls); 46 | 47 | /** 48 | * Setups number of valid calls to co_val_init_min(). 49 | */ 50 | void co_val_init_min(int valid_calls); 51 | 52 | /** 53 | * Setups number of valid calls to co_val_init_max(). 54 | */ 55 | void co_val_init_max(int valid_calls); 56 | 57 | /** 58 | * Setups number of valid calls to co_val_init(). 59 | */ 60 | void co_val_init(int valid_calls); 61 | 62 | } // namespace LelyOverride 63 | 64 | #endif // HAVE_LELY_OVERRIDE 65 | 66 | #endif // !LELY_OVERRIDE_LELY_CO_VAL_H_ 67 | -------------------------------------------------------------------------------- /unit-tests/override/libc-defs.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_OVERRIDE_LIBC_DEFS_HPP_ 24 | #define LELY_OVERRIDE_LIBC_DEFS_HPP_ 25 | 26 | #if defined(__GNUC__) && !defined(__MINGW32__) 27 | /* libc overrides won't link properly on MinGW-W64 */ 28 | #define HAVE_LIBC_OVERRIDE 1 29 | 30 | #include "defs.hpp" 31 | #endif 32 | 33 | #endif // !LELY_OVERRIDE_LIBC_DEFS_HPP_ 34 | -------------------------------------------------------------------------------- /unit-tests/override/override-test-plugin.cpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include "override-test-plugin.hpp" 24 | 25 | #include 26 | 27 | #include 28 | 29 | using Override::OverridePlugin; 30 | 31 | static const char PLUGIN_NAME[] = "LelyOverridePlugin"; 32 | 33 | OverridePlugin::OverridePlugin() : TestPlugin(PLUGIN_NAME) {} 34 | 35 | OverridePlugin::~OverridePlugin() {} 36 | 37 | class OverridePlugin::CleanUp { 38 | public: 39 | explicit CleanUp(int& vc) : vc_(vc), org_value_(vc) {} 40 | ~CleanUp() { vc_ = org_value_; } 41 | 42 | private: 43 | int& vc_; 44 | const int org_value_; 45 | }; 46 | 47 | void 48 | OverridePlugin::postTestAction(UtestShell&, TestResult&) { 49 | while (!cleanups.empty()) cleanups.pop(); 50 | } 51 | 52 | void 53 | OverridePlugin::setForNextTest(int& vc, int target_value) { 54 | cleanups.emplace(vc); 55 | vc = target_value; 56 | } 57 | 58 | OverridePlugin* 59 | OverridePlugin::getCurrent() { 60 | auto registry = TestRegistry::getCurrentRegistry(); 61 | assert(registry != nullptr); 62 | auto plugin = registry->getPluginByName(PLUGIN_NAME); 63 | assert(plugin != nullptr); 64 | return static_cast(plugin); 65 | } 66 | -------------------------------------------------------------------------------- /unit-tests/override/override-test-plugin.hpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #ifndef LELY_OVERRIDE_TEST_PLUGIN_HPP_ 24 | #define LELY_OVERRIDE_TEST_PLUGIN_HPP_ 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | namespace Override { 32 | 33 | /** 34 | * CppUTest plugin for override methods. 35 | * Maintains proper 'valid calls' values across tests. 36 | */ 37 | class OverridePlugin : public TestPlugin { 38 | public: 39 | OverridePlugin(); 40 | ~OverridePlugin(); 41 | 42 | static OverridePlugin* getCurrent(); 43 | 44 | void postTestAction(UtestShell&, TestResult&) override; 45 | 46 | void setForNextTest(int& vc, int target_value); 47 | 48 | private: 49 | class CleanUp; 50 | std::stack cleanups; 51 | }; 52 | 53 | } // namespace Override 54 | 55 | #endif // !LELY_OVERRIDE_TEST_PLUGIN_HPP_ 56 | -------------------------------------------------------------------------------- /unit-tests/tests-shared-main.cpp: -------------------------------------------------------------------------------- 1 | /**@file 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include "override/override-test-plugin.hpp" 27 | 28 | int 29 | main(int ac, char** av) { 30 | Override::OverridePlugin plugin; 31 | TestRegistry::getCurrentRegistry()->installPlugin(&plugin); 32 | return RUN_ALL_TESTS(ac, av); 33 | } 34 | -------------------------------------------------------------------------------- /unit-tests/util/test-mutex.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the CANopen Library Unit Test Suite. 3 | * 4 | * @copyright 2020 N7 Space Sp. z o.o. 5 | * 6 | * Unit Test Suite was developed under a programme of, 7 | * and funded by, the European Space Agency. 8 | * 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | #if !LELY_NO_CXX 28 | 29 | TEST_GROUP(Util_Mutex) { 30 | class Mutex : lely::util::BasicLockable { 31 | public: 32 | bool lock_was_called = false; 33 | bool unlock_was_called = false; 34 | 35 | void 36 | lock() override { 37 | lock_was_called = true; 38 | } 39 | void 40 | unlock() override { 41 | unlock_was_called = true; 42 | } 43 | }; 44 | 45 | Mutex m; 46 | }; 47 | 48 | TEST(Util_Mutex, UnlockGuard_LocksAndUnlocksMutex) { 49 | { lely::util::UnlockGuard unlock_guard_mutex(m); } 50 | 51 | CHECK_EQUAL(true, m.lock_was_called); 52 | CHECK_EQUAL(true, m.unlock_was_called); 53 | } 54 | 55 | #endif // !LELY_NO_CXX 56 | --------------------------------------------------------------------------------