You are on page 1of 20

User documentation

KWP2000

Add-On for CANoe

Version 1.2

Vector Informatik GmbH, Ingersheimer Straße 24, 70499 Stuttgart


Tel. (0711) 8 06 70-0, Fax (0711) 8 06 70-5 55
Email can@vector-informatik.de, Internet http://www.vector-informatik.de
II

Table of contents

1 History ..................................................................................................................1
1.1 List of changes in version 1.1........................................................................1
1.2 List of changes in version 1.2........................................................................1

2 Introduction..........................................................................................................2

3 Description...........................................................................................................3
3.1 Configuration.................................................................................................3
3.2 Basic operation .............................................................................................3
3.3 Available services..........................................................................................3
3.4 TP Configuration ...........................................................................................4

4 Function description ...........................................................................................5


4.1 General remarks ...........................................................................................5
4.1.1 Request function ................................................................................5
4.1.2 Request indication callback................................................................5
4.1.3 Answer function..................................................................................5
4.1.4 Answer indication callback .................................................................5
4.2 Diagnostics services......................................................................................6
4.2.1 StartDiagnosticSession ......................................................................6
4.2.2 StopDiagnosticSession.......................................................................6
4.2.3 SecurityAccess...................................................................................6
4.2.4 TesterPresent .....................................................................................7
4.2.5 EcuReset............................................................................................7
4.2.6 ReadEcuIdentification ........................................................................7
4.2.7 ReadDTCByStatus .............................................................................7
4.2.8 ClearDiagnosticInformation ................................................................8
4.2.9 InputOutputCtrlByLocalId ...................................................................8
4.2.10 ReadMemoryByAddress ....................................................................8
4.2.11 WriteMemoryByAddress.....................................................................8
4.3 Support functions ..........................................................................................9
4.4 Troubleshooting.............................................................................................9
4.4.1 Callbacks are not called .....................................................................9
4.4.2 Service not available ..........................................................................9

5 Example programs ............................................................................................11

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


1

1 History

Author Version Date Changes:

Schmidt 1.0 2003-01-07 Document created

Schmidt 1.1 2003-02-10 Corrections (API, text)

Schmidt 1.2 2004-09-22 Extensions

1.1 List of changes in version 1.1


 Renamed function “KWP_SetResponseTO” to “KWP_SetTimeoutP2”
 Example using normal addressing mode
 Description corrections and extensions

1.2 List of changes in version 1.2


 Added functions for KWP services ReadMemoryByAddress and WriteMemory-
ByAddress (DLL version 1.4.25).

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


2

2 Introduction
Diagnostics is used configure, maintain, support, control and extend an ECU before
or after it is installed in a system, e.g. a vehicle.
Diagnostics is usually performed in a request – response scheme: a tester (client)
sends a request to an ECU (or even more than one ECU) and the ECU(s) (server)
respond(s) by sending a “positive response message” containing the requested in-
formation, or a “negative response”.
The most widely used protocol is the ITU Keyword Protocol 2000 (KWP2000; cf. ISO
15765-3, ISO 14230-3), although many OEMs define their own extensions. For this
development, ISO 14230-3 version 1.5 (1997-10-1) was used.
This DLL provides support for the basic KWP services, allowing nodes simulated in
CANoe to interact with real testers or ECUs. It helps the user by providing direct ac-
cess to the (standard) service parameters.
This document describes the usage of the DLL in CANoe. Knowledge of the underly-
ing transport protocol (ISO/OSEK TP) and CAPL is expected; for the configuration of
the TP please refer to the document OSEK_TP_e.pdf (distributed with CANoe) and
section 3.4 “TP Configuration”.

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


3

3 Description

