/* SleepLib ResMed Loader Implementation Author: Mark Watkins License: GPL */ #include #include #include #include #include #include #include "resmed_loader.h" #include "SleepLib/session.h" EDFParser::EDFParser(QString name) { buffer=NULL; Open(name); } EDFParser::~EDFParser() { vector::iterator s; for (s=edfsignals.begin();s!=edfsignals.end();s++) { if ((*s)->data) delete [] (*s)->data; if ((*s)->adata) delete [] (*s)->adata; delete *s; } if (buffer) delete [] buffer; } QString EDFParser::Read(int si) { QString str; if (pos>=filesize) return ""; for (int i=0;idata=NULL; signal->adata=NULL; edfsignals[i]->label=Read(16); } for (int i=0;itransducer_type=Read(80); for (int i=0;iphysical_dimension=Read(8); for (int i=0;iphysical_minimum=Read(8).toLong(&ok); for (int i=0;iphysical_maximum=Read(8).toLong(&ok); for (int i=0;idigital_minimum=Read(8).toLong(&ok); for (int i=0;idigital_maximum=Read(8).toLong(&ok); for (int i=0;iprefiltering=Read(80); for (int i=0;inr=Read(8).toLong(&ok); for (int i=0;ireserved=Read(32); for (int i=0;ilabel << endl; if (edfsignals[i]->label!="EDF Annotations") { // Waveforms edfsignals[i]->data=new qint16 [edfsignals[i]->nr]; for (int j=0;jnr;j++){ long t; t=Read(2).toLong(&ok); if (!ok) return false; edfsignals[i]->data[j]=t & 0xffff; } } else { // Annotation data.. edfsignals[i]->adata=(char *) new char [edfsignals[i]->nr*2]; //cout << signals[i]->nr << endl;; for (int j=0;jnr*2;j++) edfsignals[i]->adata[j]=buffer[pos++]; } //cout << "Read Signal" << endl; } return true; } bool EDFParser::Open(QString name) { QFile f(name); if (!f.open(QIODevice::ReadOnly)) return false; if (!f.isReadable()) return false; filename=name; filesize=f.size(); buffer=new char [filesize]; f.read(buffer,filesize); f.close(); pos=0; } ResmedLoader::ResmedLoader() { } ResmedLoader::~ResmedLoader() { } Machine *ResmedLoader::CreateMachine(QString serial,Profile *profile) { assert(profile!=NULL); vector ml=profile->GetMachines(MT_CPAP); bool found=false; for (vector::iterator i=ml.begin(); i!=ml.end(); i++) { if (((*i)->GetClass()==resmed_class_name) && ((*i)->properties["Serial"]==serial)) { ResmedList[serial]=*i; //static_cast(*i); found=true; break; } } if (found) return ResmedList[serial]; qDebug(("Create ResMed Machine %s"+serial).toLatin1()); Machine *m=new CPAP(profile,0); m->SetClass(resmed_class_name); ResmedList[serial]=m; profile->AddMachine(m); m->properties["Serial"]=serial; m->properties["Brand"]="ResMed"; return m; } bool ResmedLoader::Open(QString & path,Profile *profile) { QString newpath; QString dirtag="DATALOG"; if (path.endsWith("/"+dirtag)) { newpath=path; } else { newpath=path+"/"+dirtag; } QDir dir(newpath); if ((!dir.exists() || !dir.isReadable())) return 0; qDebug(("ResmedLoader::Open newpath="+newpath).toLatin1()); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setSorting(QDir::Name); QFileInfoList flist=dir.entryInfoList(); map > sessfiles; QString ext,rest,datestr,s,codestr; SessionID sessionid; QDateTime date; map sessions; Session *sess; Machine *m; for (int i=0;iSetChanged(true); switch(code) { case 0: LoadEVE(m,sess,edf); break; case 1: LoadPLD(m,sess,edf); break; case 2: LoadBRP(m,sess,edf); break; case 3: LoadSAD(m,sess,edf); break; } } return 0; } bool ResmedLoader::LoadEVE(Machine *mach,Session *sess,EDFParser &edf) { QString t; for (int s=0;snr); qDebug((edf.edfsignals[s]->label+" "+t).toLatin1()); if (edf.edfsignals[s]->adata) { } } } bool ResmedLoader::LoadBRP(Machine *mach,Session *sess,EDFParser &edf) { } bool ResmedLoader::LoadSAD(Machine *mach,Session *sess,EDFParser &edf) { } bool ResmedLoader::LoadPLD(Machine *mach,Session *sess,EDFParser &edf) { } void ResInitModelMap() { // ModelMap[34]="S9 with some weird feature"; }; bool resmed_initialized=false; void ResmedLoader::Register() { if (resmed_initialized) return; qDebug("Registering ResmedLoader"); RegisterLoader(new ResmedLoader()); ResInitModelMap(); resmed_initialized=true; }