AN-IND-1-004 Diagnostics Via Gateway in CANoe
AN-IND-1-004 Diagnostics Via Gateway in CANoe
Version 1.6
2022-08-02
Application Note AN-IND-1-004
Table of Contents
1.0 Overview
CANoe supports a multitude of features for the development of diagnostics in ECUs and vehicles as a
whole. While all features are available on the CAN bus system with ISO transport protocol, not all
features are available on non-CAN bus systems, and not every proprietary transport protocol is
supported.
For most scenarios, a “diagnostics gateway” can make the CAN diagnostics features available to any
bus system. This application note explains the basic scenarios, the currently available features, the
concept of a diagnostics gateway, and finally some CAPL example implementations.
In the final section, a multi-connection CAN-FlexRay TP-level gateway is described in detail.
Please note, that since the time this application note was written, features may have been made
available for additional bus systems. For the latest information and sample implementations, please
have a look at the Vector homepage www.vector.com or call the support hotline.
Feature Availability
Implementations:
> ISO TP on CAN, LIN and FlexRay
> AMS and MOST High Protocol on MOST
Transport > AUTOSAR TP 2.0 and 3.0 on FlexRay
protocols > AUDI AUTOSAR TP 3.2.1.4 on FlexRay (in a separate package)
> BMW TP on FlexRay (in a separate package)
> K-Line
> DoIP/HSFZ
Available for:
Diagnostic > ISO TP on CAN, LIN and FlexRay
Console, Fault > AUTOSAR TP 2.0 and 3.0 on FlexRay
Memory and > AUDI AUTOSAR TP 3.2.1.4 on FlexRay (in a separate package)
Session Control > BMW TP on FlexRay (in a separate package)
Window > K-Line
> DoIP/HSFZ
Feature Availability
> FlexRay
> K-Line
> DoIP/HSFZ
Table 1: Availability of CANoe diagnostics features on bus systems and for transport protocols
Figure 1: Gateway routing diagnostic information between a bus system which supports diagnostic access natively (e.g. CAN)
and the target bus system.
Note
The samples only sketch one of several possible implementations!
Please refer to the CANoe help and manual for details on functions and CAPL keywords.
Response:
First Frame Rx 151 24 10 09 5A 81 12 34 56 78 …
400 8 10 09 5A 81 12 34 56 78 Tx
Flow 200 8 30 00 14 00 00 00 00 00 Rx
Control
Tx 150 24 30 00 14 00 …
Consecutive Rx 151 24 21 9A BC DE 00 00 00 00 …
Frame
400 8 21 9A BC DE 00 00 00 00 Tx
Discussion:
> No transport protocol implementations have to be present in the gateway.
> Since the data is not stored, gateways of this type provide the smallest transmission delay.
> The transport protocols used on the buses must be identical to the largest extend. Especially
the size and layout of the transferred protocol data must be the same, though additional
padding may be used (as indicated in the example).
Sample Implementation:
On message 0x200
{
<target>message 0x150 tgtMsg = { dlc = 24 };
long i;
for( i = 0; i < this.dlc; ++i)
tgtMsg.byte( i) = this.byte( i);
SetBusContext( targetBus);
output( tgtMsg);
}
On <target>message 0x150
{
message 0x400 canMsg = { dlc = 8 };
long i;
for( i = 0; i < 8; ++i)
canMsg.byte( i) = this.byte( i);
SetBusContext( canBus);
output( canMsg);
}
Discussion:
> This type of gateway provides the most generic form of forwarding while sticking to KWP/UDS,
since it is possible to connect between any type of bus system and transport protocol.
> Note that the buffering of the transported data in the gateway will introduce a significant delay
into the communication. It might be possible to change certain protocol parameters (e.g. the
separation time in ISO TP) to reduce this delay.
> For both sides of the gateway complete implementations of the transport protocols have to be
present, and the protocols have to be configured correctly. But other than that, no in-depth
knowledge of the protocol has to be used.
Sample Implementation:
CanTp_ReceptionInd( long connHandle, byte rxBuffer[])
{
SetBusContext( targetBus);
TargetBusSend( rxBuffer, elcount( rxBuffer));
}
1 Non-existing example
Discussion:
> This is the most flexible form of diagnostics gateway, since it can react to the requests on
application level.
> A gateway of this type will be very specific typically, i.e. for every ECU (type) another gateway
implementation might be necessary.
> Automatic configuration of such a gateway will be very hard to realize.
Sample Implementation:
On DiagRequest Door.FaultMemory_ReadAllIdentified
{
ClearCurrentDTCList();
gNextDTCToRead = 0x9001;
ReadNextDTC();
}
ReadNextDTC()
{
<target> message 01 mQueryOneDTC = { dlc = 4, byte(0) = 1, byte(1) = 1 };
mQueryOneDTC.byte(2) = gNextDTCToRead / 256;
mQueryOneDTC.byte(3) = (BYTE) gNextDTCToRead;
SetBusContext( targetBus);
output( mQueryOneDTC);
// There should be timeout handling; omitted here
}
On <target> message 02
{
if( this.byte(2) != 0)
AddDTCtoCurrentDTCList( gNextDTCToRead, this.byte(2));
++gNextDTCToRead;
if( gNextDTCToRead > 0x9027)
{
// Last DTC queried, so send DiagResponse to tester
SendCurrentDTCListToTester();
} else
{
ReadNextDTC();
}
}
5.1 Overview
In this example a complete ISO TP on CAN – AUTOSAR TP on FlexRay gateway is documented that
allows a diagnostic tester on a CAN network to simultaneously access several ECUs on a FlexRay
network.
5.2 Setup
The gateway consists of one CANoe simulation node that is attached to a CAN and a FlexRay
network. The node is configured to load the modeling libraries “AutosarFlexRayTP3.vmodule” and
“OSEK_TP.vmodule” as component on all networks.
The networks have to be configured to allow communication with real hardware on CAN (if a stand-
alone tester should be used) and FlexRay: On CAN, the correct baud rate has to be selected. On
FlexRay, the cluster definitions have to be read from a FIBEX database that includes the cycle layout.
Please refer to the CANoe manual for more details.
Note
Please note the changed timing behavior of such a TP-level gateway (cf. 4.2.2)!
Note
If a modeling library like e.g. OSEK_TP.vmodule or DoIP.vmodule is added manually to a
simulation node which is connected to several networks (like in a typical gateway node),
this will create a separate instance of this modeling library for each of these networks.
This is true even if the library might not fit to the network type (e.g., if the DoIP.vmodule
was added to a CAN network). In this case, when initializing the modeling library (e.g.,
creating a connection with CanTpCreateConnection()) or when trying to send data (e.g.,
using CanTPSendData()), it is necessary to select the correct instance of the modeling
library via its “bus context”, i.e. the network to which this instance is connected. You can
select this bus context using the CAPL function setBusContext().
The network names have to be replaced with those used in the actual configuration!
on preStart
{
gContextCAN = GetBusNameContext( "CAN"); // Replace with actual
gContextFR = GetBusNameContext( "FlexRay"); // names!
On FlexRay, it might be necessary to register slots for sending during the pre-start phase. This
depends on the way FlexRay slots are defined; please refer to the respective manuals.
// Register frames used on FlexRay for TP
SetBusContext( gContextFR);
FrTP_ReserveSendSlots(120 , 1); // Replace with actual values!
}
if( !frConn)
{
return; // no corresponding FlexRay connection found!
}
if( status != 0)
FrTP_ErrorInd( frConn, status); // forward error to our handler
}
CanTp_SendCon( long handle, dword txCount)
{
// Sending of data succeeded
}
CanTp_ErrorInd( long handle, long error)
{
char cErrorText[13][30] = {
"(no error)"
, "Timeout while waiting for CF" // 1
, "Timeout while waiting for FC" // 2
, "Wrong Sequence Number" // 3
, "TP_DLL busy" // 4
, "Unexpected PDU" // 5
, "Timeout waiting for Tx-Ack" // 6
, "WFT Overrun" // 7
, "Buffer overflow" // 8
, "Wrong parameter" // 9
, "Invalid FlowStatus received" // 10
, "Transfer abort requested" // 11
// Sentinel
, "unknown error!"
};
long i;
if( error < 0 || error >= elcount(cErrorText))
i = elcount(cErrorText) - 1;
else
i = error;
if( status != 0)
CanTp_ErrorInd( canConn, status); // forward error to our handler
}
FrTP_TxConfirmationInd( long handle)
{
// Sending of data succeeded!
}
FrTP_ErrorInd(long connectionHdl, dword error)
{
char cErrorText[14][60] = {
"(no error)"
, "Some mandatory settings are missing, e.g. the addresses"
, "The value given contradicts another setting made earlier"
, "The send request was rejected due to another transmission"
, "A reception was active when FF or SF was received"
, "A negative ACK was received for acknowledged connections"
, "The bus did not confirm transmission of a frame in time"
, "The transmitter did not receive a FC (or AF) in time"
, "The receiver did not receive the next CF in time"
, "(unknown)"
, "(unknown)"
, "The peer rejected the data since it is too long"
, "Peer sent an undefined Ack"
// Sentinel
, "unknown error!"
};
long i;
if( error < 0 || error >= elcount(cErrorText))
i = elcount(cErrorText) - 1;
else
i = error;
Figure 3: With the gateway in place, the diagnostic features of CANoe (e.g. Diagnostic Console) can be used to access the
target ECU.
SAMPLE CONFIGURATIONS
KWPSim on LIN Demo, file location: <CANoe.LIN>\Demo_LIN_CN\KWPSim_Lin
MOST Diagnostic Gateway Demo, file location:
<CANoe.MOST>\Demo_MOST_CN\MOSTDiagnostics
CANOE/DENOE DOCUMENTATION
FlexRay TP AUTOSAR documentation in the CANoe help
7.0 Contacts
For a full list with all Vector locations and addresses worldwide, please visit http://vector.com/contact/.