31enum class Key : std::uint16_t
77 return (
static_cast<std::uint16_t
>(k) & 0x8000u) != 0;
93using Ipv4 = std::array<std::uint8_t, 4>;
138 kLowRateRepetitive = 2
215 std::array<std::uint8_t, 4>
v{};
254 [[nodiscard]]
constexpr bool normal() const noexcept {
return worst() == DiagLevel::kNormal; }
306[[nodiscard]] std::array<std::byte, 1>
encode_u8(std::uint8_t v)
noexcept;
308[[nodiscard]] std::array<std::byte, 1>
encode_bool(
bool v)
noexcept;
313 requires std::is_enum_v<E> && std::is_same_v<std::underlying_type_t<E>, std::uint8_t>
316 return encode_u8(
static_cast<std::uint8_t
>(v));
337[[nodiscard]] std::expected<std::uint8_t, KeyError>
decode_u8(
338 std::span<const std::byte> v)
noexcept;
340[[nodiscard]] std::expected<std::uint16_t, KeyError>
decode_u16(
341 std::span<const std::byte> v)
noexcept;
343[[nodiscard]] std::expected<std::uint32_t, KeyError>
decode_u32(
344 std::span<const std::byte> v)
noexcept;
346[[nodiscard]] std::expected<std::int32_t, KeyError>
decode_i32(
347 std::span<const std::byte> v)
noexcept;
349[[nodiscard]] std::expected<std::uint64_t, KeyError>
decode_u64(
350 std::span<const std::byte> v)
noexcept;
352[[nodiscard]] std::expected<std::int64_t, KeyError>
decode_i64(
353 std::span<const std::byte> v)
noexcept;
356 std::span<const std::byte> v)
noexcept;
359 std::span<const std::byte> v)
noexcept;
362 std::span<const std::byte> v)
noexcept;
365 std::span<const std::byte> v)
noexcept;
368 std::span<const std::byte> v)
noexcept;
371 std::span<const std::byte> v)
noexcept;
374 std::span<const std::byte> v)
noexcept;
377 std::span<const std::byte> v)
noexcept;
380 std::span<const std::byte> v)
noexcept;
382[[nodiscard]] std::expected<bool, KeyError>
decode_bool(std::span<const std::byte> v)
noexcept;
385 std::span<const std::byte> v)
noexcept;
388 std::span<const std::byte> v)
noexcept;
391 std::span<const std::byte> v)
noexcept;
394 std::span<const std::byte> v)
noexcept;
396[[nodiscard]] std::expected<FwType, KeyError>
decode_fw_type(std::span<const std::byte> v)
noexcept;
399 std::span<const std::byte> v)
noexcept;
402 std::span<const std::byte> v)
noexcept;
405 std::span<const std::byte> v)
noexcept;
407[[nodiscard]] std::string_view
decode_string(std::span<const std::byte> v)
noexcept;
411[[nodiscard]] std::optional<std::span<const std::byte>>
find_key(
412 std::span<const KeyValue> kvs,
Key key)
noexcept;
438template <
typename T, auto Enc, auto Dec>
441 using value_type = T;
442 static constexpr bool writable =
true;
443 [[nodiscard]]
static auto encode(
const T & v)
noexcept {
return Enc(v); }
444 [[nodiscard]]
static std::expected<T, KeyError> decode(std::span<const std::byte> v)
noexcept
449template <
typename T, auto Dec>
452 using value_type = T;
453 static constexpr bool writable =
false;
454 [[nodiscard]]
static std::expected<T, KeyError> decode(std::span<const std::byte> v)
noexcept
459[[nodiscard]]
inline std::expected<std::string, KeyError> decode_string_owned(
460 std::span<const std::byte> v)
noexcept
468: detail::WritableTraits<DataType, encode_enum_u8<DataType>, decode_data_type> {};
470: detail::WritableTraits<ScanPattern, encode_enum_u8<ScanPattern>, decode_scan_pattern> {};
472: detail::WritableTraits<LidarIpConfig, encode_lidar_ip_config, decode_lidar_ip_config> {};
474: detail::WritableTraits<HostIpConfig, encode_host_ip_config, decode_host_ip_config> {};
476: detail::WritableTraits<HostIpConfig, encode_host_ip_config, decode_host_ip_config> {};
478: detail::WritableTraits<HostIpConfig, encode_host_ip_config, decode_host_ip_config> {};
480: detail::WritableTraits<HostIpConfig, encode_host_ip_config, decode_host_ip_config> {};
482: detail::WritableTraits<InstallAttitude, encode_install_attitude, decode_install_attitude> {};
484: detail::WritableTraits<FovConfig, encode_fov_config, decode_fov_config> {};
486: detail::WritableTraits<FovConfig, encode_fov_config, decode_fov_config> {};
488: detail::WritableTraits<FovEnable, encode_fov_enable, decode_fov_enable> {};
490: detail::WritableTraits<DetectMode, encode_enum_u8<DetectMode>, decode_detect_mode> {};
492: detail::WritableTraits<FuncIoConfig, encode_func_io_config, decode_func_io_config> {};
494: detail::WritableTraits<WorkState, encode_enum_u8<WorkState>, decode_work_state> {};
496: detail::WritableTraits<bool, encode_bool, decode_bool> {};
498: detail::WritableTraits<bool, encode_bool, decode_bool> {};
500: detail::WritableTraits<ImuSensorConfig, encode_imu_sensor_config, decode_imu_sensor_config> {};
502: detail::ReadOnlyTraits<std::string, detail::decode_string_owned> {};
504: detail::ReadOnlyTraits<std::string, detail::decode_string_owned> {};
506: detail::ReadOnlyTraits<Version, decode_version> {};
508: detail::ReadOnlyTraits<Version, decode_version> {};
510: detail::ReadOnlyTraits<Version, decode_version> {};
512: detail::ReadOnlyTraits<std::array<std::uint8_t, 6>, decode_mac> {};
514: detail::ReadOnlyTraits<WorkState, decode_work_state> {};
516: detail::ReadOnlyTraits<std::int32_t, decode_i32> {};
518: detail::ReadOnlyTraits<std::uint32_t, decode_u32> {};
520: detail::ReadOnlyTraits<std::uint64_t, decode_u64> {};
522: detail::ReadOnlyTraits<std::uint64_t, decode_u64> {};
524: detail::ReadOnlyTraits<std::int64_t, decode_i64> {};
526: detail::ReadOnlyTraits<TimeSyncType, decode_time_sync_type> {};
528: detail::ReadOnlyTraits<DiagStatus, decode_diag_status> {};
530: detail::ReadOnlyTraits<FwType, decode_fw_type> {};
532: detail::ReadOnlyTraits<std::array<std::uint32_t, 8>, decode_hms_codes> {};
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
Symbol visibility helpers.
The livox_mid360_core library: everything declared by the public headers.
Definition bytes.hpp:14
DiagLevel
key 0x800E: per-module abnormality level 0 normal / 1 warning / 2 error / 3 safety_err.
Definition keys.hpp:230
std::array< std::byte, 1 > encode_bool(bool v) noexcept
u8 0 / 1.
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::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::expected< HostIpConfig, KeyError > decode_host_ip_config(std::span< const std::byte > v) noexcept
Keys 0x0005 / 0x0006 / 0x0007 / 0x0009.
std::array< std::byte, 12 > encode_lidar_ip_config(const LidarIpConfig &c) noexcept
Key 0x0004: ip, netmask, gateway.
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< ScanPattern, KeyError > decode_scan_pattern(std::span< const std::byte > v) noexcept
Key 0x0001: 0, 1 or 2.
FuncOut
Function of pins OUT0 / OUT1 (key 0x0019).
Definition keys.hpp:161
@ kSafetyZone
safety zone output 0 / 1
Definition keys.hpp:164
@ kNone
output unused
Definition keys.hpp:162
@ kFollowInput
OUT0 follows IN0, OUT1 follows IN1.
Definition keys.hpp:163
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,...
std::expected< bool, KeyError > decode_bool(std::span< const std::byte > v) noexcept
u8 0 / 1; anything else is kOutOfRange.
FuncIn1
Function of pin IN1 (key 0x0019).
Definition keys.hpp:156
@ kGps
GPS input (M12 pin 10).
Definition keys.hpp:157
std::expected< ImuSensorConfig, KeyError > decode_imu_sensor_config(std::span< const std::byte > v) noexcept
Key 0x002B; a field outside its enum is kOutOfRange.
Key
Keys of the key-value list (0x0100 configure, 0x0101 inquire, 0x0102 push).
Definition keys.hpp:32
@ kProductInfo
char[64]
Definition keys.hpp:55
@ kFuncIoCfg
u8[4] IN0, IN1, OUT0, OUT1
Definition keys.hpp:46
@ kVersionHardware
u8[4]
Definition keys.hpp:58
@ kStateInfoHostIpCfg
u8[8] ip, dst port, src port
Definition keys.hpp:37
@ kPclDataType
u8, DataType 1/2/3
Definition keys.hpp:34
@ kLidarDiagStatus
u16 bitfield
Definition keys.hpp:67
@ kImuHostIpCfg
u8[8]
Definition keys.hpp:39
@ kPcFreqMod
u8, 360L only (not modelled)
Definition keys.hpp:51
@ kVersionLoader
u8[4]
Definition keys.hpp:57
@ kDetectMode
u8 0 normal / 1 sensitive
Definition keys.hpp:45
@ kSn
char[16]
Definition keys.hpp:54
@ kFovCfgEn
u8 bitmask
Definition keys.hpp:44
@ kFwType
u8 0 loader / 1 app
Definition keys.hpp:68
@ kSpeedMode
u8, 360S/360L only (not modelled)
Definition keys.hpp:49
@ kLogHostIpCfg
u8[8] firmware log host (#44); SDK2 only reads it
Definition keys.hpp:40
@ kCurWorkState
u8 WorkState
Definition keys.hpp:60
@ kCoreTemp
i32, 0.01 degC
Definition keys.hpp:61
@ kPointCloudHostIpCfg
u8[8]
Definition keys.hpp:38
@ kFovCfg1
20 bytes
Definition keys.hpp:43
@ kPowerupCnt
u32
Definition keys.hpp:62
@ kTimeFilter
u8 0/1
Definition keys.hpp:50
@ kTimeOffset
i64 ns, local - source
Definition keys.hpp:65
@ kLocalTimeNow
u64 ns
Definition keys.hpp:63
@ kLastSyncTime
u64 ns
Definition keys.hpp:64
@ kPatternMode
u8 ScanPattern; a change restarts the motor
Definition keys.hpp:35
@ kHmsCode
u32[8]
Definition keys.hpp:69
@ kMac
u8[6]
Definition keys.hpp:59
@ 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
@ kTimeSyncType
u8 0 none / 1 PTP / 2 GPS
Definition keys.hpp:66
@ kWorkTgtMode
u8 WorkState (1 SAMPLING, 2 IDLE, 9 READY)
Definition keys.hpp:47
@ kVersionApp
u8[4]
Definition keys.hpp:56
@ kFovCfg0
20 bytes
Definition keys.hpp:42
std::expected< std::uint16_t, KeyError > decode_u16(std::span< const std::byte > v) noexcept
Little-endian u16.
std::array< std::byte, 1 > encode_enum_u8(E v) noexcept
u8 enums (DataType, DetectMode, WorkState, ...).
Definition keys.hpp:314
std::array< std::byte, 24 > encode_install_attitude(const InstallAttitude &a) noexcept
Key 0x0012: three float angles, then three int32 offsets.
std::expected< std::uint32_t, KeyError > decode_u32(std::span< const std::byte > v) noexcept
Little-endian u32.
bool func_io_config_valid(const FuncIoConfig &c) noexcept
Key 0x0019 sanity (issue #52): every field within its enum.
@ kNone
not disconnected (or the event is not a disconnect / reconnect)
Definition event.hpp:82
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 / broa...
ImuGyroRange
Gyroscope full-scale range in degrees per second (key 0x002B byte 2).
Definition keys.hpp:194
std::expected< std::uint64_t, KeyError > decode_u64(std::span< const std::byte > v) noexcept
Little-endian u64.
FuncIn0
Pin functions of key 0x0019 (issue #52).
Definition keys.hpp:151
@ kPps
PPS input (M12 pin 8).
Definition keys.hpp:152
std::array< std::uint8_t, 4 > Ipv4
IPv4 address in network order, e.g. {192, 168, 1, 12}.
Definition keys.hpp:93
FwType
Key 0x8010: which firmware image is running.
Definition keys.hpp:259
ScanPattern
key 0x0001.
Definition keys.hpp:135
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< FovConfig, KeyError > decode_fov_config(std::span< const std::byte > v) noexcept
Keys 0x0015 / 0x0016. Not checked with fov_in_range().
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
bool install_attitude_valid(const InstallAttitude &a) noexcept
Key 0x0012 sanity (issue #51): the three angles finite and within [-180, 180] degrees.
std::expected< Version, KeyError > decode_version(std::span< const std::byte > v) noexcept
Keys 0x8002 / 0x8003 / 0x8004.
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::expected< std::array< std::uint8_t, 6 >, KeyError > decode_mac(std::span< const std::byte > v) noexcept
Key 0x8005.
std::expected< std::uint8_t, KeyError > decode_u8(std::span< const std::byte > v) noexcept
One byte.
std::array< std::byte, 1 > encode_u8(std::uint8_t v) noexcept
One byte.
TimeSyncType
Key 0x800C: the time source the LiDAR is synchronised to.
Definition keys.hpp:220
std::array< std::byte, 1 > encode_fov_enable(FovEnable e) noexcept
Key 0x0017 bitmask.
std::expected< DiagStatus, KeyError > decode_diag_status(std::span< const std::byte > v) noexcept
Key 0x800E; a nibble above 3 is kOutOfRange.
std::expected< DetectMode, KeyError > decode_detect_mode(std::span< const std::byte > v) noexcept
Key 0x0018: 0 or 1.
std::expected< InstallAttitude, KeyError > decode_install_attitude(std::span< const std::byte > v) noexcept
Key 0x0012. Not checked with install_attitude_valid().
std::expected< FovEnable, KeyError > decode_fov_enable(std::span< const std::byte > v) noexcept
key 0x0017; bits above bit 1 are kOutOfRange.
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::optional< std::size_t > key_value_length(Key k) noexcept
Fixed value length documented for the key, or nullopt if variable/unknown.
std::expected< std::int32_t, KeyError > decode_i32(std::span< const std::byte > v) noexcept
Little-endian i32.
std::array< std::byte, 4 > encode_func_io_config(const FuncIoConfig &c) noexcept
Key 0x0019: in0, in1, out0, out1.
std::array< std::byte, 8 > encode_host_ip_config(const HostIpConfig &c) noexcept
Keys 0x0005 / 0x0006 / 0x0007 / 0x0009: ip, dst port, src port.
ImuOutputRate
IMU output rate (key 0x002B byte 0).
Definition keys.hpp:178
std::expected< FwType, KeyError > decode_fw_type(std::span< const std::byte > v) noexcept
Key 0x8010: 0 or 1.
ImuAccelRange
Accelerometer full-scale range (key 0x002B byte 1).
Definition keys.hpp:186
std::expected< std::int64_t, KeyError > decode_i64(std::span< const std::byte > v) noexcept
Little-endian i64.
std::string_view to_string(Event::Kind kind) noexcept
Name of an event kind, e.g. "state_changed".
KeyError
Why a key value did not decode.
Definition keys.hpp:84
@ kWrongLength
the value's length differs from the key's fixed length
Definition keys.hpp:85
@ kOutOfRange
a field is outside its enum or documented range
Definition keys.hpp:86
std::array< std::byte, 3 > encode_imu_sensor_config(const ImuSensorConfig &c) noexcept
Key 0x002B: rate, accel range, gyro range.
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.
std::array< std::byte, 20 > encode_fov_config(const FovConfig &f) noexcept
Keys 0x0015 / 0x0016.
constexpr bool is_read_only(Key k) noexcept
True for the 0x8000 range (inquire / push only).
Definition keys.hpp:75
std::expected< TimeSyncType, KeyError > decode_time_sync_type(std::span< const std::byte > v) noexcept
Key 0x800C: 0, 1 or 2.
Pure-function protocol layer for the Livox Mid-360: framing, parsing and serialisation of control-com...
Key 0x800E, u16 bitfield split into four subsystem levels (issue #55).
Definition keys.hpp:240
DiagLevel system
bit 0-3
Definition keys.hpp:241
constexpr bool normal() const noexcept
worst() == kNormal.
Definition keys.hpp:254
DiagLevel ranging
bit 8-11
Definition keys.hpp:243
DiagLevel communication
bit 12-15
Definition keys.hpp:244
constexpr bool operator==(const DiagStatus &) const noexcept=default
Field-wise equality.
constexpr DiagLevel worst() const noexcept
Highest level among the four subsystems.
Definition keys.hpp:249
DiagLevel scan
bit 4-7
Definition keys.hpp:242
Keys 0x0015 / 0x0016: one FOV window in degrees.
Definition keys.hpp:124
std::int32_t yaw_start_deg
[0, 360]
Definition keys.hpp:125
std::int32_t yaw_stop_deg
[0, 360]
Definition keys.hpp:126
std::int32_t pitch_stop_deg
[-10, 60]
Definition keys.hpp:128
std::int32_t pitch_start_deg
[-10, 60]
Definition keys.hpp:127
std::uint32_t rsvd
reserved; encoded as given
Definition keys.hpp:129
Key 0x0017 bitmask: bit 0 enables fov_cfg0, bit 1 enables fov_cfg1.
Definition keys.hpp:266
bool fov1
bit 1: window 0x0016 crops the point cloud
Definition keys.hpp:268
bool fov0
bit 0: window 0x0015 crops the point cloud
Definition keys.hpp:267
The three FOV keys together (issue #39): Device::set_fov() sends the present ones in one 0x0100,...
Definition keys.hpp:275
std::optional< FovConfig > fov0
key 0x0015
Definition keys.hpp:276
std::optional< FovConfig > fov1
key 0x0016
Definition keys.hpp:277
std::optional< FovEnable > enable
key 0x0017
Definition keys.hpp:278
Key 0x0019; M12 pins 8, 10, 12, 11. Same layout as the 4 raw bytes.
Definition keys.hpp:169
FuncIn1 in1
IN1, M12 pin 10.
Definition keys.hpp:171
FuncOut out0
OUT0, M12 pin 12.
Definition keys.hpp:172
FuncOut out1
OUT1, M12 pin 11.
Definition keys.hpp:173
FuncIn0 in0
IN0, M12 pin 8.
Definition keys.hpp:170
Keys 0x0005 / 0x0006 / 0x0007 / 0x0009: where the LiDAR sends one kind of data.
Definition keys.hpp:97
Ipv4 ip
host address
Definition keys.hpp:98
std::uint16_t src_port
LiDAR-side source port.
Definition keys.hpp:100
std::uint16_t dst_port
host-side listening port
Definition keys.hpp:99
Key 0x002B: IMU output rate and ranges.
Definition keys.hpp:206
ImuGyroRange gyro_range
byte 2
Definition keys.hpp:209
ImuOutputRate output_rate
byte 0
Definition keys.hpp:207
ImuAccelRange accel_range
byte 1
Definition keys.hpp:208
Key 0x0012: mounting rotation (degrees) and offset (millimetres) of the LiDAR.
Definition keys.hpp:113
std::int32_t z_mm
offset along z
Definition keys.hpp:119
float pitch_deg
rotation about y
Definition keys.hpp:115
float roll_deg
rotation about x
Definition keys.hpp:114
float yaw_deg
rotation about z
Definition keys.hpp:116
std::int32_t y_mm
offset along y
Definition keys.hpp:118
std::int32_t x_mm
offset along x
Definition keys.hpp:117
Key 0x0004: the LiDAR's own network configuration.
Definition keys.hpp:105
Ipv4 gateway
gateway; 0.0.0.0 = none
Definition keys.hpp:108
Ipv4 ip
LiDAR address.
Definition keys.hpp:106
Ipv4 netmask
subnet mask
Definition keys.hpp:107
Keys 0x8002 / 0x8003 / 0x8004, "aa.bb.cc.dd".
Definition keys.hpp:214
std::array< std::uint8_t, 4 > v
aa, bb, cc, dd
Definition keys.hpp:215