Commit 63ce7336 authored by Stefan Gerlach's avatar Stefan Gerlach

Make Qt5SerialPort optional

parent 7b7d1f98
......@@ -28,7 +28,6 @@ find_package(Qt5 ${QT_MIN_VERSION} NO_MODULE REQUIRED COMPONENTS
Svg
Widgets
Test
SerialPort
)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
......@@ -187,6 +186,7 @@ option(ENABLE_LIBORIGIN "Build with liborigin support" ON)
option(ENABLE_ROOT "Build with ROOT (CERN) support" ON)
option(ENABLE_TESTS "Build with tests" ON)
option(ENABLE_MQTT "Build with MQTT support" ON)
option(ENABLE_QTSERIALPORT "Build with QtSerialPort support" ON)
### OS macros ####################################
IF (WIN32)
......@@ -279,16 +279,16 @@ ENDIF ()
### NETCDF (optional) #############################
IF (ENABLE_NETCDF)
FIND_PACKAGE(netCDF)
SET_PACKAGE_PROPERTIES(netCDF PROPERTIES
DESCRIPTION "Interfaces for array-oriented data access"
URL "https://www.unidata.ucar.edu/software/netcdf/"
)
IF (netCDF_FOUND)
add_definitions (-DHAVE_NETCDF)
ELSE ()
MESSAGE (STATUS "Network Common Data Format (NetCDF) Library NOT FOUND")
ENDIF ()
FIND_PACKAGE(netCDF)
SET_PACKAGE_PROPERTIES(netCDF PROPERTIES
DESCRIPTION "Interfaces for array-oriented data access"
URL "https://www.unidata.ucar.edu/software/netcdf/"
)
IF (netCDF_FOUND)
add_definitions (-DHAVE_NETCDF)
ELSE ()
MESSAGE (STATUS "Network Common Data Format (NetCDF) Library NOT FOUND")
ENDIF ()
ELSE ()
MESSAGE (STATUS "Network Common Data Format (NetCDF) Library DISABLED")
ENDIF ()
......@@ -297,63 +297,82 @@ ENDIF ()
IF (ENABLE_MQTT)
# ATTENTION: unit test uses qWaitFor() which needs Qt >= 5.10
# avoid warning for the moment using QUIET
find_package(Qt5Mqtt ${QT_MIN_VERSION} QUIET NO_MODULE)
IF (Qt5Mqtt_FOUND)
MESSAGE (STATUS "Found MQTT Library")
add_definitions (-DHAVE_MQTT)
find_package(Qt5Mqtt ${QT_MIN_VERSION} NO_MODULE)
IF (Qt5Mqtt_FOUND)
MESSAGE (STATUS "Found MQTT Library")
add_definitions (-DHAVE_MQTT)
ELSE ()
MESSAGE (STATUS "MQTT Library NOT FOUND")
ENDIF ()
ELSE ()
MESSAGE (STATUS "MQTT Library NOT FOUND")
MESSAGE (STATUS "MQTT Library DISABLED")
ENDIF ()
### QtSerialPort (optional) ###############################
IF (ENABLE_QTSERIALPORT)
find_package(Qt5SerialPort ${QT_MIN_VERSION} NO_MODULE)
SET_PACKAGE_PROPERTIES (Qt5SerialPort PROPERTIES
DESCRIPTION "Qt Serial Port library"
URL "https://doc.qt.io/qt-5/qtserialport-index.html"
PURPOSE "Support basic functionality of serial ports.")
IF (Qt5SerialPort_FOUND)
MESSAGE (STATUS "Found Qt5SerialPort Library")
add_definitions (-DHAVE_QTSERIALPORT)
ELSE ()
MESSAGE (STATUS "Qt5SerialPort Library NOT FOUND")
ENDIF ()
ELSE ()
MESSAGE (STATUS "MQTT Library DISABLED")
MESSAGE (STATUS "Qt5SerialPort Library DISABLED")
ENDIF ()
### FITS (optional) ###############################
IF (ENABLE_FITS)
FIND_PACKAGE (CFitsio)
SET_PACKAGE_PROPERTIES (CFitsio PROPERTIES
DESCRIPTION "FITS IO Library"
URL "https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html"
PURPOSE "Support for the FITS (Flexible Image Transport System) data format.")
IF (CFITSIO_FOUND)
add_definitions (-DHAVE_FITS)
include_directories (${CFITSIO_INCLUDE_DIR})
ELSE ()
MESSAGE (STATUS "Flexible Image Transport System Data Format (FITS) Library NOT FOUND")
ENDIF ()
FIND_PACKAGE (CFitsio)
SET_PACKAGE_PROPERTIES (CFitsio PROPERTIES
DESCRIPTION "FITS IO Library"
URL "https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html"
PURPOSE "Support for the FITS (Flexible Image Transport System) data format.")
IF (CFITSIO_FOUND)
add_definitions (-DHAVE_FITS)
include_directories (${CFITSIO_INCLUDE_DIR})
ELSE ()
MESSAGE (STATUS "Flexible Image Transport System Data Format (FITS) Library NOT FOUND")
ENDIF ()
ELSE ()
MESSAGE (STATUS "Flexible Image Transport System Data Format (FITS) Library DISABLED")
ENDIF ()
### LIBCERF (optional) #############################
IF (ENABLE_LIBCERF)
FIND_PACKAGE (LIBCERF)
IF (LIBCERF_FOUND)
add_definitions (-DHAVE_LIBCERF)
ELSE ()
MESSAGE (STATUS "libcerf library NOT FOUND")
ENDIF ()
FIND_PACKAGE (LIBCERF)
IF (LIBCERF_FOUND)
add_definitions (-DHAVE_LIBCERF)
ELSE ()
MESSAGE (STATUS "libcerf library NOT FOUND")
ENDIF ()
ELSE ()
MESSAGE (STATUS "libcerf library DISABLED")
ENDIF ()
### ROOT (optional) #############################
IF (ENABLE_ROOT)
FIND_PACKAGE(ZLIB)
SET_PACKAGE_PROPERTIES (ZLIB PROPERTIES
DESCRIPTION "General purpose compression library"
URL "https://www.zlib.net/"
)
FIND_PACKAGE(LZ4)
IF (ZLIB_FOUND AND LZ4_FOUND)
MESSAGE (STATUS "Found ZIP libraries ZLIB and LZ4 (needed for ROOT importer)")
add_definitions (-DHAVE_ZIP)
ELSE ()
MESSAGE (STATUS "ZIP libraries ZLIB and LZ4 (needed for ROOT importer) NOT FOUND")
ENDIF ()
FIND_PACKAGE(ZLIB)
SET_PACKAGE_PROPERTIES (ZLIB PROPERTIES
DESCRIPTION "General purpose compression library"
URL "https://www.zlib.net/"
)
FIND_PACKAGE(LZ4)
IF (ZLIB_FOUND AND LZ4_FOUND)
MESSAGE (STATUS "Found ZIP libraries ZLIB and LZ4 (needed for ROOT importer)")
add_definitions (-DHAVE_ZIP)
ELSE ()
MESSAGE (STATUS "ZIP libraries ZLIB and LZ4 (needed for ROOT importer) NOT FOUND")
ENDIF ()
ELSE ()
MESSAGE (STATUS "ROOT (CERN) importer DISABLED")
ENDIF ()
#################################################
#################################################
include(CheckFunctionExists)
......
......@@ -18,6 +18,7 @@ optional
* libcerf version 1.0 or higher to support complex error and related functions (including the devel-package, libcerf-devel or similar)
* Cantor version 19.12 or higher (including the devel package, cantor-devel or similar)
* ZLIB and LZ4 to support ROOT (CERN) TH1 histograms (including the devel package, zlib-devel and liblz4-devel or similar)
* Qt SerialPort to support serial port functionality
* Qt MQTT module (https://github.com/qt/qtmqtt) to support reading and plotting of data from MQTT brokers
......@@ -42,6 +43,7 @@ To compile LabPlot without optional dependencies even if they are present on the
-DENABLE_LIBCERF=OFF
-DENABLE_CANTOR=OFF
-DENABLE_MQTT=OFF
-DENABLE_QTSERIALPORT=OFF
-DENABLE_LIBORIGIN=OFF
Note, by switching off these libraries the feature set of LabPlot will be reduced.
......
......@@ -47,9 +47,11 @@ Copyright : (C) 2018 Stefan Gerlach (stefan.gerlach@uni.kn)
#include <QMessageBox>
#include <QProcess>
#include <QTimer>
#include <QSerialPortInfo>
#include <QTcpSocket>
#include <QUdpSocket>
#ifdef HAVE_QTSERIALPORT
#include <QSerialPortInfo>
#endif
#include <KLocalizedString>
......@@ -76,7 +78,9 @@ LiveDataSource::~LiveDataSource() {
delete m_fileSystemWatcher;
delete m_localSocket;
delete m_tcpSocket;
#ifdef HAVE_QTSERIALPORT
delete m_serialPort;
#endif
}
void LiveDataSource::initActions() {
......@@ -101,6 +105,7 @@ QStringList LiveDataSource::availablePorts() {
QStringList ports;
// qDebug() << "available ports count:" << QSerialPortInfo::availablePorts().size();
#ifdef HAVE_QTSERIALPORT
for (const QSerialPortInfo& sp : QSerialPortInfo::availablePorts()) {
ports.append(sp.portName());
......@@ -109,6 +114,7 @@ QStringList LiveDataSource::availablePorts() {
}
// For Testing:
// ports.append("/dev/pts/26");
#endif
return ports;
}
......@@ -119,8 +125,10 @@ QStringList LiveDataSource::availablePorts() {
QStringList LiveDataSource::supportedBaudRates() {
QStringList baudRates;
#ifdef HAVE_QTSERIALPORT
for (const auto& baud : QSerialPortInfo::standardBaudRates())
baudRates.append(QString::number(baud));
#endif
return baudRates;
}
......@@ -509,6 +517,7 @@ void LiveDataSource::read() {
break;
case SourceType::SerialPort:
#ifdef HAVE_QTSERIALPORT
m_serialPort = new QSerialPort(this);
m_device = m_serialPort;
DEBUG(" Serial: " << STDSTRING(m_serialPortName) << ", " << m_baudRate);
......@@ -520,6 +529,7 @@ void LiveDataSource::read() {
if (m_updateType == UpdateType::NewData)
connect(m_serialPort, &QSerialPort::readyRead, this, &LiveDataSource::readyRead);
connect(m_serialPort, static_cast<void (QSerialPort::*) (QSerialPort::SerialPortError)>(&QSerialPort::error), this, &LiveDataSource::serialPortError);
#endif
break;
case SourceType::MQTT:
break;
......@@ -585,10 +595,12 @@ void LiveDataSource::read() {
break;
case SourceType::SerialPort:
DEBUG(" Reading from serial port");
#ifdef HAVE_QTSERIALPORT
// reading data here
if (m_fileType == AbstractFileFilter::FileType::Ascii)
static_cast<AsciiFilter*>(m_filter)->readFromLiveDeviceNotFile(*m_device, this);
#endif
break;
case SourceType::MQTT:
break;
......@@ -664,6 +676,7 @@ void LiveDataSource::tcpSocketError(QAbstractSocket::SocketError socketError) {
}*/
}
#ifdef HAVE_QTSERIALPORT
void LiveDataSource::serialPortError(QSerialPort::SerialPortError serialPortError) {
switch (serialPortError) {
case QSerialPort::DeviceNotFoundError:
......@@ -704,6 +717,7 @@ void LiveDataSource::serialPortError(QSerialPort::SerialPortError serialPortErro
break;
}
}
#endif
void LiveDataSource::plotData() {
auto* dlg = new PlotDataDialog(this);
......
......@@ -34,10 +34,12 @@
#include "backend/matrix/Matrix.h"
#include <QLocalSocket>
#include <QSerialPort>
#include <QTimer>
#include <QVector>
#include <QMap>
#ifdef HAVE_QTSERIALPORT
#include <QSerialPort>
#endif
class QString;
class AbstractFileFilter;
......@@ -187,7 +189,9 @@ private:
QLocalSocket* m_localSocket{nullptr};
QTcpSocket* m_tcpSocket{nullptr};
QUdpSocket* m_udpSocket{nullptr};
#ifdef HAVE_QTSERIALPORT
QSerialPort* m_serialPort{nullptr};
#endif
QIODevice* m_device{nullptr};
QAction* m_plotDataAction{nullptr};
......@@ -201,7 +205,9 @@ private slots:
void localSocketError(QLocalSocket::LocalSocketError);
void tcpSocketError(QAbstractSocket::SocketError);
#ifdef HAVE_QTSERIALPORT
void serialPortError(QSerialPort::SerialPortError);
#endif
};
#endif
......@@ -476,6 +476,7 @@ void ImportFileDialog::checkOkButton() {
break;
}
case LiveDataSource::SourceType::SerialPort: {
#ifdef HAVE_QTSERIALPORT
const QString sPort = m_importFileWidget->serialPort();
const int baudRate = m_importFileWidget->baudRate();
......@@ -500,8 +501,9 @@ void ImportFileDialog::checkOkButton() {
okButton->setEnabled(false);
okButton->setToolTip(i18n("Serial port number is missing."));
}
#endif
break;
}
}
case LiveDataSource::SourceType::MQTT: {
#ifdef HAVE_MQTT
const bool enable = m_importFileWidget->isMqttValid();
......
......@@ -1368,6 +1368,7 @@ void ImportFileWidget::refreshPreview() {
break;
}
case LiveDataSource::SourceType::SerialPort: {
#ifdef HAVE_QTSERIALPORT
QSerialPort sPort{this};
DEBUG(" Port: " << STDSTRING(serialPort()) << ", Settings: " << baudRate() << ',' << sPort.dataBits()
<< ',' << sPort.parity() << ',' << sPort.stopBits());
......@@ -1383,7 +1384,7 @@ void ImportFileWidget::refreshPreview() {
sPort.close();
} else
DEBUG(" ERROR: failed to open serial port. error: " << sPort.error());
#endif
break;
}
case LiveDataSource::SourceType::MQTT: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment