信号发送代码补全

This commit is contained in:
Mr.V 2024-05-20 14:43:51 +08:00
parent b8880f4da7
commit 5c73baced8
1 changed files with 37 additions and 37 deletions

View File

@ -12,11 +12,11 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
QString errorMessage = ""; QString errorMessage = "";
if (!ConfigUtil::readBaseConfig(g_config_path, errorMessage, this->baseConfig_)) if (!ConfigUtil::readBaseConfig(g_config_path, errorMessage, this->baseConfig_))
{ {
this->ErrorSignals(errorMessage); emit this->ErrorSignals(errorMessage);
} }
if (!ConfigUtil::readSocketServerConfig(g_config_path, errorMessage, this->socketServerConfig_)) if (!ConfigUtil::readSocketServerConfig(g_config_path, errorMessage, this->socketServerConfig_))
{ {
this->ErrorSignals(errorMessage); emit this->ErrorSignals(errorMessage);
} }
this->queueTrainInfo_ = queueTrainInfo; this->queueTrainInfo_ = queueTrainInfo;
@ -49,8 +49,8 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
// 接收子线程的消息提示 // 接收子线程的消息提示
connect(this->tcpClient, &TcpClient::sendTcpInfoSignals, this, [=](const QString& info){ connect(this->tcpClient, &TcpClient::sendTcpInfoSignals, this, [=](const QString& info){
this->InfoSignals(info); emit this->InfoSignals(info);
this->statusInfoUpdate(info); emit this->statusInfoUpdate(info);
if (info == "链接服务端超时" if (info == "链接服务端超时"
|| info == "未连接Socket服务器" || info == "未连接Socket服务器"
|| info == "链接服务端失败" || info == "链接服务端失败"
@ -62,7 +62,7 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
}); });
// 接收子线程的TCP消息内容展示 // 接收子线程的TCP消息内容展示
connect(this->tcpClient, &TcpClient::getTcpInfoSignals, this, [=](const QString& info){ connect(this->tcpClient, &TcpClient::getTcpInfoSignals, this, [=](const QString& info){
this->InfoSignals(info); emit this->InfoSignals(info);
}); });
emit connect_socket(this->socketServerConfig_.server_ip, this->socketServerConfig_.server_port); emit connect_socket(this->socketServerConfig_.server_ip, this->socketServerConfig_.server_port);
@ -70,22 +70,22 @@ ReadComThread::ReadComThread(MQueue<TrainInfo> *queueTrainInfo,
connect(this->tcpClient, &TcpClient::comeTrainSignals, this, [=](bool type) { connect(this->tcpClient, &TcpClient::comeTrainSignals, this, [=](bool type) {
if (type) if (type)
{ {
this->InfoSignals("视频车号识别-来车了"); emit this->InfoSignals("视频车号识别-来车了");
this->videoHasTrain = true; this->videoHasTrain = true;
emit IdentifyType(); emit this->IdentifyType();
} }
else else
{ {
this->InfoSignals("视频车号识别-火车离开了"); emit this->InfoSignals("视频车号识别-火车离开了");
this->videoHasTrain = false; this->videoHasTrain = false;
if (this->needIdentify) if (this->needIdentify)
emit IdentifyType(); emit this->IdentifyType();
} }
}); });
connect(this->tcpClient, &TcpClient::getDirectionSignals, this, [=](int direction) { connect(this->tcpClient, &TcpClient::getDirectionSignals, this, [=](int direction) {
if (this->iDirection == 0) if (this->iDirection == 0)
{ {
this->InfoSignals("获得方向判定:" + QString(direction > -1 ? (direction > 0 ? "需识别" : "待定") : "无需上传")); emit this->InfoSignals("获得方向判定:" + QString(direction > -1 ? (direction > 0 ? "需识别" : "待定") : "无需上传"));
this->iDirection = direction; this->iDirection = direction;
} }
}); });
@ -127,7 +127,7 @@ void ReadComThread::openCom(const bool &type, const int &msec)
if (this->baseConfig_.havaMagnetSteel) if (this->baseConfig_.havaMagnetSteel)
logs.append("磁钢顺序:" + this->baseConfig_.magnetSteelOrder); logs.append("磁钢顺序:" + this->baseConfig_.magnetSteelOrder);
this->isOpenCom = true; this->isOpenCom = true;
this->InfoSignals(logs); emit this->InfoSignals(logs);
connect(this->serial_,&QSerialPort::readyRead,this,&ReadComThread::readCom); // connect(this->serial_,&QSerialPort::readyRead,this,&ReadComThread::readCom); //
connect(this->serial_, &QSerialPort::errorOccurred, this, &ReadComThread::serialPort_error); connect(this->serial_, &QSerialPort::errorOccurred, this, &ReadComThread::serialPort_error);
@ -140,7 +140,7 @@ void ReadComThread::openCom(const bool &type, const int &msec)
{ {
this->comDetect_->closeCom(this->serial_); this->comDetect_->closeCom(this->serial_);
this->isOpenCom = false; this->isOpenCom = false;
this->ErrorSignals("串口打开失败!"); emit this->ErrorSignals("串口打开失败!");
emit this->openComSuccess(false); emit this->openComSuccess(false);
this->timer_.start(10*1000); this->timer_.start(10*1000);
} }
@ -152,8 +152,8 @@ void ReadComThread::openCom(const bool &type, const int &msec)
if (this->comDetect_->closeCom(this->serial_)) if (this->comDetect_->closeCom(this->serial_))
{ {
this->initParam(); this->initParam();
this->InfoSignals("串口已关闭!"); emit this->InfoSignals("串口已关闭!");
this->closeComSuccess(true); emit this->closeComSuccess(true);
} }
else else
{ {
@ -177,16 +177,16 @@ void ReadComThread::readCom()
if(!data.isEmpty()) if(!data.isEmpty())
{ {
this->queue_.push(QString(data)); this->queue_.push(QString(data));
emit getRfid_signals(); emit this->getRfid_signals();
} }
data.clear(); data.clear();
} }
else else
{ {
this->ErrorSignals("等待读取超时"); emit this->ErrorSignals("等待读取超时");
} }
} catch(...) { } catch(...) {
this->ErrorSignals("读取串口数据异常!"); emit this->ErrorSignals("读取串口数据异常!");
} }
} }
@ -194,20 +194,20 @@ void ReadComThread::readTestInfo(const QString &filePath) {
// 创建一个QFile对象并打开要读取的文本文件 // 创建一个QFile对象并打开要读取的文本文件
QFile file(filePath); QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
this->ErrorSignals("无法打开测试文件:" + filePath); emit this->ErrorSignals("无法打开测试文件:" + filePath);
return; return;
} }
this->InfoSignals("开始读取测试数据..."); emit this->InfoSignals("开始读取测试数据...");
// 将文件内容读入到QStringList中 // 将文件内容读入到QStringList中
QTextStream in(&file); QTextStream in(&file);
while(!in.atEnd()) { while(!in.atEnd()) {
QString line = in.readLine(); QString line = in.readLine();
this->queue_.push(line); this->queue_.push(line);
emit getRfid_signals(); emit this->getRfid_signals();
} }
// 关闭文件 // 关闭文件
file.close(); file.close();
this->InfoSignals("---读取测试数据完毕---"); emit this->InfoSignals("---读取测试数据完毕---");
} }
/** /**
@ -236,10 +236,10 @@ void ReadComThread::getQueueDataThread()
if (strFirst == "0") if (strFirst == "0")
{ {
this->rfidHasTrain = false; this->rfidHasTrain = false;
this->InfoSignals("RFID-火车离开了"); emit this->InfoSignals("RFID-火车离开了");
// 关功放信号 // 关功放信号
// 需要结合 “来车状态”广播消息,确认是否真的车离开了; TODO:没有真离开,则向串口发送 @on& 避免关功放 // 需要结合 “来车状态”广播消息,确认是否真的车离开了; TODO:没有真离开,则向串口发送 @on& 避免关功放
emit IdentifyType(); emit this->IdentifyType();
} }
else else
{ {
@ -249,8 +249,8 @@ void ReadComThread::getQueueDataThread()
|| strFirst == this->baseConfig_.magnetSteelOrder.mid(1, 1))) || strFirst == this->baseConfig_.magnetSteelOrder.mid(1, 1)))
{ {
this->rfidHasTrain = true; this->rfidHasTrain = true;
this->InfoSignals("RFID-来车了"); emit this->InfoSignals("RFID-来车了");
emit IdentifyType(); emit this->IdentifyType();
} }
} }
}; };
@ -275,13 +275,13 @@ void ReadComThread::getQueueDataThread()
vecTrain.append(strTrainInfo); vecTrain.append(strTrainInfo);
int train_order = vecTrain.size(); int train_order = vecTrain.size();
// this->resultTableModel_->setItem(train_order - 1, 0, new QStandardItem(strTrainInfo)); // this->resultTableModel_->setItem(train_order - 1, 0, new QStandardItem(strTrainInfo));
this->addResultSignals(strTrainInfo); emit this->addResultSignals(strTrainInfo);
this->InfoSignals(QString("第%1节 %2").arg(train_order).arg(strTrainInfo)); emit this->InfoSignals(QString("第%1节 %2").arg(train_order).arg(strTrainInfo));
// 将接收到的RFID使用@符拼接起来以待后续上传web // 将接收到的RFID使用@符拼接起来以待后续上传web
this->rfidSourceInfo.append("@" + i); this->rfidSourceInfo.append("@" + i);
QString rfidinfo = this->rfidSourceInfo; QString rfidinfo = this->rfidSourceInfo;
this->rfidSourceInfo = ""; this->rfidSourceInfo = "";
emit upRfid_signals(rfidinfo); emit this->upRfid_signals(rfidinfo);
} }
} }
@ -317,19 +317,19 @@ void ReadComThread::IdentifyTypeUpdate() {
{ {
if (!this->needIdentify) if (!this->needIdentify)
{ {
this->InfoSignals("来车了"); emit this->InfoSignals("来车了");
this->mkRfidLog(); this->mkRfidLog();
this->vecTrain.clear(); this->vecTrain.clear();
this->needIdentify = true; this->needIdentify = true;
this->trainTime = this->getSystemTime(); this->trainTime = this->getSystemTime();
emit this->comeTrain(false); emit this->comeTrain(false);
} }
} }
else if (!this->rfidHasTrain && !this->videoHasTrain) else if (!this->rfidHasTrain && !this->videoHasTrain)
{ {
this->rfidSourceInfo
this->initParam(); this->initParam();
this->InfoSignals("火车离开了"); emit this->InfoSignals("火车离开了");
} }
} }
@ -392,8 +392,8 @@ bool ReadComThread::mkRfidLog()
} }
return true; return true;
} catch (const std::exception &e) { } catch (const std::exception &e) {
this->ErrorSignals("创建、打开RFID原始数据日志文件失败,详细:"); emit this->ErrorSignals("创建、打开RFID原始数据日志文件失败,详细:");
this->ErrorSignals(e.what()); emit this->ErrorSignals(e.what());
} }
return false; return false;
} }
@ -409,7 +409,7 @@ void ReadComThread::saveRfidLog(const QString &value)
this->recvLog.write(logValue.toUtf8()); this->recvLog.write(logValue.toUtf8());
this->recvLog.flush(); this->recvLog.flush();
} catch (const std::exception &e) { } catch (const std::exception &e) {
this->ErrorSignals("保存RFID原数据失败"); emit this->ErrorSignals("保存RFID原数据失败");
} }
} }
@ -427,13 +427,13 @@ bool ReadComThread::rnameRfidLog()
if (!logFile.rename(newLogFileName)) if (!logFile.rename(newLogFileName))
{ {
this->ErrorSignals("读取RFID原始数据存储重命名失败"); emit this->ErrorSignals("读取RFID原始数据存储重命名失败");
return false; return false;
} }
this->deleteOldFiles(fileInfo.path(), 3); this->deleteOldFiles(fileInfo.path(), 3);
} catch (const std::exception &e) { } catch (const std::exception &e) {
this->ErrorSignals("读取RFID原始数据存储重命名失败"); emit this->ErrorSignals("读取RFID原始数据存储重命名失败");
return false; return false;
} }
return true; return true;
@ -461,7 +461,7 @@ void ReadComThread::serialPort_error(QSerialPort::SerialPortError error)
{ {
//关闭串口 //关闭串口
this->serial_->close(); this->serial_->close();
this->ErrorSignals("串口异常退出,疑似接口松动;10秒后自动尝试重连..."); emit this->ErrorSignals("串口异常退出,疑似接口松动;10秒后自动尝试重连...");
emit this->openComSuccess(false); emit this->openComSuccess(false);
this->timer_.start(10*1000); this->timer_.start(10*1000);
} }