Correct check for unsupported types in data recording (#1458)

This commit is contained in:
Jacqueline Deans 2023-02-16 16:27:47 -06:00 committed by GitHub
parent 2fa5cdfc77
commit a8c9572186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 14 deletions

View File

@ -55,6 +55,8 @@ drg.add_variable("ball.obj.state.output.position[0]", "x_pos")
drg.add_variable("ball.obj.state.output.position[1]", "y_pos")
```
Only individual primitive types can be recorded. Arrays, strings/char *, structured objects, or STL types are not supported.
### Changing the Recording Rate
To change the recording rate call the <tt>set_cycle()</tt> method of the recording group.

View File

@ -405,6 +405,10 @@ namespace Trick {
*/
virtual int add_time_variable() ;
/** Check that a variable is supported by data recording. */
/** Variable must be a single primitive type - no STL, array, structured, string */
bool isSupportedType(REF2 * ref2, std::string& message);
/** Max number of digits to expect per recorded value.\n */
static const unsigned int record_size = 25; /**< trick_io(**) trick_units(--) */

View File

@ -27,5 +27,12 @@ drg[DR_GROUP_ID].add_variable("drx.drt.m")
drg[DR_GROUP_ID].add_variable("drx.drt.n")
drg[DR_GROUP_ID].add_variable("drx.drt.o")
drg[DR_GROUP_ID].add_variable("drx.drt.p")
drg[DR_GROUP_ID].add_variable("drx.drt.q[0]")
drg[DR_GROUP_ID].add_variable("drx.drt.q[1]")
drg[DR_GROUP_ID].add_variable("drx.drt.q[2]")
drg[DR_GROUP_ID].add_variable("drx.drt.q[3]")
drg[DR_GROUP_ID].add_variable("drx.drt.q[4]")
drg[DR_GROUP_ID].add_variable("drx.drt.r[0][0]")
trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_Buffer)
drg[DR_GROUP_ID].enable()

View File

@ -1,12 +1,12 @@
sys.exec.out.time {s},drx.drt.a {1},drx.drt.b {1},drx.drt.c {1},drx.drt.d {1},drx.drt.e {1},drx.drt.f {1},drx.drt.g {1},drx.drt.h {1},drx.drt.i {1},drx.drt.j {1},drx.drt.k {1},drx.drt.l {1},drx.drt.m {1},drx.drt.n {1}
0,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.1,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.2,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.3,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.4,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.5,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.6,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.7,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.8,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
0.9,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
1,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3
sys.exec.out.time {s},drx.drt.a {1},drx.drt.b {1},drx.drt.c {1},drx.drt.d {1},drx.drt.e {1},drx.drt.f {1},drx.drt.g {1},drx.drt.h {1},drx.drt.i {1},drx.drt.j {1},drx.drt.k {1},drx.drt.l {1},drx.drt.m {1},drx.drt.n {1},drx.drt.q[0] {1},drx.drt.q[1] {1},drx.drt.q[2] {1},drx.drt.q[3] {1},drx.drt.q[4] {1},drx.drt.r[0][0] {1}
0,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.1,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.2,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.3,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.4,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.5,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.6,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.7,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.8,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
0.9,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10
1,a,98,-1234,1234,-123456,123456,-1234567,123456789, 1234.5677, -1234.56789,-12345678912345,12345678912345,0,3,0,1,2,3,4, 10

1 sys.exec.out.time {s} drx.drt.a {1} drx.drt.b {1} drx.drt.c {1} drx.drt.d {1} drx.drt.e {1} drx.drt.f {1} drx.drt.g {1} drx.drt.h {1} drx.drt.i {1} drx.drt.j {1} drx.drt.k {1} drx.drt.l {1} drx.drt.m {1} drx.drt.n {1} drx.drt.q[0] {1} drx.drt.q[1] {1} drx.drt.q[2] {1} drx.drt.q[3] {1} drx.drt.q[4] {1} drx.drt.r[0][0] {1}
2 0 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
3 0.1 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
4 0.2 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
5 0.3 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
6 0.4 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
7 0.5 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
8 0.6 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
9 0.7 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
10 0.8 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
11 0.9 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10
12 1 a 98 -1234 1234 -123456 123456 -1234567 123456789 1234.5677 -1234.56789 -12345678912345 12345678912345 0 3 0 1 2 3 4 10

View File

@ -89,6 +89,8 @@ class DRTypes {
NUM_DEFS n;
char * o; // Should not actually be added
std::string p; // Should not actually be added
int q[5];
double r[2][2];
UINT_BITS uintB;
INT_BITS intB;

View File

@ -27,6 +27,13 @@ int DRTypes::init() {
n = THREE; //enumerated type
o = "3 May. Bistritz.—Left Munich at 8:35 P. M., on 1st May, arriving at Vienna early next morning; should have arrived at 6:46, but train was an hour late. Buda-Pesth seems a wonderful place, from the glimpse which I got of it from the train and the little I could walk through the streets. I feared to go very far from the station, as we had arrived late and would start as near the correct time as possible. The impression I had was that we were leaving the West and entering the East; the most western of splendid bridges over the Danube, which is here of noble width and depth, took us among the traditions of Turkish rule.";
p = "We left in pretty good time, and came after nightfall to Klausenburgh. Here I stopped for the night at the Hotel Royale. I had for dinner, or rather supper, a chicken done up some way with red pepper, which was very good but thirsty. (Mem., get recipe for Mina.) I asked the waiter, and he said it was called “paprika hendl,” and that, as it was a national dish, I should be able to get it anywhere along the Carpathians. I found my smattering of German very useful here; indeed, I don't know how I should be able to get on without it.";
for (int i = 0; i < 5; i++) {
q[i] = i;
}
r[0][0] = 10;
r[0][1] = 20;
r[1][0] = 30;
r[1][1] = 40;
/*============================================================================
Bitfields

View File

@ -339,6 +339,21 @@ int Trick::DataRecordGroup::add_change_variable( std::string in_name ) {
}
bool Trick::DataRecordGroup::isSupportedType(REF2 * ref2, std::string& message) {
if (ref2->attr->type == TRICK_STRING || ref2->attr->type == TRICK_STL || ref2->attr->type == TRICK_STRUCTURED) {
message = "Cannot Data Record variable " + std::string(ref2->reference) + " of unsupported type " + std::to_string(ref2->attr->type);
return false;
}
// If this is an array and not a single value, don't record it
if (ref2->num_index != ref2->attr->num_index) {
message = "Cannot Data Record arrayed variable " + std::string(ref2->reference);
return false;
}
return true;
}
/**
@details
-# The simulation output directory is retrieved from the CommandLineArguments
@ -380,8 +395,9 @@ int Trick::DataRecordGroup::init() {
delete drb ;
continue ;
} else {
if (ref2->attr->type == TRICK_STRING || ref2->attr->type == TRICK_STL || ref2->attr->type == TRICK_STRUCTURED || ref2->attr->num_index != 0) {
message_publish(MSG_WARNING, "Cannot Data Record unsupported type variable %s.\n", drb->name.c_str()) ;
std::string message;
if (!isSupportedType(ref2, message)) {
message_publish(MSG_WARNING, "%s\n", message.c_str()) ;
rec_buffer.erase(rec_buffer.begin() + jj--) ;
delete drb ;
continue ;