Libraries
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;
}