iso14229 0.10.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;
UDSErr_t UDSClientInit(UDSClient_t *client)
Call this once.
Definition iso14229.c:55
UDS client structure.
Definition iso14229.h:791
UDSTp_t * tp
Definition iso14229.h:794
UDS Transport layer.
Definition iso14229.h:255

Sending Requests

// Send Diagnostic Session Control
// Send Read Data By Identifier
uint16_t dids[] = {0xF190};
UDSSendRDBI(&client, dids, 1);
// Send ECU Reset
#define UDS_LEV_DS_EXTDS
Extended Diagnostic Session.
Definition iso14229.h:445
#define UDS_LEV_RT_HR
Hard Reset.
Definition iso14229.h:455
UDSErr_t UDSSendECUReset(UDSClient_t *client, uint8_t type)
Request ECUReset.
Definition iso14229.c:357
UDSErr_t UDSSendDiagSessCtrl(UDSClient_t *client, uint8_t mode)
Change the diagnostic session.
Definition iso14229.c:368
UDSErr_t UDSSendRDBI(UDSClient_t *client, const uint16_t *didList, const uint16_t numDataIdentifiers)
Read Data By Identifier.
Definition iso14229.c:402

Processing Responses

while (client.state != UDS_CLIENT_IDLE) {
UDSClientPoll(&client);
// Handle events in callback
}
UDSErr_t UDSClientPoll(UDSClient_t *client)
Call at <5ms intervals.
Definition iso14229.c:922
uint8_t state
Definition iso14229.h:797

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:

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 is cleared automatically after each request
UDSErr_t UDSSendTesterPresent(UDSClient_t *client)
What's up?
Definition iso14229.c:391
#define UDS_SUPPRESS_POS_RESP
set the suppress positive response bit
Definition iso14229.h:784
#define UDS_FUNCTIONAL
send the request as a functional request
Definition iso14229.h:785
uint8_t options
Definition iso14229.h:799

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:303
@ UDS_EVT_ResponseReceived
Definition iso14229.h:333
@ UDS_EVT_SendComplete
Definition iso14229.h:332
@ UDS_EVT_Err
Definition iso14229.h:304
UDSErr_t
Error Codes, including NRCs defined by the standard.
Definition iso14229.h:343
int(*) fn(struct UDSClient *client, UDSEvent_t evt, void *ev_data)
Definition iso14229.h:805

Unpacking Responses

Helper functions are provided to parse complex responses:

// Security Access response
// Request Download response
struct RequestDownloadResponse dl_resp;
// Routine Control response
struct RoutineControlResponse rc_resp;
// Read Data By Identifier response
UDSRDBIVar_t vars[] = {
{.did = 0xF190, .data = buffer, .len = sizeof(buffer)}
};
UDSUnpackRDBIResponse(&client, vars, 1);
UDSErr_t UDSUnpackSecurityAccessResponse(const UDSClient_t *client, struct SecurityAccessResponse *resp)
Parse server's response to SecurityAccess.
Definition iso14229.c:843
UDSErr_t UDSUnpackRDBIResponse(UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars)
Parse server's response to RDBI.
Definition iso14229.c:940
UDSErr_t UDSUnpackRoutineControlResponse(const UDSClient_t *client, struct RoutineControlResponse *resp)
Parse server's response to RoutineControl.
Definition iso14229.c:868
UDSErr_t UDSUnpackRequestDownloadResponse(const UDSClient_t *client, struct RequestDownloadResponse *resp)
Parse server's response to RequestDownload.
Definition iso14229.c:896
Request download response structure.
Definition iso14229.h:826
Routine control response structure.
Definition iso14229.h:833
Security access response structure.
Definition iso14229.h:817
Read data by identifier variable structure.
Definition iso14229.h:843

Some configuration options are set at compile-time. See : Compile-Time Configuration.