├── .gitignore ├── plotWindows ├── test.cpp ├── orientation_3d │ ├── resources │ │ ├── cube.png │ │ ├── textures.qrc │ │ ├── shaders.qrc │ │ ├── fshader.glsl │ │ └── vshader.glsl │ ├── orientationwindow.h │ ├── geometryengine.h │ ├── orientationwidget.h │ ├── orientationwidget.cpp │ ├── geometryengine.cpp │ └── orientationwindow.cpp ├── plotWindows.h ├── line │ ├── lineplot.h │ └── lineplot.cpp └── scatter │ ├── scatterwindow.h │ └── scatterwindow.cpp ├── doc ├── math.PNG ├── input.PNG ├── dashboard.PNG └── comparison.PNG ├── res ├── icon.png └── icon.qrc ├── config.ini ├── dataSources ├── dataSources.h ├── serialAdapter │ ├── serialadapter.h │ └── serialadapter.cpp └── networkAdapter │ ├── networkadapter.h │ └── networkadapter.cpp ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── helperObjects ├── channel │ ├── channel.h │ └── channel.cpp ├── graphHeaderWidget │ ├── graphheaderwidget.h │ └── graphheaderwidget.cpp ├── mathComponent │ ├── mathchannelcomponent.h │ └── mathchannelcomponent.cpp └── dataMultiplexer │ ├── mathchannel.h │ ├── graphclient.h │ ├── datamultiplexer.h │ └── datamultiplexer.cpp ├── main.cpp ├── datadashboard.pro ├── .drone.yml ├── .drone-github.yml ├── mainwindow.h ├── README.md ├── mainwindow.cpp └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | -------------------------------------------------------------------------------- /plotWindows/test.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/math.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vedranMv/dataDashboard/HEAD/doc/math.PNG -------------------------------------------------------------------------------- /res/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vedranMv/dataDashboard/HEAD/res/icon.png -------------------------------------------------------------------------------- /doc/input.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vedranMv/dataDashboard/HEAD/doc/input.PNG -------------------------------------------------------------------------------- /doc/dashboard.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vedranMv/dataDashboard/HEAD/doc/dashboard.PNG -------------------------------------------------------------------------------- /doc/comparison.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vedranMv/dataDashboard/HEAD/doc/comparison.PNG -------------------------------------------------------------------------------- /res/icon.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/resources/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vedranMv/dataDashboard/HEAD/plotWindows/orientation_3d/resources/cube.png -------------------------------------------------------------------------------- /plotWindows/orientation_3d/resources/textures.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | cube.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/resources/shaders.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | vshader.glsl 4 | fshader.glsl 5 | 6 | 7 | -------------------------------------------------------------------------------- /config.ini: -------------------------------------------------------------------------------- 1 | [port] 2 | name= 3 | baud= 4 | 5 | [channel] 6 | startChar= 7 | separator= 8 | endChar= 9 | 10 | [appLog] 11 | index=2 12 | maxIndex=3 13 | 14 | [ui] 15 | startPage=0 16 | -------------------------------------------------------------------------------- /dataSources/dataSources.h: -------------------------------------------------------------------------------- 1 | #ifndef DATASOURCES_H 2 | #define DATASOURCES_H 3 | 4 | #include "networkAdapter/networkadapter.h" 5 | #include "serialAdapter/serialadapter.h" 6 | 7 | #endif // DATASOURCES_H 8 | -------------------------------------------------------------------------------- /plotWindows/plotWindows.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOTWINDOWS_H 2 | #define PLOTWINDOWS_H 3 | 4 | #include "line/lineplot.h" 5 | #include "orientation_3d/orientationwindow.h" 6 | #include "scatter/scatterwindow.h" 7 | 8 | #endif // PLOTWINDOWS_H 9 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/resources/fshader.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | // Set default precision to medium 3 | precision mediump int; 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D texture; 8 | 9 | varying vec2 v_texcoord; 10 | 11 | //! [0] 12 | void main() 13 | { 14 | // Set fragment color from texture 15 | gl_FragColor = texture2D(texture, v_texcoord); 16 | } 17 | //! [0] 18 | 19 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/resources/vshader.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | // Set default precision to medium 3 | precision mediump int; 4 | precision mediump float; 5 | #endif 6 | 7 | uniform mat4 mvp_matrix; 8 | 9 | attribute vec4 a_position; 10 | attribute vec2 a_texcoord; 11 | 12 | varying vec2 v_texcoord; 13 | 14 | //! [0] 15 | void main() 16 | { 17 | // Calculate vertex position in screen space 18 | gl_Position = mvp_matrix * a_position; 19 | 20 | // Pass texture coordinate to fragment shader 21 | // Value will be automatically interpolated to fragments inside polygon faces 22 | v_texcoord = a_texcoord; 23 | } 24 | //! [0] 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /helperObjects/channel/channel.h: -------------------------------------------------------------------------------- 1 | #ifndef CHANNEL_H 2 | #define CHANNEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /** 10 | * @brief The Channel class 11 | * Used to dynamically construct input channels and assign them a label 12 | */ 13 | class Channel 14 | { 15 | public: 16 | Channel(QString label, int id, QString name); 17 | void Update(QString label, int id, QString name); 18 | 19 | QString GetLabel(); 20 | int GetId(); 21 | QString GetName(); 22 | 23 | ~Channel(); 24 | 25 | QLabel *chLabel; 26 | int channelId; 27 | QLineEdit *channelName; 28 | }; 29 | 30 | #endif // CHANNEL_H 31 | -------------------------------------------------------------------------------- /dataSources/serialAdapter/serialadapter.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIALADAPTER_H 2 | #define SERIALADAPTER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "helperObjects/dataMultiplexer/datamultiplexer.h" 9 | 10 | 11 | class SerialAdapter : public QThread 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit SerialAdapter(QObject *parent = nullptr); 17 | ~SerialAdapter(); 18 | 19 | void StartListening(); 20 | void StopListening(); 21 | 22 | signals: 23 | void logLine(const QString &s); 24 | 25 | public slots: 26 | void UpdatePort(const QString &portName, const QString &portBaud); 27 | 28 | private: 29 | void run() override; 30 | 31 | QString _portName; 32 | QString _portBaud; 33 | bool _threadQuit = false; 34 | bool _portUpdated = false; 35 | DataMultiplexer* _mux; 36 | }; 37 | 38 | #endif // SERIALADAPTER_H 39 | -------------------------------------------------------------------------------- /helperObjects/channel/channel.cpp: -------------------------------------------------------------------------------- 1 | #include "channel.h" 2 | 3 | Channel::Channel(QString label, int id, QString name) 4 | { 5 | chLabel = new QLabel(label); 6 | channelName = new QLineEdit(); 7 | 8 | channelId = id; 9 | channelName->setText(name); 10 | } 11 | 12 | /** 13 | * @brief Update channel components 14 | * @param label new label for the channel 15 | * @param id new channel id 16 | * @param name new channel name 17 | */ 18 | void Channel::Update(QString label, int id, QString name) 19 | { 20 | chLabel->setText(label); 21 | channelId = id; 22 | channelName->setText(name); 23 | } 24 | 25 | QString Channel::GetLabel() 26 | { 27 | return chLabel->text(); 28 | } 29 | 30 | int Channel::GetId() 31 | { 32 | return channelId; 33 | } 34 | 35 | QString Channel::GetName() 36 | { 37 | return channelName->text(); 38 | } 39 | 40 | Channel::~Channel() 41 | { 42 | delete chLabel; 43 | delete channelName; 44 | } 45 | -------------------------------------------------------------------------------- /dataSources/networkAdapter/networkadapter.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORKADAPTER_H 2 | #define NETWORKADAPTER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "helperObjects/dataMultiplexer/datamultiplexer.h" 9 | 10 | 11 | class NetworkAdapter : public QThread 12 | { 13 | Q_OBJECT 14 | public: 15 | NetworkAdapter(); 16 | ~NetworkAdapter(); 17 | 18 | void SetNetPort(uint16_t port); 19 | uint16_t GetPort(); 20 | bool StartListening(); 21 | void StopListening(); 22 | 23 | signals: 24 | void logLine(const QString &s); 25 | 26 | private slots: 27 | void _onNewConnection(); 28 | void onSocketStateChanged(QAbstractSocket::SocketState socketState); 29 | void onReadyRead(); 30 | 31 | private: 32 | 33 | bool _threadQuit; 34 | QTcpServer *_tcpServer; 35 | QTcpSocket *_clientSocket; 36 | 37 | uint16_t _port; 38 | DataMultiplexer* _mux; 39 | }; 40 | 41 | #endif // NETWORKADAPTER_H 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG] Issue Title" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Steps to Reproduce** 14 | To reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Environment (please complete the following information):** 27 | - OS and version: [e.g. Ubuntu 18.04/Windows 10] 28 | - Data dashboard version: [e.g. 0.2] 29 | - Using pre-compiled version from Releases? [Yes/No] 30 | - If possible, please attach latest log file (datadashboard_runX.log) and config file (it helps recreate the environment) 31 | 32 | **Additional context** 33 | Add any other context about the problem here. 34 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/orientationwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef ORIENTATIONWINDOW_H 2 | #define ORIENTATIONWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "plotWindows/orientation_3d/orientationwidget.h" 8 | 9 | 10 | class OrientationWindow : public QMdiSubWindow 11 | { 12 | Q_OBJECT 13 | public: 14 | OrientationWindow(QWidget *parent, QString objName=""); 15 | ~OrientationWindow(); 16 | 17 | void ReceiveData(double *data, uint8_t n); 18 | 19 | signals: 20 | void logLine(const QString &line); 21 | 22 | public slots: 23 | void UpdateInputChannels(uint8_t *inChannels); 24 | void InputTypeUpdated(bool rpySelected); 25 | 26 | private: 27 | void _ConstructUI(); 28 | QWidget *_contWind; 29 | QVBoxLayout *windMainLayout; 30 | graphHeaderWidget *_header; 31 | OrientationWidget *_widget3d; 32 | uint8_t _inputChannels[4]; 33 | uint8_t _maxInChannel; 34 | uint8_t _nInputs; 35 | }; 36 | 37 | #endif // ORIENTATIONWINDOW_H 38 | -------------------------------------------------------------------------------- /plotWindows/line/lineplot.h: -------------------------------------------------------------------------------- 1 | #ifndef LINEPLOT_H 2 | #define LINEPLOT_H 3 | #include 4 | #include 5 | 6 | #include 7 | #include "plotWindows/line/qcustomplot.h" 8 | 9 | class LinePlot : public QMdiSubWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | LinePlot(QString objName=""); 14 | ~LinePlot(); 15 | 16 | void UpdateInputChannels(uint8_t *inChannels); 17 | void ReceiveData(double *data, uint8_t n); 18 | 19 | signals: 20 | void logLine(const QString &line); 21 | 22 | public slots: 23 | void ChannelAdded(); 24 | void UpdateXaxis(const QString &_datasize); 25 | 26 | private slots: 27 | void _toggleAccumulatedMode(bool state); 28 | 29 | private: 30 | void _ConstructUI(); 31 | 32 | 33 | uint8_t _nInputs; 34 | QSemaphore _plotDataMutex; 35 | 36 | QWidget *_contWind; 37 | QCustomPlot *_plot; 38 | QVBoxLayout *windMainLayout; 39 | 40 | QVector_inputChannels; 41 | uint8_t _maxInChannel; 42 | 43 | graphHeaderWidget *_header; 44 | QCheckBox *_autoAdjustYaxis; 45 | QCheckBox *_accumulate; 46 | 47 | QVector < QVector >_inputCh; 48 | QVector _xAxis; 49 | QTimer *_refresher; 50 | 51 | uint32_t _XaxisSize; 52 | }; 53 | 54 | #endif // LINEPLOT_H 55 | -------------------------------------------------------------------------------- /helperObjects/graphHeaderWidget/graphheaderwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHHEADERWIDGET_H 2 | #define GRAPHHEADERWIDGET_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class graphHeaderWidget : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | graphHeaderWidget(uint8_t chnnelNum, QString ParentWinName=""); 17 | ~graphHeaderWidget(); 18 | 19 | void AppendHorSpacer(); 20 | void UpdateChannelDropdown(); 21 | 22 | QVector& GetLabels(); 23 | QVector GetChLabels(); 24 | QVector GetSelectedChannels(); 25 | 26 | void SetSelectedChannels(QVector &selectedCh); 27 | void SetChToolTip(uint8_t id, QString toolTip); 28 | 29 | public slots: 30 | 31 | QHBoxLayout* GetLayout(); 32 | 33 | signals: 34 | void UpdateInputChannels(uint8_t *inChannels); 35 | void logLine(const QString &line); 36 | 37 | private slots: 38 | void ComboBoxUpdated(const int &); 39 | 40 | private: 41 | 42 | QHBoxLayout *_mainLayout; 43 | QString _parentWinName; 44 | 45 | // List of dynamically constructed UI elements 46 | QVector_inCh; 47 | QVector_inChLabel; 48 | QWidget *_parent; 49 | uint8_t *_inputChannelList; 50 | }; 51 | 52 | #endif // GRAPHHEADERWIDGET_H 53 | -------------------------------------------------------------------------------- /helperObjects/mathComponent/mathchannelcomponent.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHCHANNELCOMPONENT_H 2 | #define MATHCHANNELCOMPONENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * @brief The UIMathChannelComponent class 15 | * Object dynamically constructed in UI to represent match channel 16 | * components under 'Math channel' page. 17 | */ 18 | class UIMathChannelComponent : public QObject 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | UIMathChannelComponent(uint8_t id); 24 | ~UIMathChannelComponent(); 25 | 26 | void UpdateMathCh(int *mathCh, int size); 27 | 28 | // Input channel 29 | void SetInCh(int inCh); 30 | int GetInCh(); 31 | // Math channel 32 | void SetMathCh(int mathCh); 33 | int GetMathCh(); 34 | // Math operation 35 | void SetMath(int math); 36 | int GetMath(); 37 | // ID of the component 38 | void SetID(uint8_t id); 39 | uint8_t GetID(); 40 | 41 | QHBoxLayout* GetLayout(); 42 | 43 | 44 | QComboBox *mathChSelector; 45 | QComboBox *mathSelector; 46 | QSpinBox *inChSelector; 47 | QPushButton *deleteButton; 48 | QHBoxLayout *layout; 49 | 50 | signals: 51 | void deleteRequested(uint8_t id); 52 | private slots: 53 | void deleteComponent(); 54 | private: 55 | // Unique identifier 56 | int _id; 57 | }; 58 | 59 | #endif // MATHCHANNELCOMPONENT_H 60 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:GPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** GNU General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU 19 | ** General Public License version 3 or (at your option) any later version 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 22 | ** included in the packaging of this file. Please review the following 23 | ** information to ensure the GNU General Public License requirements will 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 25 | ** 26 | ** $QT_END_LICENSE$ 27 | ** 28 | ****************************************************************************/ 29 | #include 30 | #include "mainwindow.h" 31 | 32 | int main(int argc, char **argv) 33 | { 34 | //! [0] 35 | QApplication app(argc, argv); 36 | 37 | //! [3] 38 | MainWindow dashboard; 39 | dashboard.show(); 40 | return app.exec(); 41 | //! [3] 42 | } 43 | -------------------------------------------------------------------------------- /datadashboard.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += datavisualization core gui widgets serialport printsupport network 4 | 5 | 6 | SOURCES += main.cpp mainwindow.cpp \ 7 | helperObjects/channel/channel.cpp \ 8 | helperObjects/dataMultiplexer/datamultiplexer.cpp \ 9 | helperObjects/graphHeaderWidget/graphheaderwidget.cpp \ 10 | helperObjects/mathComponent/mathchannelcomponent.cpp \ 11 | plotWindows/line/lineplot.cpp \ 12 | plotWindows/line/qcustomplot.cpp \ 13 | plotWindows/scatter/scatterwindow.cpp \ 14 | plotWindows/orientation_3d/orientationwidget.cpp \ 15 | plotWindows/orientation_3d/geometryengine.cpp \ 16 | plotWindows/orientation_3d/orientationwindow.cpp \ 17 | dataSources/networkAdapter/networkadapter.cpp \ 18 | dataSources/serialAdapter/serialadapter.cpp 19 | 20 | 21 | HEADERS += mainwindow.h \ 22 | dataSources/dataSources.h \ 23 | helperObjects/channel/channel.h \ 24 | helperObjects/dataMultiplexer/datamultiplexer.h \ 25 | helperObjects/dataMultiplexer/graphclient.h \ 26 | helperObjects/dataMultiplexer/mathchannel.h \ 27 | helperObjects/graphHeaderWidget/graphheaderwidget.h \ 28 | helperObjects/mathComponent/mathchannelcomponent.h \ 29 | plotWindows/line/lineplot.h \ 30 | plotWindows/line/qcustomplot.h \ 31 | plotWindows/plotWindows.h \ 32 | plotWindows/scatter/scatterwindow.h \ 33 | plotWindows/orientation_3d/orientationwindow.h \ 34 | plotWindows/orientation_3d/orientationwidget.h \ 35 | plotWindows/orientation_3d/geometryengine.h \ 36 | dataSources/networkAdapter/networkadapter.h \ 37 | dataSources/serialAdapter/serialadapter.h 38 | 39 | RESOURCES += \ 40 | res/icon.qrc \ 41 | plotWindows/orientation_3d/resources/shaders.qrc \ 42 | plotWindows/orientation_3d/resources/textures.qrc \ 43 | config.ini 44 | 45 | requires(qtConfig(combobox)) 46 | requires(qtConfig(fontcombobox)) 47 | 48 | FORMS += \ 49 | mainwindow.ui 50 | 51 | -------------------------------------------------------------------------------- /helperObjects/dataMultiplexer/mathchannel.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHCHANNEL_H 2 | #define MATHCHANNEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /** 10 | * @brief The SignalSource enum 11 | * Describing signal origin 12 | */ 13 | enum SignalSource { 14 | AllChannels, 15 | SerialSignal, 16 | MathSignal, 17 | NetworkSignal 18 | }; 19 | 20 | /** 21 | * @brief The MathOperation enum 22 | * Math operation ID (used in math componenets) 23 | */ 24 | enum MathOperation { 25 | Add_Signal, 26 | Subtract_Signal, 27 | Multiply, 28 | Add_Abs, 29 | Subtract_Abs, 30 | Multiply_Abs 31 | }; 32 | 33 | /** 34 | * @brief The MathOperationText lookup table 35 | * Links \ref enum MathOperation ID to a string 36 | */ 37 | const QVector MathOperationText { 38 | "+", 39 | "-", 40 | "*", 41 | "+ ABS", 42 | " - ABS", 43 | "* ABS" 44 | }; 45 | 46 | /** 47 | * @brief The MathChannel class 48 | * Helper class for storing and manipulating math channels 49 | * and their components 50 | */ 51 | class MathChannel 52 | { 53 | public: 54 | MathChannel(): Enabled(false) {}; 55 | void SetLabel(QString label) 56 | { 57 | _label = label; 58 | } 59 | QString GetLabel() 60 | { 61 | return _label; 62 | } 63 | /** 64 | * @brief Add new math component to this math channel 65 | * @param operation id of math operation 66 | * @param inputChannel input channel to use in the component 67 | */ 68 | void AddComponent(MathOperation operation, uint8_t inputChannel) 69 | { 70 | _component.push_back(std::tuple(operation,inputChannel)); 71 | } 72 | /** 73 | * @brief Reset the component 74 | */ 75 | void Clear() 76 | { 77 | Enabled = false; 78 | _label = QString(""); 79 | _component.clear(); 80 | } 81 | 82 | bool Enabled; 83 | 84 | //private: 85 | QString _label; 86 | std::vector< std::tuple >_component; 87 | }; 88 | 89 | 90 | #endif // MATHCHANNEL_H 91 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kind: pipeline 3 | name: build-release 4 | 5 | platform: 6 | os: linux 7 | arch: amd64 8 | 9 | workspace: 10 | base: /workspace 11 | path: dataDashboard 12 | 13 | steps: 14 | - name: build-release-win64 15 | pull: never 16 | image: qt-win64builder:5.15.1 17 | commands: 18 | - "mkdir build-win64 && cd build-win64" 19 | - "/opt/qt5.11/win64/bin/qmake -config release ../datadashboard.pro" 20 | - "make -j4" 21 | - "copy-libraries /workspace/dataDashboard/build-win64/release" 22 | - "rm release/*.o release/*.cpp release/*.h release/*.qrc" 23 | - "cp ../LICENSE release/LICENSE.txt" 24 | - "cp ../README.md release/README.md" 25 | - "cp ../config.ini release/config.ini" 26 | - "mv release Data_dashboard-${DRONE_TAG##v}-win64" 27 | - "zip -r Data_dashboard-${DRONE_TAG##v}-win64.zip Data_dashboard-${DRONE_TAG##v}-win64/" 28 | when: 29 | event: 30 | - tag 31 | 32 | - name: build-release-ubuntu 33 | pull: never 34 | image: qt-ubuntu16builder:5.15.1 35 | commands: 36 | - "mkdir build-amd64 && cd build-amd64" 37 | - "/opt/qt5.11/amd64/bin/qmake -config release ../datadashboard.pro" 38 | - "make -j4" 39 | - "cqtdeployer -qmake /opt/qt5.11/amd64/bin/qmake -bin datadashboard" 40 | - "cp ../LICENSE DistributionKit/LICENSE.txt" 41 | - "cp ../README.md DistributionKit/README.md" 42 | - "cp ../config.ini DistributionKit/config.ini" 43 | - "mv DistributionKit Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64" 44 | - "zip -r Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64.zip Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64/" 45 | when: 46 | event: 47 | - tag 48 | 49 | - name: publish-release 50 | pull: always 51 | image: plugins/gitea-release 52 | settings: 53 | api_key: 54 | from_secret: gitea_api_key 55 | base_url: https://git.vedran.ml 56 | files: 57 | - "/workspace/dataDashboard/build-win64/Data_dashboard-${DRONE_TAG##v}-win64.zip" 58 | - "/workspace/dataDashboard/build-amd64/Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64.zip" 59 | checksum: 60 | - md5 61 | - sha1 62 | - sha256 63 | when: 64 | event: tag 65 | 66 | trigger: 67 | ref: 68 | - refs/heads/master 69 | - "refs/tags/**" 70 | - "refs/pull/**" 71 | 72 | ... 73 | -------------------------------------------------------------------------------- /.drone-github.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kind: pipeline 3 | name: build-release 4 | 5 | platform: 6 | os: linux 7 | arch: amd64 8 | 9 | workspace: 10 | base: /workspace 11 | path: dataDashboard 12 | 13 | steps: 14 | - name: build-release-win64 15 | pull: never 16 | image: qt-win64builder:5.15.1 17 | commands: 18 | - "mkdir build-win64 && cd build-win64" 19 | - "/opt/qt5.11/win64/bin/qmake -config release ../datadashboard.pro" 20 | - "make -j4" 21 | - "copy-libraries /workspace/dataDashboard/build-win64/release" 22 | - "rm release/*.o release/*.cpp release/*.h release/*.qrc" 23 | - "cp ../LICENSE release/LICENSE.txt" 24 | - "cp ../README.md release/README.md" 25 | - "cp ../config.ini release/config.ini" 26 | - "mv release Data_dashboard-${DRONE_TAG##v}-win64" 27 | - "zip -r Data_dashboard-${DRONE_TAG##v}-win64.zip Data_dashboard-${DRONE_TAG##v}-win64/" 28 | when: 29 | event: 30 | - tag 31 | 32 | - name: build-release-ubuntu 33 | pull: never 34 | image: qt-ubuntu16builder:5.15.1 35 | commands: 36 | - "mkdir build-amd64 && cd build-amd64" 37 | - "/opt/qt5.11/amd64/bin/qmake -config release ../datadashboard.pro" 38 | - "make -j4" 39 | - "cqtdeployer -qmake /opt/qt5.11/amd64/bin/qmake -bin datadashboard" 40 | - "cp ../LICENSE DistributionKit/LICENSE.txt" 41 | - "cp ../README.md DistributionKit/README.md" 42 | - "cp ../config.ini DistributionKit/config.ini" 43 | - "mv DistributionKit Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64" 44 | - "zip -r Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64.zip Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64/" 45 | when: 46 | event: 47 | - tag 48 | 49 | - name: publish-release 50 | pull: always 51 | image: plugins/github-release 52 | settings: 53 | api_key: 54 | from_secret: github_api_key 55 | files: 56 | - "/workspace/dataDashboard/build-win64/Data_dashboard-${DRONE_TAG##v}-win64.zip" 57 | - "/workspace/dataDashboard/build-amd64/Data_dashboard-${DRONE_TAG##v}-ubuntu-amd64.zip" 58 | checksum: 59 | - md5 60 | - sha1 61 | - sha256 62 | when: 63 | event: tag 64 | 65 | trigger: 66 | ref: 67 | - refs/heads/master 68 | - "refs/tags/**" 69 | - "refs/pull/**" 70 | 71 | ... -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "dataSources/dataSources.h" 6 | #include "helperObjects/channel/channel.h" 7 | #include "helperObjects/mathComponent/mathchannelcomponent.h" 8 | #include "helperObjects/dataMultiplexer/datamultiplexer.h" 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #define _STYLE_TOOLTIP_(X) "

