113 lines
2.4 KiB
C++
113 lines
2.4 KiB
C++
#ifndef MAINWINDOW_H
|
|
#define MAINWINDOW_H
|
|
|
|
#include <QMainWindow>
|
|
#include <QMap>
|
|
#include <QtSerialPort/QSerialPortInfo>
|
|
#include <QtSerialPort/QSerialPort>
|
|
#include <QFile>
|
|
#include <QTimer>
|
|
#include "../Interface.hpp"
|
|
#include <asio/asio.hpp>
|
|
#include <QLibrary>
|
|
#include "MQTTOpenration.h"
|
|
#include "SerialPortScan.h"
|
|
#include "log_utils.h"
|
|
#include "SeriaPort.h"
|
|
|
|
|
|
namespace Ui
|
|
{
|
|
class MainWindow;
|
|
}
|
|
|
|
class MainWindow : public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit MainWindow(QWidget* parent = nullptr, ToolkitBase_Interface* pBaseInterface = nullptr);
|
|
~MainWindow();
|
|
|
|
signals:
|
|
void sigMqttCallback(QString strTopic, QString strMessage);
|
|
void sigMqttCallback(QString strTopic, QByteArray arrayMessage);
|
|
|
|
private slots:
|
|
void OnButtonClicked();
|
|
void OnSerialPortComboxCurIndexChanged(int index);
|
|
|
|
public slots:
|
|
void sltMQTTMessage(QString strTopic, QString strMessage);
|
|
void sltMQTTMessage(QString strTopic, QByteArray arrayMessage);
|
|
void sltMQTTSubcribe(QString strTopic);
|
|
void sltMQTTCancelTopic(QString strTopic);
|
|
|
|
protected:
|
|
|
|
struct Settings
|
|
{
|
|
// 串口名
|
|
QString name;
|
|
|
|
// 波特率
|
|
asio::serial_port::baud_rate baudRate;
|
|
QString strBaudRate;
|
|
|
|
// 奇偶校验
|
|
asio::serial_port::parity parity;
|
|
QString strParity;
|
|
|
|
// 流控制
|
|
asio::serial_port::flow_control flowControl;
|
|
QString strFlowControl;
|
|
|
|
// 数据位
|
|
asio::serial_port::character_size dataBits;
|
|
QString strDataBits;
|
|
|
|
// 停止位
|
|
asio::serial_port::stop_bits stopBits;
|
|
QString strStopBits;
|
|
};
|
|
|
|
protected:
|
|
virtual void mouseDoubleClickEvent(QMouseEvent* event);
|
|
|
|
private:
|
|
/*
|
|
* 串口相关函数
|
|
*/
|
|
void FillPortsParameters();
|
|
void FillPortsInfo();
|
|
void UpdateSettings();
|
|
void LoadConnect();
|
|
void ShowMsg(QString title, QString msg);
|
|
|
|
private:
|
|
void InitStyles();
|
|
|
|
|
|
private:
|
|
Ui::MainWindow* ui;
|
|
|
|
ToolkitBase_Interface* m_pBaseInterface;
|
|
/*
|
|
* 串口相关
|
|
*/
|
|
Settings m_varSerialPortSettings;
|
|
SerialPortScan* m_pSeriaPortScan;
|
|
QTimer m_timer;
|
|
QStringList m_portNameList;
|
|
QMap <int,std::shared_ptr<SerialPort>> m_ptrSerialPortList;
|
|
/*
|
|
* MQTT相关
|
|
*/
|
|
MQTTOpenration* m_pMQTTOpenration; //MQTT句柄
|
|
bool m_bMQTTisOpen = false; //MQTT服务是否连接
|
|
QStringList m_topicList; //订阅主题
|
|
|
|
};
|
|
|
|
#endif // MAINWINDOW_H
|