# diag **Repository Path**: rippleos/diag ## Basic Information - **Project Name**: diag - **Description**: MOSS UDS 诊断模块 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-10 - **Last Updated**: 2026-05-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mdiag - MOSS UDS Diagnostic Module UDS (Unified Diagnostic Services) diagnostic module for MOSS middleware. Implements ISO 14229 standard for automotive diagnostic communication. ## Features - **ISO 14229 Compliance**: Full UDS protocol implementation - **Transport Layer Support**: CAN (ISO 15765-2) and DoIP (ISO 13400) - **Session Management**: Default, Programming, Extended diagnostic sessions - **Security Levels**: Multi-level security access control - **DTC Management**: Diagnostic Trouble Code storage and retrieval - **Routine Control**: Custom routine execution support ## UDS Services Implemented | Service ID | Name | Description | |------------|------|-------------| | 0x10 | DiagnosticSessionControl | Switch diagnostic sessions | | 0x11 | ECUReset | Reset ECU | | 0x22 | ReadDataByIdentifier | Read data by DID | | 0x23 | ReadMemoryByAddress | Read memory by address | | 0x24 | ReadScalingDataByIdentifier | Read scaling data | | 0x27 | SecurityAccess | Security level access | | 0x28 | CommunicationControl | Control communication | | 0x29 | Authentication | Authentication service | | 0x2A | ReadDataPeriodicIdentifier | Periodic data read | | 0x2C | DynamicallyDefineDataIdentifier | Dynamic DID | | 0x2E | WriteDataByIdentifier | Write data by DID | | 0x2F | InputOutputControlByIdentifier | I/O control | | 0x31 | RoutineControl | Execute routines | | 0x34 | RequestDownload | Request download | | 0x35 | RequestUpload | Request upload | | 0x36 | TransferData | Transfer data | | 0x37 | RequestTransferExit | Exit transfer | | 0x3D | WriteMemoryByAddress | Write memory | | 0x3E | TesterPresent | Keep alive | | 0x83 | AccessTimingParameter | Timing control | | 0x84 | SecuredDataTransmission | Secured transmission | | 0x85 | ControlDTCSetting | DTC control | | 0x86 | ResponseOnEvent | Event response | | 0x87 | LinkControl | Link control | ## Architecture ``` diag/ ├── include/diag/ │ ├── mdiag.h # Main include │ ├── types.h # Type definitions │ ├── uds_server.h # UDS server │ ├── uds_client.h # UDS client │ ├── service_handler.h # Service handler base │ ├── session_manager.h # Session management │ ├── security_manager.h # Security access │ ├── dtc_manager.h # DTC management │ ├── did_handler.h # DID handler │ └── transport/ │ ├── transport.h # Transport interface │ ├── can_transport.h # CAN TP (ISO 15765-2) │ └── doip_transport.h # DoIP (ISO 13400) ├── src/ │ ├── uds_server.cpp │ ├── uds_client.cpp │ ├── session_manager.cpp │ ├── security_manager.cpp │ ├── dtc_manager.cpp │ ├── did_handler.cpp │ ├── services/ │ │ ├── session_control.cpp │ │ ├── security_access.cpp │ │ ├── data_identifier.cpp │ │ ├── routine_control.cpp │ │ └── dtc_service.cpp │ └── transport/ │ ├── can_transport.cpp │ └── doip_transport.cpp ├── test/ │ ├── test_uds_server.cpp │ ├── test_session_manager.cpp │ ├── test_security_manager.cpp │ └── test_dtc_manager.cpp └── CMakeLists.txt ``` ## Dependencies - mcom (Communication middleware) - mlog (Logging) - mruntime (Runtime foundation) ## Building ```bash cd mdiag mkdir -p build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DMDIAG_BUILD_TESTS=ON make -j$(nproc) ``` ## Usage ### Server Side (ECU) ```cpp #include // Create UDS server mdiag::UDSServer server; // Register DID handlers server.register_did_handler(0xF190, [](std::vector& data) { // VIN number data = {0x56, 0x49, 0x4E, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31}; return mdiag::NRC::PositiveResponse; }); // Register routine handlers server.register_routine_handler(0x0201, [](uint8_t control, const std::vector& in, std::vector& out) { // Custom routine return mdiag::NRC::PositiveResponse; }); // Start server with CAN transport auto transport = std::make_shared(0x7E0, 0x7E8); server.start(transport); ``` ### Client Side (Tester) ```cpp #include // Create UDS client mdiag::UDSClient client; auto transport = std::make_shared(0x7E8, 0x7E0); client.connect(transport); // Read DID auto [result, data] = client.read_data_by_identifier(0xF190); if (result == mdiag::NRC::PositiveResponse) { std::cout << "VIN: " << std::string(data.begin(), data.end()) << std::endl; } // Switch session result = client.diagnostic_session_control(mdiag::SessionType::Extended); // Security access result = client.security_access(0x01, seed_data, key_data); // Control routine auto [routine_result, routine_data] = client.routine_control(0x0201, mdiag::RoutineControl::Start, {}); ``` ## Negative Response Codes (NRC) | Code | Name | Description | |------|------|-------------| | 0x00 | PositiveResponse | Request accepted | | 0x10 | GeneralReject | General rejection | | 0x11 | ServiceNotSupported | Service not supported | | 0x12 | SubFunctionNotSupported | Sub-function not supported | | 0x13 | IncorrectMessageLength | Wrong message length | | 0x14 | ResponseTooLong | Response too long | | 0x21 | BusyRepeatRequest | Busy, repeat request | | 0x22 | ConditionsNotCorrect | Conditions not correct | | 0x24 | RequestSequenceError | Sequence error | | 0x25 | NoResponseFromSubnet | No response | | 0x26 | FailurePreventsExecution | Failure prevents execution | | 0x31 | RequestOutOfRange | Request out of range | | 0x33 | SecurityAccessDenied | Security access denied | | 0x35 | InvalidKey | Invalid key | | 0x36 | ExceededNumberOfAttempts | Too many attempts | | 0x37 | RequiredTimeDelayNotExpired | Time delay not expired | | 0x70 | UploadDownloadNotAccepted | Upload/download rejected | | 0x71 | TransferDataSuspended | Transfer suspended | | 0x72 | GeneralProgrammingFailure | Programming failure | | 0x73 | WrongBlockSequenceCounter | Wrong sequence | | 0x78 | RequestCorrectlyReceived_ResponsePending | Processing | | 0x7E | SubFunctionNotSupportedInSession | Not supported in session | | 0x7F | ServiceNotSupportedInSession | Not supported in session | ## License MIT License