mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 18:50:44 +00:00
PRS1 Waveform Sync Issue Fixed
This commit is contained in:
parent
a9cab49a6b
commit
ecd24d72dc
@ -35,8 +35,10 @@ void gFlagsGroup::Plot(gGraphWindow &w, float scrx, float scry)
|
||||
|
||||
vector<gFlagsLine *> visible;
|
||||
for (unsigned i=0;i<layers.size();i++) {
|
||||
if (!layers[i]->isEmpty()) {
|
||||
gFlagsLine *f=dynamic_cast<gFlagsLine *>(layers[i]);
|
||||
gFlagsLine *f=dynamic_cast<gFlagsLine *>(layers[i]);
|
||||
if (!f) continue;
|
||||
|
||||
if (!f->isEmpty() || f->isAlwaysVisible()) {
|
||||
visible.push_back(f);
|
||||
}
|
||||
}
|
||||
@ -49,8 +51,8 @@ void gFlagsGroup::Plot(gGraphWindow &w, float scrx, float scry)
|
||||
}
|
||||
|
||||
|
||||
gFlagsLine::gFlagsLine(gPointData *d,QColor col,QString _label,int _line_num,int _total_lines)
|
||||
:gLayer(d),label(_label),line_num(_line_num),total_lines(_total_lines)
|
||||
gFlagsLine::gFlagsLine(gPointData *d,QColor col,QString _label,bool always_visible, int _line_num,int _total_lines)
|
||||
:gLayer(d),label(_label),m_always_visible(always_visible),line_num(_line_num),total_lines(_total_lines)
|
||||
{
|
||||
color.clear();
|
||||
color.push_back(col);
|
||||
|
@ -15,13 +15,17 @@ class gFlagsLine:public gLayer
|
||||
{
|
||||
friend class gFlagsGroup;
|
||||
public:
|
||||
gFlagsLine(gPointData *d=NULL,QColor col=QColor("black"),QString _label="",int _line_num=0,int _total_lines=0);
|
||||
gFlagsLine(gPointData *d=NULL,QColor col=Qt::black,QString _label="",bool always_visible=false, int _line_num=0,int _total_lines=0);
|
||||
virtual ~gFlagsLine();
|
||||
|
||||
virtual void Plot(gGraphWindow & w,float scrx,float scry);
|
||||
|
||||
bool isAlwaysVisible() { return m_always_visible; }
|
||||
void setAlwaysVisible(bool b) { m_always_visible=b; }
|
||||
QString Label() { return label; }
|
||||
void Label(QString s) { label=s; }
|
||||
protected:
|
||||
QString label;
|
||||
bool m_always_visible;
|
||||
int line_num,total_lines;
|
||||
};
|
||||
|
||||
|
@ -547,14 +547,16 @@ bool PRS1Loader::Parse002(Session *session,unsigned char *buffer,int size,qint64
|
||||
qDebug() << "Illegal PRS1 code " << hex << int(code) << " appeared at " << hex << pos+16;
|
||||
return false;
|
||||
}
|
||||
//assert(code<ncodes);
|
||||
// QDateTime d=QDateTime::fromMSecsSinceEpoch(t);
|
||||
// qDebug()<< d.toString("yyyy-MM-dd HH:mm:ss") << ": " << hex << pos+15 << " " << hex << int(code) ;
|
||||
//if (code==0xe) {
|
||||
// pos+=2;
|
||||
//} else
|
||||
if (code!=0x12) {
|
||||
delta=buffer[pos];
|
||||
//delta=buffer[pos];
|
||||
//duration=buffer[pos+1];
|
||||
//delta=buffer[pos+1] << 8 | buffer[pos];
|
||||
delta=buffer[pos+1] << 8 | buffer[pos];
|
||||
pos+=2;
|
||||
//QDateTime d=QDateTime::fromMSecsSinceEpoch(t);
|
||||
//qDebug()<< d.toString("yyyy-MM-dd HH:mm:ss") << ": " << hex << pos+15 << " " << hex << int(code) << int(delta);
|
||||
t+=delta*1000;
|
||||
}
|
||||
MachineCode cpapcode=Codes[(int)code];
|
||||
@ -587,6 +589,7 @@ bool PRS1Loader::Parse002(Session *session,unsigned char *buffer,int size,qint64
|
||||
case 0x04: // Pressure Pulse
|
||||
data[0]=buffer[pos++];
|
||||
session->AddEvent(new Event(t,cpapcode, data,1));
|
||||
//qDebug() << hex << data[0];
|
||||
break;
|
||||
case 0x05: // RERA
|
||||
case 0x06: // Obstructive Apoanea
|
||||
@ -615,11 +618,12 @@ bool PRS1Loader::Parse002(Session *session,unsigned char *buffer,int size,qint64
|
||||
}
|
||||
break;
|
||||
case 0x0e: // Unknown
|
||||
data[0]=buffer[pos++];
|
||||
data[0]=((char *)buffer)[pos++];
|
||||
data[1]=buffer[pos++]; //(buffer[pos+1] << 8) | buffer[pos];
|
||||
//data[0]/=10.0;
|
||||
//pos+=2;
|
||||
data[2]=buffer[pos++];
|
||||
//qDebug() << hex << data[0] << data[1] << data[2];
|
||||
session->AddEvent(new Event(t,cpapcode, data, 3));
|
||||
//tt-=data[1]*1000;
|
||||
//session->AddEvent(new Event(t,CPAP_CSR, data, 2));
|
||||
@ -889,6 +893,7 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
|
||||
{
|
||||
int size,sequence,seconds,br,htype,version,numsignals;
|
||||
unsigned cnt=0;
|
||||
qint32 lastts,ts1;
|
||||
qint64 timestamp;
|
||||
|
||||
qint64 start=0;
|
||||
@ -911,6 +916,7 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
|
||||
long fpos=0;
|
||||
//int bsize=0;
|
||||
int lasthl=0;
|
||||
qint32 expected_timestamp=0;
|
||||
while (true) {
|
||||
lasthl=hl;
|
||||
hl=20;
|
||||
@ -925,12 +931,12 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
|
||||
if (header[0]!=PRS1_MAGIC_NUMBER) {
|
||||
if (cnt==0)
|
||||
return false;
|
||||
qDebug() << "Corrupt waveform, trying to recover";
|
||||
qWarning() << "Corrupt waveform, trying to recover";
|
||||
// read the damn bytes anyway..
|
||||
|
||||
br=f.read((char *)header,lasthl-hl+1); // last bit of the header
|
||||
if (br<lasthl-hl+1) {
|
||||
qDebug() << "End of file, couldn't recover";
|
||||
qWarning() << "End of file, couldn't recover";
|
||||
break;
|
||||
}
|
||||
hl=lasthl;
|
||||
@ -954,7 +960,7 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
|
||||
htype=header[3];
|
||||
ext=header[6];
|
||||
sequence=(header[10] << 24) | (header[9] << 16) | (header[8] << 8) | header[7];
|
||||
timestamp=(header[14] << 24) | (header[13] << 16) | (header[12] << 8) | header[11];
|
||||
ts1=timestamp=(header[14] << 24) | (header[13] << 16) | (header[12] << 8) | header[11];
|
||||
seconds=(header[16] << 8) | header[15];
|
||||
numsignals=header[19] << 8 | header[18];
|
||||
|
||||
@ -999,7 +1005,39 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
|
||||
qDebug() << "PRS1 Waveform data has htype set differently";
|
||||
}
|
||||
|
||||
if (!start) start=timestamp*1000; //convert from epoch to msecs since epoch
|
||||
|
||||
if (!start) {
|
||||
lastts=timestamp;
|
||||
// expected_timestamp=timestamp+seconds;
|
||||
start=timestamp*1000; //convert from epoch to msecs since epoch
|
||||
//qDebug() << "Wave: " << cnt << seconds;
|
||||
} else {
|
||||
qint32 diff=timestamp-expected_timestamp;
|
||||
if (diff<0) {
|
||||
if (duration<diff) {
|
||||
duration+=diff;
|
||||
samples+=diff*5;
|
||||
} else {
|
||||
qWarning() << "Waveform out of sync beyond the first entry" << sequence;
|
||||
}
|
||||
} else if (diff>0) {
|
||||
qDebug() << "Fixing up Waveform sync" << sequence;
|
||||
for (int i=0;i<diff*5;i++) {
|
||||
buffer[samples++]=0;
|
||||
}
|
||||
duration+=diff;
|
||||
}
|
||||
/*if (diff!=0) {
|
||||
if (cnt==1) {
|
||||
start+=diff*1000;
|
||||
} else {
|
||||
}
|
||||
} */
|
||||
//qDebug() << "Wave: " << cnt << seconds << diff;
|
||||
}
|
||||
|
||||
|
||||
expected_timestamp=timestamp+seconds;
|
||||
|
||||
if (ext!=PRS1_WAVEFORM_FILE) {
|
||||
if (cnt==0)
|
||||
@ -1033,7 +1071,7 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
|
||||
return false;
|
||||
chksum=chkbuf[0] << 8 | chkbuf[1];
|
||||
chksum=chksum;
|
||||
|
||||
lastts=ts1;
|
||||
}
|
||||
|
||||
if (samples==0)
|
||||
|
16
daily.cpp
16
daily.cpp
@ -75,13 +75,13 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
|
||||
|
||||
int sfc=7;
|
||||
bool extras=false; //true;
|
||||
fg->AddLayer(new gFlagsLine(flags[0],QColor("light green"),"CSR",0,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[1],QColor("purple"),"CA",1,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[2],QColor("#40c0ff"),"OA",2,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[3],QColor("blue"),"H",3,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[4],QColor("black"),"FL",4,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[6],QColor("gold"),"RE",6,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[5],QColor("red"),"VS",5,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[0],QColor("light green"),"CSR",false,0,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[1],QColor("purple"),"CA",true,1,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[2],QColor("#40c0ff"),"OA",true,2,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[3],QColor("blue"),"H",true,3,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[4],QColor("black"),"FL",false,4,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[6],QColor("gold"),"RE",false,6,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[5],QColor("red"),"VS",false,5,sfc));
|
||||
if (extras) {
|
||||
fg->AddLayer(new gFlagsLine(flags[8],QColor("dark green"),"U0E",7,sfc));
|
||||
fg->AddLayer(new gFlagsLine(flags[9],QColor("red"),"VS2",8,sfc));
|
||||
@ -690,7 +690,7 @@ void Daily::Load(QDate date)
|
||||
for (vector<Session *>::iterator s=cpap->begin();s!=cpap->end();s++) {
|
||||
fd=QDateTime::fromMSecsSinceEpoch((*s)->first());
|
||||
ld=QDateTime::fromMSecsSinceEpoch((*s)->last());
|
||||
tmp.sprintf(("<tr><td align=center>%08x</td><td align=center>"+fd.date().toString(Qt::SystemLocaleShortDate)+"</td><td align=center>"+fd.toString("HH:mm ")+"</td><td align=center>"+ld.toString("HH:mm")+"</td></tr>").toLatin1(),(*s)->session());
|
||||
tmp.sprintf(("<tr><td align=center>%08i</td><td align=center>"+fd.date().toString(Qt::SystemLocaleShortDate)+"</td><td align=center>"+fd.toString("HH:mm ")+"</td><td align=center>"+ld.toString("HH:mm")+"</td></tr>").toLatin1(),(*s)->session());
|
||||
html+=tmp;
|
||||
}
|
||||
html+="</table>";
|
||||
|
Loading…
Reference in New Issue
Block a user