实现换班上传xml文件,传图片正在尝试使用InternetWriteFile编写,还未实现

main
seiyu 1 year ago
parent 2020f6a810
commit 7d33939aa1

@ -10,11 +10,9 @@
#pragma comment(lib, "Wininet.lib") #pragma comment(lib, "Wininet.lib")
Cigarette* cg; Cigarette* cg;
//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue; extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
extern ConfPath g_conf_path; extern ConfPath g_conf_path;
extern bool flag; extern bool flag;
//extern FtpManager ftpManager;
ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent) ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
{ {
@ -68,8 +66,6 @@ void ExportDataThread::start_work()
void ExportDataThread::stop() void ExportDataThread::stop()
{ {
b_quit = true; b_quit = true;
//_ExportDataInfo data;
//export_Data_Info_queue->put(data);
_XMLExportDataInfo data; _XMLExportDataInfo data;
export_XMLData_Info_queue->put(data); export_XMLData_Info_queue->put(data);
InternetCloseHandle(hftp); InternetCloseHandle(hftp);
@ -225,8 +221,6 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& dat
void ExportDataThread::run() void ExportDataThread::run()
{ {
while (!b_quit) { while (!b_quit) {
//_ExportDataInfo element;
//export_Data_Info_queue->take(element);
_XMLExportDataInfo element; _XMLExportDataInfo element;
export_XMLData_Info_queue->take(element); export_XMLData_Info_queue->take(element);
@ -237,38 +231,8 @@ void ExportDataThread::run()
QString filePath = g_conf_path.config_path + "/" + xmlPath; QString filePath = g_conf_path.config_path + "/" + xmlPath;
sprintf(buf, filePath.toLocal8Bit().constData(), element.cameraId); sprintf(buf, filePath.toLocal8Bit().constData(), element.cameraId);
insertXMLNode(buf, element); insertXMLNode(buf, element);
QString remotePath = "/tmp1/" + xmlPath; QString remotePath = "/tmp/" + xmlPath;
ConnectServer(filePath, remotePath); 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) { if (size == 0) {
int pos = filePath.find_last_of('/'); int pos = remotePath.find_last_of('/');
string destFileName = filePath.substr(pos + 1); string destFileName = remotePath.substr(pos + 1);
check_save_dir(remotePath); 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)) 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{ else{
for (int i = 0; i < size; i++) { 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('/'); int pos = tempFilePath.find_last_of('/');
string destFileName = tempFilePath.substr(pos + 1); string destFileName = tempFilePath.substr(pos + 1);
check_save_dir(remotePath + tempFilePath.substr(0,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)) if(!FtpPutFileA(hftp, files[i].c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0))
qDebug() << "ftp put files failed because " << dw; qDebug() << "ftp put files failed because " << dw;
} }
} }
@ -367,4 +332,42 @@ void ExportDataThread::GetFiles(string path, std::vector<string>& files) {
} while (_findnext(hFile, &fileinfo) == 0); } while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile); _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;
} }

@ -7,13 +7,11 @@
#include <PLCDevice.h> #include <PLCDevice.h>
#include "exportData.h" #include "exportData.h"
#include <QMap> #include <QMap>
//#include <ftpManager.h>
extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法 extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
extern ConfPath g_conf_path; extern ConfPath g_conf_path;
extern SysConf g_sys_conf; //系统配置参数 extern SysConf g_sys_conf; //系统配置参数
extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras]; extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
//extern FtpManager ftpManager;
extern ExportDataThread exportDataThread; extern ExportDataThread exportDataThread;
extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度 extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度
@ -22,7 +20,6 @@ extern bool isNeedRotate[NumberOfSupportedCameras];
extern SyncQueue<std::pair<std::string, cv::Mat> >* g_save_queue; //图片保存队列 extern SyncQueue<std::pair<std::string, cv::Mat> >* g_save_queue; //图片保存队列
extern SyncQueue<std::pair<int, cv::Mat> >* g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张 extern SyncQueue<std::pair<int, cv::Mat> >* g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
extern SyncQueue<_UDPSendInfo>* UDP_Info_queue; extern SyncQueue<_UDPSendInfo>* UDP_Info_queue;
//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
extern PLCDevice* m_PLCDevice; extern PLCDevice* m_PLCDevice;
extern bool g_debug_mode; extern bool g_debug_mode;
@ -88,9 +85,6 @@ void WorkThread::run()
UDPSendInfo.FrameID = info_frame; UDPSendInfo.FrameID = info_frame;
UDPSendInfo.index = local_camera_number; UDPSendInfo.index = local_camera_number;
//_ExportDataInfo exportDataInfo;
//exportDataInfo.cameraId = local_camera_number;
if (!image.data) if (!image.data)
{ {
continue; //图像为空,跳过 continue; //图像为空,跳过
@ -101,7 +95,6 @@ void WorkThread::run()
} }
if (local_SysConf.shoot[local_camera_number] == unit_count) if (local_SysConf.shoot[local_camera_number] == unit_count)
{ {
//exportDataInfo.shotCounts = unit_count;
std::vector<cv::Mat> vec_in; std::vector<cv::Mat> vec_in;
int w = image.cols; int w = image.cols;
int h = image.rows / unit_count; int h = image.rows / unit_count;
@ -134,7 +127,6 @@ void WorkThread::run()
int time_process = ts_start.msecsTo(ts_jd); int time_process = ts_start.msecsTo(ts_jd);
emit display_timecost(local_camera_number, time_process); emit display_timecost(local_camera_number, time_process);
UDPSendInfo.timecost = QString::number(time_process); UDPSendInfo.timecost = QString::number(time_process);
//exportDataInfo.timeCost = QString::number(time_process).toStdString();
cv::Mat image1; cv::Mat image1;
cv::Mat image2; cv::Mat image2;
@ -142,8 +134,6 @@ void WorkThread::run()
QString jd_no; QString jd_no;
for (int index = 0; index < unit_count; index++) { for (int index = 0; index < unit_count; index++) {
jd_no += QString::number(vec_results[index].size()) + ","; 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); jd_no.chop(1);
emit display_jd_no(local_camera_number, jd_no); 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) + "/" + + 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) + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".jpg"; "#" + "_" + 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 #endif
} }
result_index++; result_index++;
//exportDataInfo.isNg = IsNG;
if (!IsNG) if (!IsNG)
{ {
@ -249,6 +249,7 @@ void WorkThread::run()
".jpg"; ".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
//ftpManager.uploadSingleFile(file_name, remotePath); //ftpManager.uploadSingleFile(file_name, remotePath);
//exportDataThread.ConnectServer(file_name, remotePath); //exportDataThread.ConnectServer(file_name, remotePath);
m = vec_out[index].clone(); m = vec_out[index].clone();
@ -264,7 +265,6 @@ void WorkThread::run()
".jpg"; ".jpg";
//g_save_queue->put(std::make_pair(file_name.toStdString(), m)); //g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
//ftpManager.uploadSingleFile(file_name, remotePath);
//exportDataThread.ConnectServer(file_name, remotePath); //exportDataThread.ConnectServer(file_name, remotePath);
} }
} }

Loading…
Cancel
Save