From 14db1514fec89db599766d4996b4bb1fead0eff0 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 25 八月 2022 17:49:54 +0800
Subject: [PATCH] '完善'

---
 ConsoleApplication/L2DataCapture.cpp |   74 +++++++++++++++++++++---------------
 1 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/ConsoleApplication/L2DataCapture.cpp b/ConsoleApplication/L2DataCapture.cpp
index b2ff06e..4f0910e 100644
--- a/ConsoleApplication/L2DataCapture.cpp
+++ b/ConsoleApplication/L2DataCapture.cpp
@@ -3,6 +3,7 @@
 #include<fstream>
 #include "THSActionUtil.h"
 #include <thread>
+#include "TaskChecker.h"
 bool L2DataCapture::inited;
 bool L2DataCapture::tradeTimeCapture;
 
@@ -13,6 +14,7 @@
 //是否正在执行
 bool L2DataCapture::running;
 bool L2DataCapture::runnings[THS_FRAME_COUNT];
+bool L2DataCapture::killRunnings[THS_FRAME_COUNT];
 clock_t L2DataCapture::latest_running_times[THS_FRAME_COUNT];
 
 CallbackFun L2DataCapture::data_callback;
@@ -40,7 +42,9 @@
 void L2DataCapture::_run(int index)
 {
 	while (true) {
-
+		if (killRunnings[index])
+			break;
+		TaskChecker::clientLiveTime.l2[index] = clock();
 		if (tradeTimeCapture) {
 			int time = getNowSecondTime();
 			//9:20-11:31  12:59-15:01
@@ -134,7 +138,16 @@
 		tradeQueueCapture[i] = new TradeQueueCapture();
 	}
 
-
+	running = false;
+	int length = sizeof(runnings) / sizeof(runnings[0]);
+	for (int i = 0;i < length;i++) {
+		runnings[i] = false;
+		thread rt(&(L2DataCapture::_run), i);
+		rt.detach();
+		killRunnings[i] = FALSE;
+		//thread rt_trade_queue(&(L2DataCapture::_run_trade_queue), i);
+		//rt_trade_queue.detach();
+	}
 
 	//获取同花顺窗口句柄
 	try {
@@ -143,17 +156,18 @@
 	catch (string st) {
 		throw st;
 	}
-	running = false;
-	int length = sizeof(runnings) / sizeof(runnings[0]);
-	for (int i = 0;i < length;i++) {
-		runnings[i] = false;
-		thread rt(&(L2DataCapture::_run), i);
-		rt.detach();
 
-		//thread rt_trade_queue(&(L2DataCapture::_run_trade_queue), i);
-		//rt_trade_queue.detach();
-	}
+}
 
+void L2DataCapture::reCreateChannelRunner(int index)
+{
+	//先杀死原有线程
+	killRunnings[index] = TRUE;
+	Sleep(500);
+	killRunnings[index] = FALSE;
+
+	thread rt(&(L2DataCapture::_run), index);
+	rt.detach();
 }
 
 bool L2DataCapture::isRunning() {
@@ -201,13 +215,15 @@
 
 	clock_t  starttime = clock();
 
-	/*
-	if (1 > 0) {
-	 std:map<string, TradeData> map;
-		return map;
-	}
-	*/
+	list<TradeData> resultList=  captureLevel2TradeData(openCLExcuter[identify], oimg, identify);
 
+	std::cout << "-------L2行情识别结束任务: threadid-" << std::this_thread::get_id() << "  序号:" << identify << " 耗时:" << clock() - starttime  <<"  数据量:"<< resultList.size() << endl;
+
+	return resultList;
+}
+
+list<TradeData> L2DataCapture::captureLevel2TradeData(OpenCLExcuter* openCLExcuter, cv::Mat oimg, int identify)
+{
 
 	//LogUtil::debug("截图完成");
 	clock_t time_1 = clock();
@@ -225,20 +241,20 @@
 	else {
 		if (oimg.channels() == 3)
 		{
-			openCLExcuter[identify]->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData);
+			openCLExcuter->rgb2Gray(oimg.data, oimg.cols, oimg.rows, imgData);
 		}
 		else {
-			openCLExcuter[identify]->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData);
+			openCLExcuter->rgba2Gray(oimg.data, oimg.cols, oimg.rows, imgData);
 		}
 		img.data = imgData;
 		oimg.release();
 		clock_t time_2_ = clock();
 		if (identify == 0)
 		{
-			std::cout << "灰度完成: threadid-" << std::this_thread::get_id() << " 耗时:" << (time_2_ - time_1) << endl;
+			std::cout << "灰度完成: threadid-" << std::this_thread::get_id() << " 耗时:" << (time_2_ - time_1) << "   截图尺寸:" << img.cols << "x" << img.rows << endl;
 
-			std::cout <<"通道数:"<<oimg.channels()<<endl;
-			
+			std::cout << "通道数:" << oimg.channels() << endl;
+
 			LogUtil::debug("灰度完成");
 		}
 	}
@@ -275,7 +291,7 @@
 	}
 	//一维分块图像数据
 	int* rowSplitDataOneLevel = (int*)malloc(sizeof(int) * rowDataList.size() * 4 * 7);
-	openCLExcuter[identify]->splitL2RowData(imgData, img.cols, img.rows, rowDataOneLevel, rowDataList.size(), rowSplitDataOneLevel);
+	openCLExcuter->splitL2RowData(imgData, img.cols, img.rows, rowDataOneLevel, rowDataList.size(), rowSplitDataOneLevel);
 	free(rowDataOneLevel);
 
 	/*
@@ -326,7 +342,7 @@
 	//图像识别(除开数字的部分)
 
 	int* notNumberResult = (int*)malloc(sizeof(int) * rowDataList.size() * 3);
-	openCLExcuter[identify]->recognitionNotNum(img.data, img.cols, img.rows, rowSplitDataOneLevel, 7, rowDataList.size(), notNumberResult);
+	openCLExcuter->recognitionNotNum(img.data, img.cols, img.rows, rowSplitDataOneLevel, 7, rowDataList.size(), notNumberResult);
 
 
 	int i = 0;
@@ -453,7 +469,7 @@
 	if (identify == 0)
 		std::cout << "数据准备-0数据准备: threadid-" << std::this_thread::get_id() << " 耗时:" << time_33 - time_32 << "总耗时:" << time_33 - time_1 << endl;
 
-	openCLExcuter[identify]->splitL2Num(imgData, img.cols, img.rows, pos, 4 * rowDataList.size(), zeroData, _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER, totalNumberData);
+	openCLExcuter->splitL2Num(imgData, img.cols, img.rows, pos, 4 * rowDataList.size(), zeroData, _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER, totalNumberData);
 	free(zeroData);
 	free(pos);
 
@@ -475,7 +491,7 @@
 	//准备模板数字
 	uchar* templateNums = (unsigned char*)malloc(sizeof(unsigned char) * (_NUMBER_L2_HEIGHT * rowDataList.size()) * _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER);
 
-	openCLExcuter[identify]->createNumberTemplates(rowDataList.size(), _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER, ImgUtil::numsOneLevel_level2, templateNums);
+	openCLExcuter->createNumberTemplates(rowDataList.size(), _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER, ImgUtil::numsOneLevel_level2, templateNums);
 
 	//ImgUtil::createTemplateNumData(data.size());
 	clock_t time_4 = clock();
@@ -500,7 +516,7 @@
 
 
 	//数字识别
-	uchar** numberResult = openCLExcuter[identify]->recognition_numbers(totalNumberData, templateNums, rowDataList.size() * _NUMBER_L2_HEIGHT, _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER, _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER);
+	uchar** numberResult = openCLExcuter->recognition_numbers(totalNumberData, templateNums, rowDataList.size() * _NUMBER_L2_HEIGHT, _NUMBER_L2_WIDTH * 10 * _NUMBER_L2_TOTAL_NUMBER, _NUMBER_L2_WIDTH, _NUMBER_L2_HEIGHT, _NUMBER_L2_TOTAL_NUMBER);
 	//释放内存
 	free(totalNumberData);
 	free(templateNums);
@@ -555,10 +571,6 @@
 	rowDataList.clear();
 	list<int*>().swap(rowDataList);
 	free(rowSplitDataOneLevel);
-
-	if (identify == 0)
-		std::cout << "-------L2行情识别结束任务: threadid-" << std::this_thread::get_id() << "  序号:" << identify << " 耗时:" << clock() - starttime << endl;
-
 	return resultList;
 }
 

--
Gitblit v1.8.0