// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest

#ifndef CAN_DEVICE_HPP
#define CAN_DEVICE_HPP

#include "CanPackets.hpp"
#include <atomic>
#include <linux/can.h>
#include <thread>

class CanDevice {
public:
    CanDevice();
    virtual ~CanDevice();
    bool open_device(const char* dev);
    bool close_device();

protected:
    virtual void rx_handler(uint32_t can_id, const std::vector<uint8_t>& payload);
    bool _tx(uint32_t can_id, const std::vector<uint8_t>& payload);

private:
    int can_fd;
    std::atomic_bool exit_rx_thread;
    std::thread rx_thread_handle;
    void rx_thread();
};

#endif // CAN_DEVICE_HPP
