| Task | Detail |
|---|---|
| DID 0xF190 | Implement read VIN from NvM (17 bytes, Default + Extended Session) |
| DID 0x0101 | Implement read+write engine oil grade (1 byte enum; Extended Session, Level 1) |
| DID 0x0210 | Implement IO control cooling fan duty (0–100%; Extended Session, Level 1) |
| Validation | Test all NRC conditions: wrong session, wrong security, out-of-range, precondition failure |
Lab Scope
Exercise 1: Three DID Implementations
/* Lab: implement three DIDs in AUTOSAR DCM callback pattern */
/* DID 0xF190: Read VIN */
Std_ReturnType Did_F190_Read(Dcm_OpStatusType op, uint8* Data,
Dcm_NegativeResponseCodeType* Err)
{
/* NvM block VIN: 17 bytes ASCII */
Std_ReturnType r = NvM_ReadBlock(NVM_BLOCK_VIN, Data);
if (r != E_OK) { *Err = DCM_E_CONDITIONSNOTCORRECT; return E_NOT_OK; }
return E_OK;
}
/* DID 0x0101: Read oil grade */
Std_ReturnType Did_0101_Read(Dcm_OpStatusType op, uint8* Data,
Dcm_NegativeResponseCodeType* Err)
{
Data[0] = g_oilGrade; /* application variable; range: 0,5,10,15 */
return E_OK;
}
/* DID 0x0101: Write oil grade */
Std_ReturnType Did_0101_Write(const uint8* Data, Dcm_OpStatusType op,
Dcm_NegativeResponseCodeType* Err)
{
static const uint8 valid[] = {0, 5, 10, 15};
for (uint8 i = 0; i < 4; i++) {
if (Data[0] == valid[i]) {
g_oilGrade = Data[0];
NvM_WriteBlock(NVM_BLOCK_OIL_GRADE, Data);
return E_OK;
}
}
*Err = DCM_E_REQUESTOUTOFRANGE;
return E_NOT_OK;
}
/* DID 0x0210: IO control (implemented in inputoutputcontrolbyidentifier lesson) */Exercise 2: Test NRC Conditions
#!/usr/bin/env python3
# Test all NRC conditions for the three DIDs
import udsoncan
from udsoncan.client import Client
def run_nrc_tests(client):
results = []
# Test 1: Write DID in Default Session → NRC 0x25
client.change_session(udsoncan.services.DiagnosticSessionControl.Session.defaultSession)
try:
client.write_data_by_identifier(0x0101, bytes([0x05]))
results.append(("FAIL", "Write in DS should have returned NRC 0x25"))
except udsoncan.exceptions.NegativeResponseException as e:
code = "PASS" if e.response.code == 0x25 else f"FAIL (got NRC 0x{e.response.code:02X})"
results.append((code, "Write DID in Default Session → NRC 0x25"))
# Enter Extended Session (no security yet)
client.change_session(udsoncan.services.DiagnosticSessionControl.Session.extendedDiagnosticSession)
# Test 2: Write DID without Security → NRC 0x33
try:
client.write_data_by_identifier(0x0101, bytes([0x05]))
results.append(("FAIL", "Write without security should return NRC 0x33"))
except udsoncan.exceptions.NegativeResponseException as e:
code = "PASS" if e.response.code == 0x33 else f"FAIL (got NRC 0x{e.response.code:02X})"
results.append((code, "Write DID without SecurityAccess → NRC 0x33"))
# Test 3: Write out-of-range value → NRC 0x31
# (requires security first — do SecurityAccess 0x27 in actual lab)
# results.append(run_write_test(client, 0x0101, bytes([0x07]), 0x31, "out-of-range"))
for status, desc in results:
print(f"[{status}] {desc}")Exercise 3: IO Control with Safety Guard Verification
#!/usr/bin/env python3
# IO Control lab: verify safety guard rejects control at speed > 10 km/h
import udsoncan
from udsoncan.client import Client
def test_io_control(client):
# Enter Extended Session + SecurityAccess Level 1 (seed-key exchange)
client.change_session(udsoncan.services.DiagnosticSessionControl.Session.extendedDiagnosticSession)
# (SecurityAccess steps skipped here — see security module)
# Step 1: set simulated speed > 10 km/h via Write DID (lab only)
client.write_data_by_identifier(0xFFF0, bytes([0x00, 0x32])) # 50 km/h
# Step 2: attempt IO control → expect NRC 0x22 (conditions not correct)
try:
resp = client.io_control(0x0210, udsoncan.IOMasks(),
control_option_record=bytes([0x03, 0x64])) # 100%
print("FAIL: Should have rejected at speed > 10 km/h")
except udsoncan.exceptions.NegativeResponseException as e:
print(f"{'PASS' if e.response.code == 0x22 else 'FAIL'}: Speed guard returned NRC 0x{e.response.code:02X}")
# Step 3: set speed = 0 → IO control should succeed
client.write_data_by_identifier(0xFFF0, bytes([0x00, 0x00])) # 0 km/h
resp = client.io_control(0x0210, udsoncan.IOMasks(),
control_option_record=bytes([0x03, 0x50])) # 80%
print(f"IO Control at 0 km/h: {'PASS' if resp.positive else 'FAIL'}")
# Step 4: returnControlToECU
resp = client.io_control(0x0210, udsoncan.IOMasks(),
control_option_record=bytes([0x00]))
print(f"ReturnControlToECU: {'PASS' if resp.positive else 'FAIL'}")Summary
The lab combines three service implementations with systematic NRC testing. The most important test pattern is the NRC boundary matrix: for each DID/service combination, verify every rejection condition (wrong session → 0x25, no security → 0x33, out of range → 0x31, precondition → 0x22) produces the correct NRC, not a positive response. A DID that silently ignores an out-of-range write (no NRC, accepts anything) is a safety and compliance failure regardless of whether the application eventually range-checks the value.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.