Answer TesterPresent
Build the positive or negative response to service 0x3E, honouring the suppress bit. An easy embedded C problem (UDS: requests, sessions and timing), run and…
easy · UDS: requests, sessions and timing · uds · automotive · diagnostics · negative-response
Write tester_present(req, len, resp), the handler for UDS service 0x3E TesterPresent. req holds the len bytes of a request whose first byte is 0x3E. Write the response to resp and return its length, or 0 when no response is to be sent.
| Request | Response |
|---|---|
3E 00 | 7E 00 (positive: the service byte + 0x40, then the sub-function) |
3E 80 | none: bit 7 of the sub-function suppresses the positive response |
| not exactly 2 bytes | 7F 3E 13 incorrectMessageLengthOrInvalidFormat |
| a sub-function other than 0 (ignoring bit 7) | 7F 3E 12 subFunctionNotSupported |
Check the length before the sub-function. A negative response is sent even when the suppress bit is set.
Starter code
uint16_t tester_present(const uint8_t *req, uint16_t len, uint8_t *resp) {
(void)len;
resp[0] = 0x7E;
resp[1] = req[1];
return 2;
}Example tests
The positive response
const uint8_t req[] = { 0x3E, 0x00 };
ask(req, 2);Expected output:
7E 00Suppressed
const uint8_t req[] = { 0x3E, 0x80 };
ask(req, 2);Expected output:
(no response)Learn it first
- UDS: requests, sessions and timing · Service identifiers, negative response codes and their order, sessions, P2, P2*, S3 and response pending.
More UDS: requests, sessions and timing problems
- A session that times out · Track the diagnostic session and the S3 timer that returns an ECU to the default session.
- Response pending, on time · Decide when a long-running service must send NRC 0x78, and when to give up.