3.1 Configuration
The KWP2000 add-on for CANoe consists of the files KWP2000.DLL and
KWP2000.INI. The former works as a node layer module for CANoe simulation
nodes. Please refer to the online help documentation, section “Search Sequence for
Nodelayer-DLLs”, for details of the placement of the DLLs. It is recommended to
place the DLL in a directory called “exec32” in the same folder as the configuration
file.
The INI file should be put in the same folder as the DLL file. It has the same format
as the OSEK_TP.INI file for the OSEK TP DLL, so please refer to the documentation
there for details.

3.2 Basic operation


For every KWP service <name>, two functions and two callbacks are defined, one of
each type for the client and the server:
Client Server
Function KWP_<name>R (Request) KWP_<name>A (Answer)
Callback KWP_<name>AI (Answer indication) KWP_<name>RI (request indication)
The client issues a request to the server, the server receives a callback and can
process the request. Then the server sends the answer1 back to the client, where the
answer indication is called, providing the answer from the server.

3.3 Available services


In the current implementation, not all of the KWP2000 services are available in the
DLL. The following services are represented; see function description in section 4 for
details.
StartDiagnosticSession
StopDiagnosticSession
SecurityAccess
TesterPresent
EcuReset
ReadEcuIdentification
ReadDTCByStatus
ClearDiagnosticInformation
InputOutputCtrlByLocalId
ReadMemoryByAddress

According to the standard, an answer is called „response“. But since the term „request“ also starts with the
1

letter ‚r’, it was decided to use the term „answer“ here.

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


4

WriteMemoryByAddress

3.4 TP Configuration
The KWP services rely on the transport protocol to transfer data between client and
server. The address information has to be entered in the database or set dynamically
in CAPL via function calls. The document OSEK_TP_e.pdf contains a detailed de-
scription of the TP setup.
Caveat Instead of „OSEKTL_“, the prefix of all functions is „KWP_“, e.g. instead of
„OSEKTL_SetTgtAdr“, the function is called „KWP_SetTgtAdr“. This allows
the usage of TP and KWP in parallel.
The names of the database attributes remain unchanged.

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


5

4 Function description

4.1 General remarks

4.1.1 Request function


Every request function ends with a capital “R”. The call returns 0 (long) if the request
could be sent without error. The remaining signature depends on the service.
Since the length of function names is limited, the standard names could not be used,
instead they were shortened.

4.1.2 Request indication callback


When the server receives a request, the DLL calls the callback with postfix “RI”. The
signature depends on the service, i.e. the parameter the client sends with the request
are forwarded in the arguments.
The value this callback returns determines the behaviour of the KWP DLL:
Return value DLL behaviour
0 Success: the DLL will send a simple “standard” positive response, where the pa-
rameters are derived from the received parameters (see service descriptions).
>0 The value will be used in a negative response message that the DLL sends to the
client.
-1 The CAPL program takes over the responsibility to send a response, i.e. the DLL
will not send anything to the client.
< -1 Reserved.

4.1.3 Answer function


The signature of every answer function starts with a (long) value that specifies if the
answer is a positive or negative response. If this argument is 0, a positive response
is sent and the remaining arguments will be put into the response primitive.
If the first argument is a value between 0x10 and 0xFF, a negative response is sent,
see standard section 4.4 “Response code value summary table” for the code defini-
tions.

4.1.4 Answer indication callback


After the client receives the answer from the server, the DLL calls the CAPL callback
with the postfix “AI”. Depending on the type of response message received, the first
parameter contains the following values:
First argument DLL behaviour
0 Success. The answer arrived without timeout as a positive response.
>0 A negative response message was received, this value is the response code from
the standard.
-1 Timeout indication: there was no response from the server.
< -1 Reserved.

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


6

4.2 Diagnostics services


For each service the two functions (“R” and “A”) and the two indication callbacks (“RI”
and “AI”) are listed. Please note that many of the arguments are transferred as byte
values and that therefore only the lower 8 bits are used (cf. standard).

