The UDS client API provides functionality for sending diagnostic requests to UDS servers.
Basic Usage
Initialization
UDSErr_t UDSClientInit(UDSClient_t *client)
Call this once.
Sending Requests
uint16_t dids[] = {0xF190};
#define UDS_LEV_DS_EXTDS
Extended Diagnostic Session.
#define UDS_LEV_RT_HR
Hard Reset.
UDSErr_t UDSSendECUReset(UDSClient_t *client, uint8_t type)
Request ECUReset.
UDSErr_t UDSSendDiagSessCtrl(UDSClient_t *client, uint8_t mode)
Change the diagnostic session.
UDSErr_t UDSSendRDBI(UDSClient_t *client, const uint16_t *didList, const uint16_t numDataIdentifiers)
Read Data By Identifier.
Processing Responses
while (client.
state != UDS_CLIENT_IDLE) {
}
UDSErr_t UDSClientPoll(UDSClient_t *client)
Call at <5ms intervals.
Client Structure
The UDSClient_t structure contains:
- Timeouts: p2_ms, p2_star_ms - Server response timing parameters
- Transport: tp - Pointer to ISO-TP transport layer
- State: state - Current client state
- Options: options, defaultOptions - Request behavior flags
- Callback: fn, fn_data - Event handler and user data
- Buffers: recv_buf, send_buf - Internal message buffers
Request Options
Combine these flags when sending requests:
Example:
UDSErr_t UDSSendTesterPresent(UDSClient_t *client)
What's up?
#define UDS_SUPPRESS_POS_RESP
set the suppress positive response bit
#define UDS_FUNCTIONAL
send the request as a functional request
Event-Driven API
The client uses callbacks to notify the application of events:
switch (evt) {
break;
break;
printf("Error: %s\n", UDSErrToStr(*err));
break;
}
return 0;
}
client.
fn = client_callback;
@ UDS_EVT_ResponseReceived
UDSErr_t
Error Codes, including NRCs defined by the standard.
int(*) fn(struct UDSClient *client, UDSEvent_t evt, void *ev_data)
Unpacking Responses
Helper functions are provided to parse complex responses:
{.did = 0xF190, .data = buffer, .len = sizeof(buffer)}
};
UDSErr_t UDSUnpackSecurityAccessResponse(const UDSClient_t *client, struct SecurityAccessResponse *resp)
Parse server's response to SecurityAccess.
UDSErr_t UDSUnpackRDBIResponse(UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars)
Parse server's response to RDBI.
UDSErr_t UDSUnpackRoutineControlResponse(const UDSClient_t *client, struct RoutineControlResponse *resp)
Parse server's response to RoutineControl.
UDSErr_t UDSUnpackRequestDownloadResponse(const UDSClient_t *client, struct RequestDownloadResponse *resp)
Parse server's response to RequestDownload.
Request download response structure.
Routine control response structure.
Security access response structure.
Read data by identifier variable structure.
Some configuration options are set at compile-time. See : Compile-Time Configuration.