From 258b549967de5b68f054d00db837597e3dbbf454 Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Thu, 9 May 2019 13:05:53 -0400 Subject: [PATCH] Clean up oximeter import date/time handling --- .../SleepLib/loader_plugins/cms50_loader.cpp | 6 +++-- .../loader_plugins/cms50f37_loader.cpp | 26 +++++++++---------- .../SleepLib/loader_plugins/cms50f37_loader.h | 4 +-- .../loader_plugins/md300w1_loader.cpp | 8 +++--- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/oscar/SleepLib/loader_plugins/cms50_loader.cpp b/oscar/SleepLib/loader_plugins/cms50_loader.cpp index f013f9ee..2d79cfb8 100644 --- a/oscar/SleepLib/loader_plugins/cms50_loader.cpp +++ b/oscar/SleepLib/loader_plugins/cms50_loader.cpp @@ -591,7 +591,9 @@ bool CMS50Loader::readSpoRFile(QString path) if (dchr[0]) { QString dstr(dchr); m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss"); - if (m_startTime.date().year() < 2000) { m_startTime = m_startTime.addYears(100); } + if (m_startTime.date().year() < 2000) { + m_startTime = m_startTime.addYears(100); + } } else { m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0)); cms50dplus = true; @@ -614,7 +616,7 @@ bool CMS50Loader::readSpoRFile(QString path) in >> hour >> minute >> second; if ( year == 0 ) { // typically from a CMS50D+ - m_startTime = QDateTime(QDate::currentDate(), QTime(0, 0, 0)); + m_startTime = QDateTime(QDate::currentDate(), QTime(hour, minute, second)); cms50dplus = true; } else diff --git a/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp b/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp index df2137c6..b85ccdca 100644 --- a/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp +++ b/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp @@ -13,7 +13,7 @@ // that change loader behaviour or modify channels. //******************************************************************************************** -#include +// #include #include #include #include @@ -167,20 +167,20 @@ unsigned char cms50_sequence[] = { 0xa7, 0xa2, 0xa0, 0xb0, 0xac, 0xb3, 0xad, 0xa const int TIMEOUT = 2000; -// const quint8 COMMAND_GET_VERSION = 0xa0; // not entirely sure of this one -const quint8 COMMAND_CMS50_HELLO2 = 0xa2; // stop live data stream +const quint8 COMMAND_GET_VERSION = 0xA0; // not sure of this one +const quint8 COMMAND_CMS50_HELLO2 = 0xA2; // stop live data stream const quint8 COMMAND_GET_SESSION_COUNT = 0xA3; const quint8 COMMAND_GET_SESSION_DURATION = 0xA4; const quint8 COMMAND_GET_SESSION_TIME = 0xA5; const quint8 COMMAND_GET_SESSION_DATA = 0xA6; -const quint8 COMMAND_CMS50_HELLO1 = 0xa7; // stop stored data stream +const quint8 COMMAND_CMS50_HELLO1 = 0xA7; // stop stored data stream const quint8 COMMAND_GET_OXIMETER_MODEL = 0xA8; const quint8 COMMAND_GET_OXIMETER_VENDOR = 0xA9; const quint8 COMMAND_GET_OXIMETER_DEVICEID = 0xAA; const quint8 COMMAND_GET_USER_INFO = 0xAB; const quint8 COMMAND_GET_USER_COUNT = 0xAD; // for future check and use const quint8 COMMAND_SESSION_ERASE = 0xAE; -const quint8 COMMAND_GET_OXIMETER_INFO = 0xb0; +const quint8 COMMAND_GET_OXIMETER_INFO = 0xB0; int cms50_seqlength = sizeof(cms50_sequence); @@ -188,7 +188,7 @@ int cms50_seqlength = sizeof(cms50_sequence); QString CMS50F37Loader::getUser() { - if (!user.isEmpty()) return user; + if (!userName.isEmpty()) return userName; sendCommand(COMMAND_GET_USER_INFO); @@ -196,10 +196,10 @@ QString CMS50F37Loader::getUser() time.start(); do { QApplication::processEvents(); - } while (user.isEmpty() && (time.elapsed() < TIMEOUT)); + } while (userName.isEmpty() && (time.elapsed() < TIMEOUT)); - qDebug() << "User 0 is " << user; - return user; + qDebug() << "User " << userIdx << " is " << userName; + return userName; } QString CMS50F37Loader::getVendor() @@ -343,11 +343,11 @@ QDateTime CMS50F37Loader::getDateTime(int session) } while ((imp_date.isNull() || imp_time.isNull()) && (time.elapsed() < TIMEOUT)); if (imp_date.isNull() && imp_time.isNull()) - datetime = QDateTime(QDate::currentDate(), QTime(0,0,0)); + datetime = QDateTime(QDate::currentDate(), QTime::currentTime()); else if ( imp_date.isNull() ) datetime = QDateTime(QDate::currentDate(), imp_time); else if ( imp_time.isNull() ) - datetime = QDateTime(imp_date, QTime(0,0,0)); + datetime = QDateTime(imp_date, QTime::currentTime()); else datetime = QDateTime(imp_date, imp_time); @@ -434,8 +434,8 @@ void CMS50F37Loader::processBytes(QByteArray bytes) // COMMAND_GET_USER_INFO case 0x05: // 5,80,80,f5,f3,e5,f2,80,80 userIdx = buffer.at(idx+2); // for future use - user = QString(buffer.mid(idx+3).trimmed()); - qDebug() << "pB: 0x05:" << user; + userName = QString(buffer.mid(idx+3).trimmed()); + qDebug() << "pB: 0x05:" << userName; break; // Command GET_VERSION diff --git a/oscar/SleepLib/loader_plugins/cms50f37_loader.h b/oscar/SleepLib/loader_plugins/cms50f37_loader.h index 0d9abf7c..f4805a0c 100644 --- a/oscar/SleepLib/loader_plugins/cms50f37_loader.h +++ b/oscar/SleepLib/loader_plugins/cms50f37_loader.h @@ -46,7 +46,7 @@ Q_OBJECT virtual void process(); - virtual bool isStartTimeValid() { return true; } + virtual bool isStartTimeValid() { return !cms50dplus; } virtual QString getUser(); virtual QString getModel(); @@ -132,7 +132,7 @@ protected: QDate imp_date; QTime imp_time; - QString user; + QString userName; unsigned char current_command; diff --git a/oscar/SleepLib/loader_plugins/md300w1_loader.cpp b/oscar/SleepLib/loader_plugins/md300w1_loader.cpp index ed62393d..1161e247 100644 --- a/oscar/SleepLib/loader_plugins/md300w1_loader.cpp +++ b/oscar/SleepLib/loader_plugins/md300w1_loader.cpp @@ -13,7 +13,7 @@ // loader that change loader behaviour or modify channels. //******************************************************************************************** -#include +// #include #include #include #include @@ -193,7 +193,9 @@ bool MD300W1Loader::readDATFile(const QString & path) int gap; for (int pos = 0; pos < n; ++pos) { int i = 3 + (pos * 11); - QString datestr = QString().sprintf("%02d/%02d/%02d %02d:%02d:%02d",(unsigned char)data.at(i+4),(unsigned char)data.at(i+5),(unsigned char)data.at(i+3),(unsigned char)data.at(i+6),(unsigned char)data.at(i+7),(unsigned char)data.at(i+8)); + QString datestr = QString().sprintf("%02d/%02d/%02d %02d:%02d:%02d", + (unsigned char)data.at(i+4),(unsigned char)data.at(i+5),(unsigned char)data.at(i+3), + (unsigned char)data.at(i+6),(unsigned char)data.at(i+7),(unsigned char)data.at(i+8)); QDateTime datetime = QDateTime::fromString(datestr,"MM/dd/yy HH:mm:ss"); if (datetime.date().year() < 2000) datetime = datetime.addYears(100); ts = datetime.toTime_t(); @@ -208,7 +210,7 @@ bool MD300W1Loader::readDATFile(const QString & path) } } else { // Create a new session, always for first record - qDebug() << "Create session for " << datetime.toString("yyyy.MM.dd HH:mm:ss"); + qDebug() << "Create session for " << datetime.toString("yyyy-MMM-dd HH:mm:ss"); oxirec = new QVector; oxisessions[datetime] = oxirec; m_startTime = datetime; // works for single session files...