iso14229 0.11.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:366
UDS client structure.
Definition iso14229.h:753
UDSTp_t * tp
Definition iso14229.h:755
UDS Transport layer.
Definition iso14229.h:561

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:422
#define UDS_LEV_RT_HR
Hard Reset.
Definition iso14229.h:432
UDSErr_t UDSSendECUReset(UDSClient_t *client, uint8_t type)
Request ECUReset.
Definition iso14229.c:667
UDSErr_t UDSSendDiagSessCtrl(UDSClient_t *client, uint8_t mode)
Change the diagnostic session.
Definition iso14229.c:678
UDSErr_t UDSSendRDBI(UDSClient_t *client, const uint16_t *didList, uint16_t numDataIdentifiers)
Read Data By Identifier.
Definition iso14229.c:712

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:1173
uint8_t state
Definition iso14229.h:769

Client Configuration

Some client behavior is configurable at runtime. After initialization, the library never modifies the values of these flags.

| Option | Description | Valid Range | Default Value | |-|-|-| | cfg_suppress_pos_resp | When sending requests, ask that the server not send positive responses (0x80 bit) | 0-1 | 0 | | cfg_send_functional | Send requests as functional (broadcast) | 0-1 | 0 | | cfg_ignore_srv_sess_timing | Ignore the server-provided P2/P2* values returned by a successful call to DiagnosticSessionControl | 0-1 | 0 | | cfg_data_format_identifier | See Upload/Download functional unit | 0-255 | 0 | | cfg_file_size_parameter_length | See Upload/Download functional unit | 0-255 | 4 |

Example:

client.suppress_pos_resp = 1;
UDSSendTesterPresent(&client); // sends
UDSErr_t UDSSendTesterPresent(UDSClient_t *client)
What's up?
Definition iso14229.c:701

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:277
@ UDS_EVT_ResponseReceived
Definition iso14229.h:307
@ UDS_EVT_SendComplete
Definition iso14229.h:306
@ UDS_EVT_Err
Definition iso14229.h:278
UDSErr_t
Error Codes, including NRCs defined by the standard.
Definition iso14229.h:317
int(*) fn(struct UDSClient *client, UDSEvent_t evt, void *ev_data)
Definition iso14229.h:756

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:1099
UDSErr_t UDSUnpackRDBIResponse(UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars)
Parse server's response to RDBI.
Definition iso14229.c:1191
UDSErr_t UDSUnpackRoutineControlResponse(const UDSClient_t *client, struct RoutineControlResponse *resp)
Parse server's response to RoutineControl.
Definition iso14229.c:1124
UDSErr_t UDSUnpackRequestDownloadResponse(const UDSClient_t *client, struct RequestDownloadResponse *resp)
Parse server's response to RequestDownload.
Definition iso14229.c:1151
Request download response structure.
Definition iso14229.h:789
Routine control response structure.
Definition iso14229.h:796
Security access response structure.
Definition iso14229.h:780
Read data by identifier variable structure.
Definition iso14229.h:806

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