packet.h

Enums

enum class ouster::sensor::PacketType

Types of Ouster packets that can come from a sensor.

Values:

enumerator Unknown

Packet type could not or has not been determined.

enumerator Lidar

Pointcloud data packet.

enumerator Imu

IMU data packet.

enum class ouster::sensor::PacketValidationFailure

Reasons for failure of packet validation.

Values:

enumerator NONE

No validation errors were found.

enumerator PACKET_SIZE

The packet size does not match the expected size.

enumerator ID

The prod_sn or init_id does not match the metadata.

Structs

struct ImuPacket : public ouster::sensor::Packet

Encapsulate an imu packet buffer and attributes associated with it.

Public Functions

ImuPacket()

Construct a new empty Imu Packet.

ImuPacket(int size)

Construct a new Imu packet with a pre-allocated size.

Parameters:

size – [in] size in bytes to allocate

PacketValidationFailure validate(const sensor_info &info, const ouster::sensor::packet_format &format) const

Validates that the packet matches the expected format and metadata.

Parameters:
  • info – [in] expected sensor_metadata

  • format – [in] expected packet_format

Returns:

a PacketValdationFailure with either NONE or a failure reason.

PacketValidationFailure validate(const sensor_info &info) const

Validates that the packet matches the expected format and metadata.

Parameters:

info – [in] expected sensor_metadata

Returns:

a PacketValdationFailure with either NONE or a failure reason.

inline auto sys_ts() const

Read system timestamp from the packet.

Returns:

system timestamp

inline auto accel_ts() const

Read accelerometer timestamp from the packet.

Returns:

accelerometer timestamp

inline auto gyro_ts() const

Read gyroscope timestamp from the packet.

Returns:

gyroscope timestamp

inline auto la_x() const

Read acceleration in X direction from the packet.

Returns:

acceleration in the X direction

inline auto la_y() const

Read acceleration in Y direction from the packet.

Returns:

acceleration in the Y direction

inline auto la_z() const

Read acceleration in Z direction from the packet.

Returns:

acceleration in the Z direction

inline auto av_x() const

Read angular velocity on the X axis from the packet.

Returns:

angular velocity on the X axis

inline auto av_y() const

Read angular velocity on the Y axis from the packet.

Returns:

angular velocity on the Y axis

inline auto av_z() const

Read angular velocity on the Z axis from the packet.

Returns:

angular velocity on the Z axis

Packet(PacketType type)

Construct an empty packet with a given type.

Parameters:

type – [in] type packet type (imu or lidar)

Packet(PacketType type, int size)

Construct a packet with given type and a pre-allocated size.

Parameters:
  • type – [in] type packet type (imu or lidar)

  • size – [in] size in bytes to allocate

Public Static Attributes

static const PacketType MyType = PacketType::Imu

PacketType enum for this packet type.

struct LidarPacket : public ouster::sensor::Packet

Encapsulate a lidar packet buffer and attributes associated with it.

Public Functions

LidarPacket()

Construct a new empty Lidar Packet.

LidarPacket(int size)

Construct a new Lidar packet with a pre-allocated size.

Parameters:

size – [in] size in bytes to allocate

PacketValidationFailure validate(const sensor_info &info, const ouster::sensor::packet_format &format) const

Validates that the packet matches the expected format and metadata.

Parameters:
  • info – [in] expected sensor_metadata

  • format – [in] expected packet_format

Returns:

a PacketValdationFailure with either NONE or a failure reason.

PacketValidationFailure validate(const sensor_info &info) const

Validates that the packet matches the expected format and metadata.

Parameters:

info – [in] expected sensor_metadata

Returns:

a PacketValdationFailure with either NONE or a failure reason.

inline auto nth_col(int n) const

Get pointer to the nth column in the packet.

Parameters:

n – [in] which column

Returns:

pointer to the nth column in this packet

inline auto nth_px(int n, const uint8_t *col_buf) const

Get pointer to the nth pixel of a column buffer

Parameters:
  • n – [in] which pixel

  • col_buf – [in] pointer to column data

Returns:

pointer to the nth pixel of a column buffer

inline auto col_timestamp(const uint8_t *col_buf) const

Read column timestamp from a column buffer

Parameters:

col_buf – [in] pointer to column data

Returns:

column timestamp

inline auto col_measurement_id(const uint8_t *col_buf) const

Read column measurement id from a column buffer

Parameters:

