From 7a85f9784c1b729bf037fa9dc8cc15d397d79ea9 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Thu, 4 Jun 2020 14:32:03 -0400 Subject: [PATCH] Add initial device connection classes to eventually support recording/playback. This initial commit is designed to change as little existing code as possible. Once regression tests are in place that can play back previously recorded data, we can move on to more significant changes. --- oscar/SleepLib/deviceconnection.cpp | 28 +++++++++++++++++++++ oscar/SleepLib/deviceconnection.h | 38 +++++++++++++++++++++++++++++ oscar/SleepLib/serialoximeter.cpp | 7 +++--- oscar/SleepLib/serialoximeter.h | 7 +++--- oscar/oscar.pro | 2 ++ 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 oscar/SleepLib/deviceconnection.cpp create mode 100644 oscar/SleepLib/deviceconnection.h diff --git a/oscar/SleepLib/deviceconnection.cpp b/oscar/SleepLib/deviceconnection.cpp new file mode 100644 index 00000000..23f6c5bb --- /dev/null +++ b/oscar/SleepLib/deviceconnection.cpp @@ -0,0 +1,28 @@ +/* Device Connection Class Implementation + * + * Copyright (c) 2020 The OSCAR Team + * + * 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 source code + * for more details. */ + +#include "deviceconnection.h" + +SerialPortInfo::SerialPortInfo(const QSerialPortInfo & other) + : QSerialPortInfo(other) +{ +} + +SerialPortInfo::SerialPortInfo(const SerialPortInfo & other) + : QSerialPortInfo(dynamic_cast(other)) +{ +} + +QList SerialPortInfo::availablePorts() +{ + QList out; + for (auto & info : QSerialPortInfo::availablePorts()) { + out.append(SerialPortInfo(info)); + } + return out; +} diff --git a/oscar/SleepLib/deviceconnection.h b/oscar/SleepLib/deviceconnection.h new file mode 100644 index 00000000..ce424a56 --- /dev/null +++ b/oscar/SleepLib/deviceconnection.h @@ -0,0 +1,38 @@ +/* Device Connection Class Header + * + * Copyright (c) 2020 The OSCAR Team + * + * 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 source code + * for more details. */ + +#ifndef DEVICECONNECTION_H +#define DEVICECONNECTION_H + +// TODO: This file will eventually abstract serial port or bluetooth (or other) +// connections to devices. For now it just supports serial ports. + +#include +#include + +// TODO: This class may eventually be internal to a DeviceConnection class, +// but for now it is used to provide support for recording and playback of +// serial port connections before refactoring. +class SerialPort : public QSerialPort +{ +}; + +// TODO: This class's functionality will eventually be internal to a +// DeviceConnection class, but for now it is needed to support recording +// and playback of serial port scanning before refactoring. +class SerialPortInfo : public QSerialPortInfo +{ +public: + static QList availablePorts(); + SerialPortInfo(const SerialPortInfo & other); + +protected: + SerialPortInfo(const QSerialPortInfo & other); +}; + +#endif // DEVICECONNECTION_H diff --git a/oscar/SleepLib/serialoximeter.cpp b/oscar/SleepLib/serialoximeter.cpp index 3e98e4d4..0b1acb64 100644 --- a/oscar/SleepLib/serialoximeter.cpp +++ b/oscar/SleepLib/serialoximeter.cpp @@ -1,13 +1,12 @@ /* SleepLib Machine Loader Class Implementation * * Copyright (c) 2011-2018 Mark Watkins + * Copyright (c) 2020 The OSCAR Team * * 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 source code * for more details. */ -#include - #include "serialoximeter.h" // Possibly need to replan this to include oximetry @@ -31,11 +30,11 @@ bool SerialOximeter::scanDevice(QString keyword, quint16 vendor_id, quint16 prod QStringList ports; qDebug() << "seroxi - Scanning for USB Serial devices"; - QList list=QSerialPortInfo::availablePorts(); + QList list=SerialPortInfo::availablePorts(); // How does the mac detect this as a SPO2 device? for (int i=0;iportName(); QString desc = info->description(); diff --git a/oscar/SleepLib/serialoximeter.h b/oscar/SleepLib/serialoximeter.h index 5a018269..e8a8e19c 100644 --- a/oscar/SleepLib/serialoximeter.h +++ b/oscar/SleepLib/serialoximeter.h @@ -1,6 +1,7 @@ -/* SleepLib MachineLoader Base Class Header +/* SleepLib MachineLoader Base Class Header * * Copyright (C) 2011-2018 Mark Watkins + * Copyright (c) 2020 The OSCAR Team * * 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 source code @@ -10,7 +11,7 @@ #define SERIALOXIMETER_H #include -#include +#include "SleepLib/deviceconnection.h" #include "SleepLib/machine_loader.h" @@ -126,7 +127,7 @@ protected: virtual void requestData() {} QString port; - QSerialPort serial; + SerialPort serial; QTimer startTimer; QTimer resetTimer; diff --git a/oscar/oscar.pro b/oscar/oscar.pro index be134f98..c0c6ea9d 100644 --- a/oscar/oscar.pro +++ b/oscar/oscar.pro @@ -302,6 +302,7 @@ SOURCES += \ translation.cpp \ statistics.cpp \ oximeterimport.cpp \ + SleepLib/deviceconnection.cpp \ SleepLib/serialoximeter.cpp \ SleepLib/loader_plugins/md300w1_loader.cpp \ Graphs/gSessionTimesChart.cpp \ @@ -381,6 +382,7 @@ HEADERS += \ translation.h \ statistics.h \ oximeterimport.h \ + SleepLib/deviceconnection.h \ SleepLib/serialoximeter.h \ SleepLib/loader_plugins/md300w1_loader.h \ Graphs/gSessionTimesChart.h \