LCOV - code coverage report
Current view: top level - executables/unitTest/transportConfiguration/include/transport - TransportConfiguration.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 19 19
Test Date: 2026-11-13 15:04:32 Functions: 100.0 % 7 7

            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 "busid/BusId.h"
      14              : 
      15              : #include "transport/LogicalAddress.h"
      16              : #include "transport/TransportMessage.h"
      17              : 
      18              : #include <etl/array.h>
      19              : #include <etl/span.h>
      20              : 
      21              : #include <cstdint>
      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           = ::etl::array<LogicalAddress, NUMBER_OF_ETHERNET_TESTERS>;
      35              :     using CanTesters                = ::etl::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              :     /// True if the bus uses 1-byte diagnostic addresses (i.e. not a DoIP bus).
      85              :     static bool is1ByteDiagAddressBus(uint8_t busId);
      86              : 
      87              :     static uint16_t convert2ByteAddressTo1Byte(uint16_t address);
      88              : 
      89              :     static uint16_t convert1ByteAddressTo2Byte(uint16_t address);
      90              : 
      91              :     static bool isFromTester(TransportMessage const& message);
      92              : };
      93              : 
      94              : /**
      95              :  * This function checks if the provided 16-bit address matches
      96              :  * the constant FUNCTIONAL_ALL_ISO14229.
      97              :  * \return true if they are equal and false otherwise.
      98              :  */
      99           29 : inline bool TransportConfiguration::isFunctionalAddress(uint16_t const address)
     100              : {
     101           29 :     return (FUNCTIONAL_ALL_ISO14229 == address);
     102              : }
     103              : 
     104            7 : inline bool TransportConfiguration::is1ByteDiagAddressBus(uint8_t const busId)
     105              : {
     106              :     // Only the Ethernet/DoIP buses use 2-byte diagnostic addresses.
     107            7 :     return (busId != ::busid::ETH_0) && (busId != ::busid::ETH_1);
     108              : }
     109              : 
     110              : /**
     111              :  * This function checks if the target ID of the provided TransportMessage
     112              :  * object matches the constant FUNCTIONAL_ALL_ISO14229.
     113              :  * \return true if they are equal and false otherwise.
     114              :  */
     115           10 : inline bool TransportConfiguration::isFunctionallyAddressed(TransportMessage const& message)
     116              : {
     117           10 :     return isFunctionalAddress(message.getTargetId());
     118              : }
     119              : 
     120              : inline bool TransportConfiguration::is2ByteTesterAddress(uint16_t const address)
     121              : {
     122              :     return addressfinder::is2ByteAddressIn(address, TESTER_ADDRESS_RANGE_ETHERNET)
     123              :            || addressfinder::is2ByteAddressIn(address, TESTER_ADDRESS_RANGE_CAN);
     124              : }
     125              : 
     126            5 : inline bool TransportConfiguration::is1ByteTesterAddress(uint16_t const address)
     127              : {
     128            5 :     return addressfinder::is1ByteAddressIn(address, TESTER_ADDRESS_RANGE_ETHERNET)
     129            5 :            || addressfinder::is1ByteAddressIn(address, TESTER_ADDRESS_RANGE_CAN);
     130              : }
     131              : 
     132              : /**
     133              :  * This function checks if the provided 2-byte address is a supported tester address.
     134              :  *
     135              :  * \return true if it is part of the bounded external tester set and false otherwise.
     136              :  */
     137              : inline bool TransportConfiguration::isTesterAddress(uint16_t const address)
     138              : {
     139              :     return is2ByteTesterAddress(address);
     140              : }
     141              : 
     142            2 : inline uint16_t TransportConfiguration::convert2ByteAddressTo1Byte(uint16_t const address)
     143              : {
     144            2 :     if ((address & 0xFF00U) != 0x0E00U)
     145              :     {
     146            1 :         return address;
     147              :     }
     148              : 
     149            1 :     return LogicalAddressConverterUT::convert2ByteAddressTo1Byte(address);
     150              : }
     151              : 
     152            5 : inline uint16_t TransportConfiguration::convert1ByteAddressTo2Byte(uint16_t const address)
     153              : {
     154            5 :     if ((address & 0xFFF0U) != 0x00F0U)
     155              :     {
     156            3 :         return address;
     157              :     }
     158              : 
     159            2 :     return LogicalAddressConverterUT::convert1ByteAddressTo2Byte(address);
     160              : }
     161              : 
     162              : /**
     163              :  * This function determines if the source ID of the provided TransportMessage object
     164              :  * corresponds to a 1-byte tester address.
     165              :  *
     166              :  * \return true if it does and false otherwise.
     167              :  */
     168            5 : inline bool TransportConfiguration::isFromTester(TransportMessage const& message)
     169              : {
     170            5 :     return is1ByteTesterAddress(message.getSourceId());
     171              : }
     172              : 
     173              : // Explicit template specialization declaration (definition in TransportConfiguration.cpp)
     174              : template<>
     175              : etl::array<::etl::span<LogicalAddress const>, TransportConfiguration::NUMBER_OF_ADDRESS_LISTS> const
     176              :     TransportConfiguration::LogicalAddressConverterUT::TESTER_ADDRESS_LISTS;
     177              : 
     178              : } // namespace transport
        

Generated by: LCOV version 2.0-1