Skip to content

Commit d7a825f

Browse files
authored
Fix interpretation of device timestamps (#736)
1 parent 70e18d7 commit d7a825f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/board_controller/openbci/galea_v4.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,12 @@ void GaleaV4::read_thread ()
408408
// calc delta between PC timestamp and device timestamp in last 10 packages,
409409
// use this delta later on to assign timestamps
410410
double pc_timestamp = get_timestamp ();
411-
double timestamp_last_package = 0.0;
412-
memcpy (&timestamp_last_package, b + 88 + offset_last_package, 8);
413-
timestamp_last_package /= 1000; // from ms to seconds
414-
double time_delta = pc_timestamp - timestamp_last_package;
411+
unsigned long long timestamp_last_package = 0.0;
412+
memcpy (&timestamp_last_package, b + 88 + offset_last_package,
413+
sizeof (unsigned long long)); // microseconds
414+
double timestamp_last_package_converted =
415+
static_cast<double> (timestamp_last_package) / 1000000.0; // convert to seconds
416+
double time_delta = pc_timestamp - timestamp_last_package_converted;
415417
time_buffer.add_data (&time_delta);
416418
int num_time_deltas = (int)time_buffer.get_current_data (10, latest_times);
417419
time_delta = 0.0;
@@ -447,15 +449,18 @@ void GaleaV4::read_thread ()
447449
exg_package[i - 3] =
448450
exg_scale * (double)cast_24bit_to_int32 (b + offset + 5 + 3 * (i - 4));
449451
}
450-
double timestamp_device = 0.0;
451-
memcpy (&timestamp_device, b + 88 + offset, 8);
452-
timestamp_device /= 1000; // from ms to seconds
452+
unsigned long long timestamp_device = 0.0;
453+
memcpy (&timestamp_device, b + 88 + offset,
454+
sizeof (unsigned long long)); // reports microseconds
455+
456+
double timestamp_device_converted = static_cast<double> (timestamp_device);
457+
timestamp_device_converted /= 1000000.0; // convert to seconds
453458

454459
exg_package[board_descr["default"]["timestamp_channel"].get<int> ()] =
455-
timestamp_device + time_delta - half_rtt;
460+
timestamp_device_converted + time_delta - half_rtt;
456461
exg_package[board_descr["default"]["other_channels"][0].get<int> ()] = pc_timestamp;
457462
exg_package[board_descr["default"]["other_channels"][1].get<int> ()] =
458-
timestamp_device;
463+
timestamp_device_converted;
459464
push_package (exg_package);
460465

461466
// aux, 5 times smaller sampling rate

0 commit comments

Comments
 (0)