1 // Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #ifndef VSOMEIP_V3_TP_HPP_
7 #define VSOMEIP_V3_TP_HPP_
8 
9 #include <cstdint>
10 #include <vector>
11 #include <utility>
12 #include <memory>
13 
14 #include <vsomeip/enumeration_types.hpp>
15 
16 #include "buffer.hpp"
17 
18 namespace vsomeip_v3 {
19 namespace tp {
20 
21 #define VSOMEIP_TP_HEADER_SIZE       4
22 #define VSOMEIP_TP_HEADER_POS_MIN   16
23 #define VSOMEIP_TP_HEADER_POS_MAX   19
24 #define VSOMEIP_TP_PAYLOAD_POS      20
25 
26 // 28 bit length + 3 bit reserved + 1 bit more segments
27 typedef std::uint32_t tp_header_t;
28 typedef std::uint8_t tp_message_type_t;
29 typedef std::vector<message_buffer_ptr_t> tp_split_messages_t;
30 
31 const std::uint8_t TP_FLAG = 0x20;
32 
33 class tp {
34 public:
get_offset(tp_header_t _tp_header)35     static inline length_t get_offset(tp_header_t _tp_header) {
36         return _tp_header & 0xfffffff0;
37     };
more_segments(tp_header_t _tp_header)38     static inline bool more_segments(tp_header_t _tp_header) {
39         return _tp_header & 0x1;
40     };
tp_flag_is_set(tp_message_type_t _msg_type)41     static inline bool tp_flag_is_set(tp_message_type_t _msg_type) {
42         return _msg_type & TP_FLAG;
43     };
tp_flag_set(message_type_e _msg_type)44     static inline tp_message_type_t tp_flag_set(message_type_e _msg_type) {
45         return static_cast<tp_message_type_t>(_msg_type) | TP_FLAG;
46     }
tp_flag_unset(tp_message_type_t _msg_type)47     static inline message_type_e tp_flag_unset(tp_message_type_t _msg_type) {
48         return static_cast<message_type_e>(_msg_type & ~TP_FLAG);
49     }
50 
51     static tp_split_messages_t tp_split_message(
52             const std::uint8_t * const _data, std::uint32_t _size);
53 
54     static const std::uint16_t tp_max_segment_length_;
55 };
56 
57 } // namespace tp
58 } // namespace vsomeip_v3
59 
60 #endif // VSOMEIP_V3_TP_HPP_
61