Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/trick/ReferenceUtils.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef REFERENCE_UTILS_HH
#define REFERENCE_UTILS_HH

/*
PURPOSE: ( Provides helper functions for working with REF2. )
*/

#include "trick/reference.h"

namespace Trick
{

class ReferenceUtils
{
public:
// Returns true when ref represents an access that went through an STL container:
// stl_present == 1 (STL indexed somewhere in the path, e.g. xxx[2].yyy.www)
// OR attr->type == TRICK_STL with the reference ending in ']' (e.g. vec[0])
static bool is_stl_ref(const REF2* ref);

// Returns the effective TRICK_TYPE for value interpretation:
// TRICK_STL whose reference ends with ']' -> attr->stl_elem_type
// everything else -> attr->type
static TRICK_TYPE effective_trick_type(const REF2* ref);

// Returns the effective byte size for buffer allocation / copying:
// TRICK_STL whose reference ends with ']' -> sizeof(stl_elem_type)
// everything else -> attr->size
static size_t effective_trick_size(const REF2* ref);
};

} // namespace Trick

#endif // REFERENCE_UTILS_HH
12 changes: 12 additions & 0 deletions test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_Master.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sys.exec.out.time {s},the_object.stlc.double_vector[0] {1},the_object.stlc.double_vector[1] {1},the_object.stlc.double_vector[2] {1},the_object.stlc.float_deque[0] {1},the_object.stlc.float_deque[1] {1},the_object.stlc.float_deque[2] {1},the_object.stlc.int_array[0] {1},the_object.stlc.int_array[1] {1},the_object.stlc.int_array[2] {1},the_object.stlc.int_array[3] {1},the_object.stlc.vec_user_simple[0].b {1},the_object.stlc.vec_user_simple[0].a[0] {1},the_object.stlc.vec_user_simple[0].a[2] {1},the_object.stlc.vec_user_defined[0].a {1},the_object.stlc.vec_user_defined[0].vec[0] {1},the_object.stlc.vec_user_defined[0].vec[2] {1}
0, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.1, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.2, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.3, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.4, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.5, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.6, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.7, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.8, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.9, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
1, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
Binary file not shown.
103 changes: 103 additions & 0 deletions test/SIM_stls/RUN_test_dr/input_dr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import trick

def main():
trick.exec_set_job_onoff("the_object.stlc.addData", 1, True)
trick.exec_set_job_onoff("the_object.stlc.test", 1, False)
trick.exec_set_job_onoff("the_object.stlc.print", 1, False)

# ---------------------------------------------------------------
# ASCII data recording group for STL primitive containers
# ---------------------------------------------------------------
drg = trick.DRAscii("STL_DR")

# std::vector<double> — expected values: 4.0, 5.0, 6.0
drg.add_variable("the_object.stlc.double_vector[0]")
drg.add_variable("the_object.stlc.double_vector[1]")
drg.add_variable("the_object.stlc.double_vector[2]")

# std::deque<float> — expected values: 98.7, 65.4, 32.1
drg.add_variable("the_object.stlc.float_deque[0]")
drg.add_variable("the_object.stlc.float_deque[1]")
drg.add_variable("the_object.stlc.float_deque[2]")

# std::array<int,4> — expected values: 10, 20, 30, 40
drg.add_variable("the_object.stlc.int_array[0]")
drg.add_variable("the_object.stlc.int_array[1]")
drg.add_variable("the_object.stlc.int_array[2]")
drg.add_variable("the_object.stlc.int_array[3]")

# STL-element struct member: vec_user_simple is std::vector<UserClass>
# vec_user_simple[i].a[j] = i+j, vec_user_simple[i].b = 8888888888
drg.add_variable("the_object.stlc.vec_user_simple[0].b")
drg.add_variable("the_object.stlc.vec_user_simple[0].a[0]")
drg.add_variable("the_object.stlc.vec_user_simple[0].a[2]")

