MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / read_thread

Method read_thread

src/board_controller/playback_file_board.cpp:222–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222void PlaybackFileBoard::read_thread (int preset, std::string file)
223{
224 std::string preset_str = preset_to_string (preset);
225 if (board_descr.find (preset_str) == board_descr.end ())
226 {
227 safe_logger (spdlog::level::err, "no preset {} for board {}", preset, board_id);
228 return;
229 }
230
231 FILE *fp;
232 fp = fopen (file.c_str (), "rb");
233 if (fp == NULL)
234 {
235 safe_logger (spdlog::level::err, "failed to open file in thread");
236 return;
237 }
238
239 json board_preset = board_descr[preset_str];
240 int num_rows = board_preset["num_rows"];
241 double *package = new double[num_rows];
242 for (int i = 0; i < num_rows; i++)
243 {
244 package[i] = 0.0;
245 }
246 char buf[MAX_LINE_LENGTH];
247 double last_timestamp = -1.0;
248 bool new_timestamps = use_new_timestamps; // to prevent changing during streaming
249 int timestamp_channel = board_preset["timestamp_channel"];
250 double accumulated_time_delta = 0.0;
251
252 bool reached_end = false;
253 while (keep_alive)
254 {
255 auto start = std::chrono::high_resolution_clock::now ();
256 // prevent race condition with another config_board method call
257 lock.lock ();
258 double cur_index = pos_percentage[preset];
259 if ((int)cur_index >= 0)
260 {
261 int new_pos = (int)(cur_index * (file_offsets[preset].size () / 100.0));
262 try
263 {
264 fseek (fp, file_offsets[preset][new_pos], SEEK_SET);
265 safe_logger (spdlog::level::trace, "set position in a file to {}", new_pos);
266 }
267 catch (...)
268 {
269 // should never happen since input is already validated
270 safe_logger (spdlog::level::warn, "invalid position in a file");
271 }
272 last_timestamp = -1;
273 pos_percentage[preset] = -1;
274 }
275 lock.unlock ();
276 char *res = fgets (buf, sizeof (buf), fp);
277 if ((loopback) && (res == NULL))
278 {
279 fseek (fp, 0, SEEK_SET); // go to beginning'

Callers 1

start_streamMethod · 0.95

Calls 3

get_timestampFunction · 0.85
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected