AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
isobus::SocketCANInterface Class Reference

A CAN Driver for Linux socket CAN. More...

#include <socket_can_interface.hpp>

Inheritance diagram for isobus::SocketCANInterface:
[legend]
Collaboration diagram for isobus::SocketCANInterface:
[legend]

Public Member Functions

 SocketCANInterface (const std::string deviceName)
 Constructor for the socket CAN driver.
 
virtual ~SocketCANInterface ()
 The destructor for SocketCANInterface.
 
bool get_is_valid () const override
 Returns if the socket connection is valid.
 
std::string get_device_name () const
 Returns the device name the driver is using.
 
void close () override
 Closes the socket.
 
void open () override
 Connects to the socket.
 
bool read_frame (isobus::CANMessageFrame &canFrame) override
 Returns a frame from the hardware (synchronous), or false if no frame can be read.
 
bool write_frame (const isobus::CANMessageFrame &canFrame) override
 Writes a frame to the bus (synchronous)
 
bool set_name (const std::string &newName)
 Changes the name of the device to use, which only works if the device is not open.
 

Private Attributes

struct sockaddr_can * pCANDevice
 The structure for CAN sockets.
 
std::string name
 The device name.
 
int fileDescriptor
 File descriptor for the socket.
 

Detailed Description

A CAN Driver for Linux socket CAN.

Definition at line 28 of file socket_can_interface.hpp.

Constructor & Destructor Documentation

◆ SocketCANInterface()

isobus::SocketCANInterface::SocketCANInterface ( const std::string deviceName)
explicit

Constructor for the socket CAN driver.

Parameters
[in]deviceNameThe device name to use, like "can0" or "vcan0"

Definition at line 28 of file socket_can_interface.cpp.

◆ ~SocketCANInterface()

isobus::SocketCANInterface::~SocketCANInterface ( )
virtual

The destructor for SocketCANInterface.

Definition at line 39 of file socket_can_interface.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ close()

void isobus::SocketCANInterface::close ( )
overridevirtual

Closes the socket.

Implements isobus::CANHardwarePlugin.

Definition at line 60 of file socket_can_interface.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_device_name()

std::string isobus::SocketCANInterface::get_device_name ( ) const

Returns the device name the driver is using.

Returns
The device name the driver is using, such as "can0" or "vcan0"

Definition at line 55 of file socket_can_interface.cpp.

Here is the caller graph for this function:

◆ get_is_valid()

bool isobus::SocketCANInterface::get_is_valid ( ) const
overridevirtual

Returns if the socket connection is valid.

Returns
true if connected, false if not connected

Implements isobus::CANHardwarePlugin.

Definition at line 50 of file socket_can_interface.cpp.

Here is the caller graph for this function:

◆ open()

void isobus::SocketCANInterface::open ( )
overridevirtual

Connects to the socket.

Implements isobus::CANHardwarePlugin.

Definition at line 66 of file socket_can_interface.cpp.

Here is the call graph for this function:

◆ read_frame()

bool isobus::SocketCANInterface::read_frame ( isobus::CANMessageFrame & canFrame)
overridevirtual

Returns a frame from the hardware (synchronous), or false if no frame can be read.

Parameters
[in,out]canFrameThe CAN frame that was read
Returns
true if a CAN frame was read, otherwise false

Implements isobus::CANHardwarePlugin.

Definition at line 109 of file socket_can_interface.cpp.

Here is the call graph for this function:

◆ set_name()

bool isobus::SocketCANInterface::set_name ( const std::string & newName)

Changes the name of the device to use, which only works if the device is not open.

Parameters
[in]newNameThe new name for the device (such as "can0" or "vcan0")
Returns
true if the name was changed, otherwise false (if the device is open this will return false)

Definition at line 220 of file socket_can_interface.cpp.

Here is the call graph for this function:

◆ write_frame()

bool isobus::SocketCANInterface::write_frame ( const isobus::CANMessageFrame & canFrame)
overridevirtual

Writes a frame to the bus (synchronous)

Parameters
[in]canFrameThe frame to write to the bus
Returns
true if the frame was written, otherwise false

Implements isobus::CANHardwarePlugin.

Definition at line 194 of file socket_can_interface.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ fileDescriptor

int isobus::SocketCANInterface::fileDescriptor
private

File descriptor for the socket.

Definition at line 70 of file socket_can_interface.hpp.

◆ name

std::string isobus::SocketCANInterface::name
private

The device name.

Definition at line 69 of file socket_can_interface.hpp.

◆ pCANDevice

struct sockaddr_can* isobus::SocketCANInterface::pCANDevice
private

The structure for CAN sockets.

Definition at line 68 of file socket_can_interface.hpp.


The documentation for this class was generated from the following files: