2014-04-09 21:01:57 +00:00
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim : set ts = 8 sts = 4 et sw = 4 tw = 99 :
*
* Oximetry
*
* Copyright ( c ) 2011 - 2014 Mark Watkins < jedimark @ users . sourceforge . net >
*
* This file is subject to the terms and conditions of the GNU General Public
* License . See the file COPYING in the main directory of the Linux
* distribution for more details . */
2011-07-30 00:36:31 +00:00
# include <QApplication>
2011-07-13 05:27:27 +00:00
# include <QDebug>
2011-07-13 17:42:49 +00:00
# include <QProgressBar>
2011-12-05 15:03:16 +00:00
# include <QFileDialog>
2011-07-20 03:43:41 +00:00
# include <QMessageBox>
2011-11-24 12:47:25 +00:00
# include <QLabel>
2011-12-06 14:39:14 +00:00
# include <QLocale>
2011-12-01 01:47:09 +00:00
# include <QTimer>
2011-12-06 14:39:14 +00:00
# include <QCalendarWidget>
# include <QTextCharFormat>
2011-07-13 17:42:49 +00:00
2013-10-10 00:36:03 +00:00
# include <qextserialenumerator.h>
2013-09-26 22:52:41 +00:00
2011-07-29 14:58:44 +00:00
# include "oximetry.h"
2011-07-13 05:27:27 +00:00
# include "ui_oximetry.h"
2011-12-06 14:39:14 +00:00
# include "common_gui.h"
2011-07-13 17:42:49 +00:00
# include "SleepLib/loader_plugins/cms50_loader.h"
2011-07-29 14:58:44 +00:00
# include "SleepLib/event.h"
2011-11-28 04:05:09 +00:00
# include "SleepLib/calcs.h"
2014-04-23 17:20:38 +00:00
# include "Graphs/gFooBar.h"
2011-07-13 17:42:49 +00:00
# include "Graphs/gXAxis.h"
2011-09-17 12:39:00 +00:00
# include "Graphs/gSummaryChart.h"
2011-07-13 17:42:49 +00:00
# include "Graphs/gLineChart.h"
# include "Graphs/gYAxis.h"
2011-11-28 04:05:09 +00:00
# include "Graphs/gLineOverlay.h"
2011-07-13 05:27:27 +00:00
2013-09-10 03:33:44 +00:00
# define SERIAL_DEBUG 1
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
extern QLabel * qstatus2 ;
2011-12-01 00:18:59 +00:00
# include "mainwindow.h"
2014-04-17 05:52:25 +00:00
extern MainWindow * mainwin ;
2011-11-24 12:47:25 +00:00
int lastpulse ;
2014-05-25 16:20:33 +00:00
ZSerialOximeter : : ZSerialOximeter ( QObject * parent , QString oxiname , QString portname ,
2014-04-17 05:52:25 +00:00
BaudRateType baud , FlowType flow , ParityType parity , DataBitsType databits ,
StopBitsType stopbits ) :
2011-11-24 12:47:25 +00:00
QObject ( parent ) ,
2014-04-23 13:19:56 +00:00
session ( nullptr ) , pulse ( nullptr ) , spo2 ( nullptr ) , plethy ( nullptr ) , m_port ( nullptr ) ,
2011-11-24 12:47:25 +00:00
m_opened ( false ) ,
m_oxiname ( oxiname ) ,
m_portname ( portname ) ,
m_baud ( baud ) ,
m_flow ( flow ) ,
m_parity ( parity ) ,
m_databits ( databits ) ,
m_stopbits ( stopbits )
{
2014-04-17 05:52:25 +00:00
machine = PROFILE . GetMachine ( MT_OXIMETER ) ;
2011-11-24 12:47:25 +00:00
if ( ! machine ) {
// Create generic Serial Oximeter object..
2014-04-17 05:52:25 +00:00
CMS50Loader * l = dynamic_cast < CMS50Loader * > ( GetLoader ( " CMS50 " ) ) ;
2011-11-24 12:47:25 +00:00
if ( l ) {
2014-04-17 05:52:25 +00:00
machine = l - > CreateMachine ( p_profile ) ;
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
2011-11-24 12:47:25 +00:00
qDebug ( ) < < " Create Oximeter device " ;
}
2014-04-17 05:52:25 +00:00
timer = new QTimer ( this ) ;
connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( Timeout ( ) ) ) ;
import_mode = false ;
m_mode = SO_WAIT ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
ZSerialOximeter : : ~ ZSerialOximeter ( )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
2014-04-17 05:52:25 +00:00
if ( m_port ) { m_port - > close ( ) ; }
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
disconnect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( Timeout ( ) ) ) ;
2011-12-03 14:13:14 +00:00
delete timer ;
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : Timeout ( )
2011-12-03 14:13:14 +00:00
{
qDebug ( ) < < " Timeout! " ;
2014-04-17 05:52:25 +00:00
if ( ! import_mode ) { emit ( liveStopped ( session ) ) ; }
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
bool ZSerialOximeter : : Open ( QextSerialPort : : QueryMode mode )
2011-11-24 12:47:25 +00:00
{
if ( m_portname . isEmpty ( ) ) {
qDebug ( ) < < " Tried to open with empty portname " ;
return false ;
}
qDebug ( ) < < " Opening serial port " < < m_portname < < " in mode " < < mode ;
if ( m_opened ) { // Open already?
// Just close it
2014-04-17 05:52:25 +00:00
if ( m_port ) { m_port - > close ( ) ; }
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
m_portmode = mode ;
m_callbacks = 0 ;
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
m_port = new QextSerialPort ( m_portname , m_portmode ) ;
2011-11-24 12:47:25 +00:00
m_port - > setBaudRate ( m_baud ) ;
m_port - > setFlowControl ( m_flow ) ;
m_port - > setParity ( m_parity ) ;
m_port - > setDataBits ( m_databits ) ;
m_port - > setStopBits ( m_stopbits ) ;
if ( m_port - > open ( QIODevice : : ReadWrite ) = = true ) {
2014-04-17 05:52:25 +00:00
// if (m_mode==QextSerialPort::EventDriven)
connect ( m_port , SIGNAL ( readyRead ( ) ) , this , SLOT ( ReadyRead ( ) ) ) ;
2011-12-03 10:08:40 +00:00
//connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(DsrChanged(bool)));
2014-04-17 05:52:25 +00:00
if ( ! ( m_port - > lineStatus ( ) & LS_DSR ) ) {
2011-11-24 12:47:25 +00:00
qDebug ( ) < < " check device is turned on " ;
2014-04-17 05:52:25 +00:00
}
2011-11-24 12:47:25 +00:00
qDebug ( ) < < " listening for data on " < < m_port - > portName ( ) ;
2014-04-17 05:52:25 +00:00
return m_opened = true ;
2011-11-24 12:47:25 +00:00
} else {
qDebug ( ) < < " device failed to open: " < < m_port - > errorString ( ) ;
2014-04-17 05:52:25 +00:00
return m_opened = false ;
2011-11-24 12:47:25 +00:00
}
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : Close ( )
2011-11-24 12:47:25 +00:00
{
qDebug ( ) < < " Closing serial port " < < m_portname ;
2014-04-17 05:52:25 +00:00
if ( ! m_opened ) {
2013-09-06 12:42:14 +00:00
return ;
2014-04-17 05:52:25 +00:00
}
2011-11-24 12:47:25 +00:00
2013-09-06 12:42:14 +00:00
m_port - > flush ( ) ;
2014-04-17 05:52:25 +00:00
disconnect ( m_port , 0 , 0 , 0 ) ; // SIGNAL(readyRead()), this, SLOT(ReadyRead()));
if ( m_port ) {
2013-09-06 12:42:14 +00:00
m_port - > close ( ) ;
2014-04-17 05:52:25 +00:00
}
2011-12-03 15:06:22 +00:00
//if (m_portmode==QextSerialPort::EventDriven)
2014-04-17 05:52:25 +00:00
m_mode = SO_OFF ;
m_opened = false ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : setPortName ( QString portname )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
qDebug ( ) < < " Can't change serial PortName settings while port is open! " ;
return ;
}
2014-04-17 05:52:25 +00:00
m_portname = portname ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : setBaudRate ( BaudRateType baud )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
qDebug ( ) < < " Can't change serial BaudRate settings while port is open! " ;
return ;
}
2014-04-17 05:52:25 +00:00
m_baud = baud ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : setFlowControl ( FlowType flow )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
qDebug ( ) < < " Can't change serial FlowControl settings while port is open! " ;
return ;
}
2014-04-17 05:52:25 +00:00
m_flow = flow ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : setParity ( ParityType parity )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
qDebug ( ) < < " Can't change serial Parity settings while port is open! " ;
return ;
}
2014-04-17 05:52:25 +00:00
m_parity = parity ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : setDataBits ( DataBitsType databits )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
qDebug ( ) < < " Can't change serial DataBit settings while port is open! " ;
return ;
}
2014-04-17 05:52:25 +00:00
m_databits = databits ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : setStopBits ( StopBitsType stopbits )
2011-11-24 12:47:25 +00:00
{
if ( m_opened ) {
qDebug ( ) < < " Can't change serial StopBit settings while port is open! " ;
return ;
}
2014-04-17 05:52:25 +00:00
m_stopbits = stopbits ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : addPulse ( qint64 time , EventDataType pr )
2011-11-24 12:47:25 +00:00
{
2011-12-02 14:36:40 +00:00
//EventDataType min=0,max=0;
2014-04-17 05:52:25 +00:00
if ( pr > 0 ) {
if ( lastpr = = 0 ) {
if ( pulse - > count ( ) = = 0 ) {
pulse - > setFirst ( time ) ;
if ( session - > eventlist [ OXI_Pulse ] . size ( ) < = 1 ) {
session - > setFirst ( OXI_Pulse , time ) ;
if ( session - > first ( ) = = 0 ) {
session - > set_first ( time ) ;
}
}
2011-12-05 10:50:58 +00:00
} else {
2011-12-02 07:38:44 +00:00
qDebug ( ) < < " Shouldn't happen in addPulse() " ;
}
}
2014-04-17 05:52:25 +00:00
pulse - > AddEvent ( time , pr ) ;
session - > setCount ( OXI_Pulse , session - > count ( OXI_Pulse ) + 1 ) ;
session - > setLast ( OXI_Pulse , time ) ;
2011-12-05 15:03:16 +00:00
session - > set_last ( time ) ;
2011-12-02 07:38:44 +00:00
} else {
2014-04-17 05:52:25 +00:00
if ( lastpr ! = 0 ) {
2011-12-02 07:38:44 +00:00
if ( pulse - > count ( ) > 0 ) {
2014-04-17 05:52:25 +00:00
pulse - > AddEvent ( time , lastpr ) ;
2011-12-02 07:38:44 +00:00
this - > compactToEvent ( pulse ) ;
2014-04-17 05:52:25 +00:00
session - > setLast ( OXI_Pulse , time ) ;
pulse = session - > AddEventList ( OXI_Pulse , EVL_Event ) ;
2011-12-02 07:38:44 +00:00
}
}
2011-11-24 21:19:45 +00:00
}
2014-04-17 05:52:25 +00:00
lastpr = pr ;
2011-11-24 12:47:25 +00:00
emit ( updatePulse ( pr ) ) ;
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : addSpO2 ( qint64 time , EventDataType o2 )
2011-11-24 12:47:25 +00:00
{
2011-12-02 14:36:40 +00:00
//EventDataType min=0,max=0;
2014-04-17 05:52:25 +00:00
if ( o2 > 0 ) {
if ( lasto2 = = 0 ) {
if ( spo2 - > count ( ) = = 0 ) {
2011-12-05 10:50:58 +00:00
spo2 - > setFirst ( time ) ;
2014-04-17 05:52:25 +00:00
if ( session - > eventlist [ OXI_SPO2 ] . size ( ) < = 1 ) {
session - > setFirst ( OXI_SPO2 , time ) ;
if ( session - > first ( ) = = 0 ) {
2011-12-05 15:03:16 +00:00
session - > set_first ( time ) ;
2014-04-17 05:52:25 +00:00
}
2011-12-05 10:50:58 +00:00
}
} else {
2011-12-02 07:38:44 +00:00
qDebug ( ) < < " Shouldn't happen in addSpO2() " ;
}
}
2014-04-17 05:52:25 +00:00
spo2 - > AddEvent ( time , o2 ) ;
session - > setCount ( OXI_SPO2 , session - > count ( OXI_SPO2 ) + 1 ) ;
session - > setLast ( OXI_SPO2 , time ) ;
2011-12-05 15:03:16 +00:00
session - > set_last ( time ) ;
2011-12-02 07:38:44 +00:00
} else {
2014-04-17 05:52:25 +00:00
if ( lasto2 ! = 0 ) {
2011-12-02 07:38:44 +00:00
if ( spo2 - > count ( ) > 0 ) {
2014-04-17 05:52:25 +00:00
spo2 - > AddEvent ( time , lasto2 ) ;
2011-12-02 07:38:44 +00:00
this - > compactToEvent ( spo2 ) ;
2014-04-17 05:52:25 +00:00
session - > setLast ( OXI_SPO2 , time ) ;
spo2 = session - > AddEventList ( OXI_SPO2 , EVL_Event ) ;
2011-12-02 07:38:44 +00:00
}
}
2011-11-24 21:19:45 +00:00
}
2011-12-02 07:38:44 +00:00
2014-04-17 05:52:25 +00:00
lasto2 = o2 ;
2011-11-24 12:47:25 +00:00
emit ( updateSpO2 ( o2 ) ) ;
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : addPlethy ( qint64 time , EventDataType pleth )
2011-11-24 12:47:25 +00:00
{
2011-12-25 05:05:12 +00:00
if ( ! plethy ) {
2014-04-17 05:52:25 +00:00
plethy = new EventList ( EVL_Event ) ;
2011-12-25 05:05:12 +00:00
session - > eventlist [ OXI_Plethy ] . push_back ( plethy ) ;
2014-04-17 05:52:25 +00:00
session - > setFirst ( OXI_Plethy , lasttime ) ;
2011-12-25 05:05:12 +00:00
plethy - > setFirst ( lasttime ) ;
}
2014-04-17 05:52:25 +00:00
plethy - > AddEvent ( time , pleth ) ;
session - > setCount ( OXI_Plethy , plethy - > count ( ) ) ; // update the cache
session - > setMin ( OXI_Plethy , plethy - > Min ( ) ) ;
session - > setMax ( OXI_Plethy , plethy - > Max ( ) ) ;
session - > setLast ( OXI_Plethy , time ) ;
2011-12-05 15:03:16 +00:00
session - > set_last ( time ) ;
2011-11-24 12:47:25 +00:00
plethy - > setLast ( time ) ;
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : compactToWaveform ( EventList * el )
2011-11-24 21:19:45 +00:00
{
2014-04-17 05:52:25 +00:00
double rate = double ( el - > duration ( ) ) / double ( el - > count ( ) ) ;
2011-11-24 21:19:45 +00:00
el - > setType ( EVL_Waveform ) ;
el - > setRate ( rate ) ;
el - > getTime ( ) . clear ( ) ;
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : compactToEvent ( EventList * el )
2011-11-24 22:00:37 +00:00
{
2014-04-17 05:52:25 +00:00
if ( el - > count ( ) < 2 ) { return ; }
2011-11-24 22:00:37 +00:00
EventList nel ( EVL_Waveform ) ;
2014-04-17 05:52:25 +00:00
EventDataType t = 0 , lastt = 0 ; //el->data(0);
qint64 ti = 0 ; //=el->time(0);
2011-12-06 14:39:14 +00:00
//nel.AddEvent(ti,lastt);
2014-04-17 05:52:25 +00:00
bool f = false ;
qint64 lasttime = 0 ;
EventDataType min = 999 , max = 0 ;
for ( quint32 i = 0 ; i < el - > count ( ) ; i + + ) {
t = el - > data ( i ) ;
ti = el - > time ( i ) ;
f = false ;
if ( t ! = 0 ) {
if ( t ! = lastt ) {
2011-12-06 14:39:14 +00:00
if ( ! lasttime ) {
nel . setFirst ( ti ) ;
}
2014-04-17 05:52:25 +00:00
nel . AddEvent ( ti , t ) ;
if ( t < min ) { min = t ; }
if ( t > max ) { max = t ; }
lasttime = ti ;
f = true ;
2011-12-06 14:39:14 +00:00
}
} else {
2014-04-17 05:52:25 +00:00
if ( lastt ! = 0 ) {
nel . AddEvent ( ti , lastt ) ;
lasttime = ti ;
f = true ;
2011-12-06 14:39:14 +00:00
}
2011-11-24 22:00:37 +00:00
}
2014-04-17 05:52:25 +00:00
lastt = t ;
2011-11-24 22:00:37 +00:00
}
2014-04-17 05:52:25 +00:00
2011-12-02 07:38:44 +00:00
if ( ! f ) {
2014-04-17 05:52:25 +00:00
if ( t ! = 0 ) {
nel . AddEvent ( ti , t ) ;
lasttime = ti ;
2011-12-06 14:39:14 +00:00
}
2011-12-02 07:38:44 +00:00
}
2014-04-17 05:52:25 +00:00
2011-12-06 14:39:14 +00:00
el - > setFirst ( nel . first ( ) ) ;
el - > setLast ( nel . last ( ) ) ;
el - > setMin ( min ) ;
el - > setMax ( max ) ;
2011-11-24 22:00:37 +00:00
el - > getData ( ) . clear ( ) ;
el - > getTime ( ) . clear ( ) ;
2011-11-25 12:17:37 +00:00
el - > setCount ( nel . count ( ) ) ;
2011-11-24 22:00:37 +00:00
2014-04-17 05:52:25 +00:00
el - > getData ( ) = nel . getData ( ) ;
el - > getTime ( ) = nel . getTime ( ) ;
2011-11-24 22:00:37 +00:00
}
2011-11-24 21:19:45 +00:00
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : compactAll ( )
2011-11-24 21:19:45 +00:00
{
2014-04-17 05:52:25 +00:00
if ( ! session ) { return ; }
QHash < ChannelID , QVector < EventList * > > : : iterator i ;
qint64 tminx = 0 , tmaxx = 0 , minx , maxx ;
EventDataType min , max ;
for ( i = session - > eventlist . begin ( ) ; i ! = session - > eventlist . end ( ) ; i + + ) {
const ChannelID & code = i . key ( ) ;
min = 999 , max = 0 ;
minx = maxx = 0 ;
for ( int j = 0 ; j < i . value ( ) . size ( ) ; j + + ) {
EventList * e = i . value ( ) [ j ] ;
if ( ( code = = OXI_SPO2 ) | | ( code = = OXI_Pulse ) ) {
2011-12-06 14:39:14 +00:00
compactToEvent ( e ) ;
2014-04-17 05:52:25 +00:00
} else if ( code = = OXI_Plethy ) {
2011-12-06 14:39:14 +00:00
compactToWaveform ( e ) ;
}
2014-04-17 05:52:25 +00:00
if ( min > e - > Min ( ) ) {
min = e - > Min ( ) ;
}
if ( max < e - > Max ( ) ) {
max = e - > Max ( ) ;
}
if ( ! minx | | ( minx > e - > first ( ) ) ) {
minx = e - > first ( ) ;
}
if ( ! maxx | | ( maxx < e - > last ( ) ) ) {
maxx = e - > last ( ) ;
}
2011-12-06 14:39:14 +00:00
}
2014-04-17 05:52:25 +00:00
if ( ( code = = OXI_SPO2 ) | | ( code = = OXI_Pulse ) | | ( code = = OXI_Plethy ) ) {
session - > setMin ( code , min ) ;
session - > setMax ( code , max ) ;
if ( minx ! = 0 ) {
session - > setFirst ( code , minx ) ;
if ( ! tminx | | tminx > minx ) { tminx = minx ; }
2011-12-06 14:39:14 +00:00
}
2014-04-17 05:52:25 +00:00
if ( maxx ! = 0 ) {
session - > setLast ( code , maxx ) ;
if ( ! tmaxx | | tmaxx < max ) { tmaxx = maxx ; }
2011-11-24 22:00:37 +00:00
}
2011-11-24 21:19:45 +00:00
}
}
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
if ( tminx > 0 ) { session - > really_set_first ( tminx ) ; }
if ( tmaxx > 0 ) { session - > really_set_last ( tmaxx ) ; }
2011-11-25 12:13:35 +00:00
}
2011-11-24 12:47:25 +00:00
2014-05-25 16:20:33 +00:00
Session * ZSerialOximeter : : createSession ( QDateTime date )
2011-11-24 12:47:25 +00:00
{
if ( session ) {
2014-04-17 05:52:25 +00:00
delete session ;
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
int sid = date . toTime_t ( ) ;
lasttime = qint64 ( sid ) * 1000L ;
lasto2 = lastpr = 0 ;
session = new Session ( machine , sid ) ;
2011-11-24 12:47:25 +00:00
session - > SetChanged ( true ) ;
session - > set_first ( lasttime ) ;
2014-04-17 05:52:25 +00:00
pulse = new EventList ( EVL_Event ) ;
spo2 = new EventList ( EVL_Event ) ;
2014-04-23 13:19:56 +00:00
plethy = nullptr ;
2011-11-24 12:47:25 +00:00
session - > eventlist [ OXI_Pulse ] . push_back ( pulse ) ;
session - > eventlist [ OXI_SPO2 ] . push_back ( spo2 ) ;
2014-04-17 05:52:25 +00:00
session - > setFirst ( OXI_Pulse , lasttime ) ;
session - > setFirst ( OXI_SPO2 , lasttime ) ;
2011-11-24 12:47:25 +00:00
pulse - > setFirst ( lasttime ) ;
spo2 - > setFirst ( lasttime ) ;
2014-04-17 05:52:25 +00:00
m_callbacks = 0 ;
2011-12-01 01:47:09 +00:00
2011-11-24 12:47:25 +00:00
emit ( sessionCreated ( session ) ) ;
return session ;
}
2014-05-25 16:20:33 +00:00
bool ZSerialOximeter : : startLive ( )
2011-11-24 12:47:25 +00:00
{
2014-04-17 05:52:25 +00:00
import_mode = false ;
2013-09-16 04:30:38 +00:00
killTimers ( ) ;
2014-04-17 05:52:25 +00:00
m_mode = SO_LIVE ;
2013-09-16 04:30:38 +00:00
2014-04-17 05:52:25 +00:00
lastpr = lasto2 = 0 ;
2013-09-06 12:42:14 +00:00
buffer . clear ( ) ;
2011-12-03 15:48:36 +00:00
2014-04-17 05:52:25 +00:00
if ( ! m_opened & & ! Open ( QextSerialPort : : EventDriven ) ) { return false ; }
2011-12-03 15:48:36 +00:00
createSession ( ) ;
return true ;
2011-11-24 12:47:25 +00:00
}
2014-05-25 16:20:33 +00:00
void ZSerialOximeter : : stopLive ( )
2011-11-24 12:47:25 +00:00
{
2014-04-17 05:52:25 +00:00
if ( timer - > isActive ( ) ) { timer - > stop ( ) ; }
m_mode = SO_WAIT ;
2011-12-01 06:06:13 +00:00
if ( session ) {
compactAll ( ) ;
calcSPO2Drop ( session ) ;
calcPulseChange ( session ) ;
}
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
CMS50Serial : : CMS50Serial ( QObject * parent , QString portname = " " ) :
2014-05-25 16:20:33 +00:00
ZSerialOximeter ( parent , " CMS50 " , portname , BAUD19200 , FLOW_OFF , PAR_ODD , DATA_8 , STOP_1 )
2011-11-24 12:47:25 +00:00
{
2014-04-17 05:52:25 +00:00
cms50timer = new QTimer ( this ) ;
cms50timer2 = new QTimer ( this ) ;
2011-11-24 12:47:25 +00:00
}
CMS50Serial : : ~ CMS50Serial ( )
{
2013-09-06 12:42:14 +00:00
delete cms50timer2 ;
delete cms50timer ;
}
void CMS50Serial : : killTimers ( )
{
if ( cms50timer - > isActive ( ) ) {
cms50timer - > stop ( ) ;
}
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
if ( cms50timer2 - > isActive ( ) ) {
cms50timer2 - > stop ( ) ;
}
2011-11-24 12:47:25 +00:00
}
2011-12-03 08:52:24 +00:00
void CMS50Serial : : import_process ( )
2011-11-24 12:47:25 +00:00
{
2011-12-03 14:13:14 +00:00
if ( ! session ) {
qDebug ( ) < < " User pushing import too many times in a row? " ;
return ;
}
2014-04-17 05:52:25 +00:00
2013-09-09 15:56:02 +00:00
mainwin - > getOximetry ( ) - > graphView ( ) - > setEmptyText ( tr ( " Processing... " ) ) ;
2013-09-06 12:42:14 +00:00
mainwin - > getOximetry ( ) - > graphView ( ) - > redraw ( ) ;
2011-11-24 12:47:25 +00:00
qDebug ( ) < < " CMS50 import complete. Processing " < < data . size ( ) < < " bytes " ;
2014-04-17 05:52:25 +00:00
unsigned short a , pl , o2 , lastpl = 0 , lasto2 = 0 ;
int i = 0 ;
int size = data . size ( ) ;
2011-12-02 05:54:25 +00:00
2011-12-03 14:13:14 +00:00
2014-04-17 05:52:25 +00:00
EventList * pulse = ( session - > eventlist [ OXI_Pulse ] [ 0 ] ) ;
EventList * spo2 = ( session - > eventlist [ OXI_SPO2 ] [ 0 ] ) ;
2013-09-09 15:56:02 +00:00
2014-04-17 05:52:25 +00:00
// int d=abs(oxitime.secsTo(cpaptime));
2013-09-09 15:56:02 +00:00
2014-04-17 05:52:25 +00:00
QDateTime seltime = oxitime ;
2013-09-09 15:56:02 +00:00
if ( ! cpaptime . isNull ( ) ) {
2014-05-17 05:04:40 +00:00
if ( QMessageBox : : question ( mainwin , STR_MessageBox_Question ,
2014-04-17 05:52:25 +00:00
tr ( " Did you remember to start your oximeter recording at exactly the same time you started your CPAP machine? " ) ,
QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No ) {
2013-09-09 15:56:02 +00:00
if ( ! cms50dplus ) {
// Oximeter has a clock.. Hopefully the user remembered to set their clock on the device..
2014-05-17 05:04:40 +00:00
QMessageBox : : information ( mainwin , STR_MessageBox_Information ,
tr ( " That's ok, I will use the time provided by your oximeter, however it will sync better next time if you start your oximeter recording at the same time your CPAP machine starts up. " ) +
" \n \n " +
STR_MessageBox_PleaseNote + " : " + tr ( " If you haven't set your oximeter clock you will have to manually edit this time before saving this oximetry session. " ) ,
2014-04-17 05:52:25 +00:00
QMessageBox : : Ok ) ;
2013-09-09 15:56:02 +00:00
} else {
//CMS50D+, and the user didn't start at the same time.. Kludge it because they likely turned it on around about the same time anyway.
2014-05-17 05:04:40 +00:00
QMessageBox : : information ( mainwin , STR_MessageBox_Information ,
tr ( " It looks like your oximeter doesn't provide a valid start time, I'm going to set this oximetry session starting time to the CPAP starting time anyway. " ) + " \n \n " +
tr ( " You may have to adjust it manually if you remember the real start time before saving this session. " ) + " \n \n " +
tr ( " (Also, did you remember to import todays CPAP data first?) " ) ,
2014-04-17 05:52:25 +00:00
QMessageBox : : Ok ) ;
seltime = cpaptime ;
2013-09-09 15:56:02 +00:00
}
} else {
// The best solution.. the user (hopefully) started both devices at the same time, so we pick the cpap sessions start time for optimal sync.
2014-05-17 05:04:40 +00:00
QMessageBox : : information ( mainwin , STR_MessageBox_Information ,
tr ( " The most recent CPAP Session time has been selected as the start of your oximetry session. " ) + " \n \n " +
tr ( " If you forgot to import todays CPAP data first, go and do that now, then import again from your oximeter. " ) ,
2014-04-17 05:52:25 +00:00
QMessageBox : : Ok ) ;
seltime = cpaptime ;
2013-09-09 15:56:02 +00:00
}
} else {
if ( cms50dplus ) {
// Worst case, CMS50D+ and no CPAP data.. the time is basically set to midnight the current day.
2014-05-17 05:04:40 +00:00
QMessageBox : : information ( mainwin , STR_MessageBox_Information ,
tr ( " No valid start time was provided for this oximeter session. " ) + " \n \n " +
tr ( " You will likely have to adjust your oximeter sessions start time before saving. " ) ,
2014-04-17 05:52:25 +00:00
QMessageBox : : Ok ) ;
2013-09-09 15:56:02 +00:00
} else {
// No point nagging the user at all in this case.. they don't have any CPAP data loaded, so they are just using SleepyHead with the oximeter
}
}
2014-04-17 05:52:25 +00:00
lasttime = seltime . toTime_t ( ) ;
2011-11-24 12:47:25 +00:00
session - > SetSessionID ( lasttime ) ;
2014-04-17 05:52:25 +00:00
lasttime * = 1000 ;
2011-11-24 12:47:25 +00:00
2011-12-01 00:18:59 +00:00
//spo2->setFirst(lasttime);
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
EventDataType plmin = 999 , plmax = 0 ;
EventDataType o2min = 100 , o2max = 0 ;
int plcnt = 0 , o2cnt = 0 ;
qint64 lastpltime = 0 , lasto2time = 0 ;
bool first = true ;
while ( i < ( size - 3 ) ) {
a = data . at ( i + + ) ; // low bits are supposedly the high bits of the heart rate? not here
pl = ( ( data . at ( i + + ) & 0x7f ) | ( ( a & 1 ) < < 7 ) ) & 0xff ;
o2 = data . at ( i + + ) & 0x7f ;
2013-09-14 23:32:14 +00:00
// Faulty data..?
2014-04-17 05:52:25 +00:00
if ( o2 < 50 ) {
o2 = 0 ;
}
2013-09-14 23:32:14 +00:00
2014-04-17 05:52:25 +00:00
if ( pl ! = 0 ) {
if ( lastpl ! = pl ) {
if ( lastpl = = 0 | | ! pulse ) {
2011-12-01 00:18:59 +00:00
if ( first ) {
session - > set_first ( lasttime ) ;
2014-04-17 05:52:25 +00:00
first = false ;
}
if ( plcnt = = 0 ) {
session - > setFirst ( OXI_Pulse , lasttime ) ;
2011-11-30 22:56:31 +00:00
}
2014-04-17 05:52:25 +00:00
if ( pulse & & pulse - > count ( ) = = 0 ) {
2011-12-02 05:54:25 +00:00
} else {
2014-04-17 05:52:25 +00:00
pulse = new EventList ( EVL_Event ) ;
2011-12-02 05:54:25 +00:00
session - > eventlist [ OXI_Pulse ] . push_back ( pulse ) ;
}
2011-11-30 22:56:31 +00:00
}
2014-04-17 05:52:25 +00:00
lastpltime = lasttime ;
pulse - > AddEvent ( lasttime , pl ) ;
if ( pl < plmin ) { plmin = pl ; }
if ( pl > plmax ) { plmax = pl ; }
2011-11-30 22:56:31 +00:00
plcnt + + ;
2011-11-24 12:47:25 +00:00
}
2011-12-06 14:39:14 +00:00
} else {
2014-04-17 05:52:25 +00:00
if ( lastpl ! = 0 ) {
pulse - > AddEvent ( lasttime , pl ) ;
lastpltime = lasttime ;
2011-12-06 14:39:14 +00:00
plcnt + + ;
}
2011-11-24 21:19:45 +00:00
}
2014-04-17 05:52:25 +00:00
if ( o2 ! = 0 ) {
if ( lasto2 ! = o2 ) {
if ( lasto2 = = 0 | | ! spo2 ) {
2011-12-01 00:18:59 +00:00
if ( first ) {
session - > set_first ( lasttime ) ;
2014-04-17 05:52:25 +00:00
first = false ;
}
if ( o2cnt = = 0 ) {
session - > setFirst ( OXI_SPO2 , lasttime ) ;
2011-12-01 00:18:59 +00:00
}
2014-04-17 05:52:25 +00:00
if ( spo2 & & spo2 - > count ( ) = = 0 ) {
2011-12-02 05:54:25 +00:00
} else {
2014-04-17 05:52:25 +00:00
spo2 = new EventList ( EVL_Event ) ;
2011-12-02 05:54:25 +00:00
session - > eventlist [ OXI_SPO2 ] . push_back ( spo2 ) ;
}
2011-11-30 22:56:31 +00:00
}
2014-04-17 05:52:25 +00:00
lasto2time = lasttime ;
spo2 - > AddEvent ( lasttime , o2 ) ;
if ( o2 < o2min ) { o2min = o2 ; }
if ( o2 > o2max ) { o2max = o2 ; }
2011-11-30 22:56:31 +00:00
o2cnt + + ;
2011-11-24 12:47:25 +00:00
}
2011-12-06 14:39:14 +00:00
} else {
2014-04-17 05:52:25 +00:00
if ( lasto2 ! = 0 ) {
spo2 - > AddEvent ( lasttime , o2 ) ;
lasto2time = lasttime ;
2011-12-06 14:39:14 +00:00
o2cnt + + ;
}
2011-11-24 21:19:45 +00:00
}
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
lasttime + = 1000 ;
2011-12-03 14:13:14 +00:00
//emit(updateProgress(float(i)/float(size)));
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
lastpl = pl ;
lasto2 = o2 ;
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
2011-12-06 14:39:14 +00:00
/*if (pulse && (lastpltime!=lasttime) && (pl!=0)) {
2011-12-01 00:18:59 +00:00
// lastpl==pl
pulse - > AddEvent ( lasttime , pl ) ;
lastpltime = lastpltime ;
plcnt + + ;
}
if ( spo2 & & ( lasto2time ! = lasttime ) & & ( o2 ! = 0 ) ) {
spo2 - > AddEvent ( lasttime , o2 ) ;
lasto2time = lasttime ;
o2cnt + + ;
2011-12-06 14:39:14 +00:00
} */
2014-04-17 05:52:25 +00:00
qint64 rlasttime = qMax ( lastpltime , lasto2time ) ;
2011-12-06 14:39:14 +00:00
session - > set_last ( rlasttime ) ;
2014-04-17 05:52:25 +00:00
session - > setLast ( OXI_Pulse , lastpltime ) ;
session - > setLast ( OXI_SPO2 , lasto2time ) ;
session - > setMin ( OXI_Pulse , plmin ) ;
session - > setMax ( OXI_Pulse , plmax ) ;
session - > setMin ( OXI_SPO2 , o2min ) ;
session - > setMax ( OXI_SPO2 , o2max ) ;
session - > setCount ( OXI_Pulse , plcnt ) ;
session - > setCount ( OXI_SPO2 , o2cnt ) ;
2011-11-24 12:47:25 +00:00
session - > UpdateSummaries ( ) ;
emit ( importComplete ( session ) ) ;
2014-04-17 05:52:25 +00:00
disconnect ( this , SIGNAL ( importProcess ( ) ) , this , SLOT ( import_process ( ) ) ) ;
2011-11-24 12:47:25 +00:00
}
2011-12-01 01:47:09 +00:00
2011-12-03 08:52:24 +00:00
void CMS50Serial : : ReadyRead ( )
2011-11-24 12:47:25 +00:00
{
2014-04-17 05:52:25 +00:00
if ( m_mode = = SO_OFF ) {
2013-09-06 12:42:14 +00:00
return ;
2014-04-17 05:52:25 +00:00
}
2013-09-16 04:30:38 +00:00
2014-04-17 05:52:25 +00:00
static int lastbytesize = 0 ;
2013-09-06 12:42:14 +00:00
2011-11-24 12:47:25 +00:00
QByteArray bytes ;
2013-09-06 12:42:14 +00:00
int available = m_port - > bytesAvailable ( ) ;
bytes . resize ( available ) ;
2011-11-24 12:47:25 +00:00
m_port - > read ( bytes . data ( ) , bytes . size ( ) ) ;
2014-04-17 05:52:25 +00:00
if ( m_mode = = SO_WAIT ) {
2013-09-06 12:42:14 +00:00
killTimers ( ) ;
2014-04-17 05:52:25 +00:00
// Close();
2013-09-06 12:42:14 +00:00
return ;
}
2011-12-03 00:06:11 +00:00
2013-09-06 12:42:14 +00:00
m_callbacks + + ;
2014-04-17 05:52:25 +00:00
2011-12-03 00:06:11 +00:00
if ( ! import_mode ) {
2014-04-17 05:52:25 +00:00
if ( bytes . size ( ) = = 1 ) { // CMS50D+ transmits a single 0 when switching off from finger out..
if ( lastbytesize ! = 1 ) {
2011-12-03 14:13:14 +00:00
if ( timer - > isActive ( ) ) {
timer - > stop ( ) ;
}
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
// Set the Shutdown timer
2011-12-03 14:13:14 +00:00
timer - > setSingleShot ( true ) ;
timer - > setInterval ( 10000 ) ;
timer - > start ( ) ;
}
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
qDebug ( ) < < " Oximeter switched off.. wait for timeout? " < < hex < < bytes . at ( 0 ) ;
2011-12-03 14:13:14 +00:00
return ;
} else {
2013-09-06 12:42:14 +00:00
// Cancel any shutdown timer if running
2011-12-03 14:13:14 +00:00
if ( timer - > isActive ( ) ) {
timer - > stop ( ) ;
}
}
2011-12-03 00:06:11 +00:00
}
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
lastbytesize = available ;
unsigned char c , bc = import_mode ? 0xf0 : 0x80 ;
int i = 0 ;
2013-09-06 12:42:14 +00:00
2013-09-10 03:33:44 +00:00
2014-04-17 05:52:25 +00:00
while ( ( i < available ) & & ( ( ( c = ( unsigned char ) bytes . at ( i ) ) & bc ) ! = bc ) ) {
if ( buffer . length ( ) > 0 ) {
2013-09-06 12:42:14 +00:00
// If buffer is the start of a valid but short frame, add to it..
buffer . append ( c ) ;
} // otherwise dump these bytes, as they are corrupt.
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
+ + i ;
}
// Copy the rest to the buffer.
2014-04-17 05:52:25 +00:00
for ( ; i < available ; + + i ) {
2013-09-06 12:42:14 +00:00
buffer . append ( bytes . at ( i ) ) ;
}
2014-04-17 05:52:25 +00:00
unsigned char pulse , spo2 , pwave , pbeat ;
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
available = buffer . length ( ) ;
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
bool pkt_short = false ;
i = 0 ;
short hour , minute ;
bool updated = false ;
2011-12-03 00:06:11 +00:00
2014-04-17 05:52:25 +00:00
QString zdata = " " ;
2013-09-10 03:33:44 +00:00
2014-04-17 05:52:25 +00:00
int precbytes = received_bytes ;
2013-09-06 12:42:14 +00:00
while ( i < available ) {
2014-04-17 05:52:25 +00:00
c = ( unsigned char ) buffer . at ( i ) ;
if ( ( c & 0xf0 ) = = 0xf0 ) { // Record transmit trios all start with 0xf#
if ( ( i + 3 ) > = available ) {
pkt_short = true ;
2013-09-10 03:33:44 +00:00
break ;
}
2013-09-06 12:42:14 +00:00
2013-09-10 03:33:44 +00:00
if ( ! import_mode ) { // Skip if live mode and the user bumped the upload button by mistake
2014-04-17 05:52:25 +00:00
i + = 3 ;
2013-09-10 03:33:44 +00:00
continue ;
}
2013-09-06 12:42:14 +00:00
2013-09-10 03:33:44 +00:00
imp_callbacks + + ;
2014-04-17 05:52:25 +00:00
2013-09-10 03:33:44 +00:00
if ( ! started_import ) {
2014-04-17 05:52:25 +00:00
for ( int j = 0 ; j < 3 ; j + + ) { zdata + = QString ( ) . sprintf ( " %02X " , ( unsigned char ) buffer . at ( i + j ) ) ; }
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Recieved Rec Header: " < < zdata ;
2014-04-17 05:52:25 +00:00
zdata = " " ;
2013-09-10 03:33:44 +00:00
}
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
if ( c = = 0xf2 ) { // Is this a 3 byte header trio? (there are 3 sets of these at start of record data)
2013-09-10 03:33:44 +00:00
if ( ! started_import ) { // Is this a record block header? Only need the first one
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
hour = ( unsigned char ) buffer . at ( i + 1 ) & 0x7f ;
minute = ( unsigned char ) buffer . at ( i + 2 ) & 0x7f ;
2013-09-06 12:42:14 +00:00
2013-09-10 03:33:44 +00:00
qDebug ( ) < < QString ( " Receiving Oximeter transmission %1:%2 " ) . arg ( hour ) . arg ( minute ) ;
// set importing to true or whatever..
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
finished_import = false ;
started_import = true ;
started_reading = false ;
2013-09-06 12:42:14 +00:00
2013-09-10 03:33:44 +00:00
killTimers ( ) ;
qDebug ( ) < < " Getting ready for import " ;
2013-09-16 04:30:38 +00:00
// Hide the connect message box
if ( mainwin - > getOximetry ( ) - > connectDeviceMsgBox ) {
//mainwin->getOximetry()->connectDeviceMsgBox->setText("Transfering Oximetry data from device");
2014-04-17 05:52:25 +00:00
mainwin - > getOximetry ( ) - > disconnect ( mainwin - > getOximetry ( ) - > connectDeviceMsgBox ,
SIGNAL ( buttonClicked ( QAbstractButton * ) ) , mainwin - > getOximetry ( ) , SLOT ( cancel_CheckPorts ( ) ) ) ;
2013-09-16 04:30:38 +00:00
mainwin - > getOximetry ( ) - > close ( ) ;
delete mainwin - > getOximetry ( ) - > connectDeviceMsgBox ;
2014-04-23 13:19:56 +00:00
mainwin - > getOximetry ( ) - > connectDeviceMsgBox = nullptr ;
2013-09-16 04:30:38 +00:00
}
2013-09-10 03:33:44 +00:00
mainwin - > getOximetry ( ) - > graphView ( ) - > setEmptyText ( tr ( " Please Wait, Importing... " ) ) ;
mainwin - > getOximetry ( ) - > graphView ( ) - > timedRedraw ( 50 ) ;
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
QDate oda = QDate : : currentDate ( ) ;
QTime oti = QTime ( hour ,
minute ) ; // Only CMS50E/F's have a realtime clock. CMS50D+ will set this to midnight
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
cms50dplus = ( hour = = 0 )
& & ( minute = = 0 ) ; // Either a CMS50D+ or it's really midnight, set a flag anyway for later to help choose the right sync time
2013-09-06 12:42:14 +00:00
2013-09-10 03:33:44 +00:00
// If the oximeter record time is more than the current time, then assume it was from the day before
// Or should I use split time preference instead??? Foggy Confusements..
2014-04-17 05:52:25 +00:00
if ( oti > QTime : : currentTime ( ) ) {
oda = oda . addDays ( - 1 ) ;
}
2013-09-09 15:56:02 +00:00
2014-04-17 05:52:25 +00:00
oxitime = QDateTime ( oda , oti ) ;
2013-09-09 15:56:02 +00:00
2013-09-10 03:33:44 +00:00
// Convert it to UTC
2014-04-17 05:52:25 +00:00
oxitime = oxitime . toTimeSpec ( Qt : : UTC ) ;
2013-09-09 15:56:02 +00:00
2014-04-17 05:52:25 +00:00
qDebug ( ) < < " Session start (according to CMS50) " < < oxitime < < hex < < buffer . at (
i + 1 ) < < buffer . at ( i + 2 ) < < " : " < < dec < < hour < < minute ;
2013-09-09 15:56:02 +00:00
2013-09-10 03:33:44 +00:00
// As an alternative, pick the first session of the last days data..
2014-04-17 05:52:25 +00:00
Day * day = PROFILE . GetDay ( PROFILE . LastDay ( ) , MT_CPAP ) ;
2013-09-10 03:33:44 +00:00
if ( day ) {
2014-04-17 05:52:25 +00:00
int ti = day - > first ( ) / 1000L ;
2013-09-09 15:56:02 +00:00
2014-04-17 05:52:25 +00:00
cpaptime = QDateTime : : fromTime_t ( ti ) ;
2013-09-09 15:56:02 +00:00
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Guessing session starting from CPAP data " < < cpaptime ;
2014-04-17 05:52:25 +00:00
} else { cpaptime = QDateTime ( ) ; } // null
2013-09-09 15:56:02 +00:00
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Record Import: " < < oxitime < < cpaptime ;
2014-04-17 05:52:25 +00:00
cb_reset = 1 ;
2013-09-10 03:33:44 +00:00
// CMS50D+ needs an end timer because it just stops dead after uploading
2014-04-17 05:52:25 +00:00
cms50timer2 - > singleShot ( 2000 , this , SLOT ( resetImportTimeout ( ) ) ) ;
2013-09-10 03:33:44 +00:00
}
2014-04-17 05:52:25 +00:00
i + = 3 ;
2011-11-24 12:47:25 +00:00
} else {
2013-09-10 03:33:44 +00:00
if ( ! started_import ) {
// Crap.. Missed the 0xf2 headers..
2014-04-17 05:52:25 +00:00
m_mode = SO_WAIT ;
2013-09-10 03:33:44 +00:00
killTimers ( ) ;
emit ( importAborted ( ) ) ;
2014-04-17 05:52:25 +00:00
mainwin - > getOximetry ( ) - > graphView ( ) - > setEmptyText (
tr ( " Import Failed. Wait for oximeter and try again. " ) ) ;
2014-05-17 05:04:40 +00:00
mainwin - > Notify ( tr ( " Something went wrong with reading from the Oximeter. " ) + " \n " + tr ( " Please wait for oximeter to finish tranmitting than try restarting import again. " ) ,
tr ( " Import Failed " ) ) ;
2013-09-10 03:33:44 +00:00
mainwin - > getOximetry ( ) - > graphView ( ) - > timedRedraw ( 50 ) ;
break ;
}
2014-04-17 05:52:25 +00:00
started_reading = true ; // Sometimes errornous crap is sent after data rec header
2013-09-06 12:42:14 +00:00
// Recording import
2014-04-17 05:52:25 +00:00
if ( ( i + 2 ) > = available ) {
pkt_short = true ;
2013-09-06 12:42:14 +00:00
break ;
2011-11-24 12:47:25 +00:00
}
2011-12-03 00:06:11 +00:00
2014-04-17 05:52:25 +00:00
pulse = ( unsigned char ) buffer . at ( i + 1 ) & 0x7f ;
spo2 = ( unsigned char ) buffer . at ( i + 2 ) & 0x7f ;
2013-09-06 12:42:14 +00:00
data . push_back ( buffer . at ( i ) ) ;
2014-04-17 05:52:25 +00:00
data . push_back ( buffer . at ( i + 1 ) ) ;
data . push_back ( buffer . at ( i + 2 ) ) ;
received_bytes + = 3 ;
2011-12-19 02:20:24 +00:00
2014-04-17 05:52:25 +00:00
i + = 3 ;
2011-11-24 12:47:25 +00:00
}
2011-12-19 17:51:25 +00:00
2014-04-17 05:52:25 +00:00
} else if ( ( c & 0x80 ) = = 0x80 ) {
2013-09-10 03:33:44 +00:00
if ( import_mode & & started_reading ) { // (Sometimes errornous bytes get transfered after header)
2013-09-06 12:42:14 +00:00
qDebug ( ) < < " Stopped importing due to live data " ;
// We were importing, but now are done
2011-12-19 17:51:25 +00:00
2013-09-06 12:42:14 +00:00
killTimers ( ) ;
2011-12-19 17:51:25 +00:00
2014-04-17 05:52:25 +00:00
started_import = false ;
started_reading = false ;
finished_import = true ;
m_mode = SO_WAIT ; // Temporarily pause until complete shutdown.
2013-09-06 12:42:14 +00:00
emit ( importProcess ( ) ) ;
2013-09-10 03:33:44 +00:00
break ;
2011-12-19 17:51:25 +00:00
}
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
// Standard frame.. make sure theres the full 5 byte sequence
2014-04-17 05:52:25 +00:00
if ( ( i + 4 ) > available ) {
pkt_short = true ;
2013-09-06 12:42:14 +00:00
break ;
}
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
if ( ! import_mode ) {
2014-04-17 05:52:25 +00:00
pwave = ( unsigned char ) buffer . at ( i + 1 ) ;
pbeat = ( unsigned char ) buffer . at ( i + 2 ) ;
pulse = ( ( unsigned char ) buffer . at ( i + 3 ) & 0x7f ) | ( ( pbeat & 0x40 ) < < 1 ) ;
spo2 = ( unsigned char ) buffer . at ( i + 4 ) & 0x7f ;
addPlethy ( lasttime , pwave ) ;
addPulse ( lasttime , pulse ) ;
addSpO2 ( lasttime , spo2 ) ;
lasttime + = 20 ;
updated = true ;
2013-09-06 12:42:14 +00:00
}
# if SERIAL_DEBUG
2013-09-10 03:33:44 +00:00
//qDebug() << "Live: " << pulse << spo2 << pwave << pbeat;
2013-09-06 12:42:14 +00:00
# endif
// whatever depending on mode..
2014-04-17 05:52:25 +00:00
i + = 5 ;
} else { break ; }
2011-11-25 12:13:35 +00:00
}
2011-12-03 14:13:14 +00:00
2013-09-10 03:33:44 +00:00
# if SERIAL_DEBUG
2014-04-17 05:52:25 +00:00
if ( ( import_mode ) & & ( received_bytes > precbytes ) ) {
qDebug ( ) < < " Received Bytes " < < received_bytes - precbytes ; // << ":" << zdata;
}
2013-09-10 03:33:44 +00:00
# endif
2014-04-17 05:52:25 +00:00
if ( i > 0 ) {
2013-09-06 12:42:14 +00:00
// Trim any processed bytes from the buffer.
2014-04-17 05:52:25 +00:00
buffer = buffer . mid ( i ) ;
i = 0 ;
2013-09-06 12:42:14 +00:00
// available should be < 5 or 3 here..
}
2014-04-17 05:52:25 +00:00
available = buffer . length ( ) ;
if ( available > 0 ) {
if ( ( buffer . at ( 0 ) & 0x80 ) ! = 0x80 ) {
2013-09-06 12:42:14 +00:00
buffer . clear ( ) ;
}
2011-12-03 14:13:14 +00:00
}
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
if ( updated ) {
2013-09-06 12:42:14 +00:00
emit ( dataChanged ( ) ) ;
2014-04-17 05:52:25 +00:00
}
2011-11-24 12:47:25 +00:00
}
2011-12-03 15:48:36 +00:00
void CMS50Serial : : resetDevice ( )
{
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Sending reset code to CMS50 device " ;
//m_port->flush();
2014-04-17 05:52:25 +00:00
static unsigned char b1 [ 3 ] = { 0xf6 , 0xf6 , 0xf6 } ;
if ( m_port - > write ( ( char * ) b1 , 3 ) = = - 1 ) {
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Couldn't write data reset bytes to CMS50 " ;
2011-12-03 15:48:36 +00:00
}
}
void CMS50Serial : : requestData ( )
{
2014-04-17 05:52:25 +00:00
static unsigned char b1 [ 2 ] = { 0xf5 , 0xf5 } ;
2011-12-03 15:48:36 +00:00
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Sending request code to CMS50 device " ;
2014-04-17 05:52:25 +00:00
if ( m_port - > write ( ( char * ) b1 , 2 ) = = - 1 ) {
2011-12-03 15:48:36 +00:00
qDebug ( ) < < " Couldn't write data request bytes to CMS50 " ;
}
}
2011-11-24 12:47:25 +00:00
bool CMS50Serial : : startImport ( )
{
2013-09-06 12:42:14 +00:00
buffer . clear ( ) ;
data . clear ( ) ;
2013-09-16 04:30:38 +00:00
killTimers ( ) ;
2014-04-17 05:52:25 +00:00
m_mode = SO_IMPORT ;
import_mode = true ;
started_import = false ;
started_reading = false ;
finished_import = false ;
2013-09-06 12:42:14 +00:00
2011-12-19 17:51:25 +00:00
imptime . start ( ) ;
2014-04-17 05:52:25 +00:00
imp_callbacks = 0 ;
m_callbacks = 0 ;
2013-09-10 03:33:44 +00:00
2014-04-17 05:52:25 +00:00
cb_reset = 0 ;
import_fails = 0 ;
failcnt = 0 ;
2011-12-03 17:42:26 +00:00
2014-04-17 05:52:25 +00:00
connect ( this , SIGNAL ( importProcess ( ) ) , this , SLOT ( import_process ( ) ) ) ;
2013-09-16 04:30:38 +00:00
if ( ! m_opened & & ! Open ( QextSerialPort : : EventDriven ) ) {
return false ;
}
2013-09-06 12:42:14 +00:00
// doesn't need to happen until process..
2011-11-24 12:47:25 +00:00
createSession ( ) ;
2013-09-10 03:33:44 +00:00
# ifdef SERIAL_DEBUG
qDebug ( ) < < " Starting startImportTimer " ;
# endif
startImportTimeout ( ) ;
2011-11-24 12:47:25 +00:00
return true ;
}
2013-09-16 04:30:38 +00:00
void CMS50Serial : : stopImport ( ) // Silently stops import dead
{
2014-04-17 05:52:25 +00:00
disconnect ( this , SIGNAL ( importProcess ( ) ) , this , SLOT ( import_process ( ) ) ) ;
2013-09-16 04:30:38 +00:00
2014-04-17 05:52:25 +00:00
m_mode = SO_OFF ;
// killTimers();
started_import = false ;
import_mode = false ;
finished_import = false ;
2013-09-16 04:30:38 +00:00
}
2011-12-03 16:14:51 +00:00
void CMS50Serial : : startImportTimeout ( )
{
2014-04-17 05:52:25 +00:00
if ( ( m_mode = = SO_WAIT ) | | ( m_mode = = SO_OFF )
| | finished_import
| | started_import ) {
2013-09-06 12:42:14 +00:00
2013-09-16 04:30:38 +00:00
return ;
}
2014-04-17 05:52:25 +00:00
2013-09-10 03:33:44 +00:00
// Wait until events really are jammed on the CMS50D+ before re-requesting data.
2014-04-17 05:52:25 +00:00
if ( imp_callbacks = = 0 ) { // Frozen, but still hasn't started?
int elapsed = imptime . elapsed ( ) / 1000 ;
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
if ( elapsed > 30 ) { // Give up after ~20 seconds
m_mode = SO_WAIT ;
2013-09-10 03:33:44 +00:00
killTimers ( ) ;
emit ( importAborted ( ) ) ;
mainwin - > getOximetry ( ) - > graphView ( ) - > setEmptyText ( tr ( " Import Failed " ) ) ;
mainwin - > getOximetry ( ) - > graphView ( ) - > timedRedraw ( 50 ) ;
return ;
2013-09-06 12:42:14 +00:00
} else {
2014-04-17 05:52:25 +00:00
QString a = tr ( " Set Oximeter to Upload " ) ;
for ( int j = 0 ; j < elapsed ; j + + ) { a + = " . " ; }
2013-09-10 03:33:44 +00:00
mainwin - > getOximetry ( ) - > graphView ( ) - > setEmptyText ( a ) ;
mainwin - > getOximetry ( ) - > graphView ( ) - > timedRedraw ( 50 ) ;
// Note: Newer CMS50 devices transmit from user input
requestData ( ) ;
2013-09-06 12:42:14 +00:00
}
2013-09-10 03:33:44 +00:00
// Schedule another callback to make sure it's started
2014-04-17 05:52:25 +00:00
cms50timer - > singleShot ( 1000 , this , SLOT ( startImportTimeout ( ) ) ) ;
2013-09-10 03:33:44 +00:00
}
2013-09-06 12:42:14 +00:00
}
void CMS50Serial : : resetImportTimeout ( )
{
2014-04-17 05:52:25 +00:00
if ( ( m_mode = = SO_WAIT ) | | ( finished_import ) ) {
2013-09-10 03:33:44 +00:00
return ;
2013-09-16 04:30:38 +00:00
}
2013-09-10 03:33:44 +00:00
2014-04-17 05:52:25 +00:00
if ( imp_callbacks ! = cb_reset ) {
2013-09-06 12:42:14 +00:00
// Still receiving data.. reset timer
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Still receiving data in resetImportTimeout() " ;
2014-04-17 05:52:25 +00:00
if ( cms50timer2 - > isActive ( ) ) {
2013-09-10 03:33:44 +00:00
cms50timer2 - > stop ( ) ;
2014-04-17 05:52:25 +00:00
}
cms50timer2 - > singleShot ( 2000 , this , SLOT ( resetImportTimeout ( ) ) ) ;
2011-12-03 16:14:51 +00:00
} else {
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Oximeter device stopped transmitting.. Transfer complete " ;
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
// We were importing, but now are done
if ( ! finished_import & & ( started_import & & started_reading ) ) {
2013-09-10 03:33:44 +00:00
qDebug ( ) < < " Switching CMS50 back to live mode and finalizing import " ;
2013-09-06 12:42:14 +00:00
// Turn back on live streaming so the end of capture can be dealt with
cms50timer2 - > stop ( ) ;
m_port - > flush ( ) ;
resetDevice ( ) ; // Send Reset to CMS50D+
//started_import=false;
2014-04-17 05:52:25 +00:00
finished_import = true ;
m_mode = SO_WAIT ; // Temporarily pause until complete shutdown.
2013-09-06 12:42:14 +00:00
emit ( importProcess ( ) ) ;
return ;
2011-12-03 17:42:26 +00:00
}
2014-04-17 05:52:25 +00:00
2013-09-06 12:42:14 +00:00
qDebug ( ) < < " Should CMS50 resetImportTimeout reach here? " ;
// else what???
2011-12-03 16:14:51 +00:00
}
2014-04-17 05:52:25 +00:00
cb_reset = imp_callbacks ;
2011-12-03 16:14:51 +00:00
}
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
Oximetry : : Oximetry ( QWidget * parent , gGraphView * shared ) :
2011-07-13 05:27:27 +00:00
QWidget ( parent ) ,
2011-10-05 07:41:56 +00:00
ui ( new Ui : : Oximetry )
2011-07-13 05:27:27 +00:00
{
2014-04-17 05:52:25 +00:00
m_shared = shared ;
2011-07-13 05:27:27 +00:00
ui - > setupUi ( this ) ;
2011-09-11 06:16:45 +00:00
2014-04-23 13:19:56 +00:00
port = nullptr ;
2014-04-17 05:52:25 +00:00
portname = " " ;
2011-09-11 06:16:45 +00:00
2014-04-17 05:52:25 +00:00
oximeter = new CMS50Serial ( this ) ;
2011-07-13 17:42:49 +00:00
2014-04-17 05:52:25 +00:00
day = new Day ( oximeter - > getMachine ( ) ) ;
2011-07-29 14:58:44 +00:00
2014-05-17 11:33:33 +00:00
QVBoxLayout * framelayout = new QVBoxLayout ( ui - > graphArea ) ;
ui - > graphArea - > setLayout ( framelayout ) ;
QFrame * border = new QFrame ( ui - > graphArea ) ;
framelayout - > setMargin ( 1 ) ;
border - > setFrameShape ( QFrame : : StyledPanel ) ;
framelayout - > addWidget ( border , 1 ) ;
2014-04-17 05:52:25 +00:00
layout = new QHBoxLayout ( ui - > graphArea ) ;
2011-08-29 07:13:58 +00:00
layout - > setSpacing ( 0 ) ;
layout - > setMargin ( 0 ) ;
2014-04-17 05:52:25 +00:00
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2014-05-17 11:33:33 +00:00
border - > setLayout ( layout ) ;
border - > setAutoFillBackground ( false ) ;
2011-08-29 07:13:58 +00:00
2014-04-17 05:52:25 +00:00
GraphView = new gGraphView ( ui - > graphArea , m_shared ) ;
GraphView - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Expanding ) ;
2011-08-29 07:13:58 +00:00
2014-04-17 05:52:25 +00:00
scrollbar = new MyScrollBar ( ui - > graphArea ) ;
2011-08-29 07:13:58 +00:00
scrollbar - > setOrientation ( Qt : : Vertical ) ;
2014-04-17 05:52:25 +00:00
scrollbar - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Expanding ) ;
2011-08-29 07:13:58 +00:00
scrollbar - > setMaximumWidth ( 20 ) ;
GraphView - > setScrollBar ( scrollbar ) ;
2014-04-17 05:52:25 +00:00
layout - > addWidget ( GraphView , 1 ) ;
layout - > addWidget ( scrollbar , 0 ) ;
2011-08-29 07:13:58 +00:00
layout - > layout ( ) ;
2014-04-17 05:52:25 +00:00
PLETHY = new gGraph ( GraphView , schema : : channel [ OXI_Plethy ] . label ( ) ,
schema : : channel [ OXI_Plethy ] . units ( ) , 120 ) ;
CONTROL = new gGraph ( GraphView , tr ( " Control " ) , " " , 75 ) ;
PULSE = new gGraph ( GraphView , schema : : channel [ OXI_Pulse ] . label ( ) ,
schema : : channel [ OXI_Pulse ] . units ( ) , 120 ) ;
SPO2 = new gGraph ( GraphView , schema : : channel [ OXI_SPO2 ] . label ( ) , schema : : channel [ OXI_SPO2 ] . units ( ) ,
120 ) ;
foobar = new gShadowArea ( ) ;
2011-08-29 07:13:58 +00:00
CONTROL - > AddLayer ( foobar ) ;
2014-04-17 05:52:25 +00:00
Layer * cl = new gLineChart ( OXI_Plethy ) ;
2011-08-29 07:13:58 +00:00
CONTROL - > AddLayer ( cl ) ;
cl - > SetDay ( day ) ;
CONTROL - > setBlockZoom ( true ) ;
2014-04-17 05:52:25 +00:00
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
gGraph * g = ( * GraphView ) [ i ] ;
g - > AddLayer ( new gXAxis ( ) , LayerBottom , 0 , gXAxis : : Margin ) ;
g - > AddLayer ( new gYAxis ( ) , LayerLeft , gYAxis : : Margin ) ;
2011-08-29 07:13:58 +00:00
g - > AddLayer ( new gXGrid ( ) ) ;
}
2011-07-13 17:42:49 +00:00
2014-04-17 05:52:25 +00:00
plethy = new gLineChart ( OXI_Plethy , COLOR_Plethy , false , true ) ;
2011-07-29 14:58:44 +00:00
plethy - > SetDay ( day ) ;
2011-07-15 16:11:19 +00:00
2011-08-29 07:13:58 +00:00
CONTROL - > AddLayer ( plethy ) ; //new gLineChart(OXI_Plethysomogram));
2014-04-17 05:52:25 +00:00
pulse = new gLineChart ( OXI_Pulse , COLOR_Pulse , true ) ;
2011-11-28 04:05:09 +00:00
//pulse->SetDay(day);
2011-07-29 14:58:44 +00:00
2014-04-17 05:52:25 +00:00
spo2 = new gLineChart ( OXI_SPO2 , COLOR_SPO2 , true ) ;
2011-11-28 04:05:09 +00:00
//spo2->SetDay(day);
2011-07-29 14:58:44 +00:00
PLETHY - > AddLayer ( plethy ) ;
2011-08-29 07:13:58 +00:00
2014-04-17 05:52:25 +00:00
PULSE - > AddLayer ( lo1 = new gLineOverlayBar ( OXI_PulseChange , COLOR_PulseChange , STR_TR_PC , FT_Span ) ) ;
SPO2 - > AddLayer ( lo2 = new gLineOverlayBar ( OXI_SPO2Drop , COLOR_SPO2Drop , STR_TR_O2 , FT_Span ) ) ;
2011-07-29 14:58:44 +00:00
PULSE - > AddLayer ( pulse ) ;
SPO2 - > AddLayer ( spo2 ) ;
2011-11-28 04:05:09 +00:00
PULSE - > setDay ( day ) ;
SPO2 - > setDay ( day ) ;
2011-11-28 13:16:50 +00:00
lo1 - > SetDay ( day ) ;
lo2 - > SetDay ( day ) ;
2011-11-28 04:05:09 +00:00
//go->SetDay(day);
2011-12-18 16:39:36 +00:00
GraphView - > setEmptyText ( tr ( " No Oximetry Data " ) ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-08-29 07:13:58 +00:00
on_RefreshPortsButton_clicked ( ) ;
2011-11-24 12:47:25 +00:00
ui - > RunButton - > setChecked ( false ) ;
2011-07-13 05:27:27 +00:00
2011-11-24 12:47:25 +00:00
ui - > saveButton - > setEnabled ( false ) ;
2011-11-27 16:07:28 +00:00
GraphView - > LoadSettings ( " Oximetry " ) ;
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
QLocale locale = QLocale : : system ( ) ;
QString shortformat = locale . dateFormat ( QLocale : : ShortFormat ) ;
2011-12-06 14:39:14 +00:00
if ( ! shortformat . toLower ( ) . contains ( " yyyy " ) ) {
2014-04-17 05:52:25 +00:00
shortformat . replace ( " yy " , " yyyy " ) ;
2011-12-06 14:39:14 +00:00
}
2014-04-17 05:52:25 +00:00
ui - > dateEdit - > setDisplayFormat ( shortformat + " HH:mm:ss " ) ;
2011-12-06 14:39:14 +00:00
//Qt::DayOfWeek dow=firstDayOfWeekFromLocale();
//ui->dateEdit->calendarWidget()->setFirstDayOfWeek(dow);
// Stop both calendar drop downs highlighting weekends in red
//QTextCharFormat format = ui->dateEdit->calendarWidget()->weekdayTextFormat(Qt::Saturday);
2013-09-10 15:09:09 +00:00
//format.setForeground(QBrush(COLOR_Text, Qt::SolidPattern));
2011-12-06 14:39:14 +00:00
//ui->dateEdit->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format);
//ui->dateEdit->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
2014-04-17 05:52:25 +00:00
dont_update_date = false ;
2011-07-13 05:27:27 +00:00
}
Oximetry : : ~ Oximetry ( )
2014-05-11 19:04:34 +00:00
{
delete ui ;
}
void Oximetry : : closeEvent ( QCloseEvent * event )
2011-07-13 05:27:27 +00:00
{
2011-12-03 17:42:26 +00:00
delete oximeter ;
2011-11-27 16:07:28 +00:00
GraphView - > SaveSettings ( " Oximetry " ) ;
2014-05-11 19:04:34 +00:00
QWidget : : closeEvent ( event ) ;
2011-07-13 05:27:27 +00:00
}
void Oximetry : : on_RefreshPortsButton_clicked ( )
{
QList < QextPortInfo > ports = QextSerialEnumerator : : getPorts ( ) ;
ui - > SerialPortsCombo - > clear ( ) ;
2014-04-17 05:52:25 +00:00
int z = 0 ;
2011-07-13 17:42:49 +00:00
QString firstport ;
2014-04-17 05:52:25 +00:00
bool current_found = false ;
const QString STR_USB = " USB " ;
2011-07-29 14:58:44 +00:00
// Windows build mixes these up
2013-01-20 16:31:51 +00:00
# if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
2011-07-18 11:56:56 +00:00
# define qesPORTNAME portName
# else
# define qesPORTNAME physName
# endif
2014-04-17 05:52:25 +00:00
2011-07-13 05:27:27 +00:00
for ( int i = 0 ; i < ports . size ( ) ; i + + ) {
2011-08-07 03:22:09 +00:00
if ( ! ports . at ( i ) . friendName . isEmpty ( ) ) {
2013-09-10 15:09:09 +00:00
if ( ports . at ( i ) . friendName . toUpper ( ) . contains ( STR_USB ) ) {
2014-04-17 05:52:25 +00:00
if ( firstport . isEmpty ( ) ) { firstport = ports . at ( i ) . qesPORTNAME ; }
if ( ! portname . isEmpty ( ) & & ports . at ( i ) . qesPORTNAME = = portname ) { current_found = true ; }
2011-08-07 03:22:09 +00:00
ui - > SerialPortsCombo - > addItem ( ports . at ( i ) . qesPORTNAME ) ;
z + + ;
}
} else { // Mac stuff.
2014-04-17 05:52:25 +00:00
if ( ports . at ( i ) . portName . toUpper ( ) . contains ( STR_USB )
| | ports . at ( i ) . portName . toUpper ( ) . contains ( " SPO2 " ) ) {
if ( firstport . isEmpty ( ) ) { firstport = ports . at ( i ) . portName ; }
if ( ! portname . isEmpty ( ) & & ports . at ( i ) . portName = = portname ) { current_found = true ; }
2011-08-07 03:22:09 +00:00
ui - > SerialPortsCombo - > addItem ( ports . at ( i ) . portName ) ;
z + + ;
}
2011-07-13 17:42:49 +00:00
}
2014-04-17 05:52:25 +00:00
2012-01-22 17:13:15 +00:00
qDebug ( ) < < " Serial Port: " < < ports . at ( i ) . qesPORTNAME < < ports . at ( i ) . friendName ;
qDebug ( ) < < " port name: " < < ports . at ( i ) . portName ;
qDebug ( ) < < " phys name: " < < ports . at ( i ) . physName ;
qDebug ( ) < < " friendly name: " < < ports . at ( i ) . friendName ;
qDebug ( ) < < " enumerator name: " < < ports . at ( i ) . enumName ;
2011-07-13 05:27:27 +00:00
}
2014-04-17 05:52:25 +00:00
if ( z > 0 ) {
2011-07-13 17:42:49 +00:00
ui - > RunButton - > setEnabled ( true ) ;
ui - > ImportButton - > setEnabled ( true ) ;
2014-04-17 05:52:25 +00:00
if ( ! current_found ) { portname = firstport ; }
2011-07-13 17:42:49 +00:00
} else {
ui - > RunButton - > setEnabled ( false ) ;
ui - > ImportButton - > setEnabled ( false ) ;
2014-04-17 05:52:25 +00:00
portname = " " ;
2011-07-13 17:42:49 +00:00
}
2014-04-17 05:52:25 +00:00
2011-11-24 12:47:25 +00:00
oximeter - > setPortName ( portname ) ;
2011-07-13 17:42:49 +00:00
}
2013-09-16 04:30:38 +00:00
void Oximetry : : serialImport ( )
{
2014-04-17 05:52:25 +00:00
connect ( oximeter , SIGNAL ( importComplete ( Session * ) ) , this , SLOT ( import_complete ( Session * ) ) ) ;
connect ( oximeter , SIGNAL ( importAborted ( ) ) , this , SLOT ( import_aborted ( ) ) ) ;
connect ( oximeter , SIGNAL ( updateProgress ( float ) ) , this , SLOT ( update_progress ( float ) ) ) ;
2013-09-16 04:30:38 +00:00
PLETHY - > setVisible ( false ) ;
day - > getSessions ( ) . clear ( ) ;
GraphView - > setDay ( day ) ;
//GraphView->setEmptyText(tr("Make Sure Oximeter is Ready"));
//GraphView->redraw();
2014-04-17 05:52:25 +00:00
cancel_Import = false ;
QTimer : : singleShot ( 100 , this , SLOT ( timeout_CheckPorts ( ) ) ) ;
connectDeviceMsgBox = new QMessageBox ( QMessageBox : : Information , tr ( " Connect Oximeter " ) ,
tr ( " Please connect oximeter device " ) ,
QMessageBox : : Cancel ) ;
connect ( connectDeviceMsgBox , SIGNAL ( buttonClicked ( QAbstractButton * ) ) , this ,
SLOT ( cancel_CheckPorts ( QAbstractButton * ) ) ) ;
2013-09-25 16:07:45 +00:00
connectDeviceMsgBox - > exec ( ) ;
2014-04-17 05:52:25 +00:00
// QApplication::processEvents();
2013-09-16 04:30:38 +00:00
}
2014-04-17 05:52:25 +00:00
void Oximetry : : cancel_CheckPorts ( QAbstractButton * )
2013-09-16 04:30:38 +00:00
{
qDebug ( ) < < " cancel_CheckPorts() " ;
2014-04-17 05:52:25 +00:00
cancel_Import = true ;
2013-09-16 04:30:38 +00:00
2014-04-17 05:52:25 +00:00
disconnect ( connectDeviceMsgBox , 0 , 0 ,
0 ) ; //SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(cancel_CheckPorts()));
disconnect ( oximeter , SIGNAL ( importComplete ( Session * ) ) , this , SLOT ( import_complete ( Session * ) ) ) ;
disconnect ( oximeter , SIGNAL ( importAborted ( ) ) , this , SLOT ( import_aborted ( ) ) ) ;
disconnect ( oximeter , SIGNAL ( updateProgress ( float ) ) , this , SLOT ( update_progress ( float ) ) ) ;
2013-09-16 04:30:38 +00:00
connectDeviceMsgBox - > close ( ) ;
delete connectDeviceMsgBox ;
2014-04-23 13:19:56 +00:00
connectDeviceMsgBox = nullptr ;
2013-09-16 04:30:38 +00:00
2014-04-17 05:52:25 +00:00
if ( oximeter - > isImporting ( ) ) {
2013-09-16 04:30:38 +00:00
oximeter - > stopImport ( ) ;
2014-04-17 05:52:25 +00:00
}
2013-09-16 04:30:38 +00:00
}
void Oximetry : : timeout_CheckPorts ( )
{
if ( cancel_Import ) {
return ;
}
2014-04-17 05:52:25 +00:00
if ( portname = = " " ) {
2013-09-16 04:30:38 +00:00
qDebug ( ) < < " restarting timeout_CheckPorts() " ;
on_RefreshPortsButton_clicked ( ) ;
2014-04-17 05:52:25 +00:00
if ( portname = = " " ) {
QTimer : : singleShot ( 1000 , this , SLOT ( timeout_CheckPorts ( ) ) ) ;
2013-09-16 04:30:38 +00:00
return ;
}
}
qDebug ( ) < < " Calling oximeter->startImport() " ;
2014-04-17 05:52:25 +00:00
2013-09-16 04:30:38 +00:00
if ( ! oximeter - > startImport ( ) ) {
2014-04-17 05:52:25 +00:00
QTimer : : singleShot ( 1000 , this , SLOT ( timeout_CheckPorts ( ) ) ) ;
2013-09-16 04:30:38 +00:00
return ;
}
2014-04-17 05:52:25 +00:00
2013-09-16 04:30:38 +00:00
qDebug ( ) < < " Success at oximeter->startImport() " ;
2014-04-17 05:52:25 +00:00
disconnect ( connectDeviceMsgBox , SIGNAL ( buttonClicked ( QAbstractButton * ) ) , this ,
SLOT ( cancel_CheckPorts ( QAbstractButton * ) ) ) ;
2013-09-16 04:30:38 +00:00
connectDeviceMsgBox - > close ( ) ;
delete connectDeviceMsgBox ;
2014-04-23 13:19:56 +00:00
//connectDeviceMsgBox=nullptr;
2014-04-17 05:52:25 +00:00
connectDeviceMsgBox = new QMessageBox ( QMessageBox : : Information , tr ( " Device Connected " ) ,
tr ( " Please make sure Oximeter device is in upload mode. " ) ,
QMessageBox : : Cancel ) ;
connect ( connectDeviceMsgBox , SIGNAL ( buttonClicked ( QAbstractButton * ) ) , this ,
SLOT ( cancel_CheckPorts ( QAbstractButton * ) ) ) ;
2013-09-25 16:07:45 +00:00
connectDeviceMsgBox - > exec ( ) ;
2013-09-16 04:30:38 +00:00
//mainwin->Notify(tr("Please make sure Oximeter device is in upload mode."),tr("Device Connected"));
}
2011-07-13 17:42:49 +00:00
void Oximetry : : RedrawGraphs ( )
{
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-07-13 17:42:49 +00:00
}
2011-11-24 12:47:25 +00:00
void Oximetry : : on_SerialPortsCombo_activated ( const QString & arg1 )
{
2014-04-17 05:52:25 +00:00
portname = arg1 ;
2011-11-24 12:47:25 +00:00
oximeter - > setPortName ( arg1 ) ;
}
2011-07-13 17:42:49 +00:00
2014-04-17 05:52:25 +00:00
void Oximetry : : live_stopped ( Session * session )
2011-12-03 14:13:14 +00:00
{
2011-12-08 11:41:44 +00:00
Q_UNUSED ( session ) ;
2011-12-18 16:39:36 +00:00
mainwin - > Notify ( tr ( " Oximetry live recording has been terminated due to timeout. " ) ) ;
2011-12-03 14:13:14 +00:00
//qDebug () << "Live Stopped";
on_RunButton_toggled ( false ) ;
}
2011-12-03 10:08:40 +00:00
void Oximetry : : on_RunButton_toggled ( bool checked )
2011-07-13 17:42:49 +00:00
{
2011-11-24 12:47:25 +00:00
if ( ! checked ) {
2014-04-17 05:52:25 +00:00
oximeter - > stopLive ( ) ;
ui - > RunButton - > setText ( tr ( " &Start " ) ) ;
ui - > SerialPortsCombo - > setEnabled ( true ) ;
disconnect ( oximeter , SIGNAL ( dataChanged ( ) ) , this , SLOT ( data_changed ( ) ) ) ;
disconnect ( oximeter , SIGNAL ( updatePulse ( float ) ) , this , SLOT ( pulse_changed ( float ) ) ) ;
disconnect ( oximeter , SIGNAL ( updateSpO2 ( float ) ) , this , SLOT ( spo2_changed ( float ) ) ) ;
disconnect ( oximeter , SIGNAL ( liveStopped ( Session * ) ) , this , SLOT ( live_stopped ( Session * ) ) ) ;
ui - > saveButton - > setEnabled ( true ) ;
ui - > ImportButton - > setEnabled ( true ) ;
lo2 - > SetDay ( day ) ;
lo1 - > SetDay ( day ) ;
if ( oximeter - > getSession ( ) ) {
saved_starttime = oximeter - > getSession ( ) - > first ( ) ;
}
//CONTROL->setVisible(true);
2011-07-13 17:42:49 +00:00
} else {
2011-11-24 12:47:25 +00:00
if ( oximeter - > getSession ( ) & & oximeter - > getSession ( ) - > IsChanged ( ) ) {
2014-05-17 05:04:40 +00:00
int res = askSaveSession ( ) ;
2014-04-17 05:52:25 +00:00
if ( res = = 0 ) {
2011-11-24 12:47:25 +00:00
on_saveButton_clicked ( ) ;
return ;
2014-04-17 05:52:25 +00:00
} else if ( res = = 2 ) {
2011-11-24 12:47:25 +00:00
return ;
}
} // else it's already saved.
2014-04-17 05:52:25 +00:00
2011-12-18 16:39:36 +00:00
GraphView - > setEmptyText ( tr ( " Please Wait " ) ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-12-01 06:06:13 +00:00
2011-12-24 05:55:44 +00:00
PLETHY - > setVisible ( true ) ;
SPO2 - > setVisible ( true ) ;
PULSE - > setVisible ( true ) ;
2011-11-28 04:05:09 +00:00
PLETHY - > setRecMinY ( 0 ) ;
PLETHY - > setRecMaxY ( 128 ) ;
PULSE - > setRecMinY ( 60 ) ;
PULSE - > setRecMaxY ( 100 ) ;
SPO2 - > setRecMinY ( 90 ) ;
SPO2 - > setRecMaxY ( 100 ) ;
2011-08-29 07:13:58 +00:00
2011-12-01 06:06:13 +00:00
day - > getSessions ( ) . clear ( ) ;
2014-04-17 05:52:25 +00:00
2011-12-03 00:06:11 +00:00
//QTimer::singleShot(10000,this,SLOT(oximeter_running_check()));
2011-11-24 12:47:25 +00:00
if ( ! oximeter - > startLive ( ) ) {
2011-12-18 16:39:36 +00:00
mainwin - > Notify ( tr ( " Oximetry Error! \n \n Something is wrong with the device connection. " ) ) ;
2011-11-24 12:47:25 +00:00
return ;
2011-08-07 15:37:01 +00:00
}
2014-04-17 05:52:25 +00:00
2011-11-24 12:47:25 +00:00
ui - > saveButton - > setEnabled ( false ) ;
day - > AddSession ( oximeter - > getSession ( ) ) ;
2014-04-17 05:52:25 +00:00
firstPulseUpdate = true ;
firstSPO2Update = true ;
secondPulseUpdate = true ;
secondSPO2Update = true ;
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
qint64 f = oximeter - > getSession ( ) - > first ( ) ;
2012-01-19 15:18:34 +00:00
//day->setFirst(f);
2011-11-24 12:47:25 +00:00
plethy - > setMinX ( f ) ;
pulse - > setMinX ( f ) ;
spo2 - > setMinX ( f ) ;
PLETHY - > SetMinX ( f ) ;
CONTROL - > SetMinX ( f ) ;
PULSE - > SetMinX ( f ) ;
SPO2 - > SetMinX ( f ) ;
2011-12-01 06:06:13 +00:00
//graphView()->updateScale();
2011-11-28 04:05:09 +00:00
/*PLETHY->setForceMinY(0);
2011-11-27 16:07:28 +00:00
PLETHY - > setForceMaxY ( 128 ) ;
PULSE - > setForceMinY ( 30 ) ;
PULSE - > setForceMaxY ( 180 ) ;
2011-11-28 13:16:50 +00:00
SPO2 - > setForceMinY ( 50 ) ;
SPO2 - > setForceMaxY ( 100 ) ; */
2011-11-24 12:47:25 +00:00
2014-04-17 05:52:25 +00:00
connect ( oximeter , SIGNAL ( dataChanged ( ) ) , this , SLOT ( data_changed ( ) ) ) ;
connect ( oximeter , SIGNAL ( updatePulse ( float ) ) , this , SLOT ( pulse_changed ( float ) ) ) ;
connect ( oximeter , SIGNAL ( updateSpO2 ( float ) ) , this , SLOT ( spo2_changed ( float ) ) ) ;
connect ( oximeter , SIGNAL ( liveStopped ( Session * ) ) , this , SLOT ( live_stopped ( Session * ) ) ) ;
2011-12-03 14:13:14 +00:00
2011-11-24 12:47:25 +00:00
CONTROL - > setVisible ( false ) ;
// connect.
2011-12-18 16:39:36 +00:00
ui - > RunButton - > setText ( tr ( " &Stop " ) ) ;
2011-11-24 12:47:25 +00:00
ui - > SerialPortsCombo - > setEnabled ( false ) ;
2011-12-01 15:40:32 +00:00
ui - > ImportButton - > setEnabled ( false ) ;
2011-07-13 17:42:49 +00:00
}
2011-07-17 15:57:45 +00:00
}
2011-12-03 14:13:14 +00:00
void Oximetry : : data_changed ( )
2011-07-17 15:57:45 +00:00
{
2011-07-18 00:47:21 +00:00
2014-04-17 05:52:25 +00:00
qint64 last = oximeter - > lastTime ( ) ;
qint64 first = last - 30000L ;
2012-01-19 15:18:34 +00:00
//day->setLast(last);
2011-11-24 12:47:25 +00:00
2011-12-01 06:06:13 +00:00
plethy - > setMinX ( first ) ;
plethy - > setMaxX ( last ) ;
2011-11-24 12:47:25 +00:00
pulse - > setMinX ( first ) ;
pulse - > setMaxX ( last ) ;
spo2 - > setMinX ( first ) ;
spo2 - > setMaxX ( last ) ;
2011-12-17 14:38:15 +00:00
plethy - > setMinY ( ( oximeter - > Plethy ( ) ) - > Min ( ) ) ;
plethy - > setMaxY ( ( oximeter - > Plethy ( ) ) - > Max ( ) ) ;
pulse - > setMinY ( ( oximeter - > Pulse ( ) ) - > Min ( ) ) ;
pulse - > setMaxY ( ( oximeter - > Pulse ( ) ) - > Max ( ) ) ;
spo2 - > setMinY ( ( oximeter - > Spo2 ( ) ) - > Min ( ) ) ;
spo2 - > setMaxY ( ( oximeter - > Spo2 ( ) ) - > Max ( ) ) ;
2011-11-24 12:47:25 +00:00
2011-12-17 14:38:15 +00:00
PLETHY - > SetMinY ( ( oximeter - > Plethy ( ) ) - > Min ( ) ) ;
PLETHY - > SetMaxY ( ( oximeter - > Plethy ( ) ) - > Max ( ) ) ;
PULSE - > SetMinY ( ( oximeter - > Pulse ( ) ) - > Min ( ) ) ;
PULSE - > SetMaxY ( ( oximeter - > Pulse ( ) ) - > Max ( ) ) ;
SPO2 - > SetMinY ( ( oximeter - > Spo2 ( ) ) - > Min ( ) ) ;
SPO2 - > SetMaxY ( ( oximeter - > Spo2 ( ) ) - > Max ( ) ) ;
2011-12-01 09:09:33 +00:00
/*PLETHY->MinY();
2011-11-24 12:47:25 +00:00
PLETHY - > MaxY ( ) ;
PULSE - > MinY ( ) ;
PULSE - > MaxY ( ) ;
SPO2 - > MinY ( ) ;
2011-12-01 09:09:33 +00:00
SPO2 - > MaxY ( ) ; */
2011-11-24 12:47:25 +00:00
PLETHY - > SetMaxX ( last ) ;
PULSE - > SetMaxX ( last ) ;
CONTROL - > SetMaxX ( last ) ;
SPO2 - > SetMaxX ( last ) ;
2011-08-29 07:13:58 +00:00
2014-04-17 05:52:25 +00:00
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
( * GraphView ) [ i ] - > SetXBounds ( first , last ) ;
2011-07-17 15:57:45 +00:00
}
2011-07-19 02:52:03 +00:00
{
2014-04-17 05:52:25 +00:00
int len = ( last - first ) / 1000L ;
int h = len / 3600 ;
int m = ( len / 60 ) % 60 ;
int s = ( len % 60 ) ;
if ( qstatus2 ) { qstatus2 - > setText ( QString ( ) . sprintf ( " Rec %02i:%02i:%02i " , h , m , s ) ) ; } // translation fix?
2011-07-15 10:01:28 +00:00
}
2011-08-29 07:13:58 +00:00
2011-12-01 09:09:33 +00:00
GraphView - > updateScale ( ) ;
2013-09-06 12:42:14 +00:00
GraphView - > timedRedraw ( 25 ) ;
2011-07-13 17:42:49 +00:00
}
2011-07-29 14:58:44 +00:00
2011-11-24 12:47:25 +00:00
2011-07-13 17:42:49 +00:00
extern QProgressBar * qprogress ;
extern QLabel * qstatus ;
2011-07-18 00:47:21 +00:00
2014-04-17 05:52:25 +00:00
void DumpBytes ( int blocks , unsigned char * b , int len )
2011-07-18 00:47:21 +00:00
{
2014-04-17 05:52:25 +00:00
QString a = QString : : number ( blocks , 16 ) + " : Bytes " + QString : : number ( len , 16 ) + " : " ;
for ( int i = 0 ; i < len ; i + + ) {
a . append ( QString : : number ( b [ i ] , 16 ) + " " ) ;
2011-07-18 00:47:21 +00:00
}
2014-04-17 05:52:25 +00:00
2011-07-18 00:47:21 +00:00
qDebug ( ) < < a ;
}
2011-12-01 01:47:09 +00:00
void Oximetry : : oximeter_running_check ( )
{
if ( ! oximeter - > isOpen ( ) ) {
2014-04-17 05:52:25 +00:00
if ( oximeter - > callbacks ( ) = = 0 ) {
2014-05-17 05:04:40 +00:00
qDebug ( ) < < " Not sure how oximeter_running_check gets called with a closed oximeter.. Restarting import process " ;
2011-12-18 16:39:36 +00:00
//mainwin->Notify(tr("Oximeter Error\n\nThe device has not responded.. Make sure it's switched on2"));
2011-12-03 14:13:14 +00:00
on_ImportButton_clicked ( ) ;
return ;
}
2011-12-01 01:47:09 +00:00
}
2014-04-17 05:52:25 +00:00
if ( oximeter - > callbacks ( ) = = 0 ) {
2014-05-17 05:04:40 +00:00
mainwin - > Notify ( tr ( " Oximeter Error \n \n The device has not responded.. Make sure it's switched on. " ) ) ;
2014-04-17 05:52:25 +00:00
if ( oximeter - > mode ( ) = = SO_IMPORT ) { oximeter - > stopImport ( ) ; }
if ( oximeter - > mode ( ) = = SO_LIVE ) { oximeter - > stopLive ( ) ; }
2011-12-01 06:06:13 +00:00
oximeter - > destroySession ( ) ;
day - > getSessions ( ) . clear ( ) ;
ui - > SerialPortsCombo - > setEnabled ( true ) ;
2013-09-10 15:09:09 +00:00
qstatus - > setText ( STR_TR_Ready ) ;
2011-12-01 06:06:13 +00:00
ui - > ImportButton - > setEnabled ( true ) ;
ui - > RunButton - > setChecked ( false ) ;
ui - > saveButton - > setEnabled ( false ) ;
2011-12-18 16:39:36 +00:00
GraphView - > setEmptyText ( tr ( " Check Oximeter is Ready " ) ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-12-01 06:06:13 +00:00
2011-12-01 01:47:09 +00:00
}
}
2011-07-18 00:47:21 +00:00
2011-07-13 17:42:49 +00:00
// Move this code to CMS50 Importer??
void Oximetry : : on_ImportButton_clicked ( )
{
2014-04-17 05:52:25 +00:00
connect ( oximeter , SIGNAL ( importComplete ( Session * ) ) , this , SLOT ( import_complete ( Session * ) ) ) ;
connect ( oximeter , SIGNAL ( importAborted ( ) ) , this , SLOT ( import_aborted ( ) ) ) ;
connect ( oximeter , SIGNAL ( updateProgress ( float ) ) , this , SLOT ( update_progress ( float ) ) ) ;
2011-11-24 12:47:25 +00:00
2011-12-24 05:55:44 +00:00
PLETHY - > setVisible ( false ) ;
2011-12-19 17:51:25 +00:00
day - > getSessions ( ) . clear ( ) ;
GraphView - > setDay ( day ) ;
2013-09-09 15:56:02 +00:00
//GraphView->setEmptyText(tr("Make Sure Oximeter is Ready"));
//GraphView->redraw();
2011-12-19 17:51:25 +00:00
2011-11-24 12:47:25 +00:00
if ( ! oximeter - > startImport ( ) ) {
2011-12-18 16:39:36 +00:00
mainwin - > Notify ( tr ( " Oximeter Error \n \n The device did not respond.. Make sure it's switched on. " ) ) ;
2013-09-06 12:42:14 +00:00
import_finished ( ) ;
2014-04-17 05:52:25 +00:00
// disconnect(oximeter,SIGNAL(importComplete(Session*)),this,SLOT(import_complete(Session*)));
// disconnect(oximeter,SIGNAL(importAborted()),this,SLOT(import_aborted()));
// disconnect(oximeter,SIGNAL(updateProgress(float)),this,SLOT(update_progress(float)));
2011-12-01 01:47:09 +00:00
//qDebug() << "Error starting oximetry serial import process";
2011-11-24 12:47:25 +00:00
return ;
}
2014-04-17 05:52:25 +00:00
2011-12-03 17:06:36 +00:00
//QTimer::singleShot(1000,this,SLOT(oximeter_running_check()));
2011-12-01 01:47:09 +00:00
2011-11-24 12:47:25 +00:00
if ( qprogress ) {
qprogress - > setValue ( 0 ) ;
qprogress - > setMaximum ( 100 ) ;
qprogress - > show ( ) ;
}
2014-04-17 05:52:25 +00:00
2011-11-24 12:47:25 +00:00
ui - > ImportButton - > setDisabled ( true ) ;
2011-07-13 17:42:49 +00:00
ui - > SerialPortsCombo - > setEnabled ( false ) ;
2011-12-18 16:39:36 +00:00
ui - > RunButton - > setText ( tr ( " &Start " ) ) ;
2011-07-13 17:42:49 +00:00
ui - > RunButton - > setChecked ( false ) ;
2011-11-24 12:47:25 +00:00
}
2011-07-13 17:42:49 +00:00
2011-11-24 12:47:25 +00:00
void Oximetry : : import_finished ( )
{
2013-09-16 04:30:38 +00:00
if ( connectDeviceMsgBox ) {
connectDeviceMsgBox - > close ( ) ;
2014-04-17 05:52:25 +00:00
disconnect ( connectDeviceMsgBox , SIGNAL ( buttonClicked ( QAbstractButton * ) ) , this ,
SLOT ( cancel_CheckPorts ( ) ) ) ;
2013-09-16 04:30:38 +00:00
delete connectDeviceMsgBox ;
2014-04-23 13:19:56 +00:00
connectDeviceMsgBox = nullptr ;
2013-09-16 04:30:38 +00:00
}
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
disconnect ( oximeter , SIGNAL ( importComplete ( Session * ) ) , this , SLOT ( import_complete ( Session * ) ) ) ;
disconnect ( oximeter , SIGNAL ( importAborted ( ) ) , this , SLOT ( import_aborted ( ) ) ) ;
disconnect ( oximeter , SIGNAL ( updateProgress ( float ) ) , this , SLOT ( update_progress ( float ) ) ) ;
oximeter - > disconnect ( oximeter , SIGNAL ( importProcess ( ) ) , 0 , 0 ) ;
2013-09-06 12:42:14 +00:00
2014-04-17 05:52:25 +00:00
// oximeter->Close();
2013-09-06 12:42:14 +00:00
// Hanging here.. :(
2011-07-13 17:42:49 +00:00
2011-11-24 12:47:25 +00:00
ui - > SerialPortsCombo - > setEnabled ( true ) ;
2013-09-10 15:09:09 +00:00
qstatus - > setText ( STR_TR_Ready ) ;
2011-11-24 12:47:25 +00:00
ui - > ImportButton - > setDisabled ( false ) ;
ui - > saveButton - > setEnabled ( true ) ;
2011-07-13 17:42:49 +00:00
2011-11-24 12:47:25 +00:00
if ( qprogress ) {
qprogress - > setValue ( 100 ) ;
qprogress - > hide ( ) ;
2011-07-13 17:42:49 +00:00
}
2011-11-24 12:47:25 +00:00
}
2011-07-13 17:42:49 +00:00
2011-12-03 08:52:24 +00:00
void Oximetry : : import_aborted ( )
2011-11-24 12:47:25 +00:00
{
2011-12-03 16:14:51 +00:00
day - > getSessions ( ) . clear ( ) ;
2011-12-18 16:39:36 +00:00
//QMessageBox::warning(mainwin,tr("Oximeter Error"),tr("Please make sure your oximeter is switched on, and able to transmit data.\n(You may need to enter the oximeters Settings screen for it to be able to transmit.)"),QMessageBox::Ok);
2014-04-17 05:52:25 +00:00
mainwin - > Notify (
tr ( " Please make sure your oximeter is switched on, and in the right mode to transmit data. " ) ,
tr ( " Oximeter Error! " ) , 5000 ) ;
2011-12-01 01:47:09 +00:00
//qDebug() << "Oximetry import failed";
2011-12-03 15:06:22 +00:00
2013-09-06 12:42:14 +00:00
import_finished ( ) ;
2011-11-24 12:47:25 +00:00
}
2014-04-17 05:52:25 +00:00
void Oximetry : : import_complete ( Session * session )
2011-11-24 12:47:25 +00:00
{
qDebug ( ) < < " Oximetry import complete " ;
import_finished ( ) ;
2011-12-19 17:51:25 +00:00
day - > AddSession ( oximeter - > getSession ( ) ) ;
2011-12-03 15:06:22 +00:00
if ( ! session ) {
qDebug ( ) < < " Shouldn't happen " ;
return ;
}
2011-11-24 12:47:25 +00:00
2011-12-02 05:54:25 +00:00
//calcSPO2Drop(session);
//calcPulseChange(session);
2011-11-28 13:16:50 +00:00
//PLETHY->setVisible(false);
2011-11-24 12:47:25 +00:00
2011-12-06 14:39:14 +00:00
CONTROL - > setVisible ( false ) ;
2011-07-31 20:24:43 +00:00
2014-04-17 05:52:25 +00:00
saved_starttime = session - > first ( ) ;
dont_update_date = true ;
ui - > dateEdit - > setDateTime ( QDateTime : : fromTime_t ( saved_starttime / 1000L ) ) ;
dont_update_date = false ;
2011-07-31 20:24:43 +00:00
2011-12-06 14:39:14 +00:00
updateGraphs ( ) ;
2011-11-24 12:47:25 +00:00
}
2011-07-31 20:24:43 +00:00
2011-12-03 14:13:14 +00:00
void Oximetry : : pulse_changed ( float p )
2011-11-24 12:47:25 +00:00
{
ui - > pulseLCD - > display ( p ) ;
2011-12-01 09:09:33 +00:00
return ;
2014-04-17 05:52:25 +00:00
2011-11-24 12:47:25 +00:00
if ( firstPulseUpdate ) {
if ( secondPulseUpdate ) {
2014-04-17 05:52:25 +00:00
secondPulseUpdate = false ;
2011-11-24 12:47:25 +00:00
} else {
2014-04-17 05:52:25 +00:00
firstPulseUpdate = false ;
2011-11-24 12:47:25 +00:00
GraphView - > updateScale ( ) ;
2011-07-13 17:42:49 +00:00
}
2011-11-24 12:47:25 +00:00
}
}
2011-07-29 14:58:44 +00:00
2011-11-24 12:47:25 +00:00
// Only really need to do this once..
2011-12-03 14:13:14 +00:00
void Oximetry : : spo2_changed ( float o2 )
2011-11-24 12:47:25 +00:00
{
ui - > spo2LCD - > display ( o2 ) ;
2011-12-01 09:09:33 +00:00
return ;
2014-04-17 05:52:25 +00:00
2011-11-24 12:47:25 +00:00
if ( firstSPO2Update ) {
if ( secondSPO2Update ) {
2014-04-17 05:52:25 +00:00
secondSPO2Update = false ;
2011-11-24 12:47:25 +00:00
} else {
2014-04-17 05:52:25 +00:00
firstSPO2Update = false ;
2011-11-24 12:47:25 +00:00
GraphView - > updateScale ( ) ;
}
}
}
2011-07-29 14:58:44 +00:00
2011-11-24 12:47:25 +00:00
void Oximetry : : on_saveButton_clicked ( )
{
2014-04-17 05:52:25 +00:00
if ( QMessageBox : : question ( this , tr ( " Keep This Recording? " ) ,
tr ( " Would you like to save this oximetery session? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) {
Session * session = oximeter - > getSession ( ) ;
2011-12-06 14:39:14 +00:00
2011-11-24 12:47:25 +00:00
// Process???
2011-12-01 00:18:59 +00:00
//session->UpdateSummaries();
2011-12-06 14:39:14 +00:00
PROFILE . RemoveSession ( session ) ;
2014-04-17 05:52:25 +00:00
Machine * m = oximeter - > getMachine ( ) ;
2011-12-06 14:39:14 +00:00
if ( m - > SessionExists ( session - > session ( ) ) ) {
m - > sessionlist . erase ( m - > sessionlist . find ( session - > session ( ) ) ) ;
}
2014-04-17 05:52:25 +00:00
QString path = PROFILE . Get ( m - > properties [ STR_PROP_Path ] ) + QString ( ) . sprintf ( " %08lx " ,
session - > session ( ) ) ;
QString f1 = path + " .000 " ;
QString f2 = path + " .001 " ;
2011-12-28 07:09:35 +00:00
QFile : : remove ( f1 ) ;
QFile : : remove ( f2 ) ;
2011-12-07 12:23:19 +00:00
// Forgetting to reset the session ID sucks, as it will delete sessions you don't want to delete..
2014-04-17 05:52:25 +00:00
session - > SetSessionID ( qint64 ( session - > first ( ) ) / 1000L ) ;
2011-12-07 12:23:19 +00:00
2014-04-17 05:52:25 +00:00
m - > AddSession ( session , p_profile ) ;
2011-12-07 12:23:19 +00:00
2011-11-24 12:47:25 +00:00
oximeter - > getMachine ( ) - > Save ( ) ;
2011-12-01 00:18:59 +00:00
day - > getSessions ( ) . clear ( ) ;
2011-12-06 14:39:14 +00:00
2012-01-19 15:18:34 +00:00
mainwin - > getDaily ( ) - > LoadDate ( mainwin - > getDaily ( ) - > getDate ( ) ) ;
2011-12-01 00:18:59 +00:00
mainwin - > getOverview ( ) - > ReloadGraphs ( ) ;
2013-09-09 15:56:02 +00:00
GraphView - > setEmptyText ( tr ( " No Oximetry Data " ) ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-11-24 12:47:25 +00:00
}
}
2011-12-03 14:13:14 +00:00
void Oximetry : : update_progress ( float f )
2011-11-24 12:47:25 +00:00
{
if ( qprogress ) {
2014-04-17 05:52:25 +00:00
qprogress - > setValue ( f * 100.0 ) ;
2011-11-24 12:47:25 +00:00
QApplication : : processEvents ( ) ;
2011-07-13 17:42:49 +00:00
}
2011-07-13 05:27:27 +00:00
}
2011-12-05 15:03:16 +00:00
bool Oximetry : : openSPOFile ( QString filename )
{
QFile f ( filename ) ;
2014-04-17 05:52:25 +00:00
if ( ! f . open ( QFile : : ReadOnly ) ) { return false ; }
2011-12-05 15:03:16 +00:00
QByteArray data ;
2014-04-17 05:52:25 +00:00
data = f . readAll ( ) ;
long size = data . size ( ) ;
2011-12-05 15:03:16 +00:00
2014-04-17 05:52:25 +00:00
int pos = ( ( unsigned char ) data . at ( 1 ) < < 8 ) | ( unsigned char ) data . at ( 0 ) ;
2011-12-05 15:03:16 +00:00
char dchr [ 20 ] ;
2014-04-17 05:52:25 +00:00
int j = 0 ;
for ( int i = 0 ; i < 18 * 2 ; i + = 2 ) {
dchr [ j + + ] = data . at ( 8 + i ) ;
2011-12-05 15:03:16 +00:00
}
2014-04-17 05:52:25 +00:00
dchr [ j ] = 0 ;
2011-12-05 15:03:16 +00:00
QString dstr ( dchr ) ;
2014-04-17 05:52:25 +00:00
QDateTime date = QDateTime : : fromString ( dstr , " MM/dd/yy HH:mm:ss " ) ;
if ( date . date ( ) . year ( ) < 2000 ) { date = date . addYears ( 100 ) ; }
2011-12-06 14:39:14 +00:00
//ui->dateEdit->setDateTime(date);
2011-12-05 15:03:16 +00:00
day - > getSessions ( ) . clear ( ) ;
oximeter - > createSession ( date ) ;
2014-04-17 05:52:25 +00:00
Session * session = oximeter - > getSession ( ) ;
2011-12-05 15:03:16 +00:00
day - > AddSession ( session ) ;
session - > set_first ( 0 ) ;
2014-04-17 05:52:25 +00:00
firstPulseUpdate = true ;
firstSPO2Update = true ;
secondPulseUpdate = true ;
secondSPO2Update = true ;
2011-12-05 15:03:16 +00:00
2014-04-17 05:52:25 +00:00
unsigned char o2 , pr ;
2012-01-05 12:12:42 +00:00
//quint16 pl;
2014-04-17 05:52:25 +00:00
qint64 tt = qint64 ( date . toTime_t ( ) ) * 1000L ;
2011-12-05 15:03:16 +00:00
2014-04-17 05:52:25 +00:00
for ( int i = pos ; i < size - 5 ; ) {
o2 = ( unsigned char ) ( data . at ( i + 4 ) ) ;
pr = ( unsigned char ) ( data . at ( i + 3 ) ) ;
2011-12-05 15:03:16 +00:00
//oximeter->setLastTime(tt);
2014-04-17 05:52:25 +00:00
oximeter - > addPulse ( tt , pr ) ;
oximeter - > addSpO2 ( tt , o2 ) ;
2012-01-05 12:12:42 +00:00
//pl=(unsigned char)(data.at(i+1));
2011-12-05 15:03:16 +00:00
//oximeter->addPlethy(tt,pl);
//pl=(unsigned char)(data.at(i+1));
//oximeter->addPlethy(tt,pl);
//pl=(unsigned char)(data.at(i+2));
//oximeter->addPlethy(tt,pl);
2014-04-17 05:52:25 +00:00
i + = 5 ;
2011-12-05 15:03:16 +00:00
//data_changed();
2014-04-17 05:52:25 +00:00
tt + = 1000 ;
2011-12-05 15:03:16 +00:00
}
2014-04-17 05:52:25 +00:00
qint64 t1 = session - > first ( OXI_Pulse ) ;
qint64 t2 = session - > first ( OXI_SPO2 ) ;
qint64 t3 = qMin ( t1 , t2 ) ;
2011-12-05 15:03:16 +00:00
session - > set_first ( t3 ) ;
2012-01-19 15:18:34 +00:00
//day->setFirst(t3);
2014-04-17 05:52:25 +00:00
int zi = t3 / 1000L ;
2011-12-06 14:39:14 +00:00
session - > SetSessionID ( zi ) ;
date . fromTime_t ( zi ) ;
2014-04-17 05:52:25 +00:00
dont_update_date = true ;
2011-12-06 14:39:14 +00:00
ui - > dateEdit - > setDateTime ( date ) ;
2014-04-17 05:52:25 +00:00
dont_update_date = false ;
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
t1 = session - > last ( OXI_Pulse ) ;
t2 = session - > last ( OXI_SPO2 ) ;
t3 = qMax ( t1 , t2 ) ;
2011-12-05 15:03:16 +00:00
session - > set_last ( t3 ) ;
2012-01-19 15:18:34 +00:00
//day->setLast(t3);
2011-12-05 15:03:16 +00:00
CONTROL - > setVisible ( false ) ;
2011-12-06 14:39:14 +00:00
updateGraphs ( ) ;
2011-12-05 15:03:16 +00:00
f . close ( ) ;
ui - > saveButton - > setEnabled ( true ) ;
return true ;
}
bool Oximetry : : openSPORFile ( QString filename )
{
2013-09-09 15:56:02 +00:00
//GraphView->setEmptyText(tr("Please Wait"));
2011-12-20 11:12:52 +00:00
//GraphView->redraw();
2011-12-05 15:03:16 +00:00
QFile f ( filename ) ;
2014-04-17 05:52:25 +00:00
if ( ! f . open ( QFile : : ReadOnly ) ) { return false ; }
2011-12-05 15:03:16 +00:00
QByteArray data ;
2014-04-17 05:52:25 +00:00
data = f . readAll ( ) ;
long size = data . size ( ) ;
2011-12-05 15:03:16 +00:00
2014-04-17 05:52:25 +00:00
int pos = ( ( unsigned char ) data . at ( 1 ) < < 8 ) | ( unsigned char ) data . at ( 0 ) ;
2011-12-05 15:03:16 +00:00
char dchr [ 20 ] ;
2014-04-17 05:52:25 +00:00
int j = 0 ;
for ( int i = 0 ; i < 18 * 2 ; i + = 2 ) {
dchr [ j + + ] = data . at ( 8 + i ) ;
2011-12-05 15:03:16 +00:00
}
2014-04-17 05:52:25 +00:00
dchr [ j ] = 0 ;
2011-12-05 15:03:16 +00:00
QString dstr ( dchr ) ;
2014-04-17 05:52:25 +00:00
QDateTime date = QDateTime : : fromString ( dstr , " MM/dd/yy HH:mm:ss " ) ;
if ( date . date ( ) . year ( ) < 2000 ) { date = date . addYears ( 100 ) ; }
2011-12-05 15:03:16 +00:00
day - > getSessions ( ) . clear ( ) ;
oximeter - > createSession ( date ) ;
2014-04-17 05:52:25 +00:00
Session * session = oximeter - > getSession ( ) ;
2011-12-05 15:03:16 +00:00
day - > AddSession ( session ) ;
session - > set_first ( 0 ) ;
2014-04-17 05:52:25 +00:00
firstPulseUpdate = true ;
firstSPO2Update = true ;
secondPulseUpdate = true ;
secondSPO2Update = true ;
2011-12-05 15:03:16 +00:00
2014-04-17 05:52:25 +00:00
unsigned char o2 , pr ;
2012-01-05 12:12:42 +00:00
//quint16 pl;
2014-04-17 05:52:25 +00:00
qint64 tt = qint64 ( date . toTime_t ( ) ) * 1000L ;
2011-12-05 15:03:16 +00:00
2014-04-17 05:52:25 +00:00
for ( int i = pos ; i < size - 2 ; ) {
o2 = ( unsigned char ) ( data . at ( i + 1 ) ) ;
pr = ( unsigned char ) ( data . at ( i + 0 ) ) ;
oximeter - > addPulse ( tt , pr ) ;
oximeter - > addSpO2 ( tt , o2 ) ;
2012-01-05 12:12:42 +00:00
//pl=(unsigned char)(data.at(i+1));
2014-04-17 05:52:25 +00:00
i + = 2 ;
tt + = 1000 ;
2011-12-05 15:03:16 +00:00
}
2014-04-17 05:52:25 +00:00
qint64 t1 = session - > first ( OXI_Pulse ) ;
qint64 t2 = session - > first ( OXI_SPO2 ) ;
qint64 t3 = qMin ( t1 , t2 ) ;
2011-12-05 15:03:16 +00:00
session - > set_first ( t3 ) ;
2012-01-19 15:18:34 +00:00
//day->setFirst(t3);
2014-04-17 05:52:25 +00:00
int zi = t3 / 1000L ;
2011-12-06 14:39:14 +00:00
session - > SetSessionID ( zi ) ;
date . fromTime_t ( zi ) ;
2014-04-17 05:52:25 +00:00
dont_update_date = true ;
2011-12-06 14:39:14 +00:00
ui - > dateEdit - > setDateTime ( date ) ;
2014-04-17 05:52:25 +00:00
dont_update_date = false ;
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
t1 = session - > last ( OXI_Pulse ) ;
t2 = session - > last ( OXI_SPO2 ) ;
t3 = qMax ( t1 , t2 ) ;
2011-12-05 15:03:16 +00:00
session - > set_last ( t3 ) ;
2012-01-19 15:18:34 +00:00
//day->setLast(t3);
2011-12-05 15:03:16 +00:00
//PLETHY->setVisible(false);
CONTROL - > setVisible ( false ) ;
2011-12-06 14:39:14 +00:00
updateGraphs ( ) ;
2011-12-05 15:03:16 +00:00
f . close ( ) ;
ui - > saveButton - > setEnabled ( true ) ;
return true ;
}
void Oximetry : : on_openButton_clicked ( )
{
2011-12-05 15:16:39 +00:00
if ( oximeter - > getSession ( ) & & oximeter - > getSession ( ) - > IsChanged ( ) ) {
2014-05-17 05:04:40 +00:00
int res = askSaveSession ( ) ;
2014-04-17 05:52:25 +00:00
if ( res = = 0 ) {
2011-12-05 15:16:39 +00:00
on_saveButton_clicked ( ) ;
return ;
2014-04-17 05:52:25 +00:00
} else if ( res = = 2 ) {
2011-12-05 15:16:39 +00:00
return ;
}
} // else it's already saved.
2014-04-17 05:52:25 +00:00
QString dir = " " ;
QFileDialog fd ( this , tr ( " Select an oximetry file " ) , dir , tr ( " Oximetry Files (*.spo *.spoR) " ) ) ;
2011-12-05 15:03:16 +00:00
fd . setAcceptMode ( QFileDialog : : AcceptOpen ) ;
fd . setFileMode ( QFileDialog : : ExistingFile ) ;
2014-04-17 05:52:25 +00:00
if ( fd . exec ( ) ! = QFileDialog : : Accepted ) { return ; }
QStringList filenames = fd . selectedFiles ( ) ;
if ( filenames . size ( ) > 1 ) {
2011-12-05 15:03:16 +00:00
qDebug ( ) < < " Can only open one oximetry file at a time " ;
}
2014-04-17 05:52:25 +00:00
QString filename = filenames [ 0 ] ;
bool r = false ;
if ( filename . toLower ( ) . endsWith ( " .spo " ) ) { r = openSPOFile ( filename ) ; }
else if ( filename . toLower ( ) . endsWith ( " .spor " ) ) { r = openSPORFile ( filename ) ; }
2011-12-05 15:03:16 +00:00
if ( ! r ) {
2014-04-17 05:52:25 +00:00
mainwin - > Notify ( tr ( " Couldn't open oximetry file \" " ) + filename + " \" . " ) ;
2011-12-05 15:03:16 +00:00
}
2014-04-17 05:52:25 +00:00
2011-12-05 15:03:16 +00:00
qDebug ( ) < < " opening " < < filename ;
}
2011-12-06 14:39:14 +00:00
void Oximetry : : on_dateEdit_dateTimeChanged ( const QDateTime & date )
{
2014-04-17 05:52:25 +00:00
Session * session = oximeter - > getSession ( ) ;
if ( ! session ) {
2011-12-06 14:39:14 +00:00
return ;
2014-04-17 05:52:25 +00:00
}
if ( dont_update_date ) {
2011-12-06 14:39:14 +00:00
return ;
2014-04-17 05:52:25 +00:00
}
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
qint64 first = session - > first ( ) ;
2011-12-08 11:41:44 +00:00
//qint64 last=session->last();
2014-04-17 05:52:25 +00:00
qint64 tt = qint64 ( date . toTime_t ( ) ) * 1000L ;
qint64 offset = tt - first ;
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
if ( offset ! = 0 ) {
2011-12-06 14:39:14 +00:00
session - > SetChanged ( true ) ;
ui - > saveButton - > setEnabled ( true ) ;
}
session - > offsetSession ( offset ) ;
updateGraphs ( ) ;
}
2014-05-17 05:04:40 +00:00
int Oximetry : : askSaveSession ( )
{
return QMessageBox : : question ( this , STR_MessageBox_Question ,
tr ( " Current oximetry session still has unsaved data in it. " ) + " \n \n " +
tr ( " Would you like to save it first? " ) ,
STR_MessageBox_Save , STR_MessageBox_Destroy , STR_MessageBox_Cancel , 0 , 2 ) ;
}
2014-04-17 05:52:25 +00:00
void Oximetry : : openSession ( Session * session )
2011-12-06 14:39:14 +00:00
{
if ( oximeter - > getSession ( ) & & oximeter - > getSession ( ) - > IsChanged ( ) ) {
2014-05-17 05:04:40 +00:00
int res = askSaveSession ( ) ;
2014-04-17 05:52:25 +00:00
if ( res = = 0 ) {
2011-12-06 14:39:14 +00:00
on_saveButton_clicked ( ) ;
return ;
2014-04-17 05:52:25 +00:00
} else if ( res = = 2 ) {
2011-12-06 14:39:14 +00:00
return ;
}
} // else it's already saved.
day - > getSessions ( ) . clear ( ) ;
day - > AddSession ( session ) ;
oximeter - > setSession ( session ) ;
2014-04-17 05:52:25 +00:00
saved_starttime = session - > first ( ) ;
2011-12-06 14:39:14 +00:00
oximeter - > compactAll ( ) ;
2014-04-17 05:52:25 +00:00
QDateTime date = QDateTime : : fromTime_t ( saved_starttime / 1000L ) ;
dont_update_date = true ;
2011-12-06 14:39:14 +00:00
ui - > dateEdit - > setDateTime ( date ) ;
2014-04-17 05:52:25 +00:00
dont_update_date = false ;
2011-12-06 14:39:14 +00:00
updateGraphs ( ) ;
}
void Oximetry : : updateGraphs ( )
{
2014-04-17 05:52:25 +00:00
Session * session = oximeter - > getSession ( ) ;
2011-12-06 14:39:14 +00:00
2014-04-17 05:52:25 +00:00
if ( ! session ) { return ; }
qint64 first = session - > first ( ) ;
qint64 last = session - > last ( ) ;
2011-12-06 14:39:14 +00:00
2011-12-17 14:38:15 +00:00
ui - > pulseLCD - > display ( session - > Min ( OXI_Pulse ) ) ;
ui - > spo2LCD - > display ( session - > Min ( OXI_SPO2 ) ) ;
2011-12-06 14:39:14 +00:00
2011-12-17 14:38:15 +00:00
pulse - > setMinY ( session - > Min ( OXI_Pulse ) ) ;
pulse - > setMaxY ( session - > Max ( OXI_Pulse ) ) ;
spo2 - > setMinY ( session - > Min ( OXI_SPO2 ) ) ;
spo2 - > setMaxY ( session - > Max ( OXI_SPO2 ) ) ;
2011-12-06 14:39:14 +00:00
PULSE - > setRecMinY ( 60 ) ;
PULSE - > setRecMaxY ( 100 ) ;
SPO2 - > setRecMinY ( 90 ) ;
SPO2 - > setRecMaxY ( 100 ) ;
2012-01-19 15:18:34 +00:00
//day->setFirst(first);
//day->setLast(last);
2011-12-17 14:38:15 +00:00
pulse - > setMinY ( session - > Min ( OXI_Pulse ) ) ;
pulse - > setMaxY ( session - > Max ( OXI_Pulse ) ) ;
spo2 - > setMinY ( session - > Min ( OXI_SPO2 ) ) ;
spo2 - > setMaxY ( session - > Max ( OXI_SPO2 ) ) ;
2011-12-06 14:39:14 +00:00
PULSE - > setRecMinY ( 60 ) ;
PULSE - > setRecMaxY ( 100 ) ;
SPO2 - > setRecMinY ( 90 ) ;
SPO2 - > setRecMaxY ( 100 ) ;
plethy - > setMinX ( first ) ;
pulse - > setMinX ( first ) ;
spo2 - > setMinX ( first ) ;
PLETHY - > SetMinX ( first ) ;
CONTROL - > SetMinX ( first ) ;
PULSE - > SetMinX ( first ) ;
SPO2 - > SetMinX ( first ) ;
plethy - > setMaxX ( last ) ;
pulse - > setMaxX ( last ) ;
spo2 - > setMaxX ( last ) ;
PLETHY - > SetMaxX ( last ) ;
CONTROL - > SetMaxX ( last ) ;
PULSE - > SetMaxX ( last ) ;
SPO2 - > SetMaxX ( last ) ;
PULSE - > setDay ( day ) ;
SPO2 - > setDay ( day ) ;
2014-04-17 05:52:25 +00:00
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
( * GraphView ) [ i ] - > SetXBounds ( first , last ) ;
2011-12-06 14:39:14 +00:00
}
2014-04-17 05:52:25 +00:00
2011-12-06 14:39:14 +00:00
{
2014-04-17 05:52:25 +00:00
int len = ( last - first ) / 1000L ;
int h = len / 3600 ;
int m = ( len / 60 ) % 60 ;
int s = ( len % 60 ) ;
if ( qstatus2 ) { qstatus2 - > setText ( QString ( ) . sprintf ( " %02i:%02i:%02i " , h , m , s ) ) ; }
2011-12-06 14:39:14 +00:00
}
2014-04-17 05:52:25 +00:00
2011-12-06 14:39:14 +00:00
GraphView - > updateScale ( ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-12-06 14:39:14 +00:00
}
void Oximetry : : on_resetTimeButton_clicked ( ) //revert to original session time
{
if ( oximeter - > getSession ( ) ) {
//qint64 tt=ui->dateEdit->dateTime().toTime_t()*1000;
//qint64 offset=saved_starttime-tt;
//oximeter->getSession()->offsetSession(offset);
2014-04-17 05:52:25 +00:00
dont_update_date = false ;
2011-12-06 14:39:14 +00:00
//ui->dateEdit->setDateTime(QDateTime::fromTime_t(saved_starttime/1000L));
2014-04-17 05:52:25 +00:00
ui - > dateEdit - > setDateTime ( QDateTime : : fromTime_t ( saved_starttime / 1000L ) ) ;
dont_update_date = false ;
2011-12-06 14:39:14 +00:00
}
}