CAPL is an acronym for Communication Access Programming Language, which is a programming language used in Vector testing tools chain. It is used to create:
Simulation network nodes
Measurement, analysis components
Testing modules
All of the images in this article are captured from Vector CANoe tool and their example projects.
Some characteristics of CAPL script are:
C like syntax.
Event-driven (individual functions(evaluate, set signal values, send messages) that react to received messages, expired timers event, change of a signals or in the environment).
CAPL program can be developed(.can, .cin) and compiled(.cbf) using Vector tool CAPL Browser(IDE).
Direct access to messages, signals, system variables and diagnostic parameters(via database file such as DBC CDD because CAPL Browser is integrated with CANoe,CANalyzer tool chain).
Can link to user dll(e.g. diagnostic operation: encryption API, security key/seed calculation).
.can: is execution code and compiled .cin: is for common/library function, and shall be included by .can
I. Program Structure
Sample CAPL script - simulation node that monitor CAN message and update the sysvar value to be displayed on CANoe Panel
Above sample script shall be stored in a *.can file, which then shall be complied with CAPL Compiler into executable file in CBF(CAPL Binary Format *.cbf). For a test node, main section of CAPL test script are:
I.1 include
Include files contain arbitrary but complete sections of a CAPL program: includes, variables and functions. All variables and functions that are included via the Include files will be available as global variables and functions.
The sequence of inclusion is irrelevant. The compiler reports any duplicate symbols as an error between included files and between included files and the main program. Code and data from included and parent files may use each other mutually.
One exception to the prohibition of duplicate symbols is that on start, on preStart, on preStop and on stopMeasurement may coexist in both the included file and the parent file. In these functions, the code is executed sequentially: first the code from the included file and then the code from the parent file. This means that the Include files are used to perform three tasks: declare data types, define variables and provide an (inline) function library.
I.2 variable
CAPL program variables can be declared in each function as local variable or under variables section as global variables.
NOTE: CAPL only allow declare local variable at the beginning portion of the function.
Struct, array, associative field, object, when used as function parameter will be passed as reference by default.
Other primitive data type has to used & to mark that it shall be passed as reference. E.g. void Function(byte& ref); Function(var);
sysvar or System Variables are defined under tab Environment/System Variables, it can be accessed everywhere in CANoe configuration. We define user sysvar to shared, route data around testing environment between test nodes, simulated nodes, measurement nodes, CANoe panel. CANoe also provide sysvar so test nodes can interact with other component in a testing environment such as VT System.
signal representation of the bus signals. Access to the signals is carried out with the syntax $signal, in addition you can specify the read/write operation either be raw or phys $signal.raw, $signal.phys
keep in mind, signal value does not change immediately, only after the signal is being transmitted again on the network then it can be said to be updated, and read out value is the last value transmitted on the network.
I.3 on <event>
Except for the testcases, which can be called on test execution, all of the CANoe nodes are operated base on event processing. In a test nodes most of the time, you don’t need to define the event handler, because CANoe provide a very well defined API libraries, that we can use to create a sequential testing operation (e.g. TestWaitFor* API to wait for certain event to occur). But some time, you might need access to a lower layer level of data, which can not be provide by CANoe API or you just want to create a custom procedure to filter event, in that cases define these on <event> handle and a notification mechanism(e.g. using sysvar, text event notification) will help you a lot during testing process.
I.4 functions
I.5 testcases
II. Execution Concept
A key difference between CAPL and C or C++ relates to when and how program elements are called. In C, for example, all processing sequences begin with the central start function main(). In CAPL, on the other hand, a program contains an entire assortment of procedures of equal standing, each of which reacts to external events: