1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/examples/qqtnetworkexample/qqtuserserialprotocol.h

131 lines
3.1 KiB
C
Raw Normal View History

2017-10-17 22:00:45 +08:00
#ifndef QQTUSERSERIALPROTOCOL_H
#define QQTUSERSERIALPROTOCOL_H
#include "qqtserialmessage.h"
#include "qqtprotocol.h"
#include "qqtserialport.h"
#define _SERIAL_HAND 0x0001
#define _SERIAL_HANDACK 0x8001
#define _SERIAL_CLOSE 0x0002
#define _SERIAL_CLOSEACK 0x8002
#define _SERIAL_WRITEDEVNO 0x0003
#define _SERIAL_WRITEDEVNOACK 0x8003
#define _SERIAL_READDEVNO 0x0004
#define _SERIAL_READDEVNOACK 0x8004
#define _SERIAL_WRITEPASS 0x0005
#define _SERIAL_WRITEPASSACK 0x8005
#define _SERIAL_READPASS 0x0006
#define _SERIAL_READPASSACK 0x8006
#define _SERIAL_EXCEPTIONACK 0x800F
class QQTHandupAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTHandupAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
void pack(QByteArray& l);
};
class QQTCloseAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTCloseAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
2017-10-24 11:07:24 +08:00
void pack(QByteArray& l);
2017-10-17 22:00:45 +08:00
};
class QQTWriteSerialNoAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTWriteSerialNoAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
void pack(QByteArray& l);
};
class QQTReadSerialNoAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTReadSerialNoAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
void pack(QByteArray& l);
};
class QQTWritePassAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTWritePassAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
2017-10-24 11:07:24 +08:00
void pack(QByteArray& l);
2017-10-17 22:00:45 +08:00
};
class QQTReadPassAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTReadPassAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
2017-10-24 11:07:24 +08:00
void pack(QByteArray& l);
2017-10-17 22:00:45 +08:00
};
class QQTExceptionAck : public QQTSerialMessage
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTExceptionAck(QObject* parent = 0) : QQTSerialMessage(parent) {}
2017-10-17 22:00:45 +08:00
2017-10-24 11:07:24 +08:00
void pack(QByteArray& l);
2017-10-17 22:00:45 +08:00
};
/**
* @brief The QQTUserSerialProtocol class
* 使
*/
2017-10-29 21:38:30 +08:00
class QQTUserSerialProtocol : public QQtProtocol
2017-10-17 22:00:45 +08:00
{
Q_OBJECT
public:
2017-10-24 11:07:24 +08:00
explicit QQTUserSerialProtocol(QObject* parent = 0);
2017-10-17 22:00:45 +08:00
~QQTUserSerialProtocol();
signals:
void sigSerialUnlock();
public slots:
void recvHandup(const QByteArray& l);
void sendHandupAck();
void recvClose(const QByteArray& l);
void sendCloseAck();
void recvWriteSerialNumber(const QByteArray& l);
void sendWriteSerialNumberAck();
void recvReadSerial(const QByteArray& l);
void sendReadSerialAck();
void recvWritePassword(const QByteArray& l);
void sendWritePasswordAck();
void recvReadPassword(const QByteArray& l);
void sendReadPasswordAck();
void sendExceptionAck();
2017-10-29 21:38:30 +08:00
// QQtProtocol interface
2017-10-17 22:00:45 +08:00
public:
quint16 minlength() override;
quint16 maxlength() override;
2017-10-24 11:07:24 +08:00
quint16 splitter(const QByteArray& s) override;
bool dispatcher(const QByteArray& m) override;
2017-10-17 22:00:45 +08:00
private:
2017-11-22 11:52:11 +08:00
QQtSerialPort* s0;
2017-10-17 22:00:45 +08:00
};
2017-11-22 11:52:11 +08:00
QQtSerialPort* QQTUserSerialPortInstance(QObject* parent = 0, QString name = "/dev/tty0", QQtSerialPort::BaudRate = QQtSerialPort::Baud57600);
2017-10-17 22:00:45 +08:00
#endif // QQTUSERSERIALPROTOCOL_H