parent
c3cd21f50a
commit
7080483fb8
|
|
@ -1,12 +1,14 @@
|
|||
[base]
|
||||
track_name=2
|
||||
up_result=true
|
||||
use_socket_server=false
|
||||
run_model=0
|
||||
|
||||
[serial]
|
||||
com_name=COM2
|
||||
baud=19200
|
||||
track_name=2
|
||||
have_magnet_steel=true
|
||||
magnet_steel_order=8421
|
||||
up_result=true
|
||||
use_socket_server=true
|
||||
use_device_warn=true
|
||||
|
||||
[interface]
|
||||
http_ip=192.168.2.212
|
||||
|
|
@ -24,3 +26,6 @@ delayed_upload=4
|
|||
|
||||
[device_warn]
|
||||
min_train_size=10
|
||||
|
||||
[relay]
|
||||
listener_port=7070
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
set(PROJECT_NAME Train_RFID)
|
||||
project(${PROJECT_NAME} VERSION 1.0 DESCRIPTION "火车车号识别 RFID版")
|
||||
project(${PROJECT_NAME} VERSION 1.0 DESCRIPTION "RFID火车车号识别 Win版")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
|
@ -18,7 +18,6 @@ link_directories(../lib)
|
|||
|
||||
link_libraries(ws2_32 wsock32)
|
||||
|
||||
|
||||
find_package(Qt5 COMPONENTS
|
||||
Core
|
||||
Gui
|
||||
|
|
@ -28,19 +27,15 @@ find_package(Qt5 COMPONENTS
|
|||
Concurrent
|
||||
REQUIRED)
|
||||
|
||||
#导入Qt的Network配置和在pro文件里面添加QT+=network是一样的
|
||||
#find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Network SerialPort )
|
||||
#find_package(Qt${QT_VERSION_MAJOR} REQUIRED Network COMPONENTS Core)
|
||||
#find_package(Qt5Core COMPONENTS Qt5SerialPort REQUIRED)
|
||||
|
||||
#moc编译在这里进行,请把含有Q_OBJECT宏定义的头文件放到这里来
|
||||
QT5_WRAP_CPP(MOC_Files
|
||||
qt_source/mainwindow.h
|
||||
qt_source/MainWindow.h
|
||||
interface/TcpClient.h
|
||||
threads/UpResultThread.h
|
||||
threads/UpWarnThread.h
|
||||
threads/ReadComThread.h
|
||||
)
|
||||
threads/RelayRfidThread.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
common
|
||||
|
|
@ -74,17 +69,15 @@ include_directories(
|
|||
serial
|
||||
# 线程逻辑
|
||||
threads
|
||||
|
||||
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE COMMON_SRCS_LISTS
|
||||
# UI
|
||||
qt_source/mainwindow.ui
|
||||
qt_source/MainWindow.ui
|
||||
# qt_source qt_source
|
||||
qt_source/MainWindow.cpp
|
||||
# 公共数据
|
||||
common/common.cpp
|
||||
# qt_source qt_source
|
||||
qt_source/mainwindow.cpp
|
||||
# JSON库
|
||||
util/json/jsoncpp.cpp
|
||||
# http库
|
||||
|
|
@ -120,10 +113,8 @@ add_executable(Train_RFID
|
|||
${MOC_Files}
|
||||
ico.rc
|
||||
)
|
||||
|
||||
target_link_libraries(Train_RFID
|
||||
-pthread
|
||||
|
||||
-lyaml-cpp
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
|
|
@ -131,7 +122,7 @@ target_link_libraries(Train_RFID
|
|||
Qt5::Network
|
||||
Qt5::SerialPort
|
||||
Qt5::Concurrent
|
||||
)
|
||||
)
|
||||
|
||||
if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
set(DEBUG_SUFFIX)
|
||||
|
|
@ -154,7 +145,7 @@ if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
|||
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
|
||||
endif ()
|
||||
foreach (QT_LIB Core Gui Widgets Network SerialPort)
|
||||
foreach (QT_LIB Core Gui Widgets)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,34 @@ ConfigUtil::ConfigUtil() = default;
|
|||
ConfigUtil::~ConfigUtil() = default;
|
||||
|
||||
bool ConfigUtil::readBaseConfig(const QString &configFile, QString &errorMessage, ai_matrix::BaseConfig &config) {
|
||||
try {
|
||||
if (configFile.isEmpty() || configFile.isNull())
|
||||
{
|
||||
errorMessage = "配置文件地址为空,读取配置文件失败!";
|
||||
return false;
|
||||
}
|
||||
QSettings* mset = new QSettings(configFile, QSettings::IniFormat);
|
||||
mset->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||
mset->beginGroup("base");
|
||||
config.trackName = mset->value("track_name", 1).toInt();
|
||||
config.upResult = mset->value("up_result", false).toBool();
|
||||
config.useSocketServer = mset->value("use_socket_server", false).toBool();
|
||||
config.runModel = mset->value("run_model", 1).toInt();
|
||||
// TODO: 此节点下的参数内容弃用,转移到[serial]下
|
||||
// config.comName = mset->value("com_name", "").toString();
|
||||
// config.baud = mset->value("baud", 19200).toInt();
|
||||
// config.havaMagnetSteel = mset->value("have_magnet_steel", false).toBool();
|
||||
// config.magnetSteelOrder = mset->value("magnet_steel_order", "").toString();
|
||||
|
||||
mset->endGroup();
|
||||
} catch (const std::exception &e) {
|
||||
errorMessage = e.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigUtil::writeBaseConfig(const QString &configFile, QString &errorMessage, ai_matrix::BaseConfig &config) {
|
||||
try {
|
||||
if (configFile.isEmpty() || configFile.isNull()) {
|
||||
errorMessage = "配置文件地址为空,读取配置文件失败!";
|
||||
|
|
@ -18,16 +46,34 @@ bool ConfigUtil::readBaseConfig(const QString &configFile, QString &errorMessage
|
|||
}
|
||||
QSettings* mset = new QSettings(configFile, QSettings::IniFormat);
|
||||
mset->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||
QString mdir = "";
|
||||
mset->beginGroup("base");
|
||||
|
||||
mset->setValue("track_name", config.trackName);
|
||||
mset->setValue("up_result", config.upResult);
|
||||
mset->setValue("use_socket_server", config.useSocketServer);
|
||||
mset->setValue("run_model", config.runModel);
|
||||
|
||||
mset->endGroup();
|
||||
} catch (const std::exception &e) {
|
||||
errorMessage = e.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigUtil::readSerialConfig(const QString &configFile, QString &errorMessage, ai_matrix::SerialConfig &config) {
|
||||
try {
|
||||
if (configFile.isEmpty() || configFile.isNull()) {
|
||||
errorMessage = "配置文件地址为空,读取配置文件失败!";
|
||||
return false;
|
||||
}
|
||||
QSettings* mset = new QSettings(configFile, QSettings::IniFormat);
|
||||
mset->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||
mset->beginGroup("serial");
|
||||
config.comName = mset->value("com_name", "").toString();
|
||||
config.baud = mset->value("baud", 19200).toInt();
|
||||
config.trackName = mset->value("track_name", 1).toInt();
|
||||
config.havaMagnetSteel = mset->value("have_magnet_steel", false).toBool();
|
||||
config.magnetSteelOrder = mset->value("magnet_steel_order", "").toString();
|
||||
config.upResult = mset->value("up_result", false).toBool();
|
||||
config.useSocketServer = mset->value("use_socket_server", false).toBool();
|
||||
config.useDeviceWarn = mset->value("use_device_warn", false).toBool();
|
||||
|
||||
mset->endGroup();
|
||||
} catch (const std::exception &e) {
|
||||
|
|
@ -50,8 +96,7 @@ bool ConfigUtil::readInterfaceConfig(const QString &configFile, QString &errorMe
|
|||
config.httpIp = mset->value("http_ip", "").toString();
|
||||
config.httpPort = mset->value("http_port", "").toInt();
|
||||
config.tokenPath = mset->value("token_path", 19200).toString();
|
||||
config.upResultPath = mset->value("up_result_path", "").toString();
|
||||
config.upWarningPath = mset->value("up_warning_path", "").toString();
|
||||
config.upResultPath = mset->value("up_result_path", 1).toString();
|
||||
config.username = mset->value("username", "").toString();
|
||||
config.password = mset->value("password", false).toString();
|
||||
|
||||
|
|
@ -75,6 +120,7 @@ bool ConfigUtil::readSocketServerConfig(const QString &configFile, QString &erro
|
|||
mset->beginGroup("socket_server");
|
||||
config.server_ip = mset->value("server_ip", "").toString();
|
||||
config.server_port = mset->value("server_port", "").toInt();
|
||||
config.delayed_upload = mset->value("delayed_upload", "3").toInt();
|
||||
|
||||
mset->endGroup();
|
||||
} catch (const std::exception &e) {
|
||||
|
|
@ -103,3 +149,25 @@ bool ConfigUtil::readDeviceWarnConfig(const QString &configFile, QString &errorM
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigUtil::readRelayConfig(const QString &configFile, QString &errorMessage,
|
||||
ai_matrix::RelayConfig &config) {
|
||||
try {
|
||||
if (configFile.isEmpty() || configFile.isNull()) {
|
||||
errorMessage = "配置文件地址为空,读取配置文件失败!";
|
||||
return false;
|
||||
}
|
||||
QSettings* mset = new QSettings(configFile, QSettings::IniFormat);
|
||||
mset->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||
mset->beginGroup("relay");
|
||||
config.listener_port = mset->value("listener_port", 7010).toInt();
|
||||
// config.max_connection = mset->value("max_connection", 3).toInt();
|
||||
|
||||
mset->endGroup();
|
||||
} catch (const std::exception &e) {
|
||||
errorMessage = e.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@ public:
|
|||
~ConfigUtil();
|
||||
|
||||
static bool readBaseConfig(const QString& configFile, QString &errorMessage, ai_matrix::BaseConfig &config);
|
||||
static bool readSerialConfig(const QString& configFile, QString &errorMessage, ai_matrix::SerialConfig &config);
|
||||
static bool readInterfaceConfig(const QString& configFile, QString &errorMessage, ai_matrix::InterfaceConfig &config);
|
||||
static bool readSocketServerConfig(const QString& configFile, QString &errorMessage, ai_matrix::SServerConfig &config);
|
||||
static bool readRelayConfig(const QString& configFile, QString &errorMessage, ai_matrix::RelayConfig &config);
|
||||
static bool readDeviceWarnConfig(const QString& configFile, QString &errorMessage, ai_matrix::DeviceWarnConfig &config);
|
||||
|
||||
|
||||
static bool writeBaseConfig(const QString& configFile, QString &errorMessage, ai_matrix::BaseConfig &config);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,33 +12,60 @@
|
|||
#include <QTextCodec>
|
||||
#include <QMessageBox>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QtGui>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QDebug>
|
||||
#include <QWaitCondition>
|
||||
#include <QObject>
|
||||
#include <QTcpsocket>
|
||||
#include <QDateTime>
|
||||
#include <QInputDialog>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QCloseEvent>
|
||||
#include <QAction>
|
||||
#include <QCloseEvent>
|
||||
#include <QTimer>
|
||||
#include <QListView>
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QtConcurrent>
|
||||
#include <QTcpServer>
|
||||
#include "Log.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
|
||||
namespace ai_matrix {
|
||||
const QString g_config_path = "./config/config.ini";
|
||||
|
||||
const int RELAY_MODEL = 0;
|
||||
const int IDENTIFY_MODEL = 1;
|
||||
|
||||
// --- 配置文件 ---
|
||||
|
||||
struct BaseConfig {
|
||||
// com口名称
|
||||
QString comName;
|
||||
// 波特率
|
||||
int baud;
|
||||
// 股道编号
|
||||
int trackName;
|
||||
// 是否有磁钢
|
||||
bool havaMagnetSteel;
|
||||
// 磁钢顺序
|
||||
QString magnetSteelOrder;
|
||||
// 上传识别结果标志
|
||||
bool upResult;
|
||||
// 使用socket来车通讯
|
||||
bool useSocketServer;
|
||||
// 是否使用设备异常报警
|
||||
bool useDeviceWarn;
|
||||
// 运行模式 0: 转发模式 1: 识别模式
|
||||
int runModel;
|
||||
};
|
||||
|
||||
struct SerialConfig {
|
||||
// com口名称
|
||||
QString comName;
|
||||
// 波特率
|
||||
int baud;
|
||||
// 是否有磁钢
|
||||
bool havaMagnetSteel;
|
||||
// 磁钢顺序
|
||||
QString magnetSteelOrder;
|
||||
};
|
||||
|
||||
struct InterfaceConfig {
|
||||
|
|
@ -73,6 +100,11 @@ namespace ai_matrix {
|
|||
int min_train_size;
|
||||
};
|
||||
|
||||
struct RelayConfig {
|
||||
// 监听端口
|
||||
int listener_port;
|
||||
};
|
||||
|
||||
// --- 配置文件 ---
|
||||
|
||||
struct TrainInfo {
|
||||
|
|
|
|||
|
|
@ -23,15 +23,15 @@ void TcpClient::connectToServer(QString ip, int port) {
|
|||
this->tcp_->connectToHost(ip, port); // Replace with actual server IP and port
|
||||
|
||||
if(QAbstractSocket::ConnectingState == this->tcp_->state()) {
|
||||
emit sendTcpInfoSignals("正在连接Socket服务器...");
|
||||
emit sendTcpInfoSignals("正在连接辅助识别...");
|
||||
}
|
||||
if (!this->tcp_->waitForConnected(2000))
|
||||
{
|
||||
emit sendTcpInfoSignals("链接服务端超时");
|
||||
emit sendTcpInfoSignals("链接辅助识别服务超时");
|
||||
// 5秒后尝试重新连接
|
||||
QTimer::singleShot(5000, this, [=](){
|
||||
// this->tcp_ = new QTcpSocket;
|
||||
emit sendTcpInfoSignals("重新连接Socket");
|
||||
emit sendTcpInfoSignals("重新连接辅助识别");
|
||||
emit restartSocket(this->ip_, this->port_);
|
||||
});
|
||||
return;
|
||||
|
|
@ -42,14 +42,14 @@ void TcpClient::connectToServer(QString ip, int port) {
|
|||
// 心跳包定时器启动
|
||||
this->heartbeatTimer_->start(3000);
|
||||
}
|
||||
emit sendTcpInfoSignals("链接服务端成功");
|
||||
emit sendTcpInfoSignals("链接辅助识别服务成功");
|
||||
// 连接失败
|
||||
connect(this->tcp_, &QTcpSocket::errorOccurred, this, [=](QAbstractSocket::SocketError err){
|
||||
emit sendTcpInfoSignals("链接服务端失败"); // 连接失败或其他错误,若服务器没有打开或连接失败,可以从这里会发出提示
|
||||
emit sendTcpInfoSignals("链接辅助识别服务失败"); // 连接失败或其他错误,若服务器没有打开或连接失败,可以从这里会发出提示
|
||||
});
|
||||
// 断开连接
|
||||
connect(this->tcp_, &QTcpSocket::disconnected, this, [=](){
|
||||
emit sendTcpInfoSignals("服务端断开连接");
|
||||
emit sendTcpInfoSignals("辅助识别服务断开连接");
|
||||
this->tcp_->close();
|
||||
this->tcp_->deleteLater();
|
||||
this->tcp_ = nullptr;
|
||||
|
|
@ -61,7 +61,7 @@ void TcpClient::connectToServer(QString ip, int port) {
|
|||
|
||||
// 5秒后尝试重新连接
|
||||
QTimer::singleShot(5000, this, [=](){
|
||||
emit sendTcpInfoSignals("重新连接Socket");
|
||||
emit sendTcpInfoSignals("重新连接辅助识别");
|
||||
emit restartSocket(this->ip_, this->port_);
|
||||
});
|
||||
|
||||
|
|
|
|||
26
src/main.cpp
26
src/main.cpp
|
|
@ -1,29 +1,8 @@
|
|||
|
||||
#include "mainwindow.h"
|
||||
#include "TcpClient.h"
|
||||
#include <QApplication>
|
||||
#include <MainWindow.h>
|
||||
#include "common.h"
|
||||
|
||||
void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) {
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
// 处理debug信息
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
// 处理警告信息
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
// 处理严重错误信息
|
||||
LogError<<"严重异常";
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
// 处理致命错误信息
|
||||
LogError<<"致命异常";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QDir dir("shared_key.txt");
|
||||
|
|
@ -59,7 +38,6 @@ int main(int argc, char *argv[]) {
|
|||
{
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
QApplication::setWindowIcon(QIcon("./logo.ico"));
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
//
|
||||
// Created by Mr.V on 2024/5/6.
|
||||
//
|
||||
|
||||
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved
|
||||
|
||||
#include <QFileDialog>
|
||||
#include "MainWindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
#include "TcpClient.h"
|
||||
|
||||
#define DEBUG_HTTP 1
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
this->statusBar = new QStatusBar();
|
||||
// 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);
|
||||
this->statusBar->addWidget(statusVersion);
|
||||
this->ui->statusbar->addPermanentWidget(this->statusInfo);//显示正常信息
|
||||
QLabel* statusVersion = new QLabel(" 开启时间:" + QDateTime::currentDateTime().toString("yy.MM.dd.hh.mm"),this);
|
||||
this->ui->statusbar->addWidget(statusVersion);
|
||||
|
||||
layout()->addWidget(this->statusBar);
|
||||
// layout()->addWidget(this->statusBar);
|
||||
|
||||
this->setWindowTitle("Matrix_RFID 车号识别程序(勿关!!)");
|
||||
|
||||
|
|
@ -33,6 +32,12 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
{
|
||||
this->logError(errorMessage);
|
||||
}
|
||||
if (!ConfigUtil::readSerialConfig(g_config_path, errorMessage, this->serialConfig_))
|
||||
{
|
||||
this->logError(errorMessage);
|
||||
}
|
||||
// this->ui->stackedWidget->currentChanged();
|
||||
this->ui->stackedWidget->setCurrentIndex(this->baseConfig_.runModel);
|
||||
|
||||
// 获取本机串口列表
|
||||
this->getComList();
|
||||
|
|
@ -50,7 +55,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
//初始最小化
|
||||
//this->showMinimized();//最小化
|
||||
// 设置最大展示数据行数
|
||||
this->ui->textBrowser->document()->setMaximumBlockCount(1000);
|
||||
this->ui->Log_TextBrowser->document()->setMaximumBlockCount(1000);
|
||||
this->ui->SocketLog_TextBrowser->document()->setMaximumBlockCount(1000);
|
||||
this->ui->Rfid_textBrowser->document()->setMaximumBlockCount(1000);
|
||||
|
||||
getStandardItemModel();
|
||||
this->ui->resultTable->setModel(this->resultTableModel_);
|
||||
|
|
@ -71,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
// 初始化LED指示灯
|
||||
this->upResultType(this->baseConfig_.upResult);
|
||||
|
||||
this->readComThread = new ReadComThread(&this->queueTrainInfo_, &this->queueWarn_, this);
|
||||
this->readComThread = new ReadComThread(&this->queueTrainInfo_, &this->queueWarn_, &this->queueRFID_, this);
|
||||
this->readComThread->start();
|
||||
|
||||
this->upResultThread = new UpResultThread(&this->queueTrainInfo_, this);
|
||||
|
|
@ -80,8 +87,18 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
this->upWarnThread = new UpWarnThread(&this->queueWarn_, this);
|
||||
this->upWarnThread->start();
|
||||
|
||||
this->relayRfidThread = new RelayRfidThread(&this->queueRFID_, this);
|
||||
this->relayRfidThread->start();
|
||||
|
||||
|
||||
connect(this->ui->identify, &QAction::triggered, this, &MainWindow::identifyModelClicked);
|
||||
connect(this->ui->relay, &QAction::triggered, this, &MainWindow::relayModelClicked);
|
||||
connect(this, &MainWindow::openCom_signals, this->readComThread, &ReadComThread::openCom);
|
||||
connect(this, &MainWindow::readTestRfid_signals, this->readComThread, &ReadComThread::readTestInfo);
|
||||
connect(this, &MainWindow::updateRunModel_ReadCom_signals, this->readComThread, &ReadComThread::updateRunModel);
|
||||
connect(this->relayRfidThread, &RelayRfidThread::update_client_num, this, &MainWindow::update_client_num);
|
||||
connect(this->relayRfidThread, &RelayRfidThread::ConnectInfoSignals, this, &MainWindow::ConnectInfoSignals);
|
||||
connect(this->relayRfidThread, &RelayRfidThread::RfidInfoSignals, this, &MainWindow::RfidInfoSignals);
|
||||
|
||||
connect(this->readComThread, &ReadComThread::openComSuccess, this, &MainWindow::openComResult);
|
||||
connect(this->readComThread, &ReadComThread::closeComSuccess, this, &MainWindow::closeComResult);
|
||||
|
|
@ -105,34 +122,62 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(this->upWarnThread, &UpWarnThread::WarnSignals, this, &MainWindow::WarnSlots);
|
||||
connect(this->upWarnThread, &UpWarnThread::ErrorSignals, this, &MainWindow::ErrorSlots);
|
||||
|
||||
connect(this->relayRfidThread, &RelayRfidThread::DebugSignals, this, &MainWindow::DebugSlots);
|
||||
connect(this->relayRfidThread, &RelayRfidThread::InfoSignals, this, &MainWindow::InfoSlots);
|
||||
connect(this->relayRfidThread, &RelayRfidThread::WarnSignals, this, &MainWindow::WarnSlots);
|
||||
connect(this->relayRfidThread, &RelayRfidThread::ErrorSignals, this, &MainWindow::ErrorSlots);
|
||||
|
||||
ui->openComButton->click();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
MainWindow::~MainWindow() {
|
||||
this->logInfo("-- 程序退出 --");
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::logDebug(const QString& message) {
|
||||
LogDebug << message.toStdString();
|
||||
ui->textBrowser->append(QString("[Debug] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
ui->Log_TextBrowser->append(QString("[Debug] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
}
|
||||
void MainWindow::logInfo(const QString& message) {
|
||||
LogInfo << message.toStdString();
|
||||
ui->textBrowser->append(QString("[Info] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
ui->Log_TextBrowser->append(QString("[Info] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
}
|
||||
void MainWindow::logWarn(const QString& message) {
|
||||
LogWarn << message.toStdString();
|
||||
ui->textBrowser->append(QString("[Warn] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
ui->Log_TextBrowser->append(QString("[Warn] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
}
|
||||
void MainWindow::logError(const QString& message) {
|
||||
LogError << message.toStdString();
|
||||
ui->textBrowser->append(QString("[Error] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
ui->Log_TextBrowser->append(QString("[Error] [") + this->getSystemTime() + QString::fromStdString("] ") + message);
|
||||
}
|
||||
void MainWindow::statusInfoUpdate(const QString &info) {
|
||||
this->statusInfo->setText(info);
|
||||
}
|
||||
void MainWindow::RfidInfoSignals(const QString &info) {
|
||||
this->ui->Rfid_textBrowser->append(info);
|
||||
}
|
||||
void MainWindow::ConnectInfoSignals(const QString &info) {
|
||||
this->ui->SocketLog_TextBrowser->append("- " + this->getSystemTime() + " - \n" + info);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::relayModelClicked() {
|
||||
this->updateRunModel(0);
|
||||
}
|
||||
void MainWindow::identifyModelClicked() {
|
||||
this->updateRunModel(1);
|
||||
}
|
||||
void MainWindow::updateRunModel(int page) {
|
||||
this->ui->stackedWidget->setCurrentIndex(page);
|
||||
this->baseConfig_.runModel = page;
|
||||
QString errorMessage = "";
|
||||
if (!ConfigUtil::writeBaseConfig(g_config_path, errorMessage, this->baseConfig_))
|
||||
{
|
||||
this->logError(errorMessage);
|
||||
}
|
||||
emit this->updateRunModel_ReadCom_signals(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建日志目录
|
||||
|
|
@ -169,27 +214,27 @@ QList<QString> MainWindow::getComList() {
|
|||
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(255, 255, 255); color: rgb(225, 225, 225);}");
|
||||
ui->BTBox->setStyleSheet("QComboBox {background-color: rgb(255, 255, 255);} QComboBox QAbstractItemView::item {min-height: 20px; background-color: rgb(225, 255, 255); color: rgb(0, 0, 0);}");
|
||||
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(255, 255, 255); color: rgb(225, 225, 225);}");
|
||||
ui->comBox->setStyleSheet("QComboBox {background-color: rgb(255, 255, 255);} QComboBox QAbstractItemView::item {min-height: 20px; background-color: rgb(225, 255, 255); color: rgb(0, 0, 0);}");
|
||||
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)
|
||||
if (this->serialConfig_.comName != "") {
|
||||
if (ui->comBox->findText(this->serialConfig_.comName) == -1)
|
||||
{
|
||||
ui->comBox->addItem(this->baseConfig_.comName);
|
||||
ui->comBox->addItem(this->serialConfig_.comName);
|
||||
}
|
||||
ui->comBox->setCurrentText(this->baseConfig_.comName);
|
||||
ui->comBox->setCurrentText(this->serialConfig_.comName);
|
||||
}
|
||||
if (ui->BTBox->findText(QString::number(this->baseConfig_.baud)) == -1)
|
||||
if (ui->BTBox->findText(QString::number(this->serialConfig_.baud)) == -1)
|
||||
{
|
||||
ui->BTBox->addItem(QString::number(this->baseConfig_.baud));
|
||||
ui->BTBox->addItem(QString::number(this->serialConfig_.baud));
|
||||
}
|
||||
ui->BTBox->setCurrentText(QString::number(this->baseConfig_.baud));
|
||||
ui->BTBox->setCurrentText(QString::number(this->serialConfig_.baud));
|
||||
|
||||
ui->truckEdit->setText(QString::number(this->baseConfig_.trackName));
|
||||
// ui->truckEdit->setText(QString::number(this->baseConfig_.trackName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -407,6 +452,13 @@ void MainWindow::ErrorSlots(const QString &info) {
|
|||
this->logError(info);
|
||||
}
|
||||
|
||||
// ============================= 转发 ====================================
|
||||
|
||||
void MainWindow::update_client_num(int num)
|
||||
{
|
||||
this->ui->SocketClientNum_Label->setText(QString::number(this->ui->SocketClientNum_Label->text().toInt() + num));
|
||||
}
|
||||
|
||||
// ============================= 测试 ====================================
|
||||
|
||||
void MainWindow::readTestInfo()
|
||||
|
|
|
|||
|
|
@ -1,85 +1,63 @@
|
|||
#ifndef MainWindow_H
|
||||
#define MainWindow_H
|
||||
//
|
||||
// Created by Mr.V on 2024/5/6.
|
||||
//
|
||||
|
||||
#include <QWidget>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef TRAIN_RFID_RELAY_MainWindow_H
|
||||
#define TRAIN_RFID_RELAY_MainWindow_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <WinSock2.h>
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <QWaitCondition>
|
||||
#include <ctime>
|
||||
#include <codecvt>
|
||||
#include <Iphlpapi.h>
|
||||
#include <cstdlib>
|
||||
#include <QObject>
|
||||
#include <QTcpsocket>
|
||||
#include <direct.h>
|
||||
#include <algorithm>
|
||||
#include <QDateTime>
|
||||
#include "httplib.h"
|
||||
#include "json.h"
|
||||
#include <QInputDialog>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QCloseEvent>
|
||||
#include <QAction>
|
||||
#include <QCloseEvent>
|
||||
#include <qmenu.h>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <thread>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QListView>
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QtConcurrent>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include "common.h"
|
||||
|
||||
//#include "ComDetect.h"
|
||||
|
||||
#include "UpResultThread.h"
|
||||
#include "ReadComThread.h"
|
||||
#include "RelayRfidThread.h"
|
||||
#include "TcpClient.h"
|
||||
#include "UpWarnThread.h"
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
using namespace ai_matrix;
|
||||
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
~MainWindow() override;
|
||||
|
||||
void logDebug(const QString& message);
|
||||
void logInfo(const QString& message);
|
||||
void logWarn(const QString& message);
|
||||
void logError(const QString& message);
|
||||
// 创建日志目录
|
||||
bool mkLogDir();
|
||||
static bool mkLogDir();
|
||||
|
||||
void initParam();
|
||||
|
||||
QString getSystemTime();
|
||||
static QString getSystemTime();
|
||||
|
||||
// 获const 取串口列表&
|
||||
QList<QString> getComList();
|
||||
|
|
@ -91,16 +69,19 @@ public:
|
|||
QStandardItem* getStandardItem(const QString &value);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
UpResultThread *upResultThread;
|
||||
UpWarnThread *upWarnThread;
|
||||
ReadComThread *readComThread;
|
||||
RelayRfidThread *relayRfidThread;
|
||||
|
||||
QString logRfidRecvName;
|
||||
QFile recvLog;
|
||||
|
||||
QString configPath_; //
|
||||
ai_matrix::BaseConfig baseConfig_;
|
||||
ai_matrix::SerialConfig serialConfig_;
|
||||
ai_matrix::InterfaceConfig interfaceConfig_;
|
||||
|
||||
std::string webToken; //授权信息
|
||||
|
|
@ -116,7 +97,7 @@ private:
|
|||
QList<QString> comList;
|
||||
// 整列车识别结果存储
|
||||
QStringList vecTrain;
|
||||
MQueue<QString> queue_{}; // RFID读取的数据队列
|
||||
MQueue<QString> queueRFID_{}; // RFID读取的数据队列
|
||||
MQueue<TrainInfo> queueTrainInfo_{}; // RFID读取的磁钢信息队列
|
||||
MQueue<QString> queueWarn_{}; // 报警信息队列
|
||||
|
||||
|
|
@ -128,17 +109,17 @@ private:
|
|||
|
||||
private:
|
||||
|
||||
QStatusBar* statusBar;
|
||||
QStatusBar* statusBar{};
|
||||
QLabel *statusInfo;
|
||||
|
||||
QMenu* m_pTrayMennu; //系统托盘右键菜单项
|
||||
QMenu* m_pTrayMennu{}; //系统托盘右键菜单项
|
||||
QSystemTrayIcon* m_pSystemTray; //系统托盘图标
|
||||
|
||||
//右键菜单栏选项
|
||||
QAction* m_pActionShow;
|
||||
QAction* m_pActionQuit;
|
||||
QAction* m_pActionShow{};
|
||||
QAction* m_pActionQuit{};
|
||||
void creat_action();
|
||||
void changeEvent(QEvent *event);
|
||||
void changeEvent(QEvent *event) override;
|
||||
void on_ShowMainAction();
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void creat_menu();
|
||||
|
|
@ -146,8 +127,12 @@ private:
|
|||
signals:
|
||||
void openCom_signals(const bool &type, const int &msec = 0);
|
||||
void readTestRfid_signals(const QString &filePath);
|
||||
void updateRunModel_ReadCom_signals(int model);
|
||||
|
||||
private slots:
|
||||
void relayModelClicked();
|
||||
void identifyModelClicked();
|
||||
void updateRunModel(int page);
|
||||
void openComClicked();
|
||||
void openComResult(const bool &success);
|
||||
void closeComResult(const bool &success);
|
||||
|
|
@ -157,15 +142,15 @@ private slots:
|
|||
void readTestInfo();
|
||||
|
||||
void statusInfoUpdate(const QString &info);
|
||||
void update_client_num(int num);
|
||||
void RfidInfoSignals(const QString &info);
|
||||
void ConnectInfoSignals(const QString &info);
|
||||
|
||||
void DebugSlots(const QString &info);
|
||||
void InfoSlots(const QString &info);
|
||||
void WarnSlots(const QString &info);
|
||||
void ErrorSlots(const QString &info);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
|
||||
#endif // MainWindow_H
|
||||
#endif //TRAIN_RFID_RELAY_MainWindow_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,5 @@
|
|||
/********************************************************************************
|
||||
** Form generated from reading UI file 'mainwindow.ui'
|
||||
** Form generated from reading UI file 'MainWindow.ui'
|
||||
**
|
||||
** Created by: Qt User Interface Compiler version 5.15.2
|
||||
**
|
||||
|
|
@ -10,14 +10,19 @@
|
|||
#define UI_MAINWINDOW_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QComboBox>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtWidgets/QMenu>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
#include <QtWidgets/QPushButton>
|
||||
#include <QtWidgets/QSpacerItem>
|
||||
#include <QtWidgets/QStackedWidget>
|
||||
#include <QtWidgets/QStatusBar>
|
||||
#include <QtWidgets/QTableView>
|
||||
#include <QtWidgets/QTextBrowser>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
|
@ -28,53 +33,89 @@ QT_BEGIN_NAMESPACE
|
|||
class Ui_MainWindow
|
||||
{
|
||||
public:
|
||||
QVBoxLayout *verticalLayout_3;
|
||||
QAction *actionset;
|
||||
QAction *actionshibiefuzhu;
|
||||
QAction *actionchuankou;
|
||||
QAction *identify;
|
||||
QAction *relay;
|
||||
QWidget *centralwidget;
|
||||
QVBoxLayout *verticalLayout;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QLabel *label;
|
||||
QComboBox *comBox;
|
||||
QSpacerItem *horizontalSpacer_9;
|
||||
QLabel *label_2;
|
||||
QComboBox *BTBox;
|
||||
QLabel *label_3;
|
||||
QLineEdit *truckEdit;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QLabel *LEDlabel;
|
||||
QPushButton *openComButton;
|
||||
QLabel *LEDlabel;
|
||||
QSpacerItem *horizontalSpacer_5;
|
||||
QPushButton *testButton;
|
||||
QSpacerItem *horizontalSpacer_2;
|
||||
QHBoxLayout *horizontalLayout_2;
|
||||
QVBoxLayout *verticalLayout;
|
||||
QStackedWidget *stackedWidget;
|
||||
QWidget *page;
|
||||
QVBoxLayout *verticalLayout_7;
|
||||
QVBoxLayout *verticalLayout_3;
|
||||
QHBoxLayout *horizontalLayout_5;
|
||||
QLabel *label_8;
|
||||
QLabel *SocketClientNum_Label;
|
||||
QSpacerItem *horizontalSpacer_6;
|
||||
QTextBrowser *SocketLog_TextBrowser;
|
||||
QHBoxLayout *horizontalLayout_3;
|
||||
QLabel *label_4;
|
||||
QLabel *upflagLabel;
|
||||
QSpacerItem *horizontalSpacer_3;
|
||||
QTextBrowser *Rfid_textBrowser;
|
||||
QWidget *page_2;
|
||||
QVBoxLayout *verticalLayout_6;
|
||||
QHBoxLayout *horizontalLayout_6;
|
||||
QVBoxLayout *verticalLayout_4;
|
||||
QHBoxLayout *horizontalLayout_7;
|
||||
QLabel *label_6;
|
||||
QLabel *upflagLabel;
|
||||
QSpacerItem *horizontalSpacer_7;
|
||||
QTableView *resultTable;
|
||||
QVBoxLayout *verticalLayout_2;
|
||||
QHBoxLayout *horizontalLayout_4;
|
||||
QLabel *label_5;
|
||||
QSpacerItem *horizontalSpacer_4;
|
||||
QTextBrowser *textBrowser;
|
||||
QTextBrowser *Log_TextBrowser;
|
||||
QMenuBar *menubar;
|
||||
QMenu *menu;
|
||||
QMenu *run_model;
|
||||
QStatusBar *statusbar;
|
||||
|
||||
void setupUi(QWidget *MainWindow)
|
||||
void setupUi(QMainWindow *MainWindow)
|
||||
{
|
||||
if (MainWindow->objectName().isEmpty())
|
||||
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
|
||||
MainWindow->resize(1000, 815);
|
||||
MainWindow->setMinimumSize(QSize(1000, 815));
|
||||
MainWindow->setMaximumSize(QSize(1000, 815));
|
||||
MainWindow->setStyleSheet(QString::fromUtf8("background-color: rgb(217, 235, 255);"));
|
||||
verticalLayout_3 = new QVBoxLayout(MainWindow);
|
||||
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
|
||||
actionset = new QAction(MainWindow);
|
||||
actionset->setObjectName(QString::fromUtf8("actionset"));
|
||||
actionshibiefuzhu = new QAction(MainWindow);
|
||||
actionshibiefuzhu->setObjectName(QString::fromUtf8("actionshibiefuzhu"));
|
||||
actionchuankou = new QAction(MainWindow);
|
||||
actionchuankou->setObjectName(QString::fromUtf8("actionchuankou"));
|
||||
identify = new QAction(MainWindow);
|
||||
identify->setObjectName(QString::fromUtf8("identify"));
|
||||
relay = new QAction(MainWindow);
|
||||
relay->setObjectName(QString::fromUtf8("relay"));
|
||||
centralwidget = new QWidget(MainWindow);
|
||||
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
|
||||
verticalLayout = new QVBoxLayout(centralwidget);
|
||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||
horizontalLayout = new QHBoxLayout();
|
||||
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
|
||||
label = new QLabel(MainWindow);
|
||||
horizontalLayout->setContentsMargins(-1, 6, -1, -1);
|
||||
label = new QLabel(centralwidget);
|
||||
label->setObjectName(QString::fromUtf8("label"));
|
||||
label->setMaximumSize(QSize(80, 16777215));
|
||||
label->setMaximumSize(QSize(70, 16777215));
|
||||
label->setStyleSheet(QString::fromUtf8("font: 75 9pt \"Arial\";"));
|
||||
|
||||
horizontalLayout->addWidget(label);
|
||||
|
||||
comBox = new QComboBox(MainWindow);
|
||||
comBox = new QComboBox(centralwidget);
|
||||
comBox->setObjectName(QString::fromUtf8("comBox"));
|
||||
comBox->setMinimumSize(QSize(120, 40));
|
||||
comBox->setMaximumSize(QSize(100, 40));
|
||||
|
|
@ -82,14 +123,18 @@ public:
|
|||
|
||||
horizontalLayout->addWidget(comBox);
|
||||
|
||||
label_2 = new QLabel(MainWindow);
|
||||
horizontalSpacer_9 = new QSpacerItem(40, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout->addItem(horizontalSpacer_9);
|
||||
|
||||
label_2 = new QLabel(centralwidget);
|
||||
label_2->setObjectName(QString::fromUtf8("label_2"));
|
||||
label_2->setMaximumSize(QSize(80, 16777215));
|
||||
label_2->setMaximumSize(QSize(70, 16777215));
|
||||
label_2->setStyleSheet(QString::fromUtf8("font: 75 9pt \"Arial\";"));
|
||||
|
||||
horizontalLayout->addWidget(label_2);
|
||||
|
||||
BTBox = new QComboBox(MainWindow);
|
||||
BTBox = new QComboBox(centralwidget);
|
||||
BTBox->addItem(QString());
|
||||
BTBox->addItem(QString());
|
||||
BTBox->addItem(QString());
|
||||
|
|
@ -100,34 +145,11 @@ public:
|
|||
|
||||
horizontalLayout->addWidget(BTBox);
|
||||
|
||||
label_3 = new QLabel(MainWindow);
|
||||
label_3->setObjectName(QString::fromUtf8("label_3"));
|
||||
label_3->setMaximumSize(QSize(80, 16777215));
|
||||
|
||||
horizontalLayout->addWidget(label_3);
|
||||
|
||||
truckEdit = new QLineEdit(MainWindow);
|
||||
truckEdit->setObjectName(QString::fromUtf8("truckEdit"));
|
||||
truckEdit->setMinimumSize(QSize(120, 40));
|
||||
truckEdit->setMaximumSize(QSize(100, 40));
|
||||
truckEdit->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 255);"));
|
||||
|
||||
horizontalLayout->addWidget(truckEdit);
|
||||
|
||||
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
horizontalSpacer = new QSpacerItem(80, 20, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout->addItem(horizontalSpacer);
|
||||
|
||||
LEDlabel = new QLabel(MainWindow);
|
||||
LEDlabel->setObjectName(QString::fromUtf8("LEDlabel"));
|
||||
LEDlabel->setMaximumSize(QSize(32, 32));
|
||||
LEDlabel->setStyleSheet(QString::fromUtf8("border-radius: 16px;\n"
|
||||
"background-color: red;\n"
|
||||
"border:1px solid rgba(168, 168, 168, 105);"));
|
||||
|
||||
horizontalLayout->addWidget(LEDlabel);
|
||||
|
||||
openComButton = new QPushButton(MainWindow);
|
||||
openComButton = new QPushButton(centralwidget);
|
||||
openComButton->setObjectName(QString::fromUtf8("openComButton"));
|
||||
openComButton->setMinimumSize(QSize(120, 50));
|
||||
openComButton->setMaximumSize(QSize(120, 50));
|
||||
|
|
@ -136,11 +158,21 @@ public:
|
|||
|
||||
horizontalLayout->addWidget(openComButton);
|
||||
|
||||
horizontalSpacer_5 = new QSpacerItem(20, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
LEDlabel = new QLabel(centralwidget);
|
||||
LEDlabel->setObjectName(QString::fromUtf8("LEDlabel"));
|
||||
LEDlabel->setMinimumSize(QSize(32, 32));
|
||||
LEDlabel->setMaximumSize(QSize(32, 32));
|
||||
LEDlabel->setStyleSheet(QString::fromUtf8("border-radius: 16px;\n"
|
||||
"background-color: red;\n"
|
||||
"border:1px solid rgba(168, 168, 168, 105);"));
|
||||
|
||||
horizontalLayout->addWidget(LEDlabel);
|
||||
|
||||
horizontalSpacer_5 = new QSpacerItem(50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout->addItem(horizontalSpacer_5);
|
||||
|
||||
testButton = new QPushButton(MainWindow);
|
||||
testButton = new QPushButton(centralwidget);
|
||||
testButton->setObjectName(QString::fromUtf8("testButton"));
|
||||
testButton->setMinimumSize(QSize(50, 50));
|
||||
testButton->setMaximumSize(QSize(50, 50));
|
||||
|
|
@ -149,57 +181,151 @@ public:
|
|||
|
||||
horizontalLayout->addWidget(testButton);
|
||||
|
||||
horizontalSpacer_2 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
horizontalSpacer_2 = new QSpacerItem(20, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout->addItem(horizontalSpacer_2);
|
||||
|
||||
|
||||
verticalLayout_3->addLayout(horizontalLayout);
|
||||
verticalLayout->addLayout(horizontalLayout);
|
||||
|
||||
horizontalLayout_2 = new QHBoxLayout();
|
||||
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
|
||||
verticalLayout = new QVBoxLayout();
|
||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||
stackedWidget = new QStackedWidget(centralwidget);
|
||||
stackedWidget->setObjectName(QString::fromUtf8("stackedWidget"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(stackedWidget->sizePolicy().hasHeightForWidth());
|
||||
stackedWidget->setSizePolicy(sizePolicy);
|
||||
stackedWidget->setMaximumSize(QSize(400, 16777215));
|
||||
stackedWidget->setStyleSheet(QString::fromUtf8("background-color: rgb(217, 235, 255);"));
|
||||
page = new QWidget();
|
||||
page->setObjectName(QString::fromUtf8("page"));
|
||||
verticalLayout_7 = new QVBoxLayout(page);
|
||||
verticalLayout_7->setObjectName(QString::fromUtf8("verticalLayout_7"));
|
||||
verticalLayout_7->setContentsMargins(0, 0, 0, 0);
|
||||
verticalLayout_3 = new QVBoxLayout();
|
||||
verticalLayout_3->setSpacing(9);
|
||||
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
|
||||
horizontalLayout_5 = new QHBoxLayout();
|
||||
horizontalLayout_5->setObjectName(QString::fromUtf8("horizontalLayout_5"));
|
||||
label_8 = new QLabel(page);
|
||||
label_8->setObjectName(QString::fromUtf8("label_8"));
|
||||
label_8->setMinimumSize(QSize(140, 20));
|
||||
label_8->setMaximumSize(QSize(140, 20));
|
||||
label_8->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
|
||||
horizontalLayout_5->addWidget(label_8);
|
||||
|
||||
SocketClientNum_Label = new QLabel(page);
|
||||
SocketClientNum_Label->setObjectName(QString::fromUtf8("SocketClientNum_Label"));
|
||||
SocketClientNum_Label->setMinimumSize(QSize(50, 0));
|
||||
SocketClientNum_Label->setMaximumSize(QSize(50, 20));
|
||||
QFont font;
|
||||
font.setFamily(QString::fromUtf8("Arial Black"));
|
||||
SocketClientNum_Label->setFont(font);
|
||||
|
||||
horizontalLayout_5->addWidget(SocketClientNum_Label);
|
||||
|
||||
horizontalSpacer_6 = new QSpacerItem(140, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout_5->addItem(horizontalSpacer_6);
|
||||
|
||||
|
||||
verticalLayout_3->addLayout(horizontalLayout_5);
|
||||
|
||||
SocketLog_TextBrowser = new QTextBrowser(page);
|
||||
SocketLog_TextBrowser->setObjectName(QString::fromUtf8("SocketLog_TextBrowser"));
|
||||
SocketLog_TextBrowser->setMaximumSize(QSize(400, 200));
|
||||
SocketLog_TextBrowser->setStyleSheet(QString::fromUtf8("background-color: rgba(232, 232, 232, 100);"));
|
||||
|
||||
verticalLayout_3->addWidget(SocketLog_TextBrowser);
|
||||
|
||||
horizontalLayout_3 = new QHBoxLayout();
|
||||
horizontalLayout_3->setSpacing(6);
|
||||
horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
|
||||
label_4 = new QLabel(MainWindow);
|
||||
label_4 = new QLabel(page);
|
||||
label_4->setObjectName(QString::fromUtf8("label_4"));
|
||||
label_4->setMinimumSize(QSize(0, 20));
|
||||
label_4->setMaximumSize(QSize(100, 20));
|
||||
label_4->setMinimumSize(QSize(150, 20));
|
||||
label_4->setMaximumSize(QSize(150, 20));
|
||||
|
||||
horizontalLayout_3->addWidget(label_4);
|
||||
|
||||
upflagLabel = new QLabel(MainWindow);
|
||||
upflagLabel->setObjectName(QString::fromUtf8("upflagLabel"));
|
||||
upflagLabel->setMinimumSize(QSize(70, 20));
|
||||
upflagLabel->setMaximumSize(QSize(80, 20));
|
||||
|
||||
horizontalLayout_3->addWidget(upflagLabel);
|
||||
|
||||
horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
horizontalSpacer_3 = new QSpacerItem(150, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout_3->addItem(horizontalSpacer_3);
|
||||
|
||||
|
||||
verticalLayout->addLayout(horizontalLayout_3);
|
||||
verticalLayout_3->addLayout(horizontalLayout_3);
|
||||
|
||||
resultTable = new QTableView(MainWindow);
|
||||
Rfid_textBrowser = new QTextBrowser(page);
|
||||
Rfid_textBrowser->setObjectName(QString::fromUtf8("Rfid_textBrowser"));
|
||||
Rfid_textBrowser->setMaximumSize(QSize(400, 16777215));
|
||||
Rfid_textBrowser->setStyleSheet(QString::fromUtf8("background-color: rgba(232, 232, 232, 100);"));
|
||||
|
||||
verticalLayout_3->addWidget(Rfid_textBrowser);
|
||||
|
||||
|
||||
verticalLayout_7->addLayout(verticalLayout_3);
|
||||
|
||||
stackedWidget->addWidget(page);
|
||||
page_2 = new QWidget();
|
||||
page_2->setObjectName(QString::fromUtf8("page_2"));
|
||||
verticalLayout_6 = new QVBoxLayout(page_2);
|
||||
verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6"));
|
||||
verticalLayout_6->setContentsMargins(0, 0, 0, 0);
|
||||
horizontalLayout_6 = new QHBoxLayout();
|
||||
horizontalLayout_6->setObjectName(QString::fromUtf8("horizontalLayout_6"));
|
||||
verticalLayout_4 = new QVBoxLayout();
|
||||
verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4"));
|
||||
horizontalLayout_7 = new QHBoxLayout();
|
||||
horizontalLayout_7->setSpacing(6);
|
||||
horizontalLayout_7->setObjectName(QString::fromUtf8("horizontalLayout_7"));
|
||||
label_6 = new QLabel(page_2);
|
||||
label_6->setObjectName(QString::fromUtf8("label_6"));
|
||||
label_6->setMinimumSize(QSize(0, 20));
|
||||
label_6->setMaximumSize(QSize(100, 20));
|
||||
|
||||
horizontalLayout_7->addWidget(label_6);
|
||||
|
||||
upflagLabel = new QLabel(page_2);
|
||||
upflagLabel->setObjectName(QString::fromUtf8("upflagLabel"));
|
||||
upflagLabel->setMinimumSize(QSize(50, 20));
|
||||
upflagLabel->setMaximumSize(QSize(50, 20));
|
||||
|
||||
horizontalLayout_7->addWidget(upflagLabel);
|
||||
|
||||
horizontalSpacer_7 = new QSpacerItem(180, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
|
||||
horizontalLayout_7->addItem(horizontalSpacer_7);
|
||||
|
||||
|
||||
verticalLayout_4->addLayout(horizontalLayout_7);
|
||||
|
||||
resultTable = new QTableView(page_2);
|
||||
resultTable->setObjectName(QString::fromUtf8("resultTable"));
|
||||
resultTable->setMinimumSize(QSize(220, 0));
|
||||
resultTable->setMaximumSize(QSize(220, 16777215));
|
||||
resultTable->setMaximumSize(QSize(400, 16777215));
|
||||
resultTable->setStyleSheet(QString::fromUtf8(""));
|
||||
|
||||
verticalLayout->addWidget(resultTable);
|
||||
verticalLayout_4->addWidget(resultTable);
|
||||
|
||||
|
||||
horizontalLayout_2->addLayout(verticalLayout);
|
||||
horizontalLayout_6->addLayout(verticalLayout_4);
|
||||
|
||||
|
||||
verticalLayout_6->addLayout(horizontalLayout_6);
|
||||
|
||||
stackedWidget->addWidget(page_2);
|
||||
|
||||
horizontalLayout_2->addWidget(stackedWidget);
|
||||
|
||||
verticalLayout_2 = new QVBoxLayout();
|
||||
verticalLayout_2->setSpacing(9);
|
||||
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
|
||||
horizontalLayout_4 = new QHBoxLayout();
|
||||
horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4"));
|
||||
label_5 = new QLabel(MainWindow);
|
||||
label_5 = new QLabel(centralwidget);
|
||||
label_5->setObjectName(QString::fromUtf8("label_5"));
|
||||
label_5->setMinimumSize(QSize(50, 20));
|
||||
label_5->setMaximumSize(QSize(100, 20));
|
||||
|
|
@ -214,47 +340,82 @@ public:
|
|||
|
||||
verticalLayout_2->addLayout(horizontalLayout_4);
|
||||
|
||||
textBrowser = new QTextBrowser(MainWindow);
|
||||
textBrowser->setObjectName(QString::fromUtf8("textBrowser"));
|
||||
textBrowser->setMinimumSize(QSize(700, 0));
|
||||
QFont font;
|
||||
font.setFamily(QString::fromUtf8("Arial"));
|
||||
font.setPointSize(9);
|
||||
font.setBold(false);
|
||||
font.setWeight(50);
|
||||
textBrowser->setFont(font);
|
||||
textBrowser->setStyleSheet(QString::fromUtf8("background-color: rgba(232, 232, 232, 100);"));
|
||||
Log_TextBrowser = new QTextBrowser(centralwidget);
|
||||
Log_TextBrowser->setObjectName(QString::fromUtf8("Log_TextBrowser"));
|
||||
Log_TextBrowser->setMinimumSize(QSize(650, 0));
|
||||
Log_TextBrowser->setStyleSheet(QString::fromUtf8("background-color: rgba(232, 232, 232, 100);"));
|
||||
|
||||
verticalLayout_2->addWidget(textBrowser);
|
||||
verticalLayout_2->addWidget(Log_TextBrowser);
|
||||
|
||||
|
||||
horizontalLayout_2->addLayout(verticalLayout_2);
|
||||
|
||||
|
||||
verticalLayout_3->addLayout(horizontalLayout_2);
|
||||
verticalLayout->addLayout(horizontalLayout_2);
|
||||
|
||||
MainWindow->setCentralWidget(centralwidget);
|
||||
menubar = new QMenuBar(MainWindow);
|
||||
menubar->setObjectName(QString::fromUtf8("menubar"));
|
||||
menubar->setGeometry(QRect(0, 0, 1000, 22));
|
||||
menubar->setStyleSheet(QString::fromUtf8(""));
|
||||
menu = new QMenu(menubar);
|
||||
menu->setObjectName(QString::fromUtf8("menu"));
|
||||
menu->setStyleSheet(QString::fromUtf8("background-color: rgb(155, 208, 255);"));
|
||||
run_model = new QMenu(menu);
|
||||
run_model->setObjectName(QString::fromUtf8("run_model"));
|
||||
MainWindow->setMenuBar(menubar);
|
||||
statusbar = new QStatusBar(MainWindow);
|
||||
statusbar->setObjectName(QString::fromUtf8("statusbar"));
|
||||
statusbar->setMouseTracking(false);
|
||||
MainWindow->setStatusBar(statusbar);
|
||||
|
||||
menubar->addAction(menu->menuAction());
|
||||
menu->addAction(run_model->menuAction());
|
||||
menu->addSeparator();
|
||||
menu->addAction(actionset);
|
||||
menu->addSeparator();
|
||||
menu->addAction(actionshibiefuzhu);
|
||||
menu->addSeparator();
|
||||
menu->addAction(actionchuankou);
|
||||
run_model->addAction(relay);
|
||||
run_model->addAction(identify);
|
||||
|
||||
retranslateUi(MainWindow);
|
||||
|
||||
stackedWidget->setCurrentIndex(0);
|
||||
|
||||
|
||||
QMetaObject::connectSlotsByName(MainWindow);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QWidget *MainWindow)
|
||||
void retranslateUi(QMainWindow *MainWindow)
|
||||
{
|
||||
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
|
||||
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "mainwindow", nullptr));
|
||||
actionset->setText(QCoreApplication::translate("MainWindow", "\346\216\245\345\217\243\350\256\276\347\275\256", nullptr));
|
||||
actionshibiefuzhu->setText(QCoreApplication::translate("MainWindow", "\344\270\262\345\217\243\350\256\276\347\275\256", nullptr));
|
||||
actionchuankou->setText(QCoreApplication::translate("MainWindow", "\350\257\206\345\210\253\350\276\205\345\212\251", nullptr));
|
||||
identify->setText(QCoreApplication::translate("MainWindow", "\350\257\206\345\210\253\346\250\241\345\274\217", nullptr));
|
||||
relay->setText(QCoreApplication::translate("MainWindow", "\350\275\254\345\217\221\346\250\241\345\274\217", nullptr));
|
||||
label->setText(QCoreApplication::translate("MainWindow", "\344\270\262\345\217\243\345\217\267:", nullptr));
|
||||
label_2->setText(QCoreApplication::translate("MainWindow", "\346\263\242\347\211\271\347\216\207:", nullptr));
|
||||
BTBox->setItemText(0, QCoreApplication::translate("MainWindow", "9600", nullptr));
|
||||
BTBox->setItemText(1, QCoreApplication::translate("MainWindow", "19200", nullptr));
|
||||
BTBox->setItemText(2, QCoreApplication::translate("MainWindow", "115200", nullptr));
|
||||
|
||||
label_3->setText(QCoreApplication::translate("MainWindow", "\350\202\241\351\201\223\345\220\215:", nullptr));
|
||||
LEDlabel->setText(QString());
|
||||
openComButton->setText(QCoreApplication::translate("MainWindow", "\346\211\223\345\274\200\344\270\262\345\217\243", nullptr));
|
||||
LEDlabel->setText(QString());
|
||||
testButton->setText(QCoreApplication::translate("MainWindow", "\346\265\213\350\257\225", nullptr));
|
||||
label_4->setText(QCoreApplication::translate("MainWindow", "\350\257\206\345\210\253\347\273\223\346\236\234:", nullptr));
|
||||
upflagLabel->setText(QCoreApplication::translate("MainWindow", "\344\270\215\344\270\212\344\274\240", nullptr));
|
||||
label_8->setText(QCoreApplication::translate("MainWindow", "\345\256\242\346\210\267\347\253\257\351\223\276\346\216\245\346\225\260:", nullptr));
|
||||
SocketClientNum_Label->setText(QCoreApplication::translate("MainWindow", "0", nullptr));
|
||||
label_4->setText(QCoreApplication::translate("MainWindow", "\350\275\254\345\217\221\344\277\241\346\201\257:", nullptr));
|
||||
label_6->setText(QCoreApplication::translate("MainWindow", "\350\257\206\345\210\253\347\273\223\346\236\234:", nullptr));
|
||||
upflagLabel->setText(QCoreApplication::translate("MainWindow", "\344\270\215\344\274\240", nullptr));
|
||||
label_5->setText(QCoreApplication::translate("MainWindow", "\346\227\245\345\277\227:", nullptr));
|
||||
menu->setTitle(QCoreApplication::translate("MainWindow", "\350\256\276\347\275\256", nullptr));
|
||||
run_model->setTitle(QCoreApplication::translate("MainWindow", "\350\257\206\345\210\253\346\250\241\345\274\217", nullptr));
|
||||
#if QT_CONFIG(statustip)
|
||||
statusbar->setStatusTip(QString());
|
||||
#endif // QT_CONFIG(statustip)
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
||||
MQueue<QString> *queueWarnInfo,
|
||||
MQueue<QString> *queueRFID,
|
||||
QObject *parent) :
|
||||
QThread(parent)
|
||||
{
|
||||
|
|
@ -15,6 +16,10 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
|||
{
|
||||
emit this->ErrorSignals(errorMessage);
|
||||
}
|
||||
if (!ConfigUtil::readSerialConfig(g_config_path, errorMessage, this->serialConfig_))
|
||||
{
|
||||
emit this->ErrorSignals(errorMessage);
|
||||
}
|
||||
if (!ConfigUtil::readSocketServerConfig(g_config_path, errorMessage, this->socketServerConfig_))
|
||||
{
|
||||
emit this->ErrorSignals(errorMessage);
|
||||
|
|
@ -26,6 +31,7 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
|||
|
||||
this->queueTrainInfo_ = queueTrainInfo;
|
||||
this->queueWarnInfo_ = queueWarnInfo;
|
||||
this->queueRFID_ = queueRFID;
|
||||
|
||||
this->logRfidRecvName = "./Logs/rfid_data.txt";
|
||||
this->recvLog.setFileName(logRfidRecvName);
|
||||
|
|
@ -57,11 +63,11 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
|||
connect(this->tcpClient, &TcpClient::sendTcpInfoSignals, this, [=](const QString& info){
|
||||
emit this->InfoSignals(info);
|
||||
emit this->statusInfoUpdate(info);
|
||||
if (info == "链接服务端超时"
|
||||
|| info == "未连接Socket服务器"
|
||||
|| info == "链接服务端失败"
|
||||
|| info == "服务端断开连接"
|
||||
|| info == "链接服务端失败")
|
||||
if (info == "链接辅助识别服务超时"
|
||||
|| info == "未连接辅助识别服务"
|
||||
|| info == "链接辅助识别服务失败"
|
||||
|| info == "辅助识别服务断开连接"
|
||||
|| info == "链接辅助识别服务失败")
|
||||
{
|
||||
this->videoHasTrain = false;
|
||||
}
|
||||
|
|
@ -78,14 +84,14 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
|||
{
|
||||
emit this->InfoSignals("视频车号识别-来车了");
|
||||
this->videoHasTrain = true;
|
||||
emit this->IdentifyType();
|
||||
emit IdentifyType();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit this->InfoSignals("视频车号识别-火车离开了");
|
||||
this->videoHasTrain = false;
|
||||
if (this->needIdentify)
|
||||
emit this->IdentifyType();
|
||||
emit IdentifyType();
|
||||
}
|
||||
});
|
||||
connect(this->tcpClient, &TcpClient::getDirectionSignals, this, [=](int direction) {
|
||||
|
|
@ -98,7 +104,7 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
|||
}
|
||||
}
|
||||
|
||||
void ReadComThread::run()
|
||||
[[noreturn]] void ReadComThread::run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
|
@ -124,14 +130,14 @@ void ReadComThread::openCom(const bool &type, const int &msec)
|
|||
{
|
||||
this->auto_reconnect_serial_ = true;
|
||||
this->serial_ = new QSerialPort(this);
|
||||
if (this->comDetect_->openCom(this->serial_, this->baseConfig_.comName, this->baseConfig_.baud))
|
||||
if (this->comDetect_->openCom(this->serial_, this->serialConfig_.comName, this->serialConfig_.baud))
|
||||
{
|
||||
QString logs;
|
||||
logs.append("串口打开成功\n");
|
||||
logs.append("串口号:" + this->baseConfig_.comName + "\n");
|
||||
logs.append("波特率:" + QString::number(this->baseConfig_.baud) + "\n");
|
||||
if (this->baseConfig_.havaMagnetSteel)
|
||||
logs.append("磁钢顺序:" + this->baseConfig_.magnetSteelOrder);
|
||||
logs.append("串口号:" + this->serialConfig_.comName + "\n");
|
||||
logs.append("波特率:" + QString::number(this->serialConfig_.baud) + "\n");
|
||||
if (this->serialConfig_.havaMagnetSteel)
|
||||
logs.append("磁钢顺序:" + this->serialConfig_.magnetSteelOrder);
|
||||
this->isOpenCom = true;
|
||||
emit this->InfoSignals(logs);
|
||||
|
||||
|
|
@ -183,7 +189,7 @@ void ReadComThread::readCom()
|
|||
if(!data.isEmpty())
|
||||
{
|
||||
this->queue_.push(QString(data));
|
||||
emit this->getRfid_signals();
|
||||
emit getRfid_signals();
|
||||
}
|
||||
data.clear();
|
||||
}
|
||||
|
|
@ -209,7 +215,7 @@ void ReadComThread::readTestInfo(const QString &filePath) {
|
|||
while(!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
this->queue_.push(line);
|
||||
emit this->getRfid_signals();
|
||||
emit getRfid_signals();
|
||||
}
|
||||
// 关闭文件
|
||||
file.close();
|
||||
|
|
@ -228,89 +234,119 @@ void ReadComThread::getQueueDataThread()
|
|||
QString strRfidInfo = this->queue_.getTop();
|
||||
this->queue_.pop();
|
||||
this->saveRfidLog(strRfidInfo);
|
||||
this->tmpRfid.append(strRfidInfo);
|
||||
if (this->tmpRfid.right(1) != "&")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->tmpRfid = this->tmpRfid.replace("&", "");
|
||||
QStringList rfidSubList = this->tmpRfid.split("@");
|
||||
this->tmpRfid = "";
|
||||
|
||||
auto split_lambda = [=](QString strFirst, QString strOther){
|
||||
auto split_lambda = [=](const QString& strFirst, const QString& strOther){
|
||||
if (strFirst == "0")
|
||||
{
|
||||
this->rfidHasTrain = false;
|
||||
emit this->InfoSignals("RFID-火车离开了");
|
||||
// 关功放信号
|
||||
// 需要结合 “来车状态”广播消息,确认是否真的车离开了; TODO:没有真离开,则向串口发送 @on& 避免关功放
|
||||
emit this->IdentifyType();
|
||||
emit IdentifyType();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: 此处按照4个磁钢来配置,可能存在一定限制; 另外逻辑需要优化
|
||||
if (strOther == "000000" // 第一次检测来车时(前提是上一次功放已关闭)
|
||||
&& (strFirst == this->baseConfig_.magnetSteelOrder.left(1)
|
||||
|| strFirst == this->baseConfig_.magnetSteelOrder.mid(1, 1)))
|
||||
&& (strFirst == this->serialConfig_.magnetSteelOrder.left(1)
|
||||
|| strFirst == this->serialConfig_.magnetSteelOrder.mid(1, 1)))
|
||||
{
|
||||
this->rfidHasTrain = true;
|
||||
emit this->InfoSignals("RFID-来车了");
|
||||
emit this->IdentifyType();
|
||||
emit IdentifyType();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const auto & i : rfidSubList)
|
||||
if (this->baseConfig_.runModel == ai_matrix::IDENTIFY_MODEL)
|
||||
{
|
||||
if (i.size() == 26 || i.size() == 24)
|
||||
this->tmpRfid.append(strRfidInfo);
|
||||
if (this->tmpRfid.right(1) != "&")
|
||||
{
|
||||
// 车厢信息
|
||||
QString strTrainInfo = i.mid(1,13);
|
||||
return;
|
||||
}
|
||||
|
||||
if (vecTrain.empty() || !vecTrain.contains(strTrainInfo))
|
||||
this->tmpRfid = this->tmpRfid.replace("&", "");
|
||||
QStringList rfidSubList = this->tmpRfid.split("@");
|
||||
this->tmpRfid = "";
|
||||
|
||||
for (const auto & i : rfidSubList)
|
||||
{
|
||||
if (i.size() == 26 || i.size() == 24)
|
||||
{
|
||||
// 车厢信息
|
||||
QString strTrainInfo = i.mid(1,13);
|
||||
|
||||
// 判断是否是车头 车头的第14位是 K或H (慎重)
|
||||
if (!i.mid(14, 1).contains(QRegExp("^[0-9]+$"))) continue;
|
||||
// 过滤掉车号中有非数字的
|
||||
if (!strTrainInfo.right(7).contains(QRegExp("^[0-9]+$"))) continue;
|
||||
// 因信号不稳定 增加一行过滤 出现读到的编号数据里 空格替代了实际字符的情况
|
||||
if (strTrainInfo.right(7).simplified().size() < 7) continue;
|
||||
if (vecTrain.empty() || !vecTrain.contains(strTrainInfo))
|
||||
{
|
||||
|
||||
vecTrain.append(strTrainInfo);
|
||||
int train_order = vecTrain.size();
|
||||
// 判断是否是车头 车头的第14位是 K或H (慎重)
|
||||
if (!i.mid(14, 1).contains(QRegExp("^[0-9]+$"))) continue;
|
||||
// 过滤掉车号中有非数字的
|
||||
// if (!strTrainInfo.right(7).contains(QRegExp("^[0-9]+$"))) continue;
|
||||
// 因信号不稳定 增加一行过滤 出现读到的编号数据里 空格替代了实际字符的情况
|
||||
// if (strTrainInfo.right(7).simplified().size() < 7) continue;
|
||||
|
||||
vecTrain.append(strTrainInfo);
|
||||
int train_order = vecTrain.size();
|
||||
// this->resultTableModel_->setItem(train_order - 1, 0, new QStandardItem(strTrainInfo));
|
||||
emit this->addResultSignals(strTrainInfo);
|
||||
emit this->InfoSignals(QString("第%1节 %2").arg(train_order).arg(strTrainInfo));
|
||||
emit this->addResultSignals(strTrainInfo);
|
||||
emit this->InfoSignals(QString("第%1节 %2").arg(train_order).arg(strTrainInfo));
|
||||
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
||||
this->rfidSourceInfo.append("@" + i);
|
||||
QString rfidinfo = this->rfidSourceInfo;
|
||||
this->rfidSourceInfo = "";
|
||||
emit upRfid_signals(rfidinfo);
|
||||
}
|
||||
}
|
||||
else if (i.size() == 7)
|
||||
{
|
||||
// 不使用磁钢的情况下 过滤掉磁钢信号
|
||||
if (!this->serialConfig_.havaMagnetSteel) continue;
|
||||
// 磁钢信号
|
||||
QString strFirst = i.left(1);
|
||||
QString strOther = i.mid(1, i.size() - 1);
|
||||
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
||||
this->rfidSourceInfo.append("@" + i);
|
||||
QString rfidinfo = this->rfidSourceInfo;
|
||||
this->rfidSourceInfo = "";
|
||||
emit this->upRfid_signals(rfidinfo);
|
||||
split_lambda(strFirst, strOther);
|
||||
}
|
||||
else if (i.size() == 14) // 特殊情况,来车信号少了&符
|
||||
{
|
||||
// 不使用磁钢的情况下 过滤掉磁钢信号
|
||||
if (!this->serialConfig_.havaMagnetSteel) continue;
|
||||
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);
|
||||
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
||||
this->rfidSourceInfo.append("@" + rfid_cg);
|
||||
split_lambda(strFirst, strOther);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (i.size() == 7)
|
||||
}
|
||||
else if (this->baseConfig_.runModel == ai_matrix::RELAY_MODEL)
|
||||
{
|
||||
this->queueRFID_->push(strRfidInfo);
|
||||
|
||||
this->tmpRfid.append(strRfidInfo);
|
||||
if (this->tmpRfid.right(1) != "&")
|
||||
{
|
||||
// 不使用磁钢的情况下 过滤掉磁钢信号
|
||||
if (!this->baseConfig_.havaMagnetSteel) continue;
|
||||
// 磁钢信号
|
||||
QString strFirst = i.left(1);
|
||||
QString strOther = i.mid(1, i.size() - 1);
|
||||
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
||||
this->rfidSourceInfo.append("@" + i);
|
||||
split_lambda(strFirst, strOther);
|
||||
return;
|
||||
}
|
||||
else if (i.size() == 14) // 特殊情况,来车信号少了&符
|
||||
|
||||
this->tmpRfid = this->tmpRfid.replace("&", "");
|
||||
QStringList rfidSubList = this->tmpRfid.split("@");
|
||||
this->tmpRfid = "";
|
||||
for (const auto & i : rfidSubList)
|
||||
{
|
||||
// 不使用磁钢的情况下 过滤掉磁钢信号
|
||||
if (!this->baseConfig_.havaMagnetSteel) continue;
|
||||
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);
|
||||
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
||||
this->rfidSourceInfo.append("@" + rfid_cg);
|
||||
if (i.size() == 7)
|
||||
{
|
||||
// 不使用磁钢的情况下 过滤掉磁钢信号
|
||||
if (!this->serialConfig_.havaMagnetSteel) continue;
|
||||
// 磁钢信号
|
||||
QString strFirst = i.left(1);
|
||||
QString strOther = i.mid(1, i.size() - 1);
|
||||
split_lambda(strFirst, strOther);
|
||||
}
|
||||
}
|
||||
|
|
@ -328,13 +364,14 @@ void ReadComThread::IdentifyTypeUpdate() {
|
|||
this->needIdentify = true;
|
||||
this->trainTime = this->getSystemTime();
|
||||
emit this->comeTrain(false);
|
||||
|
||||
}
|
||||
}
|
||||
else if (!this->rfidHasTrain && !this->videoHasTrain)
|
||||
{
|
||||
if (this->vecTrain.size() < this->deviceWarnConfig_.min_train_size
|
||||
&& this->iDirection > 0
|
||||
&& (this->rfidSourceInfo.size() > 128 || this->vecTrain.size() > 1))
|
||||
&& this->iDirection > 0
|
||||
&& (this->rfidSourceInfo.size() > 192 || this->vecTrain.size() > 1))
|
||||
this->queueWarnInfo_->push("火车驶过,疑似RFID设备故障,读取到的车厢号有丢失");
|
||||
this->initParam();
|
||||
emit this->InfoSignals("火车离开了");
|
||||
|
|
@ -344,7 +381,7 @@ void ReadComThread::IdentifyTypeUpdate() {
|
|||
void ReadComThread::upRfid(const QString &rfidInfo)
|
||||
{
|
||||
if (!this->baseConfig_.upResult) return;
|
||||
if (!this->needIdentify && this->baseConfig_.havaMagnetSteel)
|
||||
if (!this->needIdentify && this->serialConfig_.havaMagnetSteel)
|
||||
{
|
||||
emit upResultType(false);
|
||||
return;
|
||||
|
|
@ -385,6 +422,11 @@ void ReadComThread::upRfid(const QString &rfidInfo)
|
|||
}
|
||||
}
|
||||
|
||||
void ReadComThread::updateRunModel(int model)
|
||||
{
|
||||
this->baseConfig_.runModel = model;
|
||||
}
|
||||
|
||||
bool ReadComThread::mkRfidLog()
|
||||
{
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -20,12 +20,15 @@ class ReadComThread : public QThread{
|
|||
public:
|
||||
ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
|
||||
MQueue<QString> *queueWarnInfo,
|
||||
MQueue<QString> *queueRFID,
|
||||
QObject *parent = nullptr);
|
||||
~ReadComThread() {};
|
||||
void run() override;
|
||||
|
||||
[[noreturn]] void run() override;
|
||||
|
||||
private:
|
||||
MQueue<TrainInfo> *queueTrainInfo_ = nullptr;
|
||||
MQueue<QString> *queueRFID_ = nullptr;
|
||||
MQueue<QString> *queueWarnInfo_ = nullptr;
|
||||
MQueue<TrainInfo> queueTmpTrainInfo_{}; // RFID临时信息队列
|
||||
QSerialPort *serial_; //串口
|
||||
|
|
@ -33,6 +36,7 @@ private:
|
|||
QTimer timer_;
|
||||
|
||||
ai_matrix::BaseConfig baseConfig_;
|
||||
ai_matrix::SerialConfig serialConfig_;
|
||||
ai_matrix::SServerConfig socketServerConfig_;
|
||||
ai_matrix::DeviceWarnConfig deviceWarnConfig_;
|
||||
|
||||
|
|
@ -44,9 +48,6 @@ private:
|
|||
// 打开com口标志
|
||||
bool isOpenCom = false;
|
||||
|
||||
// RFID读取的数据队列
|
||||
MQueue<QString> queue_{};
|
||||
|
||||
QString logRfidRecvName;
|
||||
QFile recvLog;
|
||||
|
||||
|
|
@ -58,6 +59,9 @@ private:
|
|||
QString rfidSourceInfo;
|
||||
QString tmpRfid; //临时存储的RFID原始数据,用于防止接收的数据不完整
|
||||
|
||||
// RFID读取的数据队列
|
||||
MQueue<QString> queue_ = {};
|
||||
|
||||
// 识别方向正确标志
|
||||
bool needIdentify = false;
|
||||
// RFID识别有火车标志
|
||||
|
|
@ -104,8 +108,8 @@ public slots:
|
|||
void getQueueDataThread();
|
||||
void IdentifyTypeUpdate();
|
||||
void upRfid(const QString &rfidInfo);
|
||||
// void upWarn(const QString &warnInfo);
|
||||
void tryToReconnect();
|
||||
void updateRunModel(int model);
|
||||
|
||||
void readTestInfo(const QString &filePath);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ UpResultThread::UpResultThread(MQueue<TrainInfo> *queueTrainInfo, QObject *paren
|
|||
QString errorMessage = "";
|
||||
if (!ConfigUtil::readBaseConfig(g_config_path, errorMessage, this->baseConfig_))
|
||||
{
|
||||
emit this->ErrorSignals(errorMessage);
|
||||
this->ErrorSignals(errorMessage);
|
||||
}
|
||||
if (!ConfigUtil::readInterfaceConfig(g_config_path, errorMessage, this->interfaceConfig_))
|
||||
{
|
||||
emit this->ErrorSignals(errorMessage);
|
||||
this->ErrorSignals(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ bool UpResultThread::upWeb(TrainInfo &trainInfo)
|
|||
Json::StreamWriterBuilder writer;
|
||||
std::string str = Json::writeString(writer, arrayObj);
|
||||
|
||||
emit this->InfoSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,发送web: " + QString::fromStdString(str));
|
||||
this->InfoSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,发送web: " + QString::fromStdString(str));
|
||||
httplib::Client cli(this->interfaceConfig_.httpIp.toStdString(), this->interfaceConfig_.httpPort);
|
||||
|
||||
cli.set_connection_timeout(3, 0);
|
||||
|
|
@ -100,23 +100,23 @@ bool UpResultThread::upWeb(TrainInfo &trainInfo)
|
|||
{
|
||||
|
||||
if (root["msg"].asString() == "请求未授权") {
|
||||
emit this->WarnSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
this->WarnSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
if (!this->getToken()) return false;
|
||||
return this->upWeb(trainInfo);
|
||||
}
|
||||
emit this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::fromStdString(root["msg"].asString()));
|
||||
this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::fromStdString(root["msg"].asString()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,返回数据解析异常,返回数据非json:" + QString::fromStdString(res->body));
|
||||
this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,返回数据解析异常,返回数据非json:" + QString::fromStdString(res->body));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::number(res->status) + " - " + QString::fromStdString(res->body));
|
||||
this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::number(res->status) + " - " + QString::fromStdString(res->body));
|
||||
if (res->status == 401) {
|
||||
emit this->WarnSignals("因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
this->WarnSignals("因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
this->getToken();
|
||||
return this->upWeb(trainInfo);
|
||||
}
|
||||
|
|
@ -124,12 +124,12 @@ bool UpResultThread::upWeb(TrainInfo &trainInfo)
|
|||
}
|
||||
else
|
||||
{
|
||||
emit this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传数据失败,请检查网络,或者上传地址!");
|
||||
this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传数据失败,请检查网络,或者上传地址!");
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
emit this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传识别结果失败,原因:" + QString::fromStdString(e.what()));
|
||||
this->ErrorSignals("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传识别结果失败,原因:" + QString::fromStdString(e.what()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -173,17 +173,17 @@ bool UpResultThread::getToken()
|
|||
this->webToken = root["token_type"].asString();
|
||||
this->webToken.append(" ");
|
||||
this->webToken.append(root["access_token"].asString());
|
||||
emit this->InfoSignals("已获取到web token");
|
||||
this->InfoSignals("已获取到web token");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit this->ErrorSignals("获取web token失败,原因:" + QString::fromStdString(res->body));
|
||||
this->ErrorSignals("获取web token失败,原因:" + QString::fromStdString(res->body));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit this->ErrorSignals("获取web token返回数据解析异常,返回数据非json。详细:" + QString::fromStdString(res->body));
|
||||
this->ErrorSignals("获取web token返回数据解析异常,返回数据非json。详细:" + QString::fromStdString(res->body));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -193,12 +193,12 @@ bool UpResultThread::getToken()
|
|||
// if (err == httplib::Error::Connection) {
|
||||
// std::cout << " (连接出错)" << std::endl;
|
||||
// }
|
||||
emit this->ErrorSignals("获取web token失败!请检查网络或请求地址。详细:" + QString::fromStdString(to_string(err)));
|
||||
this->ErrorSignals("获取web token失败!请检查网络或请求地址。详细:" + QString::fromStdString(to_string(err)));
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
emit this->ErrorSignals("获取授权失败,原因:" + QString::fromStdString(e.what()));
|
||||
this->ErrorSignals("获取授权失败,原因:" + QString::fromStdString(e.what()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue