Apollo  6.0
Open source self driving car software
Public Member Functions | Static Public Member Functions | List of all members
apollo::drivers::canbus::Byte Class Reference

The class of one byte, which is 8 bits. It includes some operations on one byte. More...

#include <byte.h>

Collaboration diagram for apollo::drivers::canbus::Byte:
Collaboration graph

Public Member Functions

 Byte (const uint8_t *value)
 Constructor which takes a pointer to a one-byte unsigned integer. More...
 
 Byte (const Byte &value)
 Constructor which takes a reference to a one-byte unsigned integer. More...
 
 ~Byte ()=default
 Desctructor. More...
 
void set_bit_1 (const int32_t pos)
 Set the bit on a specified position to one. More...
 
void set_bit_0 (const int32_t pos)
 Set the bit on a specified position to zero. More...
 
bool is_bit_1 (const int32_t pos) const
 Check if the bit on a specified position is one. More...
 
void set_value (const uint8_t value)
 Reset this Byte by a specified one-byte unsigned integer. More...
 
void set_value_high_4_bits (const uint8_t value)
 Reset the higher 4 bits as the higher 4 bits of a specified one-byte unsigned integer. More...
 
void set_value_low_4_bits (const uint8_t value)
 Reset the lower 4 bits as the lower 4 bits of a specified one-byte unsigned integer. More...
 
void set_value (const uint8_t value, const int32_t start_pos, const int32_t length)
 Reset some consecutive bits starting from a specified position with a certain length of another one-byte unsigned integer. More...
 
uint8_t get_byte () const
 Get the one-byte unsigned integer. More...
 
uint8_t get_byte_high_4_bits () const
 Get a one-byte unsigned integer representing the higher 4 bits. More...
 
uint8_t get_byte_low_4_bits () const
 Get a one-byte unsigned integer representing the lower 4 bits. More...
 
uint8_t get_byte (const int32_t start_pos, const int32_t length) const
 Get a one-byte unsigned integer representing the consecutive bits from a specified position (from lowest) by a certain length. More...
 
std::string to_hex_string () const
 Transform to its hexadecimal represented by a string. More...
 
std::string to_binary_string () const
 Transform to its binary represented by a string. More...
 

Static Public Member Functions

static std::string byte_to_hex (const uint8_t value)
 Transform an integer with the size of one byte to its hexadecimal represented by a string. More...
 
static std::string byte_to_hex (const uint32_t value)
 Transform an integer with the size of 4 bytes to its hexadecimal represented by a string. More...
 
static std::string byte_to_binary (const uint8_t value)
 Transform an integer with the size of one byte to its binary represented by a string. More...
 

Detailed Description

The class of one byte, which is 8 bits. It includes some operations on one byte.

Constructor & Destructor Documentation

◆ Byte() [1/2]

apollo::drivers::canbus::Byte::Byte ( const uint8_t *  value)
explicit

Constructor which takes a pointer to a one-byte unsigned integer.

Parameters
valueThe pointer to a one-byte unsigned integer for construction.

◆ Byte() [2/2]

apollo::drivers::canbus::Byte::Byte ( const Byte value)

Constructor which takes a reference to a one-byte unsigned integer.

Parameters
valueThe reference to a one-byte unsigned integer for construction.

◆ ~Byte()

apollo::drivers::canbus::Byte::~Byte ( )
default

Desctructor.

Member Function Documentation

◆ byte_to_binary()

static std::string apollo::drivers::canbus::Byte::byte_to_binary ( const uint8_t  value)
static

Transform an integer with the size of one byte to its binary represented by a string.

Parameters
valueThe target integer to transform.
Returns
Binary representing the target integer.

◆ byte_to_hex() [1/2]

static std::string apollo::drivers::canbus::Byte::byte_to_hex ( const uint8_t  value)
static

Transform an integer with the size of one byte to its hexadecimal represented by a string.

Parameters
valueThe target integer to transform.
Returns
Hexadecimal representing the target integer.

