45 lines
980 B
C++
45 lines
980 B
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
class QSocketNotifier;
|
|
class QTimer;
|
|
|
|
class SerialReader : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit SerialReader(QObject *parent = nullptr);
|
|
~SerialReader() override;
|
|
|
|
[[nodiscard]] bool isOpen() const;
|
|
[[nodiscard]] QString portName() const;
|
|
|
|
public slots:
|
|
bool openPort(const QString &path, int baudRate);
|
|
void closePort();
|
|
|
|
signals:
|
|
void lineReceived(const QString &line);
|
|
void statusChanged(const QString &status);
|
|
void errorOccurred(const QString &message);
|
|
|
|
private slots:
|
|
void handleReadyRead();
|
|
void flushPartialLine();
|
|
|
|
private:
|
|
bool configurePort(int baudRate);
|
|
void processBuffer();
|
|
void setModemControlLines();
|
|
void emitSystemError(const QString &prefix);
|
|
|
|
int m_fd = -1;
|
|
QSocketNotifier *m_notifier = nullptr;
|
|
QTimer *m_pollTimer = nullptr;
|
|
QTimer *m_partialLineTimer = nullptr;
|
|
QByteArray m_buffer;
|
|
QString m_portName;
|
|
};
|