18 receiveOwnMessages(receiveOwnMessages)
20 const std::lock_guard<std::mutex> lock(
mutex);
21 ourDevice = std::make_shared<VirtualDevice>();
56 const std::lock_guard<std::mutex> lock(
mutex);
63 device->queue.push_back(canFrame);
64 device->condition.notify_one();
74 const std::lock_guard<std::mutex> lock(
mutex);
86 std::unique_lock<std::mutex> lock(
mutex);
87 ourDevice->condition.wait_for(lock, std::chrono::milliseconds(timeout), [
this] {
return !
ourDevice->queue.empty() || !
running; });
99 const std::lock_guard<std::mutex> lock(
mutex);
105 const std::lock_guard<std::mutex> lock(
mutex);
A CAN frame for interfacing with a hardware layer, like socket CAN or other interface.
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...
An OS and hardware independent virtual CAN interface driver for testing purposes. Any instance connec...