Class CanFrame

Nested Relationships

Nested Types

Class Documentation

class CanFrame

CanFrame is a wrapper around the linux/can.h struct can_frame that adds some additional functionalility.

Public Functions

CanFrame()

Construct Empty CanFrame.

explicit CanFrame(const struct can_frame &frame)

Construct CanFrame directly from a can_frame structure.

Parameters:

frame

CanFrame(const canid_t raw_id, const std::array<unsigned char, CAN_MAX_DLC> &data, const uint64_t &bus_timestamp, uint8_t len = CAN_MAX_DLC)

Initialize CanFrame with raw_id and data defined in std::array.

Parameters:
  • raw_id – Can ID already generated including error and data information

  • data – std::array<unsigned char, CAN_MAX_DLC> enforces C++ std::array for it’s core API

  • timestamp – uint64_t utc timestamp for the can frame to store

CanFrame(const canid_t id, const std::array<unsigned char, CAN_MAX_DLC> &data, const uint64_t &bus_timestamp, FrameType &frame_type, IdType &frame_id_type, uint8_t len = CAN_MAX_DLC)

Initialize CanFrame with a partial ID and data defined in std::array.

Parameters:
  • raw_id – Can ID already generated including error and data information

  • data – std::array<unsigned char, CAN_MAX_DLC> enforces C++ std::array for it’s core API

  • timestamp – uint64_t utc timestamp for the can frame to store

  • frame_type – DATA, ERROR or REMOTE

  • frame_id_type – EXTENDED or Standard

~CanFrame() = default

~CanFrame is a default destructor for now

bool set_frame(const struct can_frame &frame)

Set the internal frame to some predefined value.

Parameters:

frame – INPUT c type can_frame structure

Returns:

Whether the frame was successfully set

void set_can_id(const canid_t &id)

Set the CAN ID (does not set EFF, ERR, RTR)

Parameters:

id – INPUT can_id

void set_id_as_extended()

Set bit for extended ID.

void set_id_as_standard()

Set bit for standard ID.

void set_type_error()

Set bit for error ID (overwrites remote)

void set_type_remote()

Set bit for remote ID (overwrites error id)

void set_type_data()

Set bit to specify data frame (overwrites remote and error id)

void set_len(unsigned char len)

Set can dlc if we don’t want to send the entire array.

void set_data(const std::array<unsigned char, CAN_MAX_DLC> &data)

Set data if we have an array available.

Parameters:

data – INPUT raw data to pass through the socket

void set_bus_timestamp(const uint64_t &timestamp)

Set bus timestamp.

Parameters:

timestamp – INPUT time as uint64_t from the bus

void set_receive_timestamp(const uint64_t &timestamp)

Set receive timestamp.

Parameters:

timestamp – INPUT time as uint64_t from the bus

void set_bus_timestamp(const std::chrono::system_clock::time_point &timestamp)

Set timestamp.

Parameters:

timestamp – INPUT time as std::chrono::system_clock::time_point from the bus

void set_receive_timestamp(const std::chrono::steady_clock::time_point &timestamp)

Set timestamp.

Parameters:

timestamp – INPUT time as std::chrono::steady_clock::time_point from the adapter

std::chrono::system_clock::time_point get_bus_time() const

Get bus time.

Returns:

returns std::chrono::system_clock::time_point for when the frame was received on the bus

std::chrono::steady_clock::time_point get_receive_time() const

Get receive time.

Returns:

returns std::chrono::steady_clock::time_point for when the frame was received by the adapter

FrameType get_frame_type() const

Get frame type.

Returns:

returns polymath::socketcan::FrameType

IdType get_id_type() const

Get frame id type.

Returns:

returns polymath::socketcan::IdType

canid_t get_id() const

Get frame id.

Returns:

canid_t frame id

unsigned char get_len() const

Get length set for the can_frame.

Returns:

unsigned char defining the length

std::string get_error() const

Get a subset of can errors as a string.

Returns:

std::string detailing error parsed from an error frame

canid_t get_masked_id(uint8_t bit_length, uint8_t bit_offset) const

Get a part of the frame id that is most relevant to us.

Parameters:
  • bit_length – INPUT number of bits to return

  • bit_offset – INPUT offset of the bits to return

Returns:

Masked and shifted can id

struct can_frame get_frame() const

Get a copy of raw frame.

Returns:

frame saved inside returned as a copy

const std::array<unsigned char, CAN_MAX_DLC> get_data() const

Get the raw data.

Returns:

std::array<usnigned char, CAN_MAX_DLC> raw data