ara::diag::DiagnosticServer diagServer(
ara::core::InstanceSpecifier{"DiagApp/DiagServer"});
// $10 DiagnosticSessionControl
diagServer.RegisterService(0x10, [&](auto req) {
uint8_t session = req[1];
if (session == 0x01 || session == 0x03) { // Default, Extended
current_session = session;
return ara::diag::ServiceDataContainer{0x50, session, 0x00, 0x19, 0x01, 0xF4};
}
return ara::diag::ServiceDataContainer{0x7F, 0x10, 0x12}; // NRC subFunctionNotSupported
});
// $19 ReadDTCByStatusMask
diagServer.RegisterService(0x19, [&](auto req) {
if (req[1] == 0x02) { // subFunction 02
uint8_t mask = req[2];
auto dtcs = dtcStorage.GetDTCsByStatus(mask);
ara::diag::ServiceDataContainer resp{0x59, 0x02, 0xFF}; // FF = DTCFormatIdentifier
for (auto& dtc : dtcs) {
resp.push_back((dtc.code >> 16) & 0xFF);
resp.push_back((dtc.code >> 8) & 0xFF);
resp.push_back(dtc.code & 0xFF);
resp.push_back(dtc.statusByte);
}
return resp;
}
return ara::diag::ServiceDataContainer{0x7F, 0x19, 0x12};
});
DiagnosticServer Setup: Core Services
DoIP Transport Configuration
{
"doipConfig": {
"logicalAddress": "0x0E80",
"networkInterface": "eth0",
"port": 13400,
"maxPayloadSize": 65535
}
}
# Test with Python doipclient
python3 -c "
import doipclient
client = doipclient.DoIPClient('192.168.0.10', 13400)
client.connect()
# Send $22 F190 (Read VIN)
response = client.send_doip(bytes([0x22, 0xF1, 0x90]))
print('VIN response:', response.hex())
client.disconnect()
"
DTC Integration Test
// Force fault condition for testing
dtcMonitor.ReportMonitorAction(ara::diag::MonitorAction::kFailed);
// Wait for DTC to be stored (debounce cycle)
std::this_thread::sleep_for(std::chrono::milliseconds(500));
// Verify via $19 02 response
// DTC status byte bit 0 (testFailed) should be set
// DTC status byte bit 3 (confirmedDTC) set after confirmation threshold
// Clear DTC with $14
diagServer.RegisterService(0x14, [&](auto req) {
dtcStorage.ClearAll();
return ara::diag::ServiceDataContainer{0x54};
});
SecurityAccess Full Flow
// $27 01: Seed request (Level 1 access)
// $27 02: Key response
// $2E: WriteDID (protected by SecurityAccess)
diagServer.RegisterService(0x2E, [&](auto req) {
if (!security_unlocked) {
// NRC 0x33: SecurityAccessDenied
return ara::diag::ServiceDataContainer{0x7F, 0x2E, 0x33};
}
uint16_t did = (req[1] << 8) | req[2];
if (did == 0x0100) { // Calibration offset DID
float offset;
memcpy(&offset, &req[3], 4);
kvs.SetValue("calibOffset", offset);
kvs.SyncToStorage();
return ara::diag::ServiceDataContainer{0x6E, req[1], req[2]};
}
return ara::diag::ServiceDataContainer{0x7F, 0x2E, 0x31};
});
Summary
A complete ara::diag implementation requires $10 session control, $22/$2E data services, $27 security access gating, $19 DTC reading, and $14 DTC clearing. DoIP logical address configuration in the Machine Manifest connects the ara::diag server to the Ethernet interface accessible from the tester.
🔬 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.