Apollo 10.0
自动驾驶开放平台
apollo::drivers::canbus::Byte类 参考

The class of one byte, which is 8 bits. 更多...

#include <byte.h>

apollo::drivers::canbus::Byte 的协作图:

Public 成员函数

 Byte (const uint8_t *value)
 Constructor which takes a pointer to a one-byte unsigned integer.
 
 Byte (const Byte &value)
 Constructor which takes a reference to a one-byte unsigned integer.
 
 ~Byte ()=default
 Desctructor.
 
void set_bit_1 (const int32_t pos)
 Set the bit on a specified position to one.
 
void set_bit_0 (const int32_t pos)
 Set the bit on a specified position to zero.
 
bool is_bit_1 (const int32_t pos) const
 Check if the bit on a specified position is one.
 
void set_value (const uint8_t value)
 Reset this Byte by a specified one-byte unsigned integer.
 
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.
 
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.
 
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.
 
uint8_t get_byte () const
 Get the one-byte unsigned integer.
 
uint8_t get_byte_high_4_bits () const
 Get a one-byte unsigned integer representing the higher 4 bits.
 
uint8_t get_byte_low_4_bits () const
 Get a one-byte unsigned integer representing the lower 4 bits.
 
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.
 
std::string to_hex_string () const
 Transform to its hexadecimal represented by a string.
 
std::string to_binary_string () const
 Transform to its binary represented by a string.
 

静态 Public 成员函数

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.
 
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.
 
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.
 

详细描述

The class of one byte, which is 8 bits.

It includes some operations on one byte.

在文件 byte.h39 行定义.

构造及析构函数说明

◆ Byte() [1/2]

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

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

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

在文件 byte.cc38 行定义.

38: value_(const_cast<uint8_t *>(value)) {}

◆ Byte() [2/2]

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

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

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

在文件 byte.cc40 行定义.

40: value_(value.value_) {}

◆ ~Byte()

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

Desctructor.

成员函数说明

◆ byte_to_binary()

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.

参数
valueThe target integer to transform.
返回
Binary representing the target integer.

在文件 byte.cc66 行定义.

66 {
67 return std::bitset<8 * sizeof(uint8_t)>(value).to_string();
68}

◆ byte_to_hex() [1/2]

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.

参数
valueThe target integer to transform.
返回
Hexadecimal representing the target integer.

在文件 byte.cc49 行定义.

49 {
50 uint8_t high;
51 uint8_t low;
52 std::string result = "";
53 if (value > 0xFF) {
54 high = static_cast<uint8_t>((value >> 24) & 0xFF);
55 low = static_cast<uint8_t>((value >> 16) & 0xFF);
56 result += byte_to_hex(high);
57 result += byte_to_hex(low);
58 }
59 high = static_cast<uint8_t>((value >> 8) & 0xFF);
60 low = static_cast<uint8_t>(value & 0xFF);
61 result += byte_to_hex(high);
62 result += byte_to_hex(low);
63 return result;
64}
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.
Definition byte.cc:42

◆ byte_to_hex() [2/2]

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.

参数
valueThe target integer to transform.
返回
Hexadecimal representing the target integer.

在文件 byte.cc42 行定义.

42 {
43 static const char HEX[] = "0123456789ABCDEF";
44 uint8_t high = static_cast<uint8_t>(value >> 4);
45 uint8_t low = static_cast<uint8_t>(value & 0x0F);
46 return {HEX[high], HEX[low]};
47}

◆ get_byte() [1/2]

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

Get the one-byte unsigned integer.

返回
The one-byte unsigned integer.

在文件 byte.cc120 行定义.

120{ return *value_; }

◆ 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.

参数
start_posThe starting position (from lowest) of bits.
lengthThe length of the selected consecutive bits.
返回
The one-byte unsigned integer representing the selected bits.

在文件 byte.cc126 行定义.

