133 Device(
const Device &) =
delete;
134 Device & operator=(
const Device &) =
delete;
135 Device(Device &&) =
delete;
136 Device & operator=(Device &&) =
delete;
169 std::optional<RequestOptions> opts = std::nullopt);
171 std::expected<void, DeviceError>
stop_sampling(std::optional<RequestOptions> opts = std::nullopt);
175 std::span<const KeyValue> values, std::optional<RequestOptions> opts = std::nullopt);
177 std::expected<InquireResult, DeviceError>
inquire(
178 std::span<const std::uint16_t> keys, std::optional<RequestOptions> opts = std::nullopt);
180 std::expected<InquireResult, DeviceError>
inquire(
181 std::span<const Key> keys, std::optional<RequestOptions> opts = std::nullopt);
187 std::expected<void, DeviceError>
reboot(std::optional<RequestOptions> opts = std::nullopt);
195 std::expected<DeviceIdentity, DeviceError>
identity(
196 std::optional<RequestOptions> opts = std::nullopt);
201 std::expected<LidarSettings, DeviceError>
settings(
202 std::optional<RequestOptions> opts = std::nullopt);
205 std::expected<LidarStatus, DeviceError>
status(std::optional<RequestOptions> opts = std::nullopt);
209 std::optional<RequestOptions> opts = std::nullopt);
220 DataType format, std::optional<RequestOptions> opts = std::nullopt);
223 std::optional<RequestOptions> opts = std::nullopt);
228 ScanPattern pattern, std::optional<RequestOptions> opts = std::nullopt);
231 std::optional<RequestOptions> opts = std::nullopt);
250 std::expected<SetResult, DeviceError>
set_fov(
251 const FovSettings &
fov, std::optional<RequestOptions> opts = std::nullopt);
253 std::expected<FovSettings, DeviceError>
fov(std::optional<RequestOptions> opts = std::nullopt);
264 const InstallAttitude & a, std::optional<RequestOptions> opts = std::nullopt);
267 std::optional<RequestOptions> opts = std::nullopt);
278 const FuncIoConfig & c, std::optional<RequestOptions> opts = std::nullopt);
281 std::optional<RequestOptions> opts = std::nullopt);
293 DetectMode mode, std::optional<RequestOptions> opts = std::nullopt);
296 std::optional<RequestOptions> opts = std::nullopt);
299 bool on, std::optional<RequestOptions> opts = std::nullopt);
302 std::expected<bool, DeviceError>
imu_enabled(std::optional<RequestOptions> opts = std::nullopt);
306 const ImuSensorConfig & cfg, std::optional<RequestOptions> opts = std::nullopt);
309 std::optional<RequestOptions> opts = std::nullopt);
312 bool on, std::optional<RequestOptions> opts = std::nullopt);
314 std::expected<bool, DeviceError>
time_filter(std::optional<RequestOptions> opts = std::nullopt);
325 std::optional<RequestOptions> opts = std::nullopt);
329 std::uint64_t pps_time_ns, std::optional<RequestOptions> opts = std::nullopt);
343 std::optional<RequestOptions> opts = std::nullopt);
347 std::optional<RequestOptions> opts = std::nullopt);
361 std::optional<RequestOptions> opts = std::nullopt);
364 std::optional<RequestOptions> opts = std::nullopt);
377 const LidarIpConfig & cfg, std::optional<RequestOptions> opts = std::nullopt);
380 std::optional<RequestOptions> opts = std::nullopt);
392 std::expected<SetResult, DeviceError>
set(
393 const key_value_t<K> & value, std::optional<RequestOptions> opts = std::nullopt)
402 return set_many<Ks...>(std::nullopt, values...);
411 const auto kvs = std::apply(
412 [](
const auto &... e) {
413 return std::array<
KeyValue,
sizeof...(Ks)>{
414 KeyValue{
static_cast<std::uint16_t
>(Ks), std::span<const std::byte>(e)}...};
419 return std::unexpected(ack.error());
421 return SetResult{.reboot_required = ack->ret_code == RetCode::kParamRebootEffect};
427 std::expected<key_value_t<K>,
DeviceError>
get(std::optional<RequestOptions> opts = std::nullopt)
431 return std::unexpected(r.error());
433 return std::get<0>(std::move(*r));
441 const std::array<
Key,
sizeof...(Ks)> keys{Ks...};
442 auto res =
inquire(keys, opts);
444 return std::unexpected(res.error());
446 std::optional<DeviceError> failed;
447 std::tuple<key_value_t<Ks>...> out{decode_one<Ks>(*res, failed)...};
449 return std::unexpected(*failed);
498 explicit Device(std::unique_ptr<Impl> impl);
503 if (
const auto raw = res.get(K)) {
504 if (auto v = key_traits<K>::decode(*raw)) {
505 return std::move(*v);
514 std::unique_ptr<Impl> impl_;
Owns the receive sockets and the receive thread.
Definition context.hpp:49
std::expected< SetResult, DeviceError > set_imu_enabled(bool on, std::optional< RequestOptions > opts=std::nullopt)
Key 0x001C: whether the LiDAR sends IMU data.
SessionStats session_stats() const
Snapshot of the command Session's counters.
std::expected< DeviceIdentity, DeviceError > identity(std::optional< RequestOptions > opts=std::nullopt)
Keys 0x8000-0x8005. Missing keys leave their field empty; see decode_identity().
void cancel() noexcept
Interrupts the blocking command in progress from another thread (not serialised); it returns kCancell...
std::expected< bool, DeviceError > time_filter(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0026 as stored by the LiDAR.
std::expected< DataType, DeviceError > point_format(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0000 as stored by the LiDAR.
std::expected< SetResult, DeviceError > set_scan_pattern(ScanPattern pattern, std::optional< RequestOptions > opts=std::nullopt)
Key 0x0001.
DeviceStats stats() const
Snapshot of the data-path counters.
std::expected< ParamConfigAck, DeviceError > configure(std::span< const KeyValue > values, std::optional< RequestOptions > opts=std::nullopt)
0x0100 with raw key-value pairs (Session::configure()).
std::expected< std::tuple< key_value_t< Ks >... >, DeviceError > get_many(std::optional< RequestOptions > opts=std::nullopt)
Several keys in one 0x0101, decoded into a tuple in the order of Ks.
Definition device.hpp:438
std::expected< SetResult, DeviceError > set_detect_mode(DetectMode mode, std::optional< RequestOptions > opts=std::nullopt)
Thin wrappers over set<K>() / get<K>().
std::expected< SetResult, DeviceError > set_fov(const FovSettings &fov, std::optional< RequestOptions > opts=std::nullopt)
One 0x0100 with the present fields of fov (the LiDAR applies all or none).
std::expected< void, DeviceError > set_gps_time(std::uint64_t pps_time_ns, std::optional< RequestOptions > opts=std::nullopt)
0x0202: hands the host's GPS time of the last PPS edge to the LiDAR.
std::array< HmsCode, 8 > hms() const
hms_code slots from pushed_status() (all inactive before the first push).
std::expected< SetResult, DeviceError > set_lidar_ip_config(const LidarIpConfig &cfg, std::optional< RequestOptions > opts=std::nullopt)
lidar_ip_config_valid() → else kInvalidArgument with key before any I/O.
std::expected< void, DeviceError > reconnect()
One recovery attempt on the caller's thread (serialised with the commands): direct endpoint,...
std::expected< void, DeviceError > start_firmware_log(FirmwareLogType type=FirmwareLogType::kRealTime, std::optional< RequestOptions > opts=std::nullopt)
Writes key 0x0009 (this host, the Context's log port) through the session, then sends 0x0301 enable f...
std::optional< LidarStatus > pushed_status() const
The latest value of every status key seen in a 0x0102 push, time_ns = receive time of the last push; ...
std::expected< LidarStatus, DeviceError > status(std::optional< RequestOptions > opts=std::nullopt)
Keys 0x8006-0x8011 by inquire; see decode_status().
std::expected< SetResult, DeviceError > set_many(std::optional< RequestOptions > opts, const key_value_t< Ks > &... values)
set_many() with request options.
Definition device.hpp:407
std::expected< void, DeviceError > on_packet(PacketCallback cb)
Receive thread, once per parsed data packet, before frame assembly.
std::expected< void, DeviceError > set_frame_policy(const FramePolicy &policy)
Replace DeviceOptions::frame_policy at run time (window must be > 0 → kInvalidArgument).
std::expected< InstallAttitude, DeviceError > install_attitude(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0012 as stored by the LiDAR.
std::expected< void, DeviceError > start_debug_data(std::optional< RequestOptions > opts=std::nullopt)
Sends 0x0303 enable with this host and the Context's debug data port from the log socket and waits fo...
std::expected< void, DeviceError > on_push(PushCallback cb)
Receive thread, once per parsed push, after the push's kStateChanged / kHms / kDiagChanged events; th...
std::expected< void, DeviceError > stop_sampling(std::optional< RequestOptions > opts=std::nullopt)
work_tgt_mode = IDLE, then wait. A partial frame is discarded, not delivered.
std::expected< ScanPattern, DeviceError > scan_pattern(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0001 as stored by the LiDAR.
bool connected() const noexcept
False between kDisconnected and kReconnected.
static std::expected< std::unique_ptr< Device >, DeviceError > open(Context &context, const DiscoveredDevice &device, const DeviceOptions &opts={})
Registers with the Context (kAlreadyRegistered when another Device has the same IP),...
std::expected< key_value_t< K >, DeviceError > get(std::optional< RequestOptions > opts=std::nullopt)
One 0x0101 for K, decoded.
Definition device.hpp:427
std::optional< WorkState > work_state() const
cur_work_state from pushed_status(); nullopt before the first push.
~Device()
Unregisters from the Context (waits for an in-flight callback to return) and drops the Session.
std::expected< DetectMode, DeviceError > detect_mode(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0018 as stored by the LiDAR.
std::expected< InquireResult, DeviceError > inquire(std::span< const Key > keys, std::optional< RequestOptions > opts=std::nullopt)
0x0101 for typed keys.
std::expected< SetResult, DeviceError > set_many(const key_value_t< Ks > &... values)
Several keys in one 0x0100 (the LiDAR applies all or rejects the whole request).
Definition device.hpp:400
std::expected< void, DeviceError > reboot(std::optional< RequestOptions > opts=std::nullopt)
0x0200.
std::expected< SetResult, DeviceError > set(const key_value_t< K > &value, std::optional< RequestOptions > opts=std::nullopt)
One 0x0100 with the encoded value.
Definition device.hpp:392
FramePolicy frame_policy() const
The policy last requested (DeviceOptions::frame_policy until set_frame_policy()).
DiscoveredDevice info() const
Discovery record; ip / cmd_port / from follow a reconnect to a new address.
std::expected< FuncIoConfig, DeviceError > func_io_config(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0019 as stored by the LiDAR.
std::expected< void, DeviceError > start_sampling(std::optional< RequestOptions > opts=std::nullopt)
work_tgt_mode = SAMPLING, then wait for cur_work_state (host_setup.wait_timeout).
std::expected< LidarSettings, DeviceError > settings(std::optional< RequestOptions > opts=std::nullopt)
The 16 modelled writable keys as stored by the LiDAR; see decode_settings().
std::expected< SetResult, DeviceError > set_func_io_config(const FuncIoConfig &c, std::optional< RequestOptions > opts=std::nullopt)
func_io_config_valid() → else kInvalidArgument with key before any I/O.
std::expected< void, DeviceError > stop_firmware_log(FirmwareLogType type=FirmwareLogType::kRealTime, std::optional< RequestOptions > opts=std::nullopt)
0x0301 disable. The destructor does not send it: the LiDAR keeps pushing.
std::expected< SetResult, DeviceError > set_imu_sensor_config(const ImuSensorConfig &cfg, std::optional< RequestOptions > opts=std::nullopt)
Key 0x002B is absent on older firmware: the LiDAR then answers kLidarRejected with ret_code kParamNot...
void disconnect()
Declares the Device disconnected (reason kUser) without touching the LiDAR; the automatic worker,...
std::expected< bool, DeviceError > imu_enabled(std::optional< RequestOptions > opts=std::nullopt)
Key 0x001C as stored by the LiDAR.
std::expected< void, DeviceError > on_firmware_log(FirmwareLogCallback cb)
Receive thread, once per 0x0300 push including begin / end packets (#44).
std::expected< FovSettings, DeviceError > fov(std::optional< RequestOptions > opts=std::nullopt)
One 0x0101 for the three keys. A key the ACK lacks leaves its field empty.
std::expected< SetResult, DeviceError > set_install_attitude(const InstallAttitude &a, std::optional< RequestOptions > opts=std::nullopt)
install_attitude_valid() → else kInvalidArgument with key before any I/O.
std::expected< SetResult, DeviceError > set_point_format(DataType format, std::optional< RequestOptions > opts=std::nullopt)
Key 0x0000.
std::expected< InquireResult, DeviceError > inquire(std::span< const std::uint16_t > keys, std::optional< RequestOptions > opts=std::nullopt)
0x0101 for raw key numbers (Session::inquire()). Prefer get() / get_many().
std::expected< ImuSensorConfig, DeviceError > imu_sensor_config(std::optional< RequestOptions > opts=std::nullopt)
Key 0x002B as stored by the LiDAR.
std::expected< TimeSyncStatus, DeviceError > time_sync_status(std::optional< RequestOptions > opts=std::nullopt)
One 0x0101 for the four keys; a key missing or undecodable → kDecodeFailed with key.
std::expected< DiagStatus, DeviceError > diag_status(std::optional< RequestOptions > opts=std::nullopt)
Key 0x800E by inquire (#55); the pushed value is pushed_status()->lidar_diag_status and changes raise...
std::expected< void, DeviceError > on_debug_data(DebugDataCallback cb)
Receive thread, once per datagram on the Context's debug data socket (#93).
std::expected< void, DeviceError > on_frame(FrameCallback cb)
Receive thread, once per completed Frame.
std::expected< void, DeviceError > on_event(EventCallback cb)
Receive thread, once per Event.
std::expected< LidarIpConfig, DeviceError > lidar_ip_config(std::optional< RequestOptions > opts=std::nullopt)
Key 0x0004 as stored by the LiDAR (the address in use until the next reboot may differ).
std::expected< SetResult, DeviceError > set_time_filter(bool on, std::optional< RequestOptions > opts=std::nullopt)
Key 0x0026: with 1 the LiDAR keeps streaming through a GPS time rollback (wiki).
std::expected< void, DeviceError > stop_debug_data(std::optional< RequestOptions > opts=std::nullopt)
0x0303 disable. The destructor does not send it: the LiDAR keeps streaming.
std::expected< void, DeviceError > on_imu(ImuCallback cb)
Receive thread, once per IMU sample.
Satisfied by every key that has key_traits.
Definition keys.hpp:426
Satisfied by keys that may be written with Device::set<K>().
Definition keys.hpp:429
Host setup flow on top of Session (issue #5): point the LiDAR at this host, choose the point cloud fo...
Public API (issue #9): the shared receive side.
Debug raw data collection (issue #93): command 0x0303 switches on a diagnostic stream that Livox supp...
Public API (issue #9): notifications and errors of the device layer.
Symbol visibility helpers.
Firmware log collection (issue #44): the 0x03xx command group on the LiDAR's log port (56500).
Public API skeleton (issue #9): output types of the device layer.
Key definitions and typed encoders/decoders for the Mid-360 key-value list (section "0x0102 LiDAR Inf...
Aggregated read-back types over the keys.hpp codecs (issues #38 / #41): the identity of a LiDAR (seri...
The livox_mid360_core library: everything declared by the public headers.
Definition bytes.hpp:14
std::function< void(Frame &&)> FrameCallback
Every completed Frame, moved to the callee.
Definition device.hpp:100
constexpr std::uint16_t kDiscoveryPort
LiDAR discovery port (0x0000).
Definition protocol.hpp:31
std::function< void(const LidarStatus &)> PushCallback
Every successfully parsed 0x0102 push, as the snapshot pushed_status() now returns (#56).
Definition device.hpp:106
std::function< void(const DataPacketView &, const ReceiveInfo &)> PacketCallback
Every parsed point-cloud / IMU data packet; the view is valid only during the call.
Definition device.hpp:98
std::function< void(const DebugDataPacket &)> DebugDataCallback
One datagram of the debug raw data stream (#93); data is valid only during the call.
Definition device.hpp:110
Key
Keys of the key-value list (0x0100 configure, 0x0101 inquire, 0x0102 push).
Definition keys.hpp:32
FirmwareLogType
log_type of 0x0300 / 0x0301. SDK2 states that only the real-time log is supported.
Definition firmware_log.hpp:26
@ kRealTime
real-time log
Definition firmware_log.hpp:27
std::function< void(const ImuData &)> ImuCallback
Every IMU sample.
Definition device.hpp:102
constexpr std::uint16_t kLogPort
LiDAR log port (0x03xx, #44).
Definition protocol.hpp:36
DataType
Sample format of a data packet (data_type of the header).
Definition protocol.hpp:125
ScanPattern
key 0x0001.
Definition keys.hpp:135
DetectMode
Key 0x0018: detection sensitivity.
Definition keys.hpp:143
typename key_traits< K >::value_type key_value_t
The C++ type of key K, e.g. key_value_t<Key::kPclDataType> is DataType.
Definition keys.hpp:433
WorkState
LiDAR working state (key 0x8006 cur_work_state / 0x001A work_tgt_mode).
Definition protocol.hpp:113
TimestampPolicy
How point/IMU timestamps are produced from the packet timestamp (#6).
Definition frame.hpp:102
@ kHostOffsetOnce
default: LiDAR time + (host - LiDAR) measured once at the first packet
Definition frame.hpp:104
std::function< void(const Event &)> EventCallback
Every Event (state, HMS, diagnostics, connection, periodic stats, firmware log gaps).
Definition device.hpp:104
std::function< void(const FirmwareLogChunk &)> FirmwareLogCallback
One 0x0300 firmware log push (#44); data is valid only during the call.
Definition device.hpp:108
Pure-function protocol layer for the Livox Mid-360: framing, parsing and serialisation of control-com...
Session layer: discovery and synchronous command round-trips with one Mid-360.
A validated, non-owning view over a data packet.
Definition protocol.hpp:256
What Device hands to a DebugDataCallback: one datagram of the stream, not interpreted (receive thread...
Definition debug_data.hpp:53
Errors of Context / Device. Session-level failures are wrapped, not re-encoded.
Definition event.hpp:128
@ kDecodeFailed
get<K>(): the ACK lacked key or its value did not decode (#57)
Definition event.hpp:138
Per-Device settings, passed to Device::open().
Definition device.hpp:72
std::chrono::milliseconds stats_interval
Period of Event::Kind::kStats; 0 disables it.
Definition device.hpp:82
TimestampPolicy timestamp_policy
point / IMU time base
Definition device.hpp:76
ReconnectOptions reconnect
disconnect detection and automatic recovery
Definition device.hpp:83
FramePolicy frame_policy
how packets are cut into Frames; see set_frame_policy()
Definition device.hpp:77
SessionOptions session
command socket; bind_address defaults to the Context's
Definition device.hpp:78
std::uint16_t lidar_log_port
LiDAR-side port that 0x0301 is sent to (#44). Tests point it at the simulator.
Definition device.hpp:85
HostSetup host_setup
Ports, data type and IMU enable.
Definition device.hpp:75
std::uint16_t lidar_debug_data_port
LiDAR-side port that 0x0303 is sent to (#93): the log port; the command port does not answer.
Definition device.hpp:87
bool verify_crc
Verify the CRC32 of every data packet; failures count in DeviceStats::bad_packets.
Definition device.hpp:80
Counters of one Device, snapshot via Device::stats(). Monotonic since open().
Definition event.hpp:26
One LiDAR that answered the 0x0000 discovery broadcast.
Definition session.hpp:101
IPv4 address + UDP port. Mid-360 is IPv4 only.
Definition transport.hpp:37
One notification. kind selects which fields are meaningful; the rest are default.
Definition event.hpp:91
What Device hands to a FirmwareLogCallback (receive thread; data is valid only during the callback,...
Definition firmware_log.hpp:96
The three FOV keys together (issue #39): Device::set_fov() sends the present ones in one 0x0100,...
Definition keys.hpp:275
How a Device cuts the packet stream into Frames (#6).
Definition frame.hpp:87
A group of points closed by FramePolicy. Owns its storage; delivered by value.
Definition frame.hpp:63
Key 0x0019; M12 pins 8, 10, 12, 11. Same layout as the 4 raw bytes.
Definition keys.hpp:169
One decoded HMS code (one of the eight uint32 slots of key 0x8011).
Definition hms.hpp:32
What the LiDAR needs to know about this host.
Definition config.hpp:28
One IMU packet (the LiDAR sends one sample per packet at 200 Hz) with its time.
Definition frame.hpp:78
Key 0x002B: IMU output rate and ranges.
Definition keys.hpp:206
Result of 0x0101: owns the ACK bytes so that values stays valid after moves.
Definition session.hpp:183
Key 0x0012: mounting rotation (degrees) and offset (millimetres) of the LiDAR.
Definition keys.hpp:113
One entry of a key-value list. Non-owning: value points into the parsed buffer.
Definition protocol.hpp:360
Key 0x0004: the LiDAR's own network configuration.
Definition keys.hpp:105
Keys 0x8006-0x8011: the live state, also carried by the 0x0102 push.
Definition lidar_info.hpp:155
Per-packet metadata handed to on_packet together with the non-owning DataPacketView.
Definition device.hpp:92
Endpoint source
LiDAR address and port the datagram came from.
Definition device.hpp:94
std::uint64_t host_time_ns
kernel receive timestamp
Definition device.hpp:93
Disconnect detection and automatic recovery (issue #8).
Definition device.hpp:53
std::chrono::milliseconds discovery_timeout
Timeout of the discovery fallback per attempt (the direct attempt uses session.request).
Definition device.hpp:62
std::chrono::milliseconds max_backoff
doubling stops here
Definition device.hpp:60
std::vector< Endpoint > discovery_targets
Unicast discovery targets for the fallback; empty = broadcast (see DiscoveryOptions).
Definition device.hpp:64
std::uint16_t discovery_port
Port of the extra unicast target {ip configured by set_lidar_ip_config(), port} that the fallback add...
Definition device.hpp:67
bool enabled
false: only detect; recover with Device::reconnect()
Definition device.hpp:54
std::chrono::milliseconds initial_backoff
delay after the first failed attempt
Definition device.hpp:59
std::chrono::milliseconds push_timeout
No accepted 0x0102 push for this long → kDisconnected.
Definition device.hpp:58
Timeout and retry policy of one request.
Definition session.hpp:143
Parameters of Session::connect().
Definition session.hpp:150
Counters of one Session, see Session::stats().
Definition session.hpp:165
Result of Device::set<K>() / set_many<>(): the LiDAR accepted the values.
Definition device.hpp:114
bool reboot_required
ret_code 0x21: the new value takes effect after the next reboot (e.g. kLidarIpCfg).
Definition device.hpp:116
UDP transport layer: a thin, dependency-free wrapper over POSIX sockets.