Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2024 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 "util/RoutineControlOptionParser.h"
12 :
13 : #include <etl/unaligned_type.h>
14 :
15 : namespace uds
16 : {
17 : uint8_t
18 1 : RoutineControlOptionParser::getLogicalBlockNumberLength(uint8_t const lengthFormatIdentifier)
19 : {
20 1 : return (lengthFormatIdentifier & 0xF0U) >> 4U;
21 : }
22 :
23 1 : uint8_t RoutineControlOptionParser::getMemoryAddressLength(uint8_t const lengthFormatIdentifier)
24 : {
25 1 : return (lengthFormatIdentifier & 0xF0U) >> 4U;
26 : }
27 :
28 1 : uint8_t RoutineControlOptionParser::getMemorySizeLength(uint8_t const lengthFormatIdentifier)
29 : {
30 1 : return (lengthFormatIdentifier & 0x0FU);
31 : }
32 :
33 : uint32_t
34 5 : RoutineControlOptionParser::parseParameter(uint8_t const* const buffer, uint8_t const length)
35 : {
36 5 : switch (length)
37 : {
38 1 : case 1U:
39 : {
40 1 : return static_cast<uint32_t>(*buffer);
41 : }
42 1 : case 2U:
43 : {
44 1 : return static_cast<uint32_t>(::etl::be_uint16_t(buffer));
45 : }
46 1 : case 3U:
47 : {
48 1 : return (static_cast<uint32_t>(*buffer) << 16)
49 1 : | static_cast<uint32_t>(::etl::be_uint16_t(buffer + 1));
50 : }
51 1 : case 4U:
52 : {
53 1 : return ::etl::be_uint32_t(buffer);
54 : }
55 1 : default:
56 : {
57 1 : return 0U;
58 : }
59 : }
60 : }
61 :
62 : } // namespace uds
|