35inline constexpr std::uint16_t
kImuPort = 56400;
36inline constexpr std::uint16_t
kLogPort = 56500;
98 kParamNotSupport = 0x20,
99 kParamRebootEffect = 0x21,
100 kParamReadOnly = 0x22,
101 kParamInvalidLen = 0x23,
102 kParamKeyNumErr = 0x24,
103 kUpgradePubKeyError = 0x30,
104 kUpgradeDigestError = 0x31,
105 kUpgradeFwTypeError = 0x32,
106 kUpgradeFwOutOfRange = 0x33,
107 kUpgradeFwErasing = 0x34,
118 kMotorStartup = 0x06,
182 std::array<std::uint8_t, 6>
resv{};
191 std::span<const std::byte>
data;
196 std::span<const std::byte> frame)
noexcept;
207 std::span<const std::byte>
data{};
248 std::array<std::uint8_t, 12>
258 std::span<const std::byte>
data;
265 std::span<const std::byte> packet,
bool verify_crc =
true) noexcept;
367 std::span<const std::byte> in, std::size_t key_num)
noexcept;
377 std::span<const std::uint16_t> keys);
429 std::span<const std::byte> data)
noexcept;
432 std::span<const std::byte> data)
noexcept;
435 std::span<const std::byte> data)
noexcept;
438 std::span<const std::byte> data)
noexcept;
441 std::span<const std::byte> data)
noexcept;
Symbol visibility helpers.
The livox_mid360_core library: everything declared by the public headers.
Definition bytes.hpp:14
constexpr std::uint16_t kDebugDataPort
LiDAR-side source port of the debug raw data stream (#93, verified in #106).
Definition protocol.hpp:38
TimeType
Clock source of a data packet timestamp (time_type of the header).
Definition protocol.hpp:134
@ kNoSync
timestamp counts from LiDAR power-on
Definition protocol.hpp:135
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::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::uint16_t kDiscoveryPort
LiDAR discovery port (0x0000).
Definition protocol.hpp:31
constexpr std::size_t kPointsPerPacket
N for data_type 1, 2 and 3.
Definition protocol.hpp:55
constexpr std::uint16_t kDefaultHostImuPort
host port for IMU
Definition protocol.hpp:43
constexpr std::uint8_t kProtocolVersion
version of command frames and packets
Definition protocol.hpp:48
constexpr std::size_t kCommandDataMaxSize
Largest command payload that fits a frame.
Definition protocol.hpp:52
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.
SenderType
Originator of a command frame (sender_type of the header).
Definition protocol.hpp:86
@ kHost
the host computer
Definition protocol.hpp:87
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.
constexpr std::uint16_t kDefaultHostCommandPort
host port for commands
Definition protocol.hpp:40
@ kGps
GPS input (M12 pin 10).
Definition keys.hpp:157
CartesianPoint16 decode_cartesian16(const DataPacketView &p, std::size_t i) noexcept
Decodes the i-th sample, as decode_cartesian32() does for data type 2.
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::vector< std::byte > encode_factory_reset_request()
0x0201 REQ data: 16 reserved bytes (documented as "SN, reserved"). Zero-filled.
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.
constexpr std::uint16_t kPointCloudPort
LiDAR-side source port for point cloud.
Definition protocol.hpp:34
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].
constexpr std::size_t kDataPacketHeaderSize
version .. timestamp
Definition protocol.hpp:54
std::expected< std::vector< std::byte >, EncodeError > build_command_frame(const CommandFrameSpec &spec)
Convenience: allocate and serialise.
std::vector< std::byte > encode_param_config_request(std::span< const KeyValue > kvs)
0x0100 REQ data: key_num u16, rsvd u16, key_value_list.
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.
constexpr std::uint16_t kImuPort
LiDAR-side source port for IMU.
Definition protocol.hpp:35
std::vector< SphericalPoint > decode_all_spherical(const DataPacketView &p)
Whole-packet decoder for data type 3 (allocates).
std::expected< DiscoveryAck, ParseError > parse_discovery_ack(std::span< const std::byte > data) noexcept
Parses the data of a discovery ACK (24 bytes).
CmdId
Command IDs (cmd_id of the command frame header).
Definition protocol.hpp:64
@ kSetGpsTimestamp
set the time of the last PPS edge
Definition protocol.hpp:71
@ kPushLog
LiDAR → host on the log port; see firmware_log.hpp (#44).
Definition protocol.hpp:72
@ kFactoryReset
restore factory settings
Definition protocol.hpp:70
@ kInfoPush
LiDAR → host state push (key-value list).
Definition protocol.hpp:68
@ kParamInquire
read a list of keys
Definition protocol.hpp:67
@ kParamConfig
write a key-value list
Definition protocol.hpp:66
@ kDebugDataControl
host → LiDAR: start / stop debug raw data; debug_data.hpp (#93)
Definition protocol.hpp:75
@ kReboot
reboot after a timeout
Definition protocol.hpp:69
@ kCollectionLog
host → LiDAR port 56500: start / stop a log type
Definition protocol.hpp:73
@ kDiscovery
discovery request; the ACK is a DiscoveryAck
Definition protocol.hpp:65
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.
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
@ kCartesian32
int32 mm, 14 bytes/point, default
Definition protocol.hpp:127
@ kCartesian16
int16 10 mm, 8 bytes/point
Definition protocol.hpp:128
@ kSpherical
depth mm + theta/phi 0.01 deg, 10 bytes/point
Definition protocol.hpp:129
@ kImu
ImuSample, 24 bytes, one per packet.
Definition protocol.hpp:126
constexpr std::size_t sample_size(DataType t) noexcept
Bytes per sample for a data type (0 for unknown).
Definition protocol.hpp:268
ImuSample decode_imu(const DataPacketView &p, std::size_t i) noexcept
Decodes the i-th sample, as decode_cartesian32() does for data type 0.
constexpr std::size_t kCommandFrameMaxSize
whole command frame
Definition protocol.hpp:50
constexpr std::size_t kCommandHeaderSize
command frame header, sof .. crc32
Definition protocol.hpp:49
std::vector< std::byte > encode_reboot_request(std::uint16_t timeout_ms)
0x0200 REQ data: timeout u16 (ms).
RetCode
Result code carried as the first byte of every ACK.
Definition protocol.hpp:93
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.
constexpr std::uint8_t kCommandSof
first byte of every command frame
Definition protocol.hpp:47
constexpr std::uint16_t kCommandPort
LiDAR control command port.
Definition protocol.hpp:32
WorkState
LiDAR working state (key 0x8006 cur_work_state / 0x001A work_tgt_mode).
Definition protocol.hpp:113
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::uint16_t kPushPort
LiDAR-side source port for 0x0102 push.
Definition protocol.hpp:33
constexpr TagInfo decode_tag(std::uint8_t tag) noexcept
Splits a raw tag byte into its four fields.
Definition tag.hpp:40
SphericalPoint decode_spherical(const DataPacketView &p, std::size_t i) noexcept
Decodes the i-th sample, as decode_cartesian32() does for data type 3.
EncodeError
Why encode_command_frame() or build_command_frame() failed.
Definition protocol.hpp:212
@ kBufferTooSmall
output span cannot hold the frame
Definition protocol.hpp:214
@ kDataTooLarge
data exceeds kCommandDataMaxSize
Definition protocol.hpp:213
constexpr std::size_t command_frame_size(std::size_t data_size) noexcept
Total wire size of a frame carrying data_size payload bytes.
Definition protocol.hpp:218
constexpr std::uint16_t kDefaultHostDebugDataPort
as SDK2 (#93)
Definition protocol.hpp:45
CmdType
Request or acknowledgement (cmd_type of the command frame header).
Definition protocol.hpp:80
@ kReq
request
Definition protocol.hpp:81
@ kAck
acknowledgement of a request
Definition protocol.hpp:82
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
@ kLidar
packet timestamp as is (use with PTP / GPS synchronisation)
Definition frame.hpp:103
ParseError
Why a frame, packet or payload was rejected by the parsers in this header.
Definition protocol.hpp:142
@ kTooShort
buffer shorter than the minimal header
Definition protocol.hpp:143
@ kBadVersion
protocol version != 0
Definition protocol.hpp:145
@ kKeyNumMismatch
key_num does not match the number of entries present
Definition protocol.hpp:152
@ kLengthMismatch
length field disagrees with the buffer size or exceeds 1400
Definition protocol.hpp:146
@ kBadSof
command frame does not start with 0xAA
Definition protocol.hpp:144
@ kBadDotNum
dot_num inconsistent with payload size / data_type
Definition protocol.hpp:150
@ kUnknownDataType
data_type not in 0..3
Definition protocol.hpp:149
@ kBadCrc16
command header CRC mismatch
Definition protocol.hpp:147
@ kBadCrc32
payload CRC mismatch
Definition protocol.hpp:148
@ kTruncated
a key-value list or fixed-layout payload ended early
Definition protocol.hpp:151
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::string_view to_string(Event::Kind kind) noexcept
Name of an event kind, e.g. "state_changed".
@ kOutOfRange
a field is outside its enum or documented range
Definition keys.hpp:86
std::vector< CartesianPoint16 > decode_all_cartesian16(const DataPacketView &p)
Whole-packet decoder for data type 2 (allocates).
std::vector< CartesianPoint32 > decode_all_cartesian32(const DataPacketView &p)
Whole-packet decoders (allocate).
std::vector< ImuSample > decode_all_imu(const DataPacketView &p)
Whole-packet decoder for data type 0 (allocates).
One sample of data type 2 (kCartesian16).
Definition protocol.hpp:297
constexpr TagInfo tag_info() const noexcept
The decoded tag byte.
Definition protocol.hpp:304
std::uint8_t reflectivity
0-255
Definition protocol.hpp:301
std::int16_t x_cm
unit 10 mm
Definition protocol.hpp:298
std::int16_t y_cm
unit 10 mm
Definition protocol.hpp:299
std::int16_t z_cm
unit 10 mm
Definition protocol.hpp:300
std::uint8_t tag
raw tag byte
Definition protocol.hpp:302
One sample of data type 1 (kCartesian32).
Definition protocol.hpp:285
std::int32_t x_mm
mm
Definition protocol.hpp:286
std::int32_t y_mm
mm
Definition protocol.hpp:287
std::uint8_t reflectivity
0-255
Definition protocol.hpp:289
std::int32_t z_mm
mm
Definition protocol.hpp:288
constexpr TagInfo tag_info() const noexcept
The decoded tag byte.
Definition protocol.hpp:292
std::uint8_t tag
raw tag byte
Definition protocol.hpp:290
What encode_command_frame() writes; length and both CRCs are computed from it.
Definition protocol.hpp:200
std::uint16_t cmd_id
raw command ID, see CmdId
Definition protocol.hpp:202
CmdType cmd_type
request or ACK
Definition protocol.hpp:203
std::uint32_t seq_num
echoed by the ACK
Definition protocol.hpp:201
SenderType sender_type
host or LiDAR
Definition protocol.hpp:204
std::span< const std::byte > data
Payload, at most kCommandDataMaxSize bytes.
Definition protocol.hpp:207
A validated, non-owning view over a command frame.
Definition protocol.hpp:189
CommandHeader header
the validated header
Definition protocol.hpp:190
std::span< const std::byte > data
payload after the 24-byte header
Definition protocol.hpp:191
The 24-byte command frame header as decoded by parse_command_frame().
Definition protocol.hpp:176
std::uint32_t crc32
data CRC as carried on the wire (0 when data is empty)
Definition protocol.hpp:184
std::array< std::uint8_t, 6 > resv
reserved bytes, as carried on the wire
Definition protocol.hpp:182
SenderType sender_type
host or LiDAR
Definition protocol.hpp:181
std::uint16_t cmd_id
raw; compare against CmdId
Definition protocol.hpp:179
std::uint16_t crc16
header CRC as carried on the wire
Definition protocol.hpp:183
std::uint16_t length
sof .. end of data
Definition protocol.hpp:177
std::uint32_t seq_num
the ACK echoes the request's value
Definition protocol.hpp:178
CmdType cmd_type
request or ACK
Definition protocol.hpp:180
A validated, non-owning view over a data packet.
Definition protocol.hpp:256
DataPacketHeader header
the validated header
Definition protocol.hpp:257
std::span< const std::byte > data
payload after the 36-byte header
Definition protocol.hpp:258
Data of the 0x0000 discovery ACK.
Definition protocol.hpp:390
std::uint16_t cmd_port
LiDAR command port.
Definition protocol.hpp:395
std::array< char, 16 > serial_number
NUL-padded.
Definition protocol.hpp:393
std::array< std::uint8_t, 4 > lidar_ip
IPv4 address, first octet first.
Definition protocol.hpp:394
std::uint8_t dev_type
raw device type; see DeviceType in session.hpp
Definition protocol.hpp:392
std::string_view serial_number_view() const noexcept
serial_number up to the first NUL.
RetCode ret_code
result of the request
Definition protocol.hpp:391
The sample of an IMU packet (data type 0).
Definition protocol.hpp:321
float acc_y
g
Definition protocol.hpp:326
float gyro_x
rad/s
Definition protocol.hpp:322
float gyro_y
rad/s
Definition protocol.hpp:323
float acc_x
g
Definition protocol.hpp:325
float gyro_z
rad/s
Definition protocol.hpp:324
float acc_z
g
Definition protocol.hpp:327
Data of the 0x0102 information push.
Definition protocol.hpp:417
std::vector< KeyValue > values
spans point into the input buffer
Definition protocol.hpp:418
One entry of a key-value list. Non-owning: value points into the parsed buffer.
Definition protocol.hpp:360
std::uint16_t key
raw key; see keys.hpp
Definition protocol.hpp:361
std::span< const std::byte > value
raw little-endian value bytes
Definition protocol.hpp:362
Data of the 0x0100 parameter configuration ACK.
Definition protocol.hpp:403
std::uint16_t error_key
only meaningful when ret_code != kSuccess
Definition protocol.hpp:405
RetCode ret_code
result of the request
Definition protocol.hpp:404
Data of the 0x0101 parameter inquire ACK.
Definition protocol.hpp:410
RetCode ret_code
result of the request
Definition protocol.hpp:411
std::vector< KeyValue > values
spans point into the input buffer
Definition protocol.hpp:412
Data of an ACK that carries only a return code (0x0200, 0x0201, 0x0202, 0x0301, 0x0303).
Definition protocol.hpp:423
RetCode ret_code
result of the request
Definition protocol.hpp:424
One sample of data type 3 (kSpherical).
Definition protocol.hpp:309
std::uint16_t phi_centideg
azimuth, [0, 36000], unit 0.01 deg
Definition protocol.hpp:312
std::uint8_t tag
raw tag byte
Definition protocol.hpp:314
std::uint32_t depth_mm
distance, mm
Definition protocol.hpp:310
std::uint16_t theta_centideg
zenith, [0, 18000], unit 0.01 deg
Definition protocol.hpp:311
std::uint8_t reflectivity
0-255
Definition protocol.hpp:313
constexpr TagInfo tag_info() const noexcept
The decoded tag byte.
Definition protocol.hpp:316
Decoded tag byte: bit 0-1 adjacent glue, 2-3 rain / fog / dust, 4-5 other, 6-7 reserved.
Definition tag.hpp:28
Point tag byte (issue #34): four 2-bit confidence fields, section "Tag Information".