TReK C++  5.3.3
Telemetry/Command API
Data API

The Data API provides a set of classes to perform telemetry and command data manipulation. These classes are used internally by TReK for all telemetry and command processing and are exposed to allow user developed programs to take advantage of them if desired. The trek::Packet class provides the encapsulation of data. The picture below shows the basic structure of a packet.









Each packet can have up to three 'zones' of information: header, data, and trailer. The header zone typically has information for packet identification and routing. The data zone usually holds the values that users will be interested in. The trailer zone, if available, often just consists of a single parameter such as a checksum. For a packet to be considered valid, at least one zone must be defined.
The first row in the picture shows a packet with three zones populated. The second row shows the details for each of the zones in the packet. The header zone consists of four parameters (A, B, C, and D). The data zone consists of another packet with just the header and data zones populated. The trailer zone consists of two parameters (N and O). The third row shows that the encapsulated packet breaks down into parameters in the header (E, F, and G) and data (H, I, J, K, L, and M).

The zones in a packet that contain parameters are all trek::ParameterCollection objects. Each trek::ParameterCollection class consists of one or more trek::Parameter objects. There is no limit to the amount of encapsulation allowed for packets.

Note
It is expected that additional classes will be provided in future releases which can be added as packet zones.
Available Classes
The following classes are currently exposed by the library. Some methods in the classes have not been documented and are excluded. They will become available in a later release. Each of the classes described below can be saved to a file and loaded from a file. The format of the save file is XML.

trek::Parameter
The Parameter class encapsulates all the information for a telemetry or command data item. A parameter has a data type, length, byte order, and location to describe how to place it in a packet (build) or remove it from a packet (extract). Each parameter can have ranges set to restrict the valid values allowed. A parameter can also be calibrated with any of the built in TReK calibration options or with a user defined calibration function. An example of how to build a user defined calibrator can be found at the end of this page. The value of the parameter can also be checked for limit violations (high, low, and/or delta).

trek::ParameterCollection
The ParameterCollection class is a set of parameters that are related. A parameter collection can be used on its own, but most often will be inserted into a trek::Packet as one of the zones. A parameter collection can be created and reused in multiple packets. For example, if a parameter colllection defines the header it can be inserted as the header zone in multiple packets.

trek::Packet
The Packet class is made up of the header, data, and trailer zones and defines a set of bytes that typically are transferred over an interface such as a socket or serial device. The packet can also have optional attributes defined. The attributes available for each packet are defined in the table below:

Attribute

Description

Checksum

An integrity check for the data. The checksum can be any of the types supported by TReK (currently MD5, 16-bit sum (ISS), and CRC-32). A checksum will usually appear in either the header or trailer zone of a packet. If a checksum is specified, TReK will ensure that the data received matches the checksum. If TReK is building the data, the checksum will be calculated and placed in the packet.

Counter

An incrementing or decrementing count used for each packet. When building the packet, TReK will automatically set the counter and increment it to the next available counter value.

Identifiers

One or more identifiers can be set for a packet. Currently these are not used when receiving a packet (see packet header processors for that stuff). However, they are set when building a packet.

Length

A length for the packet including an optional offset value. For fixed length packets this value can be check to insure that the data is the correct length when received. The length is automatically set when building the packet.

Time Stamp A time to be associated with all data in the packet. When building packets, TReK uses the current system time (with optional offset) to populate this value. Upon receipt, TReK will use this value as the time the packet originated from the source.

trek::PolynomialCalibrator
The PolynomialCalibrator class performs polynomial calibration on a parameter value using an nth order polynomial equation:




where x is the converted value of the parameter, n is the order of the polynomial, and C are constant values for each term.

trek::SplineCalibrator
The SplineCalibrator class performs calibration using a series of line segments. The graphic below show a calibrator with three line segments.














The calibrated value of a parameter is found using the following equation:



trek::LimitAlarm
The LimitAlarm class holds the high, low, and delta values that cause an alarm. Multiple limit alarms can be set for a parameter and each one is assigned a 'level'. The higher the level number, the more severe the alarm. Up to 5 levels of alarms may be defined.

trek::ParameterStatus
The ParameterStatus class holds status associated with a telemetry value. Most of the methods available in the parameter status are not needed by a user program. A typical use of this class would be to set the status values and get the corresponding status string.

Extending Data API Capabilities
The Data API also allows users to write their own unique calibration functions and use them for any parameter being processed. There are two examples provided to show you "How to create a user defined calibrator" and "How to integerate a user defined calibrator".

A command line program is available to create template files for a user defined calibrator. The command line has two arguments for calibrator name and directory. The command line format will vary slightly depending on the operating system you are using. An example for Windows:

trek_create_user_cal.exe MyCal d:\my_cal_dir

For Linux:
trek_create_user_cal MyCal /home/myusername/my_cal_dir

There is an example showing a user defined calibrator and integrating it below. You can use the Windows project or makefiles that are delivered with the examples to help you build the library properly. When a user defined calibrator is loaded, the following directories are used. The first directory containing the library is used:

Current working directory
Directory defined by environment variable TREK_USER_LIB
User's home directory

Examples
The following examples are provided to show how to use Data API classes:

Define a Packet
Creates a simple packet in code and stores the definition to an XML file. The file created in this example is used for the build and extract packet examples.
Source File:
define_packet/define_packet.cpp

Build a Packet
Shows how to build a packet into a buffer from the individual parameters found in a packet. Uses the simple packet created in the define packet example.
Source File:
build_packet/build_packet.cpp

Extract a Packet
Shows how to extract data from a buffer into the individual parameters found in a packet. Uses the simple packet created in the define packet example.
Source File:
extract_packet/extract_packet.cpp

How to create a user defined calibrator
These four files show how to build a user defined calibrator. The only two files you would need to edit are the MyUserCalibrator.h and MyUserCalibrator.cpp files. It may be possible for you to only edit the Calibrate() method in the MyUserCalibrator.cpp file. You can create these files using the command line executable trek_create_user_cal found in the TReK bin directory.
Source Files:
MyUserCalibrator/MyUserCalibrator.h
MyUserCalibrator/MyUserCalibratorDefines.h
MyUserCalibrator/MyUserCalibrator.cpp
MyUserCalibrator/MyUserCalibratorExportedFunctions.cpp

How to integrate a user defined calibrator
Shows how to use the MyUserCalibrator defined in the previous example with the trek::Parameter class.
integrate_user_calibrator/integrate_user_calibrator.cpp


Additional Dependencies
The TReK Data API is also dependent on the following libraries. See the Libraries main help page for more information.

trek_toolkit_common_api
trek_toolkit_data_api
trek_toolkit_utilities_api
xerces-c_3_1