wfview/pttyhandler.h

74 wiersze
1.7 KiB
C
Czysty Zwykły widok Historia

2021-03-04 20:19:05 +00:00
#ifndef PTTYHANDLER_H
#define PTTYHANDLER_H
#include <QObject>
#include <QMutex>
#include <QDataStream>
2021-05-11 08:38:05 +00:00
#include <QIODevice>
#include <QSocketNotifier>
2021-03-04 20:19:05 +00:00
#include <QtSerialPort/QSerialPort>
// This class abstracts the comm port in a useful way and connects to
// the command creator and command parser.
class pttyHandler : public QObject
{
Q_OBJECT
public:
2021-05-05 13:11:00 +00:00
pttyHandler(QString portName);
2021-03-04 20:19:05 +00:00
pttyHandler(QString portName, quint32 baudRate);
bool serialError;
~pttyHandler();
private slots:
2021-05-11 08:38:05 +00:00
void receiveDataIn(int fd); // from physical port
2021-03-04 20:19:05 +00:00
void receiveDataFromRigToPtty(const QByteArray& data);
void debugThis();
signals:
void haveTextMessage(QString message); // status, debug only
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
void haveSerialPortError(const QString port, const QString error);
void haveStatusUpdate(const QString text);
private:
void setupPtty();
void openPort();
void closePort();
void sendDataOut(const QByteArray& writeData); // out to radio
void debugMe();
void hexPrint();
//QDataStream stream;
QByteArray outPortData;
QByteArray inPortData;
//QDataStream outStream;
//QDataStream inStream;
unsigned char buffer[256];
QString portName;
QSerialPort* port;
qint32 baudRate;
unsigned char stopBits;
bool rolledBack;
int ptfd; // pseudo-terminal file desc.
bool havePt;
QString ptDevSlave;
bool isConnected; // port opened
mutable QMutex mutex;
void printHex(const QByteArray& pdata, bool printVert, bool printHoriz);
2021-05-11 08:38:05 +00:00
QSocketNotifier *ptReader = nullptr;
2021-03-04 20:19:05 +00:00
};
#endif // PTTYHANDLER_H