Diagnostics: Connection of the Communication Layer
Valid for: CANoe DE The diagnostic commands in CAPL allow access to the diagnostic services and data using symbols that were defined in the CANdela description file. For communication, this data must be transmitted, where two ways are available:- In a tester node or test module, a call to diagSetTarget suffices. It will connect the tester to the ECU via the so-called built-in diagnostic channel provided by CANoe.
- In an ECU simulation, it is necessary to implement the CAPL callback interface. This interface consists of a set of functions implemented in CAPL that are called by CANoe to trigger actions, and special CAPL functions implemented by CANoe that forward transport protocol events to CANoe.
CAPL Callback Interface for Diagnostics
- _Diag_SetChannelParameters: This function is called by CANoe to indicate that a new communication “channel” to the ECU or tester should be opened. Typically the settings configured for the ECU are queried and the transport protocol layer is configured.
- _Diag_DataRequest: CANoe triggers the sending of data to the peer, i.e., in an ECU simulation, the bytes representing the response primitive will be given to be forwarded to the transport protocol. In a tester, the bytes represent the request primitive.
- _Diag_SendFunctional (in testers only): CANoe triggers the functional sending of a request.
- _Diag_SetupChannelReq (in testers only): For connection-oriented transport protocols, the tester has to establish a communication channel to the ECU. Once the channel is available, the tester has to call diag_SetupChannelCon.
Diag_SetupChannelCon can be called immediately.
Depending on the transport protocol implementation used, the events the CAPL program receives have to be forwarded to CANoe.Please refer to these functions for details:
- diag_DataInd
- diag_ErrorInd
- diag_DataCon
- diag_FirstFrameInd
- diag_ClosedChannelInd
- diag_SetDataSegmentation
- diag_SetupChannelCon
- Include the respective CIN file into your CAPL simulation nodes, test nodes, test modules, and test case libraries.
-
Define the following global variables in your CAPL code:
- char gECU[]
gECU is the name of the respective node, e.g., of a simulated ECU, necessary for identifying the node in case of error messages in the Write Window. In case of FlexRay, it needs to contain the name of the database node. - int cIsTester
cIsTester is a flag indicating whether the node serves as a tester (cIsTester=1) or an ECU (cIsTester=0).
- char gECU[]
- Add the respective transport protocol DLL to your CAPL node as a component, either by assigning it in the network description database or by adding it in the Components tab of the Node Configuration dialog.
- Implement the diagnostics behavior of your CAPL node using CAPL diagnostics functions, on diagRequest and on diagResponse handlers.
- Make sure there is a link between the diagnostic description and your CAPL code using the CAPL functions diagSetTarget (in a tester node) or diagInitEcuSimulation (in an ECU simulation). Alternatively, you may choose Assign to database node as usage of the diagnostic description in the Configuration|Diagnostics/ISO TP… dialog (where available).
<service> handlers for all diagnostic services you want to support with your simulation and change the value of gECU to the ECU qualifier you defined in the Diagnostics/ISO TP… dialog. Additionally, you might need to adapt the service name for the Tester Present service (in this example: TesterPresent_Process) to the service identifier specified in your diagnostic description: