Вы находитесь на странице: 1из 2

Tips and tricks for the

Tools

use of CAPL (part 3)


The third and final part of this series presents tips and tricks for advanced
users. Topics include associative arrays, performance, memory needs, and
other database access options.

signals generally exhibit ar-


Authors
U nlike languages such as
C, CAPL does not sup-
port any pointer objects as
maps string keys (without
length limitation!) to string
values up to 30 characters.
bitrary bit lengths and posi-
tions within the data payload
a reference data type and The following example uses of a message. They can also
therefore has no dynam- lastTime to store a time val- be stored in either Intel or
ic memory management. ue for each message ID oc- Motorola format.
This makes CAPL very ro- curring on the CAN network: Symbol-based access
bust, and therefore well-suit- via a signal name relieves
ed for runtime environments on message CAN1.*{ the CAPL user of all of these
that are short on memory lastTime [this.id] details. In the case of read-
Marc Lobmeyer and difficult to debug. In par- = this.time; ing or setting a signal value,
ticular, CANoe's "CAPL-on- } the CAPL compiler automat-
Board" feature benefits from ically accounts for the sig-
this; in order to improve re- 7R HQKDQFH WKH XVHU·V QDO·V SUHFLVH ELW SDWWHUQ WKDW
al-time behavior, it executes experience, CAPL provides may include masking, swap-
programs directly on cer- the following list of methods ping and shifting the bits.
tain hardware bus interfac- for associative array vari- To enhance user friend-
es. Having said that, memo- ables using dot notation: liness, other definable ob-
ry is seldom in short supply X ContainsKey queries jects in the database may
LQWKH:LQGRZV·UXQWLPHHQ- whether a specific key is improve the linguistics of
Roman Marktl vironment. Therefore in this already contained; CAPL programming. For ex-
runtime environment CAPL X Size returns the number ample, symbolic value tables
Vector Informatik GmbH offers associative arrays that of contained keys; may be associated with sig-
Ingersheimer Str. 24 can be used to store data X Remove removes one nals to use plain text names
DE-70499 Stuttgart even if the amount of data to key from the associative for signal value states. Fur-
Tel.: +49-711-80670-0 be stored is unknown at the array; thermore, authors of a da-
Fax: +49-711-80670-111 program start. Associative X Clear fully empties an as- tabase have the freedom to
arrays are containers which sociative array. define other attribute objects
Link are equivalent to maps or dy- In fact, Remove and Clear and to use them in the pro-
www.vector.com namic arrays of other pro- free up memory. gram code.
gramming languages. Inter- Finally, there is a spe- CAPL is able to use
nally, CAPL uses an efficient cial form of the for instruction database objects direct-
hash table for these arrays. for associative arrays. This ly based on their symbolic
Consequently, these spe- form iterates over all keys ac- names. However, sometimes
cial arrays enable saving bus tually contained in lastTime: the potential objects of inter-
CAN Newsletter (print) messages or measurement est are not known at the time
Tips and tricks for the use values, even if it is unknown for (long akey: lastTime) of program implementation.
of CAPL (part 1) in advance which messages {[…]} … Therefore, the CAPL user
or how many measurement may dynamically access the
values will occur. Access to databases symbolic names and proper-
In CAPL, associative ties such as message names
arrays are declared as sim- Part 1 of this article series al- and identifiers transmitted
ple arrays, but with a key ready illustrated the primary by a network node. A brief
type instead of the otherwise use of bus-specific databas- example:
usual size entry. Two exam- es in CAPL: they make it pos-
message * m;
Tips and tricks for the use ples of associative arrays: sible to introduce names for
int i, mx;
of CAPL (part 2) messages and signals. From
mx=elcount(aNet::aNode.Tx);
long lastTime [long]; a programming perspective,
for (i = 0; i < mx; ++i)
char[30] translate[ char[] ]; the complicated aspect of
{
signals is that they are usu-
m.id=aNet::aNode.TX[i];
The variable lastTime is ally tightly packed in the data
write(DBLookup(m).Name);
an array that maps long keys payload of messages for ef-
}
to long values, while translate ficiency reasons. Therefore,

18 CAN Newsletter 4/2014


These symbolic ac- that react to events. Some ables, which they could ac- CAPL programs should
Tools
cess methods allow the of these events may occur tually share. An example: also not crash in case of
user to implement generic very frequently. Therefore, faulty usage. On one hand,
programs – together with a program's performance testcase test789() this robustness is attained
the previously introduced is significantly better if { by the language structure,
associative arrays. only those events get pro- char outBuffer[1024]; since there are no general
cessed, which are con- [..] pointers. On the other hand,
Performance cerned. For example, if stability is improved by auto-
the user is only interested There are CAPL pro- matic runtime checks of ar-
Most CAPL programs must in those Flexray slots that grams with thousands of ray limits, stack limits and
meet non-trivial real-time contain a specific signal, it such test procedures, of the necessary computing
conditions. The execution is more efficient to define which only one may be ex- time.
model of a node simulated on frSlot signalname ecuted at any given time. A separate command-
with CAPL even follows the than on frSlot *. Rather than defining a large line version of the compiler
model concept that CAPL Signal edges: there local variable of the same is available. This version
programs can be execut- are two event procedure type in each event proce- is very helpful in automat-
ed at any speed (see part versions for signals and dure, defining the large vari- ing sequences in script
2 of this series of articles). system variables. on sig- able once globally in the languages.
To adequately approach nal_update and on sys- Variables section utilizes a
this ideal, CAPL programs var_update are called with lot less memory. Concluding Remarks
are compiled, i.e. they are each write access to the Another inadvisable
compiled into the machine specific data objects, even practice is to create very This series of articles
language of the specific LIWKHREMHFW·VYDOXHKDVQRW large arrays, e.g. to store has introduced CAPL as an
executing microprocessor. changed at all. By contrast, event data under the respec- example of a problem-ori-
Moreover, optimized code on signal_change (on sig- tive message IDs. An ex- ented programming lan-
sequences are used for nal in short) and on sysvar_ tended ID in CAN comprises guage. The familiar C lan-
the often complex access change (on sysvar in short) 29 bits, so it can assume guage syntax of CAPL
to signals. Below are a few offer a performance advan- over 500 million values. To VLPSOLILHV WKH XVHU·V OHDUQ-
tips on how the user can af- tage if only signal edges define an array for this pur- ing curve. Specific symbolic
fect performance. are to be handled. Those pose would be a waste of databases and concepts for
writeEx(): the write event procedures are op- memory. In such cases, it using CAPL in simulation,
function is used to output timized to trigger on value is better to use associative emulation, and testing of
specific texts to the Write changes only. arrays as described above. fieldbus nodes support the
window in CANoe and Although associative arrays application domains. Vector
CANalyzer. As an alterna- Memory needs need somewhat more mem- is carefully and continually
tive, the writeEx function ory for each key that is actu- extending the language in a
is available for outputting Unlike most block-orient- ally used, they do not need way that maintains compati-
larger quantities of data. ed languages, such as C, any memory for keys that bility with previous versions
For one, it can be used to all locally defined variables are not used. while cultivating new appli-
write directly to the Trace in CAPL are static by de- cation areas.
window or to a log file. The fault. This means that they Useful, relatively
text output generated by are all created at the pro- unknown features
writeEx is in all respects gram start, and memory
treated like a bus event, in- used to store these vari- CAPL offers a number of
cluding the high priority pro- ables is not freed until the less familiar and mainly
cessing and synchronizing end of the program. Con- newer features:
the time stamps with real sequently, CAPL may re- Structs can be used to
bus events. quire a surprisingly large define structures, similar to
Event procedures: a amount of memory if many the approach in C. Togeth-
CAPL program consists of a event procedures define er with copying operations,
combination of procedures the same type of large vari- which can also convert Intel
and Motorola formats with-
in a struct, they represent
CAPL a flexible method for data
conversion.
CAPL is a procedural programming language similar When CAPL functions
to C, which was developed by Vector Informatik. are called, the user has the
The execution of program blocks is controlled by option of passing reference
events. CAPL programs are developed and compiled parameters in addition to
in a dedicated browser. This makes it possible to value parameters. Refer-
access all of the objects contained in the database ence parameters make it
(messages, signals, environment variables) as well possible to return more than
as system variables. In addition, CAPL provides one result value from a func-
many predefined functions that support working with tion. Reference parame-
the CANoe and CANalyzer development, testing and ters can also be used within
simulation tools. CAPL–DLLs.

20 CAN Newsletter 4/2014

Вам также может понравиться