Apollo 10.0
自动驾驶开放平台
byte.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22#pragma once
23
24#include <string>
25
30namespace apollo {
31namespace drivers {
32namespace canbus {
33
39class Byte {
40 public:
45 explicit Byte(const uint8_t *value);
46
51 Byte(const Byte &value);
52
56 ~Byte() = default;
57
64 static std::string byte_to_hex(const uint8_t value);
65
72 static std::string byte_to_hex(const uint32_t value);
73
80 static std::string byte_to_binary(const uint8_t value);
81
86 void set_bit_1(const int32_t pos);
87
92 void set_bit_0(const int32_t pos);
93
99 bool is_bit_1(const int32_t pos) const;
100
105 void set_value(const uint8_t value);
106
113 void set_value_high_4_bits(const uint8_t value);
114
121 void set_value_low_4_bits(const uint8_t value);
122
131 void set_value(const uint8_t value, const int32_t start_pos,
132 const int32_t length);
133
138 uint8_t get_byte() const;
139
144 uint8_t get_byte_high_4_bits() const;
145
150 uint8_t get_byte_low_4_bits() const;
151
159 uint8_t get_byte(const int32_t start_pos, const int32_t length) const;
160
165 std::string to_hex_string() const;
166
171 std::string to_binary_string() const;
172
173 private:
174 uint8_t *value_;
175};
176
177} // namespace canbus
178} // namespace drivers
179} // namespace apollo
The class of one byte, which is 8 bits.
Definition byte.h:39
void set_bit_1(const int32_t pos)
Set the bit on a specified position to one.
Definition byte.cc:70
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
uint8_t get_byte_low_4_bits() const
Get a one-byte unsigned integer representing the lower 4 bits.
Definition byte.cc:124
std::string to_hex_string() const
Transform to its hexadecimal represented by a string.
Definition byte.cc:137
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.
Definition byte.cc:100
bool is_bit_1(const int32_t pos) const
Check if the bit on a specified position is one.
Definition byte.cc:86
void set_bit_0(const int32_t pos)
Set the bit on a specified position to zero.
Definition byte.cc:78
uint8_t get_byte_high_4_bits() const
Get a one-byte unsigned integer representing the higher 4 bits.
Definition byte.cc:122
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.
Definition byte.cc:96
std::string to_binary_string() const
Transform to its binary represented by a string.
Definition byte.cc:139
void set_value(const uint8_t value)
Reset this Byte by a specified one-byte unsigned integer.
Definition byte.cc:90
~Byte()=default
Desctructor.
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
uint8_t get_byte() const
Get the one-byte unsigned integer.
Definition byte.cc:120
class register implement
Definition arena_queue.h:37