Class real_time_tools::UsbStream

class real_time_tools::UsbStream

This class has for purpose to interact with devices and files alike as the linux philosophie does.

Depending on the current Operating system it uses the available real time APIs.

Public Functions

UsbStream()

Construct a new fstream object.

~UsbStream()

Destroy the fstream object.

bool open_device(const std::string &file_name)

This method allows you to open a port or a file.

Parameters
  • file_name:

bool set_port_config(const PortConfig &user_config)

Set the _port_config object parametrize the port configuration.

Return

true

Return

false

Parameters
  • user_config: is the configuration of the port. (see struct PortConfig)

bool close_device()

Stop the device communication.

Return

true success

Return

false problem occured

bool read_device(std::vector<uint8_t> &msg, const bool stream_on = true)

Read the port or the file.

Return

true

Return

false

Parameters
  • msg: is the command sent before this command was executed.

  • stream_on: define if we just read on the fly or we wait until we get the correct amount of data.

bool write_device(const std::vector<uint8_t> &msg)

Write msg in the port or the file.

Return

true success

Return

false problem occured

bool activate_stream_mode()

Activate the stream mode.

The read method is not blocking.

Return

true success

Return

false problem occured

bool set_poll_mode_timeout(double timeout_in_second)

Set the poll mode timeout.

The read_device method is blocking until timeout.

Return

true success

Return

false problem occured

bool flush(int duration_ms = 150)

Flush the current port.

Return

true

Return

false

Public Static Functions

std::string msg_debug_string(const std::vector<uint8_t> &msg, long int until = -1)

Display the uint8_t message in hexadecimal format.

Return

std::string the debug string

Parameters
  • msg: is the message to be displayed

  • until: is a bound on the number of displayed bytes. “-1” means display all.

bool test_msg_equal(const std::vector<uint8_t> &msg1, const std::vector<uint8_t> &msg2)

Test if two message are the same or not.

Return

true

Return

false

Parameters
  • msg1:

  • msg2:

Private Members

std::string file_name_

Private methods.

Attributes This is the path tot the device file

int file_id_

This is the port id.

ssize_t return_value_

This is the return value of the different POSIX/Xenomai methods.

bool timeout_set_

Verify that the timeout value has been set.

double timeout_

The timeout for the poll mode in seconds.

std::vector<uint8_t> buffer_

Internal buffer that is supposed to be much bigger than the message sent or received to avoid memory problems.