" X "

" 17 | 18 | namespace Ui { 19 | class MainWindow; 20 | } 21 | 22 | class MainWindow : public QWidget 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | explicit MainWindow(QWidget *parent = nullptr); 28 | ~MainWindow(); 29 | 30 | static void clearLayout(QLayout* layout, bool deleteWidgets = true); 31 | 32 | public Q_SLOTS: 33 | void logLine(const QString &line); 34 | void toggleConnection(); 35 | void refreshUI(); 36 | 37 | public slots: 38 | void UpdateAvailMathCh(); 39 | void on_delete_updateMathComp(uint8_t id); 40 | 41 | private slots: 42 | void on_channelNumber_valueChanged(int arg1); 43 | 44 | void on_addMathComp_clicked(); 45 | 46 | void on_add3D_clicked(); 47 | 48 | void on_addScatter_clicked(); 49 | 50 | void on_fileloggingEnabled_stateChanged(int arg1); 51 | 52 | void on_logfilePathDialog_clicked(); 53 | 54 | void on_addLine_clicked(); 55 | 56 | void on_enableSerial_clicked(); 57 | 58 | void on_enableNetwork_clicked(); 59 | 60 | private: 61 | void LoadSettings(); 62 | 63 | void RegisterMathChannel(uint8_t chID); 64 | 65 | Ui::MainWindow *ui; 66 | bool _pendingDeletion; 67 | SerialAdapter *dataAdapter; 68 | NetworkAdapter *netAdapter; 69 | 70 | QSettings *settings; 71 | QTimer *mainTimer; 72 | DataMultiplexer *mux; 73 | 74 | // Dynamically created/destroyed UI elements 75 | std::vectorch; 76 | std::vectormathComp; 77 | 78 | std::vectormathChEnabled; 79 | std::vectormathChName; 80 | std::vectorplots; 81 | 82 | // Program run log 83 | QFile *_logFile; 84 | QTextStream *_logFileStream; 85 | bool _loggingInitialized; 86 | }; 87 | 88 | #endif // MAINWINDOW_H 89 | -------------------------------------------------------------------------------- /helperObjects/dataMultiplexer/graphclient.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHCLIENT_H 2 | #define GRAPHCLIENT_H 3 | 4 | #include 5 | 6 | enum GraphType { 7 | Orientation3D, 8 | Scatter, 9 | Line 10 | }; 11 | 12 | 13 | class GraphClient 14 | { 15 | friend class DataMultiplexer; 16 | public: 17 | GraphClient(QString name, uint8_t nInChannels, OrientationWindow* reciver) \ 18 | :_name(name), _inChannels(nInChannels), _reciver3D(reciver) 19 | { _type = GraphType::Orientation3D; } 20 | GraphClient(QString name, uint8_t nInChannels, ScatterWindow* reciver) \ 21 | :_name(name), _inChannels(nInChannels), _receiverScatter(reciver) 22 | { _type = GraphType::Scatter; } 23 | GraphClient(QString name, uint8_t nInChannels, LinePlot* reciver) \ 24 | :_name(name), _inChannels(nInChannels), _receiverLine(reciver) 25 | { _type = GraphType::Line; } 26 | 27 | void SetInputChannels(uint8_t n, uint8_t *chList) 28 | { 29 | _inputChannelMap.clear(); 30 | 31 | for (uint8_t i = 0; i < n; i++) 32 | _inputChannelMap.push_back(chList[i]); 33 | } 34 | 35 | void SendData(uint8_t n, double* data) 36 | { 37 | switch (_type) 38 | { 39 | case GraphType::Orientation3D: 40 | _reciver3D->ReceiveData(data, n); 41 | break; 42 | case GraphType::Scatter: 43 | _receiverScatter->ReceiveData(data, n); 44 | break; 45 | case GraphType::Line: 46 | _receiverLine->ReceiveData(data, n); 47 | break; 48 | default: 49 | break; 50 | } 51 | 52 | } 53 | 54 | const QString& GetName() 55 | { 56 | return _name; 57 | } 58 | 59 | OrientationWindow* Receiver(OrientationWindow* dummy=0) 60 | { 61 | assert(dummy==dummy); 62 | return _reciver3D; 63 | } 64 | 65 | ScatterWindow* Receiver(ScatterWindow* dummy=0) 66 | { 67 | assert(dummy==dummy); 68 | return _receiverScatter; 69 | } 70 | 71 | LinePlot* Receiver(LinePlot* dummy=0) 72 | { 73 | assert(dummy==dummy); 74 | return _receiverLine; 75 | } 76 | 77 | 78 | private: 79 | GraphType _type; 80 | QString _name; 81 | uint8_t _inChannels; 82 | OrientationWindow* _reciver3D; 83 | ScatterWindow* _receiverScatter; 84 | LinePlot *_receiverLine; 85 | std::vector_inputChannelMap; 86 | }; 87 | #endif // GRAPHCLIENT_H 88 | -------------------------------------------------------------------------------- /plotWindows/scatter/scatterwindow.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:GPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** GNU General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU 19 | ** General Public License version 3 or (at your option) any later version 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 22 | ** included in the packaging of this file. Please review the following 23 | ** information to ensure the GNU General Public License requirements will 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 25 | ** 26 | ** $QT_END_LICENSE$ 27 | ** 28 | ****************************************************************************/ 29 | 30 | #ifndef SCATTERDATAMODIFIER_H 31 | #define SCATTERDATAMODIFIER_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | 43 | using namespace QtDataVisualization; 44 | 45 | class ScatterWindow : public QMdiSubWindow 46 | { 47 | Q_OBJECT 48 | public: 49 | explicit ScatterWindow(QString objName=""); 50 | ~ScatterWindow() override; 51 | 52 | void UpdateInputChannels(uint8_t *inChannels); 53 | void ReceiveData(double *data, uint8_t n); 54 | 55 | void changeFont(const QFont &font); 56 | void setGridEnabled(int enabled); 57 | 58 | signals: 59 | void logLine(const QString &line); 60 | 61 | public slots: 62 | void on_dataSize_changed(const QString &datasize); 63 | void on_resetData_pressed(); 64 | 65 | private: 66 | QWidget *_contWind; 67 | Q3DScatter *_graph; 68 | QScatterDataArray *_dataArray; 69 | 70 | uint8_t _inputChannels[3]; 71 | uint8_t _maxInChannel; 72 | 73 | graphHeaderWidget *_header; 74 | 75 | int _plotDataSize; 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /dataSources/serialAdapter/serialadapter.cpp: -------------------------------------------------------------------------------- 1 | #include "serialadapter.h" 2 | 3 | #include 4 | #include 5 | 6 | SerialAdapter::SerialAdapter(QObject *parent) : 7 | QThread(parent) 8 | { 9 | _mux = DataMultiplexer::GetP(); 10 | } 11 | 12 | SerialAdapter::~SerialAdapter() 13 | { 14 | _threadQuit = true; 15 | wait(); 16 | } 17 | 18 | /** 19 | * @brief Open serial port 20 | */ 21 | void SerialAdapter::StartListening() 22 | { 23 | // Check if the thread is already running, if not start it 24 | if (!isRunning()) 25 | { 26 | _threadQuit = false; 27 | start(); 28 | } 29 | } 30 | 31 | /** 32 | * @brief Close serial port 33 | */ 34 | void SerialAdapter::StopListening() 35 | { 36 | _threadQuit = true; 37 | } 38 | 39 | /** 40 | * @brief Update serial port parameters 41 | * @param portName 42 | * @param portBaud 43 | */ 44 | void SerialAdapter::UpdatePort(const QString &portName, const QString &portBaud) 45 | { 46 | if ((portName == _portName) && (portBaud == _portBaud)) 47 | _portUpdated = false; 48 | else 49 | { 50 | _portUpdated = true; 51 | _portName = portName; 52 | _portBaud = portBaud; 53 | } 54 | } 55 | 56 | /** 57 | * @brief Thread to read and publish serial data, capable of dynamically 58 | * updating port parameters 59 | */ 60 | void SerialAdapter::run() 61 | { 62 | QSerialPort serial; 63 | 64 | emit logLine("Serial thread started"); 65 | 66 | if (_portName.isEmpty()) 67 | { 68 | emit logLine(tr("No port name specified")); 69 | return; 70 | } 71 | 72 | _portUpdated = true; 73 | 74 | while (!_threadQuit) 75 | { 76 | // Check if port name changed while running 77 | if (_portUpdated) 78 | { 79 | serial.close(); 80 | serial.setPortName(_portName); 81 | serial.setBaudRate(_portBaud.toUInt()); 82 | 83 | if (!serial.open(QIODevice::ReadWrite)) 84 | { 85 | emit logLine(tr("Can't open %1, error code %2") 86 | .arg(_portName).arg(serial.error())); 87 | return; 88 | } 89 | _portUpdated = false; 90 | } 91 | 92 | // Read response 93 | if (serial.waitForReadyRead(5)) 94 | { 95 | QByteArray responseData = serial.readAll(); 96 | while (serial.waitForReadyRead(1)) 97 | responseData += serial.readAll(); 98 | 99 | const QString response = QString::fromUtf8(responseData); 100 | 101 | _mux->ReceiveData(response); 102 | } 103 | } 104 | serial.close(); 105 | _threadQuit = false; 106 | emit logLine("Serial thread exited"); 107 | } 108 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/geometryengine.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCore module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef GEOMETRYENGINE_H 52 | #define GEOMETRYENGINE_H 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | class GeometryEngine : protected QOpenGLFunctions 59 | { 60 | public: 61 | GeometryEngine(); 62 | virtual ~GeometryEngine(); 63 | 64 | void drawCubeGeometry(QOpenGLShaderProgram *program); 65 | 66 | private: 67 | void initCubeGeometry(); 68 | 69 | QOpenGLBuffer arrayBuf; 70 | QOpenGLBuffer indexBuf; 71 | }; 72 | 73 | #endif // GEOMETRYENGINE_H 74 | -------------------------------------------------------------------------------- /helperObjects/dataMultiplexer/datamultiplexer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Data multiplexer singleton (with helper objects) 3 | * 4 | * Thread object used to receive data from multiple sources, parse it, 5 | * perform simple math on it and pass further on to the graphs 6 | */ 7 | 8 | #ifndef DATAMULTIPLEXER_H 9 | #define DATAMULTIPLEXER_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include "graphclient.h" 20 | #include "mathchannel.h" 21 | 22 | /** 23 | * @brief The DataMultiplexer class 24 | * Designed as singleton object with GetI and GetP methods for accessing 25 | * the static instance 26 | * 27 | * Handles all the data coming in and out of the program, including all 28 | * the manipulation (math) and logging to file 29 | */ 30 | class DataMultiplexer : public QThread 31 | { 32 | 33 | Q_OBJECT 34 | 35 | public: 36 | // Get singleton 37 | static DataMultiplexer& GetI(); 38 | static DataMultiplexer* GetP(); 39 | 40 | void SetSerialFrameFormat(const QString &start, const QString &delim, const QString &end); 41 | 42 | void RegisterSerialCh(uint8_t n, QString *chName); 43 | 44 | void ReceiveData(const QString &s); 45 | 46 | 47 | void RegisterGraph(QString name, 48 | uint8_t nInChannels, 49 | OrientationWindow* reciver); 50 | void RegisterGraph(QString name, 51 | uint8_t nInChannels, 52 | ScatterWindow *receiver); 53 | void RegisterGraph(QString name, 54 | uint8_t nInChannels, 55 | LinePlot *receiver); 56 | 57 | void UnregisterGraph(OrientationWindow* reciver); 58 | void UnregisterGraph(ScatterWindow* reciver); 59 | void UnregisterGraph(LinePlot* reciver); 60 | 61 | uint16_t GetSampleRateEst(); 62 | signals: 63 | void logLine(const QString &s); 64 | void ChannelsUpdated(); 65 | 66 | public slots: 67 | 68 | void RegisterMathChannel(uint8_t channelId, 69 | MathChannel *mc); 70 | void UnegisterMathChannel(uint8_t channelId); 71 | 72 | QStringList GetChannelList(); 73 | 74 | int EnableFileLogging(const QString &logPath, bool append, char chSep); 75 | void DisableFileLogging(); 76 | 77 | private slots: 78 | void _TimerTick(); 79 | 80 | private: 81 | DataMultiplexer(); 82 | ~DataMultiplexer(); 83 | void _ComputeMathChannels(); 84 | void _InternalChannelUpdate(); 85 | 86 | void run() override; 87 | bool _threadQuit; 88 | 89 | QString _SerialframeFormat[3]; 90 | 91 | double *_channelData; 92 | uint8_t _channelCount[4]; 93 | 94 | MathChannel* _mChannel[7]; 95 | std::vector_SerialLabels; 96 | std::vector_Graphs; 97 | 98 | QString _buffer; 99 | QSemaphore _InputdataReady; 100 | 101 | QFile *_logFile; 102 | QTextStream *_logFileStream; 103 | bool _logToFile; 104 | char _logChSep; 105 | 106 | uint16_t _sampleCount; 107 | uint16_t _extSampleCount; 108 | QTimer _timer; 109 | }; 110 | 111 | #endif // DATAMULTIPLEXER_H 112 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/orientationwidget.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCore module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef ORIENTATIONWIDGET_H 52 | #define ORIENTATIONWIDGET_H 53 | 54 | #include "geometryengine.h" 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | class GeometryEngine; 66 | 67 | class OrientationWidget : public QOpenGLWidget, public QOpenGLFunctions 68 | { 69 | friend class OrientationWindow; 70 | Q_OBJECT 71 | 72 | public: 73 | using QOpenGLWidget::QOpenGLWidget; 74 | ~OrientationWidget(); 75 | 76 | QQuaternion rotation; 77 | 78 | protected: 79 | void initializeGL() override; 80 | void resizeGL(int w, int h) override; 81 | void paintGL() override; 82 | 83 | void initShaders(); 84 | void initTextures(); 85 | 86 | private: 87 | QOpenGLShaderProgram program; 88 | GeometryEngine *geometries = nullptr; 89 | QOpenGLTexture *texture = nullptr; 90 | QMatrix4x4 projection; 91 | }; 92 | 93 | 94 | 95 | #endif // ORIENTATIONWIDGET_H 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Data dashboard](https://github.com/vedranMv/dataDashboard) [![Build Status](https://ci1.my-server.dk/api/badges/vedranMv/dataDashboard/status.svg)](https://ci1.my-server.dk/vedranMv/dataDashboard) [![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](/License) 2 | ======= 3 | (QT based app for real-time data visualization) 4 | 5 | Data dashboard is a program based on QT framework that can be used to to visualize some of the common data types that one comes in contact when working with sensors. Although it was developed during my work with IMU, and is mostly centered around it, it should be versatile enough for other sensors and purposes as well. 6 | 7 | It is currently possible to: 8 | * Read data from serial port or network socket (real input channel) 9 | * Show estimated incoming data rate 10 | * Define data frame (specify start/end of frame character, as well as data separator char) 11 | * Perform basic math (addition, subtraction, abs value) on multiple input channels and visualize result of the operations (virtual input channels) 12 | * Log input channels into a file 13 | * Visualize 3D orientation by taking either euler angles or quaternion as input 14 | * Visualize linear data series (flexible number of input channels) 15 | * Plot data in 3D scatter plot (or 2D by specifying one of the inputs as 0) 16 | * Create dashboard consisting of any combination of the visualizations above on runtime 17 | * Preserve settings between runs in a configuration file 18 | * Internal app log for easier troubleshooting 19 | 20 | ## Demo of current progress 21 | Few screenshots from ``/doc``, demonstrating the UI 22 | 23 | [](doc/dashboard.PNG) 24 | 25 | [](doc/input.PNG) 26 | 27 | [](doc/comparison.PNG) 28 | 29 | Demo videos: 30 | * https://my-server.dk/public/projects/datadashboard/demo.mp4 31 | * https://my-server.dk/public/projects/datadashboard/demo_net.mp4 32 | 33 | ## How to run 34 | 35 | There are several ways to run on both windows and linux. 36 | 37 | ### Windows 38 | 39 | * Download a portable (statically linked) precompiled version from [Releases](https://github.com/vedranMv/dataDashboard/releases)_; or_ 40 | * Download QT Creator and compile the source from this repo 41 | 42 | ### Linux 43 | There are several dependencies for running on linux systems, regardless of which method below you go with: 44 | > ``sudo apt-get install libgl1-mesa-dev libfontconfig1 libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev`` 45 | 46 | After that, it's possible to: 47 | * (Ubuntu) Download a precompiled (dynamically linked), version from [Releases](https://github.com/vedranMv/dataDashboard/releases) and launch ``datadashboard.sh``_; or_ 48 | * Install QT creator and compile from scratch _; or_ 49 | * Compile the project yourself, following the guide below 50 | 51 | ### Compilation on linux 52 | 53 | 1. Download libraries and compilation tools (not available on older Ubuntu 18.04/16.04) 54 | > ``sudo apt-get install qt5-default qt5-qmake libqt5datavisualization5-dev libqt5serialport5-dev libqt5core5a libqt5x11extras5-dev`` 55 | 56 | 2. Clone this project (master branch for latest release version) 57 | > ``git clone --depth=1 https://github.com/vedranMv/dataDashboard`` 58 | 59 | 3. Make build directory inside the cloned repo 60 | > ``mkdir dataDashboard/build``
61 | ``cd dataDashboard/build`` 62 | 63 | 4. Invoke qmake, then compile with make 64 | > ``qmake -config release ../datadashboard.pro``
65 | ``make`` 66 | 67 | 5. Run the program 68 | > ``./datadashboard`` 69 | 70 | ## Known issues 71 | * Ubuntu 16.04/18.04: Launching scatter plot crashes the program (in Ubuntu 20.04 works as expected) 72 | * 3D orientation plot sometimes freezes (workaround: just switch to another tab, then reopen _Dashboard_ tab) 73 | * High data rates unsupported (scatter plot results in biggest negative impact on performance, see video) 74 | 75 | ## Acknowledgments 76 | Made using: 77 | * QT framework & examples 78 | * [CQtDeployer](https://github.com/QuasarApp/CQtDeployer) part of CI pipeline for ubuntu 79 | * [QTCustomPlot](https://www.qcustomplot.com/index.php/introduction) line plot component 80 | -------------------------------------------------------------------------------- /dataSources/networkAdapter/networkadapter.cpp: -------------------------------------------------------------------------------- 1 | #include "networkadapter.h" 2 | 3 | NetworkAdapter::NetworkAdapter(): _threadQuit(false), _clientSocket(nullptr), 4 | _port(0) 5 | { 6 | _tcpServer = new QTcpServer(); 7 | connect(_tcpServer, &QTcpServer::newConnection, 8 | this, &NetworkAdapter::_onNewConnection); 9 | 10 | _mux = DataMultiplexer::GetP(); 11 | } 12 | 13 | NetworkAdapter::~NetworkAdapter() 14 | { 15 | // Pass kill signal to the thread and wait for it to terminate 16 | _threadQuit = true; 17 | wait(); 18 | StopListening(); 19 | } 20 | 21 | /** 22 | * @brief Network port setted 23 | * @param port 24 | */ 25 | void NetworkAdapter::SetNetPort(uint16_t port) 26 | { 27 | _port = port; 28 | } 29 | 30 | /** 31 | * @brief Network port getter 32 | * @return 33 | */ 34 | uint16_t NetworkAdapter::GetPort() 35 | { 36 | return _port; 37 | } 38 | 39 | /** 40 | * @brief Start listening on network port 41 | * Starts up TCP server on a port 42 | */ 43 | bool NetworkAdapter::StartListening() 44 | { 45 | if (!_tcpServer->isListening()) 46 | { 47 | // External process use this flag to control thread, avoid 48 | // forcing its value here 49 | //_threadQuit = false; 50 | 51 | if (_port == 0) 52 | { 53 | return false; 54 | emit logLine("Port cannot be 0"); 55 | } 56 | 57 | _tcpServer->listen(QHostAddress::Any, _port); 58 | _tcpServer->resumeAccepting(); 59 | emit logLine("Waiting for new connection on port "+QString::number(_port)); 60 | } 61 | 62 | return true; 63 | } 64 | 65 | /** 66 | * @brief Stop listening on network port 67 | * Stop TCP server and tear down a client connection if it exists 68 | */ 69 | void NetworkAdapter::StopListening() 70 | { 71 | emit logLine("Disconnecting client"); 72 | 73 | if (_clientSocket != nullptr) 74 | if (_clientSocket->isOpen()) 75 | { 76 | disconnect(_clientSocket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); 77 | disconnect(_clientSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), 78 | this, SLOT(onSocketStateChanged(QAbstractSocket::SocketState))); 79 | _clientSocket->close(); 80 | delete _clientSocket; 81 | _clientSocket = nullptr; 82 | } 83 | 84 | emit logLine("Stopping network thread"); 85 | if (_tcpServer->isListening()) 86 | _tcpServer->close(); 87 | } 88 | 89 | /** 90 | * @brief [Slot] Handler for new TCP connection 91 | * Called by TCP server whenever a new client is asking to be connected 92 | */ 93 | void NetworkAdapter::_onNewConnection() 94 | { 95 | _clientSocket = _tcpServer->nextPendingConnection(); 96 | _tcpServer->pauseAccepting(); 97 | emit logLine("Connection established, reading data"); 98 | //start(); 99 | 100 | connect(_clientSocket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); 101 | connect(_clientSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), 102 | this, SLOT(onSocketStateChanged(QAbstractSocket::SocketState))); 103 | } 104 | 105 | /** 106 | * @brief [Slot] Handler for state change in sockets 107 | * Used to handle a client disconnecting from the server. Functions log 108 | * disconnect, delete client object and reset the pointer. Afterwards, 109 | * the server is enabled to receive new clients. 110 | * @param socketState socket state after a change 111 | */ 112 | void NetworkAdapter::onSocketStateChanged(QAbstractSocket::SocketState socketState) 113 | { 114 | if (socketState == QAbstractSocket::UnconnectedState) 115 | { 116 | emit logLine("Client disconnected, waiting for new connection"); 117 | _clientSocket->deleteLater(); 118 | _clientSocket = nullptr; 119 | _tcpServer->resumeAccepting(); 120 | } 121 | } 122 | 123 | /** 124 | * @brief [Slot] Handler for new incoming data on the socket 125 | * Called by the client socket when there's new data available 126 | */ 127 | void NetworkAdapter::onReadyRead() 128 | { 129 | QByteArray responseData = _clientSocket->readAll(); 130 | const QString response = QString::fromUtf8(responseData); 131 | 132 | _mux->ReceiveData(response); 133 | } 134 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/orientationwidget.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCore module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include "orientationwidget.h" 52 | #include "helperObjects/dataMultiplexer/datamultiplexer.h" 53 | 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | OrientationWidget::~OrientationWidget() 60 | { 61 | // Make sure the context is current when deleting the texture 62 | // and the buffers. 63 | makeCurrent(); 64 | delete texture; 65 | delete geometries; 66 | doneCurrent(); 67 | } 68 | 69 | void OrientationWidget::initializeGL() 70 | { 71 | initializeOpenGLFunctions(); 72 | 73 | glClearColor(0, 0, 0, 1); 74 | 75 | initShaders(); 76 | initTextures(); 77 | 78 | //! [2] 79 | // Enable depth buffer 80 | glEnable(GL_DEPTH_TEST); 81 | 82 | // Enable back face culling 83 | glEnable(GL_CULL_FACE); 84 | //! [2] 85 | geometries = new GeometryEngine; 86 | update(); 87 | } 88 | 89 | //! [3] 90 | void OrientationWidget::initShaders() 91 | { 92 | // Compile vertex shader 93 | if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vshader.glsl")) 94 | close(); 95 | 96 | // Compile fragment shader 97 | if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fshader.glsl")) 98 | close(); 99 | 100 | // Link shader pipeline 101 | if (!program.link()) 102 | close(); 103 | 104 | // Bind shader pipeline for use 105 | if (!program.bind()) 106 | close(); 107 | } 108 | //! [3] 109 | 110 | //! [4] 111 | void OrientationWidget::initTextures() 112 | { 113 | // Load cube.png image 114 | texture = new QOpenGLTexture(QImage(":/cube.png").mirrored()); 115 | 116 | // Set nearest filtering mode for texture minification 117 | texture->setMinificationFilter(QOpenGLTexture::Nearest); 118 | 119 | // Set bilinear filtering mode for texture magnification 120 | texture->setMagnificationFilter(QOpenGLTexture::Linear); 121 | 122 | // Wrap texture coordinates by repeating 123 | // f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2) 124 | texture->setWrapMode(QOpenGLTexture::Repeat); 125 | } 126 | //! [4] 127 | 128 | //! [5] 129 | void OrientationWidget::resizeGL(int w, int h) 130 | { 131 | // Calculate aspect ratio 132 | qreal aspect = qreal(w) / qreal(h ? h : 1); 133 | 134 | // Set near plane to 3.0, far plane to 7.0, field of view 45 degrees 135 | const qreal zNear = 3.0, zFar = 7.0, fov = 45.0; 136 | 137 | // Reset projection 138 | projection.setToIdentity(); 139 | 140 | // Set perspective projection 141 | projection.perspective(fov, aspect, zNear, zFar); 142 | } 143 | //! [5] 144 | 145 | void OrientationWidget::paintGL() 146 | { 147 | // Clear color and depth buffer 148 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 149 | 150 | texture->bind(); 151 | 152 | //! [6] 153 | 154 | // Calculate model view transformation 155 | QMatrix4x4 matrix; 156 | matrix.translate(0.0, 0.0, -5.0); 157 | matrix.rotate(rotation); 158 | 159 | // Set modelview-projection matrix 160 | program.setUniformValue("mvp_matrix", projection * matrix); 161 | //! [6] 162 | 163 | // Use texture unit 0 which contains cube.png 164 | program.setUniformValue("texture", 0); 165 | 166 | // Draw cube geometry 167 | geometries->drawCubeGeometry(&program); 168 | } 169 | -------------------------------------------------------------------------------- /helperObjects/mathComponent/mathchannelcomponent.cpp: -------------------------------------------------------------------------------- 1 | #include "mathchannelcomponent.h" 2 | #include "helperObjects/dataMultiplexer/mathchannel.h" 3 | 4 | #define _STYLE_TOOLTIP_(X) "

" X "

" 5 | 6 | 7 | UIMathChannelComponent::~UIMathChannelComponent() 8 | { 9 | // Deletion of object is called from MainWindow 10 | // Here we only need to delete the layout 11 | while (QLayoutItem* item = layout->takeAt(0)) 12 | { 13 | if (QWidget* widget = item->widget()) 14 | widget->deleteLater(); 15 | delete item; 16 | } 17 | layout->deleteLater(); 18 | } 19 | 20 | /** 21 | * @brief Constructor 22 | * @param id unique identifier of the component 23 | */ 24 | UIMathChannelComponent::UIMathChannelComponent(uint8_t id): _id(id) 25 | { 26 | QLabel *labels[4]; 27 | QSpacerItem *horSpacer; 28 | 29 | labels[0] = new QLabel("Math channel"); 30 | labels[1] = new QLabel("+= "); 31 | labels[2] = new QLabel("(Input channel"); 32 | labels[3] = new QLabel(")"); 33 | 34 | mathChSelector = new QComboBox(); 35 | inChSelector = new QSpinBox(); 36 | 37 | // Populate dropdown with operation text 38 | mathSelector = new QComboBox(); 39 | for (auto &X : MathOperationText) 40 | mathSelector->addItem(X); 41 | 42 | deleteButton = new QPushButton(); 43 | deleteButton->setText("X"); 44 | deleteButton->setFixedWidth(25); 45 | 46 | layout = new QHBoxLayout(); 47 | layout->setObjectName("mathChannel_"+QString::number(_id)); 48 | 49 | horSpacer = new QSpacerItem (20,20,QSizePolicy::Expanding); 50 | 51 | // Construct layout with all the elements 52 | layout->addWidget(labels[0], 0, Qt::AlignLeft); 53 | layout->addWidget(mathChSelector, 0, Qt::AlignLeft); 54 | layout->addWidget(labels[1], 0, Qt::AlignLeft); 55 | layout->addWidget(mathSelector, 0, Qt::AlignLeft); 56 | layout->addWidget(labels[2], 0, Qt::AlignLeft); 57 | layout->addWidget(inChSelector, 0, Qt::AlignLeft); 58 | layout->addWidget(labels[3], 0, Qt::AlignLeft); 59 | 60 | layout->addSpacerItem(horSpacer); 61 | layout->addWidget(deleteButton, 0, Qt::AlignLeft); 62 | 63 | labels[0]->setToolTip(_STYLE_TOOLTIP_("Select input channel to be used " 64 | "in math operation")); 65 | inChSelector->setToolTip(_STYLE_TOOLTIP_("Select input channel to be used " 66 | "in math operation")); 67 | labels[1]->setToolTip(_STYLE_TOOLTIP_("Select math channel that the " 68 | "operation should be a component of")); 69 | mathChSelector->setToolTip(_STYLE_TOOLTIP_("Select math channel that the " 70 | "operation should be a component of")); 71 | labels[2]->setToolTip(_STYLE_TOOLTIP_("Select arithmetic operation to be " 72 | "performed on the input channel ")); 73 | mathSelector->setToolTip(_STYLE_TOOLTIP_("Select arithmetic operation to be " 74 | "performed on the input channel ")); 75 | deleteButton->setToolTip(_STYLE_TOOLTIP_("Delete math component")); 76 | 77 | for (int i = 0; i < 6; i++) 78 | mathChSelector->addItem(QString::number(i+1)); 79 | 80 | QObject::connect(deleteButton, &QPushButton::pressed, 81 | this, &UIMathChannelComponent::deleteComponent); 82 | } 83 | 84 | /** 85 | * @brief Update the list of math channels with the newly provided one 86 | * @param mathCh Array of new math channel IDs 87 | * @param size Size of mathCh array 88 | */ 89 | void UIMathChannelComponent::UpdateMathCh(int *mathCh, int size) 90 | { 91 | int oldCh = mathChSelector->currentText().toInt(), 92 | index = -1; 93 | mathChSelector->clear(); 94 | 95 | for (int i = 0; i < size; i++) 96 | { 97 | mathChSelector->addItem(QString::number(mathCh[i])); 98 | // Attempt to preserve selected channel, if it 99 | // exists in the new list save its index and 100 | // activate it afterwards 101 | if (mathCh[i] == oldCh) 102 | index = i; 103 | } 104 | mathChSelector->setCurrentIndex(index); 105 | } 106 | 107 | /** 108 | * @brief Set selected input channel 109 | * @param inCh Input channel to take the data from for this math component 110 | */ 111 | void UIMathChannelComponent::SetInCh(int inCh) 112 | { 113 | inChSelector->setValue(inCh); 114 | } 115 | 116 | /** 117 | * @brief Get currently selected input channel 118 | * @return Currently selected input channel 119 | */ 120 | int UIMathChannelComponent::GetInCh() 121 | { 122 | return inChSelector->value(); 123 | } 124 | 125 | /** 126 | * @brief Set selected math channel for this component 127 | * @param mathCh Math channel to be associated with this math component 128 | */ 129 | void UIMathChannelComponent::SetMathCh(int mathCh) 130 | { 131 | bool valid = false; 132 | int i; 133 | 134 | // Find if desired math channel exists 135 | for (i = 0; i < mathChSelector->count(); i++) 136 | if (mathChSelector->itemText(i).toInt() == mathCh) 137 | { 138 | valid = true; 139 | break; 140 | } 141 | 142 | // If it exists, select it 143 | if (valid) 144 | mathChSelector->setCurrentIndex(i); 145 | } 146 | 147 | /** 148 | * @brief Get selected math channel for this component 149 | * @return 150 | */ 151 | int UIMathChannelComponent::GetMathCh() 152 | { 153 | return mathChSelector->currentText().toInt(); 154 | } 155 | 156 | /** 157 | * @brief Set math operation for this component 158 | * @param math id of math component 159 | */ 160 | void UIMathChannelComponent::SetMath(int math) 161 | { 162 | mathSelector->setCurrentIndex(math); 163 | } 164 | 165 | /** 166 | * @brief Get selected math operation for this component 167 | * @return id of the selected math component 168 | */ 169 | int UIMathChannelComponent::GetMath() 170 | { 171 | return mathSelector->currentIndex(); 172 | } 173 | 174 | /** 175 | * @brief [Slot] Called by parent to delete this component 176 | */ 177 | void UIMathChannelComponent::deleteComponent() 178 | { 179 | emit deleteRequested(_id); 180 | } 181 | 182 | /** 183 | * @brief Return layout of this component (used in deletion) 184 | * @return 185 | */ 186 | QHBoxLayout* UIMathChannelComponent::GetLayout() 187 | { 188 | return layout; 189 | } 190 | 191 | /** 192 | * @brief Set this component's ID 193 | * @param id id to set 194 | */ 195 | void UIMathChannelComponent::SetID(uint8_t id) 196 | { 197 | _id = id; 198 | } 199 | 200 | /** 201 | * @brief Get this component's ID 202 | * @return 203 | */ 204 | uint8_t UIMathChannelComponent::GetID() 205 | { 206 | return _id; 207 | } 208 | -------------------------------------------------------------------------------- /helperObjects/graphHeaderWidget/graphheaderwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "graphheaderwidget.h" 2 | #include "helperObjects/dataMultiplexer/datamultiplexer.h" 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /** 11 | * @brief Create header widget 12 | * Header widget contains main layout (horiz.) and two vertical 13 | * widgets inside of it containing labels and combo-boxes 14 | * 1111111111111111 15 | * 1 2222 3333 * /1 16 | * 1 2 2 3 3 * /1 17 | * 1 2222 3333 * /1 18 | * 1111111111111111 19 | * Stars depict area where extra horizontal widgets can be injected 20 | * before \ref AppendHorSpacer is called. Finally, horizontal spacer 21 | * is added in the back, shown in / 22 | * @param chnnelNum Number of input channels 23 | */ 24 | graphHeaderWidget::graphHeaderWidget(uint8_t chnnelNum, QString ParentWinName) 25 | : _parentWinName(ParentWinName), _parent(nullptr) 26 | { 27 | // Create layouts 28 | _mainLayout = new QHBoxLayout(); 29 | QVBoxLayout *chLabels = new QVBoxLayout(); 30 | QVBoxLayout *inChannels = new QVBoxLayout(); 31 | 32 | _mainLayout->addLayout(chLabels); 33 | _mainLayout->addLayout(inChannels); 34 | 35 | _inputChannelList = new uint8_t[chnnelNum]; 36 | 37 | // Loop to create channel labels and drop-downs 38 | for (uint8_t i = 0; i < chnnelNum; i++) 39 | { 40 | _inChLabel.push_back(new QLabel()); 41 | _inChLabel.back()->setText("Channel "+QString::number(i)); 42 | _inChLabel.back()->setToolTip( _STYLE_TOOLTIP_(\ 43 | "Select which input channel should be used as channel " \ 44 | + QString::number(i) + " in the plot")); 45 | _inChLabel.back()->setFixedHeight(22); 46 | 47 | _inCh.push_back(new QComboBox()); 48 | // Set fixed height for nicer look 49 | _inCh.back()->setFixedHeight(22); 50 | _inCh.back()->setToolTip( _STYLE_TOOLTIP_(\ 51 | "Select which input channel should be used as channel " \ 52 | + QString::number(i) + " in the plot")); 53 | 54 | // Trigger 'ComboBoxUpdated' function here whenever the combo-boxes 55 | // get updated 56 | QObject::connect(_inCh[i], 57 | QOverload::of(&QComboBox::currentIndexChanged), 58 | this, 59 | &graphHeaderWidget::ComboBoxUpdated); 60 | 61 | chLabels->addWidget(_inChLabel.back()); 62 | inChannels->addWidget(_inCh.back()); 63 | } 64 | UpdateChannelDropdown(); 65 | } 66 | 67 | /** 68 | * @brief Add horizontal spacer to the end of the layout 69 | * Seals the header widget once the header contains all the 70 | * necessary fields 71 | */ 72 | void graphHeaderWidget::AppendHorSpacer() 73 | { 74 | _mainLayout->addSpacerItem(new QSpacerItem (20,20,QSizePolicy::Expanding)); 75 | } 76 | 77 | /** 78 | * @brief [Slot] Called from mux to refresh the list of channels in the 79 | * drop-down menus 80 | */ 81 | void graphHeaderWidget::UpdateChannelDropdown() 82 | { 83 | QString time = QDateTime::currentDateTime().time().toString(); 84 | emit logLine("Updating channel dropdown for "+_parentWinName); 85 | for (QComboBox* X : _inCh) 86 | { 87 | emit logLine(" Processing"); 88 | // Save selected entry in an attempt to reselect it after refresh 89 | QString currentItem = X->currentText(); 90 | // Clear list 91 | X->clear(); 92 | // Insert new list 93 | X->addItems(DataMultiplexer::GetI().GetChannelList()); 94 | // Attempt to reselect old value 95 | int newIndex = X->findText(currentItem); 96 | if (newIndex >= 0) 97 | X->setCurrentIndex(newIndex); 98 | } 99 | 100 | time = QDateTime::currentDateTime().time().toString(); 101 | emit logLine("Finished updating channel dropdown for "+_parentWinName); 102 | } 103 | 104 | /** 105 | * @brief Returns reference to labels so they can be stylize or edited from 106 | * external sources 107 | * @return Reference to the vector of labels 108 | */ 109 | QVector& graphHeaderWidget::GetLabels() 110 | { 111 | return _inChLabel; 112 | } 113 | 114 | /** 115 | * @brief Returns array of selected channel names, as selected in combo boxes 116 | * @return array of channel labels 117 | */ 118 | QVector graphHeaderWidget::GetChLabels() 119 | { 120 | QVector retVal; 121 | 122 | for (QComboBox* X : _inCh) 123 | retVal.push_back(X->currentText()); 124 | 125 | return retVal; 126 | } 127 | 128 | /** 129 | * @brief Returns an array with which channels are selected on the graph 130 | * @return Vector containing indexes of selected channel in every drop-down 131 | */ 132 | QVector graphHeaderWidget::GetSelectedChannels() 133 | { 134 | QVectorretVal; 135 | 136 | for (QComboBox* X : _inCh) 137 | retVal.push_back(X->currentIndex()); 138 | 139 | return retVal; 140 | } 141 | 142 | /** 143 | * @brief Restore the selected channels in their respective drop-downs 144 | * provided the list generated by \ref graphHeaderWidget::GetSelectedChannels() 145 | * @param selectedCh list saying which id to select in which QComboBox 146 | */ 147 | void graphHeaderWidget::SetSelectedChannels(QVector &selectedCh) 148 | { 149 | for (uint8_t i = 0; i < _inCh.size(); i++) 150 | // Check that current index exists in the array 151 | if (i < selectedCh.size()) 152 | // Check that the value on current index does not exceed total 153 | // number of index on the list 154 | if (selectedCh[i] < _inCh[i]->count()) 155 | _inCh[i]->setCurrentIndex(selectedCh[i]); 156 | } 157 | 158 | /** 159 | * @brief Update tooltip of a selected channel 160 | * @param id Channel ID to be updated 161 | * @param toolTip String to use as tooltip 162 | */ 163 | void graphHeaderWidget::SetChToolTip(uint8_t id, QString toolTip) 164 | { 165 | // Check if Id is valid 166 | if ((id >= _inCh.size()) || (id >= _inChLabel.size())) 167 | return; 168 | _inChLabel[id]->setToolTip( _STYLE_TOOLTIP_(+toolTip+)); 169 | _inCh[id]->setToolTip( _STYLE_TOOLTIP_(+toolTip+)); 170 | } 171 | /** 172 | * @brief Returns main header layout 173 | * @return main header layout 174 | */ 175 | QHBoxLayout* graphHeaderWidget::GetLayout() 176 | { 177 | return _mainLayout; 178 | } 179 | 180 | /** 181 | * @brief [Private Slot] Handles pushing an updated list of input channels to 182 | * the parent window 183 | * Called by the combo-boxes when their value is changed 184 | */ 185 | void graphHeaderWidget::ComboBoxUpdated(const int &) 186 | { 187 | for (uint8_t i = 0; i < _inCh.size(); i++) 188 | _inputChannelList[i] = _inCh[i]->currentIndex(); 189 | 190 | emit UpdateInputChannels(_inputChannelList); 191 | } 192 | 193 | graphHeaderWidget::~graphHeaderWidget() 194 | { 195 | delete [] _inputChannelList; 196 | } 197 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/geometryengine.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCore module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include "geometryengine.h" 52 | 53 | #include 54 | #include 55 | 56 | struct VertexData 57 | { 58 | QVector3D position; 59 | QVector2D texCoord; 60 | }; 61 | 62 | //! [0] 63 | GeometryEngine::GeometryEngine() 64 | : indexBuf(QOpenGLBuffer::IndexBuffer) 65 | { 66 | initializeOpenGLFunctions(); 67 | 68 | // Generate 2 VBOs 69 | arrayBuf.create(); 70 | indexBuf.create(); 71 | 72 | // Initializes cube geometry and transfers it to VBOs 73 | initCubeGeometry(); 74 | } 75 | 76 | GeometryEngine::~GeometryEngine() 77 | { 78 | arrayBuf.destroy(); 79 | indexBuf.destroy(); 80 | } 81 | //! [0] 82 | 83 | void GeometryEngine::initCubeGeometry() 84 | { 85 | // For cube we would need only 8 vertices but we have to 86 | // duplicate vertex for each face because texture coordinate 87 | // is different. 88 | VertexData vertices[] = { 89 | // Vertex data for face 0 90 | {QVector3D(-1.0f, -1.0f, 1.0f), QVector2D(0.0f, 0.0f)}, // v0 91 | {QVector3D( 1.0f, -1.0f, 1.0f), QVector2D(0.33f, 0.0f)}, // v1 92 | {QVector3D(-1.0f, 1.0f, 1.0f), QVector2D(0.0f, 0.5f)}, // v2 93 | {QVector3D( 1.0f, 1.0f, 1.0f), QVector2D(0.33f, 0.5f)}, // v3 94 | 95 | // Vertex data for face 1 96 | {QVector3D( 1.0f, -1.0f, 1.0f), QVector2D( 0.0f, 0.5f)}, // v4 97 | {QVector3D( 1.0f, -1.0f, -1.0f), QVector2D(0.33f, 0.5f)}, // v5 98 | {QVector3D( 1.0f, 1.0f, 1.0f), QVector2D(0.0f, 1.0f)}, // v6 99 | {QVector3D( 1.0f, 1.0f, -1.0f), QVector2D(0.33f, 1.0f)}, // v7 100 | 101 | // Vertex data for face 2 102 | {QVector3D( 1.0f, -1.0f, -1.0f), QVector2D(0.66f, 0.5f)}, // v8 103 | {QVector3D(-1.0f, -1.0f, -1.0f), QVector2D(1.0f, 0.5f)}, // v9 104 | {QVector3D( 1.0f, 1.0f, -1.0f), QVector2D(0.66f, 1.0f)}, // v10 105 | {QVector3D(-1.0f, 1.0f, -1.0f), QVector2D(1.0f, 1.0f)}, // v11 106 | 107 | // Vertex data for face 3 108 | {QVector3D(-1.0f, -1.0f, -1.0f), QVector2D(0.66f, 0.0f)}, // v12 109 | {QVector3D(-1.0f, -1.0f, 1.0f), QVector2D(1.0f, 0.0f)}, // v13 110 | {QVector3D(-1.0f, 1.0f, -1.0f), QVector2D(0.66f, 0.5f)}, // v14 111 | {QVector3D(-1.0f, 1.0f, 1.0f), QVector2D(1.0f, 0.5f)}, // v15 112 | 113 | // Vertex data for face 4 114 | {QVector3D(-1.0f, -1.0f, -1.0f), QVector2D(0.33f, 0.0f)}, // v16 115 | {QVector3D( 1.0f, -1.0f, -1.0f), QVector2D(0.66f, 0.0f)}, // v17 116 | {QVector3D(-1.0f, -1.0f, 1.0f), QVector2D(0.33f, 0.5f)}, // v18 117 | {QVector3D( 1.0f, -1.0f, 1.0f), QVector2D(0.66f, 0.5f)}, // v19 118 | 119 | // Vertex data for face 5 120 | {QVector3D(-1.0f, 1.0f, 1.0f), QVector2D(0.33f, 0.5f)}, // v20 121 | {QVector3D( 1.0f, 1.0f, 1.0f), QVector2D(0.66f, 0.5f)}, // v21 122 | {QVector3D(-1.0f, 1.0f, -1.0f), QVector2D(0.33f, 1.0f)}, // v22 123 | {QVector3D( 1.0f, 1.0f, -1.0f), QVector2D(0.66f, 1.0f)} // v23 124 | }; 125 | 126 | // Indices for drawing cube faces using triangle strips. 127 | // Triangle strips can be connected by duplicating indices 128 | // between the strips. If connecting strips have opposite 129 | // vertex order then last index of the first strip and first 130 | // index of the second strip needs to be duplicated. If 131 | // connecting strips have same vertex order then only last 132 | // index of the first strip needs to be duplicated. 133 | GLushort indices[] = { 134 | 0, 1, 2, 3, 3, // Face 0 - triangle strip ( v0, v1, v2, v3) 135 | 4, 4, 5, 6, 7, 7, // Face 1 - triangle strip ( v4, v5, v6, v7) 136 | 8, 8, 9, 10, 11, 11, // Face 2 - triangle strip ( v8, v9, v10, v11) 137 | 12, 12, 13, 14, 15, 15, // Face 3 - triangle strip (v12, v13, v14, v15) 138 | 16, 16, 17, 18, 19, 19, // Face 4 - triangle strip (v16, v17, v18, v19) 139 | 20, 20, 21, 22, 23 // Face 5 - triangle strip (v20, v21, v22, v23) 140 | }; 141 | 142 | //! [1] 143 | // Transfer vertex data to VBO 0 144 | arrayBuf.bind(); 145 | arrayBuf.allocate(vertices, 24 * sizeof(VertexData)); 146 | 147 | // Transfer index data to VBO 1 148 | indexBuf.bind(); 149 | indexBuf.allocate(indices, 34 * sizeof(GLushort)); 150 | //! [1] 151 | } 152 | 153 | //! [2] 154 | void GeometryEngine::drawCubeGeometry(QOpenGLShaderProgram *program) 155 | { 156 | // Tell OpenGL which VBOs to use 157 | arrayBuf.bind(); 158 | indexBuf.bind(); 159 | 160 | // Offset for position 161 | quintptr offset = 0; 162 | 163 | // Tell OpenGL programmable pipeline how to locate vertex position data 164 | int vertexLocation = program->attributeLocation("a_position"); 165 | program->enableAttributeArray(vertexLocation); 166 | program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(VertexData)); 167 | 168 | // Offset for texture coordinate 169 | offset += sizeof(QVector3D); 170 | 171 | // Tell OpenGL programmable pipeline how to locate vertex texture coordinate data 172 | int texcoordLocation = program->attributeLocation("a_texcoord"); 173 | program->enableAttributeArray(texcoordLocation); 174 | program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData)); 175 | 176 | // Draw cube geometry using indices from VBO 1 177 | glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, nullptr); 178 | } 179 | //! [2] 180 | -------------------------------------------------------------------------------- /plotWindows/orientation_3d/orientationwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "orientationwindow.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | OrientationWindow::OrientationWindow(QWidget *parent, QString objName): _nInputs(3) 10 | { 11 | this->setParent(parent); 12 | this->setObjectName(objName); 13 | // Create container window 14 | _contWind = new QWidget(); 15 | this->setWidget(_contWind); 16 | windMainLayout = new QVBoxLayout(_contWind); 17 | 18 | _ConstructUI(); 19 | } 20 | 21 | OrientationWindow::~OrientationWindow() 22 | { 23 | emit logLine("3D: Destroying the plot"); 24 | DataMultiplexer::GetI().UnregisterGraph(this); 25 | 26 | disconnect(DataMultiplexer::GetP(), 27 | &DataMultiplexer::ChannelsUpdated, 28 | _header, 29 | &graphHeaderWidget::UpdateChannelDropdown); 30 | MainWindow::clearLayout(_contWind->layout()); 31 | } 32 | 33 | /** 34 | * @brief Constructs UI based on configuration variables 35 | * Separated from the constructor to allow layout changes on runtime 36 | */ 37 | void OrientationWindow::_ConstructUI() 38 | { 39 | // Check if UI is already been constructed, then destroy it 40 | if (!_contWind->layout()->isEmpty()) 41 | { 42 | emit logLine("3D: Deconstructing existing UI"); 43 | DataMultiplexer::GetI().UnregisterGraph(this); 44 | // Make sure input channel drop-downs have updated list of channels 45 | disconnect(DataMultiplexer::GetP(), 46 | &DataMultiplexer::ChannelsUpdated, 47 | _header, 48 | &graphHeaderWidget::UpdateChannelDropdown); 49 | MainWindow::clearLayout(_contWind->layout()); 50 | } 51 | 52 | QString mode = ""; 53 | if (_nInputs == 3) 54 | mode = "Euler mode"; 55 | else 56 | mode = "Quaternion mode"; 57 | 58 | emit logLine("3D: Constructing new UI in " + mode); 59 | 60 | // Basic header with input channel drop-downs 61 | _header = new graphHeaderWidget(_nInputs, this->objectName()); 62 | windMainLayout->addLayout(_header->GetLayout()); 63 | 64 | // Line to separate channels from config 65 | QFrame *_vertLine = new QFrame(); 66 | _vertLine->setFrameShape(QFrame::VLine); 67 | _vertLine->setFrameShadow(QFrame::Sunken); 68 | _header->GetLayout()->addWidget(_vertLine); 69 | 70 | // Header items for orientation plot 71 | QVBoxLayout *orientationSpecificHeader = new QVBoxLayout(); 72 | _header->GetLayout()->addLayout(orientationSpecificHeader); 73 | _header->AppendHorSpacer(); 74 | 75 | // Radio buttons for switching between euler and quat input 76 | QRadioButton *rpyInput = new QRadioButton(); 77 | rpyInput->setText("Euler (RPY)"); 78 | rpyInput->setToolTip(_STYLE_TOOLTIP_(\ 79 | "Orientation is supplied as Euler angles in degrees")); 80 | 81 | QRadioButton *quatInput = new QRadioButton(); 82 | quatInput->setText("Quaternion (w,x,y,z)"); 83 | quatInput->setToolTip(_STYLE_TOOLTIP_(\ 84 | "Orientation is supplied as a normalized quaternion")); 85 | 86 | // Add radio buttons to the header widget 87 | if (_nInputs == 3) 88 | rpyInput->setChecked(true); 89 | else 90 | quatInput->setChecked(true); 91 | orientationSpecificHeader->addWidget(new QLabel("Input type")); 92 | orientationSpecificHeader->addWidget(rpyInput); 93 | orientationSpecificHeader->addWidget(quatInput); 94 | orientationSpecificHeader->addSpacerItem(new QSpacerItem (20,20,QSizePolicy::Expanding)); 95 | 96 | connect(rpyInput, &QRadioButton::toggled, 97 | this, &OrientationWindow::InputTypeUpdated); 98 | 99 | // 3D orientation widget 100 | _widget3d = new OrientationWidget(); 101 | _widget3d->setMinimumSize(QSize(200,200)); 102 | _widget3d->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 103 | windMainLayout->addWidget(_widget3d); 104 | 105 | // Make sure input channel drop-downs have updated list of channels 106 | QObject::connect(DataMultiplexer::GetP(), 107 | &DataMultiplexer::ChannelsUpdated, 108 | _header, 109 | &graphHeaderWidget::UpdateChannelDropdown); 110 | // Handle dynamic channel selection by drop-down 111 | QObject::connect(_header, &graphHeaderWidget::UpdateInputChannels, 112 | this, &OrientationWindow::UpdateInputChannels); 113 | 114 | for (uint8_t i = 0; i < _nInputs; i++) 115 | _inputChannels[i] = 0; 116 | 117 | _maxInChannel = 0; 118 | 119 | // Update channel names in the header 120 | if (_nInputs == 3) 121 | { 122 | _header->GetLabels()[0]->setText("Roll"); 123 | _header->SetChToolTip(0, _STYLE_TOOLTIP_("Cube roll")); 124 | _header->GetLabels()[1]->setText("Pitch"); 125 | _header->SetChToolTip(1, _STYLE_TOOLTIP_("Cube pitch")); 126 | _header->GetLabels()[2]->setText("Yaw"); 127 | _header->SetChToolTip(2, _STYLE_TOOLTIP_("Cube yaw")); 128 | } 129 | else if (_nInputs == 4) 130 | { 131 | _header->GetLabels()[0]->setText("w"); 132 | _header->SetChToolTip(0, _STYLE_TOOLTIP_("Quaternion w component")); 133 | _header->GetLabels()[1]->setText("x"); 134 | _header->SetChToolTip(1, _STYLE_TOOLTIP_("Quaternion x component")); 135 | _header->GetLabels()[2]->setText("y"); 136 | _header->SetChToolTip(2, _STYLE_TOOLTIP_("Quaternion y component")); 137 | _header->GetLabels()[3]->setText("z"); 138 | _header->SetChToolTip(3, _STYLE_TOOLTIP_("Quaternion z component")); 139 | } 140 | 141 | // Register with the mux 142 | DataMultiplexer::GetI().RegisterGraph(this->objectName(), _nInputs, this); 143 | } 144 | 145 | /** 146 | * @brief [Slot] Handle switching between the plot modes (euler vs quat.) 147 | * @param rpySelected 'true' if euler mode has been selected 148 | */ 149 | void OrientationWindow::InputTypeUpdated(bool rpySelected) 150 | { 151 | emit logLine("3D: Mode change requested"); 152 | if (rpySelected) 153 | _nInputs = 3; 154 | else 155 | _nInputs = 4; 156 | 157 | _ConstructUI(); 158 | } 159 | 160 | /** 161 | * @brief Function directly called by the multiplexer to push data into 162 | * the graph 163 | * @param data Array of available data 164 | * @param n Size of data array 165 | */ 166 | void OrientationWindow::ReceiveData(double *data, uint8_t n) 167 | { 168 | // Check if the largest index of input channels is available in the 169 | // received block of data 170 | if (n < _maxInChannel) 171 | return; 172 | 173 | // Update rotation 174 | if (_nInputs == 3) 175 | _widget3d->rotation = \ 176 | QQuaternion::fromEulerAngles( (float)data[ _inputChannels[1] ], 177 | (float)data[ _inputChannels[2] ], 178 | (float)data[ _inputChannels[0] ] ); 179 | else 180 | _widget3d->rotation = \ 181 | QQuaternion((float)data[ _inputChannels[0] ], 182 | (float)data[ _inputChannels[1] ], 183 | (float)data[ _inputChannels[2] ], 184 | (float)data[ _inputChannels[3] ] ); 185 | 186 | _widget3d->update();; 187 | } 188 | 189 | /** 190 | * @brief [Slot] Function that is called whenever input channel has been 191 | * changed in the drop-down fields of the header. It updates the channels 192 | * used as data sources for the plot. 193 | * @param inChannels Array of 3 input channel indexes 194 | */ 195 | void OrientationWindow::UpdateInputChannels(uint8_t *inChannels) 196 | { 197 | emit logLine("3D: Updating input channels"); 198 | _inputChannels[0] = inChannels[0]; 199 | _inputChannels[1] = inChannels[1]; 200 | _inputChannels[2] = inChannels[2]; 201 | 202 | _maxInChannel = 0; 203 | for (uint8_t i = 0; i < 3; i++) 204 | if (inChannels[i] > _maxInChannel) 205 | _maxInChannel = inChannels[i]; 206 | } 207 | -------------------------------------------------------------------------------- /plotWindows/scatter/scatterwindow.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:GPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** GNU General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU 19 | ** General Public License version 3 or (at your option) any later version 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 22 | ** included in the packaging of this file. Please review the following 23 | ** information to ensure the GNU General Public License requirements will 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 25 | ** 26 | ** $QT_END_LICENSE$ 27 | ** 28 | ****************************************************************************/ 29 | 30 | #include "scatterwindow.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | 46 | using namespace QtDataVisualization; 47 | 48 | const int dataSize = 10000; 49 | 50 | ScatterWindow::ScatterWindow(QString objName): _plotDataSize(dataSize) 51 | { 52 | _graph = new Q3DScatter(); 53 | this->setObjectName(objName); 54 | // Create container window and set size policy 55 | _contWind = new QWidget(); 56 | 57 | // Main vertical layout 58 | QVBoxLayout *windMainLayout = new QVBoxLayout(_contWind); 59 | this->setWidget(_contWind); 60 | 61 | _header = new graphHeaderWidget(3, this->objectName()); 62 | windMainLayout->addLayout(_header->GetLayout()); 63 | // Update channel labels 64 | _header->GetLabels()[0]->setText("X-axis"); 65 | _header->SetChToolTip(0, \ 66 | _STYLE_TOOLTIP_("Select X-axis of the scatter plot")); 67 | _header->GetLabels()[1]->setText("Y-axis"); 68 | _header->SetChToolTip(1, \ 69 | _STYLE_TOOLTIP_("Select Y-axis of the scatter plot")); 70 | _header->GetLabels()[2]->setText("Z-axis"); 71 | _header->SetChToolTip(2, \ 72 | _STYLE_TOOLTIP_("Select Z-axis of the scatter plot")); 73 | 74 | // Line to separate channels from config 75 | QFrame *_vertLine = new QFrame(); 76 | _vertLine->setFrameShape(QFrame::VLine); 77 | _vertLine->setFrameShadow(QFrame::Sunken); 78 | _header->GetLayout()->addWidget(_vertLine); 79 | 80 | // Header items for orientation plot 81 | QVBoxLayout *scatterSpecificHeader = new QVBoxLayout(); 82 | _header->GetLayout()->addLayout(scatterSpecificHeader); 83 | _header->AppendHorSpacer(); 84 | 85 | // Data size line edit 86 | scatterSpecificHeader->addWidget(new QLabel("Data size")); 87 | QLineEdit *_plotDataSizeLE = new QLineEdit(); 88 | _plotDataSizeLE->setValidator( new QIntValidator(1, _plotDataSize*10, this) ); 89 | _plotDataSizeLE->setToolTip(_STYLE_TOOLTIP_("Number of past data points " 90 | "kept in the graph (automatically updated)")); 91 | _plotDataSizeLE->setText(QString::number(_plotDataSize)); 92 | 93 | QObject::connect(_plotDataSizeLE, &QLineEdit::textChanged, 94 | this, &ScatterWindow::on_dataSize_changed); 95 | scatterSpecificHeader->addWidget(_plotDataSizeLE); 96 | // Reset data set push button 97 | QPushButton *resetView = new QPushButton(); 98 | resetView->setText("Clear data"); 99 | resetView->setToolTip(_STYLE_TOOLTIP_("Press to clear all data from the" 100 | " scatter plot")); 101 | QObject::connect(resetView, &QPushButton::pressed, 102 | this, &ScatterWindow::on_resetData_pressed); 103 | scatterSpecificHeader->addWidget(resetView); 104 | 105 | 106 | QWidget *graphCont = QWidget::createWindowContainer(_graph); 107 | graphCont->setMinimumSize(QSize(200,200)); 108 | graphCont->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 109 | windMainLayout->addWidget(graphCont,1); 110 | 111 | 112 | // Handle dynamic channel selection by drop-down 113 | QObject::connect(_header, &graphHeaderWidget::UpdateInputChannels, 114 | this, &ScatterWindow::UpdateInputChannels); 115 | 116 | // Make sure input channel drop-downs have updated list of channels 117 | QObject::connect(DataMultiplexer::GetP(), 118 | &DataMultiplexer::ChannelsUpdated, 119 | _header, 120 | &graphHeaderWidget::UpdateChannelDropdown); 121 | 122 | // Stylize the graph 123 | _graph->activeTheme()->setType(Q3DTheme::ThemeEbony); 124 | QFont font = _graph->activeTheme()->font(); 125 | font.setPointSize(40.0f); 126 | _graph->activeTheme()->setFont(font); 127 | _graph->setShadowQuality(QAbstract3DGraph::ShadowQualityNone); 128 | _graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront); 129 | 130 | QScatterDataProxy *proxy = new QScatterDataProxy(this); 131 | QScatter3DSeries *series = new QScatter3DSeries(proxy, this); 132 | series->setItemLabelFormat(QStringLiteral("@xTitle: @xLabel @yTitle: @yLabel @zTitle: @zLabel")); 133 | series->setMeshSmooth(true); 134 | 135 | // Add data series we'll be working with 136 | _graph->addSeries(series); 137 | if (_graph->seriesList().size()) 138 | _graph->seriesList().at(0)->setMesh(QAbstract3DSeries::MeshPoint); 139 | _graph->activeTheme()->setBackgroundEnabled(false); 140 | changeFont(QFont("Arial")); 141 | 142 | _dataArray = new QScatterDataArray(); 143 | _dataArray->resize(_plotDataSize); 144 | 145 | _graph->seriesList().at(0)->dataProxy()->resetArray(_dataArray); 146 | 147 | // Register with the mux 148 | DataMultiplexer::GetI().RegisterGraph(this->objectName(), 3, this); 149 | } 150 | 151 | /** 152 | * @brief ScatterWindow::~ScatterWindow 153 | */ 154 | ScatterWindow::~ScatterWindow() 155 | { 156 | emit logLine("Scatter: Destroying the plot"); 157 | DataMultiplexer::GetI().UnregisterGraph(this); 158 | 159 | QObject::disconnect(DataMultiplexer::GetP(), 160 | &DataMultiplexer::ChannelsUpdated, 161 | _header, 162 | &graphHeaderWidget::UpdateChannelDropdown); 163 | 164 | QObject::disconnect(_header, &graphHeaderWidget::UpdateInputChannels, 165 | this, &ScatterWindow::UpdateInputChannels); 166 | delete _header; 167 | 168 | _graph->seriesList().clear(); 169 | _graph->close(); 170 | delete _graph; 171 | 172 | MainWindow::clearLayout(_contWind->layout()); 173 | } 174 | 175 | /** 176 | * @brief [Slot] Function that is called whenever input channel has been 177 | * changed in the drop-down fields of the header. It updates the channels 178 | * used as data sources for the plot. 179 | * @param inChannels Array of 3 input channel indexes 180 | */ 181 | void ScatterWindow::UpdateInputChannels(uint8_t *inChannels) 182 | { 183 | emit logLine("Scatter: Updating input channels"); 184 | _inputChannels[0] = inChannels[0]; 185 | _inputChannels[1] = inChannels[1]; 186 | _inputChannels[2] = inChannels[2]; 187 | 188 | _maxInChannel = 0; 189 | for (uint8_t i = 0; i < 3; i++) 190 | if (inChannels[i] > _maxInChannel) 191 | _maxInChannel = inChannels[i]; 192 | 193 | _graph->axisX()->setTitle(_header->GetChLabels()[0]); 194 | _graph->axisY()->setTitle(_header->GetChLabels()[1]); 195 | _graph->axisZ()->setTitle(_header->GetChLabels()[2]); 196 | 197 | // Reset plot on channel change 198 | on_resetData_pressed(); 199 | } 200 | 201 | /** 202 | * @brief Function directly called by the multiplexer to push data into 203 | * the graph 204 | * @param data Array of available data 205 | * @param n Size of data array 206 | */ 207 | void ScatterWindow::ReceiveData(double *data, uint8_t n) 208 | { 209 | static uint32_t index = 0; 210 | // Check if the largest index of input channels is available in the 211 | // received block of data 212 | if (n < _maxInChannel) 213 | return; 214 | 215 | _graph->seriesList().at(0)->dataProxy()->setItem(index,QScatterDataItem(QVector3D( (float)data[ _inputChannels[0] ], 216 | (float)data[ _inputChannels[1] ], 217 | (float)data[ _inputChannels[2] ]))); 218 | index = (index+1) % _plotDataSize; 219 | } 220 | 221 | 222 | void ScatterWindow::changeFont(const QFont &font) 223 | { 224 | QFont newFont = font; 225 | newFont.setPointSizeF(40.0f); 226 | _graph->activeTheme()->setFont(newFont); 227 | } 228 | 229 | 230 | void ScatterWindow::setGridEnabled(int enabled) 231 | { 232 | _graph->activeTheme()->setGridEnabled((bool)enabled); 233 | } 234 | 235 | /** 236 | * @brief [Slot] Handles change in data size line edit 237 | * @param __plotDataSize Current text of line edit 238 | */ 239 | void ScatterWindow::on_dataSize_changed(const QString &__plotDataSize) 240 | { 241 | // Safe to assign, validation rule defined in the constructor 242 | _plotDataSize = __plotDataSize.toInt(); 243 | 244 | _dataArray->resize(_plotDataSize); 245 | _graph->seriesList().at(0)->dataProxy()->resetArray(_dataArray); 246 | } 247 | 248 | /** 249 | * @brief [Slot] Handles press of a 'Reset data button' 250 | */ 251 | void ScatterWindow::on_resetData_pressed() 252 | { 253 | emit logLine("Scatter: Data reset requested"); 254 | _dataArray->clear(); 255 | _dataArray->resize(_plotDataSize); 256 | _graph->seriesList().at(0)->dataProxy()->resetArray(_dataArray); 257 | } 258 | -------------------------------------------------------------------------------- /plotWindows/line/lineplot.cpp: -------------------------------------------------------------------------------- 1 | #include "lineplot.h" 2 | #include "helperObjects/dataMultiplexer/datamultiplexer.h" 3 | #include 4 | 5 | 6 | const uint32_t XaxisSize = 500; 7 | 8 | LinePlot::LinePlot(QString objName): _nInputs(1), _maxInChannel(0), _XaxisSize(XaxisSize) 9 | { 10 | // Create container window 11 | _contWind = new QWidget(); 12 | this->setObjectName(objName); 13 | windMainLayout = new QVBoxLayout(_contWind); 14 | this->setWidget(_contWind); 15 | 16 | _refresher = new QTimer(this); 17 | 18 | _ConstructUI(); 19 | 20 | _plotDataMutex.release(); 21 | } 22 | 23 | LinePlot::~LinePlot() 24 | { 25 | emit logLine("Line: Destroying the plot"); 26 | DataMultiplexer::GetI().UnregisterGraph(this); 27 | // Wait to get mutex before deleting the rest. Prevents rare crashes 28 | // when closing the window 29 | _plotDataMutex.acquire(); 30 | _refresher->stop(); 31 | disconnect(_refresher, SIGNAL(timeout()), _plot, SLOT(replot())); 32 | disconnect(DataMultiplexer::GetP(), 33 | &DataMultiplexer::ChannelsUpdated, 34 | _header, 35 | &graphHeaderWidget::UpdateChannelDropdown); 36 | _plotDataMutex.release(); 37 | MainWindow::clearLayout(_contWind->layout()); 38 | } 39 | 40 | /** 41 | * @brief Constructs UI based on configuration variables 42 | * Separated from the constructor to allow layout changes on runtime 43 | */ 44 | void LinePlot::_ConstructUI() 45 | { 46 | // Save old plot settings 47 | QVector selectedChannels; 48 | bool autoRefresh = true, 49 | accumulate = false; 50 | double yMin = -1, 51 | yMax = 1; 52 | 53 | // Check if UI is already been constructed, then destroy it 54 | if (!_contWind->layout()->isEmpty()) 55 | { 56 | // Loop to drop-downs and save selected channels 57 | selectedChannels = _header->GetSelectedChannels(); 58 | autoRefresh = _autoAdjustYaxis->isChecked(); 59 | accumulate = _accumulate->isChecked(); 60 | yMax = _plot->yAxis->range().upper; 61 | yMin = _plot->yAxis->range().lower; 62 | 63 | emit logLine("Line: Deconstructing existing UI"); 64 | _refresher->stop(); 65 | DataMultiplexer::GetI().UnregisterGraph(this); 66 | disconnect(_refresher, SIGNAL(timeout()), _plot, SLOT(replot())); 67 | disconnect(DataMultiplexer::GetP(), 68 | &DataMultiplexer::ChannelsUpdated, 69 | _header, 70 | &graphHeaderWidget::UpdateChannelDropdown); 71 | MainWindow::clearLayout(_contWind->layout()); 72 | } 73 | 74 | emit logLine("Line: Constructing new UI with "+QString::number(_nInputs)+" channels"); 75 | 76 | // Basic header with input channel drop-downs 77 | _header = new graphHeaderWidget(_nInputs, this->objectName()); 78 | windMainLayout->addLayout(_header->GetLayout()); 79 | 80 | // Reselect the channels 81 | _header->SetSelectedChannels(selectedChannels); 82 | 83 | // Handle dynamic channel selection by drop-down 84 | QObject::connect(_header, &graphHeaderWidget::UpdateInputChannels, 85 | this, &LinePlot::UpdateInputChannels); 86 | 87 | // Make sure input channel drop-downs have updated list of channels 88 | QObject::connect(DataMultiplexer::GetP(), 89 | &DataMultiplexer::ChannelsUpdated, 90 | _header, 91 | &graphHeaderWidget::UpdateChannelDropdown); 92 | 93 | // Line to separate channels from config 94 | QFrame *_vertLine = new QFrame(); 95 | _vertLine->setFrameShape(QFrame::VLine); 96 | _vertLine->setFrameShadow(QFrame::Sunken); 97 | _header->GetLayout()->addWidget(_vertLine); 98 | 99 | // Extra parts of header, specific to Line plot 100 | QVBoxLayout *lineSpecificHeader = new QVBoxLayout(); 101 | _header->GetLayout()->addLayout(lineSpecificHeader); 102 | _header->AppendHorSpacer(); 103 | 104 | // 'Add plot' button and add it to the layout 105 | QPushButton *addPlot = new QPushButton(); 106 | addPlot->setText("Add channel"); 107 | addPlot->setToolTip(_STYLE_TOOLTIP_("Add new channel to the plot")); 108 | addPlot->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); 109 | connect(addPlot, SIGNAL(pressed()), this, SLOT(ChannelAdded())); 110 | lineSpecificHeader->addWidget(addPlot); 111 | 112 | QHBoxLayout *plotOptions = new QHBoxLayout(); 113 | // Checkbox to toggle automatic scaling on y-axis 114 | _autoAdjustYaxis = new QCheckBox(); 115 | _autoAdjustYaxis->setText("Auto Y scale"); 116 | _autoAdjustYaxis->setChecked(autoRefresh); 117 | _autoAdjustYaxis->setToolTip(_STYLE_TOOLTIP_("When checked, Y-range is " 118 | "automatically enlarged to fit all data")); 119 | plotOptions->addWidget(_autoAdjustYaxis); 120 | 121 | _accumulate = new QCheckBox(); 122 | _accumulate->setText("Accumulate data(!)"); 123 | _accumulate->setToolTip(_STYLE_TOOLTIP_("Experimental feature! It will " 124 | "accumulate data for as long as there's available memory. There's " 125 | "no checks for available memory so it has a potential to crash the program.")); 126 | _accumulate->setChecked(accumulate); 127 | _accumulate->setVisible(true); 128 | connect(_accumulate, &QCheckBox::toggled, this, &LinePlot::_toggleAccumulatedMode); 129 | // TODO: Implement accumulated data logging 130 | plotOptions->addWidget(_accumulate); 131 | 132 | lineSpecificHeader->addLayout(plotOptions); 133 | 134 | // Textbox to update the size of x-axis 135 | QLineEdit *xAxisSize = new QLineEdit(); 136 | xAxisSize->setValidator( new QIntValidator(10, 5000, this) ); 137 | xAxisSize->setToolTip(_STYLE_TOOLTIP_("Change the length of X axis: Number" 138 | " of past samples used to plot the curve with. Limited to 5000 samples")); 139 | xAxisSize->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); 140 | xAxisSize->setText( QString::number(_XaxisSize) ); 141 | connect(xAxisSize, &QLineEdit::textChanged, this, &LinePlot::UpdateXaxis); 142 | lineSpecificHeader->addWidget(new QLabel("X axis size")); 143 | lineSpecificHeader->addWidget(xAxisSize); 144 | 145 | lineSpecificHeader->addSpacerItem(new QSpacerItem (20,20,QSizePolicy::Expanding)); 146 | 147 | // Create plot 148 | _plot = new QCustomPlot(); 149 | _plot->setMinimumSize(QSize(200,200)); 150 | _plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 151 | connect(_refresher, SIGNAL(timeout()), _plot, SLOT(replot())); 152 | 153 | if (_inputCh.size() < _nInputs) 154 | _inputCh.resize(_nInputs); 155 | 156 | // Based on the number of inputs, add graphs into the plot 157 | for (uint8_t i = 0; i < _nInputs; i++) 158 | { 159 | _plot->addGraph(); 160 | // There's 19 predefined colours, make sure we assign a unique colour 161 | // to a channel, but never overflow 162 | _plot->graph()->setPen(QPen((Qt::GlobalColor)((i+6) % 19))); 163 | 164 | // Match label of the channel to the graph colour 165 | QPalette palette = _header->GetLabels()[i]->palette(); 166 | palette.setColor(_header->GetLabels()[i]->foregroundRole(), (Qt::GlobalColor)((i+6) % 19)); 167 | _header->GetLabels()[i]->setPalette(palette); 168 | 169 | _inputCh[i].resize(_XaxisSize); 170 | } 171 | 172 | _inputChannels.resize(_nInputs); 173 | 174 | // General graph configuration, common to all graphs 175 | _plot->axisRect()->setupFullAxesBox(true); 176 | _plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); 177 | _plot->axisRect()->setRangeZoom(Qt::Vertical); 178 | _plot->axisRect()->setRangeDrag(Qt::Vertical); 179 | _plot->xAxis->setRange(-(double)_XaxisSize, 0); 180 | _plot->yAxis->setRange(yMin, yMax); 181 | 182 | // Populate X-axis values 183 | _xAxis.resize(_XaxisSize); 184 | for (uint32_t i = 0; i < _XaxisSize; i++) 185 | _xAxis[i] = (double)i - (double)_XaxisSize; 186 | 187 | // Plot is configured, add to the window 188 | windMainLayout->addWidget(_plot); 189 | 190 | // Restart the timer for refreshing UI 191 | _refresher->start(20); 192 | 193 | // Register with the mux 194 | DataMultiplexer::GetI().RegisterGraph(this->objectName(), _nInputs, this); 195 | } 196 | 197 | 198 | /** 199 | * @brief [Slot] Called when "Add channel" has been pressed 200 | * Handles reconstructing the UI to add another data channel onto 201 | * the line plot 202 | */ 203 | void LinePlot::ChannelAdded() 204 | { 205 | emit logLine("Line: Waiting for mutex to update channel count"); 206 | _plotDataMutex.acquire(); 207 | 208 | _nInputs++; 209 | _ConstructUI(); 210 | 211 | _plotDataMutex.release(); 212 | emit logLine("Line: Finished updating channel count"); 213 | } 214 | 215 | /** 216 | * @brief [Slot] Called when 'Accumulated' checkbox has been toggled 217 | * Handles switching between data-accumulation and normal mode 218 | * @param state True if data-accumulation has been enabled in UI 219 | */ 220 | void LinePlot::_toggleAccumulatedMode(bool state) 221 | { 222 | 223 | if (state) 224 | { 225 | // Data-accumulation mode 226 | _xAxis.resize(1); 227 | _xAxis[0] = 0; 228 | 229 | for (uint8_t i = 0; i < _nInputs; i++) 230 | _inputCh[i].resize(1); 231 | } 232 | else 233 | { 234 | // Normal mode 235 | // Populate X-axis values 236 | _xAxis.resize(_XaxisSize); 237 | for (uint32_t i = 0; i < _XaxisSize; i++) 238 | _xAxis[i] = (double)i - (double)_XaxisSize; 239 | // Limit plot to the actual size of X-axis 240 | _plot->xAxis->setRange(-(double)_XaxisSize, 0); 241 | // Clean up channel data arrays 242 | for (uint8_t i = 0; i < _nInputs; i++) 243 | _inputCh[i].resize(_XaxisSize); 244 | } 245 | } 246 | 247 | /** 248 | * @brief [Slot] Adjust length of X axis in UI based on user input 249 | * Called when textbox in UI is edited. Changes the size of X axis 250 | * @param _dataSize 251 | */ 252 | void LinePlot::UpdateXaxis(const QString &_dataSize) 253 | { 254 | _plotDataMutex.acquire(); 255 | emit logLine("Line: Updating x-axis size to: "+_dataSize); 256 | 257 | _XaxisSize = _dataSize.toUInt(); 258 | 259 | // Adjust plot range 260 | _plot->xAxis->setRange(-(double)_XaxisSize, 0); 261 | 262 | // Populate X-axis vector 263 | _xAxis.resize(_XaxisSize); 264 | for (uint32_t i = 0; i < _XaxisSize; i++) 265 | _xAxis[i] = (double)i - (double)_XaxisSize; 266 | 267 | // Resize input arrays 268 | for (uint8_t i = 0; i < _nInputs; i++) 269 | { 270 | _inputCh[i].clear(); 271 | _inputCh[i].resize(_XaxisSize); 272 | } 273 | 274 | _plotDataMutex.release(); 275 | } 276 | /** 277 | * @brief [Slot] Function called whenever input channel has been 278 | * changed in the drop-down fields of the header. It updates the channels 279 | * used as data sources for the plot. 280 | * @param inChannels Array of \ref _nInputs input channel indexes 281 | */ 282 | void LinePlot::UpdateInputChannels(uint8_t *inChannels) 283 | { 284 | 285 | emit logLine("Line: Input channels"); 286 | 287 | if (_header->GetLabels().size() != _nInputs) 288 | { 289 | emit logLine("Line: Inconsistency in received and required number of channels."); 290 | return; 291 | } 292 | 293 | _plotDataMutex.acquire(); 294 | 295 | // Reset the max index of input channels 296 | _maxInChannel = 0; 297 | 298 | for (uint8_t i = 0; i < _nInputs; i++) 299 | { 300 | _inputChannels[i] = inChannels[i]; 301 | 302 | if (inChannels[i] > _maxInChannel) 303 | _maxInChannel = inChannels[i]; 304 | 305 | _plot->graph(i)->setName(_header->GetLabels()[i]->text()); 306 | } 307 | 308 | _plotDataMutex.release(); 309 | } 310 | 311 | /** 312 | * @brief Function directly called by the multiplexer to push data into 313 | * the graph 314 | * @param data Array of available data 315 | * @param n Size of data array 316 | */ 317 | void LinePlot::ReceiveData(double *data, uint8_t n) 318 | { 319 | double maxYVal, minYVal; 320 | 321 | // Check if the largest index of input channels is available in the 322 | // received block of data 323 | if (n < _maxInChannel) 324 | return; 325 | 326 | // Initialize Y axis limits 327 | maxYVal = minYVal = data[_inputChannels[0]]; 328 | 329 | // If we can't acquire mutex in a millisecond, return and try again 330 | // with new data 331 | // TODO: can it be problematic in low data-rate applications if we arrive 332 | // here while another element holds the mutex? 333 | if (!_plotDataMutex.tryAcquire(1,1)) 334 | return; 335 | 336 | // If data accumulation is enabled, resize X axis as we gather the 337 | // samples. When we hit the end of current range, increase range by 20% 338 | if (_accumulate->isChecked()) 339 | { 340 | _xAxis.push_front(_xAxis.front()-1); 341 | if (_xAxis.front() < _plot->xAxis->range().lower) 342 | _plot->xAxis->setRange(_xAxis.front()*1.2, 0); 343 | } 344 | 345 | for (uint8_t i = 0; i < _nInputs; i++) 346 | { 347 | // Populate the graph 348 | // Since graph has already been initialized, we keep popping out the 349 | // oldest data point, and pushing in the new. Visually, the direction 350 | // of movement as the graph above 351 | if (!_accumulate->isChecked()) 352 | // When not accumulating, pop the oldest data to make space for new 353 | _inputCh[i].pop_front(); 354 | _inputCh[i].push_back(data[_inputChannels[i]]); 355 | 356 | // Connect updated data source to graph 357 | _plot->graph(i)->setData(_xAxis, _inputCh[i]); 358 | 359 | // Update Y axis limits boundaries 360 | if (data[_inputChannels[i]] > maxYVal) maxYVal = data[_inputChannels[i]]; 361 | if (data[_inputChannels[i]] < minYVal) minYVal = data[_inputChannels[i]]; 362 | } 363 | 364 | 365 | 366 | // If enabled, automatically adjust range to 10% more than max value, and 367 | // 10% less then min value 368 | if (_autoAdjustYaxis->isChecked()) 369 | { 370 | if (minYVal < _plot->yAxis->range().lower) 371 | _plot->yAxis->setRange(minYVal * 1.1, _plot->yAxis->range().upper); 372 | if (maxYVal > _plot->yAxis->range().upper) 373 | _plot->yAxis->setRange(_plot->yAxis->range().lower, maxYVal * 1.1); 374 | } 375 | 376 | _plotDataMutex.release(); 377 | } 378 | -------------------------------------------------------------------------------- /helperObjects/dataMultiplexer/datamultiplexer.cpp: -------------------------------------------------------------------------------- 1 | #include "datamultiplexer.h" 2 | #include 3 | 4 | DataMultiplexer& DataMultiplexer::GetI() 5 | { 6 | static DataMultiplexer inst; 7 | return inst; 8 | } 9 | 10 | DataMultiplexer* DataMultiplexer::GetP() 11 | { 12 | return &(GetI()); 13 | } 14 | 15 | DataMultiplexer::DataMultiplexer(): _threadQuit(false), _sampleCount(0), 16 | _extSampleCount(0) 17 | { 18 | _InputdataReady.release(); 19 | 20 | for (uint8_t i=0; i < 7; i++) 21 | _mChannel[i] = new MathChannel(); 22 | 23 | _logFile = nullptr; 24 | _logFileStream = nullptr; 25 | _logToFile = false; 26 | 27 | connect(&_timer, &QTimer::timeout, this, &DataMultiplexer::_TimerTick); 28 | _timer.setInterval(1000); 29 | _timer.start(); 30 | } 31 | 32 | DataMultiplexer::~DataMultiplexer() 33 | { 34 | // Pass kill signal to the thread and wait for it to terminate 35 | _threadQuit = true; 36 | wait(); 37 | 38 | for (uint8_t i=0; i < 7; i++) 39 | delete _mChannel[i]; 40 | 41 | delete [] _channelData; 42 | } 43 | 44 | void DataMultiplexer::_TimerTick() 45 | { 46 | _extSampleCount = _sampleCount; 47 | _sampleCount = 0; 48 | } 49 | 50 | uint16_t DataMultiplexer::GetSampleRateEst() 51 | { 52 | return _extSampleCount; 53 | } 54 | 55 | /** 56 | * @brief DataMultiplexer::SetSerialFrameFormat 57 | * @param start 58 | * @param delim 59 | * @param end 60 | */ 61 | void DataMultiplexer::SetSerialFrameFormat(const QString &start, const QString &delim, const QString &end) 62 | { 63 | _SerialframeFormat[0] = start; 64 | _SerialframeFormat[1] = delim; 65 | _SerialframeFormat[2] = end; 66 | 67 | logLine(QString("Updated frame format with ")+ 68 | _SerialframeFormat[0].length()+ 69 | _SerialframeFormat[1].length()+ 70 | _SerialframeFormat[2].length()); 71 | } 72 | 73 | void DataMultiplexer::RegisterSerialCh(uint8_t n, QString *chName) 74 | { 75 | emit logLine(tr("Registering %1 channels").arg(n)); 76 | _SerialLabels.clear(); 77 | 78 | for (uint8_t i = 0; i < n; i++) 79 | _SerialLabels.push_back(chName[i]); 80 | emit logLine("Adding new labels"); 81 | 82 | 83 | _channelCount[SignalSource::SerialSignal] = n; 84 | emit logLine("Updating serial channel count"); 85 | 86 | _InternalChannelUpdate(); 87 | 88 | emit ChannelsUpdated(); 89 | 90 | } 91 | 92 | /** 93 | * @brief RegisterMathChannel 94 | * @param channelId Math channel id (1-indexed) 95 | * @param mc 96 | */ 97 | void DataMultiplexer::RegisterMathChannel(uint8_t channelId, 98 | MathChannel *mc) 99 | { 100 | emit logLine(tr("Registering channel %1").arg(channelId)); 101 | _threadQuit = true; 102 | wait(); 103 | 104 | // Clean up old variable 105 | delete _mChannel[channelId-1]; 106 | 107 | // Move new data in 108 | _mChannel[channelId-1] = mc; 109 | // Enable math channel 110 | _mChannel[channelId-1]->Enabled = true; 111 | _channelCount[SignalSource::MathSignal]++; 112 | 113 | _InternalChannelUpdate(); 114 | emit ChannelsUpdated(); 115 | 116 | emit logLine(tr("Finished registering channel %1").arg(channelId)); 117 | _threadQuit = false; 118 | } 119 | 120 | /** 121 | * @brief DataMultiplexer::UnegisterMathChannel 122 | * @param channelId Math channel (1-indexed) 123 | */ 124 | void DataMultiplexer::UnegisterMathChannel(uint8_t channelId) 125 | { 126 | emit logLine(tr("Unregistering channel %1").arg(channelId)); 127 | 128 | _threadQuit = true; 129 | wait(); 130 | 131 | _mChannel[channelId-1]->Clear(); 132 | _channelCount[SignalSource::MathSignal]--; 133 | 134 | _InternalChannelUpdate(); 135 | emit ChannelsUpdated(); 136 | 137 | emit logLine(tr("Finished unregistering channel %1").arg(channelId)); 138 | _threadQuit = false; 139 | } 140 | 141 | /** 142 | * @brief Assemble a list of available input channels. Usually called by the 143 | * graphs to know which channels to the user 144 | * @return QStringList with all channel labels 145 | */ 146 | QStringList DataMultiplexer::GetChannelList() 147 | { 148 | QStringList retVal; 149 | 150 | for (QString &X : _SerialLabels) 151 | retVal.append(X); 152 | 153 | for (MathChannel* X : _mChannel) 154 | if (X->Enabled) 155 | retVal.append(X->GetLabel()); 156 | 157 | return retVal; 158 | } 159 | 160 | /** 161 | * @brief Perform internal update of available input channels 162 | */ 163 | void DataMultiplexer::_InternalChannelUpdate() 164 | { 165 | // This can't be done with a running thread. Stop it beforehand 166 | if (isRunning()) 167 | { 168 | _threadQuit = true; 169 | wait(); 170 | } 171 | 172 | emit logLine(tr("Deleting channel list of size %1").arg(_channelCount[SignalSource::AllChannels])); 173 | 174 | // TODO: This breaks heap boundary when ran with active serial port? 175 | // If _channelData has been initialized before, delete it first 176 | // if (_channelCount[SignalSource::AllChannels] != 0) 177 | // delete [] _channelData; 178 | 179 | // Compute new number total of channels 180 | _channelCount[SignalSource::AllChannels] = 181 | _channelCount[SignalSource::SerialSignal] + 182 | _channelCount[SignalSource::MathSignal]; 183 | 184 | emit logLine(tr("Allocating %1 new channels").arg(_channelCount[SignalSource::AllChannels])); 185 | // Allocate data array for all current channels 186 | _channelData = new double[_channelCount[SignalSource::AllChannels]]; 187 | 188 | // Update finished, remember to revive the thread 189 | _threadQuit = false; 190 | } 191 | 192 | /** 193 | * @brief Register orientation plot 194 | * @param name Name of the plot 195 | * @param nInChannels Number of input channels 196 | * @param receiver Pointer to graph object 197 | */ 198 | void DataMultiplexer::RegisterGraph(QString name, 199 | uint8_t nInChannels, 200 | OrientationWindow* receiver) 201 | { 202 | _Graphs.push_back(new GraphClient(name,nInChannels,receiver)); 203 | emit logLine("Registered graph "+name); 204 | } 205 | /** 206 | * @brief Register scatter plot 207 | * @param name Name of the plot 208 | * @param nInChannels Number of input channels 209 | * @param receiver Pointer to graph object 210 | */ 211 | void DataMultiplexer::RegisterGraph(QString name, 212 | uint8_t nInChannels, 213 | ScatterWindow* receiver) 214 | { 215 | _Graphs.push_back(new GraphClient(name,nInChannels,receiver)); 216 | emit logLine("Registered graph "+name); 217 | } 218 | /** 219 | * @brief Register line plot 220 | * @param name Name of the plot 221 | * @param nInChannels Number of input channels 222 | * @param receiver Pointer to graph object 223 | */ 224 | void DataMultiplexer::RegisterGraph(QString name, 225 | uint8_t nInChannels, 226 | LinePlot* receiver) 227 | { 228 | _Graphs.push_back(new GraphClient(name,nInChannels,receiver)); 229 | emit logLine("Registered graph "+name); 230 | } 231 | 232 | 233 | /** 234 | * @brief Unregister orientation plot 235 | * @param reciver Pointer to graph object 236 | */ 237 | void DataMultiplexer::UnregisterGraph(OrientationWindow* reciver) 238 | { 239 | QString name(""); 240 | for (uint8_t i = 0; i < _Graphs.size(); i++) 241 | { 242 | if (_Graphs[i]->Receiver(reciver) == reciver) 243 | { 244 | name = _Graphs[i]->_name; 245 | _Graphs.erase(_Graphs.begin()+i); 246 | break; 247 | } 248 | } 249 | emit logLine("Unregistered graph "+name); 250 | } 251 | /** 252 | * @brief Unregister scatter plot 253 | * @param reciver Pointer to graph object 254 | */ 255 | void DataMultiplexer::UnregisterGraph(ScatterWindow* reciver) 256 | { 257 | QString name(""); 258 | for (uint8_t i = 0; i < _Graphs.size(); i++) 259 | { 260 | if (_Graphs[i]->Receiver(reciver) == reciver) 261 | { 262 | name = _Graphs[i]->_name; 263 | _Graphs.erase(_Graphs.begin()+i); 264 | break; 265 | } 266 | } 267 | emit logLine("Unregistered graph "+name); 268 | } 269 | /** 270 | * @brief Unregister line plot 271 | * @param reciver Pointer to graph object 272 | */ 273 | void DataMultiplexer::UnregisterGraph(LinePlot* reciver) 274 | { 275 | QString name(""); 276 | for (uint8_t i = 0; i < _Graphs.size(); i++) 277 | { 278 | if (_Graphs[i]->Receiver(reciver) == reciver) 279 | { 280 | name = _Graphs[i]->_name; 281 | _Graphs.erase(_Graphs.begin()+i); 282 | break; 283 | } 284 | } 285 | emit logLine("Unregistered graph "+name); 286 | } 287 | 288 | /** 289 | * @brief Enable logging data into a file 290 | * @param logPath System path to log file 291 | * @param append If true, append data to existing file. If false, overwrite 292 | * existing file 293 | * @param chSep Channel separator character 294 | * @return 0 on success, -1 otherwise 295 | */ 296 | int DataMultiplexer::EnableFileLogging(const QString &logPath, bool append, char chSep) 297 | { 298 | emit logLine("Enabling logging to file "+logPath); 299 | _logFile = new QFile(logPath); 300 | 301 | QIODevice::OpenMode flags = QIODevice::WriteOnly | QIODevice::Text; 302 | if (append) 303 | flags |= QIODevice::Append; 304 | 305 | if (!_logFile->open(flags)) 306 | { 307 | emit logLine("Error opening log file"); 308 | _logFile->deleteLater(); 309 | return -1; 310 | } 311 | 312 | _logFileStream = new QTextStream(_logFile); 313 | _logChSep = chSep; 314 | 315 | _logToFile = true; 316 | return 0; 317 | } 318 | 319 | /** 320 | * @brief Disabling logging to file 321 | */ 322 | void DataMultiplexer::DisableFileLogging() 323 | { 324 | logLine("Waiting on mutex to disable file logging"); 325 | 326 | _logToFile = false; 327 | _InputdataReady.acquire(2); 328 | 329 | 330 | _logFile->close(); 331 | delete _logFileStream; 332 | _logFile->deleteLater(); 333 | 334 | _InputdataReady.release(1); 335 | 336 | logLine("File logging disabled"); 337 | } 338 | 339 | 340 | /** 341 | * @brief Compute math channel values from input values 342 | * Called from data handling thread 343 | */ 344 | void DataMultiplexer::_ComputeMathChannels() 345 | { 346 | for (uint8_t i = 0; i < 6; i++) 347 | { 348 | // Skip channel if it's not enabled 349 | if (!_mChannel[i]->Enabled) 350 | continue; 351 | 352 | // Math channels are offset by the count of serial channels 353 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] = 0; 354 | 355 | for (uint8_t j = 0; j < _mChannel[i]->_component.size(); j++) 356 | if (std::get<0>(_mChannel[i]->_component[j]) == MathOperation::Add_Signal) 357 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] += \ 358 | _channelData[ std::get<1>(_mChannel[i]->_component[j]) ]; 359 | else if (std::get<0>(_mChannel[i]->_component[j]) == MathOperation::Subtract_Signal) 360 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] -= \ 361 | _channelData[ std::get<1>(_mChannel[i]->_component[j]) ]; 362 | else if (std::get<0>(_mChannel[i]->_component[j]) == MathOperation::Multiply) 363 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] *= \ 364 | _channelData[ std::get<1>(_mChannel[i]->_component[j]) ]; 365 | else if (std::get<0>(_mChannel[i]->_component[j]) == MathOperation::Add_Abs) 366 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] += \ 367 | abs(_channelData[ std::get<1>(_mChannel[i]->_component[j]) ]); 368 | else if (std::get<0>(_mChannel[i]->_component[j]) == MathOperation::Subtract_Abs) 369 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] -= \ 370 | abs(_channelData[ std::get<1>(_mChannel[i]->_component[j]) ]); 371 | else if (std::get<0>(_mChannel[i]->_component[j]) == MathOperation::Multiply_Abs) 372 | _channelData[ _channelCount[SignalSource::SerialSignal] + i] *= \ 373 | abs(_channelData[ std::get<1>(_mChannel[i]->_component[j]) ]); 374 | } 375 | } 376 | 377 | /** 378 | * @brief [Slot] Entry point for incoming serial data 379 | * @param buffer buffer of received data that's passed to the main thread 380 | * for parsing and dispatching 381 | */ 382 | void DataMultiplexer::ReceiveData(const QString &buffer) 383 | { 384 | 385 | _InputdataReady.acquire(1); 386 | 387 | // Buffer should never go over 4k, otherwise somethign is wrong 388 | if (_buffer.length() + buffer.length() < 4000) 389 | _buffer += buffer; 390 | else 391 | _buffer = buffer; 392 | 393 | if (!isRunning() && !_threadQuit) 394 | { 395 | // External process use this flag to control thread, avoid 396 | // forcing its value here 397 | //_threadQuit = false; 398 | start(); 399 | } 400 | 401 | _InputdataReady.release(2); 402 | } 403 | 404 | /** 405 | * @brief Multiplexer main thread 406 | * This thread is started upon constructing the multiplexer, and is spun up 407 | * to listen for incoming data, compute math channels and update data in the 408 | * registered graphs 409 | */ 410 | void DataMultiplexer::run() 411 | { 412 | emit logLine("Data thread started"); 413 | while (!_threadQuit) 414 | { 415 | if (!_InputdataReady.tryAcquire(2,1)) 416 | continue; 417 | 418 | QString buffer = _buffer; 419 | // Sanity check, has this been properly initialized? 420 | if (_SerialLabels.size() == 0) 421 | { 422 | emit logLine(tr("No input channels registered")); 423 | _InputdataReady.release(1); 424 | return; 425 | } 426 | 427 | QString tmp(""); 428 | // Loop through received data and split it in frames. 'i' holds 429 | // current char position and is further incremented inside the loop 430 | for (int32_t i = 0; i < buffer.length(); i++) 431 | { 432 | // tmp holds all characters of the current frame we've processes 433 | // If that frame is incomplete, we can push it into the processing 434 | // on the next iteration of the loop with new data. 435 | tmp = ""; 436 | 437 | // If provided, find starting character of the frame 438 | if (_SerialframeFormat[0].length() == 1) 439 | { 440 | // Loop until we reach the last char in starting sequence 441 | while (buffer[i++].cell() == _SerialframeFormat[0][0].cell()) 442 | { 443 | tmp += buffer[i-1]; 444 | 445 | // If we're about to look outside the buffer, terminate further 446 | // processing and jump outside of this loop to wait for 447 | // new data frame 448 | if ((i+1) >= buffer.length()) 449 | { 450 | // Save current part fo the frame under assumption that it 451 | // might get completed with new data coming in 452 | _buffer = tmp; 453 | goto end_goto; 454 | } 455 | } 456 | } 457 | 458 | // Used to save strings containing numeric values of each channel 459 | // in the frame 460 | QStringList chnValues; 461 | // Look for terminating sequance of a frame in buffer 462 | if (_SerialframeFormat[2].length() > 0) 463 | { 464 | QString tmpNumber = ""; 465 | // ffIter keeps track of the current character in frame 466 | // counter. It's incremented every time current char in frame 467 | // counter is found in the buffer, and immediately reset to 0 468 | // when there's no match 469 | uint8_t ffIter = 0; 470 | 471 | // Loop until the _SerialframeFormat[2] is found in buffer 472 | // This block essentially tries to find a substring 473 | // _SerialframeFormat[2] in buffer. 474 | while (ffIter < _SerialframeFormat[2].length()) 475 | { 476 | // Save data in temporary buffer in case this frame 477 | // is not complete 478 | tmp += buffer[i]; 479 | 480 | // In case where frame format characters are subset of 481 | // values in the data, this will fail. Maybe future 482 | // consideration? 483 | if (buffer[i].cell() == _SerialframeFormat[2][ffIter].cell()) 484 | ffIter++; 485 | else 486 | { 487 | ffIter=0; 488 | // Check if current char is channel separator, if so 489 | // add the value we just assembled to the string list 490 | if (buffer[i] == _SerialframeFormat[1]) 491 | { 492 | chnValues.append(tmpNumber); 493 | tmpNumber = ""; 494 | } 495 | else 496 | // Otherwise, just keep adding chars from the buffer 497 | // into the number accumulator 498 | { 499 | tmpNumber += buffer[i]; 500 | } 501 | } 502 | 503 | // If we're about to look outside the buffer, terminate further 504 | // processing and jump outside of this loop to wait for 505 | // new data frame 506 | if ((i+1) >= buffer.length() && 507 | (ffIter != _SerialframeFormat[2].length())) 508 | { 509 | // To get in here, we must've found the starting sequence 510 | // of the frame but not the ending one. In this case, we 511 | // want to save this partial frame so that the missing 512 | // piece is appended next time new serial data is available 513 | 514 | // Save buffer for next loop iteration 515 | _buffer = tmp; 516 | //emit logLine("Failed to match terminator sequence"); 517 | goto end_goto; 518 | } 519 | else 520 | { 521 | i++; 522 | } 523 | } 524 | // We can only get to here if the terminating sequence has 525 | // been found. Add the last number detected before the sequence 526 | chnValues.append(tmpNumber); 527 | } 528 | // Check for discrepancy in channel count 529 | if (chnValues.size() != (int)_SerialLabels.size()) 530 | { 531 | emit logLine(tr("Channel number discrepancy. Got %1, expected %2")\ 532 | .arg(chnValues.size()).arg(_SerialLabels.size())); 533 | continue; 534 | } 535 | // Go through the list of channels and move it into data buffer 536 | for (uint8_t j = 0; j < chnValues.size(); j++) 537 | { 538 | bool ok = false; 539 | double tmp = chnValues[j].toDouble(&ok); 540 | 541 | if (ok) 542 | _channelData[j] = tmp; 543 | else 544 | { 545 | _channelData[j] = 0.0; 546 | emit logLine(tr("Error converting to double")); 547 | continue; 548 | } 549 | } 550 | 551 | _ComputeMathChannels(); 552 | // Update graphs 553 | for (GraphClient* X : _Graphs) 554 | X->SendData(_channelCount[SignalSource::AllChannels], _channelData); 555 | // Log to file if enabled 556 | if (_logToFile) 557 | { 558 | QString line = ""; 559 | for (uint8_t k = 0; k < _channelCount[SignalSource::AllChannels]; k++) 560 | { 561 | line += QString::number(_channelData[k]); 562 | if ((k+1) < _channelCount[SignalSource::AllChannels]) 563 | line += _logChSep; 564 | } 565 | (*_logFileStream) << line << Qt::endl; 566 | } 567 | _sampleCount++; 568 | } 569 | // We've reached the end of buffer and successfully processed 570 | // everything inside, clear it 571 | _buffer = ""; 572 | end_goto: 573 | 574 | _InputdataReady.release(1); 575 | 576 | } 577 | emit logLine("Data thread stopped"); 578 | } 579 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include "plotWindows/scatter/scatterwindow.h" 5 | #include "plotWindows/orientation_3d/orientationwindow.h" 6 | #include "plotWindows/line/lineplot.h" 7 | #include "helperObjects/graphHeaderWidget/graphheaderwidget.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | const QString __appVersion__ = "1.0"; 32 | QString __configVersion__; 33 | 34 | MainWindow::MainWindow(QWidget *parent) : 35 | QWidget(parent), 36 | ui(new Ui::MainWindow), 37 | _pendingDeletion(false), 38 | _loggingInitialized(false) 39 | { 40 | // Setup UI made in designer 41 | ui->setupUi(this); 42 | setWindowIcon(QIcon(":/icons/icon.png")); 43 | 44 | // Collect handles for checkboxes and names for math channels into arrays 45 | mathChEnabled.push_back(ui->mathCh1en); 46 | mathChEnabled.push_back(ui->mathCh2en); 47 | mathChEnabled.push_back(ui->mathCh3en); 48 | mathChEnabled.push_back(ui->mathCh4en); 49 | mathChEnabled.push_back(ui->mathCh5en); 50 | mathChEnabled.push_back(ui->mathCh6en); 51 | 52 | mathChName.push_back(ui->mathCh1name); 53 | mathChName.push_back(ui->mathCh2name); 54 | mathChName.push_back(ui->mathCh3name); 55 | mathChName.push_back(ui->mathCh4name); 56 | mathChName.push_back(ui->mathCh5name); 57 | mathChName.push_back(ui->mathCh6name); 58 | 59 | // Initialize objects 60 | dataAdapter = new SerialAdapter(); 61 | netAdapter = new NetworkAdapter(); 62 | mainTimer = new QTimer(); 63 | mux = DataMultiplexer::GetP(); 64 | settings = new QSettings(QString("config.ini"), QSettings::IniFormat); 65 | 66 | connect(mux, &DataMultiplexer::logLine, this, &MainWindow::logLine); 67 | logLine("Starting up.."); 68 | 69 | /** 70 | * Check presence of OpenGL drivers 71 | */ 72 | Q3DScatter *graph = new Q3DScatter(); 73 | // Check that OpenGL exists 74 | if (!graph->hasContext()) { 75 | QMessageBox msgBox; 76 | msgBox.setText("Couldn't initialize the OpenGL context."); 77 | msgBox.exec(); 78 | return; 79 | } 80 | delete graph; 81 | 82 | /** 83 | * Configure parameters for serial port 84 | */ 85 | // Port selector 86 | const auto infos = QSerialPortInfo::availablePorts(); 87 | for (const QSerialPortInfo &info : infos) 88 | ui->portSelector->addItem(info.portName()); 89 | // Port baud 90 | ui->portBaud->addItem("1000000"); 91 | ui->portBaud->addItem("115200"); 92 | ui->portBaud->addItem("9600"); 93 | ui->portBaud->setCurrentIndex(1); 94 | 95 | // 'Connect' button opens serial port connection 96 | QObject::connect(ui->connectButton, &QPushButton::clicked, 97 | this, &MainWindow::toggleConnection); 98 | // Serial adapter objects logs data into a MainWindow logger 99 | QObject::connect(dataAdapter, &SerialAdapter::logLine, 100 | this, &MainWindow::logLine); 101 | // Serial adapter objects logs data into a MainWindow logger 102 | QObject::connect(netAdapter, &NetworkAdapter::logLine, 103 | this, &MainWindow::logLine); 104 | 105 | // Connect channel enable signals to slot 106 | for (uint8_t i = 0; i < mathChEnabled.size(); i++) 107 | QObject::connect(mathChEnabled[i], &QCheckBox::clicked, 108 | this, &MainWindow::UpdateAvailMathCh); 109 | 110 | //TODO: Add data bits, parity and flow control fields 111 | // For now assume 8bits, no parity, no flow control, 1 stop bit 112 | // Connect/disconnect button 113 | logLine("Start-up completed, loading settings..."); 114 | LoadSettings(); 115 | 116 | // Timer ticks at 1s, refreshing certain UI elements 117 | mainTimer->setInterval(1000); 118 | QObject::connect(mainTimer, &QTimer::timeout, this, &MainWindow::refreshUI); 119 | mainTimer->start(); 120 | } 121 | 122 | /** 123 | * @brief Clean up and backup settings on exit 124 | * When exiting the window, save all settings and clean up 125 | */ 126 | MainWindow::~MainWindow() 127 | { 128 | logLine("Deleting main window"); 129 | _pendingDeletion = true; 130 | 131 | // Save port options 132 | settings->setValue("port/name", 133 | ui->portSelector->itemText(ui->portSelector->currentIndex())); 134 | settings->setValue("port/baud", 135 | ui->portBaud->itemText(ui->portBaud->currentIndex())); 136 | settings->setValue("port/enabled",ui->enableNetwork->isChecked()); 137 | 138 | settings->setValue("channel/startChar", ui->frameStartCh->text()); 139 | settings->setValue("channel/separator", ui->frameChSeparator->text()); 140 | settings->setValue("channel/endChar", ui->frameEndSep->text()); 141 | settings->setValue("channel/endCharR", ui->termSlashR->isChecked()); 142 | settings->setValue("channel/endCharN", ui->termSlashN->isChecked()); 143 | 144 | // Save channel settings 145 | for (uint8_t i = 0; i < ch.size(); i++) 146 | { 147 | QString chID_str = QString::number(i); 148 | 149 | settings->setValue("channel/channel"+chID_str+"ID", ch[i]->GetId()); 150 | settings->setValue("channel/channel"+chID_str+"name", ch[i]->GetName()); 151 | } 152 | 153 | // Save math channels 154 | for (uint8_t i = 0; i < mathComp.size(); i++) 155 | { 156 | QString id_str = QString::number(i); 157 | 158 | 159 | settings->setValue("math/component"+id_str+"inCh", 160 | mathComp[i]->GetInCh()); 161 | settings->setValue("math/component"+id_str+"mathCh", 162 | mathComp[i]->GetMathCh()); 163 | settings->setValue("math/component"+id_str+"math", 164 | mathComp[i]->GetMath()); 165 | } 166 | settings->setValue("math/componentCount", (uint8_t)mathComp.size()); 167 | 168 | // Save math channel labels 169 | for (uint8_t i = 0; i < mathChEnabled.size(); i++) 170 | if (mathChEnabled[i]->isChecked()) 171 | settings->setValue("math/channel"+QString::number(i+1)+"name", 172 | mathChName[i]->text()); 173 | 174 | // Save file logging settings to file 175 | settings->setValue("fileLogging/append", ui->appendButton->isChecked()); 176 | settings->setValue("fileLogging/folder", ui->logfilePath->text()); 177 | settings->setValue("fileLogging/fileName", ui->logfileName->text()); 178 | settings->setValue("fileLogging/channelSeparator", ui->logfileChSep->text()); 179 | 180 | // Save currently open page 181 | settings->setValue("ui/startPage", ui->tabWidget->currentIndex()); 182 | 183 | // Save network input settings 184 | settings->setValue("network/port",ui->netportSelector->value()); 185 | settings->setValue("network/enabled",ui->enableNetwork->isChecked()); 186 | settings->setValue("port/enabled",ui->enableSerial->isChecked()); 187 | 188 | 189 | settings->sync(); 190 | 191 | for (Channel *X : ch) 192 | delete X; 193 | ch.clear(); 194 | 195 | for (UIMathChannelComponent *X : mathComp) 196 | delete X; 197 | mathComp.clear(); 198 | 199 | // Clean-up for program run log 200 | _loggingInitialized = false; 201 | _logFile->close(); 202 | delete _logFileStream; 203 | _logFile->deleteLater(); 204 | 205 | delete ui; 206 | } 207 | 208 | /** 209 | * @brief Load settings from the configuration file 210 | */ 211 | void MainWindow::LoadSettings() 212 | { 213 | // Config file versioning 214 | __configVersion__ = 215 | settings->value("misc/configVersion",__appVersion__).toString(); 216 | settings->setValue("misc/configVersion",__configVersion__); 217 | settings->sync(); 218 | 219 | // Data frame settings 220 | ui->frameStartCh->setText( 221 | settings->value("channel/startChar","").toString()); 222 | ui->frameChSeparator->setText( 223 | settings->value("channel/separator","").toString()); 224 | ui->frameEndSep->setText( 225 | settings->value("channel/endChar","").toString()); 226 | ui->termSlashN->setChecked( 227 | settings->value("channel/endCharN","false").toBool()); 228 | ui->termSlashR->setChecked( 229 | settings->value("channel/endCharR","false").toBool()); 230 | 231 | // Number of data channels 232 | uint8_t nInChannels = settings->value("channel/numOfChannels","1").toInt(); 233 | ui->channelNumber->setValue(nInChannels); 234 | on_channelNumber_valueChanged(ui->channelNumber->value()); 235 | 236 | // Load number of math components (components must be added before 237 | // enabling channels) 238 | uint8_t mathComponentCount = settings->value("math/componentCount","0").toUInt(); 239 | for (uint8_t i = 0; i < mathComponentCount; i++) 240 | on_addMathComp_clicked(); 241 | 242 | // Read mask of enabled math channels and apply UI changes 243 | uint8_t mathChMask = settings->value("math/channelMask","0").toUInt(); 244 | for (uint8_t i = 0; i < mathChEnabled.size(); i++) 245 | if ( mathChMask & (uint8_t)(1<<(i+1)) ) 246 | { 247 | mathChEnabled[i]->setChecked(true); 248 | } 249 | UpdateAvailMathCh(); 250 | 251 | // Load file logging settings 252 | ui->appendButton->setChecked( 253 | settings->value("fileLogging/append","true").toBool()); 254 | ui->overwriteButton->setChecked( 255 | !settings->value("fileLogging/append","true").toBool()); 256 | ui->logfilePath->setText( 257 | settings->value("fileLogging/folder","").toString()); 258 | ui->logfileName->setText( 259 | settings->value("fileLogging/fileName","").toString()); 260 | ui->logfileChSep->setText( 261 | settings->value("fileLogging/channelSeparator",",").toString()); 262 | 263 | // Restore last opened tab 264 | ui->tabWidget->setCurrentIndex(settings->value("ui/startPage","0").toUInt()); 265 | 266 | // Load settings for network connection 267 | ui->netportSelector->setValue(settings->value("network/port","5555").toUInt()); 268 | ui->enableNetwork->setChecked(settings->value("network/enabled","false").toBool()); 269 | ui->enableSerial->setChecked(settings->value("port/enabled","true").toBool()); 270 | if (ui->enableNetwork->isChecked()) 271 | ui->networkGroup->setEnabled(true); 272 | if (ui->enableSerial->isChecked()) 273 | ui->serialGroup->setEnabled(true); 274 | 275 | } 276 | 277 | /** 278 | * @brief Trigger refresh of various UI elements 279 | * Usually called periodically every 1s from a main timer 280 | */ 281 | void MainWindow::refreshUI() 282 | { 283 | ui->timestamp->setText(QDateTime::currentDateTime().time().toString()); 284 | 285 | // Refresh port selector if nothing is selected 286 | if (ui->portSelector->currentText() == "") 287 | { 288 | const auto infos = QSerialPortInfo::availablePorts(); 289 | for (const QSerialPortInfo &info : infos) 290 | ui->portSelector->addItem(info.portName()); 291 | } 292 | 293 | ui->sampleRate->setText("Data rate: "+ 294 | QString::number(mux->GetSampleRateEst())+" Hz"); 295 | } 296 | 297 | /** 298 | * @brief Toggle a connection to data adapter 299 | * Turn a connection to the underlying data adapter on or off 300 | */ 301 | void MainWindow::toggleConnection() 302 | { 303 | 304 | if (ui->connectButton->text() == "Connect") 305 | { 306 | // Update frame information in MUX 307 | QString termSeq = ui->frameEndSep->text(); 308 | if (ui->termSlashR->isChecked()) 309 | termSeq += QChar(0x000D); 310 | if (ui->termSlashN->isChecked()) 311 | termSeq += QChar(0x000A); 312 | 313 | if (ui->frameChSeparator->text() == "" || 314 | termSeq == "") 315 | { 316 | logLine("Frame channel separator and frame terminator cannot be empty!"); 317 | return; 318 | } 319 | mux->SetSerialFrameFormat(ui->frameStartCh->text(), \ 320 | ui->frameChSeparator->text(), \ 321 | termSeq); 322 | 323 | // Collect channel labels and register them in the mux 324 | QString *chLabels = new QString[ch.size()]; 325 | for (uint8_t i = 0; i < ch.size(); i++) 326 | { 327 | chLabels[i] = ch[i]->GetName(); 328 | } 329 | mux->RegisterSerialCh(ch.size(), chLabels); 330 | // Clean up before exit 331 | delete[] chLabels; 332 | 333 | if (ui->enableSerial->isChecked()) 334 | { 335 | // Configure serial port 336 | dataAdapter->UpdatePort(ui->portSelector->itemText( 337 | ui->portSelector->currentIndex()), \ 338 | ui->portBaud->itemText(ui->portBaud->currentIndex())); 339 | // Prevent edits to serial port while connection is open 340 | ui->serialGroup->setEnabled(false); 341 | 342 | dataAdapter->StartListening(); 343 | //TODO: How to handle a case where function is called, but results in an error? 344 | } 345 | 346 | if (ui->enableNetwork->isChecked()) 347 | { 348 | // TODO: Input validation on port! 349 | netAdapter->SetNetPort(ui->netportSelector->value()); 350 | ui->networkGroup->setEnabled(false); 351 | 352 | netAdapter->StartListening(); 353 | } 354 | // Rename the button 355 | ui->connectButton->setText("Disconnect"); 356 | } 357 | else if (ui->connectButton->text() == "Disconnect") 358 | { 359 | if (ui->enableSerial->isChecked()) 360 | { 361 | ui->serialGroup->setEnabled(true); 362 | dataAdapter->StopListening(); 363 | } 364 | 365 | if (ui->enableNetwork->isChecked()) 366 | { 367 | ui->networkGroup->setEnabled(true); 368 | netAdapter->StopListening(); 369 | } 370 | 371 | ui->connectButton->setText("Connect"); 372 | } 373 | 374 | } 375 | 376 | /** 377 | * @brief [Slot function] Log a line to UI and an external run log file 378 | * @param line 379 | */ 380 | void MainWindow::logLine(const QString &line) 381 | { 382 | QString time = QDateTime::currentDateTime().time().toString(); 383 | 384 | // There's a chance this function is called after the UI has been deleted 385 | // Make sure we never try to access UI elements if MainWindow destructor 386 | // has been called. 387 | if (_pendingDeletion) 388 | return; 389 | 390 | // Handle opening and rotating logs between the program launches. On 391 | // every launch, increments the log descriptor and open new logfile to 392 | // write to. 393 | if (!_loggingInitialized) 394 | { 395 | // Load logfile info 396 | uint8_t lastLogIndex = settings->value("appLog/index","0").toUInt(); 397 | const uint8_t maxLogIndex = settings->value("appLog/maxIndex","3").toUInt(); 398 | 399 | uint8_t currentLogIndex = (lastLogIndex + 1) % maxLogIndex; 400 | _logFile = new QFile("datadashboard_run"+QString::number(currentLogIndex)+".log"); 401 | 402 | if (!_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) 403 | { 404 | ui->logLine->setText(time + ": " + "Error opening log file"); 405 | return; 406 | } 407 | 408 | _logFileStream = new QTextStream(_logFile); 409 | settings->setValue("appLog/index", currentLogIndex); 410 | _loggingInitialized = true; 411 | } 412 | 413 | ui->logLine->setText(time + ": " + line); 414 | 415 | // If log file is initialized, append a line in there as well 416 | if (_loggingInitialized) 417 | (*_logFileStream) << time + ": " + line << Qt::endl; 418 | } 419 | 420 | /** 421 | * @brief [Slot function] Handles dynamic construction of data channels 422 | * When called, it destroys all existing channel entries, and constructs 423 | * a number of new ones corresponding to the argument. 424 | * At the same time, number of channels is saved into a config file, 425 | * and existing data from config file is used to populate new fields 426 | * @param arg1 427 | */ 428 | void MainWindow::on_channelNumber_valueChanged(int arg1) 429 | { 430 | settings->setValue("channel/numOfChannels", arg1); 431 | settings->sync(); 432 | 433 | logLine("Channel number changed to "\ 434 | +QString::number(arg1)+", reconstructing UI"); 435 | 436 | // Clear existing list of channels 437 | clearLayout(ui->channelList, true); 438 | // Clear old list with channel elements 439 | ch.clear(); 440 | 441 | // Reconstruct part of UI to offer requested number of channels 442 | for (uint8_t i = 0; i < arg1; i++) 443 | { 444 | QString chID_str = QString::number(i); 445 | QHBoxLayout *entry = new QHBoxLayout(); 446 | 447 | // Extract settings for this channel from config file, if existing 448 | int chID = settings->value("channel/channel"+chID_str+"ID", chID_str).toInt(); 449 | QString chName = settings->value("channel/channel" + chID_str + "name","Serial "+ chID_str).toString(); 450 | 451 | // Construct UI elements for channel configuration 452 | Channel *tmp = new Channel("Channel " + chID_str, chID, chName); 453 | ch.push_back(tmp); 454 | 455 | // Add UI elements to a layout, then push layout into the UI 456 | entry->addWidget(tmp->chLabel, 0, Qt::AlignLeft); 457 | entry->addWidget(tmp->channelName, 0, Qt::AlignLeft); 458 | ui->channelList->addLayout(entry); 459 | } 460 | } 461 | 462 | /** 463 | * @brief Delete all elements in a layout provided in arguments 464 | * @param layout Layout to delete objects from 465 | * @param deleteWidgets If true, delete widgets 466 | */ 467 | void MainWindow::clearLayout(QLayout* layout, bool deleteWidgets) 468 | { 469 | while (QLayoutItem* item = layout->takeAt(0)) 470 | { 471 | if (deleteWidgets) 472 | { 473 | if (QWidget* widget = item->widget()) 474 | { 475 | widget->deleteLater(); 476 | } 477 | } 478 | if (QLayout* childLayout = item->layout()) 479 | clearLayout(childLayout, deleteWidgets); 480 | delete item; 481 | } 482 | } 483 | 484 | /////////////////////////////////////////////////////////////////////////////// 485 | //// 486 | /// Math components UI manipulations 487 | /// 488 | /////////////////////////////////////////////////////////////////////////////// 489 | /** 490 | * @brief Register a math channel with the given ID in the mux 491 | * @param chID channel Id to be registered 492 | */ 493 | void MainWindow::RegisterMathChannel(uint8_t chID) 494 | { 495 | MathChannel *mc = new MathChannel(); 496 | logLine("Attempting to register math channel. Looking up components..."); 497 | 498 | mc->SetLabel(mathChName[chID-1]->text()); 499 | // Look up all the components of this channel ID 500 | for (UIMathChannelComponent *X : mathComp) 501 | { 502 | // T 503 | if (X->GetMathCh() == (chID)) 504 | { 505 | mc->AddComponent(static_cast(X->GetMath()), X->GetInCh()); 506 | } 507 | } 508 | 509 | logLine("Registering math channel "+QString::number(chID)+" with "\ 510 | +QString::number(mc->_component.size())+" components"); 511 | 512 | mux->RegisterMathChannel(chID, mc); 513 | } 514 | 515 | /** 516 | * @brief [Slot function] Add new math component to the scroll list 517 | */ 518 | void MainWindow::on_addMathComp_clicked() 519 | { 520 | static uint32_t _id = 0; 521 | // Convert current id to string for easier manipulation 522 | QString id_str = QString::number(_id); 523 | 524 | logLine("Adding math component "+id_str); 525 | 526 | // Construct component for channel math and save it to global variable 527 | UIMathChannelComponent *tmp = new UIMathChannelComponent((uint8_t)mathComp.size()); 528 | mathComp.push_back(tmp); 529 | 530 | // Add new component to the UI 531 | ui->mathCompLayout->addLayout(tmp->GetLayout()); 532 | // Update available math channels in the component 533 | 534 | logLine("Math component "+id_str+" added to UI"); 535 | 536 | // Set values from settings, if exist, otherwise load defaults 537 | tmp->SetInCh(settings->value("math/component"+id_str+"inCh","0").toInt()); 538 | tmp->SetMathCh(settings->value("math/component"+id_str+"mathCh","1").toInt()); 539 | tmp->SetMath(settings->value("math/component"+id_str+"math","0").toInt()); 540 | 541 | connect(tmp, &UIMathChannelComponent::deleteRequested, \ 542 | this, &MainWindow::on_delete_updateMathComp); 543 | 544 | logLine("Saved math component "+id_str); 545 | _id++; 546 | } 547 | 548 | /** 549 | * @brief [Slot function] Update a list of available math channels used by 550 | * other components. Function called whenever a match channel checkbox 551 | * has been clicked 552 | */ 553 | void MainWindow::UpdateAvailMathCh() 554 | { 555 | // List of channels currently enabled, to be passed to QComboBoxes 556 | // in math components list -> not used for now 557 | int mathCh[6] = {0}; 558 | int count = 0; 559 | 560 | // Collapse all enabled channels into a binary mask, 561 | // save mask into a config file 562 | static uint8_t chMask = 0; 563 | 564 | logLine("Updating available math channels in UI..."); 565 | 566 | // Loop through all QCheckBox elements and configure UI look based on 567 | // whether they are checked or not 568 | for (uint8_t i = 0; i < mathChEnabled.size(); i++) 569 | { 570 | QString id_str = QString::number(i+1); 571 | if (mathChEnabled[i]->isChecked()) 572 | { 573 | mathCh[count++] = (i+1); 574 | mathChName[i]->setEnabled(true); 575 | // Load channel name from settings, if it exists and there 576 | // isn't one already set 577 | if (mathChName[i]->text() == "") 578 | mathChName[i]->setText( 579 | settings->value("math/channel"+id_str+"name", 580 | "Math "+id_str).toString()); 581 | logLine("Channel "+QString::number(i+1)+" enabled in UI"); 582 | } 583 | else 584 | mathChName[i]->setEnabled(false); 585 | 586 | // If it's enabled, but it wasn't in the last call 587 | if (mathChEnabled[i]->isChecked() && !(((1<<(i+1)) & chMask) > 0)) 588 | { 589 | logLine("Channel "+QString::number(i+1)+" has been enabled"); 590 | chMask |= (1<<(i+1)); 591 | RegisterMathChannel(i+1); 592 | } 593 | // If it's disabled, but it was enabled in the last call 594 | else if (!mathChEnabled[i]->isChecked() && (((1<<(i+1)) & chMask) > 0)) 595 | { 596 | chMask &= ~(1<<(i+1)); 597 | mux->UnegisterMathChannel(i+1); 598 | logLine("Channel "+QString::number(i+1)+" has been disabled"); 599 | } 600 | } 601 | 602 | // Save channel mask 603 | settings->setValue("math/channelMask", chMask); 604 | settings->sync(); 605 | 606 | // Go through existing math components list and update QComboBox with new 607 | // available math channels 608 | // for (MathChannelComponent* X : mathComp) 609 | // X->UpdateMathCh(mathCh, count); 610 | 611 | } 612 | 613 | /** 614 | * @brief [Slot function] Called by MathChannelComponent class when the delete 615 | * button has been pressed. It handles deletion in UI and clean up in backend 616 | * @param id ID of MathChannelComponent::_id to be deleted 617 | */ 618 | void MainWindow::on_delete_updateMathComp(uint8_t id) 619 | { 620 | // Math component got destroyed 621 | logLine("Requested to delete math channel "+QString::number(id)); 622 | // Find component in vector 623 | uint8_t i; 624 | for (i = 0; i < mathComp.size(); i++) 625 | if (mathComp[i]->GetID() == id) 626 | break; 627 | // Clear UI elements 628 | clearLayout(mathComp[i]->GetLayout()); 629 | // Delete remainder 630 | delete mathComp[i]; 631 | // Remove the entry from vector 632 | mathComp.erase(mathComp.begin()+i); 633 | 634 | // Update IDs of entries in the vector 635 | for (i = 0; i < mathComp.size(); i++) 636 | mathComp[i]->SetID(i); 637 | } 638 | 639 | 640 | 641 | /////////////////////////////////////////////////////////////////////////////// 642 | //// 643 | /// Dynamic creation of graphs 644 | /// 645 | /////////////////////////////////////////////////////////////////////////////// 646 | 647 | /** 648 | * @brief [Slot] Create new 3D orientation graph 649 | */ 650 | void MainWindow::on_add3D_clicked() 651 | { 652 | logLine("UI: Creating 3D plot"); 653 | static uint8_t _3DgraphCount = 0; 654 | QString winID = QString::number(_3DgraphCount); 655 | 656 | OrientationWindow *orient3DWindow = new OrientationWindow(this, "orientationWindow_"+winID); 657 | //orient3DWindow->setObjectName("orientationWindow_"+winID); 658 | QObject::connect(orient3DWindow, &OrientationWindow::logLine, 659 | this, &MainWindow::logLine); 660 | QMdiSubWindow *plotWindow = ui->mdiArea->addSubWindow(orient3DWindow); 661 | 662 | plotWindow->setWindowFlags(Qt::WindowCloseButtonHint); 663 | plotWindow->setAttribute(Qt::WA_DeleteOnClose, true); 664 | plotWindow->setWindowTitle("3D Orientation " + winID); 665 | plotWindow->setWindowIcon(QIcon(":/icons/icon.png")); 666 | 667 | plotWindow->show(); 668 | _3DgraphCount++; 669 | } 670 | 671 | /** 672 | * @brief [Slot] Create new scatter graph 673 | */ 674 | void MainWindow::on_addScatter_clicked() 675 | { 676 | logLine("UI: Creating scatter plot"); 677 | static uint8_t _ScatterCount = 0; 678 | QString winID = QString::number(_ScatterCount); 679 | 680 | // Create scatter plot 681 | ScatterWindow *scatterWindow = new ScatterWindow("scatterWindow_"+winID); 682 | //scatterWindow->setObjectName("scatterWindow_"+winID); 683 | QObject::connect(scatterWindow, &ScatterWindow::logLine, 684 | this, &MainWindow::logLine); 685 | QMdiSubWindow *plotWindow = ui->mdiArea->addSubWindow(scatterWindow); 686 | 687 | plotWindow->setWindowFlags(Qt::WindowCloseButtonHint); 688 | plotWindow->setAttribute(Qt::WA_DeleteOnClose, true); 689 | plotWindow->setWindowTitle("Scatter " + winID); 690 | plotWindow->setWindowIcon(QIcon(":/icons/icon.png")); 691 | 692 | plotWindow->show(); 693 | _ScatterCount++; 694 | } 695 | 696 | /** 697 | * @brief [Slot] Create new line plot 698 | */ 699 | void MainWindow::on_addLine_clicked() 700 | { 701 | logLine("UI: Creating line plot"); 702 | static uint8_t _LineCount = 0; 703 | QString winID = QString::number(_LineCount); 704 | 705 | // Create line plot 706 | LinePlot *lineplotWindow = new LinePlot("lineWindow_"+winID); 707 | //lineplotWindow->setObjectName("lineWindow_"+winID); 708 | QObject::connect(lineplotWindow, &LinePlot::logLine, 709 | this, &MainWindow::logLine); 710 | QMdiSubWindow *plotWindow = ui->mdiArea->addSubWindow(lineplotWindow); 711 | 712 | plotWindow->setWindowFlags(Qt::WindowCloseButtonHint); 713 | plotWindow->setAttribute(Qt::WA_DeleteOnClose, true); 714 | plotWindow->setWindowTitle("Line plot " + winID); 715 | plotWindow->setWindowIcon(QIcon(":/icons/icon.png")); 716 | 717 | plotWindow->show(); 718 | _LineCount++; 719 | } 720 | 721 | 722 | /////////////////////////////////////////////////////////////////////////////// 723 | //// 724 | /// Logging channel data to file 725 | /// 726 | /////////////////////////////////////////////////////////////////////////////// 727 | 728 | /** 729 | * @brief [Slot] Open file dialog when 'Path' button has been click 730 | * Once the path has been selected, update textbox in UI 731 | */ 732 | void MainWindow::on_logfilePathDialog_clicked() 733 | { 734 | QString saveDir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), 735 | "/home", 736 | QFileDialog::ShowDirsOnly 737 | | QFileDialog::DontResolveSymlinks); 738 | ui->logfilePath->setText(saveDir); 739 | } 740 | 741 | /** 742 | * @brief [Slot] Handle enabling/disabling logging to file 743 | * Handles click events to the 'Enable' checkbox which toggles logging to 744 | * the file. Updates UI and communicates with the MUX 745 | * @param arg1 State of the checkbox 746 | */ 747 | void MainWindow::on_fileloggingEnabled_stateChanged(int arg1) 748 | { 749 | // Checked can have PartiallyChecked and Checked states, so instead 750 | // evaluate if Unchecked 751 | if (arg1 == Qt::Unchecked) 752 | { 753 | ui->overwriteButton->setEnabled(true); 754 | ui->appendButton->setEnabled(true); 755 | ui->logfilePathDialog->setEnabled(true); 756 | ui->logfilePath->setEnabled(true); 757 | ui->logfileName->setEnabled(true); 758 | ui->logfileChSep->setEnabled(true); 759 | // Disable file logging in mux 760 | mux->DisableFileLogging(); 761 | } 762 | else 763 | { 764 | ui->overwriteButton->setEnabled(false); 765 | ui->appendButton->setEnabled(false); 766 | ui->logfilePathDialog->setEnabled(false); 767 | ui->logfilePath->setEnabled(false); 768 | ui->logfileName->setEnabled(false); 769 | ui->logfileChSep->setEnabled(false); 770 | // Save file logging settings to file 771 | settings->setValue("fileLogging/append", ui->appendButton->isChecked()); 772 | settings->setValue("fileLogging/folder", ui->logfilePath->text()); 773 | settings->setValue("fileLogging/fileName", ui->logfileName->text()); 774 | settings->setValue("fileLogging/channelSeparator", ui->logfileChSep->text()); 775 | // Enable file logging in mux 776 | QString logPath = ui->logfilePath->text()+'/'+ui->logfileName->text(); 777 | 778 | int retVal = mux->EnableFileLogging(logPath, 779 | ui->appendButton->isChecked(), 780 | ui->logfileChSep->text()[0].cell()); 781 | if (retVal != 0) 782 | ui->fileloggingEnabled->setChecked(false); 783 | } 784 | } 785 | 786 | /** 787 | * @brief [Slot] Enabled serial data input radio button 788 | * Handler for click event on radio button 789 | */ 790 | void MainWindow::on_enableSerial_clicked() 791 | { 792 | // Return if network thread is running 793 | if (netAdapter->isRunning()) 794 | return; 795 | 796 | ui->networkGroup->setEnabled(false); 797 | ui->serialGroup->setEnabled(true); 798 | ui->enableSerial->setChecked(true); 799 | } 800 | 801 | /** 802 | * @brief [Slot] Enabled network data input radio button 803 | * Handler for click event on radio button 804 | */ 805 | void MainWindow::on_enableNetwork_clicked() 806 | { 807 | // Return if serial thread is running 808 | if (dataAdapter->isRunning()) 809 | return; 810 | 811 | ui->serialGroup->setEnabled(false); 812 | ui->networkGroup->setEnabled(true); 813 | ui->enableNetwork->setChecked(true); 814 | } 815 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------