2018-06-19 19:58:52 +00:00
|
|
|
#ifndef COMMHANDLER_H
|
|
|
|
#define COMMHANDLER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QtSerialPort/QSerialPort>
|
|
|
|
|
|
|
|
// This class abstracts the comm port in a useful way and connects to
|
|
|
|
// the command creator and command parser.
|
|
|
|
|
|
|
|
class commHandler : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-05-08 18:31:05 +00:00
|
|
|
commHandler(QObject* parent = nullptr);
|
|
|
|
commHandler(QString portName, quint32 baudRate, quint8 wfFormat,QObject* parent = nullptr);
|
2021-02-02 09:05:59 +00:00
|
|
|
bool serialError;
|
2021-11-06 06:21:36 +00:00
|
|
|
bool rtsStatus();
|
2018-11-16 22:08:21 +00:00
|
|
|
|
2018-06-19 19:58:52 +00:00
|
|
|
~commHandler();
|
|
|
|
|
2021-11-06 06:21:36 +00:00
|
|
|
public slots:
|
|
|
|
void setUseRTSforPTT(bool useRTS);
|
|
|
|
void setRTS(bool rtsOn);
|
|
|
|
|
2018-06-19 19:58:52 +00:00
|
|
|
private slots:
|
2019-01-10 06:44:48 +00:00
|
|
|
void receiveDataIn(); // from physical port
|
2018-06-19 19:58:52 +00:00
|
|
|
void receiveDataFromUserToRig(const QByteArray &data);
|
|
|
|
void debugThis();
|
|
|
|
|
|
|
|
signals:
|
2019-01-10 06:44:48 +00:00
|
|
|
void haveTextMessage(QString message); // status, debug only
|
|
|
|
void sendDataOutToPort(const QByteArray &writeData); // not used
|
2018-06-19 19:58:52 +00:00
|
|
|
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
|
2021-02-02 09:05:59 +00:00
|
|
|
void haveSerialPortError(const QString port, const QString error);
|
2021-02-05 20:26:18 +00:00
|
|
|
void haveStatusUpdate(const QString text);
|
2018-06-19 19:58:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setupComm();
|
|
|
|
void openPort();
|
|
|
|
void closePort();
|
|
|
|
|
2021-11-06 06:21:36 +00:00
|
|
|
|
2019-01-10 06:44:48 +00:00
|
|
|
void sendDataOut(const QByteArray &writeData); // out to radio
|
2018-06-19 19:58:52 +00:00
|
|
|
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;
|
2018-06-22 23:31:52 +00:00
|
|
|
bool rolledBack;
|
2018-06-19 19:58:52 +00:00
|
|
|
|
2019-01-10 06:44:48 +00:00
|
|
|
QSerialPort *pseudoterm;
|
|
|
|
int ptfd; // pseudo-terminal file desc.
|
|
|
|
mutable QMutex ptMutex;
|
|
|
|
bool havePt;
|
|
|
|
QString ptDevSlave;
|
|
|
|
|
2021-11-06 06:21:36 +00:00
|
|
|
bool PTTviaRTS = false;
|
|
|
|
|
2018-06-19 19:58:52 +00:00
|
|
|
bool isConnected; // port opened
|
|
|
|
mutable QMutex mutex;
|
2018-06-22 23:31:52 +00:00
|
|
|
void printHex(const QByteArray &pdata, bool printVert, bool printHoriz);
|
2022-04-18 19:29:50 +00:00
|
|
|
bool combineWf = false;
|
|
|
|
QByteArray spectrumData;
|
|
|
|
quint8 spectrumDivisionNumber;
|
|
|
|
quint8 spectrumDivisionMax;
|
|
|
|
quint8 spectrumCenterOrFixed;
|
|
|
|
quint8 spectrumInformation;
|
|
|
|
quint8 spectrumOutOfRange;
|
|
|
|
quint8 lastSpectrum = 0;
|
2018-06-19 19:58:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COMMHANDLER_H
|