livox-mid360-core¶
Important
Unofficial. This project is not affiliated with, endorsed by, or supported by Livox or DJI. "Livox" and "Mid-360" are trademarks of their respective owners and are used here only to identify the device this library talks to.
A clean-room, dependency-free C++ SDK for the Livox Mid-360 LiDAR, written from the public protocol specification only. It targets Ubuntu 24.04 and later and the base Mid-360 (Mid-360S / Mid-360L specific features are out of scope for v1).
Status¶
Version 0.1.0: phase 1 is complete. The protocol, UDP transport, session and device layers
are implemented and tested end to end against the bundled LiDAR simulator, including
automatic reconnection and multi-device operation. Phase 2 (typed configuration and status
APIs, diagnostics, samples, hardware verification) is in progress and phase 3 (C ABI, ROS 2)
has not started. Firmware upgrade commands (0x04xx) are out of scope. The full item list
with tracking issues is in docs/roadmap.md.
Getting started¶
docs/getting_started.md goes step by step from a fresh Ubuntu 24.04
machine to point clouds: build and test, receive from the bundled simulator, record and replay
an .lvx2 file, connect a real Mid-360 and use the library from your own CMake project. The
same pages, with the API reference generated from the headers, are published as the
project site.
Requirements¶
- Ubuntu 24.04+ with GCC 13/14 or Clang 19 (macOS with Apple Clang works for development and is built and tested in CI).
x86-64 and arm64 are both verified in CI (native
ubuntu-24.04-armrunners). NVIDIA Jetson with JetPack 6 (Ubuntu 22.04) is outside this support statement until a compatible toolchain is confirmed. Clang 18 with libstdc++ does not expose<expected>(it reports__cpp_concepts201907); use Clang 19+ or-stdlib=libc++there. Clang links the libstdc++ of the newest GCC whoselibgcc-N-devis installed: withlibgcc-14-devbut nolibstdc++-14-devit fails withcannot find -lstdc++, so installlibstdc++-14-devtoo. - CMake ≥ 3.28, Ninja recommended
- Compiler flag
-std=c++23: the code is C++20 plusstd::expected, which standard libraries ship under C++23 only - Tests: Catch2 v3 (
apt install catch2; otherwise fetched automatically with FetchContent)
Build¶
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build --output-on-failure
cmake --install build --prefix /usr/local
CMake options:
| Option | Meaning | Default |
|---|---|---|
LIVOX_MID360_BUILD_TESTS |
Build the Catch2 unit tests (including the simulator-backed tests) | ON when built top-level, OFF as a subproject |
LIVOX_MID360_BUILD_RERUN |
Build livox-mid360-rerun, a Rerun viewer for live and lvx2 point clouds. Fetches the Rerun C++ SDK and builds Apache Arrow, the only third-party dependency in the repository (docs/rerun.md) |
OFF |
LIVOX_MID360_BUILD_FUZZERS |
Build the libFuzzer targets (Clang only) | OFF |
LIVOX_MID360_WARNINGS_AS_ERRORS |
Treat compiler warnings as errors (-Werror) |
ON when built top-level, OFF as a subproject |
LIVOX_MID360_ENABLE_ASAN |
Enable AddressSanitizer | OFF |
LIVOX_MID360_ENABLE_UBSAN |
Enable UndefinedBehaviorSanitizer | OFF |
LIVOX_MID360_ENABLE_COVERAGE |
Instrument the library and tests with --coverage -fprofile-update=atomic (gcov) |
OFF |
BUILD_SHARED_LIBS |
Build a shared library (standard CMake variable, defaulted by this project) | ON |
"Top-level" is decided by PROJECT_IS_TOP_LEVEL, so consumers using add_subdirectory or
FetchContent get no tests and no -Werror unless they opt in.
Usage¶
find_package(livox_mid360_core CONFIG REQUIRED)
target_link_libraries(app PRIVATE livox::mid360_core)
#include <iostream>
#include <livox/mid360/mid360.hpp>
using namespace livox::mid360;
// One receive thread for all LiDARs (host ports 56201 / 56301 / 56401 on this interface).
auto ctx = Context::create({.bind_address = {192, 168, 1, 5}});
if (!ctx) {
std::cerr << to_string(ctx.error()) << "\n";
return 1;
}
// Find the LiDAR, point it at this host (commands block on the calling thread).
auto devices = discover(); // broadcast 0x0000, 1 s
if (!devices || devices->empty()) {
std::cerr << "discovery: " << (devices ? "no LiDAR answered" : to_string(devices.error()))
<< "\n";
return 1;
}
auto dev = Device::open(**ctx, devices->front(), {.session = {.bind_address = {192, 168, 1, 5}}});
if (!dev) {
std::cerr << to_string(dev.error()) << "\n";
return 1;
}
// Frames and IMU samples arrive on the receive thread; hand them to your own thread.
BoundedQueue<Frame> frames; // drops the oldest when full
(void)(*dev)->on_frame([&](Frame && f) { frames.push(std::move(f)); });
(void)(*dev)->on_imu([](const ImuData & imu) { /* 200 Hz */ });
(void)(*dev)->on_event([](const Event & e) { std::clog << to_string(e) << "\n"; });
if (auto r = (*dev)->start_sampling(); !r) { // work_tgt_mode = SAMPLING + wait
std::cerr << to_string(r.error()) << "\n"; // e.g. session: lidar_rejected ...
return 1;
}
while (auto f = frames.pop(std::chrono::seconds{1})) {
for (const Point & p : f->points) {
// x, y, z in metres, offset_ns from f->base_time_ns
}
}
(void)(*dev)->stop_sampling();
dev->reset(); // Devices before the Context
A runnable version with CLI flags, SIGINT handling and a simulator recipe is
examples/minimal_receive.cpp and examples/collect_firmware_log.cpp (see examples/README.md).
The lower layers stay available on their own: Session / apply_host_setup for synchronous
control without a receive thread, and parse_data_packet / decode_cartesian32 for raw
datagrams (parsers return std::expected<..., ParseError> and non-owning views into the
input buffer; keep the buffer alive while you use the result). See docs/api.md for the
threading rules and docs/architecture.md for how the layers, threads and data flows fit together.
Layout¶
include/livox/mid360/ public headers (crc, protocol, keys, hms, bytes, transport, session, config,
context, device, frame, event, mid360 umbrella)
src/ implementation
tests/ Catch2 tests, generated golden vectors, libFuzzer targets
tools/ Python reference implementation, pcap decoder, golden-vector generator, LiDAR simulator,
tools/cli: livox-mid360-cli (lvx2 record / replay, docs/lvx2.md),
tools/rerun: livox-mid360-rerun (Rerun viewer, docs/rerun.md)
docs/ getting_started.md (first steps), roadmap.md (status and plans), architecture.md (overview: layers, threads, data flow), protocol_notes.md (wiki ambiguities), transport.md (UDP layer guide), session.md (discovery/commands), api.md (device layer design), simulator.md, lvx2.md (record / replay), rerun.md (viewer)
docker/ Ubuntu 24.04 reproduction of CI
Contributing¶
Lint, fuzzing, coverage and how to reproduce CI locally are described in CONTRIBUTING.md. Open work is tracked in docs/roadmap.md.
References¶
- Protocol: https://livox-wiki-en.readthedocs.io/en/latest/tutorials/new_product/mid360/livox_eth_protocol_mid360.html (rev v1.4.12)
- HMS codes: https://livox-wiki-en.readthedocs.io/en/latest/tutorials/new_product/mid360/hms_code_mid360.html
- Mid-360 downloads (manual, firmware, Livox Viewer 2, sample point clouds): https://www.livoxtech.com/mid-360/downloads
- All Livox downloads (Livox Viewer releases, LVX file specifications, SDK API reference): https://www.livoxtech.com/downloads
The official Livox-SDK2 is used only as a behavioural reference for hardware testing. No code is copied from it.
License¶
Apache-2.0. See LICENSE.