col_buf – [in] pointer to column data

Returns:

column measurement id

inline auto col_status(const uint8_t *col_buf) const

Read column status from a column buffer

Parameters:

col_buf – [in] pointer to column data

Returns:

column status

template<typename T>
inline void col_field(const uint8_t *col_buf, const std::string &f, T *dst, int dst_stride = 1) const

Copy the specified channel field out of a packet measurement block.

Template Parameters:

T – T should be a numeric type large enough to store values of the specified field. Otherwise, data will be truncated.

Parameters:
  • col_buf[in] a measurement block pointer returned by nth_col().

  • f[in] the channel field to copy.

  • dst[out] destination array of size pixels_per_column * dst_stride.

  • dst_stride[in] stride for writing to the destination array.

inline auto packet_type() const

Read the packet type from the packet header.

Returns:

packet type

inline auto frame_id() const

Read the frame id from the packet header.

Returns:

frame id

inline auto init_id() const

Read the init id from the packet header.

Returns:

init id

inline auto prod_sn() const

Read the product serial number from the packet header.

Returns:

product serial number

inline auto alert_flags() const

Read the alert flags from the packet header.

Returns:

alert flags

inline auto countdown_thermal_shutdown() const

Read the thermal shutdown countdown from the packet header.

Returns:

thermal shutdown countdown

inline auto countdown_shot_limiting() const

Read the shot limiting countdown from the packet header.

Returns:

shot limiting countdown

inline auto thermal_shutdown() const

Read the thermal shutdown state from the packet header.

Returns:

thermal shutdown state

inline auto shot_limiting() const

Read the shot limiting state from the packet header.

Returns:

shot limiting state

inline auto footer() const

Get a pointer to the packet footer.

Returns:

pointer to packet footer of lidar buffer, can be nullptr if packet format doesn’t have packet footer.

inline auto crc() const

Return the CRC contained in the packet footer if present.

Returns:

crc contained in the packet if present

inline auto calculate_crc() const

Calculate the CRC for the given packet data.

Returns:

calculated crc of the packet

inline auto block_parsable() const

Returns maximum available size of parsing block usable with block_field

Returns:

if packet format does not allow for block parsing, returns 0

template<typename T, int BlockDim>
inline void block_field(Eigen::Ref<img_t<T>> field, const std::string &f) const

Copy the specified channel field out of a packet measurement block. Faster traversal than col_field, but has to copy the entire packet all at once.

Parameters:
  • field – [out] destination eigen array

  • f – [in] the channel field to copy

Template Parameters:

T – T should be a numeric type large enough to store values of the specified field. Otherwise, data will be truncated.

Packet(PacketType type)

Construct an empty packet with a given type.

Parameters:

type – [in] type packet type (imu or lidar)

Packet(PacketType type, int size)

Construct a packet with given type and a pre-allocated size.

Parameters:
  • type – [in] type packet type (imu or lidar)

  • size – [in] size in bytes to allocate

Public Static Attributes

static const PacketType MyType = PacketType::Lidar

PacketType enum for this packet type.

struct Packet

Encapsulate a packet buffer and attributes associated with it.

Subclassed by ouster::sensor::ImuPacket, ouster::sensor::LidarPacket

Public Functions

inline PacketType type() const

Returns the type of the packet

Returns:

the packet type

template<typename Type>
inline Type &as()

Attempt to cast the packet to the desired concrete PacketType.

Throws:

runtime_error – if packet is not that of that type

Template Parameters:

Type – Type of packet to cast to. Either LidarPacker or ImuPacket.

Returns:

reference to the packet as the desired type

Public Members

uint64_t host_timestamp

Timestamp in nanoseconds of packet capture.

std::vector<uint8_t> buf

Packet data.

std::shared_ptr<ouster::sensor::packet_format> format

packet_format associated with this packet

Functions

PacketValidationFailure ouster::sensor::validate_packet(const sensor_info &info, const ouster::sensor::packet_format &format, const uint8_t *buf, uint64_t buf_size, PacketType type = PacketType::Unknown)

Validate a packet buffer against a given type.

Parameters:
  • info[in] The sensor info to try to check the buffer against.

  • format[in] The packet format to try to check the buffer against.

  • buf[in] The packet buffer to validate.

  • buf_size[in] The size of the packet buffer.

  • type[in] Optional type of packet to try and validate as. Unknown will try and guess the packet type

Returns:

Result of the validation

Deprecations