Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions include/trick/DataRecordGroup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ namespace Trick {
* @param curr_tic_in - time in tics to match and advance the next cycle tic
*/
void advance_log_tics_given_curr_tic(long long curr_tic_in);

/**
* Reset all the logging rates cycles and next tics as if coming out of restart or a run-time set_cycle call
*/
void reset_cycle_data_from_curr_tic();
} ;

} ;
Expand Down
2 changes: 1 addition & 1 deletion test/SIM_checkpoint_data_recording/RUN_test9/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
drg[DR_GROUP_ID].set_cycle(0.1)
drg[DR_GROUP_ID].add_cycle(0.25)

trick.checkpoint(7.0)
trick.checkpoint(7.01)

trick.stop(10.0)

Expand Down
2 changes: 1 addition & 1 deletion test/SIM_checkpoint_data_recording/RUN_test9/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def main():
exec(open("Modified_data/foo.dr").read())

# trick.checkpoint(7.0)
trick.add_read(5.0, 'trick.load_checkpoint("RUN_test9/chkpnt_7.000000")') # contains data recording, starts at t=7
trick.add_read(5.0, 'trick.load_checkpoint("RUN_test9/chkpnt_7.010000")') # contains data recording, starts at t=7.01

trick.stop(10.0)

Expand Down
31 changes: 25 additions & 6 deletions trick_source/sim_services/DataRecord/DataRecordGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ Trick::LoggingCycle::LoggingCycle(double rate_in)

void Trick::LoggingCycle::set_rate(double rate_in)
{
long long curr_tic = exec_get_time_tics();
rate_in_seconds = rate_in;
long long cycle_tics = (long long)round(rate_in * Trick::JobData::time_tic_value);
rate_in_tics = cycle_tics;
next_cycle_in_tics= exec_get_time_tics();
if((curr_tic % cycle_tics) != 0)
{
next_cycle_in_tics = (curr_tic/cycle_tics) * cycle_tics + cycle_tics;
} else
{
next_cycle_in_tics = curr_tic;
}
}

Trick::DataRecordGroup::DataRecordGroup( std::string in_name, Trick::DR_Type dr_type ) :
Expand Down Expand Up @@ -177,12 +184,18 @@ const std::string & Trick::DataRecordGroup::get_group_name() {
int Trick::DataRecordGroup::set_cycle( double in_cycle ) {
logging_rates[0].set_rate(in_cycle);
write_job->set_cycle(in_cycle) ;
if(inited) {
reset_cycle_data_from_curr_tic();
}
return(0) ;
}

int Trick::DataRecordGroup::add_cycle(double in_cycle)
{
logging_rates.emplace_back(in_cycle);
if(inited) {
reset_cycle_data_from_curr_tic();
}
return(0);
}

Expand Down Expand Up @@ -620,14 +633,19 @@ int Trick::DataRecordGroup::restart() {
init() ;

// Account for the fact that the current time tics is actually already passed for a checkpoint.
reset_cycle_data_from_curr_tic();

return 0 ;
}

void Trick::DataRecordGroup::reset_cycle_data_from_curr_tic()
{
long long curr_tics = exec_get_time_tics();
advance_log_tics_given_curr_tic(curr_tics);

write_job->next_tics = calculate_next_logging_tic(curr_tics);
write_job->cycle_tics = write_job->next_tics - curr_tics;
write_job->cycle = (double)write_job->cycle_tics / Trick::JobData::time_tic_value;

return 0 ;
}

int Trick::DataRecordGroup::write_header() {
Expand Down Expand Up @@ -839,10 +857,11 @@ void Trick::DataRecordGroup::advance_log_tics_given_curr_tic(long long curr_tic_
{
for(size_t cycleIndex = 0; cycleIndex < logging_rates.size(); ++cycleIndex)
{
long long logNextTic = logging_rates[cycleIndex].next_cycle_in_tics;
if(logNextTic == curr_tic_in)
long long & logNextTic = logging_rates[cycleIndex].next_cycle_in_tics;

while(logNextTic <= curr_tic_in)
{
logging_rates[cycleIndex].next_cycle_in_tics += logging_rates[cycleIndex].rate_in_tics;
logNextTic += logging_rates[cycleIndex].rate_in_tics;
}
}
}
Expand Down
Loading