Simvik

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.

RequestResponse
3E 007E 00 (positive: the service byte + 0x40, then the sub-function)
3E 80none: bit 7 of the sub-function suppresses the positive response
not exactly 2 bytes7F 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 00

Suppressed

const uint8_t req[] = { 0x3E, 0x80 };
ask(req, 2);

Expected output:

(no response)

Learn it first

More UDS: requests, sessions and timing problems