TReK C++  5.3.2
Telemetry/Command API
tlm_api_cpp_newest/cpp_newest_main.cpp
#include <stdio.h>
#include "telemetry_api.h"
#include "parameter.h"
#include "packet.h"
//
// NOTE: This example requires the TReK Data GUI to be started and the PDSS Payload
// Packet with APID 7 to be activated with a Real-Time data mode.
//
using namespace trek;
int main()
{
TelemetryApi tlm_api;
StringArray pkt_key_list;
Packet pkt;
uint8_t buf[4096];
uint32_t buf_len;
uint32_t token = 0; // always initialize the token to zero
int ret_value;
//
// Connect to a data store.
//
ret_value = tlm_api.Connect("DefaultDataStore");
if( ret_value )
{
printf( "Error %d: Could not connect to data store.\n", ret_value );
return 1;
}
//
// Calling this method allows the API to clean up resources that may be
// left over from a user program that crashed. Not checking the return
// value as it is safe to continue if this method fails.
//
tlm_api.Cleanse();
//
// Get a list of the packet keys currently being processed. If you know
// your packet key already, this isn't needed.
//
ret_value = tlm_api.GetSourceList( pkt_key_list );
if( ret_value )
{
printf( "Error %d: Could not get packet list.\n", ret_value );
return 1;
}
for( uint32_t ii = 0; ii < pkt_key_list.Size(); ii++ )
printf( "Packet key %u: %s\n", ii+1, pkt_key_list.GetAt(ii) );
//
// Get the packet definition so that parameters can be extracted
// from the packet.
//
ret_value = tlm_api.GetPacketDefinition( "PdssPayload.RT.PL.7", pkt );
if( ret_value )
{
printf( "Error %d: Could not get packet definition.\n", ret_value );
return 1;
}
//
// Get the latest packet from the data store.
//
buf_len = 4096; // always reset this value for each call
ret_value = tlm_api.GetNewestPacket( "PdssPayload.RT.PL.7", token, buf, buf_len );
if( ret_value )
{
printf( "Error %d: Could not get the latest packet.\n", ret_value );
return 1;
}
//
// Use the packet definition to extract the data.
//
uint32_t last_bit_used;
ret_value = pkt.Extract( buf, buf_len, last_bit_used );
if( ret_value )
{
printf( "Error %d: Could not extract parameter data from the packet.\n", ret_value );
return 1;
}
//
// The packet has been extracted and can now get the values using the Packet class
// methods. Look up a parameter and get its value.
//
Parameter *param_ptr;
ret_value = pkt.FindParameter( "MSID016", &param_ptr );
if( ret_value )
{
printf( "Error %d: Could not find parameter.\n", ret_value );
return 1;
}
int32_t int_value;
ret_value = param_ptr->GetValue( int_value );
if( ret_value )
{
printf( "Error %d: Could not get parameter value.\n", ret_value );
return 1;
}
printf( "Value is: %d.\n", int_value );
//
// It is always best to call Disconnect when you are finished with the
// API. There are system resources that can be freed when you no
// longer need the API.
//
ret_value = tlm_api.Disconnect();
if( ret_value )
{
printf( "Error %d: API did not disconnect properly.\n", ret_value );
return 1;
}
return 0;
}
int32_t Connect(const char *name)
Connects this instance of the API to TReK for the specified destination.
Definition: api_client.cpp:130
int32_t Disconnect()
Disconnects from the destination.
Definition: api_client.cpp:343
int32_t Cleanse()
Cleans up any resources from crashed user programs.
Definition: api_client.cpp:468
This class describes a packet composed of one or more parameters.
Definition: packet.h:72
int32_t Extract(uint8_t *input_ptr, uint32_t input_length, uint32_t &last_bit_used)
Extracts all of the parameters in the packet from the specified buffer.
Definition: packet.cpp:1714
int32_t FindParameter(const char *name, Parameter **param_ptr)
Finds the specified parameter name in the packet.
Definition: packet.cpp:2348
This class describes a single parameter within a telemetry or command message including its value.
Definition: parameter.h:95
int32_t GetValue(int8_t &input, uint16_t sample_number=1)
Gets the value of a parameter as an 8-bit signed integer.
Definition: parameter.cpp:8546
This class provides a wrapper for std::vector and std::string so different versions of the standard t...
Definition: string_array.h:19
uint32_t Size()
Returns the number of items in the string array.
Definition: string_array.cpp:67
const char * GetAt(uint32_t index)
Returns the string at the given location.
Definition: string_array.cpp:89
Provides access to telemetry features of TReK.
Definition: telemetry_api.h:44
int32_t GetPacketDefinition(const char *pkt_key, Packet &pkt)
Retrieve the Packet definition for the specified key.
Definition: telemetry_api.cpp:296
int32_t GetNewestPacket(const char *pkt_key, uint32_t &token, uint8_t *buf, uint32_t &len)
Gets a copy of the newest packet available from the data store.
Definition: telemetry_api.cpp:396
int32_t GetSourceList(StringArray &pkt_key_list)
Gets the list of packet keys currently being processed.
Definition: telemetry_api.cpp:112
Defines the trek::Packet class.
Defines the trek::Parameter class.
Defines the trek::TelemetryApi class.