-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommhandler.h
95 lines (74 loc) · 2.29 KB
/
commhandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef COMMHANDLER_H
#define COMMHANDLER_H
#include <QObject>
#include <QMutex>
#include <QDataStream>
#include <QtSerialPort/QSerialPort>
#include <QTime>
#include <QTimer>
#include "wfviewtypes.h"
// 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:
commHandler(QObject* parent = nullptr);
commHandler(QString portName, quint32 baudRate, quint8 wfFormat,QObject* parent = nullptr);
bool serialError;
bool rtsStatus();
~commHandler();
public slots:
void setUseRTSforPTT(bool useRTS);
void setRTS(bool rtsOn);
void handleError(QSerialPort::SerialPortError error);
void init();
private slots:
void receiveDataIn(); // from physical port
void receiveDataFromUserToRig(const QByteArray &data);
void debugThis();
signals:
void haveTextMessage(QString message); // status, debug only
void sendDataOutToPort(const QByteArray &writeData); // not used
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
void havePortError(errorType err);
void haveStatusUpdate(const QString text);
private:
void setupComm();
void openPort();
void closePort();
void sendDataOut(const QByteArray &writeData); // out to radio
void debugMe();
void hexPrint();
//QDataStream stream;
QByteArray outPortData;
QByteArray inPortData;
QByteArray previousSent;
//QDataStream outStream;
//QDataStream inStream;
unsigned char buffer[256];
QString portName;
QSerialPort *port=Q_NULLPTR;
qint32 baudrate;
unsigned char stopbits;
bool rolledBack;
QSerialPort *pseudoterm;
int ptfd; // pseudo-terminal file desc.
mutable QMutex ptMutex;
bool havePt;
QString ptDevSlave;
bool PTTviaRTS = false;
bool isConnected; // port opened
mutable QMutex mutex;
void printHex(const QByteArray &pdata, bool printVert, bool printHoriz);
bool combineWf = false;
QByteArray spectrumData;
quint8 spectrumDivisionNumber;
quint8 spectrumDivisionMax;
quint8 spectrumCenterOrFixed;
quint8 spectrumInformation;
quint8 spectrumOutOfRange;
quint8 lastSpectrum = 0;
QTime lastDataReceived;
};
#endif // COMMHANDLER_H