diff --git a/src/interface/TcpClient.cpp b/src/interface/TcpClient.cpp index c66cb70..a9ddca4 100644 --- a/src/interface/TcpClient.cpp +++ b/src/interface/TcpClient.cpp @@ -91,7 +91,7 @@ void TcpClient::connectToServer(QString ip, int port) { come_time = jsonObject["cometime"].toString(); carType = jsonObject["type"].toString(); } - else if (jsonObject["type"].toString() != carType && carType == "1") + else if (jsonObject["type"].toString() != carType) { // 火车无 emit this->comeTrainSignals(false); diff --git a/src/main.cpp b/src/main.cpp index aad26e9..5549d35 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) { QString const key=line; QSharedMemory shared_memory; shared_memory.setKey(key);//设置固定共享内存段的key值 - if(shared_memory.attach()) //尝试将进程附加到该共享内存段 + if (shared_memory.attach()) //尝试将进程附加到该共享内存段 { QMessageBox messageBox(QMessageBox::Warning,QString::fromUtf8("提示"),QString::QString::fromUtf8("当前程序正在运行中...")); messageBox.setButtonText(QMessageBox::Ok,QString::QString::fromUtf8("确认!")); @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) { QApplication::setWindowIcon(QIcon("./logo.ico")); MainWindow w; w.show(); - qInfo() << "111"; + return QApplication::exec(); } return QApplication::exec(); diff --git a/src/qt_source/DeleteOldLog.cpp b/src/qt_source/DeleteOldLog.cpp new file mode 100644 index 0000000..c10f75e --- /dev/null +++ b/src/qt_source/DeleteOldLog.cpp @@ -0,0 +1,19 @@ +// +// Created by Mr.V on 2024/3/16. +// + +#include "DeleteOldLog.h" + +void DeleteOldLog::deleteFile() { + QDir dir("./Logs"); + QStringList fileList; + QFileInfoList fileInfoList = dir.entryInfoList(fileList, QDir::Files); + + for (int i = 0; i < fileInfoList.size(); i++) { + QFileInfo info = fileInfoList.at(i); + if (info.birthTime() < QDateTime::currentDateTime().addDays(-10)) + { + QFile::remove(info.absoluteFilePath()); + } + } +} \ No newline at end of file diff --git a/src/qt_source/DeleteOldLog.h b/src/qt_source/DeleteOldLog.h new file mode 100644 index 0000000..e2f3c25 --- /dev/null +++ b/src/qt_source/DeleteOldLog.h @@ -0,0 +1,20 @@ +// +// Created by Mr.V on 2024/3/16. +// + +#ifndef TRAIN_RFID_DELETEOLDLOG_H +#define TRAIN_RFID_DELETEOLDLOG_H +#include +#include +#include + +class DeleteOldLog { + Q_OBJECT +public: + bool readDeleteConfig(); +public slots: + void deleteFile(); +}; + + +#endif //TRAIN_RFID_DELETEOLDLOG_H diff --git a/src/qt_source/mainwindow.cpp b/src/qt_source/mainwindow.cpp index c07f3cb..473e0ee 100644 --- a/src/qt_source/mainwindow.cpp +++ b/src/qt_source/mainwindow.cpp @@ -15,12 +15,12 @@ MainWindow::MainWindow(QWidget *parent) this->statusBar = new QStatusBar(); this->statusInfo = new QLabel("初始化完成",this); this->statusBar->addPermanentWidget(this->statusInfo);//显示正常信息 - QLabel* statusVersion = new QLabel("编译版本:" + QDateTime::currentDateTime().toString("yy.MM.dd.hh.mm"),this); + QLabel* statusVersion = new QLabel("开启时间:" + QDateTime::currentDateTime().toString("yy.MM.dd.hh.mm"),this); this->statusBar->addWidget(statusVersion); layout()->addWidget(this->statusBar); - this->setWindowTitle("Matrix_RFID"); + this->setWindowTitle("Matrix_RFID 车号识别程序(勿关!!)"); this->configPath_ = "./config/config.ini"; if (!this->mkLogDir()) @@ -137,7 +137,8 @@ MainWindow::MainWindow(QWidget *parent) { this->logInfo("视频车号识别-火车离开了"); this->videoHasTrain = false; - emit IdentifyType(); + if (this->needIdentify) + emit IdentifyType(); } }); } @@ -342,6 +343,7 @@ bool MainWindow::upWeb(std::string &carriageType, std::string &carriageNumber, s try { httplib::Client cli(this->interfaceConfig_.httpIp.toStdString(), this->interfaceConfig_.httpPort); cli.set_connection_timeout(0, 300 * 1000); + cli.set_read_timeout(1,0); httplib::Headers header; httplib::Params params; Json::Value arrayObj; //构建对象 @@ -350,6 +352,7 @@ bool MainWindow::upWeb(std::string &carriageType, std::string &carriageNumber, s //header.emplace("Content-Type", "application/json"); arrayObj["comeTime"] = time; + arrayObj["collectTime"] = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString(); arrayObj["carriageNumber"] = carriageNumber; arrayObj["carriageType"] = carriageType; arrayObj["carriageOrder"] = carriageOrder; @@ -428,6 +431,8 @@ bool MainWindow::getToken() try { httplib::Client cli(this->interfaceConfig_.httpIp.toStdString(), this->interfaceConfig_.httpPort); + cli.set_connection_timeout(0, 300 * 1000); + cli.set_read_timeout(1,0); httplib::Headers header; httplib::Params params; @@ -530,8 +535,8 @@ void MainWindow::creat_action() { m_pActionShow = new QAction("主界面", this); connect(m_pActionShow, &QAction::triggered, this,&MainWindow::on_ShowMainAction); - m_pActionQuit = new QAction("退出", this); - connect(m_pActionQuit, &QAction::triggered, this, &MainWindow::on_ExitAppAction); +// m_pActionQuit = new QAction("退出", this); +// connect(m_pActionQuit, &QAction::triggered, this, &MainWindow::on_ExitAppAction); } void MainWindow::creat_menu() @@ -540,9 +545,9 @@ void MainWindow::creat_menu() //新增菜单项---显示主界面 m_pTrayMennu->addAction(m_pActionShow); //增加分隔符 - m_pTrayMennu->addSeparator(); - //新增菜单项---退出程序 - m_pTrayMennu->addAction(m_pActionQuit); +// m_pTrayMennu->addSeparator(); +// //新增菜单项---退出程序 +// m_pTrayMennu->addAction(m_pActionQuit); //把QMenu赋给QSystemTrayIcon对象 m_pSystemTray->setContextMenu(m_pTrayMennu); } @@ -576,6 +581,7 @@ void MainWindow::on_ExitAppAction() exit(0); } else { QMessageBox::warning(this, "验证失败", "密码不正确!"); + //event->ignore(); // 阻止关闭窗口 } } @@ -701,8 +707,8 @@ void MainWindow::getQueueDataThread() return; } // this->logDebug("--" + this->tmpRfid); - this->tmpRfid = this->tmpRfid.replace("@", ""); - QStringList rfidSubList = this->tmpRfid.split("&"); + this->tmpRfid = this->tmpRfid.replace("&", ""); + QStringList rfidSubList = this->tmpRfid.split("@"); this->tmpRfid = ""; auto split_lambda = [=](QString strFirst, QString strOther){ @@ -730,7 +736,7 @@ void MainWindow::getQueueDataThread() for (const auto & i : rfidSubList) { - if (i.size() == 26) + if (i.size() == 26 || i.size() == 24) { // 车厢信息 QString strTrainInfo = i.left(14); @@ -757,9 +763,13 @@ void MainWindow::getQueueDataThread() } else if (i.size() == 14) // 特殊情况,来车信号少了&符 { - QString strFirst = i.left(1); - QString strOther = i.mid(1, 6); - split_lambda(strFirst, strOther); + 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); + split_lambda(strFirst, strOther); + } + } } }