2024-02-29 06:20:06 +00:00
|
|
|
|
|
2024-03-14 13:14:36 +00:00
|
|
|
|
#include <QFileDialog>
|
2024-02-29 06:20:06 +00:00
|
|
|
|
#include "MainWindow.h"
|
|
|
|
|
|
#include "ui_MainWindow.h"
|
2024-03-14 13:14:36 +00:00
|
|
|
|
#include "TcpClient.h"
|
2024-02-29 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
#define DEBUG_HTTP 1
|
|
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->statusBar = new QStatusBar();
|
|
|
|
|
|
this->statusInfo = new QLabel("初始化完成",this);
|
|
|
|
|
|
this->statusBar->addPermanentWidget(this->statusInfo);//显示正常信息
|
2024-03-17 10:30:35 +00:00
|
|
|
|
QLabel* statusVersion = new QLabel("开启时间:" + QDateTime::currentDateTime().toString("yy.MM.dd.hh.mm"),this);
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->statusBar->addWidget(statusVersion);
|
|
|
|
|
|
|
|
|
|
|
|
layout()->addWidget(this->statusBar);
|
|
|
|
|
|
|
2024-03-17 10:30:35 +00:00
|
|
|
|
this->setWindowTitle("Matrix_RFID 车号识别程序(勿关!!)");
|
2024-02-29 06:20:06 +00:00
|
|
|
|
this->configPath_ = "./config/config.ini";
|
|
|
|
|
|
|
|
|
|
|
|
if (!this->mkLogDir())
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError("创建Log目录失败!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 配置文件读取
|
|
|
|
|
|
QString errorMessage = "";
|
|
|
|
|
|
if (!ConfigUtil::readBaseConfig(this->configPath_, errorMessage, this->baseConfig_))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError(errorMessage);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!ConfigUtil::readInterfaceConfig(this->configPath_, errorMessage, this->interfaceConfig_))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError(errorMessage);
|
|
|
|
|
|
}
|
2024-03-14 13:14:36 +00:00
|
|
|
|
if (!ConfigUtil::readSocketServerConfig(this->configPath_, errorMessage, this->socketServerConfig_))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError(errorMessage);
|
|
|
|
|
|
}
|
2024-02-29 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
// 获取本机串口列表
|
|
|
|
|
|
this->getComList();
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化界面上的串口打开参数
|
|
|
|
|
|
this->initComboBox();
|
|
|
|
|
|
|
|
|
|
|
|
this->serial_ = new QSerialPort;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pSystemTray=new QSystemTrayIcon(this);
|
|
|
|
|
|
|
|
|
|
|
|
connect(this->ui->openComButton, &QPushButton::clicked, this, &MainWindow::openComClicked);
|
|
|
|
|
|
|
|
|
|
|
|
connect(this, &MainWindow::getRfid_signals, this, &MainWindow::getQueueDataThread);
|
|
|
|
|
|
|
|
|
|
|
|
connect(this, &MainWindow::upRfid_signals, this, &MainWindow::upRfid);
|
|
|
|
|
|
|
2024-03-14 13:14:36 +00:00
|
|
|
|
connect(this->ui->testButton, &QPushButton::clicked, this, &MainWindow::readTestInfo);
|
|
|
|
|
|
// 识别状态改变
|
|
|
|
|
|
connect(this, &MainWindow::IdentifyType, this, &MainWindow::IdentifyTypeUpdate);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
//最小化信号槽
|
|
|
|
|
|
connect(m_pSystemTray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason)));
|
|
|
|
|
|
|
|
|
|
|
|
this->logRfidRecvName = "./Logs/rfid_data.txt";
|
2024-03-27 12:09:46 +00:00
|
|
|
|
this->recvLog.setFileName(logRfidRecvName);
|
|
|
|
|
|
this->recvLog.open(QIODevice::ReadWrite | QIODevice::Append);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
//初始最小化
|
|
|
|
|
|
//this->showMinimized();//最小化
|
|
|
|
|
|
// 设置最大展示数据行数
|
|
|
|
|
|
this->ui->textBrowser->document()->setMaximumBlockCount(1000);
|
|
|
|
|
|
|
|
|
|
|
|
getStandardItemModel();
|
|
|
|
|
|
this->ui->resultTable->setModel(this->resultTableModel_);
|
|
|
|
|
|
this->ui->resultTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
|
this->ui->resultTable->verticalHeader()->setMinimumWidth(50);
|
|
|
|
|
|
|
|
|
|
|
|
if (!this->baseConfig_.upResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon("./Fail.ico");
|
|
|
|
|
|
QPixmap m_pic = icon.pixmap(icon.actualSize(QSize(32, 32)));//size自行调整
|
|
|
|
|
|
this->ui->upflagLabel->setPixmap(m_pic);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
QIcon icon("./Succ.ico");
|
|
|
|
|
|
QPixmap m_pic = icon.pixmap(icon.actualSize(QSize(32, 32)));//size自行调整
|
|
|
|
|
|
this->ui->upflagLabel->setPixmap(m_pic);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-14 13:14:36 +00:00
|
|
|
|
if (this->baseConfig_.useSocketServer)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 创建线程
|
|
|
|
|
|
QThread *threadWork = new QThread; // 任务线程
|
|
|
|
|
|
|
|
|
|
|
|
this->tcpClient = new TcpClient(this);
|
|
|
|
|
|
this->tcpClient->moveToThread(threadWork);
|
|
|
|
|
|
|
|
|
|
|
|
connect(this, &MainWindow::connect_socket, this->tcpClient, &TcpClient::connectToServer);
|
|
|
|
|
|
|
|
|
|
|
|
// 子线程反馈 socket 到主线程
|
|
|
|
|
|
connect(this->tcpClient, &TcpClient::socketComplete, this, [=](QTcpSocket* tcp, QString ip, quint16 port){
|
|
|
|
|
|
this->tcp_ = tcp;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 接收子线程的消息提示
|
2024-03-17 11:11:34 +00:00
|
|
|
|
connect(this->tcpClient, &TcpClient::sendTcpInfoSignals, this, [=](const QString& info){
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->logInfo(info);
|
|
|
|
|
|
this->statusInfo->setText(info);
|
|
|
|
|
|
if (info == "链接服务端超时"
|
|
|
|
|
|
|| info == "未连接Socket服务器"
|
|
|
|
|
|
|| info == "链接服务端失败"
|
|
|
|
|
|
|| info == "服务端断开连接"
|
|
|
|
|
|
|| info == "链接服务端失败")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->videoHasTrain = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-03-17 11:11:34 +00:00
|
|
|
|
// 接收子线程的TCP消息内容展示
|
|
|
|
|
|
connect(this->tcpClient, &TcpClient::getTcpInfoSignals, this, [=](const QString& info){
|
|
|
|
|
|
this->logInfo(info);
|
|
|
|
|
|
});
|
2024-03-14 13:14:36 +00:00
|
|
|
|
|
|
|
|
|
|
emit connect_socket(this->socketServerConfig_.server_ip, this->socketServerConfig_.server_port);
|
|
|
|
|
|
|
2024-04-03 17:51:29 +00:00
|
|
|
|
connect(this->tcpClient, &TcpClient::comeTrainSignals, this, [=](bool type) {
|
2024-03-14 13:14:36 +00:00
|
|
|
|
if (type)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logInfo("视频车号识别-来车了");
|
|
|
|
|
|
this->videoHasTrain = true;
|
|
|
|
|
|
emit IdentifyType();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logInfo("视频车号识别-火车离开了");
|
|
|
|
|
|
this->videoHasTrain = false;
|
2024-03-17 10:30:35 +00:00
|
|
|
|
if (this->needIdentify)
|
|
|
|
|
|
emit IdentifyType();
|
2024-03-14 13:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-04-03 17:51:29 +00:00
|
|
|
|
connect(this->tcpClient, &TcpClient::getDirectionSignals, this, [=](int direction) {
|
|
|
|
|
|
if (this->iDirection != direction)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logInfo("获得方向判定:" + QString(direction > -1 ? (direction > 0 ? "需识别" : "待定") : "无需上传"));
|
|
|
|
|
|
this->iDirection = direction;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-03-14 13:14:36 +00:00
|
|
|
|
}
|
2024-03-21 06:10:39 +00:00
|
|
|
|
|
2024-03-27 12:09:46 +00:00
|
|
|
|
ui->openComButton->click();
|
2024-04-03 17:51:29 +00:00
|
|
|
|
|
|
|
|
|
|
// QThread *thread = new QThread;
|
|
|
|
|
|
// // 创建并移至线程的lambda表达式
|
|
|
|
|
|
// moveToThread(thread);
|
|
|
|
|
|
// connect(thread, &QThread::started, [=]() {
|
|
|
|
|
|
//// // 配置文件读取
|
|
|
|
|
|
//// QString errorMessage = "";
|
|
|
|
|
|
//// ai_matrix::BaseConfig baseConfig;
|
|
|
|
|
|
//// ai_matrix::InterfaceConfig interfaceConfig;
|
|
|
|
|
|
//// if (!ConfigUtil::readBaseConfig(this->configPath_, errorMessage, baseConfig))
|
|
|
|
|
|
//// {
|
|
|
|
|
|
//// this->logError(errorMessage);
|
|
|
|
|
|
//// }
|
|
|
|
|
|
//// if (!ConfigUtil::readInterfaceConfig(this->configPath_, errorMessage, interfaceConfig))
|
|
|
|
|
|
//// {
|
|
|
|
|
|
//// this->logError(errorMessage);
|
|
|
|
|
|
//// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// while (true)
|
|
|
|
|
|
// {
|
|
|
|
|
|
//// if ((this->iDirection == 0 && this->queueTrainInfo_.size() <= 4) || this->iDirection < 0) continue;
|
|
|
|
|
|
// while (!this->queueTrainInfo_.isEmpty())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// TrainInfo trainInfo_ = this->queueTrainInfo_.pop();
|
|
|
|
|
|
// if (!this->upWeb(trainInfo_))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// //this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败!");
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
//// QThread::msleep(1000);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// QThread::msleep(2000);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
//
|
|
|
|
|
|
// connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
|
|
|
|
|
// thread->start();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logInfo("-- 程序退出 --");
|
2024-02-29 11:35:22 +00:00
|
|
|
|
this->initParam();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::logDebug(const QString& message) {
|
|
|
|
|
|
LogDebug << message.toStdString();
|
2024-02-29 11:35:22 +00:00
|
|
|
|
ui->textBrowser->append(QString("[Debug] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::logInfo(const QString& message) {
|
|
|
|
|
|
LogInfo << message.toStdString();
|
2024-02-29 11:35:22 +00:00
|
|
|
|
ui->textBrowser->append(QString("[Info] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::logWarn(const QString& message) {
|
|
|
|
|
|
LogWarn << message.toStdString();
|
2024-02-29 11:35:22 +00:00
|
|
|
|
ui->textBrowser->append(QString("[Warn] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::logError(const QString& message) {
|
|
|
|
|
|
LogError << message.toStdString();
|
2024-02-29 11:35:22 +00:00
|
|
|
|
ui->textBrowser->append(QString("[Error] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::initParam() {
|
2024-03-27 12:09:46 +00:00
|
|
|
|
this->rfidSourceInfo = "";
|
2024-02-29 06:20:06 +00:00
|
|
|
|
this->trainTime = "";
|
2024-03-27 12:09:46 +00:00
|
|
|
|
if (this->recvLog.isOpen()) this->recvLog.close();
|
2024-02-29 11:35:22 +00:00
|
|
|
|
this->vecTrain.clear();
|
|
|
|
|
|
this->needIdentify = false;
|
|
|
|
|
|
this->rnameRfidLog();
|
|
|
|
|
|
this->queue_.clear();
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->iDirection = 0;
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 创建日志目录
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool MainWindow::mkLogDir()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_access("Logs", 0) == -1) { //判断是否存在日志的文件夹,没有则创建
|
|
|
|
|
|
std::string folderPath = "Logs";
|
|
|
|
|
|
if (0 != _mkdir(folderPath.c_str()))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::mkRfidLog()
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
QFileInfo fileInfo(this->logRfidRecvName);
|
|
|
|
|
|
if(fileInfo.isFile())
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
this->recvLog.setFileName(this->logRfidRecvName);
|
|
|
|
|
|
if (!this->recvLog.isOpen())
|
|
|
|
|
|
{
|
|
|
|
|
|
this->recvLog.open(QIODevice::ReadWrite | QIODevice::Append);
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
|
this->logError("创建、打开RFID原始数据日志文件失败,详细:");
|
|
|
|
|
|
this->logError(e.what());
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-27 12:09:46 +00:00
|
|
|
|
void MainWindow::deleteOldFiles(const QString &path, int days)
|
|
|
|
|
|
{
|
|
|
|
|
|
QDir dir(path);
|
|
|
|
|
|
foreach(QFileInfo fi, dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot))
|
|
|
|
|
|
{
|
|
|
|
|
|
if((fi.lastModified().addDays(days) < QDateTime::currentDateTime()))
|
|
|
|
|
|
{
|
|
|
|
|
|
QFile::remove(fi.absoluteFilePath());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
bool MainWindow::rnameRfidLog()
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
this->recvLog.close();
|
|
|
|
|
|
QFile logFile(this->logRfidRecvName);
|
|
|
|
|
|
QFileInfo fileInfo(logFile);
|
2024-03-27 12:09:46 +00:00
|
|
|
|
if (fileInfo.size() == 0) return false;
|
2024-02-29 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
QString newLogFileName = fileInfo.path() + "/";
|
|
|
|
|
|
newLogFileName.append(QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"));
|
|
|
|
|
|
newLogFileName.append(".txt");
|
|
|
|
|
|
|
|
|
|
|
|
if (!logFile.rename(newLogFileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError("读取RFID原始数据,存储重命名失败!");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-03-27 12:09:46 +00:00
|
|
|
|
|
|
|
|
|
|
this->deleteOldFiles(fileInfo.path(), 3);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
|
this->logError("读取RFID原始数据,存储重命名失败!");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::saveRfidLog(const QString &value)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
QString logValue = value + "\n";
|
|
|
|
|
|
if (!this->recvLog.isOpen())
|
|
|
|
|
|
{
|
|
|
|
|
|
this->recvLog.open(QIODevice::ReadWrite | QIODevice::Append);
|
|
|
|
|
|
}
|
|
|
|
|
|
this->recvLog.write(logValue.toUtf8());
|
|
|
|
|
|
this->recvLog.flush();
|
|
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
|
this->logError("保存RFID原数据失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取本地所有串口
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
QList<QString> MainWindow::getComList() {
|
|
|
|
|
|
// 获取系统所有串口信息
|
|
|
|
|
|
QList<QSerialPortInfo> availablePorts = QSerialPortInfo::availablePorts();
|
|
|
|
|
|
for (const auto & availablePort : availablePorts) {
|
|
|
|
|
|
this->comList.append(availablePort.portName());
|
|
|
|
|
|
}
|
|
|
|
|
|
return this->comList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化 comboxBox 组件的值
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::initComboBox() {
|
|
|
|
|
|
// ui->BTBox->setEditable(true);
|
|
|
|
|
|
ui->BTBox->setStyleSheet("QComboBox {background-color: rgb(255, 255, 255);} QComboBox QAbstractItemView::item {min-height: 30px; background-color: rgb(225, 225, 225);}");
|
|
|
|
|
|
ui->BTBox->setView(new QListView());
|
|
|
|
|
|
ui->comBox->setEditable(true);
|
|
|
|
|
|
ui->comBox->setStyleSheet("QComboBox {background-color: rgb(255, 255, 255);} QComboBox QAbstractItemView::item {min-height: 30px; background-color: rgb(225, 225, 225);}");
|
|
|
|
|
|
ui->comBox->setMaxVisibleItems(5);
|
|
|
|
|
|
ui->comBox->setView(new QListView());
|
|
|
|
|
|
ui->comBox->addItems(this->comList);
|
|
|
|
|
|
if (this->baseConfig_.comName != "") {
|
|
|
|
|
|
if (ui->comBox->findText(this->baseConfig_.comName) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->comBox->addItem(this->baseConfig_.comName);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui->comBox->setCurrentText(this->baseConfig_.comName);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ui->BTBox->findText(QString::number(this->baseConfig_.baud)) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->BTBox->addItem(QString::number(this->baseConfig_.baud));
|
|
|
|
|
|
}
|
|
|
|
|
|
ui->BTBox->setCurrentText(QString::number(this->baseConfig_.baud));
|
|
|
|
|
|
|
|
|
|
|
|
ui->truckEdit->setText(QString::number(this->baseConfig_.trackName));
|
2024-03-14 13:14:36 +00:00
|
|
|
|
|
|
|
|
|
|
this->rfidHasTrain = false;
|
|
|
|
|
|
this->videoHasTrain = false;
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief:获取系统时间
|
|
|
|
|
|
* @param:
|
|
|
|
|
|
* @return:空
|
|
|
|
|
|
*/
|
|
|
|
|
|
QString MainWindow::getSystemTime()
|
|
|
|
|
|
{
|
|
|
|
|
|
return QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取结果框的ItemModel
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
QStandardItemModel* MainWindow::getStandardItemModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this->resultTableModel_== nullptr) this->resultTableModel_ = new QStandardItemModel();
|
|
|
|
|
|
this->resultTableModel_->setColumnCount(1);
|
|
|
|
|
|
this->resultTableModel_->setHeaderData(0,Qt::Horizontal, "车号");
|
|
|
|
|
|
return this->resultTableModel_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStandardItem* MainWindow::getStandardItem(const QString &value)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItem *resultTableItem = new QStandardItem();
|
|
|
|
|
|
resultTableItem->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
|
resultTableItem->setText(value);
|
|
|
|
|
|
return resultTableItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************同 web 交互****************************************/
|
2024-03-27 12:09:46 +00:00
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief:Http发送RFID数据
|
|
|
|
|
|
* @param:carriageType:车型
|
|
|
|
|
|
* @param:carriageNumber:车号
|
|
|
|
|
|
* @param:carriageOrder:车节号
|
|
|
|
|
|
* @param:time:当前时间
|
2024-03-27 12:09:46 +00:00
|
|
|
|
* @param:rfidSourceInfo:RFID的原始数据(过滤掉了重复磁条信息)
|
2024-02-29 06:20:06 +00:00
|
|
|
|
* @return: 成功:true
|
|
|
|
|
|
* 失败:false
|
|
|
|
|
|
*/
|
2024-04-03 17:51:29 +00:00
|
|
|
|
bool MainWindow::upWeb(TrainInfo &trainInfo)
|
2024-02-29 06:20:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
Json::Value arrayObj; //构建对象
|
|
|
|
|
|
|
2024-04-03 17:51:29 +00:00
|
|
|
|
arrayObj["comeTime"] = trainInfo.trainTime;
|
|
|
|
|
|
arrayObj["collectTime"] = trainInfo.collectTime;
|
|
|
|
|
|
arrayObj["carriageNumber"] = trainInfo.carriageNum;
|
|
|
|
|
|
arrayObj["carriageType"] = trainInfo.carriageType;
|
|
|
|
|
|
arrayObj["carriageOrder"] = trainInfo.strOrder;
|
|
|
|
|
|
// arrayObj["steel"] = trainInfo.strRfidInfo;
|
2024-02-29 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
Json::Value trainParams;
|
|
|
|
|
|
trainParams["poundNo"] = std::to_string(this->baseConfig_.trackName);
|
|
|
|
|
|
arrayObj["trainParams"] = trainParams;
|
|
|
|
|
|
Json::StreamWriterBuilder writer;
|
|
|
|
|
|
std::string str = Json::writeString(writer, arrayObj);
|
|
|
|
|
|
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logInfo("第" + QString::fromStdString(trainInfo.strOrder) + "节,发送web: " + QString::fromStdString(str));
|
2024-03-27 12:09:46 +00:00
|
|
|
|
httplib::Client cli(this->interfaceConfig_.httpIp.toStdString(), this->interfaceConfig_.httpPort);
|
2024-04-03 17:51:29 +00:00
|
|
|
|
|
|
|
|
|
|
cli.set_connection_timeout(3, 0);
|
|
|
|
|
|
cli.set_read_timeout(0, 700 * 1000);
|
2024-03-27 12:09:46 +00:00
|
|
|
|
httplib::Headers header;
|
|
|
|
|
|
httplib::Params params;
|
|
|
|
|
|
header.emplace("blade-auth", this->webToken);
|
|
|
|
|
|
//header.emplace("Content-Type", "application/json");
|
|
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
auto res = cli.Post(this->interfaceConfig_.upResultPath.toStdString(), header, str, "application/json");
|
2024-04-03 17:51:29 +00:00
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (res->status == 200)
|
|
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logInfo("第" + QString::fromStdString(trainInfo.strOrder) + "节,web返回: " + QString::fromStdString(res->body));
|
2024-02-29 06:20:06 +00:00
|
|
|
|
Json::CharReaderBuilder readerBuilder;
|
|
|
|
|
|
std::istringstream iss(res->body);
|
|
|
|
|
|
Json::Value root;
|
|
|
|
|
|
std::string errs;
|
|
|
|
|
|
bool parsingSuccessful = Json::parseFromStream(readerBuilder, iss, &root, &errs);
|
|
|
|
|
|
if (parsingSuccessful)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (root["success"].asBool())
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (root["msg"].asString() == "请求未授权") {
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logWarn("第" + QString::fromStdString(trainInfo.strOrder) + "节,因请求未授权,而上传识别结果失败!重新请求token。");
|
2024-02-29 11:35:22 +00:00
|
|
|
|
if (!this->getToken()) return false;
|
2024-04-03 17:51:29 +00:00
|
|
|
|
return this->upWeb(trainInfo);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::fromStdString(root["msg"].asString()));
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,返回数据解析异常,返回数据非json:" + QString::fromStdString(res->body));
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::number(res->status) + " - " + QString::fromStdString(res->body));
|
2024-02-29 06:20:06 +00:00
|
|
|
|
if (res->status == 401) {
|
|
|
|
|
|
this->logWarn("因请求未授权,而上传识别结果失败!重新请求token。");
|
|
|
|
|
|
this->getToken();
|
2024-04-03 17:51:29 +00:00
|
|
|
|
return this->upWeb(trainInfo);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传数据失败,请检查网络,或者上传地址!");
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传识别结果失败,原因:");
|
2024-02-29 06:20:06 +00:00
|
|
|
|
this->logError(e.what());
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief:Http获取授权
|
|
|
|
|
|
* @param:
|
|
|
|
|
|
* @return:
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool MainWindow::getToken()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
httplib::Client cli(this->interfaceConfig_.httpIp.toStdString(), this->interfaceConfig_.httpPort);
|
2024-03-17 10:30:35 +00:00
|
|
|
|
cli.set_connection_timeout(0, 300 * 1000);
|
2024-03-27 12:09:46 +00:00
|
|
|
|
cli.set_read_timeout(0,300*1000);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
httplib::Headers header;
|
|
|
|
|
|
httplib::Params params;
|
|
|
|
|
|
|
|
|
|
|
|
header.emplace("Authorization", "Basic Y2xpZW50X2VudGVycHJpc2U6Y2xpZW50X2VudGVycHJpc2Vfc2VjcmV0");
|
|
|
|
|
|
|
|
|
|
|
|
params.emplace("username", this->interfaceConfig_.username.toStdString());
|
|
|
|
|
|
params.emplace("password", this->interfaceConfig_.password.toStdString());
|
|
|
|
|
|
params.emplace("tenantId", "000000");
|
|
|
|
|
|
params.emplace("grant_type", "password");
|
|
|
|
|
|
auto res = cli.Post("/api/blade-auth/oauth/token", header, params);
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (res->status == 200)
|
|
|
|
|
|
{
|
|
|
|
|
|
Json::CharReaderBuilder readerBuilder;
|
|
|
|
|
|
std::istringstream iss(res->body);
|
|
|
|
|
|
Json::Value root;
|
|
|
|
|
|
std::string errs;
|
|
|
|
|
|
bool parsingSuccessful = Json::parseFromStream(readerBuilder, iss, &root, &errs);
|
|
|
|
|
|
|
|
|
|
|
|
if (parsingSuccessful)
|
|
|
|
|
|
{
|
2024-02-29 11:35:22 +00:00
|
|
|
|
if (!root.get("token_type", "").asString().empty())
|
2024-02-29 06:20:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
this->webToken = root["token_type"].asString();
|
|
|
|
|
|
this->webToken.append(" ");
|
|
|
|
|
|
this->webToken.append(root["access_token"].asString());
|
|
|
|
|
|
this->logInfo("已获取到web token");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-03-27 12:09:46 +00:00
|
|
|
|
this->logError("获取web token失败,原因:" + QString::fromStdString(res->body));
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError("获取web token返回数据解析异常,返回数据非json。详细:" + QString::fromStdString(res->body));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
auto err = res.error();
|
|
|
|
|
|
// if (err == httplib::Error::Connection) {
|
|
|
|
|
|
// std::cout << " (连接出错)" << std::endl;
|
|
|
|
|
|
// }
|
|
|
|
|
|
this->logError("获取web token失败!请检查网络或请求地址。详细:" + QString::fromStdString(to_string(err)));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError("获取授权失败,原因:");
|
|
|
|
|
|
this->logError(e.what());
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************最小化相关****************************************/
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief:接收最小化信号
|
|
|
|
|
|
* @param:
|
|
|
|
|
|
* @return:空
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::changeEvent(QEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((event->type()==QEvent::WindowStateChange)&&isMinimized())
|
|
|
|
|
|
{
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->hide();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
m_pSystemTray->setIcon(QIcon("./logo.ico")); // 托盘时显示的图片
|
|
|
|
|
|
m_pSystemTray->setToolTip("Rfid车号识别-股道号:" + QString::number(this->baseConfig_.trackName)); // 鼠标在托盘图片时的提示
|
|
|
|
|
|
m_pSystemTray->showMessage("Rfid车号识别","已隐藏至托盘",QSystemTrayIcon::Information,10000);
|
|
|
|
|
|
event->ignore();
|
|
|
|
|
|
//建立托盘操作的菜单
|
|
|
|
|
|
creat_action();
|
|
|
|
|
|
creat_menu();
|
|
|
|
|
|
m_pSystemTray->show(); // 显示图片图标
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 弹出对话框要求用户输入账号和密码
|
|
|
|
|
|
QString password = QInputDialog::getText(this, "密码验证", "请输入密码:", QLineEdit::Password);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证账号和密码是否正确
|
|
|
|
|
|
if (password == "matrix") {
|
2024-02-29 11:35:22 +00:00
|
|
|
|
this->initParam();
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->tcp_->close();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
event->accept(); // 关闭窗口
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
QMessageBox::warning(this, "验证失败", "密码不正确!");
|
|
|
|
|
|
event->ignore(); // 阻止关闭窗口
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::creat_action()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pActionShow = new QAction("主界面", this);
|
|
|
|
|
|
connect(m_pActionShow, &QAction::triggered, this,&MainWindow::on_ShowMainAction);
|
2024-03-17 10:30:35 +00:00
|
|
|
|
// m_pActionQuit = new QAction("退出", this);
|
|
|
|
|
|
// connect(m_pActionQuit, &QAction::triggered, this, &MainWindow::on_ExitAppAction);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::creat_menu()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTrayMennu = new QMenu(this);
|
|
|
|
|
|
//新增菜单项---显示主界面
|
|
|
|
|
|
m_pTrayMennu->addAction(m_pActionShow);
|
|
|
|
|
|
//增加分隔符
|
2024-03-17 10:30:35 +00:00
|
|
|
|
// m_pTrayMennu->addSeparator();
|
|
|
|
|
|
// //新增菜单项---退出程序
|
|
|
|
|
|
// m_pTrayMennu->addAction(m_pActionQuit);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
//把QMenu赋给QSystemTrayIcon对象
|
|
|
|
|
|
m_pSystemTray->setContextMenu(m_pTrayMennu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief:显示
|
|
|
|
|
|
* @param:
|
|
|
|
|
|
* @return:空
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::on_ShowMainAction()
|
|
|
|
|
|
{
|
|
|
|
|
|
this->show();
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->showNormal();
|
|
|
|
|
|
this->activateWindow();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief:最小化
|
|
|
|
|
|
* @param:
|
|
|
|
|
|
* @return:空
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::on_ExitAppAction()
|
|
|
|
|
|
{
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 弹出对话框要求用户输入密码
|
2024-03-14 13:14:36 +00:00
|
|
|
|
QString password = QInputDialog::getText(this, "密码验证", "请输入密码:", QLineEdit::Password);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
// 验证账号和密码是否正确
|
2024-03-14 13:14:36 +00:00
|
|
|
|
if (password == "matrix") {
|
|
|
|
|
|
this->initParam();
|
|
|
|
|
|
this->tcp_->close();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
exit(0);
|
|
|
|
|
|
} else {
|
2024-03-14 13:14:36 +00:00
|
|
|
|
QMessageBox::warning(this, "验证失败", "密码不正确!");
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(reason){
|
|
|
|
|
|
case QSystemTrayIcon::Trigger:
|
|
|
|
|
|
//单击托盘图标
|
|
|
|
|
|
this->showNormal();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case QSystemTrayIcon::DoubleClick:
|
|
|
|
|
|
//双击托盘图标
|
|
|
|
|
|
//双击后显示主程序窗口
|
|
|
|
|
|
this->showNormal();
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->activateWindow();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************串口操作*************************************/
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 打开串口
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::openComClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ui->openComButton->text() == "打开串口")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->serial_ = this->comDetect_.openCom(ui->comBox->currentText(), ui->BTBox->currentIndex());
|
|
|
|
|
|
if (this->serial_ != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString logs;
|
|
|
|
|
|
logs.append("串口打开成功\n");
|
|
|
|
|
|
logs.append("串口号:" + ui->comBox->currentText() + "\n");
|
2024-03-21 03:24:36 +00:00
|
|
|
|
logs.append("波特率:" + ui->BTBox->currentText() + "\n");
|
2024-04-03 17:51:29 +00:00
|
|
|
|
if (this->baseConfig_.havaMagnetSteel)
|
|
|
|
|
|
logs.append("磁钢顺序:" + this->baseConfig_.magnetSteelOrder);
|
2024-02-29 06:20:06 +00:00
|
|
|
|
this->isOpenCom = true;
|
|
|
|
|
|
this->logInfo(logs);
|
|
|
|
|
|
this->ui->openComButton->setText("关闭串口");
|
|
|
|
|
|
this->ui->LEDlabel->setStyleSheet("border-radius: 16px;\ "
|
|
|
|
|
|
"background-color: rgba(74, 221, 108, 225);\ "
|
|
|
|
|
|
"border:1px solid rgba(168, 168, 168, 105);");
|
2024-04-03 17:51:29 +00:00
|
|
|
|
connect(this->serial_,&QSerialPort::readyRead,this,&MainWindow::readCom); //
|
2024-03-27 12:09:46 +00:00
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
connect(this->serial_, &QSerialPort::errorOccurred, this, &MainWindow::serialPort_error);
|
2024-03-14 13:14:36 +00:00
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this->isOpenCom = false;
|
|
|
|
|
|
this->logInfo("串口打开失败!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 弹出对话框要求用户输入密码
|
|
|
|
|
|
QString password = QInputDialog::getText(this, "密码验证", "请输入密码:", QLineEdit::Password);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证账号和密码是否正确
|
|
|
|
|
|
if (password == "matrix") {
|
|
|
|
|
|
if (this->comDetect_.closeCom())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this->needIdentify == true) this->needIdentify = false;
|
|
|
|
|
|
this->isOpenCom = false;
|
|
|
|
|
|
this->logInfo("串口已关闭!");
|
|
|
|
|
|
this->initParam();
|
|
|
|
|
|
this->ui->openComButton->setText("打开串口");
|
|
|
|
|
|
this->ui->LEDlabel->setStyleSheet("border-radius: 16px;\ "
|
|
|
|
|
|
"background-color: red;\ "
|
|
|
|
|
|
"border:1px solid rgba(168, 168, 168, 105);");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
QMessageBox::warning(this, "验证失败", "密码不正确!");
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 串口异常退出的槽函数
|
|
|
|
|
|
* @param error
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::serialPort_error(QSerialPort::SerialPortError error)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (error != QSerialPort::NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
//关闭串口
|
|
|
|
|
|
this->serial_->close();
|
|
|
|
|
|
this->ui->openComButton->setText("打开串口");
|
|
|
|
|
|
this->logError("串口异常退出,疑似接口松动");
|
|
|
|
|
|
this->ui->LEDlabel->setStyleSheet("border-radius: 16px; \ "
|
|
|
|
|
|
"background-color: red;\ "
|
|
|
|
|
|
"border:1px solid rgba(168, 168, 168, 105);");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::readCom()
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
2024-03-27 12:09:46 +00:00
|
|
|
|
if (this->serial_->waitForReadyRead(10)) {
|
2024-03-20 05:50:02 +00:00
|
|
|
|
QByteArray data = this->serial_->readAll(); // 读取数据
|
|
|
|
|
|
if(!data.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
this->queue_.push(QString(data));
|
|
|
|
|
|
emit getRfid_signals();
|
|
|
|
|
|
}
|
2024-04-03 17:51:29 +00:00
|
|
|
|
// this->serial_->clear();
|
2024-03-20 05:50:02 +00:00
|
|
|
|
data.clear();
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
2024-04-03 17:51:29 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logError("等待读取超时");
|
|
|
|
|
|
}
|
2024-02-29 06:20:06 +00:00
|
|
|
|
} catch(...) {
|
|
|
|
|
|
this->logError("读取串口数据异常!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief:从queue中获取数据
|
|
|
|
|
|
* @param:空
|
|
|
|
|
|
* @return:空
|
|
|
|
|
|
*/
|
|
|
|
|
|
void MainWindow::getQueueDataThread()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this->queue_.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
|
|
QString strRfidInfo = this->queue_.getTop();
|
|
|
|
|
|
this->queue_.pop();
|
|
|
|
|
|
this->saveRfidLog(strRfidInfo);
|
|
|
|
|
|
this->tmpRfid.append(strRfidInfo);
|
|
|
|
|
|
if (this->tmpRfid.right(1) != "&")
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-27 12:09:46 +00:00
|
|
|
|
|
2024-03-17 10:30:35 +00:00
|
|
|
|
this->tmpRfid = this->tmpRfid.replace("&", "");
|
|
|
|
|
|
QStringList rfidSubList = this->tmpRfid.split("@");
|
2024-02-29 06:20:06 +00:00
|
|
|
|
this->tmpRfid = "";
|
|
|
|
|
|
|
2024-03-14 13:14:36 +00:00
|
|
|
|
auto split_lambda = [=](QString strFirst, QString strOther){
|
|
|
|
|
|
if (strFirst == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->rfidHasTrain = false;
|
|
|
|
|
|
this->logInfo("RFID-火车离开了");
|
|
|
|
|
|
// 关功放信号
|
|
|
|
|
|
// 需要结合 “来车状态”广播消息,确认是否真的车离开了; TODO:没有真离开,则向串口发送 @on& 避免关功放
|
|
|
|
|
|
emit IdentifyType();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: 此处按照4个磁钢来配置,可能存在一定限制; 另外逻辑需要优化
|
|
|
|
|
|
if (strOther == "000000" // 第一次检测来车时(前提是上一次功放已关闭)
|
|
|
|
|
|
&& (strFirst == this->baseConfig_.magnetSteelOrder.left(1)
|
|
|
|
|
|
|| strFirst == this->baseConfig_.magnetSteelOrder.mid(1, 1)))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->rfidHasTrain = true;
|
|
|
|
|
|
this->logInfo("RFID-来车了");
|
|
|
|
|
|
emit IdentifyType();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
for (const auto & i : rfidSubList)
|
|
|
|
|
|
{
|
2024-03-17 10:30:35 +00:00
|
|
|
|
if (i.size() == 26 || i.size() == 24)
|
2024-02-29 06:20:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
// 车厢信息
|
|
|
|
|
|
QString strTrainInfo = i.left(14);
|
2024-03-14 13:14:36 +00:00
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
if (vecTrain.empty() || !vecTrain.contains(strTrainInfo))
|
|
|
|
|
|
{
|
2024-03-14 13:14:36 +00:00
|
|
|
|
bool isNoCarriage = false;
|
|
|
|
|
|
int carT = strTrainInfo.mid(3, 2).simplified().toInt(&isNoCarriage);
|
2024-03-20 05:50:02 +00:00
|
|
|
|
if (isNoCarriage && carT >= 10) continue;
|
2024-03-21 06:10:39 +00:00
|
|
|
|
// 因信号不稳定 增加一行过滤 出现文字中带有字母及数字以外的字符时,过滤
|
|
|
|
|
|
if (!strTrainInfo.contains(QRegExp("^[A-Z0-9\\s]+$"))) continue;
|
2024-03-21 02:52:12 +00:00
|
|
|
|
// 因信号不稳定 增加一行过滤 出现读到的数据里 空格替代了实际字符的情况
|
|
|
|
|
|
if (strTrainInfo.mid(7, 7).simplified().size() < 7) continue;
|
2024-02-29 06:20:06 +00:00
|
|
|
|
vecTrain.append(strTrainInfo);
|
2024-03-14 13:14:36 +00:00
|
|
|
|
int train_order = vecTrain.size();
|
|
|
|
|
|
this->resultTableModel_->setItem(train_order - 1, 0, new QStandardItem(strTrainInfo));
|
|
|
|
|
|
this->logInfo(QString("第%1节 %2").arg(train_order).arg(strTrainInfo));
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
|
|
|
|
|
this->rfidSourceInfo.append("@" + i);
|
|
|
|
|
|
QString rfidinfo = this->rfidSourceInfo;
|
|
|
|
|
|
this->rfidSourceInfo = "";
|
|
|
|
|
|
emit upRfid_signals(rfidinfo);
|
|
|
|
|
|
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (i.size() == 7)
|
|
|
|
|
|
{
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 不使用磁钢的情况下 过滤掉磁钢信号
|
|
|
|
|
|
if (!this->baseConfig_.havaMagnetSteel) continue;
|
2024-02-29 06:20:06 +00:00
|
|
|
|
// 磁钢信号
|
|
|
|
|
|
QString strFirst = i.left(1);
|
|
|
|
|
|
QString strOther = i.mid(1, i.size() - 1);
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
|
|
|
|
|
this->rfidSourceInfo.append("@" + i);
|
2024-03-14 13:14:36 +00:00
|
|
|
|
split_lambda(strFirst, strOther);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (i.size() == 14) // 特殊情况,来车信号少了&符
|
|
|
|
|
|
{
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 不使用磁钢的情况下 过滤掉磁钢信号
|
|
|
|
|
|
if (!this->baseConfig_.havaMagnetSteel) continue;
|
2024-03-17 10:30:35 +00:00
|
|
|
|
for (int j = 0; j < i.size(); j+=7) {
|
|
|
|
|
|
QString rfid_cg = i.mid(j, 7);
|
|
|
|
|
|
QString strFirst = rfid_cg.left(1);
|
|
|
|
|
|
QString strOther = rfid_cg.mid(1, 6);
|
2024-03-27 12:09:46 +00:00
|
|
|
|
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
|
|
|
|
|
this->rfidSourceInfo.append("@" + rfid_cg);
|
2024-03-17 10:30:35 +00:00
|
|
|
|
split_lambda(strFirst, strOther);
|
|
|
|
|
|
}
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-27 12:09:46 +00:00
|
|
|
|
void MainWindow::upRfid(QString rfidInfo)
|
2024-02-29 06:20:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (!this->baseConfig_.upResult) return;
|
2024-03-06 06:13:50 +00:00
|
|
|
|
if (!this->needIdentify && this->baseConfig_.havaMagnetSteel)
|
2024-02-29 06:20:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon("./Fail.ico");
|
|
|
|
|
|
QPixmap m_pic = icon.pixmap(icon.actualSize(QSize(32, 32)));//size自行调整
|
|
|
|
|
|
this->ui->upflagLabel->setPixmap(m_pic);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
QIcon icon("./Succ.ico");
|
|
|
|
|
|
QPixmap m_pic = icon.pixmap(icon.actualSize(QSize(32, 32)));//size自行调整
|
|
|
|
|
|
this->ui->upflagLabel->setPixmap(m_pic);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString info = this->vecTrain.back();
|
|
|
|
|
|
int order = this->vecTrain.size();
|
|
|
|
|
|
|
|
|
|
|
|
info = info.mid(1,info.size() - 1);
|
2024-02-29 11:35:22 +00:00
|
|
|
|
|
2024-03-27 12:09:46 +00:00
|
|
|
|
TrainInfo trainInfo;
|
|
|
|
|
|
trainInfo.carriageType = info.left(6).simplified().toStdString();
|
|
|
|
|
|
trainInfo.carriageNum = info.mid(6, info.size() - 6).simplified().toStdString();
|
|
|
|
|
|
trainInfo.strOrder = QString::number(order).toStdString();
|
2024-04-03 17:51:29 +00:00
|
|
|
|
trainInfo.trainTime = this->trainTime.toStdString();
|
|
|
|
|
|
trainInfo.collectTime = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString();
|
2024-03-27 12:09:46 +00:00
|
|
|
|
trainInfo.strRfidInfo = rfidInfo.toStdString();
|
|
|
|
|
|
|
|
|
|
|
|
this->queueTrainInfo_.push(trainInfo);
|
2024-04-03 17:51:29 +00:00
|
|
|
|
// QtConcurrent::run([=](){
|
|
|
|
|
|
if ((this->iDirection == 0 && this->queueTrainInfo_.size() <= 4) || this->iDirection < 0) return;
|
2024-03-27 12:09:46 +00:00
|
|
|
|
while (!this->queueTrainInfo_.isEmpty())
|
|
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
TrainInfo trainInfo_ = this->queueTrainInfo_.pop();
|
|
|
|
|
|
if (!this->upWeb(trainInfo_))
|
2024-03-27 12:09:46 +00:00
|
|
|
|
{
|
2024-04-03 17:51:29 +00:00
|
|
|
|
//this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败!");
|
2024-03-27 12:09:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-03 17:51:29 +00:00
|
|
|
|
// });
|
2024-02-29 06:20:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-14 13:14:36 +00:00
|
|
|
|
void MainWindow::IdentifyTypeUpdate() {
|
|
|
|
|
|
if (this->rfidHasTrain || this->videoHasTrain)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!this->needIdentify)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->logInfo("来车了");
|
|
|
|
|
|
this->mkRfidLog();
|
2024-03-27 12:09:46 +00:00
|
|
|
|
this->vecTrain.clear();
|
2024-03-14 13:14:36 +00:00
|
|
|
|
this->needIdentify = true;
|
|
|
|
|
|
this->trainTime = this->getSystemTime();
|
|
|
|
|
|
this->resultTableModel_->clear();
|
|
|
|
|
|
this->resultTableModel_ = this->getStandardItemModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!this->rfidHasTrain && !this->videoHasTrain)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->initParam();
|
|
|
|
|
|
this->logInfo("火车离开了");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================= 测试 ====================================
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::readTestInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (this->isOpenCom)
|
|
|
|
|
|
{
|
|
|
|
|
|
logWarn("请先关闭串口后进行测试操作!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QString filePath = QFileDialog::getOpenFileName(this, "选择一个文件", QDir::currentPath(), "(*.*)");
|
|
|
|
|
|
if(filePath.isEmpty()){
|
|
|
|
|
|
QMessageBox::warning(this, "打开文件", "选择文件不能为空");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 创建一个QFile对象并打开要读取的文本文件
|
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
|
logError("无法打开测试文件:" + filePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
logInfo("开始读取测试数据...");
|
|
|
|
|
|
// 将文件内容读入到QStringList中
|
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
|
|
while(!in.atEnd()) {
|
|
|
|
|
|
QString line = in.readLine();
|
|
|
|
|
|
this->queue_.push(line);
|
|
|
|
|
|
emit getRfid_signals();
|
|
|
|
|
|
}
|
|
|
|
|
|
// 关闭文件
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
logInfo("---读取测试数据完毕---");
|
|
|
|
|
|
}
|