wfview/commhandler.h

79 wiersze
1.9 KiB
C
Czysty Zwykły widok Historia

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:
commHandler();
commHandler(QString portName, quint32 baudRate);
bool serialError;
2018-06-19 19:58:52 +00:00
~commHandler();
private slots:
void receiveDataIn(); // from physical port
void receiveDataInPt(); // from pseudo-term
2018-06-19 19:58:52 +00:00
void receiveDataFromUserToRig(const QByteArray &data);
void debugThis();
signals:
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
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();
void initializePt(); // like ch constructor
void setupPtComm();
void openPtPort();
void sendDataOut(const QByteArray &writeData); // out to radio
void sendDataOutPt(const QByteArray &writeData); // out to pseudo-terminal
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;
bool rolledBack;
2018-06-19 19:58:52 +00:00
QSerialPort *pseudoterm;
int ptfd; // pseudo-terminal file desc.
mutable QMutex ptMutex;
bool havePt;
QString ptDevSlave;
2018-06-19 19:58:52 +00:00
bool isConnected; // port opened
mutable QMutex mutex;
void printHex(const QByteArray &pdata, bool printVert, bool printHoriz);
2018-06-19 19:58:52 +00:00
};
#endif // COMMHANDLER_H