Veethree D7 SDK
Loading...
Searching...
No Matches
vsdk::comms::can_adapter Class Reference

Detailed Description

The CAN interface setup class.

This is a utility class for getting all the available CAN interfaces, bringing them up or down and configuring them.

Basic usage example (bring can0 up, set its bitrate, get its bitrate, bring it down)

void func()
{
using namespace vsdk::comms;
can_adapter can0("can0");
// start with a default bitrate
bool started = can0.start(bitrate_250k);
...
// change the bitrate
bool changed = can0.set_bitrate(bitrate_500k);
...
// get the bitrate
uint32_t br = can0.get_bitrate();
...
// stop the adapter
bool stopped = can0.stop();
}
CAN Adapter.
can_adapter(std::string_view name)
Constructor that uses the interface name.
constexpr uint32_t bitrate_500k
Common CAN bitrates.
Definition can_adapter_interface.h:29
constexpr uint32_t bitrate_250k
Common CAN bitrates.
Definition can_adapter_interface.h:28
@ stopped
Device is stopped.
Definition can_common.h:51
Any entities that belong to the comms library.
Definition can_adapter.h:12

#include <can_adapter.h>

Public Member Functions

 can_adapter (std::string_view name)
 Constructor that uses the interface name.
 can_adapter (const can_adapter &other)
 Copy constructor.
can_adapter & operator= (const can_adapter &other)
 Copy assignment operator.
 can_adapter (can_adapter &&other) noexcept=default
 Move constructor.
can_adapter & operator= (can_adapter &&other) noexcept=default
 Move assignment operator.
std::string name () const
 Get the adapter's name.
bool start ()
 Bring the adapter up.
bool start (uint32_t default_bitrate)
 Bring the adapter up with a bitrate.
bool stop ()
 Bring the adapter down.
bool restart ()
 Restart this interface.
can_status get_bus_state ()
 Get the current CAN Bus state.
bool set_bitrate (uint32_t bitrate)
 Set the CAN bit rate.
uint32_t get_bitrate ()
 Get the current CAN bit rate.
void get_config (can_parameters &param)
 Get the current configuration for this interface.
bool set_config (const can_parameters &param)
 Set the configuration for this interface.

Static Public Member Functions

static std::vector< can_adapter > list_adapters ()
 Get all the CAN adapters.

Detailed Description

The CAN interface setup class.

This is a utility class for getting all the available CAN interfaces, bringing them up or down and configuring them.

Basic usage example (bring can0 up, set its bitrate, get its bitrate, bring it down)

void func()
{
using namespace vsdk::comms;
can_adapter can0("can0");
// start with a default bitrate
bool started = can0.start(bitrate_250k);
...
// change the bitrate
bool changed = can0.set_bitrate(bitrate_500k);
...
// get the bitrate
uint32_t br = can0.get_bitrate();
...
// stop the adapter
bool stopped = can0.stop();
}

Constructor & Destructor Documentation

◆ can_adapter()

vsdk::comms::can_adapter::can_adapter ( std::string_view name)
explicit

Constructor that uses the interface name.

Parameters
nameThe name of the interface.

Member Function Documentation

◆ get_config()

void vsdk::comms::can_adapter::get_config ( can_parameters & param)

Get the current configuration for this interface.

Exceptions
std::system_errorif the adapter does not exist on the system or an underlying OS issue occurrs

◆ set_bitrate()

bool vsdk::comms::can_adapter::set_bitrate ( uint32_t bitrate)

Set the CAN bit rate.

Exceptions
std::system_errorif the adapter does not exist on the system or an underlying OS issue occurrs

◆ set_config()

bool vsdk::comms::can_adapter::set_config ( const can_parameters & param)

Set the configuration for this interface.

Only set the fields that need to be changed. Any field that is not set will be left untouched.

◆ start() [1/2]

bool vsdk::comms::can_adapter::start ( )

Bring the adapter up.

Note
The adapter should already be configured before calling this. The call will fail otherwise and the adapter's state will not change.
Returns
true if successfully brought the adapter up, false otherwise
Exceptions
std::system_errorif the adapter does not exist on the system or an underlying OS issue occurrs

◆ start() [2/2]

bool vsdk::comms::can_adapter::start ( uint32_t default_bitrate)

Bring the adapter up with a bitrate.

Parameters
default_bitrateThe bitrate with which to start the adapter
Exceptions
std::system_errorif the adapter does not exist on the system or an underlying OS issue occurrs

◆ stop()

bool vsdk::comms::can_adapter::stop ( )

Bring the adapter down.

Exceptions
std::system_errorif the adapter does not exist on the system or an underlying OS issue occurrs

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