diff --git a/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp b/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp index 01e86e26..d17eea6d 100644 --- a/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp @@ -175,7 +175,8 @@ int cms50_seqlength = sizeof(cms50_sequence); QString CMS50F37Loader::getUser() { - user = QString(); + if (!user.isEmpty()) return user; + sendCommand(COMMAND_GET_USER_INFO); QTime time; @@ -226,20 +227,6 @@ QString CMS50F37Loader::getDeviceString() return QString("%1 %2").arg(getVendor()).arg(getModel()); } -int CMS50F37Loader::getUserIndex() -{ - user_index = -1; - sendCommand(COMMAND_GET_USER_INFO); - - QTime time; - time.start(); - do { - QApplication::processEvents(); - } while ((user_index < 0) && (time.elapsed() < TIMEOUT)); - - return user_index; -} - int CMS50F37Loader::getSessionCount() { session_count = -1; @@ -322,7 +309,7 @@ void CMS50F37Loader::processBytes(QByteArray bytes) quint8 pulse; do { - unsigned char res = bytes.at(idx); + unsigned char res = buffer.at(idx); len = lengths[res & 0x1f]; @@ -357,8 +344,7 @@ void CMS50F37Loader::processBytes(QByteArray bytes) // COMMAND_GET_USER_INFO case 0x05: // 5,80,80,f5,f3,e5,f2,80,80 // User - user = QString(buffer.mid(idx+3,4)); - user_index = buffer.at(idx+8); + user = QString(buffer.mid(idx+3).trimmed()); qDebug() << "0x05:" << user; break; @@ -369,6 +355,10 @@ void CMS50F37Loader::processBytes(QByteArray bytes) // COMMAND_GET_SESSION_TIME case 0x07: // 7,80,80,80,94,8e,88,92 + for (int i = 2, msb = buffer.at(idx+1); i < len; i++, msb>>= 1) { + buffer[idx+i] = (buffer[idx+i] & 0x7f) | (msb & 0x01 ? 0x80 : 0); + } + year = QString().sprintf("%02i%02i",buffer.at(idx+4), buffer.at(idx+5)).toInt(); month = QString().sprintf("%02i", buffer.at(idx+6)).toInt(); day = QString().sprintf("%02i", buffer.at(idx+7)).toInt(); @@ -379,10 +369,15 @@ void CMS50F37Loader::processBytes(QByteArray bytes) // COMMAND_GET_SESSION_DURATION case 0x08: // 8,80,80,80,a4,81,80,80 // 00, 00, 24, 01, 00, 00 + for (int i = 2, msb = buffer.at(idx+1); i < len; i++, msb>>= 1) { + buffer[idx+i] = (buffer[idx+i] & 0x7f) | (msb & 0x01 ? 0x80 : 0); + } + // duration - duration = ((buffer.at(idx+1) & 0x4) << 5); - duration |= buffer.at(idx+4); - duration |= (buffer.at(idx+5) | ((buffer.at(idx+1) & 0x8) << 4)) << 8; + duration = buffer.at(idx+4); + duration = buffer.at(idx+5) << 8; + duration = buffer.at(idx+6) << 8; + duration = buffer.at(idx+7) << 8; break; // COMMAND_GET_SESSION_COUNT diff --git a/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.h b/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.h index 8a9a2a0c..0d00da64 100644 --- a/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.h +++ b/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.h @@ -53,7 +53,6 @@ Q_OBJECT virtual QString getVendor(); virtual QString getDeviceString(); - virtual int getUserIndex(); virtual QDateTime getDateTime(int session); virtual int getDuration(int session); virtual int getSessionCount(); @@ -125,7 +124,6 @@ protected: QTime imp_time; QString user; - int user_index; unsigned char current_command; diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp index fb08a225..bdc06d00 100644 --- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp @@ -1010,17 +1010,19 @@ MachineInfo ResmedLoader::PeekInfo(const QString & path) struct EDFduration { - EDFduration() { start = end = 0; } + EDFduration() { start = end = 0; iseve = false; } EDFduration(const EDFduration & copy) { path = copy.path; start = copy.start; end = copy.end; + iseve = copy.iseve; } EDFduration(quint32 start, quint32 end, QString path) : start(start), end(end), path(path) {} quint32 start; quint32 end; QString path; + bool iseve; }; @@ -1119,25 +1121,29 @@ EDFduration getEDFDuration(QString filename) QDateTime dt2 = QDateTime::fromString(filedate, "yyyyMMdd_hhmmss"); quint32 st2 = dt2.toTime_t(); - if (end < start) end = start; - - if (ext == "EVE") { - // This is an unavoidable kludge, because there genuinely is no duration given for EVE files. - // It could partially be avoided by parsing the EDF annotations completely, but on days with no events, this would be pointless. - - // Add some seconds to make sure some overlap happens with related sessions. - - // ************** Be cautious with this value ************** - - // A Firmware bug causes (perhaps with failing SD card) sessions to sometimes take a long time to write, and it can screw this up - // I've really got no way of detecting the other condition.. I can either have one or the other. - - end += 20; - } - start = qMin(st2, start); + if (end < start) end = qMax(st2, start)+1; // This alone should really cover the EVE.EDF condition + +// if (ext == "EVE") { +// // This is an unavoidable kludge, because there genuinely is no duration given for EVE files. +// // It could partially be avoided by parsing the EDF annotations completely, but on days with no events, this would be pointless. + +// // Add some seconds to make sure some overlap happens with related sessions. + +// // ************** Be cautious with this value ************** + +// // A Firmware bug causes (perhaps with failing SD card) sessions to sometimes take a long time to write, and it can screw this up +// // I've really got no way of detecting the other condition.. I can either have one or the other. + +// // Wait... EVE and BRP start at the same time.. that should be enough to counter overlaps! +// end += 1; +// } + + EDFduration dur(start, end, filename); + dur.iseve = (ext.toUpper() == "EVE"); + return dur; } @@ -1275,7 +1281,13 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path) EDFGroup group; if (type == "BRP") group.BRP = newpath; - else if (type == "EVE") group.EVE = newpath; + else if (type == "EVE") { + if (group.BRP.isEmpty()) { + qDebug() << "Jedimark's Order theory was wrong.. EVE's need to be parsed seperately!"; + } + group.EVE = newpath; + } + else if (type == "PLD") group.PLD = newpath; else if (type == "SAD") group.SAD = newpath; else continue;