Skip to content

Contributing

Thank you for helping with livox-mid360-core. This page covers the checks a change has to pass and how to run them locally. The build itself is in the README; the design is in docs/architecture.md and the per-layer pages next to it; open work and project decisions are in docs/roadmap.md.

Ground rules

  • Clean room. The library is written from the public Livox protocol wiki only. Do not copy or paraphrase code from Livox-SDK2 or other drivers; use them solely to compare behaviour on hardware. Record wiki ambiguities and their resolution in docs/protocol_notes.md.
  • Scope. Base Mid-360, Ubuntu 24.04+, no third-party runtime dependencies (the opt-in livox-mid360-rerun viewer, docs/rerun.md, is the one exception). See the decisions table in docs/roadmap.md before proposing something outside that.
  • Issues first. Every feature and design decision has an issue; link it from the PR and record the decisions taken in the issue or the matching docs/ page. Issue templates: bug report, hardware report (a real Mid-360 differs from the simulator or the docs, #11) and feature request; the first two ask for the version, platform and firmware. Labels: no-hardware (doable against the simulator), needs-hardware, phase-2 / phase-3, good first issue.
  • Tests. Protocol changes need golden vectors regenerated by tools/gen_golden_vectors.py (CI fails on a diff), transport / session / device changes need a simulator-driven test in tests/, and anything asynchronous must stay green under ASan + UBSan on a 2-vCPU runner. Keep simulator data rates low in tests (see tests/test_reconnect.cpp).
  • Errors, not exceptions. Fallible calls return std::expected; the library never writes to stdout or stderr.

Lint

Style and static analysis are enforced by the Lint workflow (clang-format 19, clang-tidy 19, ruff, ament_cppcheck, ament_lint_cmake). The configuration files .clang-format, .clang-tidy and pyproject.toml are shared with livox-mid360-ros2 (ament_clang_format --config; ruff reads pyproject.toml directly, ament_flake8 cannot, see below).

C++ follows the ROS 2 C++ style: .clang-format is a verbatim copy of the configuration shipped with ament_clang_format (the commit is named in the file header) and is re-synced by hand, not by CI. On top of the formatter, clang-tidy's readability-braces-around-statements requires braces on every if / for / while body. Deviations from the ROS 2 rules: #pragma once instead of include guards (so cpplint is not used, #17), and no cpplint-style header/footer comments. Code blocks in the documentation follow the same style.

Python (tools/, scripts/) follows the ROS 2 Python style as checked by ament_flake8 and ament_pep257 with their default settings, but enforced here with ruff: pyproject.toml selects the matching rule families (single quotes, google import order, 99 columns, the ament pydocstyle convention with the summary of a multi-line docstring on the second line). ruff has no port of flake8-deprecated or flake8-class-newline, so a class without a docstring needs a blank line before its first member, and ruff format's a[x : y] slice spacing trips E203; write a[x:end] with a named bound instead. Python snippets in docs and docstrings follow the same style. Whether the ruff configuration still matches the ROS 2 tools is checked by hand with the real tools (the ROS 2 side has no pyproject.toml support, so livox-mid360-ros2 uses ament_flake8 / ament_pep257 defaults). scripts/lint-ament-python.sh runs both on tools/ and scripts/ through uvx.

Of the ROS 2 ament_lint_common set, two more checks run here because they are cheap and useful on a plain CMake library (#65): ament_cppcheck (cppcheck from apt, with AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1 because ament refuses cppcheck 2.x by default) and ament_lint_cmake (all-lower-case command names, 140 columns). Both are installed with uv from the jazzy branch of ament_lint (AMENT_LINT_BRANCH in lint.yml). The rest is deliberately not run: ament_cpplint would need five filters for tool limitations (C++23 headers, Catch2 macros) and its remaining findings were fixed once by hand; ament_copyright requires the ROS 2 header format, and files here keep the one-line SPDX-License-Identifier: Apache-2.0; ament_uncrustify conflicts with clang-format, so the ROS 2 driver package uses ament_cmake_clang_format instead. The driver's colcon test never lints this library's files, so these are consistency checks, not requirements.

Run the same checks as CI locally with the commands below. The Python tools come from uv (#191); install them with uv tool install ruff==0.16.9 (the RUFF_VERSION in lint.yml) and, for the ROS 2 checks, uv tool install "ament_cppcheck @ git+https://github.com/ament/ament_lint.git@jazzy#subdirectory=ament_cppcheck", then the same for ament_lint_cmake. cppcheck itself comes from the system package manager.

scripts/lint.sh              # check (clang-tidy needs clang-19 and builds build-tidy/)
scripts/lint.sh --fix        # apply clang-format and ruff fixes
scripts/lint.sh --no-tidy    # formatting only
scripts/lint.sh --no-ament   # without the ROS 2 checks (needs cppcheck and the ament tools)
scripts/lint.sh --ament-only # only the ROS 2 checks

Fuzzing

Eight libFuzzer targets live in tests/fuzz/: the protocol parsers (fuzz_command_frame, fuzz_data_packet, fuzz_key_value_list), the endpoint text parser (fuzz_transport_text), the session helpers that turn a received datagram into a result (fuzz_session_ack, fuzz_discovery_ack, via the internal src/session_detail.hpp) and the whole Session request loop driven over a loopback socket pair (fuzz_session_loopback: the input selects the call, the retry count and the reply datagrams, which are queued before the call so no threads are involved) and the frame assembler fed with synthesised packet headers (fuzz_frame_assembler, via the internal src/frame_assembler.hpp). Each target has a seed corpus in tests/fuzz/corpus/<target>/, generated by tools/gen_fuzz_corpus.py from the Python reference implementation and kept in sync by CI. Build with Clang and run all of them:

cmake -S . -B build-fuzz -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++-19 \
      -DLIVOX_MID360_BUILD_FUZZERS=ON -DLIVOX_MID360_ENABLE_ASAN=ON -DLIVOX_MID360_ENABLE_UBSAN=ON
cmake --build build-fuzz --target fuzzers
scripts/fuzz.sh build-fuzz 30   # seconds per target; CI runs the same script

Coverage

The Coverage workflow builds with GCC 14 and LIVOX_MID360_ENABLE_COVERAGE=ON, runs the Catch2 suite and uploads a gcovr report to Codecov (README badge, line coverage). The HTML report is attached to each run as the coverage-html artifact. The counters are updated atomically (-fprofile-update=atomic): the tests are multithreaded, and racing counters make gcov report negative branch counts, which gcovr rejects (#125). Locally (gcovr from apt or pip):

cmake -S . -B build-cov -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLIVOX_MID360_ENABLE_COVERAGE=ON
cmake --build build-cov && ctest --test-dir build-cov
gcovr --root . --txt-metric branch --filter 'src/.*' --filter 'include/livox/mid360/.*' \
      --exclude 'tests/.*' --exclude 'build.*/.*' --html-details coverage.html --print-summary

Counted: src/ and include/livox/mid360/. Excluded: tests, fuzzers, generated golden vectors, Catch2, and the non-Linux fallback branches in src/transport.cpp (marked with GCOVR_EXCL_START / GCOVR_EXCL_STOP, since CI measures on Linux). Branch coverage is reported but the badge and the Codecov status checks use line coverage; both checks are informational for now.

Documentation site

The pages in docs/, this file, the README and the READMEs of examples/ and tools/ are published with the API reference as the project site (#104), built with Zensical (#185) and deployed to GitHub Pages from main by the Docs workflow. Write the Markdown for GitHub: scripts/stage_docs.py copies it into site-src/ (git-ignored) with the relative links and the > [!NOTE] alerts rewritten for the site, so edit the sources, not site-src/. zensical.toml holds the navigation, so a new page in docs/ needs an entry there; a page without one, or an entry without a page, fails stage_docs.py. Zensical runs in strict mode and fails on a broken link or anchor. Zensical and its dependencies are locked in requirements-docs.txt; after editing requirements-docs.in, relock with uv pip compile requirements-docs.in --python-version 3.12 --universal -o requirements-docs.txt.

API reference

The public headers in include/livox/mid360/ are the API reference: Doxygen generates it from their /// comments (#104). Every public symbol needs a comment. Write plain prose (the first sentence is the brief, no @param / @return), use ///< after struct fields and enum values, start each header with a /// @file description, and group the members of a large class with /// @name and ///@{ / ///@}. Symbols in a detail namespace are excluded. The Doxyfile turns every warning into an error, and the Docs workflow builds the reference on every pull request.

Doxygen is pinned to one release, because other versions report different warnings. scripts/install-doxygen.sh downloads that release binary into .cache/ and checks its SHA256. The upstream binaries cover Linux x86-64 and macOS; on other hosts, install the same version yourself and set DOXYGEN.

scripts/install-doxygen.sh           # once: the pinned Doxygen into .cache/
scripts/build-docs.sh                # the reference in docs/reference/, then the site in site/
scripts/build-docs.sh --serve        # the same, served on http://localhost:8000 with reload
scripts/build-docs.sh --doxygen-only # the reference only, without Python

The site steps run stage_docs.py and Zensical through uv. All output directories are git-ignored.

Continuous integration

CI runs gcc-13, gcc-14 and clang-19 in Release plus gcc-14 and clang-19 in Debug with ASan + UBSan, each on x86-64 and arm64 (ubuntu-24.04-arm), Apple Clang in Release on macos-latest, and separate jobs for the Python reference and simulator tests and a short run of every fuzzer. Lint runs clang-format 19, clang-tidy 19 and ruff; Coverage uploads to Codecov. Docs builds the API reference and the site, deploys it from main, and unlike the others also runs on documentation-only changes.

To reproduce CI locally on any Docker host: docker/check.sh [linux/arm64|linux/amd64]. The platform defaults to the host's. On Apple Silicon linux/arm64 runs natively; a non-native platform runs under QEMU emulation, where the script only does the Release builds, ctest and the Python tests and skips the sanitizer and fuzz steps. docker/check.sh runs the linters before the builds, so it is the one-stop pre-push check.

Pull requests

  • One issue per PR where possible; title in the conventional style used in the history (feat(device): ..., fix: ..., docs: ..., ci: ..., test: ...).
  • Update the documentation that describes what you changed in the same PR: the per-layer page in docs/, docs/architecture.md if threads, locks or data flow moved, and docs/roadmap.md when an issue is finished.
  • PRs are squash-merged; the PR title becomes the commit subject.
  • The PR template (.github/pull_request_template.md) carries this list as a checklist; strike through or remove the items that do not apply.