更新数据上传
This commit is contained in:
parent
556c025d88
commit
0be507724f
|
@ -89,8 +89,10 @@ void TcpClient::connectToServer(QString ip, int port) {
|
|||
{
|
||||
// 来车
|
||||
emit this->comeTrainSignals(true);
|
||||
if (jsonObject["direction"].toInt(0) != 0) emit this->getDirectionSignals(jsonObject["direction"].toInt(0));
|
||||
come_time = jsonObject["cometime"].toString();
|
||||
carType = jsonObject["type"].toString();
|
||||
// direction = jsonObject["direction"].toBool(false);
|
||||
}
|
||||
else if (jsonObject["type"].toString() != carType && carType == "1")
|
||||
{
|
||||
|
@ -99,6 +101,12 @@ void TcpClient::connectToServer(QString ip, int port) {
|
|||
come_time = jsonObject["cometime"].toString();
|
||||
carType = jsonObject["type"].toString();
|
||||
}
|
||||
|
||||
if (jsonObject["type"].toString() == carType && jsonObject["direction"].toInt(0) != 0)
|
||||
{
|
||||
// 判断出火车方向
|
||||
emit this->getDirectionSignals(jsonObject["direction"].toInt(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@ private:
|
|||
int port_;
|
||||
|
||||
QString carType = "0";
|
||||
QString direction = "0";
|
||||
bool direction = false;
|
||||
QString come_time = "";
|
||||
|
||||
bool exit_flag = false; // 退出标记
|
||||
|
@ -33,6 +33,7 @@ public slots:
|
|||
|
||||
signals:
|
||||
void comeTrainSignals(bool type);
|
||||
void getDirectionSignals(int direction);
|
||||
void sendTcpInfoSignals(QString info);
|
||||
void socketComplete(QTcpSocket* tcp, QString ip, quint16 port); // tcp句柄发送给主线程监管
|
||||
void restartSocket(QString ip, int port); //重启Socket连接
|
||||
|
|
|
@ -126,7 +126,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
emit connect_socket(this->socketServerConfig_.server_ip, this->socketServerConfig_.server_port);
|
||||
|
||||
connect(this->tcpClient, &TcpClient::comeTrainSignals, this, [=](bool type){
|
||||
connect(this->tcpClient, &TcpClient::comeTrainSignals, this, [=](bool type) {
|
||||
if (type)
|
||||
{
|
||||
this->logInfo("视频车号识别-来车了");
|
||||
|
@ -141,9 +141,53 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
emit IdentifyType();
|
||||
}
|
||||
});
|
||||
connect(this->tcpClient, &TcpClient::getDirectionSignals, this, [=](int direction) {
|
||||
if (this->iDirection != direction)
|
||||
{
|
||||
this->logInfo("获得方向判定:" + QString(direction > -1 ? (direction > 0 ? "需识别" : "待定") : "无需上传"));
|
||||
this->iDirection = direction;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui->openComButton->click();
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -178,6 +222,7 @@ void MainWindow::initParam() {
|
|||
this->needIdentify = false;
|
||||
this->rnameRfidLog();
|
||||
this->queue_.clear();
|
||||
this->iDirection = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -357,21 +402,17 @@ QStandardItem* MainWindow::getStandardItem(const QString &value)
|
|||
* @return: 成功:true
|
||||
* 失败:false
|
||||
*/
|
||||
bool MainWindow::upWeb(std::string &carriageType,
|
||||
std::string &carriageNumber,
|
||||
std::string &carriageOrder,
|
||||
std::string &time,
|
||||
std::string &strRfidInfo)
|
||||
bool MainWindow::upWeb(TrainInfo &trainInfo)
|
||||
{
|
||||
try {
|
||||
Json::Value arrayObj; //构建对象
|
||||
|
||||
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;
|
||||
arrayObj["steel"] = strRfidInfo;
|
||||
arrayObj["comeTime"] = trainInfo.trainTime;
|
||||
arrayObj["collectTime"] = trainInfo.collectTime;
|
||||
arrayObj["carriageNumber"] = trainInfo.carriageNum;
|
||||
arrayObj["carriageType"] = trainInfo.carriageType;
|
||||
arrayObj["carriageOrder"] = trainInfo.strOrder;
|
||||
// arrayObj["steel"] = trainInfo.strRfidInfo;
|
||||
|
||||
Json::Value trainParams;
|
||||
trainParams["poundNo"] = std::to_string(this->baseConfig_.trackName);
|
||||
|
@ -379,22 +420,23 @@ bool MainWindow::upWeb(std::string &carriageType,
|
|||
Json::StreamWriterBuilder writer;
|
||||
std::string str = Json::writeString(writer, arrayObj);
|
||||
|
||||
this->logInfo("第" + QString::fromStdString(carriageOrder) + "节,发送web: " + QString::fromStdString(str));
|
||||
|
||||
this->logInfo("第" + QString::fromStdString(trainInfo.strOrder) + "节,发送web: " + QString::fromStdString(str));
|
||||
httplib::Client cli(this->interfaceConfig_.httpIp.toStdString(), this->interfaceConfig_.httpPort);
|
||||
cli.set_connection_timeout(0, 300 * 1000);
|
||||
cli.set_read_timeout(1,0);
|
||||
|
||||
cli.set_connection_timeout(3, 0);
|
||||
cli.set_read_timeout(0, 700 * 1000);
|
||||
httplib::Headers header;
|
||||
httplib::Params params;
|
||||
header.emplace("blade-auth", this->webToken);
|
||||
//header.emplace("Content-Type", "application/json");
|
||||
|
||||
auto res = cli.Post(this->interfaceConfig_.upResultPath.toStdString(), header, str, "application/json");
|
||||
|
||||
if (res)
|
||||
{
|
||||
if (res->status == 200)
|
||||
{
|
||||
this->logInfo("第" + QString::fromStdString(carriageOrder) + "节,web返回: " + QString::fromStdString(res->body));
|
||||
this->logInfo("第" + QString::fromStdString(trainInfo.strOrder) + "节,web返回: " + QString::fromStdString(res->body));
|
||||
Json::CharReaderBuilder readerBuilder;
|
||||
std::istringstream iss(res->body);
|
||||
Json::Value root;
|
||||
|
@ -410,37 +452,36 @@ bool MainWindow::upWeb(std::string &carriageType,
|
|||
{
|
||||
|
||||
if (root["msg"].asString() == "请求未授权") {
|
||||
this->logWarn("第" + QString::fromStdString(carriageOrder) + "节,因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
this->logWarn("第" + QString::fromStdString(trainInfo.strOrder) + "节,因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
if (!this->getToken()) return false;
|
||||
return this->upWeb(carriageType, carriageNumber, carriageOrder, time, strRfidInfo);
|
||||
return this->upWeb(trainInfo);
|
||||
}
|
||||
this->logError("---");
|
||||
this->logError("第" + QString::fromStdString(carriageOrder) + "节,识别结果上传失败,原因:" + QString::fromStdString(root["msg"].asString()));
|
||||
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::fromStdString(root["msg"].asString()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->logError("第" + QString::fromStdString(carriageOrder) + "节,识别结果上传失败,返回数据解析异常,返回数据非json:" + QString::fromStdString(res->body));
|
||||
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,返回数据解析异常,返回数据非json:" + QString::fromStdString(res->body));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->logError("第" + QString::fromStdString(carriageOrder) + "节,识别结果上传失败,原因:" + QString::number(res->status) + " - " + QString::fromStdString(res->body));
|
||||
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败,原因:" + QString::number(res->status) + " - " + QString::fromStdString(res->body));
|
||||
if (res->status == 401) {
|
||||
this->logWarn("因请求未授权,而上传识别结果失败!重新请求token。");
|
||||
this->getToken();
|
||||
return this->upWeb(carriageType, carriageNumber, carriageOrder, time, strRfidInfo);
|
||||
return this->upWeb(trainInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->logError("第" + QString::fromStdString(carriageOrder) + "节,上传数据失败,请检查网络,或者上传地址!");
|
||||
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传数据失败,请检查网络,或者上传地址!");
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
this->logError("第" + QString::fromStdString(carriageOrder) + "节,上传识别结果失败,原因:");
|
||||
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,上传识别结果失败,原因:");
|
||||
this->logError(e.what());
|
||||
}
|
||||
return false;
|
||||
|
@ -642,14 +683,15 @@ void MainWindow::openComClicked()
|
|||
logs.append("串口打开成功\n");
|
||||
logs.append("串口号:" + ui->comBox->currentText() + "\n");
|
||||
logs.append("波特率:" + ui->BTBox->currentText() + "\n");
|
||||
logs.append("磁钢顺序:" + this->baseConfig_.magnetSteelOrder);
|
||||
if (this->baseConfig_.havaMagnetSteel)
|
||||
logs.append("磁钢顺序:" + this->baseConfig_.magnetSteelOrder);
|
||||
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);");
|
||||
connect(this->serial_,&QSerialPort::readyRead,this,&MainWindow::readCom);
|
||||
connect(this->serial_,&QSerialPort::readyRead,this,&MainWindow::readCom); //
|
||||
|
||||
connect(this->serial_, &QSerialPort::errorOccurred, this, &MainWindow::serialPort_error);
|
||||
|
||||
|
@ -712,9 +754,13 @@ void MainWindow::readCom()
|
|||
this->queue_.push(QString(data));
|
||||
emit getRfid_signals();
|
||||
}
|
||||
this->serial_->clear();
|
||||
// this->serial_->clear();
|
||||
data.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->logError("等待读取超时");
|
||||
}
|
||||
} catch(...) {
|
||||
this->logError("读取串口数据异常!");
|
||||
}
|
||||
|
@ -844,25 +890,22 @@ void MainWindow::upRfid(QString rfidInfo)
|
|||
trainInfo.carriageType = info.left(6).simplified().toStdString();
|
||||
trainInfo.carriageNum = info.mid(6, info.size() - 6).simplified().toStdString();
|
||||
trainInfo.strOrder = QString::number(order).toStdString();
|
||||
trainInfo.nowTime = this->trainTime.toStdString();
|
||||
trainInfo.trainTime = this->trainTime.toStdString();
|
||||
trainInfo.collectTime = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString();
|
||||
trainInfo.strRfidInfo = rfidInfo.toStdString();
|
||||
|
||||
this->queueTrainInfo_.push(trainInfo);
|
||||
auto up = QtConcurrent::run([=](){
|
||||
// QtConcurrent::run([=](){
|
||||
if ((this->iDirection == 0 && this->queueTrainInfo_.size() <= 4) || this->iDirection < 0) return;
|
||||
while (!this->queueTrainInfo_.isEmpty())
|
||||
{
|
||||
TrainInfo trainInfo = this->queueTrainInfo_.pop();
|
||||
if (!this->upWeb(trainInfo.carriageType,
|
||||
trainInfo.carriageNum,
|
||||
trainInfo.strOrder,
|
||||
trainInfo.nowTime,
|
||||
trainInfo.strRfidInfo))
|
||||
TrainInfo trainInfo_ = this->queueTrainInfo_.pop();
|
||||
if (!this->upWeb(trainInfo_))
|
||||
{
|
||||
this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败!");
|
||||
//this->logError("第" + QString::fromStdString(trainInfo.strOrder) + "节,识别结果上传失败!");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// });
|
||||
}
|
||||
|
||||
void MainWindow::IdentifyTypeUpdate() {
|
||||
|
|
|
@ -70,7 +70,8 @@ public:
|
|||
void logInfo(const QString& message);
|
||||
void logWarn(const QString& message);
|
||||
void logError(const QString& message);
|
||||
|
||||
// 创建日志目录
|
||||
static bool mkLogDir();
|
||||
bool mkRfidLog();
|
||||
void deleteOldFiles(const QString &path, int days);
|
||||
bool rnameRfidLog();
|
||||
|
@ -78,12 +79,7 @@ public:
|
|||
|
||||
void initParam();
|
||||
|
||||
bool upWeb(std::string &carriageType,
|
||||
std::string &carriageNumber,
|
||||
std::string &carriageOrder,
|
||||
std::string &time,
|
||||
std::string &rfidSourceInfo);
|
||||
bool getToken();
|
||||
|
||||
|
||||
QString getSystemTime();
|
||||
|
||||
|
@ -91,8 +87,7 @@ public:
|
|||
QList<QString> getComList();
|
||||
// 将所有串口const 展示在下&拉列表
|
||||
void initComboBox();
|
||||
// 创建日志目录
|
||||
static bool mkLogDir();
|
||||
|
||||
// 获取QStandardItem
|
||||
QStandardItemModel* getStandardItemModel();
|
||||
QStandardItem* getStandardItem(const QString &value);
|
||||
|
@ -102,7 +97,8 @@ private:
|
|||
std::string carriageType;
|
||||
std::string carriageNum;
|
||||
std::string strOrder;
|
||||
std::string nowTime;
|
||||
std::string trainTime;
|
||||
std::string collectTime;
|
||||
std::string strRfidInfo;
|
||||
};
|
||||
QString trainTime;
|
||||
|
@ -139,11 +135,16 @@ private:
|
|||
bool videoHasTrain = false;
|
||||
// RFID识别有火车标志
|
||||
bool rfidHasTrain = false;
|
||||
// 是否是需要识别的方向 -1:不识别 0:未确定 1:识别
|
||||
int iDirection = 0;
|
||||
// 获取当前时间
|
||||
QDateTime currentTime_ = QDateTime::currentDateTime();
|
||||
|
||||
TcpClient* tcpClient;
|
||||
|
||||
bool upWeb(TrainInfo &trainInfo);
|
||||
bool getToken();
|
||||
|
||||
private:
|
||||
QTcpSocket* tcp_ = nullptr;
|
||||
QStatusBar* statusBar;
|
||||
|
|
Loading…
Reference in New Issue