From 7d33939aa184976c2f6ba579100bbb17dc898223 Mon Sep 17 00:00:00 2001 From: seiyu Date: Fri, 5 Jan 2024 17:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8D=A2=E7=8F=AD=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0xml=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=AD=A3=E5=9C=A8=E5=B0=9D=E8=AF=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?InternetWriteFile=E7=BC=96=E5=86=99=EF=BC=8C=E8=BF=98=E6=9C=AA?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cigarette/exportData.cpp | 91 +++++++++++++++++++++------------------- Cigarette/workthread.cpp | 26 ++++++------ 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/Cigarette/exportData.cpp b/Cigarette/exportData.cpp index d24b493..8944068 100644 --- a/Cigarette/exportData.cpp +++ b/Cigarette/exportData.cpp @@ -10,11 +10,9 @@ #pragma comment(lib, "Wininet.lib") Cigarette* cg; -//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue; extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue; extern ConfPath g_conf_path; extern bool flag; -//extern FtpManager ftpManager; ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent) { @@ -68,8 +66,6 @@ void ExportDataThread::start_work() void ExportDataThread::stop() { b_quit = true; - //_ExportDataInfo data; - //export_Data_Info_queue->put(data); _XMLExportDataInfo data; export_XMLData_Info_queue->put(data); InternetCloseHandle(hftp); @@ -225,8 +221,6 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& dat void ExportDataThread::run() { while (!b_quit) { - //_ExportDataInfo element; - //export_Data_Info_queue->take(element); _XMLExportDataInfo element; export_XMLData_Info_queue->take(element); @@ -237,38 +231,8 @@ void ExportDataThread::run() QString filePath = g_conf_path.config_path + "/" + xmlPath; sprintf(buf, filePath.toLocal8Bit().constData(), element.cameraId); insertXMLNode(buf, element); - QString remotePath = "/tmp1/" + xmlPath; + QString remotePath = "/tmp/" + xmlPath; ConnectServer(filePath, remotePath); - - QDateTime now_ts = QDateTime::currentDateTime(); - for (int index = 0; index < element.shotCounts; index++) { - // 上传ALL - QString all_folder = g_conf_path.save_pics_path + "/ALL/" - + now_ts.toString("yyyy-MM-dd") + "/" - + QString::number(element.cameraId + 1) + "/" + QString::number(index + 1); - QString all_folder_remote = "./image/ALL/" - + now_ts.toString("yyyy-MM-dd") + "/" - + QString::number(element.cameraId + 1) + "/" + QString::number(index + 1) + "/"; - ConnectServer(all_folder, all_folder_remote); - - // 上传ng - QString ng_folder = g_conf_path.save_pics_path + "/ng/" - + now_ts.toString("yyyy-MM-dd") + "/" - + QString::number(element.cameraId + 1) + "/" + QString::number(index + 1); - QString ng_folder_remote = "./image/ng/" - + now_ts.toString("yyyy-MM-dd") + "/" - + QString::number(element.cameraId + 1) + "/" + QString::number(index + 1) + "/"; - ConnectServer(ng_folder, ng_folder_remote); - - // 上传ng_result - QString ng_result_folder = g_conf_path.save_pics_path + "/ng_result/" - + now_ts.toString("yyyy-MM-dd") + "/" - + QString::number(element.cameraId + 1) + "/" + QString::number(index + 1); - QString ng_result_folder_remote = "./image/ng_result/" - + now_ts.toString("yyyy-MM-dd") + "/" - + QString::number(element.cameraId + 1) + "/" + QString::number(index + 1) + "/"; - ConnectServer(ng_result_folder, ng_result_folder_remote); - } } } @@ -322,21 +286,22 @@ void ExportDataThread::ConnectServer(QString srcPath, QString destPath) { // 上传文件源为一个文件 if (size == 0) { - int pos = filePath.find_last_of('/'); - string destFileName = filePath.substr(pos + 1); - check_save_dir(remotePath); + int pos = remotePath.find_last_of('/'); + string destFileName = remotePath.substr(pos + 1); + string tempPath = remotePath.substr(0, pos + 1); + check_save_dir(tempPath); if (!FtpPutFileA(hftp, filePath.c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) - qDebug() << "ftp put file failed because" << dw; + qDebug() << "ftp put file failed because" << dw; } // 上传源为一个文件夹 else{ for (int i = 0; i < size; i++) { - string tempFilePath = files[i].c_str(); + string tempFilePath = (string(files[i]).erase(0, filePath.length() + 1)).c_str(); // 获取上传路径中的文件名 int pos = tempFilePath.find_last_of('/'); string destFileName = tempFilePath.substr(pos + 1); - check_save_dir(remotePath + tempFilePath.substr(0,pos+1)); - if(!FtpPutFileA(hftp, tempFilePath.c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) + check_save_dir(remotePath + tempFilePath.substr(0, pos + 1)); + if(!FtpPutFileA(hftp, files[i].c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) qDebug() << "ftp put files failed because " << dw; } } @@ -367,4 +332,42 @@ void ExportDataThread::GetFiles(string path, std::vector& files) { } while (_findnext(hFile, &fileinfo) == 0); _findclose(hFile); } +} + +BOOL ExportDataThread::FtpUploadPic(uchar *buffer, string remotePath) { + DWORD dwBytesReturn = 0; + DWORD UploadDataSize = 0; + BYTE* pUploadData = NULL; + DWORD dwRet, bRet = 0; + string tempFile = "temp.jpg"; + + HINTERNET hFtpFile = NULL; + hFtpFile = FtpOpenFileA(hftp, remotePath.c_str(), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, NULL); + + // 打开文件 + HANDLE hFile = CreateFileA(tempFile.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL); + if (INVALID_HANDLE_VALUE == hFile) { + qDebug() << "CreateFile error because " << GetLastError(); + CloseHandle(hFile); + return FALSE; + } + + /// -> 以下的代码还未改好 + // 获取文件大小 + UploadDataSize = GetFileSize(hFile, NULL); + pUploadData = new BYTE[UploadDataSize]; + // 读取文件到缓冲区 + ReadFile(hFile, pUploadData, UploadDataSize, &dwRet, NULL); + UploadDataSize = dwRet; + + // 开始上传数据 + bRet = InternetWriteFile(hFtpFile, buffer, UploadDataSize, &dwBytesReturn); + if (FALSE == bRet) { + qDebug() << "InternetWirteFile error because " << GetLastError(); + delete[] buffer; + return FALSE; + } + delete[] buffer; + CloseHandle(hFile); + return TRUE; } \ No newline at end of file diff --git a/Cigarette/workthread.cpp b/Cigarette/workthread.cpp index b00cd6e..27ffadb 100644 --- a/Cigarette/workthread.cpp +++ b/Cigarette/workthread.cpp @@ -7,13 +7,11 @@ #include #include "exportData.h" #include -//#include extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法 extern ConfPath g_conf_path; extern SysConf g_sys_conf; //系统配置参数 extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras]; -//extern FtpManager ftpManager; extern ExportDataThread exportDataThread; extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度 @@ -22,7 +20,6 @@ extern bool isNeedRotate[NumberOfSupportedCameras]; extern SyncQueue >* g_save_queue; //图片保存队列 extern SyncQueue >* g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张 extern SyncQueue<_UDPSendInfo>* UDP_Info_queue; -//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue; extern PLCDevice* m_PLCDevice; extern bool g_debug_mode; @@ -88,9 +85,6 @@ void WorkThread::run() UDPSendInfo.FrameID = info_frame; UDPSendInfo.index = local_camera_number; - //_ExportDataInfo exportDataInfo; - //exportDataInfo.cameraId = local_camera_number; - if (!image.data) { continue; //图像为空,跳过 @@ -101,7 +95,6 @@ void WorkThread::run() } if (local_SysConf.shoot[local_camera_number] == unit_count) { - //exportDataInfo.shotCounts = unit_count; std::vector vec_in; int w = image.cols; int h = image.rows / unit_count; @@ -134,7 +127,6 @@ void WorkThread::run() int time_process = ts_start.msecsTo(ts_jd); emit display_timecost(local_camera_number, time_process); UDPSendInfo.timecost = QString::number(time_process); - //exportDataInfo.timeCost = QString::number(time_process).toStdString(); cv::Mat image1; cv::Mat image2; @@ -142,8 +134,6 @@ void WorkThread::run() QString jd_no; for (int index = 0; index < unit_count; index++) { jd_no += QString::number(vec_results[index].size()) + ","; - //exportDataInfo.jd[index] = vec_results[index].size(); - //exportDataInfo.isJdExist[index] = vec_results[index].size() > 0; } jd_no.chop(1); emit display_jd_no(local_camera_number, jd_no); @@ -177,8 +167,19 @@ void WorkThread::run() + QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) + "#" + "_" + QString::number(index + 1) + ".jpg"; + std::string filename = file_name.toLocal8Bit().constData(); + g_save_queue->put(std::make_pair(filename, m)); + + std::size_t pos = filename.find_first_of("/"); + std::string tempPath = filename.substr(pos + 1); + pos = tempPath.find_first_of("/"); + tempPath = tempPath.substr(pos + 1); + std::string remote_file_name = "/image/" + tempPath; - g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); + //if (m.data) + //{ + // BOOL bRet = exportDataThread.FtpUploadPic(m.data, remote_file_name); + //} } } @@ -214,7 +215,6 @@ void WorkThread::run() #endif } result_index++; - //exportDataInfo.isNg = IsNG; if (!IsNG) { @@ -249,6 +249,7 @@ void WorkThread::run() ".jpg"; g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); //ftpManager.uploadSingleFile(file_name, remotePath); + //exportDataThread.ConnectServer(file_name, remotePath); m = vec_out[index].clone(); @@ -264,7 +265,6 @@ void WorkThread::run() ".jpg"; //g_save_queue->put(std::make_pair(file_name.toStdString(), m)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); - //ftpManager.uploadSingleFile(file_name, remotePath); //exportDataThread.ConnectServer(file_name, remotePath); } }