126 {
127 if (start_pos > BYTE_LENGTH - 1 || start_pos < 0 || length < 1) {
128 return 0x00;
129 }
130 int32_t end_pos = std::min(start_pos + length - 1, BYTE_LENGTH - 1);
131 int32_t real_len = end_pos + 1 - start_pos;
132 uint8_t result = static_cast<uint8_t>(*value_ >> start_pos);
133 result &= RANG_MASK_1_L[real_len - 1];
134 return result;
135}

◆ 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.

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

在文件 byte.cc122 行定义.

122{ return get_byte(4, 4); }
uint8_t get_byte() const
Get the one-byte unsigned integer.
Definition byte.cc:120

◆ 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.

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

在文件 byte.cc124 行定义.

124{ return get_byte(0, 4); }

◆ 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.

参数
posThe position of the bit to check.
返回
If the bit on a specified position is one.

在文件 byte.cc86 行定义.

86 {
87 return pos >= 0 && pos < BYTE_LENGTH && ((*value_ >> pos) % 2 == 1);
88}

◆ set_bit_0()

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

Set the bit on a specified position to zero.

参数
posThe position of the bit to be set to zero.

在文件 byte.cc78 行定义.

78 {
79 static const uint8_t BIT_MASK_0[] = {0xFE, 0xFD, 0xFB, 0xF7,
80 0xEF, 0xDF, 0xBF, 0x7F};
81 if (pos >= 0 && pos < BYTE_LENGTH) {
82 *value_ &= BIT_MASK_0[pos];
83 }
84}

◆ set_bit_1()

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

Set the bit on a specified position to one.

参数
posThe position of the bit to be set to one.

在文件 byte.cc70 行定义.

70 {
71 static const uint8_t BIT_MASK_1[] = {0x01, 0x02, 0x04, 0x08,
72 0x10, 0x20, 0x40, 0x80};
73 if (pos >= 0 && pos < BYTE_LENGTH) {
74 *value_ |= BIT_MASK_1[pos];
75 }
76}

◆ 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.

参数
valueThe one-byte unsigned integer to set this Byte.

在文件 byte.cc90 行定义.

90 {
91 if (value_ != nullptr) {
92 *value_ = value;
93 }
94}

◆ 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.

参数
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.

在文件 byte.cc102 行定义.

103 {
104 if (start_pos > BYTE_LENGTH - 1 || start_pos < 0 || length < 1) {
105 return;
106 }
107 int32_t end_pos = std::min(start_pos + length - 1, BYTE_LENGTH - 1);
108 int32_t real_len = end_pos + 1 - start_pos;
109 uint8_t current_value_low = 0x00;
110 if (start_pos > 0) {
111 current_value_low = *value_ & RANG_MASK_1_L[start_pos - 1];
112 }
113 uint8_t current_value_high = *value_ & RANG_MASK_0_L[end_pos];
114 uint8_t middle_value = value & RANG_MASK_1_L[real_len - 1];
115 middle_value = static_cast<uint8_t>(middle_value << start_pos);
116 *value_ = static_cast<uint8_t>(current_value_high + middle_value +
117 current_value_low);
118}

◆ 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.

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

在文件 byte.cc96 行定义.

96 {
97 set_value(value, 4, 4);
98}
void set_value(const uint8_t value)
Reset this Byte by a specified one-byte unsigned integer.
Definition byte.cc:90

◆ 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.

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

在文件 byte.cc100 行定义.

100{ set_value(value, 0, 4); }

◆ to_binary_string()

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

Transform to its binary represented by a string.

返回
Binary representing the Byte.

在文件 byte.cc139 行定义.

139{ return byte_to_binary(*value_); }
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.
Definition byte.cc:66

◆ to_hex_string()

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

Transform to its hexadecimal represented by a string.

返回
Hexadecimal representing the Byte.

在文件 byte.cc137 行定义.

137{ return byte_to_hex(*value_); }

该类的文档由以下文件生成: