File sample_decoder.hpp
File List > include > nebula_sample_decoders > sample_decoder.hpp
Go to the documentation of this file
// Copyright 2025 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef NEBULA_SAMPLE_DECODER_HPP
#define NEBULA_SAMPLE_DECODER_HPP
#include <nebula_core_common/point_types.hpp>
#include <nebula_core_common/util/expected.hpp>
#include <nebula_core_decoders/angles.hpp>
#include <cstdint>
#include <functional>
#include <vector>
namespace nebula::drivers
{
enum class DecodeError : uint8_t {
PACKET_FORMAT_INVALID,
CALLBACK_NOT_SET,
EMPTY_PACKET,
};
const char * to_cstr(DecodeError error);
struct PacketMetadata
{
uint64_t packet_timestamp_ns{};
bool did_scan_complete{false};
};
struct PerformanceCounters
{
uint64_t decode_time_ns{0};
uint64_t callback_time_ns{0};
};
struct PacketDecodeResult
{
PerformanceCounters performance_counters;
util::expected<PacketMetadata, DecodeError> metadata_or_error;
};
class SampleDecoder
{
public:
using pointcloud_callback_t =
std::function<void(const NebulaPointCloudPtr & pointcloud, double timestamp_s)>;
explicit SampleDecoder(
FieldOfView<float, Degrees> fov /*, other decoder args */, pointcloud_callback_t pointcloud_cb);
[[nodiscard]] PacketDecodeResult unpack(const std::vector<uint8_t> & packet);
void set_pointcloud_callback(pointcloud_callback_t pointcloud_cb);
private:
static constexpr uint64_t k_packets_per_sample_scan = 10;
FieldOfView<float, Degrees> fov_;
pointcloud_callback_t pointcloud_callback_;
NebulaPointCloudPtr current_scan_cloud_{std::make_shared<NebulaPointCloud>()};
uint64_t packet_count_{0};
};
} // namespace nebula::drivers
#endif // NEBULA_SAMPLE_DECODER_HPP