kbLogger 2.0.b1
The automotive ready test and logging program.
Translator Class Reference

This class defines the API of the Translator.

#include <translator.h>

Public Slots

Translator related functions.
void setVerbose (int iVerboseLevel)
 Sets the verbosity of the Translator.
 
void trace (QString strText)
 Sends a trace message to the connected TraceViewer.
 
QString translate (QString strFrom)
 Translate a hex string. Call this from within the script.
 
TranslatorProtocolcreateProtocol (QString strName, QString strMessageIdPositions)
 Creates an user defined protocol.
 
TranslatorProtocolcreateProtocol (QString strName, unsigned int uOffset, QString strMessageIdPositions)
 Creates an user defined protocol.
 
TranslatorProtocolgetProtocol (QString strName)
 Gets an user defined protocol.
 
TranslatorMessagecreateMessage (QString strName, quint64 uMessageId)
 Creates a user defined message.
 
TranslatorMessagecreateMessage (QString strName, QString strMessageId)
 Creates a user defined message.
 
TranslatorMessagegetMessage (QString strMessageHandle)
 Returns the message for that given message handle.
 
TranslatorSignalUserArraycreateArray (QString strName, unsigned int uOffset=0)
 Creates an user defined array.
 
TranslatorSignalUserBoolcreateBool (QString strName, unsigned int uOffset=0)
 Creates a Bool signal.
 
TranslatorSignalUserEnum8 * createEnum8 (QString strName, unsigned int uOffset=0)
 Creates a Enum8 signal.
 
TranslatorSignalUserEnum16 * createEnum16 (QString strName, unsigned int uOffset=0)
 Creates a Enum16 signal.
 
TranslatorSignalUserEnum32 * createEnum32 (QString strName, unsigned int uOffset=0)
 Creates a Enum32 signal.
 
TranslatorSignalUserFloat32createFloat32 (QString strName, unsigned int uOffset=0)
 Creates a Float32 signal.
 
TranslatorSignalUserFloat64createFloat64 (QString strName, unsigned int uOffset=0)
 Creates a Float64 signal.
 
TranslatorSignalUserInt8createInt8 (QString strName, unsigned int uOffset=0)
 Creates a Int8 signal.
 
TranslatorSignalUserInt16createInt16 (QString strName, unsigned int uOffset=0)
 Creates a Int16 signal.
 
TranslatorSignalUserInt32createInt32 (QString strName, unsigned int uOffset=0)
 Creates a Int32 signal.
 
TranslatorSignalUserInt64createInt64 (QString strName, unsigned int uOffset=0)
 Creates a Int64 signal.
 
TranslatorSignalUserSpacecreateSpace (QString strName, unsigned int uOffset=0)
 Creates an user defined empty space.
 
TranslatorSignalUserStringcreateString (QString strName, unsigned int uOffset=0)
 Creates an user defined string.
 
TranslatorSignalUserStructcreateStruct (QString strName, unsigned int uOffset=0)
 Creates an user defined struct.
 
TranslatorSignalUserUint8createUint8 (QString strName, unsigned int uOffset=0)
 Creates a Uint8 signal.
 
TranslatorSignalUserUint16createUint16 (QString strName, unsigned int uOffset=0)
 Creates a Uint16 signal.
 
TranslatorSignalUserUint32createUint32 (QString strName, unsigned int uOffset=0)
 Creates a Uint32 signal.
 
TranslatorSignalUserUint64createUint64 (QString strName, unsigned int uOffset=0)
 Creates a Uint64 signal.
 
ScriptValue extractSignal (QString strText, QString strVariableName)
 Extracts a variable from the given message, which was already translated by the TranslatorObject.
 

Member Function Documentation

◆ createArray

TranslatorSignalUserArray * createArray ( QString strArrayName,
unsigned int uOffset = 0 )
slot

Creates an user defined array.

This defines a static or variable array of the same signal. The signal can also be a structure.

The example below shows an array, which starts after an offset of 3 bytes and repeats its signal 5 times.

Example:

