libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
UdsServices.h
Go to the documentation of this file.
1 #ifndef UDSSERVICES_H
2 #define UDSSERVICES_H
3 
4 #include <type_traits>
5 #include <utility>
6 #include <array>
7 #include <cstdint>
8 
9 
10 namespace doip::uds {
11 
12 enum class UdsService : uint8_t {
14  ECUReset = 0x11,
15  SecurityAccess = 0x27,
16  CommunicationControl = 0x28,
17  TesterPresent = 0x3E,
20  ControlDTCSetting = 0x85,
21  ResponseOnEvent = 0x86,
22  LinkControl = 0x87,
23  ReadDataByIdentifier = 0x22,
24  ReadMemoryByAddress = 0x23,
28  WriteDataByIdentifier = 0x2E,
29  WriteMemoryByAddress = 0x3D,
31  ReadDTCInformation = 0x19,
32 };
33 
34 using uds_length = uint16_t;
41 };
42 
44 
45 constexpr std::array<UdsServiceDescriptor, 19> UDS_SERVICE_DESCRIPTORS = {{
47  { UdsService::ECUReset, 2, 2, 2, 2 },
50  { UdsService::TesterPresent, 2, 2, 2, 2 },
65 }};
66 
67 /**
68  * @brief Find service descriptor by service ID
69  *
70  * @param sid the UDS service ID
71  * @return const UdsServiceDescriptor* the service descriptor or nullptr if not found
72  */
74  auto it = std::find_if(UDS_SERVICE_DESCRIPTORS.begin(), UDS_SERVICE_DESCRIPTORS.end(),
75  [sid](const UdsServiceDescriptor& desc) {
76  return desc.service == sid;
77  });
78  if (it != UDS_SERVICE_DESCRIPTORS.end()) {
79  return &(*it);
80  }
81  return nullptr;
82 }
83 
84 } // namespace doip::uds
85 
86 #endif /* UDSSERVICES_H */
uint16_t uds_length
Definition: UdsServices.h:34
constexpr uds_length MAX_UDS_MESSAGE_LENGTH
Definition: UdsServices.h:43
const UdsServiceDescriptor * findServiceDescriptor(UdsService sid)
Find service descriptor by service ID.
Definition: UdsServices.h:73
constexpr std::array< UdsServiceDescriptor, 19 > UDS_SERVICE_DESCRIPTORS
Definition: UdsServices.h:45