4
4
#include < chrono>
5
5
#include < sstream>
6
6
#include < mutex>
7
+ #include < string>
7
8
8
9
#ifndef USING_ROS2
9
10
#define MCAP_IMPLEMENTATION
@@ -35,7 +36,7 @@ namespace DataTamer
35
36
static constexpr char const * kDataTamer = " data_tamer" ;
36
37
37
38
MCAPSink::MCAPSink (const std::string& filepath, bool do_compression)
38
- : filepath_(filepath), compression_(do_compression)
39
+ : filepath_(filepath), compression_(do_compression), original_filepath_(filepath)
39
40
{
40
41
openFile (filepath_);
41
42
}
@@ -121,7 +122,13 @@ bool MCAPSink::storeSnapshot(const Snapshot& snapshot)
121
122
auto const now = std::chrono::system_clock::now ();
122
123
if (reset_time_ != std::chrono::seconds (0 ) && now - start_time_ > reset_time_)
123
124
{
124
- restartRecording (filepath_, compression_);
125
+ if (create_file_on_reset_)
126
+ {
127
+ // change the current filepath to the original with "_[# resets]"" appended
128
+ filepath_ = original_filepath_ + " _" + std::to_string (file_reset_counter_);
129
+ ++file_reset_counter_;
130
+ }
131
+ restartRecordingImpl (filepath_, compression_, false );
125
132
}
126
133
return true ;
127
134
}
@@ -131,6 +138,11 @@ void MCAPSink::setMaxTimeBeforeReset(std::chrono::seconds reset_time)
131
138
reset_time_ = reset_time;
132
139
}
133
140
141
+ void MCAPSink::setCreateNewFileOnReset (bool create_file_on_reset)
142
+ {
143
+ create_file_on_reset_ = create_file_on_reset;
144
+ }
145
+
134
146
void MCAPSink::stopRecording ()
135
147
{
136
148
std::scoped_lock lk (mutex_);
@@ -140,8 +152,20 @@ void MCAPSink::stopRecording()
140
152
}
141
153
142
154
void MCAPSink::restartRecording (const std::string& filepath, bool do_compression)
155
+ {
156
+ restartRecordingImpl (filepath, do_compression, true );
157
+ }
158
+
159
+ void MCAPSink::restartRecordingImpl (const std::string& filepath, bool do_compression,
160
+ bool new_file)
143
161
{
144
162
std::scoped_lock lk (mutex_);
163
+ if (new_file)
164
+ {
165
+ // if this was called by a user, we need to change the filepath that we will increment when reset
166
+ file_reset_counter_ = 1 ;
167
+ original_filepath_ = filepath;
168
+ }
145
169
filepath_ = filepath;
146
170
compression_ = do_compression;
147
171
openFile (filepath_);
0 commit comments