From f3273b204592283afd4f00be339d3ce9aa4a291c Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Mon, 9 May 2022 10:51:17 -0400 Subject: [PATCH] Fix incorrect Viatom warning when a CheckMe O2 Max recorded an odd number of samples. --- .../SleepLib/loader_plugins/viatom_loader.cpp | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/oscar/SleepLib/loader_plugins/viatom_loader.cpp b/oscar/SleepLib/loader_plugins/viatom_loader.cpp index dbaf5dcb..9d0fb2fa 100644 --- a/oscar/SleepLib/loader_plugins/viatom_loader.cpp +++ b/oscar/SleepLib/loader_plugins/viatom_loader.cpp @@ -418,19 +418,23 @@ QList ViatomFile::ReadData() QList dedup; bool all_are_duplicated = true; - CHECK_VALUE(records.size() % 2, 0); - for (int i = 0; i < records.size(); i += 2) { - auto & a = records.at(i); - auto & b = records.at(i+1); - if (a.spo2 != b.spo2 - || a.hr != b.hr - || a.oximetry_invalid != b.oximetry_invalid - || a.motion != b.motion - || a.vibration != b.vibration) { - all_are_duplicated = false; - break; + if ((records.size() % 2) != 0) { + // An odd number of samples inherently can't be all duplicates. + all_are_duplicated = false; + } else { + for (int i = 0; i < records.size(); i += 2) { + auto & a = records.at(i); + auto & b = records.at(i+1); + if (a.spo2 != b.spo2 + || a.hr != b.hr + || a.oximetry_invalid != b.oximetry_invalid + || a.motion != b.motion + || a.vibration != b.vibration) { + all_are_duplicated = false; + break; + } + dedup.append(a); } - dedup.append(a); } if (m_sig == 5) { // Confirm that CheckMe O2 Max is a true 2s sample rate.