proto-debuger/protoDebuger/serialcontroller.h

60 lines
1.4 KiB
C
Raw Normal View History

2021-04-10 14:22:41 +00:00
#ifndef SERIALCONTROLLER_H
#define SERIALCONTROLLER_H
#include <QObject>
#include <QList>
#include "qserialproto.h"
#include <vector>
#include <QDebug>
2021-04-12 15:39:06 +00:00
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
2021-04-10 14:22:41 +00:00
#define OK 0
#define NULLPOINTER -1
/*
2021-04-11 03:28:04 +00:00
*
2021-04-10 14:22:41 +00:00
data -> controler -> proto -> listener
*/
using namespace std;
class SerialController : public QObject
{
Q_OBJECT
public slots:
void ReadyRead();
void AboutClose();
public:
2021-04-16 18:27:32 +00:00
typedef class {
public:
virtual int OnDataRecv();
}SerialListener;
2021-04-10 14:22:41 +00:00
typedef enum {
ERROR_OPEN = -1,
ERROR_SEND = -2,
}SerialError;
explicit SerialController(QObject *parent = nullptr);
2021-04-12 15:39:06 +00:00
int OpenSerial(QString port,QString baudRate, QString dataBits, QString stopBits, QString flow);
2021-04-10 14:22:41 +00:00
int CloseSerial();
2021-04-12 15:39:06 +00:00
QList<QSerialPortInfo> GetPorts();
2021-04-10 14:22:41 +00:00
int SetProto(QSerialProto *);
int SendData(uint8_t *,uint8_t len);
2021-04-12 15:39:06 +00:00
void GetSetting(QString baudRate, QString dataBits, QString stopBits, QString flow);
2021-04-10 14:22:41 +00:00
signals:
private:
2021-04-12 15:39:06 +00:00
QList<QSerialPortInfo> mPorts;
2021-04-10 14:22:41 +00:00
bool mConnected;
2021-04-12 15:39:06 +00:00
QSerialPort *mCurrentPort;
2021-04-10 14:22:41 +00:00
QSerialProto *mProto;
2021-04-12 15:39:06 +00:00
QString mPortName;
uint32_t mBaudrate;
QSerialPort::DataBits mDataBits;
QSerialPort::Parity mParity;
QSerialPort::StopBits mStopBits;
QSerialPort::FlowControl mFlow;
2021-04-10 14:22:41 +00:00
};
#endif // SERIALCONTROLLER_H