var myFirstParameter = tr.createUint8("myFirstParameter", 0);
var myArraySignal = tr.createUint16(("myArraySignal");
var myArray = tr.createArray("myArray", 3); // Let 3 Bytes free before the Array starts
myArray.setSignal(myArraySignal);
myArray.setRxDimension(5);
Parameters
strArrayNameThe name of the array.
uOffsetThe offset between the previous parameter and the array.
Returns
The handle of the created array.

◆ createBool

TranslatorSignalUserBool * createBool ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined bool signal.

Example:

var mySignal = tr.createBool("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and signal.
Returns
The handle of the created bool signal.

◆ createEnum16

TranslatorSignalUserEnum16 * createEnum16 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Enum16 signal.

Example:

var mySignal = tr.createEnum16("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createEnum32

TranslatorSignalUserEnum32 * createEnum32 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Enum32 signal.

Example:

var mySignal = tr.createEnum32("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createEnum8

TranslatorSignalUserEnum8 * createEnum8 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Enum8 signal.

Example:

var mySignal = tr.createEnum8("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createFloat32

TranslatorSignalUserFloat32 * createFloat32 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Float32 signal.

Example:

var mySignal = tr.createFloat32("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createFloat64

TranslatorSignalUserFloat64 * createFloat64 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Float64 signal.

Example:

var mySignal = tr.createFloat64("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createInt16

TranslatorSignalUserInt16 * createInt16 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Int16 signal.

Example:

var mySignal = tr.createInt16("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createInt32

TranslatorSignalUserInt32 * createInt32 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Int32 signal.

Example:

var mySignal = tr.createInt32("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createInt64

TranslatorSignalUserInt64 * createInt64 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Int64 signal.

Example:

var mySignal = tr.createInt64("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createInt8

TranslatorSignalUserInt8 * createInt8 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Int8 signal.

Example:

var mySignal = tr.createInt8("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createMessage [1/2]

TranslatorMessage * createMessage ( QString strMessageName,
QString strMessageId )
slot

Creates a user defined message.

This function creates a message with a longer message ID.

var myMessage = tr.createMessage("myMessage", "11223344556677889900");
Parameters
strMessageNameThe name of the message to create.
strMessageIdThe message ID as a hex string.
Returns
The handle of the message.

◆ createMessage [2/2]

TranslatorMessage * createMessage ( QString strMessageName,
quint64 uMessageId )
slot

Creates a user defined message.

var myMessage = tr.createMessage("myMessage", 0x1122334455667788);
Parameters
strMessageNameThe name of the message to create.
uMessageIdThe message ID of the message.
Returns
The handle of the message.

◆ createProtocol [1/2]

TranslatorProtocol * createProtocol ( QString strProtocolName,
QString strMessageIdPositions )
slot

Creates a protocol.

The parameter strMessageIdPositions contains a description where in the byte stream the relevant message Ids can be found. For example, he string "0-2,4" means, the 32bit value from byte 0, 1, 3 and 4 is the ID for this message.

Example:

var protocol1 = tr.createProtocol("protocol1", "0-2,4,5-7,8");
Parameters
strProtocolNameThe name of the protocol.
strMessageIdPositionsThe message ID description string.
Returns
The handle of the created protocol.

◆ createProtocol [2/2]

TranslatorProtocol * createProtocol ( QString strProtocolName,
unsigned int uOffset,
QString strMessageIdPositions )
slot

Creates a protocol.

The parameter strMessageIdPositions contains a description where in the byte stream the relevant message Ids can be found. For example, he string "0-2,4" means, the 32bit value from byte 0, 1, 2 and 4 is the ID for this message. If the parameter uOffset is e.g. 5, the 32bit value from byte 5, 6, 7 and 9 is the ID for this message.

Example:

var protocol1 = tr.createProtocol("protocol1", "0-2,4,5-7,8");
Parameters
strProtocolNameThe name of the protocol.
uOffsetThe offset between the beginning of the message and the relevant bytes of the protocol.
strMessageIdPositionsThe message ID description string.
Returns
The handle of the created protocol.

◆ createSpace

TranslatorSignalUserSpace * createSpace ( QString strSpaceName,
unsigned int uOffset = 0 )
slot

Creates an user defined space.

The example below shows a space, which starts after an offset of 3 bytes and has a length of 8 bytes.

Example:

var myFirstParameter = tr.createUint8("myFirstParameter", 0);
var mySpace = tr.createSpace(("mySpace", 3);
var mySpace.setLength(8);
var myThirtParameter = tr.createUint8("myThirtParameter", 0);
Parameters
strSpaceNameThe name of the space.
uOffsetThe offset between the previous parameter and the space.
Returns
The handle of the created space.

◆ createString

TranslatorSignalUserString * createString ( QString strStringName,
unsigned int uOffset = 0 )
slot

Creates an user defined string.

The example below shows a string, which starts after an offset of 3 bytes and has a length of 8 bytes.

Example:

var myFirstParameter = tr.createUint8("myFirstParameter", 0);
var myString = tr.createString(("myString", 3);
var myString.setLength(8);
var myThirtParameter = tr.createUint8("myThirtParameter", 0);
Parameters
strStringNameThe name of the string.
uOffsetThe offset between the previous parameter and the string.
Returns
The handle of the created string.

◆ createStruct

TranslatorSignalUserStruct * createStruct ( QString strStructName,
unsigned int uOffset = 0 )
slot

Creates an user defined struct.

This defines a struct of the different signals. The signals can also be an array.

The example below shows a struct, which starts after an offset of 3 bytes and contains multiple signals.

Example:

var myFirstParameter = tr.createUint8("myFirstParameter", 0);
var myStruct = tr.createStruct("myStruct", 3); // Let 3 Bytes free before the Struct starts
myStruct.appendSignal(tr.createUint8("myFirstElement", 0));
myStruct.appendSignal(tr.createUint8("mySecondElement", 0));
Parameters
strStructNameThe name of the struct.
uOffsetThe offset between the previous parameter and the struct.
Returns
The handle of the created struct.

◆ createUint16

TranslatorSignalUserUint16 * createUint16 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Uint16 signal.

Example:

var mySignal = tr.createUint16("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createUint32

TranslatorSignalUserUint32 * createUint32 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Uint32 signal.

Example:

var mySignal = tr.createUint32("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createUint64

TranslatorSignalUserUint64 * createUint64 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Uint64 signal.

Example:

var mySignal = tr.createUint64("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ createUint8

TranslatorSignalUserUint8 * createUint8 ( QString strSignalName,
unsigned int uOffset = 0 )
slot

Creates an user defined Uint8 signal.

Example:

var mySignal = tr.createUint8("mySignal", 0);
Parameters
strSignalNameThe name of the signal.
uOffsetThe offset between the previous and this signal.
Returns
The handle of the created signal.

◆ extractSignal

ScriptValue extractSignal ( QString strText,
QString strVariableName )
slot

Extracts a variable from the given message, which was already translated by the TranslatorObject.

Example

function myCallback(strPayload)
{
var myVariable = so.extractVariable(strPayload, "myVariable");
so.trace("myVariable = " + myVariable);
}
Parameters
strTextThe text which contains the variables.
strVariableNameThe name of the variable to search.
Returns
The content of the variable in case of success, otherwise an undefined value.

◆ getMessage

TranslatorMessage * getMessage ( QString strMessageHandle)
slot

Returns the message for that given message handle.

Parameters
strMessageHandle
Returns
The message

◆ getProtocol

TranslatorProtocol * getProtocol ( QString strName)
slot

Gets an user defined protocol.

var myProtocol = tr.getProtocol("myProtocol");
Parameters
strNameThe protocol name.
Returns
The handle of the protocol.

◆ setVerbose

void setVerbose ( int iVerboseLevel)
slot

Sets the verbosity of the Translator.

Useful for debugging user scripts within the TranslatorObject.

tr.setVerbose(2); // Sets the max verbose level
Parameters
iVerboseLevel0 means quite. 1 and 2 means more output.

◆ trace

void trace ( QString strText)
slot

Sends a trace message to the connected TraceViewer.

Example:

tr.trace("my trace message");
Parameters
strTextThe text to send to the TraceViewer.

◆ translate

QString translate ( QString strFrom)
slot

Translate a hex string. Call this from within the script.

var myHexString = "A4B5C6";
tr.translate(myHexString);
Parameters
strFromThe hex string to translate.
Returns
The translated message in case of success. An empty string otherwise.