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

Method read_thread

src/board_controller/openbci/galea.cpp:359–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357}
358
359void Galea::read_thread ()
360{
361 int res;
362 unsigned char b[Galea::max_transaction_size];
363 DataBuffer time_buffer (1, 11);
364 double latest_times[10];
365 for (int i = 0; i < Galea::max_transaction_size; i++)
366 {
367 b[i] = 0;
368 }
369
370 int num_exg_rows = board_descr["default"]["num_rows"];
371 int num_aux_rows = board_descr["auxiliary"]["num_rows"];
372 double *exg_package = new double[num_exg_rows];
373 double *aux_package = new double[num_aux_rows];
374 for (int i = 0; i < num_exg_rows; i++)
375 {
376 exg_package[i] = 0.0;
377 }
378 for (int i = 0; i < num_aux_rows; i++)
379 {
380 aux_package[i] = 0.0;
381 }
382
383 while (keep_alive)
384 {
385 res = socket->recv (b, Galea::max_transaction_size);
386 if (res == -1)
387 {
388#ifdef _WIN32
389 safe_logger (spdlog::level::err, "WSAGetLastError is {}", WSAGetLastError ());
390#else
391 safe_logger (spdlog::level::err, "errno {} message {}", errno, strerror (errno));
392#endif
393 continue;
394 }
395 if (res % Galea::package_size != 0)
396 {
397 if (res > 0)
398 {
399 // more likely its a string received, try to print it
400 b[res] = '\0';
401 safe_logger (spdlog::level::warn, "Received: {}", b);
402 }
403 continue;
404 }
405 else
406 {
407 int num_packages = res / Galea::package_size;
408 int offset_last_package = Galea::package_size * (num_packages - 1);
409 // calc delta between PC timestamp and device timestamp in last 10 packages,
410 // use this delta later on to assign timestamps
411 double pc_timestamp = get_timestamp ();
412 unsigned long long timestamp_last_package = 0.0;
413 memcpy (&timestamp_last_package, b + 88 + offset_last_package,
414 sizeof (unsigned long long)); // microseconds
415 double timestamp_last_package_converted =
416 static_cast<double> (timestamp_last_package) / 1000000.0; // convert to seconds

Callers 3

start_streamMethod · 0.95
start_streamMethod · 0.45
start_streamMethod · 0.45

Calls 9

get_timestampFunction · 0.85
cast_24bit_to_int32Function · 0.85
get_current_dataMethod · 0.80
get_gain_for_channelMethod · 0.80
recvMethod · 0.45
add_dataMethod · 0.45

Tested by

no test coverage detected