Simvik

Response pending, on time

Decide when a long-running service must send NRC 0x78, and when to give up. A medium embedded C problem (UDS: requests, sessions and timing), run and graded…

medium · UDS: requests, sessions and timing · uds · automotive · diagnostics · timing · state-machine

A service that cannot answer within P2 (50 ms) must send the negative response 7F <service> 78, requestCorrectlyReceived-ResponsePending, before P2 expires; the tester then waits up to P2\* (5000 ms), and the server must send another 78 before that expires too.

Write the timing. Times are milliseconds from a counter that wraps around.

  • pending_start(p, now): a long job begins. The first 78 is due at 80 % of P2 after now.
  • pending_poll(p, now): called every millisecond while the job runs. Return:
  • SEND_NOTHING when not busy, or nothing is due yet;
  • SEND_PENDING when a 78 is due: count it, and make the next one due at 80 % of P2\* after now;
  • SEND_GENERAL_REJECT when a 78 is due but MAX_PENDING have already been sent: the job has taken too long. The server answers 7F <service> 10, and is no longer busy.
  • pending_done(p): the job finished and its final response was sent. No longer busy.

Starter code

void pending_start(pending_t *p, uint32_t now) {
  p->busy = true;
  p->next_ms = now + P2_MS;
  p->sent = 0;
}

pending_action_t pending_poll(pending_t *p, uint32_t now) {
  if (now < p->next_ms) return SEND_NOTHING;
  p->next_ms = now + P2_STAR_MS;
  return SEND_PENDING;
}

void pending_done(pending_t *p) {
  p->busy = false;
}

Example tests

The first 0x78 comes inside P2

pending_t p = { 0 };
pending_start(&p, 1000);
run(&p, 1000, 1100);

Expected output:

t=1040: 7F xx 78

A job of six seconds

pending_t p = { 0 };
pending_start(&p, 0);
run(&p, 0, 6000);
pending_done(&p);
run(&p, 6001, 20000);
printf("done\n");

Expected output:

t=40: 7F xx 78
t=4040: 7F xx 78
done

Learn it first

More UDS: requests, sessions and timing problems

  • Answer TesterPresent · Build the positive or negative response to service 0x3E, honouring the suppress bit.
  • A session that times out · Track the diagnostic session and the S3 timer that returns an ECU to the default session.