4.2.1 StartDiagnosticSession
Type Function/Callback Parameters Description
Long StartSessionR long DiagnosticMode, Request the start of a diagnostic
long BaudRate session, choosing a mode and
transmission rate (use –1 if rate
should not be sent)
Long StartSessionRI long DiagnosticMode, Requested mode and baud rate
long BaudRate (-1 if not transmitted)
Long StartSessionA long code, Return the mode and baud rate
long DiagnosticMode, actually used. If rate = -1, it is not
long BaudRate sent on the bus.
Void StartSessionAI long state, Incoming request or request
long DiagnosticMode state. Also returns the parameter
long BaudRate sent.

Note: The parameter “BaudRate” is normally only used on serial line interfaces,
i.e. not in conjunction with CAN. Most users will set this value to –1.

4.2.2 StopDiagnosticSession
Type Function/Callback Parameters Description
Long StopSessionR Void …
Long StopSessionRI (none)
Long StopSessionA Long code …
Void StopSessionAI Long state …

4.2.3 SecurityAccess
Type Function/Callback Parameters Description
Long SecurityAccessR Long AccessMode, byte Request switch to a protected
data[], dword datalen mode. Server should send key or
seed
Long SecurityAccessRI long AccessMode, byte da- mode and key/seed data, datalen
ta[], dword datalen may be 0
Long SecurityAccessA Long code, long Access- Return key or seed.
Mode, byte data[], dword
datalen
Void SecurityAccessAI long state, long Access- Status and key/seed data.
Mode, byte data[], dword
datalen

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


7

4.2.4 TesterPresent
Type Function/Callback Parameters Description
Long TesterPresentR dword ResponseRequired Periodically sent by the tester
(client) to make the ECU (server)
stay in diagnostic mode. The pa-
rameter indicates whether the
tester expects a response (OEM
specific).
Long TesterPresentRI (none) Standard not clear here!
Long TesterPresentA Long code, dword Respon- Respond if necessary.
seRequired
Void TesterPresentAI Long state …

4.2.5 EcuReset
Type Function/Callback Parameters Description
Long EcuResetR Dword ResetMode
Long EcuResetRI Dword ResetMode
Long EcuResetA Long code, byte data[], Return the reset status. Datalen
dword datalen may be 0.
Void EcuResetAI Long state, byte data[], …
dword datalen

4.2.6 ReadEcuIdentification
Type Function/Callback Parameters Description
Long ReadEcuIdentR Dword option Which data?
Long ReadEcuIdentRI Dword option Requested information
Long ReadEcuIdentA Long code, Byte data[], Return the requested information.
dword datalen
Void ReadEcuIdentAI Long state, byte data[], Status and requested data, if suc-
dword datalen cessful.

4.2.7 ReadDTCByStatus
(Note the name change from „status“ to „state“.)
Type Function/Callback Parameters Description/remarks
Long ReadDTCByStateR dword statusOfDTC, Only 8, resp. 16 bit of the input
dword groupOfDTC parameters are used
Long ReadDTCByStateRI Dword statusOfDTC, Only 8, resp. 16 bit of the input
dword groupOfDTC parameters are used
Long ReadDTCByStateA Long code, Return the requested DTC(s)
byte data[], dword datalen
Void ReadDTCByStateAI Long state, byte data[],
dword datalen

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


8

4.2.8 ClearDiagnosticInformation
Type Function/Callback Parameters Description/remarks
Long ClearDiagInfoR dword groupOfDTC Only 16 bit are used
Long ClearDiagInfoRI dword groupOfDTC Only 16 bit are used
Long ClearDiagInfoA Long code, dword grou- Only 16 bit are used for
pOfDTC groupOfDTC
Void ClearDiagInfoAI Long code, dword grou- Only 16 bit are used for
pOfDTC groupOfDTC

