iso14229 0.9.0
ISO14229-1 (UDS) C Library
Loading...
Searching...
No Matches
UDS Client

The UDS client API provides functionality for sending diagnostic requests to UDS servers.

Basic Usage

Initialization

UDSClient_t client;
UDSTp_t *transport = /* initialize your transport */;
UDSClientInit(&client);
client.tp = transport;
UDS client structure.
Definition iso14229.h:729
UDSTp_t * tp
Definition iso14229.h:732
UDS Transport layer.
Definition iso14229.h:254

For transport initialization, see Transport Selection.

Sending Requests

// Send Diagnostic Session Control
UDSSendDiagSessCtrl(&client, UDS_LEV_DS_EXTDS);
// Send Read Data By Identifier
uint16_t dids[] = {0xF190};
UDSSendRDBI(&client, dids, 1);
// Send ECU Reset
UDSSendECUReset(&client, UDS_LEV_RT_HR);
#define UDS_LEV_RT_HR
0x11 ECU Reset SubFunction = [resetType] ISO14229-1:2020 Table 34 UDS Level Reset Type
Definition iso14229.h:440

Processing Responses

while (client.state != UDS_CLIENT_IDLE) {
UDSClientPoll(&client);
// Handle events in callback
}
uint8_t state
Definition iso14229.h:735

Client Structure

The UDSClient 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:

Flag Description
UDS_SUPPRESS_POS_RESP Suppress positive response (0x80 bit)
UDS_FUNCTIONAL Send as functional request (broadcast)
UDS_IGNORE_SRV_TIMINGS Ignore the server-provided P2/P2* values returned by a successful call to DiagnosticSessionControl

Example:

client.options = UDS_SUPPRESS_POS_RESP | UDS_FUNCTIONAL;
UDSSendTesterPresent(&client);
// client.options is cleared automatically after each request
uint8_t options
Definition iso14229.h:737

Event-Driven API

The client uses callbacks to notify the application of events:

int fn(UDSClient_t *client, UDSEvent_t evt, void *ev_data) {
switch (evt) {
// Request sent successfully
break;
// Response received
break;
// Error occurred
UDSErr_t *err = (UDSErr_t *)ev_data;
printf("Error: %s\n", UDSErrToStr(*err));
break;
}
return 0;
}
client.fn = client_callback;
UDSEvent_t
UDS events.
Definition iso14229.h:298
@ UDS_EVT_ResponseReceived
Definition iso14229.h:328
@ UDS_EVT_SendComplete
Definition iso14229.h:327
@ UDS_EVT_Err
Definition iso14229.h:299
int(* fn)(struct UDSClient *client, UDSEvent_t evt, void *ev_data)
Definition iso14229.h:741

Supported Services

See UDS Services.

Unpacking Responses

Helper functions are provided to parse complex responses:

// Security Access response
UDSUnpackSecurityAccessResponse(&client, &resp);
// Request Download response
struct RequestDownloadResponse dl_resp;
UDSUnpackRequestDownloadResponse(&client, &dl_resp);
// Routine Control response
struct RoutineControlResponse rc_resp;
UDSUnpackRoutineControlResponse(&client, &rc_resp);
// Read Data By Identifier response
UDSRDBIVar_t vars[] = {
{.did = 0xF190, .data = buffer, .len = sizeof(buffer)}
};
UDSUnpackRDBIResponse(&client, vars, 1);
Request download response structure.
Definition iso14229.h:762
Routine control response structure.
Definition iso14229.h:769
Security access response structure.
Definition iso14229.h:753
Read data by identifier variable structure.
Definition iso14229.h:779
uint16_t did
Definition iso14229.h:780

Configuration

Client behavior can be configured at compile-time:

Define Default Description
UDS_CLIENT_DEFAULT_P2_MS 150 Default P2 timeout (ms)
UDS_CLIENT_DEFAULT_P2_STAR_MS 1500 Default P2* timeout (ms)
UDS_CLIENT_SEND_BUF_SIZE 4095 Send buffer size
UDS_CLIENT_RECV_BUF_SIZE 4095 Receive buffer size

See Also