Add a time variable in seconds to the variable server

Added a time variable that is in seconds.  A created a special case
for var_add if you add "time" then this variable will be added to
the list of variables returned.

trick.var_add("time")

refs #151
This commit is contained in:
Alex Lin 2016-01-14 10:49:27 -06:00
parent 903ff05960
commit 7e542440d1
4 changed files with 31 additions and 2 deletions

View File

@ -430,6 +430,11 @@ namespace Trick {
*/
int write_binary_data( int Start, char *buf1, int PacketNum );
/**
@brief Make a time reference.
*/
REF2* make_time_ref();
/**
@brief Make a "bad-reference" reference.
*/
@ -471,6 +476,9 @@ namespace Trick {
/** Dummy integer for bad references.\n */
static int bad_ref_int ; /**< trick_io(**) */
/** The simulation time converted to seconds\n */
double time ; /**< trick_units(s) */
/** List of client requested variables.\n */
std::vector <VariableReference *> vars; /**< trick_io(**) */

View File

@ -62,7 +62,7 @@ Trick::VariableReference::VariableReference(REF2 * in_ref ) {
}
Trick::VariableReference::~VariableReference() {
delete ref ;
free(ref) ;
free(buffer_in) ;
free(buffer_out) ;
}

View File

@ -16,6 +16,19 @@
int Trick::VariableServerThread::bad_ref_int = 0 ;
REF2* Trick::VariableServerThread::make_time_ref() {
REF2* new_ref;
new_ref = (REF2*)calloc(1, sizeof(REF2));
new_ref->reference = strdup("time") ;
new_ref->units = strdup("s") ;
new_ref->address = (char *)&time ;
new_ref->attr = (ATTRIBUTES*)calloc(1, sizeof(ATTRIBUTES)) ;
new_ref->attr->type = TRICK_DOUBLE ;
new_ref->attr->units = strdup("s") ;
new_ref->attr->size = sizeof(double) ;
return new_ref;
}
REF2* Trick::VariableServerThread::make_error_ref(std::string in_name) {
REF2* new_ref;
new_ref = (REF2*)calloc(1, sizeof(REF2));
@ -34,7 +47,11 @@ int Trick::VariableServerThread::var_add(std::string in_name) {
VariableReference * new_var ;
REF2 * new_ref ;
new_ref = ref_attributes(const_cast<char*>(in_name.c_str())) ;
if ( in_name.compare("time") == 0 ) {
new_ref = make_time_ref() ;
} else {
new_ref = ref_attributes(const_cast<char*>(in_name.c_str())) ;
}
if ( new_ref == NULL ) {
message_publish(MSG_ERROR, "Variable Server could not find variable %s.\n", in_name.c_str());

View File

@ -4,6 +4,7 @@
#include "trick/VariableServer.hh"
#include "trick/memorymanager_c_intf.h"
#include "trick/exec_proto.h"
int Trick::VariableServerThread::copy_sim_data() {
@ -16,6 +17,9 @@ int Trick::VariableServerThread::copy_sim_data() {
if ( pthread_mutex_trylock(&copy_mutex) == 0 ) {
// Get the simulation time we start this copy
time = (double)exec_get_time_tics() / exec_get_time_tic_value() ;
for ( ii = 0 ; ii < vars.size() ; ii++ ) {
curr_var = vars[ii] ;