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 first78is due at 80 % of P2 afternow.pending_poll(p, now): called every millisecond while the job runs. Return:SEND_NOTHINGwhen not busy, or nothing is due yet;SEND_PENDINGwhen a78is due: count it, and make the next one due at 80 % of P2\* afternow;SEND_GENERAL_REJECTwhen a78is due butMAX_PENDINGhave already been sent: the job has taken too long. The server answers7F <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 78A 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
doneLearn 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
- 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.