# STL-element struct member: vec_user_defined is std::vector<SimpleWrapper>
# vec_user_defined[i].a = 888, vec_user_defined[i].vec[j] = i+j
drg.add_variable("the_object.stlc.vec_user_defined[0].a")

# Nested STL: outer vector element's inner vector element
# vec_user_defined[0].vec = {0, 1, 2, ..., 9}
drg.add_variable("the_object.stlc.vec_user_defined[0].vec[0]")
drg.add_variable("the_object.stlc.vec_user_defined[0].vec[2]")

drg.set_cycle(0.1)
drg.freq = trick.DR_Always
drg.thisown = 0
trick.add_data_record_group(drg, trick.DR_Buffer)

# ---------------------------------------------------------------
# Binary data recording group — same variables
# ---------------------------------------------------------------
drg_bin = trick.DRBinary("STL_DR_bin")
drg_bin.add_variable("the_object.stlc.double_vector[0]")
drg_bin.add_variable("the_object.stlc.double_vector[1]")
drg_bin.add_variable("the_object.stlc.double_vector[2]")
drg_bin.add_variable("the_object.stlc.float_deque[0]")
drg_bin.add_variable("the_object.stlc.float_deque[1]")
drg_bin.add_variable("the_object.stlc.float_deque[2]")
drg_bin.add_variable("the_object.stlc.int_array[0]")
drg_bin.add_variable("the_object.stlc.int_array[1]")
drg_bin.add_variable("the_object.stlc.int_array[2]")
drg_bin.add_variable("the_object.stlc.int_array[3]")
drg_bin.add_variable("the_object.stlc.vec_user_simple[0].b")
drg_bin.add_variable("the_object.stlc.vec_user_simple[0].a[0]")
drg_bin.add_variable("the_object.stlc.vec_user_simple[0].a[2]")
drg_bin.add_variable("the_object.stlc.vec_user_defined[0].a")
drg_bin.add_variable("the_object.stlc.vec_user_defined[0].vec[0]")
drg_bin.add_variable("the_object.stlc.vec_user_defined[0].vec[2]")
drg_bin.set_cycle(0.1)
drg_bin.freq = trick.DR_Always
drg_bin.thisown = 0
trick.add_data_record_group(drg_bin, trick.DR_Buffer)

# ---------------------------------------------------------------
# HDF5 data recording group — same variables
# ---------------------------------------------------------------
drg_hdf5 = trick.DRHDF5("STL_DR_hdf5")
drg_hdf5.add_variable("the_object.stlc.double_vector[0]")
drg_hdf5.add_variable("the_object.stlc.double_vector[1]")
drg_hdf5.add_variable("the_object.stlc.double_vector[2]")
drg_hdf5.add_variable("the_object.stlc.float_deque[0]")
drg_hdf5.add_variable("the_object.stlc.float_deque[1]")
drg_hdf5.add_variable("the_object.stlc.float_deque[2]")
drg_hdf5.add_variable("the_object.stlc.int_array[0]")
drg_hdf5.add_variable("the_object.stlc.int_array[1]")
drg_hdf5.add_variable("the_object.stlc.int_array[2]")
drg_hdf5.add_variable("the_object.stlc.int_array[3]")
drg_hdf5.add_variable("the_object.stlc.vec_user_simple[0].b")
drg_hdf5.add_variable("the_object.stlc.vec_user_simple[0].a[0]")
drg_hdf5.add_variable("the_object.stlc.vec_user_simple[0].a[2]")
drg_hdf5.add_variable("the_object.stlc.vec_user_defined[0].a")
drg_hdf5.add_variable("the_object.stlc.vec_user_defined[0].vec[0]")
drg_hdf5.add_variable("the_object.stlc.vec_user_defined[0].vec[2]")
drg_hdf5.set_cycle(0.1)
drg_hdf5.freq = trick.DR_Always
drg_hdf5.thisown = 0
trick.add_data_record_group(drg_hdf5, trick.DR_Buffer)

trick.exec_set_freeze_frame(0.10)
trick.stop(1.0)

