10#ifndef VIRTUAL_CAN_PLUGIN_HPP
11#define VIRTUAL_CAN_PLUGIN_HPP
18#include <condition_variable>
55 void close()
override;
91 std::deque<isobus::CANMessageFrame>
queue;
98 static std::map<std::string, std::vector<std::shared_ptr<VirtualDevice>>>
channels;
An abstraction between this CAN stack and any hardware layer.
A base class for a CAN driver. Can be derived into your platform's required interface.
A classical CAN frame, with 8 data bytes.
An abstract base class for a CAN driver.
A CAN frame for interfacing with a hardware layer, like socket CAN or other interface.
An OS and hardware independent virtual CAN interface driver for testing purposes.
std::string get_channel_name() const
Returns the assigned virtual channel name.
void open() override
Connects to the socket.
const bool receiveOwnMessages
If true, the driver will receive its own messages.
void clear_queue() const
Clear the internal received message queue.
std::atomic_bool running
If true, the driver is running.
static constexpr size_t MAX_QUEUE_SIZE
The maximum size of the queue, mostly arbitrary.
const std::string channel
The virtual channel name.
bool write_frame(const isobus::CANMessageFrame &canFrame) override
Writes a frame to the bus (synchronous)
VirtualCANPlugin(const std::string channel="", const bool receiveOwnMessages=false)
Constructor for the virtual CAN driver.
bool read_frame(isobus::CANMessageFrame &canFrame) override
Returns a frame from the hardware (synchronous), or false if no frame can be read....
std::shared_ptr< VirtualDevice > ourDevice
A pointer to the virtual device of this instance.
bool get_queue_empty() const
Returns if the internal received message queue is empty or not.
bool get_is_valid() const override
Returns if the socket connection is valid.
static std::mutex mutex
Mutex to access channels and queues for thread safety.
void close() override
Closes the socket.
static std::map< std::string, std::vector< std::shared_ptr< VirtualDevice > > > channels
A channel is a vector of devices.
void write_frame_as_if_received(const isobus::CANMessageFrame &canFrame) const
Allows us to write messages as if we received them from the bus.
virtual ~VirtualCANPlugin()
Destructor for the virtual CAN driver.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
A struct holding information about a virtual CAN device.
std::condition_variable condition
A condition variable to wake us up when a frame is received.
std::deque< isobus::CANMessageFrame > queue
A queue of CAN frames.