9 uint8_t sid = request[0];
18 std::cerr <<
"UdsMock: Request length " << request.size()
19 <<
" out of bounds for service 0x" << std::hex << static_cast<int>(service) << std::dec
25 auto it = m_handlers.find(sid);
26 if (it != m_handlers.end() && it->second) {
27 resp = it->second->handle(request);
32 auto rspSize = resp.second.size() + 1;
33 if (rspSize < desc->minRspLength || rspSize > desc->
maxRspLength) {
34 std::cerr <<
"UdsMock: Response length " << resp.second.size()
35 <<
" out of bounds for service 0x" << std::hex << static_cast<int>(service) << std::dec
40 return makeResponse(request, resp.first, resp.second);
45 uint8_t sessionType = req[1];
46 return handler(sessionType);
52 uint8_t resetType = req[1];
53 return handler(resetType);
59 uint16_t did = (
static_cast<uint16_t
>(req[1]) << 8) | req[2];
66 uint16_t did = (
static_cast<uint16_t
>(req[1]) << 8) | req[2];
67 return handler(did,
ByteArray(req.data() + 3, req.size() - 3));
73 uint8_t subFunction = req[1];
74 return handler(subFunction);
void registerDiagnosticSessionControlHandler(std::function< UdsResponse(uint8_t sessionType)> handler)
void registerReadDataByIdentifierHandler(std::function< UdsResponse(uint16_t did)> handler)
void registerWriteDataByIdentifierHandler(std::function< UdsResponse(uint16_t did, ByteArray value)> handler)
void registerService(UdsService serviceId, IUdsServiceHandlerPtr handler)
void registerECUResetHandler(std::function< UdsResponse(uint8_t resetType)> handler)
void registerTesterPresentHandler(std::function< UdsResponse(uint8_t subFunction)> handler)
ByteArray handleDiagnosticRequest(const ByteArray &request) const
@ IncorrectMessageLengthOrInvalidFormat
@ GeneralProgrammingFailure
const UdsServiceDescriptor * findServiceDescriptor(UdsService sid)
Find service descriptor by service ID.
std::pair< UdsResponseCode, ByteArray > UdsResponse
@ DiagnosticSessionControl
A dynamic array of bytes with utility methods for network protocol handling.