Skip to content

PonomarevDA/libdcnode

Repository files navigation

libdcnode Code Smells Lines of Code build

Lightweight DroneCAN / UAVCAN v0 node toolkit built on top of libcanard, platform_specific and libparams. It wraps the transport, exposes a small C API for node setup/spin, and offers C++ helpers for typed publishers/subscribers and logging.

Features

  • Implements core DroneCAN services out of the box: NodeStatus, GetNodeInfo, Param.GetSet and Param.ExecuteOpcode, RestartNode, and GetTransportStats.
  • Platform abstraction (include/libdcnode/platform.hpp) so you can plug in your own timing, reset, unique-ID, and CAN driver callbacks.
  • Templated C++ wrappers for publishing/subscribing (include/libdcnode/pub.hpp, include/libdcnode/sub.hpp) with optional filters and periodic senders; legacy interfaces remain in include/libdcnode/publisher.hpp and include/libdcnode/subscriber.hpp.
  • Debug logger (include/libdcnode/logger.hpp) that publishes uavcan.protocol.debug.LogMessage with severity helpers.
  • DSDL compiler baked into the build (Libs/dronecan_dsdlc) so message code is generated during CMake configure.

Prerequisites

  • C/C++ toolchain with C++17, CMake >= 3.15, Python 3 (for tests/tools).
  • Linux SocketCAN stack and ip utilities (used by scripts/vcan.sh).
  • can-utils (for monitoring) and dronecan_gui_tool are handy when playing with the examples.

Getting started

Set up the Python deps (used by the DSDL generator and tests):

python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

Then wire the library into your project:

add_subdirectory(libdcnode)
target_link_libraries(my_app PRIVATE libdcnode::libdcnode)

During configure, DSDL code is generated into build/generated/libdcnode/serialization using Libs/dronecan_dsdlc/dronecan_dsdlc.py. If you add custom DSDL namespaces, point DSDL_IN_DIR (see CMakeLists.txt) to your set or rerun scripts/code_generation.sh with your paths.

Provide the platform and params hooks from include/libdcnode/platform.hpp and include/libdcnode/params.hpp in your application; the Ubuntu example shows minimal implementations.

Ubuntu example (build, link, run)

The examples/ubuntu target demonstrates the C API plus the modern C++ pub/sub wrappers end-to-end.

# Prepare a virtual CAN iface once (uses sudo):
scripts/vcan.sh slcan0

# Build and run the example:
make ubuntu

What it does: sets uavcan.node.id (default 50) and system.name, wires platform callbacks (time, restart request, UID, CAN driver) in examples/ubuntu/main.cpp, subscribes to esc.RawCommand/actuator.ArrayCommand/indication.LightsCommand, and publishes periodic equipment.power.CircuitStatus + equipment.power.BatteryInfo while serving NodeStatus/GetNodeInfo.

In gui_tool you will see:

drawing

drawing

Testing

python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt
scripts/vcan.sh slcan0  # once, requires sudo
pytest tests/smoke_socketcan.py

The smoke tests expect the Ubuntu example (node ID 50 on slcan0) to be running; they verify NodeStatus and GetNodeInfo responses via the dronecan Python client.

Changelog

Version ReleaseDate Note
v0.7.0 2025-12-28 Added DSDL ser/des generator
v0.6.0 2025-10-17 Build model changed: standalone library; platform hooks provided by user (no more source-include mode).
v0.5.0 2024-09-26 Decoupled the platform specific functions from the library
v0.4.0 2024-07-29 Added macro helpers for pub and sub traits
v0.3.* 2024-01-06 Incremental serialization additions
v0.2.0 2024-01-06 Add bxcan and fdcan drivers
v0.1.0 2023-12-22 First public drop; pure C, manual serialization, and source-include usage (include the C sources into your app).

License

The software is distributed under term of MPL v2.0 license.

About

Lightweight DroneCAN node toolkit built on top of libcanard, platform_specific and libparams

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •