File usb_stream.hpp¶
-
namespace
real_time_tools
-
class
PortConfig
- #include <usb_stream.hpp>
Simple config class that encapsulate the port parameters for a USB port.
This should cover enough paramter to setup the USB port for the imu_3DM_GX3_25, imu_3DM_GX3_45 and the imu_3DM_GX5 in xenomai, rt_preempt and ubuntu (potentially MacOS: non posix).
Public Types
-
enum
StopBits
This is if one wants 1 or 2 stop bits.
Values:
-
enumerator
one
= 1
-
enumerator
two
= 2
-
enumerator
-
enum
DataBits
This correspond to the number of data bits echanged.
Values:
-
enumerator
cs7
= 0
-
enumerator
cs8
= 1
-
enumerator
Public Functions
-
int
get_bauderate
() Get the _bauderate object.
- Return
int
Public Members
-
bool
rts_cts_enabled_
Enabling/Disabling rts cts.
TODO: look for what is rts cts
-
bool
parity_
Use or not a parity bit.
-
StopBits
stop_bits_
Defines the choice of the stop bits.
(see enum StopBits)
-
bool
prepare_size_definition_
Defines if the port should prepare the size definition.
-
DataBits
data_bits_
Defines the number of bits echanged.
(see enum DataBits)
-
int
baude_rate_
Defines the BaudeRate to be used.
(see enum BaudeRate)
-
enum
-
class
UsbStream
- #include <usb_stream.hpp>
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 displayeduntil
: 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.
-
-
class