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, 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 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;
UDSErr_t UDSSendTesterPresent(UDSClient_t *client)
What's up?
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.