diff --git a/SleepLib/event.h b/SleepLib/event.h index dd2af625..52e3de7d 100644 --- a/SleepLib/event.h +++ b/SleepLib/event.h @@ -10,7 +10,7 @@ #include #include "machine_common.h" -typedef double EventDataType; +typedef float EventDataType; class Event { diff --git a/SleepLib/loader_plugins/prs1_loader.cpp b/SleepLib/loader_plugins/prs1_loader.cpp index e0aad523..6366d23a 100644 --- a/SleepLib/loader_plugins/prs1_loader.cpp +++ b/SleepLib/loader_plugins/prs1_loader.cpp @@ -889,7 +889,181 @@ bool PRS1Loader::OpenEvents(Session *session,QString filename) return true; } +struct WaveHeaderList { + quint16 interleave; + quint8 sample_format; + WaveHeaderList(quint16 i,quint8 f){ interleave=i; sample_format=f; } +}; + bool PRS1Loader::OpenWaveforms(Session *session,QString filename) +{ + //int sequence,seconds,br,htype,version,numsignals; + QFile file(filename); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Couldn't open waveform file" << filename; + return false; + } + + int pos,br,size=file.size(); + if (size>max_load_buffer_size) { + qWarning() << "Waveform too big, increase max_load_buffer_size in PRS1Loader sourcecode" << filename; + return false; + } + + br=file.read((char *)m_buffer,size); + if (br2) { + qWarning() << "More than 2 Waveforms in " << filename; + return false; + } + pos=0x14+(num_signals-1)*3; + vector whl; + // add the in reverse... + for (int i=0;i3) { + qDebug() << "3 Faulty Waveform Headers in a row.. Aborting" << filename; + return false; + } + qDebug() << "Faulty Header Checksum, skipping block" << block; + pos+=length; + continue; + } else { + int diff=(lasttimestamp+duration)-timestamp; + length=m_buffer[pos+0x1] | m_buffer[pos+0x2] << 8; // block length in bytes + duration=m_buffer[pos+0xf] | m_buffer[pos+0x10] << 8; // block duration in seconds + if (diff || corrupt) { + qDebug() << "Timestamp restarts" << diff << corrupt << duration; + + + for (int i=0;iAddWaveform(w); + wlength[i]=0; + wdur[i]=0; + } + start=timestamp; + corrupt=0; + } + } + + pos+=hl+1; + //qDebug() << (duration*num_signals*whl[0].interleave) << length-(hl+3); + if (num_signals==1) { // no interleave.. this is much quicker. + int bs=duration*whl[0].interleave; + memcpy((char *)&(waveform[0])[wlength[0]],(char *)&m_buffer[pos],bs); + + wlength[0]+=bs; + + pos+=bs; + } else { + for (int i=0;iAddWaveform(w); + } + + int froog=3; + /* file.read(headerbytes,sizeof(PRS1Header)); + file.read(waveheaderbytes,sizeof(PRS1Header)); + int ns=waveheader.num_signals; + WaveHeaderList ws[ns]; + char * wsc=&ws[0]; + file.read(wsc,waveheader.num_signals*3); + chksum8=0; + for (int i=0;i<15;i++) chksum8+=headerbytes[i]; + for (int i=0;i<5;i++) chksum8+=waveheaderbytes[i]; + for (int i=0;iabs(diff)) { - duration+=diff; // really Subtracting.. - samples+=diff*5; - } else { - qWarning() << "Waveform out of sync beyond the first entry" << sequence << duration << diff; + if (version==5) { + qWarning() << "ASV Waveform out of sync" << sequence << duration << diff << timestamp-lastts; + } else { + if (diff<0) { + if (duration>abs(diff)) { + duration+=diff; // really Subtracting.. + samples+=diff*5; + } else { + qWarning() << "Waveform out of sync beyond the first entry" << sequence << duration << diff; + } + } else if (diff>0) { + qDebug() << "Fixing up Waveform sync" << sequence; + for (int i=0;i0) { - qDebug() << "Fixing up Waveform sync" << sequence; - for (int i=0;i >::iterator i; vector::iterator j; + int zz=0; for (i=waveforms.begin(); i!=waveforms.end(); i++) { + qDebug() << "Storing Waveform" << zz++ << filename; out << (quint16)i->first; // Machine Code t16=i->second.size(); out << t16; // Number of (hopefully non-linear) waveform chunks - + int chnk=0; for (j=i->second.begin(); j!=i->second.end(); j++) { + qDebug() << "Storing Waveform Chunk" << chnk++; Waveform &w=*(*j); // 64bit number.. @@ -656,6 +660,7 @@ bool Session::StoreWaveforms(QString filename) //t8=0; // 0=signed, 1=unsigned, 2=float // followed by sample data. + qDebug() << "Writing " << (*j)->samples() << "samples"; for (int k=0; k<(*j)->samples(); k++) out << w[k]; } } diff --git a/docs/PRS1 Data Format.odt b/docs/PRS1 Data Format.odt index 4608054c..97668957 100644 Binary files a/docs/PRS1 Data Format.odt and b/docs/PRS1 Data Format.odt differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 316c5228..75480aa0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -79,7 +79,7 @@ MainWindow::MainWindow(QWidget *parent) : if (!pref.Exists("LinkGraphMovement")) pref["LinkGraphMovement"]=true; else ui->action_Link_Graphs->setChecked(pref["LinkGraphMovement"].toBool()); - if (!pref.Exists("ShowDebug")) pref["ShowDebug"]=false; + if (!pref.Exists("ShowDebug")) pref["ShowDebug"]=true; else ui->actionDebug->setChecked(pref["ShowDebug"].toBool()); if (!pref["ShowDebug"].toBool()) {