File sample_hw_interface.hpp
File List > include > nebula_sample_hw_interfaces > sample_hw_interface.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_HW_INTERFACE_HPP
#define NEBULA_SAMPLE_HW_INTERFACE_HPP
#include <nebula_core_common/util/expected.hpp>
#include <nebula_core_hw_interfaces/connections/udp.hpp>
#include <nebula_sample_common/sample_configuration.hpp>
#include <cstdint>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <variant>
namespace nebula::drivers
{
class SampleHwInterface
{
public:
struct Error
{
enum class Code : uint8_t {
CALLBACK_NOT_REGISTERED,
INVALID_CALLBACK,
INVALID_OPERATION,
SOCKET_OPEN_FAILED,
SOCKET_CLOSE_FAILED,
};
Code code;
std::string message;
};
static const char * to_cstr(Error::Code code);
explicit SampleHwInterface(ConnectionConfiguration connection_configuration);
util::expected<std::monostate, Error> sensor_interface_start();
util::expected<std::monostate, Error> sensor_interface_stop();
util::expected<std::monostate, Error> register_scan_callback(
connections::UdpSocket::callback_t scan_callback);
private:
ConnectionConfiguration connection_configuration_;
std::optional<connections::UdpSocket> udp_socket_;
std::shared_ptr<connections::UdpSocket::callback_t> packet_callback_;
std::mutex callback_mutex_;
};
} // namespace nebula::drivers
#endif // NEBULA_SAMPLE_HW_INTERFACE_HPP