Teledyne CATC References Manual

PROTOCOL SOLUTIONS GROUP 3385 SCOTT BLVD SANTA CLARA, CA 95054
Reference Manual
Manual Version 1.20
For all software versions
October 2013
CATC Scripting Language Teledyne LeCroy
Document Disclaimer
The information contained in this document has been carefully checked and is believed to be reliable. However, no responsibility can be assumed for inaccuracies that may not have been detected.
Teledyne LeCroy reserves the right to revise the information presented in this document without notice or penalty.
Trademarks and Servicemarks
Teledyne Lecroy is a trademark of Teledyne LeCroy. All other trademarks are property of their respective companies.
Copyright
Copyright © 2002-2012, Teledyne LeCroy, Inc. All Rights Reserved. This document may be printed and reproduced without additional permission, but all copies
should contain this copyright notice.
ii
CATC Scripting Language
Table of Contents
iii
TABLE OF
C
ONTENTS
Table of Contents . . ... ... .... ... ... .... ... ... .... ... . iii
1 Introduction ... ... ... ... .... ... ... .... ... ... .... ... . . 1
Features of CATC Script i n g La nguage .............................. 1
2 Values . ... .... ... ... ... .... ... ... .... ... ... .... ... . . 3
Literals ...................... ................................. 3
Integers ................... ................................. 3
Strings ................... ................................. 3
Escape Sequences ........ ................................. 4
Lists ..................... ................................. 4
Raw Bytes ................ ................................. 4
Null ..................... ................................. 4
Variables .................... ................................. 5
Global Variables ........... ................................. 5
Local Variables ............ ................................. 6
Constants .................... ................................. 6
3 Expressions .... ... ... ... .... ... ... .... ... ... .... ... . . 7
select
expression ............. ................................. 7
4 Operators . .... ... ... ... .... ... ... .... ... ... .... ... . . 9
Operations ................... ................................. 9
Operator Precedence and Associativity .............................. 9
5 Comments . .... ... ... ... .... ... ... .... ... ... .... ... . 17
6 Keywords . .... ... ... ... .... ... ... .... ... ... .... ... . 19
7 Statements . .... ... ... ... .... ... ... .... ... ... .... ... . 21
Expression Statements .......... ................................ 21
if Statements ................. ................................ 21
if-else Statements .............. ................................ 21
while Statements .............. ................................ 22
for Statements ................ ................................ 22
return Statements .............. ................................ 23
Compound Statements .......... ................................ 24
CATC Scripting Language
Table of Contents
iv
8 Preprocessing . . ... ... ... .... ... ... .... ... ... .... ... . 27
9 Context ... .... ... ... ... .... ... ... .... ... ... .... ... . 29
10 Functions . . .... ... ... ... .... ... ... .... ... ... .... ... . 31
11 Primitives . .... ... ... ... .... ... ... .... ... ... .... ... . 33
Call() ....................... ................................ 33
Format() ..................... ................................ 33
Format Conversion Characters ................................ 34
GetNBits() ................... ................................ 35
NextNBits() .................. ................................ 36
Resolve() .................... ................................ 37
Trace() ...................... ................................ 37
12 Decoder Primitives . ... ... .... ... ... .... ... ... .... ... . 39
Abort() ...................... ................................ 39
AddCell() .................... ................................ 39
AddDataCell() ................ ................................ 41
AddEvent() ................... ................................ 42
AddSeparator() ................ ................................ 43
BeginCellBlock() .............. ................................ 43
Complete() ................... ................................ 46
EndCellBlock() ............... ................................ 47
GetBitOffset() ................ ................................ 47
PeekNBits() .................. ................................ 48
Pending() .................... ................................ 48
Reject() ...................... ................................ 49
13 Modules ... .... ... ... ... .... ... ... .... ... ... .... ... . 51
Module Functions ............. ................................ 51
ProcessData() .............. ................................ 51
CollectData() .............. ................................ 51
BuildCellList() ............. ................................ 51
Module Data ................. ................................ 52
ModuleType ............... ................................ 52
OutputType ............... ................................ 52
InputType ................. ................................ 52
LevelName ................ ................................ 52
DecoderDesc .............. ................................ 52
Icon ..................... ................................ 53
How to Contact Teledyne LeCroy ….... .... ... ... .... ... . 51
CATC S
Reference Manual
C
1
Introduction
1
CRIPTING LANGUAGE
HAPTER
CHAPTER 1:
CATC Scripting Language (CSL) was developed to create scripts that would allow users to do file-based decoding with CATC USBTracer, USBMobile, and USBAd­visor analyzers. CSL is used to edit CATC Decode Scripting (CDS) files. CATC analyzers are equipped with built-in decoders in addition to script-based decoders that can be modified by the users or implemented as-is. Decoding scripts for analyzers are distributed in the /scripts directory. These scripts are tools to decode and display transactions. Users can also add entirely new, customized decoders.
CSL is based on C language syntax, so anyone with a C programming background will have no trouble learning CSL. The simple, yet powerful, structure of CSL also enables less experienced users to easily acquire the basic knowledge needed to start writing custom scripts.
I
NTRODUCTION
Features of CATC Scripting Language
Powerful -- provides a high-level API while simultaneously allowing
implementation of complex algorithms.
Easy to learn and use -- has a simple but effective syntax.
Self-contained -- needs no external tools to run scripts.
Wide range of value types -- provides efficient and easy processing of data.
Used to create built-in script-based decoders for analyzers.
May be used to write custom decoders.
General purpose -- is integrated in a number of CATC products.
New in CSL Version 1.1
Compound assignment operators added
Increment and decrement operators added
New in Document Revision 1.11
Fixed typos in examples for Call(), GetNBits(), NextNBits(),
Trace(), GetBitOffset(), and PeekNBits().
New in Document Revision
Added new CATC
address.
1.12
C
2
Values
CATC Scripting Language
2
HAPTER
CHAPTER 2:
V
ALUES
There are five value types that may be manipulated by a script: integers, strings, lists, raw bytes, and null. CSL is not a strongly typed language. Value types need
not be pre-declared. Literals, variables and constants can take on any of the five value types, and the types can be reassigned dynamically.
Literals
Literals are data that remain unchanged when the program is compiled. Literals are a way of expressing hard-coded data in a script.
Integers
Integer literals represent numeric values with no fractions or decimal points. Hexa­decimal, octal, decimal, and binary notation are supported:
Hexadecimal numbers must be preceded by 0x: 0x2A, 0x54, 0xFFFFFF01 Octal numbers must begin with 0: 0775, 017, 0400 Decimal numbers are written as usual: 24, 1256, 2 Binary numbers are denoted with 0b: 0b01101100, 0b01, 0b100000
Strings
String literals are used to represent text. A string consists of zero or more characters and can include numbers, letters, spaces, and punctuation. An empty string ("") contains no characters and evaluates to false in an expression, whereas a non-empty string evaluates to true. Double quotes surround a string, and some standard backslash (\) escape sequences are supported.
String Represented text
"Quote: \"This is a string literal.\""
"256"
"abcd!$%&*" abcd!$%&*
Quote: "This is a string literal."
**Note that this does not represent the integer
256
256, but only the characters that make up the number.
"June 26, 2001" June 26, 2001
"[ 1, 2, 3 ]" [ 1, 2, 3 ]
Table 2.1: Examples of String Literals
C
2
Values
CATC Scripting Language
3
Escape
double quote
\"
"\"Quotes!\""
"Quotes!"
Escape Sequences
These are the available escape sequences in CSL:
HAPTER
Character
backslash
horizontal tab \t "Before tab\tAfter tab" Before tab After tab newline
single quote
Sequence Example
\\
\n
\'
"This is a backslash: \\"
"This is how\nto get a newline."
"\'Single quote\'"
Output
This is a backslash: \
This is how to get a newline.
'Single quote'
Table 2.2: Escape Sequences
Lists
A list can hold zero or more pieces of data. A list that contains zero pieces of data is called an empty list. An empty list evaluates to false when used in an expression, whereas a non-empty list evaluates to true. List literals are expressed using the square bracket ([]) delimiters. List elements can be of any type, including lists.
[1, 2, 3, 4] [] ["one", 2, "three", [4, [5, [6]]]]
Raw Bytes
Raw binary values are used primarily for efficient access to packet payloads. A literal notation is supported using single quotes:
'00112233445566778899AABBCCDDEEFF'
This represents an array of 16 bytes with values starting at 00 and ranging up to 0xFF. The values can only be hexadecimal digits. Each digit represents a nybble
(four bits), and if there are not an even number of nybbles specified, an implicit zero is added to the first byte. For example:
'FFF'
is interpreted as
'0FFF'
Null
Null indicates an absence of valid data. The keyword null represents a literal null value and evaluates to false when used in expressions.
C
2
Values
CATC Scripting Language
4
result = null;
Variables
Variables are used to store information, or data, that can be modified. A variable can be thought of as a container that holds a value.
All variables have names. Variable names must contain only alphanumeric charac­ters and the underscore ( _ ) character, and they cannot begin with a number. Some possible variable names are
x _NewValue name_2
A variable is created when it is assigned a value. Variables can be of any value type, and can change type with re-assignment. Values are assigned using the assignment operator ( = ). The name of the variable goes on the left side of the operator, and the value goes on the right:
x = [ 1, 2, 3 ] New_value = x name2 = "Smith"
If a variable is referenced before it is assigned a value, it evaluates to null.
HAPTER
There are two types of variables: global and local.
Global Variables
Global variables are defined outside of the scope of functions. Defining global variables requires the use of the keyword set. Global variables are visible through­out a file (and all files that it includes).
set Global = 10;
If an assignment in a function has a global as a left-hand value, a variable will not be created, but the global variable will be changed. For example
set Global = 10; Function()
{
Global = "cat"; Local = 20;
}
C
2
Values
CATC Scripting Language
5
will create a local variable called Local, which will only be visible within the function Function. Additionally, it will change the value of Global to "cat", which will be visible to all functions. This will also change its value type from an
integer to a string.
Local Variables
Local variables are not declared. Instead, they are created as needed. Local variables are created either by being in a function's parameter list, or simply by being assigned a value in a function body.
Function(Parameter) {
Local = 20;
}
This function will create a local variable Parameter and a local variable Local, which has an assigned value of 20.
HAPTER
Constants
A constant is similar to a variable, except that its value cannot be changed. Like variables, constant names must contain only alphanumeric characters and the un­derscore ( _ ) character, and they cannot begin with a number.
Constants are declared similarly to global variables using the keyword const:
const CONSTANT = 20;
They can be assigned to any value type, but will generate an error if used in the left­hand side of an assignment statement later on. For instance,
const constant_2 = 3; Function()
{
constant_2 = 5;
}
will generate an error. Declaring a constant with the same name as a global, or a global with the same name
as a constant, will also generate an error. Like globals, constants can only be declared in the file scope.
C
3
Expressions
CATC Scripting Language
6
HAPTER
CHAPTER 3:
E
XPRESSIONS
An expression is a statement that calculates a value. The simplest type of expression is assignment:
x = 2
The expression x = 2 calculates 2 as the value of x. All expressions contain operators, which are described in Chapter 4, Operators, on
page 9. The operators indicate how an expression should be evaluated in order to arrive at its value. For example
x + 2
says to add 2 to x to find the value of the expression. Another example is
x > 2
which indicates that x is greater than 2. This is a Boolean expression, so it will evaluate to either true or false. Therefore, if x = 3, then x > 2 will evaluate to true; if x = 1, it will return false.
True is denoted by a non-zero integer (any integer except 0), and false is a zero integer (0). True and false are also supported for lists (an empty list is false, while all others are true), and strings (an empty string is false, while all others are true), and null is considered false. However, all Boolean operators will result in integer values.
select expression
The select expression selects the value to which it evaluates based on Boolean expressions. This is the format for a select expression:
select {
<expression1> : <statement1> <expression2> : <statement2> ...
};
The expressions are evaluated in order, and the statement that is associated with the first true expression is executed. That value is what the entire expression evaluates to.
C
3
Expressions
CATC Scripting Language
7
x = 10 Value_of_x = select {
x < 5 : "Less than 5"; x >= 5 : "Greater than or equal to 5";
};
The above expression will evaluate to “Greater than or equal to 5” because the first true expression is x >= 5. Note that a semicolon is required at the end of a select expression because it is not a compound statement and can be used in an expression context.
There is also a keyword default, which in effect always evaluates to true. An example of its use is
Astring = select {
A == 1 : "one"; A == 2 : "two"; A == 3: "three"; A > 3 : "overflow"; default : null;
};
If none of the first four expressions evaluates to true, then default will be eval- uated, returning a value of null for the entire expression.
select expressions can also be used to conditionally execute statements, similar to C switch statements:
select {
A == 1 : DoSomething(); A == 2 : DoSomethingElse(); default: DoNothing();
};
In this case the appropriate function is called depending on the value of A, but the evaluated result of the select expression is ignored.
HAPTER
C
4
Operators
CATC Scripting Language
8
HAPTER
CHAPTER 4:
O
PERATORS
An operator is a symbol that represents an action, such as addition or subtraction, that can be performed on data. Operators are used to manipulate data. The data being manipulated are called operands. Literals, function calls, constants, and variables can all serve as operands. For example, in the operation
x + 2
the variable
x
and the integer 2 are both operands, and + is the operator.
Operations
Operations can be performed on any combination of value types, but will result in a null value if the operation is not defined. Defined operations are listed in the Operand Types column of Table 4.2 on page 12. Any binary operation on a null and a non-null value will result in the non-null value. For example, if
x = null
then
3 * x
will return a value of 3. A binary operation is an operation that contains an operand on each side of the
operator, as in the preceding examples. An operation with only one operand is called a unary operation, and requires the use of a unary operator. An example of a unary operation is
!1
which uses the logical negation operator. It returns a value of 0. The unary operators are sizeof(), head(), tail(),
Operator Precedence and Associativity
Operator rules of precedence and associativity determine in what order operands are evaluated in expressions. Expressions with operators of higher precedence are evaluated first. In the expression
the the addition. Therefore, the expression evaluates to 49.
~
and !.
4 + 9 * 5
*
operator has the highest precedence, so the multiplication is performed before
C
4
Operators
CATC Scripting Language
9
The associative operator
()
is used to group parts o f the expression, forcing those
parts to be evaluated first. In this way, the rules of precedence can be overridden. For example,
( 4 + 9 ) * 5
causes the addition to be performed before the multiplication, resulting in a value of 65.
When operators of equal precedence occur in an expression, the operands are evaluated according to the associativity of the operators. This means that if an op­erator's associativity is left to right, then the operations will be done starting from the left side of the expression. So, the expression
4 + 9 - 6 + 5
would evaluate to 12. However, if the associative operator is used to group a part or parts of the expression, those parts are evaluated first. Therefore,
( 4 + 9 ) - ( 6 + 5 )
has a value of 2. In Table 4.1, Operator Precedence and Associativity, the operators are listed in
order of precedence, from highest to lowest. Operators on the same line have equal precedence, and their associativity is shown in the second column.
~ ! sizeof head tail
Operator Symbol Associativity
++ -­[] ()
* / %
+ -
<< >>
< > <= >=
== !=
& ^
| && ||
Right to left Left to right
Right to left
Left to right Left to right
Left to right
Left to right Left to right
Left to right
Left to right Left to right
Left to right
Left to right
Table 4.1: Operator Precedence and Associativity
HAPTER
C
4
Operators
CATC Scripting Language
10
HAPTER
+=
Operator Symbol
*=
I=
%=
I=
>>= <<=
&=
Table 4.1: Operator Precedence and Associativity
Associativity
Right to left
(Continued)
C
4
Operators
CATC Scripting Language
11
Operator
Operand
R
esult
[ ]
Raw[1] = 0x11
( )
2 + ( 4 * 3 ) = 14
*
3 * 1 = 3
/
3 / 1 = 3
%
3 % 1 = 0
+
2 + 2 = 4
"one " + "two" = "one two"
'001122334455'
[1, 2] + [3, 4] = [1, 2, 3, 4]
1 + [2, 3] = [1, 2, 3]
"one" + ["two"] = ["one", "two"]
-
3 – 1 = 2
++
--
HAPTER
Symbol
Index Operator
Associative Operator
Arithmetic Operators
Description
Index or subscript
Associative
Multiplication Integer-integer Division Modulus Addition
Types
Raw Bytes
Types
Integer
Examples
Raw = '001122'
List
Any
Integer-integer Integer-integer Integer-integer String-string Raw byte-raw byte Raw
Any
Any
Integer Integer Integer Integer String
List = [0, 1, 2, 3, [4, 5]] List[2] = 2 List[4] = [4, 5] List[4][1] = 5
*Note: if an indexed Raw value is assigned to any value that is not a byte ( > 255 or not an integer), the variable will be promoted to a list before the assignment is performed.
( 2 + 4 ) * 3 = 18
'001122' + '334455' =
List-list Integer-list Integer-string
String-list
Subtraction
Increment and Decrement Operators
Increment
Decrement
Integer-integer
Integer
Integer
List List String
List Integer
Integer
Integer
"number = " + 2 = "number = 2"
*Note:
integer-string concatenation
conversion.
a = 1 ++a = 2
b = 1 b++ = 1 *Note that the value of b after execution is 2.
a = 2
--a = 1
b = 2 b-- = 2
*Note that the value of b after execution is 1.
uses decimal
Table 4.2: Operators
C
4
Operators
CATC Scripting Language
12
Operator
Operand
R
esult
==
2 == 2
"three" == "three"
'001122' == '001122'
!=
2 != 3
"three" != "four"
'001122' != '334455'
<
1 < 2
"abc" < "def"
>
2 > 1
"xyz" > "abc"
<=
23 <= 27
"cat" <= "dog"
>=
2 >= 1
!
!9 = 0 !"" = 1
&&
1 && 0 = 0 1 && "cat" = 1
||
1 || 0 = 1 "" || !"cat" = 0
HAPTER
Symbol
Equality Operators
Relational Operators
Description
Equal
Not equal
Less than
Greater than
Less than or equal
Greater than or equal
Types
Integer-integer String-string Raw byte-raw byte Integer List-list
Integer-integer String-string Raw byte-raw byte Integer List-list
Integer-integer String-string Integer-integer String-string Integer-integer String-string Integer-integer String-string
Types
Integer Integer
Integer
Integer Integer
Integer
Integer Integer Integer Integer Integer Integer Integer Integer
Examples
[1, [2, 3]] == [1, [2, 3]]
*Note: equality operations on values of different types will evaluate to false.
[1, [2, 3]] != [1, [2, 4]]
*Note: equality operations on values of different types will evaluate to false.
"sun" >= "moon"
*Note: relational operations on string values are evaluated according to character order in the ASCII table.
Logical Operators
Negation
Logical AND All combinations
Logical OR
All combinations of types
of types All combinations
of types
Table 4.2: Operators (Continued)
Integer
Integer
Integer
!0 = 1 !"cat" = 0
1 && 1 = 1 1 && !"" = 1
1 || 1 = 1 0 || 0 = 0
C
4
Operators
CATC Scripting Language
13
Operator
Operand
R
esult
~
&
0b01010100
^
0b10101011
|
0b11111111
<<
0b11111110 << 3 = 0b11110000
>>
0b11111110 >> 1 = 0b01111111
=
B = C = A
+=
+= 1 = 2
+= "two" = "one two"
+= '334455' = '001122334455'
+= [3, 4] = [1, 2, 3, 4]
+= [2, 3] = [1, 2, 3]
+ ["two"] = ["one", "two"]
-=
–= 1 = 2
*=
*= 1 = 3
/=
/= 1 = 3
%=
%= 1 = 0
>>=
>>= 1 = 0b01111111
<<=
<<= 3 = 0b11111110000
HAPTER
Symbol
Bitwise Logical Operators
Shift Operators
Assignment Operators
Description
Bitwise complement
Bitwise AND Integer-integer
Bitwise exclusive OR
Bitwise inclusive OR
Left shift Right shift
Assignment
Addition assignment
Subtraction assignment
Multiplication assignment
Division assignment
Modulus assignment
Right shift assignment
Left shift assignment
Types
Integer-integer
Integer-integer
Integer-integer
Integer-integer Integer-integer
Any
Integer-integer
String-string
Raw byte-raw byte Raw
List-list
Integer-list
Integer-string
String-list
Integer-integer
Integer-integer
Integer-integer
Integer-integer
Integer-integer
Integer-integer
Types
Integer
Integer
Integer
Integer
Integer Integer
Any
Integer
String
List
List
String
List
Integer
Integer
Integer
Integer
Integer
Integer
Examples
~0b11111110 = 0b00000001
0b11111110 & 0b01010101 =
0b11111110 ^ 0b01010101 =
0b11111110 | 0b01010101 =
A = 1
x = 1 x
a = "one " a
z = '001122' z
x = [1, 2] x
y = 1 y
a = "number = " a += 2 = "number = 2"
*Note: conversion.
s = "one" s
y = 3 y
x = 3 x
s = 3 s
y = 3 y
b = 0b11111110 b
a = 0b11111110 a
integer-string concatenation
uses decimal
Table 4.2: Operators (Continued)
C
4
Operators
CATC Scripting Language
14
Operator
Operand
R
esult
&=
&= 0b01010101 = 0b01010100
^=
|=
sizeof()
head()
tail()
HAPTER
Symbol
Assignment Operators (continued)
List Operators
Description
Bitwise AND assignment
Bitwise exclusive OR assignment
Bitwise inclusive OR assignment
Number of elements
Head
Tail
Types
Integer-integer
Integer-integer
Integer-integer
Any
List
List
Types
Integer
Integer
Integer
Integer
Any
List
Examples
a = 0b11111110 a
e = 0b11111110 e ^= 0b01010101 = 0b10101011
i = 0b11111110 i |= 0b01010101 = 0b11111111
sizeof([1, 2, 3]) = 3 sizeof('0011223344') = 5 sizeof("string") = 6 sizeof(12) = 1 sizeof([1, [2, 3]]) = 2
*Note: the last example sizeof() operator returns the shallow count of a complex list.
head([1, 2, 3]) = 1
*Note: the Head of a list is the first item in the list.
tail([1, 2, 3]) = [2, 3]
*Note: the Tail of a list includes everything except the Head.
demonstrates
that the
Table 4.2: Operators (Continued)
Loading...
+ 39 hidden pages