DiagCom - DiadromSW/DiagDoipCom GitHub Wiki

DiagCom represents a vehicle communication REST service based on Doip(IS013400)/UDS(ISO14229). It identifies on the local network vehicles that have Doip support and gives the possibility to run diagnostic services on detected vehicles. Identification is done by reading UDP Vehicle Identification Messages, that provide information about vehicle IP and VIN. Besides vehicle detection and running Diagnostic services, the service has few predefined vehicle operations, such as Clear and Read DTC and Read Battery Voltage. As well as a few logg-related endpoints, such as start/stop logging and extract logging for a specific vehicle.

The DiagCom service can be installed via Wix installer and run as windows service on http://localhost:5001/ with a local system account. It can be also used as a library by importing DiagCom nuget or by using directly from the provided source code.

How to get started with DiagCom in Visual Studio

  1. Clone the repository DiagDoipCom and choose the branch Master
  2. Set the DiagCom.RestApi as Setup Project and Build Solution.
  3. Start in Debug or Release mode the RestApi project
  4. Open Chrome or another browser and navigate to https://localhost:5001/index.html

A swagger page with API documentation of the DiagCom service will be loaded

DiagCom Solution structure

The provided solution has 8 main projects:

  • DiagCom.RestApi - represents the Rest APi wrapper of DiagCom. It is responsible for starting the service on a specified host and resolving project dependencies.
  • DiagCom.Commands - can be imported and used without RestApi. It contains predefined vehicle commands, connections and running context.
  • DiagCom.Uds - Contains logic related to diagnostic services, and retries on the UDP level.
  • DiagCom.Doip - Handles Doip Request/Response
  • DiagCom.LocalCommunication - Contains connection logic and processing of Diagnostic messages received from vehicle
  • DiagComSetup - The project is to build the DiagCom installer. Wixtoolset extension needs to be available in VS. This can be found in the Visual Studio tab Extension -> Manage Extensions
  • Logging - has two methods to log both done via Nlog (https://nlog-project.org/). The first is logging into the log file "SystemLog.log". This logging begins when the DiagCom service starts. SystemLog logs the general flow for DiagCom. The configuration of the log rules is static in the "nlog.config" file in the RestApi project. The second logging method is for "Vin Logs" These logs ISO14229. The configuration is dynamic at LogHandler.StartLogging().
  • CustomActions - There is a Cors certificate required to run DiagCom as Service. It is created as a custom action during DiagCom installation.

DiagCom API

DiagCom Service Web API

GET /VehicleCommunication/GetConnectedVehicles

Identifies and establishes UDP and TCP-connections to respective connected vehicles. Broadcasted VINs received on UDP connections is cached and returned. Cached connections VIN will be returned for followed requests

Responses

Code Description
200 JSON-Array of VINs currently connected vehicles
409 Generic vehicle communication error

POST /VehicleCommunication/ReadClearDTCs

Read vehicle's DTCs and runs clear operation if flag Erase is true before reading. If any ECU does not respond a physical request is sent. Result is merged with input ECUs and not responding ECUs are detected

Payload

ReadDtcsPayload

Field Name Type Description
vin string Vehicle Idenification Number
ecus array List of ecu addresses
erase bool Flag if clear Dtc operation will execute before read Dtc operation

Responses

Code Description
200 JSON-array with JObjects containing detected DTCs on each ECU
400 Invalid input payload.
409 Generic vehicle communication error

GET /VehicleCommunication/GetDtcStatus

Retrieve DTC extended data associated with defined DTC. Extended data consist of status and indicator. This api calls service 19 with subfunction 06.

Parameters

Name Located in Description
vin query Vehicle Identification Number
dtcId query Diagnostic Trouble Code Identifier
ecuAddress query Ecu adress

Payload exemple:

{
  "vin": "LVX00000000000001",
  "ecus": [
    "1001",
    "1261"
  ],
  "erase": true
}

Responses

Code Description
200 Success.
400 Bad Request
409 Conflict
412 Client Error

POST /VehicleCommunication/RunDiagnosticSequence

Creates a sequence of diagnostic services and runs them synchronous on specified vehicle.

Payload

DiagnosticSequencePayload

Field Name Type Description
vin string Vehicle Identification Number
diagnosticSequence DiagnosticSequence Payload object for RunDiagnosticSequence

DiagnosticSequence

Field Name Type Description
identifier string Sequence Identifier. Can be a GUID value. Can be used by requester to keep track of sequences
sequence array Diagnostic Service objects that contains information about UDS services to run on vehicle

DiagnosticService

Field Name Type Description
ecuAddress string Ecu address
description string A short description for service to be run
service string UDS service to be run on vehicle. It needs to be in hex
payload string Service specific data in hex. Can be Dids or other payload
parsingData ParsingData Object that contains parameters to parse

ParsingData

Field Name Type Description
identifier string Parsing data Identifier
description string A short description
totalBytes string Bytes array lenght to be used for data to parse
parameters array Parameters to be extracted from received bytes array

Parameters

Field Name Type Description
identifier string Parsing data Identifier
dataType string Parameter data type. It has support for following parameter types:ascii, bcd, hex, signed, unsigned
description string A short description for parameter to be parsed
max string Max value of the parameter if its relevant. Not required
min string Min value of the parameter if its relevant. Not required
offsetBits string
totalBits string

Payload exemple:

{
  "vin": "LVX00000000000001",
  "diagnosticSequence": {
    "identifier": "d4cd0ad1-5849-4370-9699-f48683d3b623",
    "sequence": [
      {
        "ecuaddress": "1401",
        "description": "Read Data By Identifier Usage Mode",
        "service": "22",
        "payload": "DD0A",
        "parsingdata": {
          "identifier": "DD0A",
          "description": "Usage Mode",
          "totalbytes": "0",
          "parameters": [
            {
              "identifier": "DD0A_1",
              "datatype": "Unsigned",
              "description": "",
              "format": "dec",
              "max": "",
              "min": "",
              "offsetbits": "0",
              "position": "1",
              "precision": "",
              "totalbits": "8"
            }
          ]
        }
      }
    ]
  }
}

Responses

Code Description
200 Parsed results.
400 Invalid input payload.
409 Generic vehicle communication error
412 Client Error
502 Server Error

GET /VehicleCommunication/ReadBatteryVoltage/{vin}

Request battery voltage of a vehicle with specified VIN.

Parameters

Field Name Type Description
vin string Vehicle Identification Number

Responses

Code Description
200 Battery voltage of vehicle in millivolts.
400 Invalid VIN.
409 Generic vehicle communication error

POST /VehicleCommunication/RawDiagnosticSequence

Executes a sequence of diagnostic services.

Payload

RawSequence

Field Name Type Description
vin string Vehicle Idenification Number
ecuAddress string Ecu addresses or Functional request address
request string UDS service and payload as hex string

Payload exemple:

{
  "vin": "LVX00000000000001",
  "ecuAddress": "1FFF",
  "request": "1903"
}

Responses

Code Description
200 Success