91 lines
2.7 KiB
C
91 lines
2.7 KiB
C
|
|
#ifndef MAINWINDOW_H
|
|||
|
|
#define MAINWINDOW_H
|
|||
|
|
|
|||
|
|
#include "clickablecombobox.h"
|
|||
|
|
#include <QMainWindow>
|
|||
|
|
//#include <QSerialPort>
|
|||
|
|
#include <QSerialPortInfo>
|
|||
|
|
#include <QTimer>
|
|||
|
|
#include <QLabel>
|
|||
|
|
#include <QSettings>
|
|||
|
|
#include <QSystemTrayIcon>
|
|||
|
|
#include <QMap>
|
|||
|
|
#include <QFile>
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
QT_BEGIN_NAMESPACE
|
|||
|
|
namespace Ui { class MainWindow; }
|
|||
|
|
QT_END_NAMESPACE
|
|||
|
|
|
|||
|
|
class MainWindow : public QMainWindow
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
public:
|
|||
|
|
MainWindow(QWidget *parent = nullptr);
|
|||
|
|
~MainWindow();
|
|||
|
|
ClickableComboBox *portComboBox;
|
|||
|
|
|
|||
|
|
private slots:
|
|||
|
|
void on_openButton_clicked();
|
|||
|
|
void on_closeButton_clicked();
|
|||
|
|
void on_sendButton_clicked();
|
|||
|
|
void on_clearSendButton_clicked();
|
|||
|
|
void on_clearReceiveButton_clicked();
|
|||
|
|
void on_clearDecimalButton_clicked();
|
|||
|
|
void readData();
|
|||
|
|
void on_saveButton_clicked();
|
|||
|
|
void on_timerButton_clicked();
|
|||
|
|
void timer_Event();
|
|||
|
|
void on_realTimeSaveCheckBox_stateChanged(int state);
|
|||
|
|
void openConfigDir(); // 打开配置文件目录
|
|||
|
|
void openRealTimeSaveDir(); // 打开实时保存目录
|
|||
|
|
void parseBeidouData(const QString& beidouData);
|
|||
|
|
void parseTxxxData(const QString& payload);
|
|||
|
|
QString hexToAscii(const QString& hexStr);
|
|||
|
|
void processHexTxxxFrames();
|
|||
|
|
void processHexBdtxrFrames();
|
|||
|
|
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
Ui::MainWindow *ui;
|
|||
|
|
QSerialPort *serial;
|
|||
|
|
QTimer *timer;
|
|||
|
|
|
|||
|
|
void updatePortList();
|
|||
|
|
void updateBaudRateList();
|
|||
|
|
void saveRealTimeData(const QString &data); // 单参数版本,ID从行尾提取
|
|||
|
|
QFile realTimeFile;
|
|||
|
|
|
|||
|
|
int txCount; // S
|
|||
|
|
int rxCount; // R
|
|||
|
|
QLabel *txLabel; // 发送计数的标签
|
|||
|
|
QLabel *rxLabel; // 接收计数的标签
|
|||
|
|
|
|||
|
|
QByteArray dataBuffer;
|
|||
|
|
|
|||
|
|
void readConfig(); // 用于读取配置文件
|
|||
|
|
QString defaultFilePath; // 保存默认文件路径
|
|||
|
|
void generateFileName();
|
|||
|
|
|
|||
|
|
QSystemTrayIcon *trayIcon; // 托盘图标
|
|||
|
|
void closeEvent(QCloseEvent *event) override;
|
|||
|
|
|
|||
|
|
QMap<QString, QFile*> realTimeFiles;
|
|||
|
|
QByteArray receiveBuffer; // 解析缓冲(原始字节)
|
|||
|
|
QByteArray displayBuffer; // 接收区显示缓冲(文本模式)
|
|||
|
|
QString hexParseBuffer; // 十六进制解析缓冲(空格分隔的大写HEX)
|
|||
|
|
QMap<QString, int> recordCounts; // 存储每个ID的记录计数
|
|||
|
|
void initializeRecordCounts(); // 初始化记录计数函数
|
|||
|
|
int getLastRecordFromFile(const QString &filePath); // 读取文件最后一条RECORD值
|
|||
|
|
|
|||
|
|
// 日志相关
|
|||
|
|
QFile *logFile; // 日志文件
|
|||
|
|
void initializeLogFile(); // 初始化日志文件
|
|||
|
|
void writeLog(const QString &message); // 写入日志
|
|||
|
|
QString logDirPath; // 日志目录(来自 config.ini 的 [Log]/defaultPath)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#endif // MAINWINDOW_H
|