4.2.9 InputOutputCtrlByLocalId
Type Function/Callback Parameters Description/remarks
Long IOCtrlLocalIdR Dword localId, dword con- Datalen may be 0
trol, byte data[], dword
datalen
Long IOCtrlLocalIdRI Dword localId, dword con-
trol, byte data[], dword
datalen
Long IOCtrlLocalIdA Long code, dword localId, Datalen may be 0
dword control, byte data[],
dword datalen
Void IOCtrlLocalIdAI Long code, dword localId,
dword control, byte data[],
dword datalen

4.2.10 ReadMemoryByAddress
Type Function/Callback Parameters Description/remarks
Long ReadMemByAddrR Dword address, dword size 24 bit address
Long ReadMemByAddrRI Dword address, dword size
Long ReadMemByAddrA Long code, byte data[],
dword datalen
Void ReadMemByAddrAI Long code, byte data[],
dword datalen

4.2.11 WriteMemoryByAddress
Type Function/Callback Parameters Description/remarks
Long WriteMemByAddrR Dword address, byte data[], 24 bit address
dword datalen
Long WriteMemByAddrRI Dword address, byte data[],
dword datalen
Long WriteMemByAddrA Long code, dword address
Void WriteMemByAddrAI Long code, dword address

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


9

4.3 Support functions


These functions may be used in CAPL programs to query the state or set parame-
ters, or for often used conversions.
Type Function Parameters Description
Long SetTimeoutP2 dword milliseconds Length of timeout when waiting for
responses, in ms.
Long ResponseCode Dword code, Converts the response code into a
char lineout[], text description. Text will be cut if
dword lineLength the second argument is not large
enough to hold it.
Long ResponseCodeMne Dword code, Converts the response code into
char mnemonic[], the official mnemonic given in the
dword mneLength standard.
Long MnemonicResCode char mnemonic[] Convert the mnemonic given in
the standard (ignoring case) to the
response code. Returns –1 if not
found.
Long ServiceIdMne Dword code, Convert the service id into its
char mnemonic[], mnemonic. Returns 0 if it was
dword mneLength found, not 0 otherwise.
Long LastServiceId (void) Returns the id of the last service
request/answer received, or of the
timeout

4.4 Troubleshooting
This section lists some of the most common problems encountered when using the
DLL and tries to offer solutions.

4.4.1 Callbacks are not called


Problem: Although the correct service primitive is transmitted, the callback is not
called.
Possible causes and solutions:
 The callback signatures are not correct.
Compare the callback definitions (arguments and return value type) with the de-
scription above and correct them. Look for DLL messages on measurement
start; you can increase the write level via the INI file (section [Intern], parameter
“WriteLevel“).
 The addressing parameters are not consistent.
Make sure that the addressing parameters, i.e. addressing mode and Rx- and
Tx IDs (normal mode) resp. ECU number and base address (other modes) are
correct.

4.4.2 Service not available


At the moment, only the listed services are supported by the DLL. If you need addi-
tional standard services, please contact Vector Informatik.

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


10

Please note that a client may send data directly using the “KWP_DataReq” function
(cf. “OSEKTL_DataReq”), which will lead to call of the “KWP_DataInd” callback func-
tion (cf. “OSEKTL_DataInd”) in the server.
In this example, a non-standard service is implemented (without timeout check etc.):
// Tester side ------
MyKWPServiceR( DWORD parameter) {
byte data[5];
data[0] = 0x99; // non-standard ID
data[1] = 0x10; // argument
data[2] = parameter >> 16;
data[3] = parameter >> 8;
data[4] = parameter;
KWP_DataReq( data, 5); // transfer data to ECU
}

MyKWPServiceAI( byte buffer[], long count) {


// process response data
}

KWP_DataInd( long count) {


Byte buffer[4095];
KWP_GetRxData(buffer, elcount(buffer));
if( buffer[0] == 0x99 + 0x40)
{
MyKWPServiceAI( buffer, count);
} // else ...
}

// ECU side ------


