livox_mid360_core
C++ driver library for the Livox Mid-360 LiDAR
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
8#pragma once
9
10#include <cstddef>
11#include <cstdint>
12#include <expected>
13#include <memory>
14#include <optional>
15#include <string_view>
16#include <vector>
17
22
23LIVOX_MID360_API_BEGIN
24namespace livox::mid360
25{
26
29{
30 Ipv4 bind_address{0, 0, 0, 0};
33 std::uint16_t imu_port = kDefaultHostImuPort;
34 std::uint16_t log_port = kDefaultHostLogPort;
38 std::optional<std::uint16_t> debug_data_port;
39 std::size_t recv_buffer_bytes = 4u << 20;
40 std::size_t batch_size = 32;
41};
42
43class Device;
44
48class Context
49{
50public:
54 [[nodiscard]] static std::expected<std::unique_ptr<Context>, DeviceError> create(
55 const ContextOptions & opts = {});
56
57 ~Context();
58 Context(const Context &) = delete;
59 Context & operator=(const Context &) = delete;
60 Context(Context &&) = delete;
61 Context & operator=(Context &&) = delete;
62
64 [[nodiscard]] const ContextOptions & options() const noexcept;
66 [[nodiscard]] ContextStats stats() const;
67
72
74 [[nodiscard]] Device * find(std::string_view serial_number) const;
76 [[nodiscard]] std::vector<Device *> devices() const;
78
79private:
80 friend class Device;
81 struct Impl;
82 explicit Context(std::unique_ptr<Impl> impl);
83 std::unique_ptr<Impl> impl_;
84};
85
86} // namespace livox::mid360
87LIVOX_MID360_API_END
Owns the receive sockets and the receive thread.
Definition context.hpp:49
const ContextOptions & options() const noexcept
Effective options: ports requested as 0 are replaced by the bound ones.
ContextStats stats() const
Snapshot of the receive-side counters.
std::vector< Device * > devices() const
Every open Device, in registration order.
static std::expected< std::unique_ptr< Context >, DeviceError > create(const ContextOptions &opts={})
Opens the receive sockets and starts the receive thread.
Device * find(std::string_view serial_number) const
The open Device with this serial number, or nullptr.
One LiDAR: commands through its own Session, data through the Context it was opened on.
Definition device.hpp:122
Public API (issue #9): notifications and errors of the device layer.
Symbol visibility helpers.
The livox_mid360_core library: everything declared by the public headers.
Definition bytes.hpp:14
constexpr std::uint16_t kDefaultHostImuPort
host port for IMU
Definition protocol.hpp:43
std::array< std::uint8_t, 4 > Ipv4
IPv4 address in network order, e.g. {192, 168, 1, 12}.
Definition keys.hpp:93
constexpr std::uint16_t kDefaultHostLogPort
firmware log (#44)
Definition protocol.hpp:44
constexpr std::uint16_t kDefaultHostPointCloudPort
host port for point cloud
Definition protocol.hpp:42
constexpr std::uint16_t kDefaultHostPushPort
host port for 0x0102 push
Definition protocol.hpp:41
Pure-function protocol layer for the Livox Mid-360: framing, parsing and serialisation of control-com...
Sockets and receive-thread settings of a Context, passed to Context::create().
Definition context.hpp:29
std::optional< std::uint16_t > debug_data_port
Debug raw data (#93).
Definition context.hpp:38
Ipv4 bind_address
interface for the four receive sockets
Definition context.hpp:30
std::uint16_t point_port
0 = ephemeral
Definition context.hpp:32
std::size_t batch_size
datagrams per recvmmsg
Definition context.hpp:40
std::uint16_t log_port
firmware log (#44); 0 = ephemeral
Definition context.hpp:34
std::uint16_t push_port
0 = ephemeral (tests)
Definition context.hpp:31
std::uint16_t imu_port
0 = ephemeral
Definition context.hpp:33
std::size_t recv_buffer_bytes
SO_RCVBUF request per socket.
Definition context.hpp:39
Counters of the shared receive side, snapshot via Context::stats().
Definition event.hpp:72
Errors of Context / Device. Session-level failures are wrapped, not re-encoded.
Definition event.hpp:128
UDP transport layer: a thin, dependency-free wrapper over POSIX sockets.