More CMS50F stuff, and a resmed fix

This commit is contained in:
Mark Watkins 2014-08-20 13:03:01 +10:00
parent c39a28a536
commit ef8958ce12
3 changed files with 46 additions and 41 deletions

View File

@ -175,7 +175,8 @@ int cms50_seqlength = sizeof(cms50_sequence);
QString CMS50F37Loader::getUser() QString CMS50F37Loader::getUser()
{ {
user = QString(); if (!user.isEmpty()) return user;
sendCommand(COMMAND_GET_USER_INFO); sendCommand(COMMAND_GET_USER_INFO);
QTime time; QTime time;
@ -226,20 +227,6 @@ QString CMS50F37Loader::getDeviceString()
return QString("%1 %2").arg(getVendor()).arg(getModel()); 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() int CMS50F37Loader::getSessionCount()
{ {
session_count = -1; session_count = -1;
@ -322,7 +309,7 @@ void CMS50F37Loader::processBytes(QByteArray bytes)
quint8 pulse; quint8 pulse;
do { do {
unsigned char res = bytes.at(idx); unsigned char res = buffer.at(idx);
len = lengths[res & 0x1f]; len = lengths[res & 0x1f];
@ -357,8 +344,7 @@ void CMS50F37Loader::processBytes(QByteArray bytes)
// COMMAND_GET_USER_INFO // COMMAND_GET_USER_INFO
case 0x05: // 5,80,80,f5,f3,e5,f2,80,80 case 0x05: // 5,80,80,f5,f3,e5,f2,80,80
// User // User
user = QString(buffer.mid(idx+3,4)); user = QString(buffer.mid(idx+3).trimmed());
user_index = buffer.at(idx+8);
qDebug() << "0x05:" << user; qDebug() << "0x05:" << user;
break; break;
@ -369,6 +355,10 @@ void CMS50F37Loader::processBytes(QByteArray bytes)
// COMMAND_GET_SESSION_TIME // COMMAND_GET_SESSION_TIME
case 0x07: // 7,80,80,80,94,8e,88,92 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(); year = QString().sprintf("%02i%02i",buffer.at(idx+4), buffer.at(idx+5)).toInt();
month = QString().sprintf("%02i", buffer.at(idx+6)).toInt(); month = QString().sprintf("%02i", buffer.at(idx+6)).toInt();
day = QString().sprintf("%02i", buffer.at(idx+7)).toInt(); day = QString().sprintf("%02i", buffer.at(idx+7)).toInt();
@ -379,10 +369,15 @@ void CMS50F37Loader::processBytes(QByteArray bytes)
// COMMAND_GET_SESSION_DURATION // COMMAND_GET_SESSION_DURATION
case 0x08: // 8,80,80,80,a4,81,80,80 // 00, 00, 24, 01, 00, 00 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
duration = ((buffer.at(idx+1) & 0x4) << 5); duration = buffer.at(idx+4);
duration |= buffer.at(idx+4); duration = buffer.at(idx+5) << 8;
duration |= (buffer.at(idx+5) | ((buffer.at(idx+1) & 0x8) << 4)) << 8; duration = buffer.at(idx+6) << 8;
duration = buffer.at(idx+7) << 8;
break; break;
// COMMAND_GET_SESSION_COUNT // COMMAND_GET_SESSION_COUNT

View File

@ -53,7 +53,6 @@ Q_OBJECT
virtual QString getVendor(); virtual QString getVendor();
virtual QString getDeviceString(); virtual QString getDeviceString();
virtual int getUserIndex();
virtual QDateTime getDateTime(int session); virtual QDateTime getDateTime(int session);
virtual int getDuration(int session); virtual int getDuration(int session);
virtual int getSessionCount(); virtual int getSessionCount();
@ -125,7 +124,6 @@ protected:
QTime imp_time; QTime imp_time;
QString user; QString user;
int user_index;
unsigned char current_command; unsigned char current_command;

View File

@ -1010,17 +1010,19 @@ MachineInfo ResmedLoader::PeekInfo(const QString & path)
struct EDFduration { struct EDFduration {
EDFduration() { start = end = 0; } EDFduration() { start = end = 0; iseve = false; }
EDFduration(const EDFduration & copy) { EDFduration(const EDFduration & copy) {
path = copy.path; path = copy.path;
start = copy.start; start = copy.start;
end = copy.end; end = copy.end;
iseve = copy.iseve;
} }
EDFduration(quint32 start, quint32 end, QString path) : EDFduration(quint32 start, quint32 end, QString path) :
start(start), end(end), path(path) {} start(start), end(end), path(path) {}
quint32 start; quint32 start;
quint32 end; quint32 end;
QString path; QString path;
bool iseve;
}; };
@ -1119,25 +1121,29 @@ EDFduration getEDFDuration(QString filename)
QDateTime dt2 = QDateTime::fromString(filedate, "yyyyMMdd_hhmmss"); QDateTime dt2 = QDateTime::fromString(filedate, "yyyyMMdd_hhmmss");
quint32 st2 = dt2.toTime_t(); 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); 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); EDFduration dur(start, end, filename);
dur.iseve = (ext.toUpper() == "EVE");
return dur; return dur;
} }
@ -1275,7 +1281,13 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path)
EDFGroup group; EDFGroup group;
if (type == "BRP") group.BRP = newpath; 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 == "PLD") group.PLD = newpath;
else if (type == "SAD") group.SAD = newpath; else if (type == "SAD") group.SAD = newpath;
else continue; else continue;