Libsockcanpp
A complete C++ wrapper around socketcan.
|
Welcome to the documentation for libsockcanpp!
libsockcanpp is a socketcan wrapper library for C++, aimed to be easy to use without any fuss.
[!NOTE] C++11 SUPPORT:
This library supports modern C++ features, such as concepts in certain places. If your project cannot support C++20 features, you can force the C++ standard back by setting
-Dsockcanpp_CONCEPT_SUPPORT=OFF
in the command-line orset(sockcanpp_CONCEPT_SUPPORT OFF CACHE BOOL "Force C++ standard back to 11")
in your CMakeLists.txt.
libsockcanpp was designed with use in CMake projects, but it can also easily be integrated into existing Makefile projects, as long as cmake is present on the build system.
1) clone the repository: git clone https://github.com/SimonCahill/libsockcanpp.git
2) create build directory: mkdir build && cd build
3) generate build files: cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchains/desired-toolchain.cmake
4) building library: make -j
1) clone the repository: git clone https://github.com/SimonCahill/libsockcanpp.git
2) add the following to CMakeLists.txt
3) generate and build 4) ??? profit
libsockcanpp provides a simple interface to socketcan, which is represented by the CanDriver class.
CanDriver
handles the setup of the socket; it does not however setup the CAN interface!
The example below describes how to instantiate a new instance of CanDriver.
You can create as many instances as required, the resources are free
'd once the instance has gone out of scope or been deleted.
The following parameters are required for correct instantiation:
1) CAN interface: [v]can[0-?] 2) CAN protocol: see linux/can.h for options 3) (optional) CAN sender ID (arbitration ID)
The following exceptions may be thrown if something went wrong during initialisation:
libsockcanpp provides a first-class datatype,
CanId supports the following operations:
Sending CAN frames with sockcanpp is as easy as you could imagine.
1) instantiate a
Receiving CAN messages is almost as simple as sending them! Firstly, check if there are any messages in the buffer, then pull them out; either one-by-one, or all at once!