Libraries
integrate_user_calibrator/integrate_user_calibrator.cpp
/*
This example uses a user defined calibrator named MyUserCalibrator to
calibrator values in a Parameter. This example just shows how to add and
use a calibrator you define. More information is available in other
examples on how to use parameters in packets.
Note: You should build the MyUserCalibrator example before running this
example.
*/
#include "calibrator_support_functions.h"
#include "parameter.h"
#include <stdio.h>
using namespace trek;
int main()
{
int ret_value;
Calibrator *cal_ptr;
double cal_value;
//
// Create a 32 bit signed integer parameter.
//
p.SetName( "MyParameter" );
p.SetStartBit( 0 ); // we won't use this in the example
p.SetModifiableFlag( true );
//
// First read in the calibrator using this function from the Data API.
// The name should not include the operating specific parts of the filename.
// The function will add that as needed. Just pass in a string like
// "MyUserCalibrator", not "MyUserCalibrator.dll" or "libMyUserCalibrator.so".
// The calibrator library will be searched for in the following places:
// 1. Current directory
// 2. Directory specified by TREK_USER_LIB
// 3. Home directory
//
const char *my_cal_name = "MyUserCalibrator";
ret_value = CreateUserCalibrator( my_cal_name, &cal_ptr );
if( ret_value )
{
printf( "CreateUserCalibrator failed with return code of %d.\n", ret_value );
return 1;
}
//
// Now let the parameter know it should use the calibrator.
//
p.SetDefaultCalibrator( *cal_ptr );
//
// Since the calibrator was copied by the parameter class, it is safe to
// delete it now.
//
delete cal_ptr;
//
// We can now calibrate data. First attempt is a value that will cause
// calibration to fail (see MyUserCalibrator for details).
//
ret_value = p.SetValue( 50 );
if( ret_value )
{
printf("Unexpected failure. Return was %d.\n", ret_value );
return 1;
}
//
// Ask for the calibrated value.
//
ret_value = p.GetCalibratedValue( cal_value );
if( ret_value == SUCCESS )
{
printf("Unexpected success...should have failed.\n");
return 1;
}
//
// Now set the parameter value to something that will succeed.
//
ret_value = p.SetValue( 20 );
if( ret_value )
{
printf("Unexpected failure. Return was %d.\n", ret_value );
return 1;
}
//
// Ask for the calibrated value.
//
ret_value = p.GetCalibratedValue( cal_value );
if( ret_value )
{
printf("Unexpected failure. Return was %d.\n", ret_value );
return 1;
}
printf("Calibrated value is %lf\n", cal_value );
return 0;
}