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()
{
...
...
uint32_t br = can0.get_bitrate();
...
}
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:11
#include <can_adapter.h>
|
| | 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.
|
| can_type | type () const |
| | Get the adapter type (physical or virtual)
|
| 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 ¶m) |
| | Get the current configuration for this interface.
|
| bool | set_config (const can_parameters ¶m) |
| | Set the configuration for this interface.
|
|
|
static std::vector< can_adapter > | list_adapters () |
| | Get all the CAN adapters.
|
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()
{
...
...
uint32_t br = can0.get_bitrate();
...
}
◆ can_adapter()
| vsdk::comms::can_adapter::can_adapter |
( |
std::string_view | name | ) |
|
|
explicit |
Constructor that uses the interface name.
- Parameters
-
| name | The name of the interface. |
◆ get_config()
Get the current configuration for this interface.
- Exceptions
-
| std::system_error | if the adapter does not exist on the system or an underlying OS issue occurs |
◆ set_bitrate()
| bool vsdk::comms::can_adapter::set_bitrate |
( |
uint32_t | bitrate | ) |
|
Set the CAN bit rate.
- Exceptions
-
| std::system_error | if the adapter does not exist on the system or an underlying OS issue occurs |
◆ 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_error | if the adapter does not exist on the system or an underlying OS issue occurs |
◆ start() [2/2]
| bool vsdk::comms::can_adapter::start |
( |
uint32_t | default_bitrate | ) |
|
Bring the adapter up with a bitrate.
- Parameters
-
| default_bitrate | The bitrate with which to start the adapter |
- Exceptions
-
| std::system_error | if the adapter does not exist on the system or an underlying OS issue occurs |
◆ stop()
| bool vsdk::comms::can_adapter::stop |
( |
| ) |
|
Bring the adapter down.
- Exceptions
-
| std::system_error | if the adapter does not exist on the system or an underlying OS issue occurs |
◆ type()
| can_type vsdk::comms::can_adapter::type |
( |
| ) |
const |
Get the adapter type (physical or virtual)
- Returns
- can_type
The documentation for this class was generated from the following file: