Apollo  6.0
Open source self driving car software
byte.h
Go to the documentation of this file.
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 
30 namespace apollo {
31 namespace drivers {
32 namespace canbus {
33 
39 class 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
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...
void set_bit_1(const int32_t pos)
Set the bit on a specified position to one.
bool is_bit_1(const int32_t pos) const
Check if the bit on a specified position is one.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
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.
std::string to_hex_string() const
Transform to its hexadecimal represented by a string.
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.
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.
The class of one byte, which is 8 bits. It includes some operations on one byte.
Definition: byte.h:39
std::string to_binary_string() const
Transform to its binary represented by a string.
Byte(const uint8_t *value)
Constructor which takes a pointer to a one-byte unsigned integer.
uint8_t get_byte_low_4_bits() const
Get a one-byte unsigned integer representing the lower 4 bits.
void set_value(const uint8_t value)
Reset this Byte by a specified one-byte unsigned integer.
~Byte()=default
Desctructor.
apollo::cyber::base::std 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.
void set_bit_0(const int32_t pos)
Set the bit on a specified position to zero.