◆ byte_to_hex() [2/2]

static std::string apollo::drivers::canbus::Byte::byte_to_hex ( const uint32_t  value)
static

Transform an integer with the size of 4 bytes to its hexadecimal represented by a string.

Parameters
valueThe target integer to transform.
Returns
Hexadecimal representing the target integer.

◆ get_byte() [1/2]

uint8_t apollo::drivers::canbus::Byte::get_byte ( ) const

Get the one-byte unsigned integer.

Returns
The one-byte unsigned integer.

◆ get_byte() [2/2]

uint8_t apollo::drivers::canbus::Byte::get_byte ( const int32_t  start_pos,
const int32_t  length 
) const

Get a one-byte unsigned integer representing the consecutive bits from a specified position (from lowest) by a certain length.

Parameters
start_posThe starting position (from lowest) of bits.
lengthThe length of the selected consecutive bits.
Returns
The one-byte unsigned integer representing the selected bits.

◆ get_byte_high_4_bits()

uint8_t apollo::drivers::canbus::Byte::get_byte_high_4_bits ( ) const

Get a one-byte unsigned integer representing the higher 4 bits.

Returns
The one-byte unsigned integer representing the higher 4 bits.

◆ get_byte_low_4_bits()

uint8_t apollo::drivers::canbus::Byte::get_byte_low_4_bits ( ) const

Get a one-byte unsigned integer representing the lower 4 bits.

Returns
The one-byte unsigned integer representing the lower 4 bits.

◆ is_bit_1()

bool apollo::drivers::canbus::Byte::is_bit_1 ( const int32_t  pos) const

Check if the bit on a specified position is one.

Parameters
posThe position of the bit to check.
Returns
If the bit on a specified position is one.

◆ set_bit_0()

void apollo::drivers::canbus::Byte::set_bit_0 ( const int32_t  pos)

Set the bit on a specified position to zero.

Parameters
posThe position of the bit to be set to zero.

◆ set_bit_1()

void apollo::drivers::canbus::Byte::set_bit_1 ( const int32_t  pos)

Set the bit on a specified position to one.

Parameters
posThe position of the bit to be set to one.

◆ set_value() [1/2]

void apollo::drivers::canbus::Byte::set_value ( const uint8_t  value)

Reset this Byte by a specified one-byte unsigned integer.

Parameters
valueThe one-byte unsigned integer to set this Byte.

◆ set_value() [2/2]

void apollo::drivers::canbus::Byte::set_value ( const uint8_t  value,
const int32_t  start_pos,
const int32_t  length 
)

Reset some consecutive bits starting from a specified position with a certain length of another one-byte unsigned integer.

Parameters
valueThe one-byte unsigned integer whose certain bits are used to set this Byte.
start_posThe starting position (from the lowest) of the bits.
lengthThe length of the consecutive bits.

◆ set_value_high_4_bits()

void apollo::drivers::canbus::Byte::set_value_high_4_bits ( const uint8_t  value)

Reset the higher 4 bits as the higher 4 bits of a specified one-byte unsigned integer.

Parameters
valueThe one-byte unsigned integer whose higher 4 bits are used to set this Byte's higher 4 bits.

◆ set_value_low_4_bits()

void apollo::drivers::canbus::Byte::set_value_low_4_bits ( const uint8_t  value)

Reset the lower 4 bits as the lower 4 bits of a specified one-byte unsigned integer.

Parameters
valueThe one-byte unsigned integer whose lower 4 bits are used to set this Byte's lower 4 bits.

◆ to_binary_string()

std::string apollo::drivers::canbus::Byte::to_binary_string ( ) const

Transform to its binary represented by a string.

Returns
Binary representing the Byte.

◆ to_hex_string()

std::string apollo::drivers::canbus::Byte::to_hex_string ( ) const

Transform to its hexadecimal represented by a string.

Returns
Hexadecimal representing the Byte.

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