if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions test/SIM_stls/models/STLCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ int STLCheckpoint::addData() {
float_deque.push_back(65.4) ;
float_deque.push_back(32.1) ;

int_array[0] = 10;
int_array[1] = 20;
int_array[2] = 30;
int_array[3] = 40;

string_deque.push_back("Welcome") ;
string_deque.push_back("to") ;
string_deque.push_back("PhoneMart") ;
Expand Down
14 changes: 8 additions & 6 deletions test/SIM_stls/models/STLCheckpoint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#ifndef STLCHECKPOINT_HH
#define STLCHECKPOINT_HH

#include <map>
#include <vector>
#include <list>
#include <array>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <string>
#include <utility>

#include <vector>

class SimpleWrapper {
public:
Expand Down Expand Up @@ -61,6 +61,8 @@ class STLCheckpoint {
std::multimap< int , std::string > string_data_multimap ;
std::multimap< std::string , std::string > string_multimap ;

std::array<int, 4> int_array;

std::vector< double > double_vector ;
std::vector< std::string > string_vector ;

Expand Down
6 changes: 6 additions & 0 deletions test_sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ SIM_stls:
returns: 0
RUN_test/unit_test.py:
returns: 0
RUN_test_dr/input_dr.py:
returns: 0
compare:
- test/SIM_stls/RUN_test_dr/log_STL_DR.csv vs. test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_Master.csv
- test/SIM_stls/RUN_test_dr/log_STL_DR_bin.trk vs. test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_bin_Master.trk
- test/SIM_stls/RUN_test_dr/log_STL_DR_hdf5.header vs. test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_hdf5_Master.header

SIM_test_dr:
path: test/SIM_test_dr
Expand Down
156 changes: 81 additions & 75 deletions trick_source/sim_services/DataRecord/DRAscii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
((Alex Lin) (NASA) (April 2009) (--) (c++ port)))
*/

#include <iostream>
#include <stdlib.h>
#include <string.h>

#include "trick/DRAscii.hh"

#include "trick/ReferenceUtils.hh"
#include "trick/bitfield_proto.h"
#include "trick/command_line_protos.h"
#include "trick/memorymanager_c_intf.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
#include "trick/bitfield_proto.h"

#include <iostream>
#include <stdlib.h>
#include <string.h>

Trick::DRAscii::DRAscii( std::string in_name, Trick::DR_Type dr_type ) : Trick::DataRecordGroup( in_name, dr_type ) {

Expand Down Expand Up @@ -181,79 +183,83 @@ int Trick::DRAscii::copy_data_ascii_item( Trick::DataRecordBuffer * DI, int item
unsigned long bf;
int sbf;

address = DI->buffer + (item_num * DI->ref->attr->size) ;
int item_size = (int)Trick::ReferenceUtils::effective_trick_size(DI->ref);
TRICK_TYPE item_type = Trick::ReferenceUtils::effective_trick_type(DI->ref);
address = DI->buffer + (item_num * item_size);

size_t writer_buf_spare = writer_buff + writer_buff_size - buf;

switch (DI->ref->attr->type) {
case TRICK_CHARACTER:
snprintf(buf, writer_buf_spare, "%c", *((char *) address));
break;

case TRICK_UNSIGNED_CHARACTER:
snprintf(buf, writer_buf_spare, "%u", *((unsigned char *) address));
break;

case TRICK_BOOLEAN:
snprintf(buf, writer_buf_spare, "%u", *((bool *) address));
break;

case TRICK_STRING:
snprintf(buf, writer_buf_spare, "%s", *((char **) address));
break;

case TRICK_SHORT:
snprintf(buf, writer_buf_spare, "%d", *((short *) address));
break;

case TRICK_UNSIGNED_SHORT:
snprintf(buf, writer_buf_spare, "%u", *((unsigned short *) address));
break;

case TRICK_ENUMERATED:
case TRICK_INTEGER:
snprintf(buf, writer_buf_spare, "%d", *((int *) address));
break;

case TRICK_UNSIGNED_INTEGER:
snprintf(buf, writer_buf_spare, "%u", *((unsigned int *) address));
break;

case TRICK_LONG:
snprintf(buf, writer_buf_spare, "%ld", *((long *) address));
break;

case TRICK_UNSIGNED_LONG:
snprintf(buf, writer_buf_spare, "%lu", *((unsigned long *) address));
break;

case TRICK_FLOAT:
snprintf(buf, writer_buf_spare, ascii_float_format.c_str() , *((float *) address));
break;

case TRICK_DOUBLE:
snprintf(buf, writer_buf_spare, ascii_double_format.c_str() , *((double *) address));
break;

case TRICK_BITFIELD:
sbf = GET_BITFIELD(address, DI->ref->attr->size, DI->ref->attr->index[0].start, DI->ref->attr->index[0].size);
snprintf(buf, writer_buf_spare, "%d", sbf);
break;

case TRICK_UNSIGNED_BITFIELD:
bf = GET_UNSIGNED_BITFIELD(address, DI->ref->attr->size, DI->ref->attr->index[0].start, DI->ref->attr->index[0].size);
snprintf(buf, writer_buf_spare, "%lu", bf);
break;

case TRICK_LONG_LONG:
snprintf(buf, writer_buf_spare, "%lld", *((long long *) address));
break;

case TRICK_UNSIGNED_LONG_LONG:
snprintf(buf, writer_buf_spare, "%llu", *((unsigned long long *) address));
break;
default:
break;
switch (item_type)
{
case TRICK_CHARACTER:
snprintf(buf, writer_buf_spare, "%c", *((char*)address));
break;

case TRICK_UNSIGNED_CHARACTER:
snprintf(buf, writer_buf_spare, "%u", *((unsigned char*)address));
break;

case TRICK_BOOLEAN:
snprintf(buf, writer_buf_spare, "%u", *((bool*)address));
break;

case TRICK_STRING:
snprintf(buf, writer_buf_spare, "%s", *((char**)address));
break;

case TRICK_SHORT:
snprintf(buf, writer_buf_spare, "%d", *((short*)address));
break;

case TRICK_UNSIGNED_SHORT:
snprintf(buf, writer_buf_spare, "%u", *((unsigned short*)address));
break;

case TRICK_ENUMERATED:
case TRICK_INTEGER:
snprintf(buf, writer_buf_spare, "%d", *((int*)address));
break;

case TRICK_UNSIGNED_INTEGER:
snprintf(buf, writer_buf_spare, "%u", *((unsigned int*)address));
break;

case TRICK_LONG:
snprintf(buf, writer_buf_spare, "%ld", *((long*)address));
break;

case TRICK_UNSIGNED_LONG:
snprintf(buf, writer_buf_spare, "%lu", *((unsigned long*)address));
break;

case TRICK_FLOAT:
snprintf(buf, writer_buf_spare, ascii_float_format.c_str(), *((float*)address));
break;

case TRICK_DOUBLE:
snprintf(buf, writer_buf_spare, ascii_double_format.c_str(), *((double*)address));
break;

case TRICK_BITFIELD:
sbf = GET_BITFIELD(address, DI->ref->attr->size, DI->ref->attr->index[0].start, DI->ref->attr->index[0].size);
snprintf(buf, writer_buf_spare, "%d", sbf);
break;

case TRICK_UNSIGNED_BITFIELD:
bf = GET_UNSIGNED_BITFIELD(address, DI->ref->attr->size, DI->ref->attr->index[0].start,
DI->ref->attr->index[0].size);
snprintf(buf, writer_buf_spare, "%lu", bf);
break;

case TRICK_LONG_LONG:
snprintf(buf, writer_buf_spare, "%lld", *((long long*)address));
break;

case TRICK_UNSIGNED_LONG_LONG:
snprintf(buf, writer_buf_spare, "%llu", *((unsigned long long*)address));
break;
default:
break;
}

return(0) ;
Expand Down
Loading
Loading