livox_mid360_core
C++ driver library for the Livox Mid-360 LiDAR
Loading...
Searching...
No Matches
livox::mid360 Namespace Reference

The livox_mid360_core library: everything declared by the public headers. More...

Namespaces

namespace  bytes
 Little-endian byte helpers used by the protocol layer (bytes.hpp).
namespace  crc
 CRC-16 and CRC-32 as defined by the Mid-360 communication protocol (crc.hpp).

Classes

class  BoundedQueue
 Bounded single-producer / multi-consumer queue for handing Frames or ImuData from the receive thread to any other thread. More...
struct  CartesianPoint16
 One sample of data type 2 (kCartesian16). More...
struct  CartesianPoint32
 One sample of data type 1 (kCartesian32). More...
struct  CommandFrameSpec
 What encode_command_frame() writes; length and both CRCs are computed from it. More...
struct  CommandFrameView
 A validated, non-owning view over a command frame. More...
struct  CommandHeader
 The 24-byte command frame header as decoded by parse_command_frame(). More...
class  Context
 Owns the receive sockets and the receive thread. More...
struct  ContextOptions
 Sockets and receive-thread settings of a Context, passed to Context::create(). More...
struct  ContextStats
 Counters of the shared receive side, snapshot via Context::stats(). More...
struct  Datagram
 One received UDP datagram. More...
struct  DataPacketHeader
 The 36-byte data packet header as decoded by parse_data_packet(). More...
struct  DataPacketView
 A validated, non-owning view over a data packet. More...
struct  DebugDataControlRequest
 0x0303 request: start (enable) or stop the stream towards host_ip:host_port. More...
struct  DebugDataPacket
 What Device hands to a DebugDataCallback: one datagram of the stream, not interpreted (receive thread; data is valid only during the callback, copy it to keep it). More...
class  Device
 One LiDAR: commands through its own Session, data through the Context it was opened on. More...
struct  DeviceError
 Errors of Context / Device. Session-level failures are wrapped, not re-encoded. More...
