CAPL CheatSheet
CAPL CheatSheet
CAPL CheatSheet
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 less or equal to 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]}; default: // in all other cases
on message this.<selector>
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 for (i=0; i<10; i=i+1)
► BYTE(0…7), { // statements
Type definition in the variables section: WORD(0..6), }
struct MyStructType DWORD(0…4),
{ QWORD(0) raw data While Loop
int anInt; while(c<50)
► Signals { // statements
long aLong; on message <msg>
}; }
{
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.
CAPL & CANoe or in an event handler (e.g. a gateway) ► Watch for compiler warnings, enable them all in CANoe options
on message CAN1.* ► Use comments
{ ► Use name prefixes, e.g.
Signals and system variables should be accessed via symbol explorer or per auto- message * myMsg2;
completion. c<Name> constants
myMsg2 = this;
myMsg2.sigA = this.sigA * 2.0;
g<Name> global variables
Signals ut<Name> utility functions
myMsg2.CAN = 2;
$<sig> = 1; phys. signal value is set and with next message output(myMsg); // send p<Name> Function parameters
it will be sent by the interaction layer. } ► 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
v = $<sig>[.raw]; ► Even if not needed for single statements after if: use curly brackets
Physical values are of type double. Attribute names with (*) are OEM specific. Vector IL: ► Event handler should not be a long runner
$<sig> =<msg>.<sig>::<text> Access to text table definitions <msg>.<attribute> ► Allow reuse with CAPL include files
► GenMsgSendType* ► Return values should be assigned to local variables.
System Variables
► GenMsgCycleTime* Their values are visible when debugging.
Assigning values:
@<sys> = 1;
► GenMsgILSupport* ► Check return values
Notation on this Sheet
@sysvar::<sys> is also possible <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
► unit // string var a CAPL variable
<type>: String, IntArray, LongArray, FloatArray, Data ► 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)