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 "transport/LogicalAddress.h"
14 : #include "transport/TransportMessage.h"
15 :
16 : #include <etl/array.h>
17 : #include <etl/span.h>
18 :
19 : #include <array>
20 :
21 : #include <platform/estdint.h>
22 :
23 : namespace transport
24 : {
25 : class TransportConfiguration
26 : {
27 : public:
28 : TransportConfiguration() = delete;
29 :
30 : static constexpr size_t NUMBER_OF_ETHERNET_TESTERS = 3;
31 : static constexpr size_t NUMBER_OF_CAN_TESTERS = 2;
32 : static constexpr size_t NUMBER_OF_ADDRESS_LISTS = 2;
33 :
34 : using EthernetTesters = std::array<LogicalAddress, NUMBER_OF_ETHERNET_TESTERS>;
35 : using CanTesters = std::array<LogicalAddress, NUMBER_OF_CAN_TESTERS>;
36 : using LogicalAddressConverterUT = LogicalAddressConverter<NUMBER_OF_ADDRESS_LISTS>;
37 :
38 : static constexpr EthernetTesters TESTER_ADDRESS_RANGE_ETHERNET
39 : = {{{0x0ECDU, 0x00F0U}, {0x0E12U, 0x00F1U}, {0x0EFFU, 0x00F2U}}};
40 : static constexpr CanTesters TESTER_ADDRESS_RANGE_CAN
41 : = {{{0x0E10U, 0x00F3U}, {0x0E01U, 0x00F4U}}};
42 :
43 : /**
44 : * Functional addressing
45 : */
46 : static uint16_t const FUNCTIONAL_ALL_ISO14229 = 0x00DFU;
47 :
48 : enum
49 : {
50 : INVALID_DIAG_ADDRESS = 0xFFU
51 : };
52 :
53 : /**
54 : * Maximum payload size for functionally addressed messages
55 : */
56 : static uint16_t const MAX_FUNCTIONAL_MESSAGE_PAYLOAD_SIZE = 6U;
57 :
58 : /**
59 : * Buffer size for diagnostic payload
60 : */
61 : static uint16_t const DIAG_PAYLOAD_SIZE = 4095U;
62 :
63 : /**
64 : * Number of full size transport messages
65 : */
66 : static uint8_t const NUMBER_OF_FULL_SIZE_TRANSPORT_MESSAGES = 5U;
67 :
68 : /**
69 : * Maximum number of transport messages
70 : */
71 : static uint8_t const MAXIMUM_NUMBER_OF_TRANSPORT_MESSAGES
72 : = NUMBER_OF_FULL_SIZE_TRANSPORT_MESSAGES * 8U;
73 :
74 : static bool isFunctionalAddress(uint16_t address);
75 :
76 : static bool isFunctionallyAddressed(TransportMessage const& message);
77 :
78 : static bool is2ByteTesterAddress(uint16_t address);
79 :
80 : static bool is1ByteTesterAddress(uint16_t address);
81 :
82 : static bool isTesterAddress(uint16_t address);
83 :
84 : static uint16_t convert2ByteAddressTo1Byte(uint16_t address);
85 :
86 : static uint16_t convert1ByteAddressTo2Byte(uint16_t address);
87 :
88 : static bool isFromTester(TransportMessage const& message);
89 : };
90 :
91 : /**
92 : * This function checks if the provided 16-bit address matches
93 : * the constant FUNCTIONAL_ALL_ISO14229.
94 : * \return true if they are equal and false otherwise.
95 : */
96 29 : inline bool TransportConfiguration::isFunctionalAddress(uint16_t const address)
97 : {
98 29 : return (FUNCTIONAL_ALL_ISO14229 == address);
99 : }
100 :
101 : /**
102 : * This function checks if the target ID of the provided TransportMessage
103 : * object matches the constant FUNCTIONAL_ALL_ISO14229.
104 : * \return true if they are equal and false otherwise.
105 : */
106 10 : inline bool TransportConfiguration::isFunctionallyAddressed(TransportMessage const& message)
107 : {
108 10 : return isFunctionalAddress(message.getTargetId());
109 : }
110 :
111 : inline bool TransportConfiguration::is2ByteTesterAddress(uint16_t const address)
112 : {
113 : return addressfinder::is2ByteAddressIn(address, TESTER_ADDRESS_RANGE_ETHERNET)
114 : || addressfinder::is2ByteAddressIn(address, TESTER_ADDRESS_RANGE_CAN);
115 : }
116 :
117 5 : inline bool TransportConfiguration::is1ByteTesterAddress(uint16_t const address)
118 : {
119 5 : return addressfinder::is1ByteAddressIn(address, TESTER_ADDRESS_RANGE_ETHERNET)
120 5 : || addressfinder::is1ByteAddressIn(address, TESTER_ADDRESS_RANGE_CAN);
121 : }
122 :
123 : /**
124 : * This function checks if the provided 2-byte address is a supported tester address.
125 : *
126 : * \return true if it is part of the bounded external tester set and false otherwise.
127 : */
128 : inline bool TransportConfiguration::isTesterAddress(uint16_t const address)
129 : {
130 : return is2ByteTesterAddress(address);
131 : }
132 :
133 2 : inline uint16_t TransportConfiguration::convert2ByteAddressTo1Byte(uint16_t const address)
134 : {
135 2 : if ((address & 0xFF00U) != 0x0E00U)
136 : {
137 1 : return address;
138 : }
139 :
140 1 : return LogicalAddressConverterUT::convert2ByteAddressTo1Byte(address);
141 : }
142 :
143 5 : inline uint16_t TransportConfiguration::convert1ByteAddressTo2Byte(uint16_t const address)
144 : {
145 5 : if ((address & 0xFFF0U) != 0x00F0U)
146 : {
147 3 : return address;
148 : }
149 :
150 2 : return LogicalAddressConverterUT::convert1ByteAddressTo2Byte(address);
151 : }
152 :
153 : /**
154 : * This function determines if the source ID of the provided TransportMessage object
155 : * corresponds to a 1-byte tester address.
156 : *
157 : * \return true if it does and false otherwise.
158 : */
159 5 : inline bool TransportConfiguration::isFromTester(TransportMessage const& message)
160 : {
161 5 : return is1ByteTesterAddress(message.getSourceId());
162 : }
163 :
164 : // Explicit template specialization declaration (definition in TransportConfiguration.cpp)
165 : template<>
166 : etl::array<::etl::span<LogicalAddress const>, TransportConfiguration::NUMBER_OF_ADDRESS_LISTS> const
167 : TransportConfiguration::LogicalAddressConverterUT::TESTER_ADDRESS_LISTS;
168 :
169 : } // namespace transport
|