The class of one byte, which is 8 bits.
更多...
#include <byte.h>
|
| 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.
|
|
|
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.h 第 39 行定义.
◆ Byte() [1/2]
apollo::drivers::canbus::Byte::Byte |
( |
const uint8_t * |
value | ) |
|
|
explicit |
Constructor which takes a pointer to a one-byte unsigned integer.
- 参数
-
value | The pointer to a one-byte unsigned integer for construction. |
在文件 byte.cc 第 38 行定义.
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.
- 参数
-
value | The reference to a one-byte unsigned integer for construction. |
在文件 byte.cc 第 40 行定义.
40: value_(value.value_) {}
◆ ~Byte()
apollo::drivers::canbus::Byte::~Byte |
( |
| ) |
|
|
default |
◆ 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.
- 参数
-
value | The target integer to transform. |
- 返回
- Binary representing the target integer.
在文件 byte.cc 第 66 行定义.
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.
- 参数
-
value | The target integer to transform. |
- 返回
- Hexadecimal representing the target integer.
在文件 byte.cc 第 49 行定义.
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);
58 }
59 high = static_cast<uint8_t>((value >> 8) & 0xFF);
60 low = static_cast<uint8_t>(value & 0xFF);
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.
◆ 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.
- 参数
-
value | The target integer to transform. |
- 返回
- Hexadecimal representing the target integer.
在文件 byte.cc 第 42 行定义.
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.cc 第 120 行定义.
◆ 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_pos | The starting position (from lowest) of bits. |
length | The length of the selected consecutive bits. |
- 返回
- The one-byte unsigned integer representing the selected bits.
在文件 byte.cc 第 126 行定义.
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.cc 第 122 行定义.
uint8_t get_byte() const
Get the one-byte unsigned integer.
◆ 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.cc 第 124 行定义.
◆ 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.
- 参数
-
pos | The position of the bit to check. |
- 返回
- If the bit on a specified position is one.
在文件 byte.cc 第 86 行定义.
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.
- 参数
-
pos | The position of the bit to be set to zero. |
在文件 byte.cc 第 78 行定义.
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.
- 参数
-
pos | The position of the bit to be set to one. |
在文件 byte.cc 第 70 行定义.
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.
- 参数
-
value | The one-byte unsigned integer to set this Byte. |
在文件 byte.cc 第 90 行定义.
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.
- 参数
-
value | The one-byte unsigned integer whose certain bits are used to set this Byte. |
start_pos | The starting position (from the lowest) of the bits. |
length | The length of the consecutive bits. |
在文件 byte.cc 第 102 行定义.
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.
- 参数
-
value | The one-byte unsigned integer whose higher 4 bits are used to set this Byte's higher 4 bits. |
在文件 byte.cc 第 96 行定义.
96 {
98}
void set_value(const uint8_t value)
Reset this Byte by a specified one-byte unsigned integer.
◆ 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.
- 参数
-
value | The one-byte unsigned integer whose lower 4 bits are used to set this Byte's lower 4 bits. |
在文件 byte.cc 第 100 行定义.
◆ 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.cc 第 139 行定义.
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.
◆ 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.cc 第 137 行定义.
该类的文档由以下文件生成:
- modules/drivers/canbus/common/byte.h
- modules/drivers/canbus/common/byte.cc