Sunteți pe pagina 1din 3

CAPL Cheat Sheet CAN

Program Structure and Data Types Program Structure and Data Types - continued C-Syntax

Parts marked with *) are not available for CANalyzer. Access to struct members: Operators
gMyStruct.aLong = 22; a = 23 + b; add and assign
Including other Files textually (CAPL Include)
Includes Constants */- multiplication, division, subtraction
{ const <type> = <val>; r = 37 % 7; modulo division for integer, here: 2
#include "MySource.cin" a++; b--; increment or decrement an integer type
} Events c+=22.0; increment and assignment
CAPL is 100% event driven, event handler syntax: -= *= /= decrement, multiplication, division and assignment
Global Variables, <type> = data type on <event type> [additional parameter]
variables { a==b comparison operator „equal“
{ // variable declaration < <= > >= ! = other comparison operators
<type> myVar[=val]; // elementary // program code ! (a<7) && (b>20) logical not(!), and (&&)
<type> myArray[10]; // array } || logical or
char myString[20] [="val"]; &|~ bitwise and, or, complement
} <event type>
^ bitwise exclusive or (XOR)
<type> a) System Events a = 2<<3; bit-shift left (afterwards a is 16)
► signed int(16), long(32), int64(64) ► key 'character' or * keyboard events
► unsigned byte(8), word(16), dword(32), qword(64) ► timer <tmr> Timer expired >> bit-shift right
► Floating point float(64), double(64) ► preStart pre measurement start Please note: Don’t mix up comparison (==) and assignment (=) operator!
► character char(8) ► start after measurement start
If Decision
► Messages message <CAN-id> name ► stopMeasurement before measurement stop if (c <= 50)
message <DBC-Name> name b) Value Objects { // if c <= 50
► Other types Associative Fields  Help ► signal <sig> Signal value changed *) }
Domain specific types  Help ► signal_update <sig> Signal write access *) Optional branches:
Values in round brackets: Number of bits (not in the source code!). ► sysvar <sys> System variable value changed else if ((c > 50) && (c <= 70))
All types are usable as local variables. ► sysvar_update <sys> System variable write access { // if c in [50,70]
elcount(myString) returns the array size. ► envvar Value change environment variable }