KWP_DataInd( long count) {
Byte buffer[4095];
KWP_GetRxData(buffer, elcount(buffer));
if( buffer[0] == 0x99)
{
MyKWPServiceRI( buffer, count);
} // else ...
}

MyKWPServiceRI( byte buffer[], long count) {


long param;
byte data[3];
// process raw data, then send response
data[0] = 0x99 + 0x40;
data[1] = 0x10;
data[2] = 0xEE;
KWP_DataReq( data, 3);
}

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


11

5 Example programs
A KWP demo is provided in the folder Demo_CAN_CN\KWP2000, please refer to the
documentation there.
The following small example demonstrates the usage of the KWP2000 DLL. A data-
base containing the nodes “Client” and “Server” and the following node attribute defi-
nitions and values is necessary:

Node attribute Attribute type Attribute value


TpTxIdentifier Integer “Client”: 0x607 ”Server”: 0x60d
TpRxIdentifier Integer “Client”: 0x60d ”Server”: 0x607
NodeLayerModules String Default: “KWP2000.DLL”
TpAddressingMode Integer [0…3] Default: 0 (normal)

Usage: initiate the session by pressing the space bar and end the session by press-
ing ‘x’. You can set the server state by pressing the keys ‘0’ to ‘4’. Then after pressing
the space bar, different server behaviour can be observed: immediate or delayed re-
sponse/ negative response, and ignoring of the request to provoke a timeout.

Please note that this example does not implement realistic ECU or tester behaviour!

/* ----------------------------------------------------------------------
* File: client.can
* This file implements a simple tester that sends request to an ECU.
*/
variables {
char name[7] = "Tester";
int gServerOpen = 0;
BYTE gKey[20];
msTimer presentTimer;
int gIdent = 0;
}

on key ' ' {


KWP_StartSessionR( 0x01, -1);
}

void KWP_StartSessionAI (long result, long mode, long rate) {


write( "%s: StartSessionAI( %x, %x)", name, result, mode);
if( 0 == result) {
write( "%s: StartSession successful!", name);
// settimer( presentTimer, 1000);
}
else
ReportFailure( "StartSession", result);
}

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


12

on key 'x' {
KWP_StopSessionR();
}

ReportFailure ( char service[], long result) {


char desc[20], mnemonic[10], serviceMne[10];
BYTE lastId;

lastId = KWP_LastServiceId();
KWP_ServiceIdMne( lastId, serviceMne, 10);

if( result < 0) {


write( "%s: %s request (0x%x %s) timed out!",
name, service, lastId, serviceMne);
return;
}
KWP_ResponseCode( result, desc, 20);
KWP_ResponseCodeMne( result, mnemonic, 10);
write( "%s: %s request (0x%x %s) fails: %s (%s)!",
name, service, lastId, serviceMne, mnemonic, desc);
}
on key 'o' {
BYTE mode;
if( !gServerOpen) {
mode = 1;
KWP_SecurityAccessR( 1, gKey, 0);
}
}

KWP_SecurityAccessAI (long code, long mode, BYTE data[], DWORD datalen) {


write( "%s: SecurityAccessAI( 0x%x, 0x%x, ..., %d)", name, code, mode,
datalen);
if( !code && (mode & 1) && datalen >= 8) {
// Seed is returned!
MakeKey( data);
KWP_SecurityAccessR( mode + 1, data, 8);
return;
}
if( !code && (mode & 1) == 0 && datalen > 0 && data[0] == 0x34) {
// Success!
gServerOpen = 1;
return;
}
if( code) {
ReportFailure( "SecurityAccess", code);
} else {
write( "%s: SecurityAccess - unknown error.", name);
}
}

MakeKey (BYTE seedKeyInOut[]) {


int i;
for( i = 0; i < 8; i ++)
seedKeyInOut[i] += 'a' - 'A';
}

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


13

on timer presentTimer {
KWP_TesterPresentR( 1); // Answer expected.
}

