wfview/pttyhandler.h

80 wiersze
2.0 KiB
C

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>
#include "rigidentities.h"
2023-01-05 19:37:53 +00:00
#include "wfviewtypes.h"
2021-03-04 20:19:05 +00:00
// 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:
explicit pttyHandler(QString portName, QObject* parent = nullptr);
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();
void receiveFoundRigID(rigCapabilities rigCaps);
2021-03-04 20:19:05 +00:00
signals:
void haveTextMessage(QString message); // status, debug only
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
2023-01-05 19:37:53 +00:00
void havePortError(errorType err);
2021-03-04 20:19:05 +00:00
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;
2021-05-13 22:13:48 +00:00
QSerialPort* port = Q_NULLPTR;
2021-03-04 20:19:05 +00:00
qint32 baudRate;
unsigned char stopBits;
bool rolledBack;
int ptfd; // pseudo-terminal file desc.
2022-03-23 15:45:51 +00:00
int ptKeepAlive=0; // Used to keep the pty alive after client disconnects.
2021-03-04 20:19:05 +00:00
bool havePt;
QString ptDevSlave;
2021-05-12 08:14:48 +00:00
bool isConnected=false; // port opened
2021-03-04 20:19:05 +00:00
mutable QMutex mutex;
void printHex(const QByteArray& pdata, bool printVert, bool printHoriz);
bool disableTransceive = false;
QSocketNotifier *ptReader = Q_NULLPTR;
quint8 civId=0;
rigCapabilities rigCaps;
2021-03-04 20:19:05 +00:00
};
#endif // PTTYHANDLER_H