Please note: c) Messages else
► Local variables are implicitly static. ► message <msg> CAN1.frmStatus { … } // in all other cases
► No program statements prior to variable declarations ► message <id>-<id> 0x100-999 Switch Selection
► message * any message switch (c) // integer
Comments
{
… // rest of line is comment message [*] All messages, also those that are processed by
/* all inside is comment */ case 50: // if c==50: …
another event handler in this CAPL source code. …
Ctrl-k-c: comment the selected area This break; // leave this branch
Ctrl-k-u: uncomment Event data can be accessed via this. case 100:
case 101: // cntr==100 or cntr==101
Own Types – Enums on key * this = character break;
Type definition in the variables section: on signal this[.raw] = physical [raw] value *) …
enum eMyEnumType {eMyEnum1 [=1],eMyEnum2 [=2]}; on message this.<selector> default: // in all other cases
break;
Declaration of an enum variable & initialization: ► TIME measurement time }
enum eMyEnumType gMyEnum = eMyEnum1; ► ID CAN-ID
► DLC message length (data) For Loop
Usage:
► DIR RX, TX for (initialization; condition; modification):
if (gMyEnum == eMyEnum2)
► CAN channel number int i;
Own Types – Structs ► BYTE(0…7),
for (i=0; i<10; i=i+1)
{ // statements
Type definition in the variables section: WORD(0..6), }
struct DWORD(0…4),
{ QWORD(0) raw data While Loop
int anInt; while(c<50)
► Signals
long aLong; { // statements
on message <msg>
} MyStructType; }
{
Declaration of a struct variable and initialization: this.sigTemp
struct MyStructType gMyStruct [= {20,-1}]; Raw data of the temperature signal is returned (compare to “on signal this“).
Physical values are accessed with .phys.

Page 1 | 3 See all Technical Trainings at


© 2015. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. V1.0 | 2015-10-30 www.vector-academy.com
CAPL Cheat Sheet CAN

C-Syntax - continued CAPL & CANoe - continued Useful CAPL Functions

do while – loop Timer Write Window


Loop is executed at least once ► Write window output void write(char format[], ...);
Declaration in the variables section:
do write("Sig phys=%f, Raw=%d", $sig, $sig.raw);
msTimer myTmr;
{ // statements %... = Format expression
} while (c<50); Simple Timer: %d decimal %4d 4 digits
setTimer(myTmr, <time>); %f float %6.2f 6 digits in total, including 2 dec. places
Please note: %x hex %08X 8 digits, leading zeroes, capital letters
Start periodic timer, times in milliseconds:
Do not implement infinite loops. CANoe must be terminated via task manager. %s string for character arrays
setTimerCyclic(myTmr,<period>[,first period]);
Functions
Stopping ► writeCreate create a new write window tab  Help
[<return type>] MyFunction (<type> arg1, …)
cancelTimer(myTmr);
{ ► writeClear clear a write tab  Help
[return [constant | Variable];] Check if active: ► writeEx extended write  Help
} isTimerActive(myTmr) ► snprintf output to a string buffer  Help
return type: int, long, int64, byte, word, dword, float, double Event Handler Interaction Layer (control from within the node)
void: no return value on timer myTmr ► Stop message sending
{ … } ILDisableMsg(<msg>)
Calling a function
[var=]MyFunction([val][,val]…); Messages ► Activate message sending
ILEnableMsg(<msg>)
Signals and system variables as function parameters Declaration of message variables: ► Other:
void MyFunction(signal *sig, sysvar * sys) message <*|id|msg> myMsg;
IL…()  Help
{
$sig = 20.0; Modification:
@sys = 20.0; myMsg.<selector> = <val>;
$sig = DBLookup(sig).maximum; // see attributes <selector> see section this.
}
DBlookup(…) allows to access database attributes. Copy messages: CAPL Tips
myMsg2 = myMsg1;
CAPL & CANoe ► Watch for compiler warnings, enable them all in CANoe options
or in an event handler (e.g. a gateway)
on message CAN1.*
► Use comments
Signals and system variables should be accessed via symbol explorer or per auto- { ► Use name prefixes, e.g.
completion. message * myMsg2; c<Name> constants
myMsg2 = this; g<Name> global variables
Signals myMsg2.sigA = this.sigA * 2.0; ut<Name> utility functions
$<sig> = 1; phys. signal value is set and with next message it myMsg2.CAN = 2; p<Name> Function parameters
will be sent by the interaction layer. output(myMsg); // send
► Avoid complex calculations in conditions (readability, debugging)
}
$<sig>.raw = 1; assign signal raw data Instead: assign intermediate results to local variables
access last received Signal[raw] value. Attributes ► Even if not needed for single statements after if: use curly brackets
v = $<sig>[.raw];
Physical values are of type double. Attribute names with (*) are OEM specific. Vector IL: ► Event handler should not be a long runner
<msg>.<attribute> ► Allow reuse with CAPL include files
System Variables ► Return values should be assigned to local variables.
► GenMsgSendType*
Assigning values: Their values are visible when debugging.
@<sys> = 1;
► GenMsgCycleTime*
@sysvar::<sys> is also possible
► GenMsgILSupport*
Notation on this Sheet
<sig>.<attribute>
Reading values:
► GenSigStartValue* <> mandatory
if (@<sys>==2.0)
► GenSigInactiveValue* [] optional or array index
Special system variables, arrays: ► GenSigSendType* val value or string
SysSetVariable<type>(<sys>,buffer[]); ► factor // for conversion sig a signal name
SysGetVariable<type>(<sys>,buffer[],size); ► offset // for conversion sys a system variable name
<type>: String, IntArray, LongArray, FloatArray, Data ► unit // string var a CAPL variable
► maximum // physical my… user identifier
SysVar with conversion formula also as .raw for raw values
► minimum // physical msg message name
 Help see online help (F1)

Page 2 | 3 See all Technical Trainings at


© 2015. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. V1.0 | 2015-10-30 www.vector-academy.com
CAPL Cheat Sheet CAN

Test Modules *) Test Modules - continued Test Modules - continued