KWP_TesterPresentAI (long code) {


// Ignore answer;

// make sure another request is sent.


settimer( presentTimer, 1000);
}

on key 'r' {
KWP_EcuResetR( 27);
}

KWP_EcuResetAI (long code, byte data[], DWORD datalen) {


if( code) {
ReportFailure( "EcuReset", code);
return;
}
write( "%s: EcuReset answer of %d byte.", name, datalen);
}

KWP_ReadEcuIdentAI (long code, BYTE data[], DWORD datalen) {


char line[100];

if( code) {
ReportFailure( "ReadEcuIdent", code);
return;
}

byteToChar( data, line, datalen);


write( "%s: ReadEcuIdent returned \"%s\"", name, line);
}

byteToChar (BYTE source[], char dest[], DWORD len) {


if( elCount(dest) < len-1) len = elCount(dest)-1;

dest[len] = 0;
while( len-- > 0)
dest[len] = source[len];
}

on key 'i' {
KWP_ReadEcuIdentR( gIdent++);
gIdent &= 0x3; // 4 values, 0 is unknown!
}

on key 'd' {
KWP_ReadDTCByStateR( 1, 99);
}

on key 'c' {
KWP_ClearDiagInfoR( 99);
}

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


14

on key 'l' {
BYTE buff[5];
KWP_IOCtrlLocalIdR(27, 1, buff, 5);
}

KWP_IOCtrlLocalIdAI (long state, DWORD localId, DWORD control, byte data[], DWORD
datalen) {
if( state) {
ReportFailure( "IOCtrlLocalIdAI", state);
return;
}
write( "%s: IOCtrlLocalIdAI returned Id %d, control %d and %d byte", name,
localId, control, datalen);
}

KWP_ClearDiagInfoAI (long state, DWORD group) {


if( state) {
ReportFailure( "ClearDiagInfoAI", state);
return;
}
write( "%s: ClearDiagInfoAI returned for group %d", name, group);
}

KWP_ReadDTCByStateAI (long state, BYTE data[], DWORD datalen) {


if( state) {
ReportFailure( "ReadDTCByStateAI", state);
return;
}
write( "%s: ReadDTCByStateAI returned %d byte", name, datalen);
}
/* --------------------------------------------------------------------*/

/* ----------------------------------------------------------------------
* File: server.can
* This file implements a simple ECU that responds to tester requests.
*/
variables {
char name[7] = "Server";
mstimer mytimer;
int state = 0; // answer, delay, deny, delay+deny or ignore request.
int gLocked = -1; // -1: locked, 0: open
long gMode = -1;
}

long KWP_StartSessionRI (long mode, long baudrate) {


long code;

gMode = mode;
write( "%s: received StartSession request, mode %d ", name, mode);
switch( state) {
case 0:
write( "%s: answering immediately.", name);
return 0; // Let DLL handle response, returning same values.

case 1:
case 3:

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


15

write( "%s: delaying answer.", name);


settimer( mytimer, 200);
return -1; // "I will handle response myself."
case 2:
code = KWP_MnemonicResCode( "EnoA");
write( "%s: sending negative response EnoA (0x%x).", name, code);
return code; // "Send this negative response."
case 4:
write( "%s: ignoring to provoke timeout.", name);
// Do not use timer, i.e. ignore request.
return -1; // "I will handle response myself."
}
}

KWP_DataInd (long rxlength) {


write( "%s: got %d byte", name, rxlength);
}

on timer mytimer {
long code;
char desc[20];

if( state == 1) {
write( "%s: sending delayed positive answer to StartSession.", name);
KWP_StartSessionA( 0, gMode, -1);
} else {
code = KWP_MnemonicResCode( "b-RR");
KWP_ResponseCode( code, desc, 20);
write( "%s: sending delayed negative 0x%x answer (%s) to StartSes-
sion.",
name, code, desc);
KWP_StartSessionA( code, -1, -1); // arguments are ignored.
}
}

