Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #pragma once
12 :
13 : #include "someip/ITpListener.h"
14 : #include "someip/SomeIpMessage.h"
15 :
16 : #include <etl/array.h>
17 : #include <etl/span.h>
18 :
19 : #include <cstdint>
20 :
21 : namespace someip
22 : {
23 : /**
24 : * Implementation of a TP receiver.
25 : */
26 : class TpReceiver
27 : {
28 : public:
29 : enum class TpResult : uint8_t
30 : {
31 : TP_OK,
32 : TP_PENDING,
33 : TP_ERROR
34 : };
35 :
36 : bool isActive() const;
37 :
38 : bool isExpired(uint32_t time) const;
39 :
40 : bool isMatching(NetworkChannel const& channel, SomeIpMessage const& message) const;
41 :
42 : void start(NetworkChannel& channel, SomeIpMessage const& message, ITpListener& listener);
43 :
44 : void stop();
45 :
46 : TpResult
47 : receive(NetworkChannel const& channel, SomeIpMessage const& message, uint32_t timestamp);
48 :
49 : protected:
50 22 : explicit TpReceiver(::etl::span<uint8_t> const& buffer) : _buffer(buffer) {}
51 :
52 : private:
53 : ::etl::span<uint8_t> _buffer;
54 : NetworkChannel* _pChannel = nullptr;
55 :
56 : ITpListener* _pListener = nullptr;
57 : uint32_t _timestamp = 0;
58 :
59 : size_t _totalPayloadLength = 0;
60 : size_t _receivedPayloadLength = 0;
61 : };
62 :
63 : namespace declare
64 : {
65 : template<size_t BufferSize>
66 : class TpReceiver : public ::someip::TpReceiver
67 : {
68 : public:
69 18 : TpReceiver() : ::someip::TpReceiver(_buffer), _buffer() {}
70 :
71 : private:
72 : ::etl::array<uint8_t, BufferSize> _buffer;
73 : };
74 : } // namespace declare
75 : } // namespace someip
|