Route a PDU through the stack
A PDU router: deliver each received PDU to every destination its routing table names. A medium embedded C problem (AUTOSAR Classic for diagnostics…
medium · AUTOSAR Classic for diagnostics engineers · autosar · automotive · table-driven · routing · gateway
In an AUTOSAR ECU the PDU router (PduR) decides where each received message goes. It knows no protocol: it only follows a generated table. One received PDU may have several routes: a wheel speed message can go to this ECU's own signals (Com) and also be forwarded to another bus.
Write PduR_RxIndication(routes, n, rx_pdu, data, len). For every row of routes whose rx_pdu matches, in table order:
DEST_COM: callCom_RxIndication(rx_pdu, data, len).DEST_DCM: callDcm_RxIndication(rx_pdu, data, len).DEST_GATEWAY: callCanIf_Transmit(tx_pdu, data, len), unlesslenis more than the route'smax_len: then the PDU does not fit the destination and that route is skipped.
Return the number of destinations the PDU was delivered to. A gateway route counts only if CanIf_Transmit returned true. A PDU with no route is dropped: return 0.
Starter code
uint8_t PduR_RxIndication(const route_t *routes, size_t n, uint16_t rx_pdu, const uint8_t *data, uint8_t len) {
for (size_t i = 0; i < n; i++) {
if (routes[i].rx_pdu != rx_pdu) continue;
if (routes[i].dest == DEST_COM) Com_RxIndication(rx_pdu, data, len);
else if (routes[i].dest == DEST_DCM) Dcm_RxIndication(rx_pdu, data, len);
else CanIf_Transmit(rx_pdu, data, len);
return 1;
}
return 0;
}Example tests
A diagnostic request goes to the Dcm
const uint8_t req[3] = { 0x22, 0xF1, 0x90 };
rx(20, req, 3);Expected output:
PDU 20:
Dcm: PDU 20, service 22, 3 bytes
delivered to 1One PDU, three destinations
const uint8_t speeds[8] = { 0x11, 2, 3, 4, 5, 6, 7, 8 };
rx(10, speeds, 8);Expected output:
PDU 10:
Com: PDU 10, 8 bytes, first 11
CanIf: send PDU 60, 8 bytes, first 11
CanIf: send PDU 63, 8 bytes, first 11
delivered to 3Learn it first
- AUTOSAR Classic for diagnostics engineers · The layered architecture, the path of a diagnostic request through CanIf, CanTp, PduR, Dcm and Dem, and NvM.
More AUTOSAR Classic for diagnostics engineers problems
- Read a redundant NvM block · Pick the valid copy of a block stored twice, say which copy needs repair, and fall back to defaults.