Check as constraint (=observation of the test environment)
Structure Waiting for Events  Help:
long testWaitFor<what>(…, <max time in millisec.>); or as condition (=observation of the ECU behavior). Both write events to the
MainTest is called upon test module start and determines the sequence of test
<what> report and impact the verdict:
cases. Test groups organize the test module structure and reporting.
testAdd<Condition|Constraint>(dword[,1])
void MainTest() ► Timeout fixed time span
{ With the optional second parameter being 1 the verdict is not influenced.
► SignalIn/OutSideRange sys / sig value within / outside range
… variables declaration ► SignalMatch sys / sig value Stimulations
MyTestcase1(…);
► ValueInput user input Create signal value sequences. Creation with
testGroupBegin (<title>, <description>);
► Message message reception <dword> = stmCreate_<what>(<signal>,<parameter>)
MyTestcase1(…);
… ► TesterConfirmation user confirmation  Help <what>
MyTestcaseN(…); ► MeasurementEnd wait for measurement end ► CSV comma separated values
testGroupEnd(); ► Ramp
Return value: 0 = timeout; 1 = event
} ► Toggle
Functions marked with testcase are test cases. They do not have return Evaluation ► …  Help
values. Using C statements:
testcase MyTestcase1()
Control:
if … else …
{ … } stmControl_Start|Stop(<dword>)
Better for signals and system variables:
Accordance with Simulation Nodes: testValidateSignalMatch("id",<Sys/Sig>,<val>); Diagnostics
testValidateSignalIn/OutRange -> Help Diagnostic objects must be declared. The service qualifier should be inserted via
► All event handler
► C-syntax Reporting Drag & Drop from the Symbol Explorer:
testCaseTitle DiagRequest <service qualifier> myReq;
► Data types DiagResponse <service qualifier> myResp;
► System variables und signal access testModuleTitle
teststep[Pass|Fail]("id", "text …%d text", <var>); Selecting the diagnostic target:
Test verdict testreportAdd<what>(…) DiagSetTarget("<ECU qualifier>");
Every test step, test case, test group and the test module has a test result Fail or <what>
Pass. ► EngineerInfo Set a request parameter, the parameter qualifier taken from the Symbol
► ExternalRef Explorer:
Test cases diagSetParameter(myReq, "<Parameter>", val);
► Image
Most test cases can be structured logically into three phases:
► WindowCapture Send:
1. Stimulation: signals, IOs, messages …
► …  Help DiagSendRequest(myReq);
2. Wait for a reaction
3. Evaluation Fault Insertion Wait for a response:
From the test module for all simulation nodes int = testWaitForDiagResponse(myName,10000);
The phases are made of test steps that set the test verdict:
testcase myTestcase() ► TestDisableMessage<(msg>) Evaluation, the response can be addressed with the request (request and
{ … ► TestEnableMessage(<msg>) response belong together):
testStep<Pass|Fail>("id", "description"); ► TestEnableCRCCalculation(<msg> double = DiagGetResponseParameter(myReq, "Para");
… ► TestResetAllFaultInjections()
testStep ("id", "description"); // w/o verdict Alternative:
► …  Help DiagGetLastResponse(myReq, myResp);
}
id is a user definable text for identification. Background Checks Other functions:
Configuration: (identification is done with a dword handle) ► DiagGetLastResponseCode(myReq) -1 upon positive response,
Functions / Test Functions <dword> = ChkCreate_<checktype> (<parameter>)
Frequently used tests should be implemented as test functions or functions ( for else negative response code
<Check type>
re-use). Both produce different reporting data. ► DiagGetComplexParameter(…) dynamic data  Help
► MsgAbsCycleTimeViolation
► Diag…  Help
Stimulation ► ErrorFramesOccured
@<sys> = <val>; // system variable ► …  Help Test Module Tips
$<sig> = <val>; // with interaction layer
Control:
output(<msg>); // local message object ► Implement functions for re-use in test cases (readability, maintenance,
chkControl_<Start|Stop|Reset|Destroy(<dword>)
effort).
Evaluation: ► Check return values and document problems with TestStepFail().
chkQuery_<what>(<dword>)
<what>
► NumEvents
► EventStatus
► …  Help

Page 3 | 3 See all Technical Trainings at


© 2015. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. V1.0 | 2015-10-30 www.vector-academy.com

S-ar putea să vă placă și