struct  DeviceIdentity
 Keys 0x8000-0x8005 (issue #38). More...
struct  DeviceOptions
 Per-Device settings, passed to Device::open(). More...
struct  DeviceStats
 Counters of one Device, snapshot via Device::stats(). Monotonic since open(). More...
struct  DiagStatus
 Key 0x800E, u16 bitfield split into four subsystem levels (issue #55). More...
struct  DiscoveredDevice
 One LiDAR that answered the 0x0000 discovery broadcast. More...
struct  DiscoveryAck
 Data of the 0x0000 discovery ACK. More...
struct  DiscoveryOptions
 Parameters of discover(). More...
struct  Endpoint
 IPv4 address + UDP port. Mid-360 is IPv4 only. More...
struct  Event
 One notification. kind selects which fields are meaningful; the rest are default. More...
struct  Extrinsic
 Host-side install attitude transform (issue #51). More...
struct  FirmwareLogChunk
 What Device hands to a FirmwareLogCallback (receive thread; data is valid only during the callback, copy it to keep it). More...
struct  FirmwareLogControlRequest
 0x0301 request: start (enable) or stop collecting log_type. More...
struct  FirmwareLogFlags
 flag bits of a 0x0300 push (SDK2 logger_manager.cpp). More...
struct  FirmwareLogPushAck
 Host → LiDAR answer to a push with ack_requested(), sent as a cmd-type 0x0300 frame. More...
struct  FirmwareLogPushHeader
 0x0300 push header (16 bytes, little-endian) followed by data_length bytes. More...
struct  FirmwareLogPushView
 A validated 0x0300 push: header plus a view over its data. More...
struct  FovConfig
 Keys 0x0015 / 0x0016: one FOV window in degrees. More...
struct  FovEnable
 Key 0x0017 bitmask: bit 0 enables fov_cfg0, bit 1 enables fov_cfg1. More...
struct  FovSettings
 The three FOV keys together (issue #39): Device::set_fov() sends the present ones in one 0x0100, Device::fov() reads all three. More...
struct  Frame
 A group of points closed by FramePolicy. Owns its storage; delivered by value. More...
struct  FramePolicy
 How a Device cuts the packet stream into Frames (#6). More...
struct  FuncIoConfig
 Key 0x0019; M12 pins 8, 10, 12, 11. Same layout as the 4 raw bytes. More...
struct  HmsCode
 One decoded HMS code (one of the eight uint32 slots of key 0x8011). More...
struct  HostIpConfig
 Keys 0x0005 / 0x0006 / 0x0007 / 0x0009: where the LiDAR sends one kind of data. More...
struct  HostSetup
 What the LiDAR needs to know about this host. More...
struct  HostSetupKeyValues
 The 0x0100 payload of the first request, without the session: values are views into storage, so the struct must outlive its use. More...
struct  HostSetupResult
 Outcome of apply_host_setup(). More...
struct  ImuData
 One IMU packet (the LiDAR sends one sample per packet at 200 Hz) with its time. More...
struct  ImuSample
 The sample of an IMU packet (data type 0). More...
struct  ImuSensorConfig
 Key 0x002B: IMU output rate and ranges. More...
struct  InfoPush
 Data of the 0x0102 information push. More...
struct  InquireResult
 Result of 0x0101: owns the ACK bytes so that values stays valid after moves. More...
struct  InstallAttitude
 Key 0x0012: mounting rotation (degrees) and offset (millimetres) of the LiDAR. More...
struct  key_traits
struct  key_traits< Key::kCoreTemp >
struct  key_traits< Key::kCurWorkState >
struct  key_traits< Key::kDetectMode >
struct  key_traits< Key::kFovCfg0 >
struct  key_traits< Key::kFovCfg1 >
struct  key_traits< Key::kFovCfgEn >
struct  key_traits< Key::kFuncIoCfg >
struct  key_traits< Key::kFwType >
struct  key_traits< Key::kHmsCode >
struct  key_traits< Key::kImuDataEn >
struct  key_traits< Key::kImuHostIpCfg >
struct  key_traits< Key::kImuSensorCfg >
struct  key_traits< Key::kInstallAttitude >
struct  key_traits< Key::kLastSyncTime >
struct  key_traits< Key::kLidarDiagStatus >
struct  key_traits< Key::kLidarIpCfg >
struct  key_traits< Key::kLocalTimeNow >
struct  key_traits< Key::kLogHostIpCfg >
struct  key_traits< Key::kMac >
struct  key_traits< Key::kPatternMode >
struct  key_traits< Key::kPclDataType >
struct  key_traits< Key::kPointCloudHostIpCfg >
struct  key_traits< Key::kPowerupCnt >
struct  key_traits< Key::kProductInfo >
struct  key_traits< Key::kSn >
struct  key_traits< Key::kStateInfoHostIpCfg >
struct  key_traits< Key::kTimeFilter >
struct  key_traits< Key::kTimeOffset >
struct  key_traits< Key::kTimeSyncType >
struct  key_traits< Key::kVersionApp >
struct  key_traits< Key::kVersionHardware >
struct  key_traits< Key::kVersionLoader >
struct  key_traits< Key::kWorkTgtMode >
struct  KeyValue
 One entry of a key-value list. Non-owning: value points into the parsed buffer. More...
struct  LidarIpConfig
 Key 0x0004: the LiDAR's own network configuration. More...
struct  LidarSettings
 The 16 modelled writable keys. More...
struct  LidarStatus
 Keys 0x8006-0x8011: the live state, also carried by the 0x0102 push. More...
struct  LogRecord
 One diagnostic record. The views are valid only during the handler call. More...
struct  Lvx2DeviceInfo
 One entry of the lvx2 device-info block (63 bytes on disk). More...
struct  Lvx2DevicePlayStats
 The share of one played device in Lvx2PlayStats. More...
struct  Lvx2Error
 Error of the lvx2 writer, reader and player. More...
struct  Lvx2FileHeader
 Public + private header of a file. More...
struct  Lvx2Packet
 One package (packet) of a frame as read from a file. More...
class  Lvx2Player
 Replays a file: packets go to on_packet as-is, and through a FrameAssembler per device (timestamps are the recorded ones, TimestampPolicy::kLidar) to on_frame / on_device_frame. More...
struct  Lvx2PlayOptions
 Settings of an Lvx2Player. More...
struct  Lvx2PlayStats
 Result of Lvx2Player::run(): the totals over all played devices, plus each device's share. More...
class  Lvx2Reader
 Reads an lvx2 file package by package. More...
class  Lvx2Writer
 Writes an lvx2 file from raw data packets. More...
struct  ParamConfigAck
 Data of the 0x0100 parameter configuration ACK. More...
struct  ParamInquireAck
 Data of the 0x0101 parameter inquire ACK. More...
struct  Point
 One return, same semantics as livox_ros_driver2's CustomPoint. More...
class  Poller
 Waits for readability on a set of sockets. More...
struct  RawAck
 Result of a raw request: the ACK payload, owned. More...
struct  ReadyEvent
 One socket reported by Poller::wait(). More...
struct  ReceiveInfo
 Per-packet metadata handed to on_packet together with the non-owning DataPacketView. More...
struct  ReconnectOptions
 Disconnect detection and automatic recovery (issue #8). More...
struct  RequestOptions
 Timeout and retry policy of one request. More...
class  Session
 Synchronous command channel to one LiDAR. Move-only. More...
struct  SessionError
 Error of a Session call or of discover(). Only the fields named by kind are meaningful. More...
struct  SessionOptions
 Parameters of Session::connect(). More...
struct  SessionStats
 Counters of one Session, see Session::stats(). More...
struct  SetResult
 Result of Device::set<K>() / set_many<>(): the LiDAR accepted the values. More...
struct  SimpleAck
 Data of an ACK that carries only a return code (0x0200, 0x0201, 0x0202, 0x0301, 0x0303). More...
struct  SocketOptions
 Options of UdpSocket::open(). More...
struct  SphericalPoint
 One sample of data type 3 (kSpherical). More...
struct  TagInfo
 Decoded tag byte: bit 0-1 adjacent glue, 2-3 rain / fog / dust, 4-5 other, 6-7 reserved. More...
struct  TimeSyncStatus
 Time-sync state read by Device::time_sync_status() (issue #53): keys 0x8009–0x800C in one inquire. More...
struct  TransportError
 Error of a transport call: a category plus the errno it came from. More...
class  UdpSocket
 Non-blocking IPv4 UDP socket. Move-only; closes the descriptor on destruction. More...
struct  Version
 Keys 0x8002 / 0x8003 / 0x8004, "aa.bb.cc.dd". More...

Concepts

concept  typed_key
 Satisfied by every key that has key_traits.
concept  writable_key
 Satisfied by keys that may be written with Device::set<K>().

Typedefs

using PacketCallback = std::function<void(const DataPacketView &, const ReceiveInfo &)>
 Every parsed point-cloud / IMU data packet; the view is valid only during the call.
using FrameCallback = std::function<void(Frame &&)>
 Every completed Frame, moved to the callee.
using ImuCallback = std::function<void(const ImuData &)>
 Every IMU sample.
using EventCallback = std::function<void(const Event &)>
 Every Event (state, HMS, diagnostics, connection, periodic stats, firmware log gaps).
using PushCallback = std::function<void(const LidarStatus &)>
 Every successfully parsed 0x0102 push, as the snapshot pushed_status() now returns (#56).
using FirmwareLogCallback = std::function<void(const FirmwareLogChunk &)>
 One 0x0300 firmware log push (#44); data is valid only during the call.
using DebugDataCallback = std::function<void(const DebugDataPacket &)>
 One datagram of the debug raw data stream (#93); data is valid only during the call.
using LogHandler = std::function<void(const LogRecord &)>
 Called from the Context receive thread, the Device worker thread and caller threads, never while an SDK mutex is held.
Key traits

key_traits<K> (issue #57): the C++ type of each key and its codec, used by Device::set<K>() / get<K>().

Writable keys have encode (bytes for a KeyValue) and decode; read-only keys only decode. Keys of the Mid-360S / 360L (kSpeedMode, kPcFreqMod) have no traits on purpose (project decision, docs/roadmap.md).

template<Key K>
using key_value_t = typename key_traits<K>::value_type
 The C++ type of key K, e.g. key_value_t<Key::kPclDataType> is DataType.

Enumerations

enum class  DisconnectReason : std::uint8_t {
  kNone = 0 , kPushTimeout , kCommandTimeout , kRebootRequested ,
  kUser
}
 Why a Device left the connected state (Event::reason, issue #8). More...
enum class  FirmwareLogType : std::uint8_t { kRealTime = 0 , kException = 1 }
 log_type of 0x0300 / 0x0301. SDK2 states that only the real-time log is supported. More...
enum class  TimestampPolicy : std::uint8_t { kLidar , kHostOffsetOnce , kHostReceive }
 How point/IMU timestamps are produced from the packet timestamp (#6). More...
enum class  HmsLevel : std::uint8_t {
  kNone = 0 , kInfo = 1 , kWarning = 2 , kError = 3 ,
  kFatal = 4
}
 Abnormal level, byte 0 of an HMS code. More...
enum class  Key : std::uint16_t {
  kPclDataType = 0x0000 , kPatternMode = 0x0001 , kLidarIpCfg = 0x0004 , kStateInfoHostIpCfg = 0x0005 ,
  kPointCloudHostIpCfg = 0x0006 , kImuHostIpCfg = 0x0007 , kLogHostIpCfg = 0x0009 , kInstallAttitude = 0x0012 ,
  kFovCfg0 = 0x0015 , kFovCfg1 = 0x0016 , kFovCfgEn = 0x0017 , kDetectMode = 0x0018 ,
  kFuncIoCfg = 0x0019 , kWorkTgtMode = 0x001A , kImuDataEn = 0x001C , kSpeedMode = 0x0021 ,
  kTimeFilter = 0x0026 , kPcFreqMod = 0x0029 , kImuSensorCfg = 0x002B , kSn = 0x8000 ,
  kProductInfo = 0x8001 , kVersionApp = 0x8002 , kVersionLoader = 0x8003 , kVersionHardware = 0x8004 ,
  kMac = 0x8005 , kCurWorkState = 0x8006 , kCoreTemp = 0x8007 , kPowerupCnt = 0x8008 ,
  kLocalTimeNow = 0x8009 , kLastSyncTime = 0x800A , kTimeOffset = 0x800B , kTimeSyncType = 0x800C ,
  kLidarDiagStatus = 0x800E , kFwType = 0x8010 , kHmsCode = 0x8011
}
 Keys of the key-value list (0x0100 configure, 0x0101 inquire, 0x0102 push). More...
enum class  KeyError : std::uint8_t { kWrongLength , kOutOfRange }
 Why a key value did not decode. More...
enum class  LogLevel : std::uint8_t {
  kOff , kError , kWarn , kInfo ,
  kDebug , kTrace
}
 Severity, ordered: a level is emitted when it is <= the level set with set_log_level(). More...
enum class  SessionErrorKind : std::uint8_t {
  kTransport , kTimeout , kBadResponse , kLidarRejected ,
  kUnexpectedState , kCancelled , kInvalidArgument
}
 Category of a SessionError. More...
enum class  DeviceType : std::uint8_t { kUnknown , kMid360 }
 Device type named by the dev_type byte of the 0x0000 ACK (#58). More...
enum class  TagConfidence : std::uint8_t { kHigh = 0 , kMedium = 1 , kLow = 2 , kReserved = 3 }
 Confidence that a point is a normal return for one tag category; higher = more likely noise.
enum class  TransportErrorCode : std::uint8_t {
  kSocketCreate , kBind , kSetOption , kAddressInUse ,
  kNetworkUnreachable , kSendFailed , kMessageTooLong , kWouldBlock ,
  kTimeout , kInterrupted , kClosed , kInvalidArgument ,
  kOther
}
 Category of a TransportError. More...

Functions

HostSetupKeyValues host_setup_key_values (const HostSetup &setup, const Ipv4 &host_ip)
 Build the first 0x0100 request of apply_host_setup() for setup.
std::expected< HostSetupResult, SessionError > apply_host_setup (Session &session, const HostSetup &setup, std::optional< RequestOptions > opts=std::nullopt)
 Apply setup through session.
std::array< std::byte, kDebugDataControlSize > encode_debug_data_control (const DebugDataControlRequest &req) noexcept
 0x0303 payload: {enable u8, host_ip u8[4], host_port u16, reserved u16}, little-endian.
std::expected< DebugDataControlRequest, ParseError > parse_debug_data_control (std::span< const std::byte > data) noexcept
 enable is any non-zero byte; bytes after the ninth are ignored.
std::string_view to_string (Event::Kind kind) noexcept
 Name of an event kind, e.g. "state_changed".
std::string_view to_string (DisconnectReason reason) noexcept
 Name of a disconnect reason, e.g. "push_timeout".
std::string to_string (const Event &event)
 One-line description of an event with the fields its kind uses.
std::string_view to_string (DeviceError::Kind kind) noexcept
 Name of an error kind, e.g. "invalid_state".
std::string to_string (const DeviceError &err)
 One-line description of an error, including the wrapped SessionError or key.
std::string_view to_string (FirmwareLogType t) noexcept
 Lower-case name ("realtime", "exception"; "unknown" for other values).
std::string to_string (const FirmwareLogPushHeader &h)
 One-line summary of the header fields, for logs.
std::array< std::byte, 2 > encode_firmware_log_control (const FirmwareLogControlRequest &req) noexcept
 0x0301 payload: {log_type, enable}.
std::expected< FirmwareLogControlRequest, ParseError > parse_firmware_log_control (std::span< const std::byte > data) noexcept
 Inverse of encode_firmware_log_control(); enable is any non-zero byte, extra bytes are ignored.
std::expected< FirmwareLogPushView, ParseError > parse_firmware_log_push (std::span< const std::byte > data) noexcept
 0x0300 payload: header + data.
std::expected< std::vector< std::byte >, EncodeError > encode_firmware_log_push (const FirmwareLogPushHeader &header, std::span< const std::byte > data)
 Serialises a push payload (header + data); nullopt-free: data above the frame limit is an EncodeError::kDataTooLarge.
std::array< std::byte, kFirmwareLogPushAckSize > encode_firmware_log_push_ack (const FirmwareLogPushAck &ack) noexcept
 FirmwareLogPushAck payload: {ret_code u8, log_type u8, file_index u8, trans_index u32}.
std::expected< FirmwareLogPushAck, ParseError > parse_firmware_log_push_ack (std::span< const std::byte > data) noexcept
 Inverse of encode_firmware_log_push_ack(); bytes after the seventh are ignored.
Extrinsic extrinsic_from (const InstallAttitude &a) noexcept
 Rotation = Rz(yaw) * Ry(pitch) * Rx(roll) (intrinsic ZYX, right-handed, degrees); translation = offsets in mm / 1000, added after the rotation.
void apply (const Extrinsic &e, std::span< Point > points) noexcept
 Transforms every point in place; reflectivity, tag, line and offset are untouched.
void apply (const Extrinsic &e, Frame &frame) noexcept
 Transforms every point of frame in place, as the span overload does.
constexpr HmsCode decode_hms (std::uint32_t raw) noexcept
 Splits a raw HMS code into its fields.
std::string_view to_string (HmsLevel l) noexcept
 Name of the level, e.g. "warning".
std::string_view hms_description (std::uint16_t abnormal_id) noexcept
 Human-readable description for an abnormal ID from the official table, or "" if unknown.
std::string_view hms_suggestion (std::uint16_t abnormal_id) noexcept
 Suggested action from the official table, or "" if unknown.
std::string_view to_string (Key k) noexcept
 Wire name of the key, e.g. "pcl_data_type".
constexpr bool is_read_only (Key k) noexcept
 True for the 0x8000 range (inquire / push only).
std::optional< std::size_t > key_value_length (Key k) noexcept
 Fixed value length documented for the key, or nullopt if variable/unknown.
std::optional< std::span< const std::byte > > find_key (std::span< const KeyValue > kvs, Key key) noexcept
 Finds the first entry with key in a parsed list.
std::string to_string (const Version &v)
 "aa.bb.cc.dd".
DeviceIdentity decode_identity (std::span< const KeyValue > kvs) noexcept
 Missing or undecodable keys leave the field at its default (empty string / zero).
std::string to_string (const DeviceIdentity &id)
 sn=... product_info=... version_app=a.b.c.d version_loader=... version_hardware=... mac=..
void set_log_level (LogLevel level) noexcept
 Process-wide.
LogLevel log_level () noexcept
 Current process-wide level, see set_log_level().
void set_log_handler (LogHandler handler)
 Process-wide; safe to call while a Context is running.
std::string format_log_record (const LogRecord &record)
 2026-09-26T12:34:56.789Z W [serial] message (UTC, millisecond precision, one-letter level E/W/I/D/T, [-] when the serial is empty).
LogHandler stderr_log_handler ()
 Writes format_log_record() + '
' to stderr.
std::expected< LogHandler, DeviceError > file_log_handler (const std::filesystem::path &path, bool append=true)
 Opens (creates or, with append, extends) path and returns a handler that writes format_log_record() + '
' and flushes after every record.
std::string_view to_string (LogLevel level) noexcept
 Lower-case name, e.g. "warn".
std::string_view to_string (Lvx2Error::Kind kind) noexcept
 Snake-case name of the kind ("io", "invalid_argument", "unsupported_data_type", "bad_file").
std::string to_string (const Lvx2Error &err)
 The kind, the detail and, for kIo, the errno text in one line.
std::string_view to_string (SessionErrorKind kind) noexcept
 Short snake_case name, e.g. "timeout".
std::string to_string (const SessionError &err)
 Human readable one-line description.
constexpr DeviceType to_device_type (std::uint8_t dev_type) noexcept
 Map a raw dev_type byte; every value other than kMid360DevType is kUnknown.
std::string_view to_string (DeviceType type) noexcept
 "mid360" or "unknown".
std::expected< std::vector< DiscoveredDevice >, SessionError > discover (const DiscoveryOptions &options={})
 Send 0x0000 and collect ACKs.
std::string_view to_string (TagConfidence c) noexcept
 Name of the confidence, e.g. "medium".
std::string to_string (const TagInfo &t)
 One line such as "glue=high particles=low other=high"; reserved is shown only when set.
constexpr TagInfo decode_tag (std::uint8_t tag) noexcept
 Splits a raw tag byte into its four fields.
constexpr bool is_noise (std::uint8_t tag, TagConfidence worst_accepted=TagConfidence::kHigh) noexcept
 True when the adjacent-glue or particle confidence is worse than worst_accepted; the other and reserved fields are not consulted.
std::optional< Endpoint > parse_endpoint (std::string_view text)
 Parse "a.b.c.d" (port = 0) or "a.b.c.d:port". Returns nullopt on malformed input.
std::string to_string (const Endpoint &ep)
 Format as "a.b.c.d:port".
std::string ip_to_string (const std::array< std::uint8_t, 4 > &ip)
 Format only the address part, "a.b.c.d".
std::string_view to_string (TransportErrorCode code)
 Short snake_case name, e.g. "would_block".
std::string to_string (const TransportError &err)
 Human readable "code (strerror)" text.
Encoders

Encoders: produce the raw value bytes for a key (to be wrapped in a KeyValue).

std::array< std::byte, 1 > encode_u8 (std::uint8_t v) noexcept
 One byte.
std::array< std::byte, 1 > encode_bool (bool v) noexcept
 u8 0 / 1.
std::array< std::byte, 1 > encode_fov_enable (FovEnable e) noexcept
 Key 0x0017 bitmask.
template<typename E>
requires std::is_enum_v<E> && std::is_same_v<std::underlying_type_t<E>, std::uint8_t>
std::array< std::byte, 1 > encode_enum_u8 (E v) noexcept
 u8 enums (DataType, DetectMode, WorkState, ...).
std::array< std::byte, 8 > encode_host_ip_config (const HostIpConfig &c) noexcept
 Keys 0x0005 / 0x0006 / 0x0007 / 0x0009: ip, dst port, src port.
std::array< std::byte, 12 > encode_lidar_ip_config (const LidarIpConfig &c) noexcept
 Key 0x0004: ip, netmask, gateway.
std::array< std::byte, 24 > encode_install_attitude (const InstallAttitude &a) noexcept
 Key 0x0012: three float angles, then three int32 offsets.
std::array< std::byte, 20 > encode_fov_config (const FovConfig &f) noexcept
 Keys 0x0015 / 0x0016.
std::array< std::byte, 4 > encode_func_io_config (const FuncIoConfig &c) noexcept
 Key 0x0019: in0, in1, out0, out1.
std::array< std::byte, 3 > encode_imu_sensor_config (const ImuSensorConfig &c) noexcept
 Key 0x002B: rate, accel range, gyro range.
Decoders

Decoders: parse a key's raw value bytes.

Length is validated.

std::expected< std::uint8_t, KeyError > decode_u8 (std::span< const std::byte > v) noexcept
 One byte.
std::expected< std::uint16_t, KeyError > decode_u16 (std::span< const std::byte > v) noexcept
 Little-endian u16.
std::expected< std::uint32_t, KeyError > decode_u32 (std::span< const std::byte > v) noexcept
 Little-endian u32.
std::expected< std::int32_t, KeyError > decode_i32 (std::span< const std::byte > v) noexcept
 Little-endian i32.
std::expected< std::uint64_t, KeyError > decode_u64 (std::span< const std::byte > v) noexcept
 Little-endian u64.
std::expected< std::int64_t, KeyError > decode_i64 (std::span< const std::byte > v) noexcept
 Little-endian i64.
std::expected< HostIpConfig, KeyError > decode_host_ip_config (std::span< const std::byte > v) noexcept
 Keys 0x0005 / 0x0006 / 0x0007 / 0x0009.
std::expected< LidarIpConfig, KeyError > decode_lidar_ip_config (std::span< const std::byte > v) noexcept
 Key 0x0004. Not checked with lidar_ip_config_valid().
std::expected< InstallAttitude, KeyError > decode_install_attitude (std::span< const std::byte > v) noexcept
 Key 0x0012. Not checked with install_attitude_valid().
std::expected< FovConfig, KeyError > decode_fov_config (std::span< const std::byte > v) noexcept
 Keys 0x0015 / 0x0016. Not checked with fov_in_range().
std::expected< FuncIoConfig, KeyError > decode_func_io_config (std::span< const std::byte > v) noexcept
 Key 0x0019; a field outside its enum is kOutOfRange.
std::expected< ImuSensorConfig, KeyError > decode_imu_sensor_config (std::span< const std::byte > v) noexcept
 Key 0x002B; a field outside its enum is kOutOfRange.
std::expected< Version, KeyError > decode_version (std::span< const std::byte > v) noexcept
 Keys 0x8002 / 0x8003 / 0x8004.
std::expected< std::array< std::uint8_t, 6 >, KeyError > decode_mac (std::span< const std::byte > v) noexcept
 Key 0x8005.
std::expected< WorkState, KeyError > decode_work_state (std::span< const std::byte > v) noexcept
 Keys 0x001A / 0x8006; a value that is not a WorkState enumerator is kOutOfRange.
std::expected< bool, KeyError > decode_bool (std::span< const std::byte > v) noexcept
 u8 0 / 1; anything else is kOutOfRange.
std::expected< DataType, KeyError > decode_data_type (std::span< const std::byte > v) noexcept
 key 0x0000: 1, 2 or 3 (0 = IMU is not a point-cloud data type).
std::expected< ScanPattern, KeyError > decode_scan_pattern (std::span< const std::byte > v) noexcept
 Key 0x0001: 0, 1 or 2.
std::expected< DetectMode, KeyError > decode_detect_mode (std::span< const std::byte > v) noexcept
 Key 0x0018: 0 or 1.
std::expected< TimeSyncType, KeyError > decode_time_sync_type (std::span< const std::byte > v) noexcept
 Key 0x800C: 0, 1 or 2.
std::expected< FwType, KeyError > decode_fw_type (std::span< const std::byte > v) noexcept
 Key 0x8010: 0 or 1.
std::expected< FovEnable, KeyError > decode_fov_enable (std::span< const std::byte > v) noexcept
 key 0x0017; bits above bit 1 are kOutOfRange.
std::expected< DiagStatus, KeyError > decode_diag_status (std::span< const std::byte > v) noexcept
 Key 0x800E; a nibble above 3 is kOutOfRange.
std::expected< std::array< std::uint32_t, 8 >, KeyError > decode_hms_codes (std::span< const std::byte > v) noexcept
 Key 0x8011: the eight raw slots; see decode_hms().
std::string_view decode_string (std::span< const std::byte > v) noexcept
 NUL-padded string keys (0x8000 sn, 0x8001 product_info). Returns the text before the first NUL.
Typed key values

One-line forms of the typed key values.

std::string_view to_string (ScanPattern p) noexcept
 "non_repetitive", "repetitive" or "low_rate_repetitive".
std::string_view to_string (DetectMode m) noexcept
 "normal" or "sensitive".
std::string_view to_string (TimeSyncType t) noexcept
 "none", "ptp" or "gps".
std::string_view to_string (FwType t) noexcept
 "loader" or "app".
std::string_view to_string (ImuOutputRate r) noexcept
 Rate with unit, e.g. "200Hz".
std::string_view to_string (ImuAccelRange r) noexcept
 Range with unit, e.g. "4g".
std::string_view to_string (ImuGyroRange r) noexcept
 Range with unit, e.g. "2000dps" or "62.5dps".
std::string to_string (const HostIpConfig &c)
 ip:dst_port<-src_port
std::string to_string (const LidarIpConfig &c)
 ip/netmask/gateway
std::string to_string (const InstallAttitude &a)
 r<roll>/p<pitch>/y<yaw>/x<mm>/y<mm>/z<mm>
std::string to_string (const FovConfig &f)
 yaw<start>-<stop>/pitch<start>-<stop>
std::string to_string (const FovEnable &e)
 fov0:<0|1>,fov1:<0|1>
std::string to_string (const FovSettings &s)
 fov0=<...> fov1=<...> enable=<...>; absent fields are omitted, all absent → "".
std::string_view to_string (FuncIn0 f) noexcept
 "pps".
std::string_view to_string (FuncIn1 f) noexcept
 "gps".
std::string_view to_string (FuncOut f) noexcept
 "none", "follow_input" or "safety_zone".
std::string to_string (const FuncIoConfig &c)
 in0/in1/out0/out1, e.g. "pps/gps/none/safety_zone".
std::string to_string (const ImuSensorConfig &c)
 <rate>/<accel>/<gyro>, e.g. 200Hz/4g/2000dps
std::string_view to_string (DiagLevel level) noexcept
 "normal", "warning", "error" or "safety_error".
std::string to_string (const DiagStatus &d)
 sys<n>/scan<n>/rng<n>/comm<n> with the numeric level of each subsystem.
Point cloud / IMU data packet

36-byte header + data.

std::expected< DataPacketView, ParseError > parse_data_packet (std::span< const std::byte > packet, bool verify_crc=true) noexcept
 Parses and validates a data packet (version, length, CRC32, data_type/dot_num consistency).
constexpr std::size_t sample_size (DataType t) noexcept
 Bytes per sample for a data type (0 for unknown).
CartesianPoint32 decode_cartesian32 (const DataPacketView &p, std::size_t i) noexcept
 Decodes the i-th sample. The caller guarantees data_type matches and i < dot_num.
CartesianPoint16 decode_cartesian16 (const DataPacketView &p, std::size_t i) noexcept
 Decodes the i-th sample, as decode_cartesian32() does for data type 2.
SphericalPoint decode_spherical (const DataPacketView &p, std::size_t i) noexcept
 Decodes the i-th sample, as decode_cartesian32() does for data type 3.
ImuSample decode_imu (const DataPacketView &p, std::size_t i) noexcept
 Decodes the i-th sample, as decode_cartesian32() does for data type 0.
std::vector< CartesianPoint32 > decode_all_cartesian32 (const DataPacketView &p)
 Whole-packet decoders (allocate).
std::vector< CartesianPoint16 > decode_all_cartesian16 (const DataPacketView &p)
 Whole-packet decoder for data type 2 (allocates).
std::vector< SphericalPoint > decode_all_spherical (const DataPacketView &p)
 Whole-packet decoder for data type 3 (allocates).
std::vector< ImuSample > decode_all_imu (const DataPacketView &p)
 Whole-packet decoder for data type 0 (allocates).
std::uint64_t sample_timestamp_ns (const DataPacketHeader &h, std::size_t i) noexcept
 Timestamp of the i-th sample: timestamp + i * time_interval / (dot_num - 1), in ns.
Key-value lists

0x0100 / 0x0101 / 0x0102 payloads.

std::expected< std::vector< KeyValue >, ParseError > parse_key_value_list (std::span< const std::byte > in, std::size_t key_num) noexcept
 Parses key_num consecutive {key u16, length u16, value[length]} entries.
void append_key_value_list (std::vector< std::byte > &out, std::span< const KeyValue > kvs)
 Encodes {key,length,value}* into out (appends).
std::vector< std::byte > encode_param_config_request (std::span< const KeyValue > kvs)
 0x0100 REQ data: key_num u16, rsvd u16, key_value_list.
std::vector< std::byte > encode_param_inquire_request (std::span< const std::uint16_t > keys)
 0x0101 REQ data: key_num u16, rsvd u16, key u16[key_num].
std::vector< std::byte > encode_reboot_request (std::uint16_t timeout_ms)
 0x0200 REQ data: timeout u16 (ms).
std::vector< std::byte > encode_factory_reset_request ()
 0x0201 REQ data: 16 reserved bytes (documented as "SN, reserved"). Zero-filled.
std::vector< std::byte > encode_set_gps_timestamp_request (std::uint64_t pps_time_ns)
 0x0202 REQ data: type u8 (2 = GPS), time_set u64 (ns of last PPS rising edge).
std::expected< DiscoveryAck, ParseError > parse_discovery_ack (std::span< const std::byte > data) noexcept
 Parses the data of a discovery ACK (24 bytes).
std::expected< ParamConfigAck, ParseError > parse_param_config_ack (std::span< const std::byte > data) noexcept
 Parses the data of a parameter configuration ACK (3 bytes).
std::expected< ParamInquireAck, ParseError > parse_param_inquire_ack (std::span< const std::byte > data) noexcept
 Parses the data of a parameter inquire ACK: ret_code u8, key_num u16, key_value_list.
std::expected< InfoPush, ParseError > parse_info_push (std::span< const std::byte > data) noexcept
 Parses the data of a 0x0102 push: key_num u16, rsvd u16, key_value_list.
std::expected< SimpleAck, ParseError > parse_simple_ack (std::span< const std::byte > data) noexcept
 Parses the data of an ACK whose first byte is the return code.

Variables

constexpr std::size_t kDebugDataControlSize = 9
 Size of the 0x0303 request payload in bytes.
constexpr std::uint8_t kFirmwareLogFlagAck = 0x01
 FirmwareLogFlags::ack_requested.
constexpr std::uint8_t kFirmwareLogFlagBegin = 0x02
 FirmwareLogFlags::file_begin.
constexpr std::uint8_t kFirmwareLogFlagEnd = 0x04
 FirmwareLogFlags::file_end.
constexpr std::size_t kFirmwareLogPushHeaderSize = 16
 Size of the 0x0300 push header in bytes.
constexpr std::size_t kFirmwareLogPushDataMaxSize
 Largest data part of one 0x0300 push that fits a command frame.
constexpr std::size_t kFirmwareLogPushAckSize = 7
 Size of the FirmwareLogPushAck payload in bytes.
constexpr std::array< Key, 6 > kIdentityKeys
 The keys decode_identity() reads, for one inquire.
constexpr std::uint8_t kMid360DevType = 9
 dev_type a Mid-360 reports in the 0x0000 ACK.
constexpr std::size_t kMaxDatagramSize = 1500
 Maximum datagram size worth allocating for: Ethernet MTU.
constexpr const char * kVersionString = LIVOX_MID360_CORE_VERSION_STRING
 Library version string, same as LIVOX_MID360_CORE_VERSION_STRING.
constexpr const char * kProtocolDocRevision = "v1.4.12 (2026-09-21)"
 Protocol document revision this implementation was written against.
Constants
constexpr std::uint16_t kDiscoveryPort = 56000
 LiDAR discovery port (0x0000).
constexpr std::uint16_t kCommandPort = 56100
 LiDAR control command port.
constexpr std::uint16_t kPushPort = 56200
 LiDAR-side source port for 0x0102 push.
constexpr std::uint16_t kPointCloudPort = 56300
 LiDAR-side source port for point cloud.
constexpr std::uint16_t kImuPort = 56400
 LiDAR-side source port for IMU.
constexpr std::uint16_t kLogPort = 56500
 LiDAR log port (0x03xx, #44).
constexpr std::uint16_t kDebugDataPort = 60301
 LiDAR-side source port of the debug raw data stream (#93, verified in #106).
constexpr std::uint16_t kDefaultHostCommandPort = 56101
 host port for commands
constexpr std::uint16_t kDefaultHostPushPort = 56201
 host port for 0x0102 push
constexpr std::uint16_t kDefaultHostPointCloudPort = 56301
 host port for point cloud
constexpr std::uint16_t kDefaultHostImuPort = 56401
 host port for IMU
constexpr std::uint16_t kDefaultHostLogPort = 56501
 firmware log (#44)
constexpr std::uint16_t kDefaultHostDebugDataPort = 44332
 as SDK2 (#93)
constexpr std::uint8_t kCommandSof = 0xAA
 first byte of every command frame
constexpr std::uint8_t kProtocolVersion = 0
 version of command frames and packets
constexpr std::size_t kCommandHeaderSize = 24
 command frame header, sof .. crc32
constexpr std::size_t kCommandFrameMaxSize = 1400
 whole command frame
constexpr std::size_t kCommandDataMaxSize = kCommandFrameMaxSize - kCommandHeaderSize
 Largest command payload that fits a frame.
constexpr std::size_t kDataPacketHeaderSize = 36
 version .. timestamp
constexpr std::size_t kPointsPerPacket = 96
 N for data_type 1, 2 and 3.

Typed values

enum class  ScanPattern : std::uint8_t { kNonRepetitive = 0 , kRepetitive = 1 , kLowRateRepetitive = 2 }
 key 0x0001. More...
enum class  DetectMode : std::uint8_t { kNormal = 0 , kSensitive = 1 }
 Key 0x0018: detection sensitivity.
enum class  FuncIn0 : std::uint8_t { kPps = 0 }
 Pin functions of key 0x0019 (issue #52). More...
enum class  FuncIn1 : std::uint8_t { kGps = 0 }
 Function of pin IN1 (key 0x0019). More...
enum class  FuncOut : std::uint8_t { kNone = 0 , kFollowInput = 1 , kSafetyZone = 2 }
 Function of pins OUT0 / OUT1 (key 0x0019). More...
enum class  ImuOutputRate : std::uint8_t { k200Hz = 0 , k500Hz = 1 , k100Hz = 2 , k50Hz = 3 }
 IMU output rate (key 0x002B byte 0).
enum class  ImuAccelRange : std::uint8_t { k4g = 0 , k8g = 1 , k16g = 2 , k32g = 3 }
 Accelerometer full-scale range (key 0x002B byte 1).
enum class  ImuGyroRange : std::uint8_t {
  k2000dps = 0 , k1000dps = 1 , k500dps = 2 , k250dps = 3 ,
  k125dps = 4 , k62_5dps = 5 , k31_25dps = 6 , k15_625dps = 7
}
 Gyroscope full-scale range in degrees per second (key 0x002B byte 2).
enum class  TimeSyncType : std::uint8_t { kNone = 0 , kPtp = 1 , kGps = 2 }
 Key 0x800C: the time source the LiDAR is synchronised to.
enum class  DiagLevel : std::uint8_t { kNormal = 0 , kWarning = 1 , kError = 2 , kSafetyError = 3 }
 key 0x800E: per-module abnormality level 0 normal / 1 warning / 2 error / 3 safety_err. More...
enum class  FwType : std::uint8_t { kLoader = 0 , kApp = 1 }
 Key 0x8010: which firmware image is running.
using Ipv4 = std::array<std::uint8_t, 4>
 IPv4 address in network order, e.g. {192, 168, 1, 12}.
bool fov_in_range (const FovConfig &f) noexcept
 What a Mid-360 accepts for a FOV window (#268): yaw in [0, 360] and pitch in [-10, 60], both ends included, and start <= stop for both.
bool lidar_ip_config_valid (const LidarIpConfig &c) noexcept
 Key 0x0004 sanity (issue #50): ip neither 0.0.0.0 nor 255.255.255.255 nor the subnet's network / broadcast address, netmask a contiguous prefix of 1 to 30 bits, gateway either 0.0.0.0 (none) or inside the subnet and different from ip.
bool install_attitude_valid (const InstallAttitude &a) noexcept
 Key 0x0012 sanity (issue #51): the three angles finite and within [-180, 180] degrees.
bool func_io_config_valid (const FuncIoConfig &c) noexcept
 Key 0x0019 sanity (issue #52): every field within its enum.

Enumerations

enum class  CmdId : std::uint16_t {
  kDiscovery = 0x0000 , kParamConfig = 0x0100 , kParamInquire = 0x0101 , kInfoPush = 0x0102 ,
  kReboot = 0x0200 , kFactoryReset = 0x0201 , kSetGpsTimestamp = 0x0202 , kPushLog = 0x0300 ,
  kCollectionLog = 0x0301 , kDebugDataControl = 0x0303
}
 Command IDs (cmd_id of the command frame header). More...
enum class  CmdType : std::uint8_t { kReq = 0x00 , kAck = 0x01 }
 Request or acknowledgement (cmd_type of the command frame header). More...
enum class  SenderType : std::uint8_t { kHost = 0x00 , kLidar = 0x01 }
 Originator of a command frame (sender_type of the header). More...
enum class  RetCode : std::uint8_t {
  kSuccess = 0x00 , kFailure = 0x01 , kNotPermitNow = 0x02 , kOutOfRange = 0x03 ,
  kParamNotSupport = 0x20 , kParamRebootEffect = 0x21 , kParamReadOnly = 0x22 , kParamInvalidLen = 0x23 ,
  kParamKeyNumErr = 0x24 , kUpgradePubKeyError = 0x30 , kUpgradeDigestError = 0x31 , kUpgradeFwTypeError = 0x32 ,
  kUpgradeFwOutOfRange = 0x33 , kUpgradeFwErasing = 0x34
}
 Result code carried as the first byte of every ACK.
enum class  WorkState : std::uint8_t {
  kSampling = 0x01 , kIdle = 0x02 , kError = 0x04 , kSelfCheck = 0x05 ,
  kMotorStartup = 0x06 , kUpgrade = 0x08 , kReady = 0x09
}
 LiDAR working state (key 0x8006 cur_work_state / 0x001A work_tgt_mode). More...
enum class  DataType : std::uint8_t { kImu = 0 , kCartesian32 = 1 , kCartesian16 = 2 , kSpherical = 3 }
 Sample format of a data packet (data_type of the header). More...
enum class  TimeType : std::uint8_t { kNoSync = 0 , kPtp = 1 , kGps = 2 }
 Clock source of a data packet timestamp (time_type of the header). More...
enum class  ParseError : std::uint8_t {
  kTooShort , kBadSof , kBadVersion , kLengthMismatch ,
  kBadCrc16 , kBadCrc32 , kUnknownDataType , kBadDotNum ,
  kTruncated , kKeyNumMismatch
}
 Why a frame, packet or payload was rejected by the parsers in this header. More...
std::string_view to_string (RetCode c) noexcept
 Short name of a return code, for logs.
std::string_view to_string (WorkState s) noexcept
 Short name of a working state, for logs.
std::string_view to_string (DataType t) noexcept
 Short name of a data type, for logs.
std::string_view to_string (TimeType t) noexcept
 Short name of a time type, for logs.
std::string_view to_string (ParseError e) noexcept
 Short description of a parse error, for logs.
std::string_view to_string (CmdId id) noexcept
 Short name of a command ID, for logs.

Control command frame

24-byte header + data, max 1400 bytes.

enum class  EncodeError : std::uint8_t { kDataTooLarge , kBufferTooSmall }
 Why encode_command_frame() or build_command_frame() failed. More...
std::expected< CommandFrameView, ParseError > parse_command_frame (std::span< const std::byte > frame) noexcept
 Parses and fully validates (SOF, version, length, CRC16, CRC32) one command frame.
constexpr std::size_t command_frame_size (std::size_t data_size) noexcept
 Total wire size of a frame carrying data_size payload bytes.
std::expected< std::size_t, EncodeError > encode_command_frame (std::span< std::byte > out, const CommandFrameSpec &spec) noexcept
 Serialises a frame into out, computing both CRCs. Returns bytes written.
std::expected< std::vector< std::byte >, EncodeError > build_command_frame (const CommandFrameSpec &spec)
 Convenience: allocate and serialise.

Settings

Settings (issue #41).

constexpr std::array< Key, 16 > kSettingsKeys
 The keys decode_settings() reads, for one inquire.
LidarSettings decode_settings (std::span< const KeyValue > kvs) noexcept
 Decodes the kSettingsKeys present in kvs; other keys are ignored.
std::string to_string (const LidarSettings &s)
 One line, name=value per present key in kSettingsKeys order, empty optionals omitted.

Status

Status (issue #41).

constexpr std::array< Key, 10 > kStatusKeys
 The keys decode_status() reads, for one inquire.
std::string to_string (const TimeSyncStatus &s)
 local_time=... last_sync=... offset=... type=..., times in ns.
LidarStatus decode_status (std::span< const KeyValue > kvs) noexcept
 Decodes the kStatusKeys present in kvs, each HMS slot through decode_hms(); other keys are ignored and time_ns stays 0.
std::string to_string (const LidarStatus &s)
 One line, name=value per present key; core_temp in degC with two decimals, hms=[..] lists only the active codes as 0x<raw>:<level>.

Detailed Description

The livox_mid360_core library: everything declared by the public headers.

Typedef Documentation

◆ LogHandler

using livox::mid360::LogHandler = std::function<void(const LogRecord &)>

Called from the Context receive thread, the Device worker thread and caller threads, never while an SDK mutex is held.

It must not throw and must not call back into the SDK.

Enumeration Type Documentation

◆ DisconnectReason

enum class livox::mid360::DisconnectReason : std::uint8_t
strong

Why a Device left the connected state (Event::reason, issue #8).

Enumerator
kNone 

not disconnected (or the event is not a disconnect / reconnect)

kPushTimeout 

no 0x0102 push for ReconnectOptions::push_timeout

kCommandTimeout 

a command timed out while the push was already stale

kRebootRequested 

Device::reboot() was acknowledged.

kUser 

Device::disconnect().

◆ FirmwareLogType

enum class livox::mid360::FirmwareLogType : std::uint8_t
strong

log_type of 0x0300 / 0x0301. SDK2 states that only the real-time log is supported.

Enumerator
kRealTime 

real-time log

kException 

ACKed by 13.18.0244, but no chunk arrived on demand (#11).

◆ TimestampPolicy

enum class livox::mid360::TimestampPolicy : std::uint8_t
strong

How point/IMU timestamps are produced from the packet timestamp (#6).

Enumerator
kLidar 

packet timestamp as is (use with PTP / GPS synchronisation)

kHostOffsetOnce 

default: LiDAR time + (host - LiDAR) measured once at the first packet

kHostReceive 

kernel receive time of the packet

◆ HmsLevel

enum class livox::mid360::HmsLevel : std::uint8_t
strong

Abnormal level, byte 0 of an HMS code.

Enumerator
kNone 

slot unused

◆ Key

enum class livox::mid360::Key : std::uint16_t
strong

Keys of the key-value list (0x0100 configure, 0x0101 inquire, 0x0102 push).

Keys with bit 15 set are read-only.

Enumerator
kPclDataType 

u8, DataType 1/2/3

kPatternMode 

u8 ScanPattern; a change restarts the motor

kLidarIpCfg 

u8[12] ip, mask, gateway

kStateInfoHostIpCfg 

u8[8] ip, dst port, src port

kPointCloudHostIpCfg 

u8[8]

kImuHostIpCfg 

u8[8]

kLogHostIpCfg 

u8[8] firmware log host (#44); SDK2 only reads it

kInstallAttitude 

24 bytes: 3 float deg + 3 int mm

kFovCfg0 

20 bytes

kFovCfg1 

20 bytes

kFovCfgEn 

u8 bitmask

kDetectMode 

u8 0 normal / 1 sensitive

kFuncIoCfg 

u8[4] IN0, IN1, OUT0, OUT1

kWorkTgtMode 

u8 WorkState (1 SAMPLING, 2 IDLE, 9 READY)

kImuDataEn 

u8 0/1

kSpeedMode 

u8, 360S/360L only (not modelled)

kTimeFilter 

u8 0/1

kPcFreqMod 

u8, 360L only (not modelled)

kImuSensorCfg 

u8[3] rate, accel range, gyro range

kSn 

char[16]

kProductInfo 

char[64]

kVersionApp 

u8[4]

kVersionLoader 

u8[4]

kVersionHardware 

u8[4]

kMac 

u8[6]

kCurWorkState 

u8 WorkState

kCoreTemp 

i32, 0.01 degC

kPowerupCnt 

u32

kLocalTimeNow 

u64 ns

kLastSyncTime 

u64 ns

kTimeOffset 

i64 ns, local - source

kTimeSyncType 

u8 0 none / 1 PTP / 2 GPS

kLidarDiagStatus 

u16 bitfield

kFwType 

u8 0 loader / 1 app

kHmsCode 

u32[8]

◆ KeyError

enum class livox::mid360::KeyError : std::uint8_t
strong

Why a key value did not decode.

Enumerator
kWrongLength 

the value's length differs from the key's fixed length

kOutOfRange 

a field is outside its enum or documented range

◆ ScanPattern

enum class livox::mid360::ScanPattern : std::uint8_t
strong

key 0x0001.

The wiki says only kNonRepetitive is effective on the base Mid-360, but the LiDAR accepts all three; a change restarts the motor (#11, #269).

◆ FuncIn0

enum class livox::mid360::FuncIn0 : std::uint8_t
strong

Pin functions of key 0x0019 (issue #52).

The wiki defines a single input function per pin; the enums exist so a value outside the table is caught before any I/O.

Enumerator
kPps 

PPS input (M12 pin 8).

◆ FuncIn1

enum class livox::mid360::FuncIn1 : std::uint8_t
strong

Function of pin IN1 (key 0x0019).

Enumerator
kGps 

GPS input (M12 pin 10).

◆ FuncOut

enum class livox::mid360::FuncOut : std::uint8_t
strong

Function of pins OUT0 / OUT1 (key 0x0019).

Enumerator
kNone 

output unused

kFollowInput 

OUT0 follows IN0, OUT1 follows IN1.

kSafetyZone 

safety zone output 0 / 1

◆ DiagLevel

enum class livox::mid360::DiagLevel : std::uint8_t
strong

key 0x800E: per-module abnormality level 0 normal / 1 warning / 2 error / 3 safety_err.

One nibble of key 0x800E: 0 normal .. 3 safety error. Only 0 has been seen on hardware (13.18.0244); the field layout is still open (#111).

◆ LogLevel

enum class livox::mid360::LogLevel : std::uint8_t
strong

Severity, ordered: a level is emitted when it is <= the level set with set_log_level().

Enumerator
kOff 

default: nothing is emitted

kError 

socket failures on the receive thread

kWarn 

disconnects, command timeouts

kInfo 

state transitions, reconnect attempts, host-setup replay, open / close

kDebug 

request retries, datagrams from unknown sources

kTrace 

reserved

◆ CmdId

enum class livox::mid360::CmdId : std::uint16_t
strong

Command IDs (cmd_id of the command frame header).

Enumerator
kDiscovery 

discovery request; the ACK is a DiscoveryAck

kParamConfig 

write a key-value list

kParamInquire 

read a list of keys

kInfoPush 

LiDAR → host state push (key-value list).

kReboot 

reboot after a timeout

kFactoryReset 

restore factory settings

kSetGpsTimestamp 

set the time of the last PPS edge

kPushLog 

LiDAR → host on the log port; see firmware_log.hpp (#44).

kCollectionLog 

host → LiDAR port 56500: start / stop a log type

kDebugDataControl 

host → LiDAR: start / stop debug raw data; debug_data.hpp (#93)

◆ CmdType

enum class livox::mid360::CmdType : std::uint8_t
strong

Request or acknowledgement (cmd_type of the command frame header).

Enumerator
kReq 

request

kAck 

acknowledgement of a request

◆ SenderType

enum class livox::mid360::SenderType : std::uint8_t
strong

Originator of a command frame (sender_type of the header).

Enumerator
kHost 

the host computer

kLidar 

the LiDAR

◆ WorkState

enum class livox::mid360::WorkState : std::uint8_t
strong

LiDAR working state (key 0x8006 cur_work_state / 0x001A work_tgt_mode).

Only kSampling, kIdle and kReady may be requested via work_tgt_mode.

◆ DataType

enum class livox::mid360::DataType : std::uint8_t
strong

Sample format of a data packet (data_type of the header).

Enumerator
kImu 

ImuSample, 24 bytes, one per packet.

kCartesian32 

int32 mm, 14 bytes/point, default

kCartesian16 

int16 10 mm, 8 bytes/point

kSpherical 

depth mm + theta/phi 0.01 deg, 10 bytes/point

◆ TimeType

enum class livox::mid360::TimeType : std::uint8_t
strong

Clock source of a data packet timestamp (time_type of the header).

Enumerator
kNoSync 

timestamp counts from LiDAR power-on

kPtp 

IEEE 1588v2.0 or gPTP master time.

kGps 

GPS (PPS + GPRMC).

◆ ParseError

enum class livox::mid360::ParseError : std::uint8_t
strong

Why a frame, packet or payload was rejected by the parsers in this header.

Enumerator
kTooShort 

buffer shorter than the minimal header

kBadSof 

command frame does not start with 0xAA

kBadVersion 

protocol version != 0

kLengthMismatch 

length field disagrees with the buffer size or exceeds 1400

kBadCrc16 

command header CRC mismatch

kBadCrc32 

payload CRC mismatch

kUnknownDataType 

data_type not in 0..3

kBadDotNum 

dot_num inconsistent with payload size / data_type

kTruncated 

a key-value list or fixed-layout payload ended early

kKeyNumMismatch 

key_num does not match the number of entries present

◆ EncodeError

enum class livox::mid360::EncodeError : std::uint8_t
strong

Why encode_command_frame() or build_command_frame() failed.

Enumerator
kDataTooLarge 

data exceeds kCommandDataMaxSize

kBufferTooSmall 

output span cannot hold the frame

◆ SessionErrorKind

enum class livox::mid360::SessionErrorKind : std::uint8_t
strong

Category of a SessionError.

Enumerator
kTransport 

socket error; see transport

kTimeout 

no matching ACK within all attempts

kBadResponse 

ACK arrived but its payload did not parse / serial mismatch.

kLidarRejected 

ACK with ret_code != success; see ret_code / error_key.

kUnexpectedState 

wait_for_state observed ERROR or UPGRADE; see work_state

kCancelled 

cancel() was called

kInvalidArgument 

rejected before sending; see error_key for the offending key

◆ DeviceType

enum class livox::mid360::DeviceType : std::uint8_t
strong

Device type named by the dev_type byte of the 0x0000 ACK (#58).

The wiki lists no enumeration; only the Mid-360 value is known (9, recorded on hardware in #110).

Enumerator
kUnknown 

any other value; the raw byte stays in DiscoveredDevice::dev_type

◆ TransportErrorCode

enum class livox::mid360::TransportErrorCode : std::uint8_t
strong

Category of a TransportError.

Known errno values map to a specific code; the rest keep the code of the failing step.

Enumerator
kSocketCreate 

socket(), eventfd() or pipe() failed

kBind 

bind() or getsockname() failed

kSetOption 

a socket or descriptor option could not be set

kAddressInUse 

EADDRINUSE.

kNetworkUnreachable 

ENETUNREACH, EHOSTUNREACH, EADDRNOTAVAIL, EACCES.

kSendFailed 

sendto() failed with another errno

kMessageTooLong 

EMSGSIZE.

kWouldBlock 

nothing pending on a non-blocking socket (EAGAIN)

kTimeout 

timed out

kInterrupted 

EINTR.

kClosed 

the socket or Poller is closed (EBADF, ENOTSOCK)

kInvalidArgument 

EINVAL, EAFNOSUPPORT, or a rejected argument.

kOther 

any other failure

Function Documentation

◆ host_setup_key_values()

HostSetupKeyValues livox::mid360::host_setup_key_values ( const HostSetup & setup,
const Ipv4 & host_ip )
nodiscard

Build the first 0x0100 request of apply_host_setup() for setup.

host_ip goes into the three host ip-config keys; setup.ip is not consulted (apply_host_setup() resolves it first).

◆ apply_host_setup()

std::expected< HostSetupResult, SessionError > livox::mid360::apply_host_setup ( Session & session,
const HostSetup & setup,
std::optional< RequestOptions > opts = std::nullopt )
nodiscard

Apply setup through session.

Errors are the session's: kLidarRejected carries the error_key the LiDAR complained about; kTimeout / kUnexpectedState come from the wait.

◆ encode_debug_data_control()

std::array< std::byte, kDebugDataControlSize > livox::mid360::encode_debug_data_control ( const DebugDataControlRequest & req)
nodiscardnoexcept

0x0303 payload: {enable u8, host_ip u8[4], host_port u16, reserved u16}, little-endian.

The ACK is a single ret_code: parse_simple_ack().

◆ parse_firmware_log_push()

std::expected< FirmwareLogPushView, ParseError > livox::mid360::parse_firmware_log_push ( std::span< const std::byte > data)
nodiscardnoexcept

0x0300 payload: header + data.

data_length must match the bytes present (kTruncated / kLengthMismatch otherwise); log_type is not range-checked (unknown types pass through).

◆ apply()

void livox::mid360::apply ( const Extrinsic & e,
std::span< Point > points )
noexcept

Transforms every point in place; reflectivity, tag, line and offset are untouched.

Call the span overload qualified (livox::mid360::apply): ADL on std::span also finds std::apply.

◆ fov_in_range()

bool livox::mid360::fov_in_range ( const FovConfig & f)
nodiscardnoexcept

What a Mid-360 accepts for a FOV window (#268): yaw in [0, 360] and pitch in [-10, 60], both ends included, and start <= stop for both.

A reversed window is rejected (no wrap-around); an equal yaw start / stop is accepted and crops every point. The codecs do not check this; Device::set_fov() and HostSetup do.

◆ lidar_ip_config_valid()

bool livox::mid360::lidar_ip_config_valid ( const LidarIpConfig & c)
nodiscardnoexcept

Key 0x0004 sanity (issue #50): ip neither 0.0.0.0 nor 255.255.255.255 nor the subnet's network / broadcast address, netmask a contiguous prefix of 1 to 30 bits, gateway either 0.0.0.0 (none) or inside the subnet and different from ip.

The codec does not check this; Device::set_lidar_ip_config() does.

◆ install_attitude_valid()

bool livox::mid360::install_attitude_valid ( const InstallAttitude & a)
nodiscardnoexcept

Key 0x0012 sanity (issue #51): the three angles finite and within [-180, 180] degrees.

The offsets are int32 mm and always encodable. The codec does not check this; Device::set_install_attitude() does.

◆ func_io_config_valid()

bool livox::mid360::func_io_config_valid ( const FuncIoConfig & c)
nodiscardnoexcept

Key 0x0019 sanity (issue #52): every field within its enum.

decode_func_io_config() rejects the same values with KeyError::kOutOfRange; Device::set_func_io_config() checks this before any I/O.

◆ set_log_level()

void livox::mid360::set_log_level ( LogLevel level)
noexcept

Process-wide.

Level filtering happens before any formatting, so kOff / kError cost one atomic load per call site.

◆ set_log_handler()

void livox::mid360::set_log_handler ( LogHandler handler)

Process-wide; safe to call while a Context is running.

A handler that is executing when it is replaced finishes its call; the previous handler object is destroyed when the last such call returns. A default-constructed handler restores "no output".

◆ format_log_record()

std::string livox::mid360::format_log_record ( const LogRecord & record)
nodiscard

2026-09-26T12:34:56.789Z W [serial] message (UTC, millisecond precision, one-letter level E/W/I/D/T, [-] when the serial is empty).

No trailing newline.

◆ file_log_handler()

std::expected< LogHandler, DeviceError > livox::mid360::file_log_handler ( const std::filesystem::path & path,
bool append = true )
nodiscard

Opens (creates or, with append, extends) path and returns a handler that writes format_log_record() + '
' and flushes after every record.

On failure the error is DeviceError::Kind::kIo with the errno of the open.

◆ parse_data_packet()

std::expected< DataPacketView, ParseError > livox::mid360::parse_data_packet ( std::span< const std::byte > packet,
bool verify_crc = true )
nodiscardnoexcept

Parses and validates a data packet (version, length, CRC32, data_type/dot_num consistency).

A crc32 of 0 is not checked: a Mid-360 leaves it at 0 in point cloud packets (#219). Set verify_crc=false to skip the CRC on hot paths after you have trusted the source.

◆ sample_timestamp_ns()

std::uint64_t livox::mid360::sample_timestamp_ns ( const DataPacketHeader & h,
std::size_t i )
nodiscardnoexcept

Timestamp of the i-th sample: timestamp + i * time_interval / (dot_num - 1), in ns.

time_interval is in 0.1 us (= 100 ns) units. Returns timestamp when dot_num <= 1.

◆ discover()

std::expected< std::vector< DiscoveredDevice >, SessionError > livox::mid360::discover ( const DiscoveryOptions & options = {})
nodiscard

Send 0x0000 and collect ACKs.

Duplicates (same serial number) are collapsed, first wins. An empty result is not an error.

◆ decode_tag()

TagInfo livox::mid360::decode_tag ( std::uint8_t tag)
nodiscardconstexprnoexcept

Splits a raw tag byte into its four fields.

The documented layout fits points with a return. The reserved bits 6-7 are not always 0 on a Mid-360 (13.18.0244, #11): about 20 % of the points without a return carry 0x80 or 0xC0, and a few returns carry 0x40.

◆ is_noise()

bool livox::mid360::is_noise ( std::uint8_t tag,
TagConfidence worst_accepted = TagConfidence::kHigh )
nodiscardconstexprnoexcept

True when the adjacent-glue or particle confidence is worse than worst_accepted; the other and reserved fields are not consulted.

With the default any degradation is noise.

Variable Documentation

◆ kFirmwareLogPushDataMaxSize

std::size_t livox::mid360::kFirmwareLogPushDataMaxSize
inlineconstexpr
Initial value:
=
constexpr std::size_t kCommandDataMaxSize
Largest command payload that fits a frame.
Definition protocol.hpp:52
constexpr std::size_t kFirmwareLogPushHeaderSize
Size of the 0x0300 push header in bytes.
Definition firmware_log.hpp:48

Largest data part of one 0x0300 push that fits a command frame.

◆ kIdentityKeys

std::array<Key, 6> livox::mid360::kIdentityKeys
inlineconstexpr
Initial value:
{
@ kProductInfo
char[64]
Definition keys.hpp:55
@ kVersionHardware
u8[4]
Definition keys.hpp:58
@ kVersionLoader
u8[4]
Definition keys.hpp:57
@ kSn
char[16]
Definition keys.hpp:54
@ kMac
u8[6]
Definition keys.hpp:59
@ kVersionApp
u8[4]
Definition keys.hpp:56

The keys decode_identity() reads, for one inquire.

◆ kSettingsKeys

std::array<Key, 16> livox::mid360::kSettingsKeys
inlineconstexpr
Initial value:
{
@ kFuncIoCfg
u8[4] IN0, IN1, OUT0, OUT1
Definition keys.hpp:46
@ kStateInfoHostIpCfg
u8[8] ip, dst port, src port
Definition keys.hpp:37
@ kPclDataType
u8, DataType 1/2/3
Definition keys.hpp:34
@ kImuHostIpCfg
u8[8]
Definition keys.hpp:39
@ kDetectMode
u8 0 normal / 1 sensitive
Definition keys.hpp:45
@ kFovCfgEn
u8 bitmask
Definition keys.hpp:44
@ kPointCloudHostIpCfg
u8[8]
Definition keys.hpp:38
@ kFovCfg1
20 bytes
Definition keys.hpp:43
@ kTimeFilter
u8 0/1
Definition keys.hpp:50
@ kPatternMode
u8 ScanPattern; a change restarts the motor
Definition keys.hpp:35
@ kInstallAttitude
24 bytes: 3 float deg + 3 int mm
Definition keys.hpp:41
@ kImuSensorCfg
u8[3] rate, accel range, gyro range
Definition keys.hpp:52
@ kImuDataEn
u8 0/1
Definition keys.hpp:48
@ kLidarIpCfg
u8[12] ip, mask, gateway
Definition keys.hpp:36
@ kWorkTgtMode
u8 WorkState (1 SAMPLING, 2 IDLE, 9 READY)
Definition keys.hpp:47
@ kFovCfg0
20 bytes
Definition keys.hpp:42

The keys decode_settings() reads, for one inquire.

◆ kStatusKeys

std::array<Key, 10> livox::mid360::kStatusKeys
inlineconstexpr
Initial value:
{
@ kLidarDiagStatus
u16 bitfield
Definition keys.hpp:67
@ kFwType
u8 0 loader / 1 app
Definition keys.hpp:68
@ kCurWorkState
u8 WorkState
Definition keys.hpp:60
@ kCoreTemp
i32, 0.01 degC
Definition keys.hpp:61
@ kPowerupCnt
u32
Definition keys.hpp:62
@ kTimeOffset
i64 ns, local - source
Definition keys.hpp:65
@ kLocalTimeNow
u64 ns
Definition keys.hpp:63
@ kLastSyncTime
u64 ns
Definition keys.hpp:64
@ kHmsCode
u32[8]
Definition keys.hpp:69
@ kTimeSyncType
u8 0 none / 1 PTP / 2 GPS
Definition keys.hpp:66

The keys decode_status() reads, for one inquire.

◆ kDiscoveryPort

std::uint16_t livox::mid360::kDiscoveryPort = 56000
inlineconstexpr

LiDAR discovery port (0x0000).

discover() broadcasts to it by default; a unicast to it (DiscoveryOptions::targets, the Device reconnect path) is answered by the simulator and is still to be confirmed on hardware (#11).

◆ kMaxDatagramSize

std::size_t livox::mid360::kMaxDatagramSize = 1500
inlineconstexpr

Maximum datagram size worth allocating for: Ethernet MTU.

Command frames are at most 1400 bytes and point-cloud packets 36 + 96 * 14 = 1380 bytes.