on key '0' {
// switch server in state "answer immediately to request"
state = 0;
}

on key '1' {
// switch server in state "answer after delay to request"
state = 1;
}

on key '2' {
// switch server in state "answer with negative response"
state = 2;
}

on key '3' {
// switch server in state "delay then deny request"
state = 3;
}

on key '4' {

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


16

// switch server in state "ignore request"


state = 4;
}

long KWP_SecurityAccessRI (long mode, BYTE data[], DWORD datalen) {


BYTE buff[20];
int count;
double number;

if( mode > 0x80 || mode <= 0)


return KWP_MnemonicResCode("ROOR");

if( mode & 1) {


// requestSeed (of level mode/2)
// Compute and send seed
MakeSeed(mode + 1, buff);
KWP_SecurityAccessA( 0, mode, buff, 8);
return -1; // Handle answer myself.
}

// sendKey
MakeSeed( mode, buff);
MakeKey( buff);
if( datalen >= 8 && 0 == bytencmp( buff, data, 8)) {
state = 0; // answer immediately, if possible
gLocked = 0; // key valid, open server
buff[0] = 0x34;
KWP_SecurityAccessA( 0, mode, buff, 1);
return -1;
} else {
state = 2; // deny requests
gLocked = -1;// lock server
return KWP_MnemonicResCode("IK"); // Invalid Key
}

MakeSeed (int seed, BYTE seedOut[]) {


int i;
for( i = 0; i < 8; i ++)
seedOut[i] = (i * i * seed - i + 43) % 26 + 'A';
}

int bytencmp (BYTE a[], BYTE b[], long len) {


while( len-- > 0)
if( a[len] != b[len]) return a[len] - b[len];
return 0;
}

MakeKey (BYTE seedKeyInOut[]) {


int i;
for( i = 0; i < 8; i ++)
seedKeyInOut[i] += 'a' - 'A';
}

long KWP_TesterPresentRI () {

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH


17

return 0; // let DLL answer.

// Here should be a timer monitoring, stopping diagnostics on timeout.


}

long KWP_EcuResetRI (DWORD mode) {


BYTE value[1];
value[0] = 43;
KWP_EcuResetA( 0, value, 1);
return -1;
}

long KWP_ReadEcuIdentRI(DWORD what) {


byte info[100];
int len;
switch( what) {
case 1:
len = charToByte( "KWP2000 Demo", info);
break;
case 2:
len = charToByte( "Vector Informatik", info);
break;
case 3:
len = charToByte( "Trs 2002-05-03", info);
break;
default:
len = charToByte( "???", info);
}
KWP_ReadEcuIdentA( 0, info, len);
return -1;
}

int charToByte (char source[], byte dest[]) {


int i;
i = elCount(source);
while( i-- > 0) {
dest[i] = source[i];
}
return elCount(source) -1;
}

long KWP_StopSessionRI () {
write( "%s: Stopping diagnostics mode.", name);
gLocked = 1;
return -1; // Do not answer ...
}

long KWP_ReadDTCByStateRI( DWORD status, DWORD group) {


BYTE buff[5]; // dummy
write( "%s: ReadDTCByStateRI( %d, %d)", name, status, group);
KWP_ReadDTCByStateA( 0, buff, 5);
return -1;
}

long KWP_ClearDiagInfoRI ( DWORD group) {


write( "%s: ClearDiagInfoRI( %d)", name, group);

© Vector Informatik GmbH KWP2000 User Manual Version 1.2


18

return 0;
}

long KWP_IOCtrlLocalIdRI (DWORD localId, DWORD control, byte data[], DWORD datalen)
{
write( "%s: IOCtrlLocalIdRI( %d, %d, ..., %d)",
name, localId, control, datalen);
return 0;
}/* --------------------------------------------------------------------*/

Version 1.2 KWP2000 User Manual © Vector Informatik GmbH

You might also like