Erste lauffähige Version
This commit is contained in:
41
include/connectdialog.h
Normal file
41
include/connectdialog.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <QDialog>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFormLayout>
|
||||
#include <QSerialPort>
|
||||
#include <QSerialPortInfo>
|
||||
|
||||
struct SerialConfig {
|
||||
QString portName;
|
||||
qint32 baudRate = 115200;
|
||||
QSerialPort::DataBits dataBits = QSerialPort::Data8;
|
||||
QSerialPort::Parity parity = QSerialPort::NoParity;
|
||||
QSerialPort::StopBits stopBits = QSerialPort::OneStop;
|
||||
QSerialPort::FlowControl flowControl = QSerialPort::NoFlowControl;
|
||||
QString logFilePath; // empty = no logging
|
||||
};
|
||||
|
||||
class ConnectDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConnectDialog(QWidget *parent = nullptr);
|
||||
|
||||
SerialConfig config() const;
|
||||
|
||||
private slots:
|
||||
void browseLogFile();
|
||||
void refreshPorts();
|
||||
|
||||
private:
|
||||
QComboBox *m_portCombo = nullptr;
|
||||
QComboBox *m_baudCombo = nullptr;
|
||||
QComboBox *m_dataBitsCombo = nullptr;
|
||||
QComboBox *m_parityCombo = nullptr;
|
||||
QComboBox *m_stopBitsCombo = nullptr;
|
||||
QComboBox *m_flowCombo = nullptr;
|
||||
QLineEdit *m_logPathEdit = nullptr;
|
||||
};
|
||||
68
include/mainwindow.h
Normal file
68
include/mainwindow.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
#include <QMainWindow>
|
||||
#include <QThread>
|
||||
#include <QTabWidget>
|
||||
#include <QSplitter>
|
||||
#include <QStatusBar>
|
||||
#include <QToolBar>
|
||||
#include <QLabel>
|
||||
#include <QAction>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include "serialworker.h"
|
||||
#include "rawview.h"
|
||||
#include "tableview.h"
|
||||
#include "tagwidget.h"
|
||||
#include "connectdialog.h"
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void onConnectClicked();
|
||||
void onDisconnectClicked();
|
||||
void onPortOpened();
|
||||
void onPortClosed();
|
||||
void onReconnecting(int attempt);
|
||||
void onClearScreen();
|
||||
void onError(const QString &message);
|
||||
void onNewLine(const QString &line);
|
||||
void onTagDetected(const QString &tag, const QString &value);
|
||||
void showFormatReference();
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
void setupToolBar();
|
||||
void setupStatusBar();
|
||||
void clearAllViews();
|
||||
|
||||
// Worker & thread
|
||||
QThread *m_thread = nullptr;
|
||||
SerialWorker *m_worker = nullptr;
|
||||
|
||||
// Views
|
||||
RawView *m_rawView = nullptr;
|
||||
TableView *m_tableView = nullptr;
|
||||
TagWidget *m_tagWidget = nullptr;
|
||||
|
||||
// Status bar widgets
|
||||
QLabel *m_portLabel = nullptr;
|
||||
QLabel *m_stateLabel = nullptr;
|
||||
QLabel *m_reconnectLabel = nullptr;
|
||||
|
||||
// Toolbar widgets
|
||||
QCheckBox *m_autoReconnectCb = nullptr;
|
||||
QSpinBox *m_reconnectIntervalSb= nullptr;
|
||||
|
||||
// Actions
|
||||
QAction *m_connectAction = nullptr;
|
||||
QAction *m_disconnectAction = nullptr;
|
||||
|
||||
SerialConfig m_lastConfig;
|
||||
};
|
||||
45
include/rawview.h
Normal file
45
include/rawview.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
#include <QSpinBox>
|
||||
|
||||
// RawView shows the raw UART output in a QPlainTextEdit with:
|
||||
// - Configurable maximum line count (default: unlimited / very large)
|
||||
// - Auto-scroll that pauses when the user scrolls up
|
||||
// - Horizontal scroll (word wrap off)
|
||||
// - Incremental text search
|
||||
// - Clear button
|
||||
class RawView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RawView(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void appendLine(const QString &line);
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void onSearch(const QString &text);
|
||||
void onScrollValueChanged(int value);
|
||||
void onAutoScrollToggled(bool enabled);
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
void applyColorScheme();
|
||||
|
||||
QPlainTextEdit *m_textEdit = nullptr;
|
||||
QLineEdit *m_searchEdit = nullptr;
|
||||
QPushButton *m_clearBtn = nullptr;
|
||||
QCheckBox *m_autoScrollCb = nullptr;
|
||||
QLabel *m_lineCountLbl = nullptr;
|
||||
bool m_autoScroll = true;
|
||||
int m_lineCount = 0;
|
||||
};
|
||||
76
include/serialworker.h
Normal file
76
include/serialworker.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QSerialPort>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
// SerialWorker lives in its own QThread and owns the QSerialPort.
|
||||
// It emits newLine() for every complete line received,
|
||||
// tagDetected() when a line contains a recognised tag like [WDG],
|
||||
// and clearScreen() when the ANSI clear-screen sequence \033[2J is received.
|
||||
// Auto-reconnect: if the port drops unexpectedly (e.g. USB cable pulled),
|
||||
// the worker retries every reconnectIntervalMs until success or closePort().
|
||||
class SerialWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SerialWorker(QObject *parent = nullptr);
|
||||
~SerialWorker();
|
||||
|
||||
// Auto-reconnect configuration (call before openPort, or any time)
|
||||
void setAutoReconnect(bool enabled) { m_autoReconnect = enabled; }
|
||||
void setReconnectInterval(int ms) { m_reconnectIntervalMs = ms; }
|
||||
|
||||
public slots:
|
||||
void openPort(const QString &portName, qint32 baudRate,
|
||||
QSerialPort::DataBits dataBits,
|
||||
QSerialPort::Parity parity,
|
||||
QSerialPort::StopBits stopBits,
|
||||
QSerialPort::FlowControl flowControl);
|
||||
void closePort(); // explicit user disconnect – stops reconnect
|
||||
void setLogFile(const QString &path);
|
||||
void stopLogging();
|
||||
|
||||
signals:
|
||||
void newLine(const QString &line);
|
||||
void tagDetected(const QString &tag, const QString &value);
|
||||
void clearScreen(); // emitted when \033[2J\033[H (or \033[2J alone) is received
|
||||
void portOpened();
|
||||
void portClosed();
|
||||
void reconnecting(int attempt); // fired each retry attempt
|
||||
void errorOccurred(const QString &message);
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onPortError(QSerialPort::SerialPortError err);
|
||||
void tryReconnect();
|
||||
|
||||
private:
|
||||
void processRawData(const QByteArray &data);
|
||||
void processLine(const QString &line);
|
||||
void scheduleReconnect();
|
||||
|
||||
QSerialPort *m_port = nullptr;
|
||||
QFile *m_logFile = nullptr;
|
||||
QTextStream *m_logStream = nullptr;
|
||||
QString m_buffer;
|
||||
|
||||
// Reconnect state
|
||||
QTimer *m_reconnectTimer = nullptr;
|
||||
bool m_autoReconnect = true;
|
||||
bool m_userDisconnected = false; // true only after explicit closePort()
|
||||
int m_reconnectIntervalMs = 2000;
|
||||
int m_reconnectAttempt = 0;
|
||||
|
||||
// Saved config for reconnect
|
||||
QString m_portName;
|
||||
qint32 m_baudRate = 115200;
|
||||
QSerialPort::DataBits m_dataBits = QSerialPort::Data8;
|
||||
QSerialPort::Parity m_parity = QSerialPort::NoParity;
|
||||
QSerialPort::StopBits m_stopBits = QSerialPort::OneStop;
|
||||
QSerialPort::FlowControl m_flowControl= QSerialPort::NoFlowControl;
|
||||
};
|
||||
52
include/tableview.h
Normal file
52
include/tableview.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
|
||||
// TableView interprets UART lines as delimited data and shows them in a table.
|
||||
// The first line that matches the column count is used as the header row if it
|
||||
// starts with '#'. Otherwise column names are auto-generated (Col 1, Col 2, …).
|
||||
//
|
||||
// Supported delimiters: comma, semicolon, tab, pipe, space
|
||||
// To use: send lines like:
|
||||
// #time,temp,voltage,current
|
||||
// 1234,23.5,3.3,0.42
|
||||
class TableView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TableView(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void appendLine(const QString &line);
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void onDelimiterChanged(int index);
|
||||
void onMaxRowsChanged();
|
||||
void rebuildTable();
|
||||
|
||||
private:
|
||||
void parseHeaders(const QString &line);
|
||||
bool tryAppendRow(const QString &line);
|
||||
|
||||
QTableWidget *m_table = nullptr;
|
||||
QComboBox *m_delimCombo = nullptr;
|
||||
QLineEdit *m_maxRowsEdit = nullptr;
|
||||
QPushButton *m_clearBtn = nullptr;
|
||||
QCheckBox *m_autoScrollCb = nullptr;
|
||||
|
||||
QStringList m_headers;
|
||||
QList<QStringList> m_rows; // raw data for rebuild
|
||||
int m_maxRows = 500;
|
||||
char m_delimiter = ',';
|
||||
bool m_autoScroll = true;
|
||||
bool m_headersSet = false;
|
||||
};
|
||||
37
include/tagpanel.h
Normal file
37
include/tagpanel.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QTableWidget>
|
||||
|
||||
// TagPanel displays the most recent data associated with a single tag (e.g. [WDG]).
|
||||
// Values are parsed as key=value pairs, or shown as a raw string if no '=' is found.
|
||||
// Example input line: [WDG] uptime=1234 temp=42.1 load=0.8
|
||||
class TagPanel : public QGroupBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TagPanel(const QString &tag, QWidget *parent = nullptr);
|
||||
|
||||
const QString &tag() const { return m_tag; }
|
||||
|
||||
public slots:
|
||||
void update(const QString &value);
|
||||
|
||||
private:
|
||||
void parseKeyValue(const QString &value);
|
||||
void showRaw(const QString &value);
|
||||
void ensureRow(const QString &key);
|
||||
|
||||
QString m_tag;
|
||||
QTableWidget *m_table = nullptr;
|
||||
QLabel *m_rawLabel = nullptr;
|
||||
QLabel *m_timestampLabel = nullptr;
|
||||
QStringList m_keys; // ordered list for row lookup
|
||||
};
|
||||
30
include/tagwidget.h
Normal file
30
include/tagwidget.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
#include "tagpanel.h"
|
||||
|
||||
// TagWidget is the side-panel that receives tagDetected() signals from the
|
||||
// SerialWorker and creates/updates one TagPanel per unique tag.
|
||||
class TagWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TagWidget(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void handleTag(const QString &tag, const QString &value);
|
||||
void clearAll();
|
||||
void removeTag(const QString &tag);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_panelLayout = nullptr;
|
||||
QMap<QString, TagPanel*> m_panels;
|
||||
};
|
||||
Reference in New Issue
Block a user