Autoware.Auto
socket_can_id.hpp
Go to the documentation of this file.
1 // Copyright 2019 the Autoware Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
18 #ifndef SOCKETCAN__SOCKET_CAN_ID_HPP_
19 #define SOCKETCAN__SOCKET_CAN_ID_HPP_
20 
21 #include <common/types.hpp>
23 
24 #include <stdexcept>
25 
28 
29 namespace autoware
30 {
31 namespace drivers
32 {
33 namespace socketcan
34 {
35 
36 constexpr std::size_t MAX_DATA_LENGTH = 8U;
38 class SOCKETCAN_PUBLIC SocketCanTimeout : public std::runtime_error
39 {
40 public:
41  explicit SocketCanTimeout(const char8_t * const what)
42  : runtime_error{what} {}
43 }; // class SocketCanTimeout
44 
45 enum class FrameType : uint32_t
46 {
47  DATA,
48  ERROR,
49  REMOTE
50  // SocketCan doesn't support Overload frame directly?
51 }; // enum class FrameType
52 
54 struct StandardFrame_ {};
55 //lint -e{1502} NOLINT It's a tag
58 struct ExtendedFrame_ {};
59 //lint -e{1502} NOLINT It's a tag
61 
65 {
66 public:
67  using IdT = uint32_t;
68  using LengthT = uint32_t;
69  // Default constructor: standard data frame with id 0
70  CanId() = default;
72  explicit CanId(const IdT raw_id, const LengthT data_length = 0U);
75  CanId(const IdT id, FrameType type, StandardFrame_);
78  CanId(const IdT id, FrameType type, ExtendedFrame_);
79 
81  CanId & standard() noexcept;
83  CanId & extended() noexcept;
85  CanId & error_frame() noexcept;
87  CanId & remote_frame() noexcept;
89  CanId & data_frame() noexcept;
91  CanId & frame_type(const FrameType type);
94  CanId & identifier(const IdT id);
95 
97  IdT identifier() const noexcept;
99  IdT get() const noexcept;
101  bool8_t is_extended() const noexcept;
104  FrameType frame_type() const;
106  LengthT length() const noexcept;
107 
108 private:
109  SOCKETCAN_LOCAL CanId(const IdT id, FrameType type, bool8_t is_extended);
110 
111  IdT m_id{};
112  LengthT m_data_length{};
113 }; // class CanId
114 } // namespace socketcan
115 } // namespace drivers
116 } // namespace autoware
117 
118 #endif // SOCKETCAN__SOCKET_CAN_ID_HPP_
visibility_control.hpp
types.hpp
This file includes common type definition.
autoware::drivers::socketcan::StandardFrame_
Tag for standard frame.
Definition: socket_can_id.hpp:54
autoware::drivers::socketcan::MAX_DATA_LENGTH
constexpr std::size_t MAX_DATA_LENGTH
Definition: socket_can_id.hpp:36
SOCKETCAN_PUBLIC
#define SOCKETCAN_PUBLIC
Definition: drivers/socketcan/include/socketcan/visibility_control.hpp:44
autoware::drivers::socketcan::SocketCanTimeout::SocketCanTimeout
SocketCanTimeout(const char8_t *const what)
Definition: socket_can_id.hpp:41
autoware::drivers::socketcan::CanId::IdT
uint32_t IdT
Definition: socket_can_id.hpp:67
SOCKETCAN_LOCAL
#define SOCKETCAN_LOCAL
Definition: drivers/socketcan/include/socketcan/visibility_control.hpp:45
autoware::drivers::socketcan::ExtendedFrame_
Tag for extended frame.
Definition: socket_can_id.hpp:58
autoware::common::types::char8_t
char char8_t
Definition: types.hpp:34
autoware::common::types::bool8_t
bool bool8_t
Definition: types.hpp:33
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::drivers::socketcan::SocketCanTimeout
Special error for timeout.
Definition: socket_can_id.hpp:38
autoware::drivers::socketcan::FrameType::DATA
@ DATA
autoware::drivers::socketcan::ExtendedFrame
constexpr ExtendedFrame_ ExtendedFrame
Definition: socket_can_id.hpp:60
autoware::drivers::socketcan::FrameType
FrameType
Definition: socket_can_id.hpp:45
autoware::drivers::socketcan::FrameType::ERROR
@ ERROR
autoware::drivers::socketcan::FrameType::REMOTE
@ REMOTE
autoware::drivers::socketcan::CanId
Definition: socket_can_id.hpp:64
autoware::drivers::socketcan::CanId::LengthT
uint32_t LengthT
Definition: socket_can_id.hpp:68
autoware::drivers::socketcan::StandardFrame
constexpr StandardFrame_ StandardFrame
Definition: socket_can_id.hpp:56