A modern high-performance CAN communication protocol library for Linux, designed for scenarios with strict real-time requirements.
- High concurrency based on
epoll. In scenarios with 100k messages per second (Send + Receive):- Low CPU usage: average
8%CPU usage (on AMD Ryzen 7 7840HS), no frame loss - Low latency: average latency as low as 10 µs per message
- See InterfaceStressTest for details
- Low CPU usage: average
- User-friendly API
- No root privileges required: with the
HyCAN Daemonsystem service, user applications can run as normal users - Automated interface management: the daemon manages
CAN/VCANinterfaces onNetlinkdirectly inside the library
- High real-time requirements
- Control algorithms depending on vast motor feedback frames on the CAN bus
- Highly sensitive to message delays
- Reduced deployment complexity and improved security
- Avoid running scripts to manually bring up CAN/VCAN interfaces before each run
- Remove the dependency on root privileges for user applications
- Centralized management of CAN interface resources through the daemon
- No need to introduce other heavyweight libraries
-
Build system
- CMake (>= 3.20)
-
Compilers
- GCC (>= 13) or Clang (>= 15)
-
System environment
- Linux
canandvcankernel modules (usually provided by thelinux-modules-extrapackage) - Load the kernel modules with
modprobe:
sudo modprobe vcan sudo modprobe can
- Linux
Download the prebuilt packages from the releases page.
# Debian-based systems
sudo apt install pkg-config cmake libnl-3-dev libnl-route-3-dev libexpected-devcmake -S . -B build
cmake --build build
# Install to the system (including the HyCAN daemon)
sudo cmake --install buildHyCAN is designed to be consumed from CMake projects. A minimal CMakeLists.txt example:
cmake_minimum_required(VERSION 3.20)
project(MyConsumerApp)
find_package(HyCAN REQUIRED)
add_executable(MyConsumerApp main.cpp)
target_link_libraries(MyConsumerApp PRIVATE HyCAN::HyCAN)Example main.cpp:
#include <HyCAN/Interface/Interface.hpp>
using HyCAN::CANInterface;
int main() {
constexpr can_frame test_frame = {
.can_id = 0x100,
.len = 8,
.data = {0, 1, 2, 3, 4, 5, 6, 7},
};
CANInterface can_interface("can0");
can_interface.send(test_frame);
return 0;
}Your application can now run with normal user privileges:
# No sudo required!
./MyConsumerAppMake sure the HyCAN daemon is running:
# Start the daemon if it is not running
sudo systemctl start hycan-daemonSee the programs under the example directory.
HyCAN uses a daemon-based architecture:
- HyCAN Daemon: runs as a
systemdservice with root privileges to manage CAN/VCAN interfaces - User applications: communicate with the daemon via IPC and can operate CAN interfaces without root privileges
- Security isolation: only the daemon needs elevated privileges; user code runs in a restricted environment
# Check daemon status
sudo systemctl status hycan-daemon
# View daemon logs
sudo journalctl -u hycan-daemon -f
# Restart the daemon
sudo systemctl restart hycan-daemonIf you encounter permission-related errors, make sure:
- The HyCAN daemon is installed and running
- Your application is running as a normal user (no sudo required)
- More examples and tests
- Native Linux CAN filter support
- Doxygen docs
-
Messageclass wrapping common functionality