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 : #include "someip/EventMessage.h"
12 :
13 : #include <etl/algorithm.h>
14 :
15 : namespace someip
16 : {
17 : namespace internal
18 : {
19 151 : EventMessage::EventMessage() { etl::fill(etl::begin(_buffer), etl::end(_buffer), 0x00U); }
20 :
21 31 : void EventMessage::clear()
22 : {
23 31 : _pduList.clear();
24 31 : _destination.clear();
25 31 : _sendTime = 0U;
26 31 : _bufferOffset = 0U;
27 31 : _localPort = 0U;
28 31 : _proto = 0U;
29 31 : }
30 :
31 441 : bool EventMessage::isInitialized() const { return _destination.isSet(); }
32 :
33 19 : void EventMessage::init(
34 : ::ip::IPEndpoint const& destination, uint16_t const localPort, uint8_t const proto)
35 : {
36 19 : clear();
37 :
38 19 : _destination = destination;
39 19 : _localPort = localPort;
40 19 : _proto = proto;
41 19 : }
42 :
43 139 : bool EventMessage::isMatching(
44 : ::ip::IPEndpoint const& destination, uint16_t const localPort, uint8_t const proto) const
45 : {
46 139 : return (_destination == destination) && (_localPort == localPort) && (_proto == proto);
47 : }
48 :
49 3 : bool EventMessage::isFull() const { return _pduList.full(); }
50 :
51 3 : bool EventMessage::hasPdu(uint32_t const pdu) const { return _pduList.contains(pdu); }
52 :
53 20 : void EventMessage::addPdu(uint32_t const pdu)
54 : {
55 20 : if (!_pduList.full())
56 : {
57 20 : (void)_pduList.insert(pdu);
58 : }
59 20 : }
60 :
61 23 : ::etl::span<uint8_t> EventMessage::getBuffer()
62 : {
63 23 : return ::etl::span<uint8_t>(_buffer, BUFFER_SIZE);
64 : }
65 :
66 26 : uint16_t EventMessage::getBufferOffset() const { return _bufferOffset; }
67 :
68 20 : void EventMessage::incBufferOffset(uint16_t const length) { _bufferOffset += length; }
69 :
70 3 : ::ip::IPEndpoint const& EventMessage::getDestination() const { return _destination; }
71 :
72 3 : uint16_t EventMessage::getLocalPort() const { return _localPort; }
73 :
74 3 : uint8_t EventMessage::getProto() const { return _proto; }
75 :
76 106 : uint32_t EventMessage::getSendTime() const { return _sendTime; }
77 :
78 20 : void EventMessage::adjustSendTime(uint32_t const time)
79 : {
80 20 : if ((_sendTime == 0U) || (_sendTime > time))
81 : {
82 19 : _sendTime = time;
83 : }
84 20 : }
85 :
86 : } // namespace internal
87 :
88 : } // namespace someip
|