| | |
| | | #endif |
| | | #include "JsonUtil.h" |
| | | #include <exception> |
| | | #include "OcrUtil.h" |
| | | |
| | | |
| | | #ifdef _DEBUG |
| | |
| | | } |
| | | } |
| | | autoMsgStatic.SetWindowTextW(_T("等待打开副屏1...")); |
| | | |
| | | |
| | | for (int i = 0; i < 5; i++) { |
| | | HWND second = THSActionUtil::getSecondWindow(); |
| | | if (second > 0) { |
| | |
| | | THSActionUtil::openSecondScreen(); |
| | | Sleep(1000); |
| | | } |
| | | |
| | | |
| | | autoMsgStatic.SetWindowTextW(_T("副屏1已打开...")); |
| | | Sleep(1000); |
| | | // 开启 涨停识别 |
| | |
| | | CappDlg::OnBnClickedButton12(); |
| | | autoMsgStatic.SetWindowTextW(_T("启动涨停启动成功")); |
| | | |
| | | // 开启委托识别 |
| | | // 开启委托识别 |
| | | |
| | | // 开启交易成功识别 |
| | | // 开启交易成功识别 |
| | | |
| | | |
| | | |
| | |
| | | |
| | | |
| | | void CappDlg::OnL2DataCallback(int index, string code, long captureTime, long processTime, list<TradeData*> dataList, void* context) { |
| | | clock_t time_start = clock(); |
| | | //转为json |
| | | CappDlg* app = (CappDlg*)context; |
| | | //cout << "回调:" << std::this_thread::get_id() << ":" << index << endl; |
| | | CButton* btn = (CButton*)app->GetDlgItem(IDC_CHECK1); |
| | | bool check = btn->GetCheck(); |
| | | if (check) { |
| | | if (index == 0) |
| | | { |
| | | cout << "\n*****状态判断用时*****:" << (clock() - time_start) << endl; |
| | | } |
| | | time_start = clock(); |
| | | string data = JsonUtil::loadL2Data(app->clientNum, index, code, captureTime, processTime, dataList); |
| | | for (list<TradeData*>::iterator el = dataList.begin(); el != dataList.end();++el) { |
| | | for (list<TradeData*>::iterator el = dataList.begin(); el != dataList.end(); ++el) { |
| | | delete (*el); |
| | | } |
| | | dataList.clear(); |
| | | clock_t time_start = clock(); |
| | | if (index == 0) |
| | | { |
| | | cout << "\n*****组装数据处理用时*****:" << (clock() - time_start) << endl; |
| | | } |
| | | |
| | | time_start = clock(); |
| | | try { |
| | | app->socketManager->sendMsg(index, data.c_str()); |
| | | } |
| | |
| | | app->socketManager->resetClient(index); |
| | | app->socketManager->Connect(index); |
| | | } |
| | | //cout << "*****数据处理时间:" << (clock() - time_start) << endl; |
| | | if (index == 0) |
| | | { |
| | | cout << "\n*****服务端数据处理时间*****:" << (clock() - time_start) << endl; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | clock_t time_start = clock(); |
| | | |
| | | try { |
| | | app->socketManager->sendMsg(8, data.c_str()); |
| | | SocketManager::sendMsg(data.c_str()); |
| | | } |
| | | catch (string st) { |
| | | //重新连接服务器 |
| | | app->socketManager->resetClient(8); |
| | | app->socketManager->Connect(8); |
| | | |
| | | } |
| | | |
| | | |
| | | //上传账户可用余额 |
| | | data = JsonUtil::loadAvailableMoney(app->clientNum, money); |
| | | try { |
| | | app->socketManager->sendMsg(8, data.c_str()); |
| | | SocketManager::sendMsg(data.c_str()); |
| | | } |
| | | catch (string st) { |
| | | app->socketManager->resetClient(8); |
| | | app->socketManager->Connect(8); |
| | | } |
| | | |
| | | cout << "####交易成功数据处理时间:" << (clock() - time_start) << endl; |
| | |
| | | //app->onlineCheck.PostMessage(WM_LBUTTONUP, 0, 0); |
| | | RECT rect; |
| | | Win32Util::getWindowRect(app->onlineCheck.m_hWnd, &rect); |
| | | Win32Util::click((rect.left + rect.right )/ 2, (rect.top + rect.bottom) / 2, 10); |
| | | |
| | | Win32Util::click((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2, 10); |
| | | |
| | | } |
| | | else if (action == "repairL2Data") { |
| | | //修正代码与L2行情代码不对应 或者 L2行情无数据的情况 |
| | |
| | | return string(); |
| | | } |
| | | |
| | | list<OCRResult> CappDlg::MatOcr(string key_regex, cv::Mat mat) |
| | | { |
| | | return OcrUtil::mat_ocr(key_regex, mat); |
| | | } |
| | | |
| | | //心跳信号 |
| | | void CappDlg::onHeartbeat() { |
| | | //5s一次心跳 |
| | |
| | | if (!limitUpCapture->isInited()) |
| | | { |
| | | try { |
| | | limitUpCapture->init(OnLimitUpDataCallback, this); |
| | | limitUpCapture->init(OnLimitUpDataCallback, MatOcr, this); |
| | | } |
| | | catch (string st) { |
| | | if (notify) |
| | |
| | | Win32Util::showWindow(l2); |
| | | //初始化l2的各个窗口句柄 |
| | | app->capture->refreshHWND(); |
| | | //选中板块 |
| | | try { |
| | | //THSActionUtil::correctL2ScreenPlate(OcrUtil::mat_ocr); |
| | | } |
| | | catch (string st) { |
| | | |
| | | } |
| | | } |
| | | |
| | | HWND second = THSActionUtil::getSecondWindow(); |
| | |
| | | //将副屏1与副屏2缩小为屏幕的一半 |
| | | Win32Util::moveWin(second, device_pos.x, device_pos.y + device_height / 2, device_width / 2 - 50, device_height / 2); |
| | | Win32Util::moveWin(third, device_pos.x + device_width / 2 + 30, device_pos.y + device_height / 2, device_width / 2 - 50, device_height / 2); |
| | | |
| | | try { |
| | | Sleep(500); |
| | | THSActionUtil::correctL2ScreenPlate(OcrUtil::mat_ocr); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | } |
| | | |
| | | void CappDlg::autoStartL2(void* context) |
| | |
| | | app->socketManager->resetClient(8); |
| | | app->socketManager->Connect(8); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | void CappDlg::autoStartTradeDelegate(void* context) |
| | |
| | | { |
| | | try { |
| | | socketManager->sendMsg(i, "test"); |
| | | scount++; |
| | | |
| | | scount++; |
| | | |
| | | } |
| | | catch (string st) { |
| | | |
| | |
| | | { |
| | | socketManager->sendMsg(i, "test"); |
| | | scount++; |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | void CappDlg::OnBnClickedButton20() |
| | | { |
| | | try { |
| | | THSActionUtil::checkEnv(); |
| | | checkTHSEnv(this); |
| | | AfxMessageBox(_T("检测通过")); |
| | | } |
| | | catch (const string& st) { |
| | |
| | | //启动任务 |
| | | void CappDlg::OnBnClickedButton5() |
| | | { |
| | | //检测环境 |
| | | |
| | | try { |
| | | THSActionUtil::checkEnv(); |
| | | } |
| | | catch (string st) { |
| | | CString msg(st.c_str()); |
| | | AfxMessageBox(msg); |
| | | return; |
| | | } |
| | | |
| | | CButton* btn = (CButton*)GetDlgItem(IDC_BUTTON5); |
| | | |
| | |
| | | } |
| | | } |
| | | if (!capture->isRunning()) { |
| | | |
| | | // 检测环境 |
| | | checkTHSEnv(this); |
| | | |
| | | try { |
| | | map<int, string> result = THSActionUtil::getListenL2GPCodes(recognitionManager); |
| | |
| | | |
| | | //TODO 测试图片切割 |
| | | //THSActionUtil::getListenL2GPAreaActionBar(); |
| | | // 检测同花顺板块是否选中 |
| | | try { |
| | | Sleep(500); |
| | | THSActionUtil::correctL2ScreenPlate(OcrUtil::mat_ocr); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | |
| | | } |
| | | else { |
| | |
| | | if (!limitUpCapture->isInited()) { |
| | | try |
| | | { |
| | | limitUpCapture->init(OnLimitUpDataCallback, this); |
| | | limitUpCapture->init(OnLimitUpDataCallback,MatOcr,this); |
| | | |
| | | } |
| | | catch (string st) |
| | |
| | | AfxMessageBox(msg); |
| | | return; |
| | | } |
| | | //如果已经打开了远航版的交易,就需要点击当日委托 |
| | | try { |
| | | tradeListCapture->selectTradeSuccess(MatOcr); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | |
| | | tradeListCapture->startTradeSuccess(); |
| | | tradeBtn.SetWindowTextW(_T("暂停成交识别任务")); |
| | |
| | | |
| | | //打开同花顺远航版的委托界面 |
| | | HWND win = 0; |
| | | if (win <= 0) { |
| | | //判断是否已经打开了同花顺远航版 |
| | | for (int i = 0; i < 10; i++) |
| | | { |
| | | win = THSActionUtil::getTradeSimpleDelegateWindow(); |
| | | if (win <= 0) |
| | | { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺远航版"); |
| | | if (wlist.size() > 0) { |
| | | HWND mainWin = *(wlist.begin()); |
| | | //按F12 |
| | | Win32Util::sendMessage(mainWin, WM_KEYDOWN, VK_F12, 0); |
| | | Win32Util::sendMessage(mainWin, WM_KEYUP, VK_F12, 0); |
| | | //等待反应 |
| | | Sleep(500); |
| | | } |
| | | else { |
| | | //等待远航版打开 |
| | | Sleep(1000); |
| | | } |
| | | } |
| | | else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //如果已经打开了远航版的交易,就需要点击当日委托 |
| | | try { |
| | | HWND menuWin = TradeListCapture::getSimpleTradeLeftMenu(win); |
| | | if (menuWin > 0) { |
| | | cv::Mat img = CaptureUtil::capture(menuWin); |
| | | string result = JsonUtil::loadOcrData(clientNum, img, "当日委托"); |
| | | result = socketManager->sendMsg(result.c_str()); |
| | | Json::Value root = JsonUtil::parseJson(result); |
| | | if (root["code"] == 0) { |
| | | //图像识别成功 |
| | | Json::Value datas = root["data"]["datas"]; |
| | | Json::Value ps = datas[0]["position"]; |
| | | //position格式:[[0,13],[12,13],[12,15],[0,15]] |
| | | //获取中心点 |
| | | int x = (ps[0][0].asInt() + ps[1][0].asInt()) / 2; |
| | | int y= (ps[0][1].asInt() + ps[2][1].asInt()) / 2; |
| | | RECT rect; |
| | | Win32Util::getWindowRect(menuWin,&rect); |
| | | x = rect.left + x; |
| | | y = rect.top + y; |
| | | //点击 |
| | | Win32Util::click(x,y,10); |
| | | if (win <= 0) { |
| | | //判断是否已经打开了同花顺远航版 |
| | | for (int i = 0; i < 10; i++) |
| | | { |
| | | win = THSActionUtil::getTradeSimpleDelegateWindow(); |
| | | if (win <= 0) |
| | | { |
| | | list<HWND> wlist = Win32Util::searchWindow("同花顺远航版"); |
| | | if (wlist.size() > 0) { |
| | | HWND mainWin = *(wlist.begin()); |
| | | //按F12 |
| | | Win32Util::sendMessage(mainWin, WM_KEYDOWN, VK_F12, 0); |
| | | Win32Util::sendMessage(mainWin, WM_KEYUP, VK_F12, 0); |
| | | //等待反应 |
| | | Sleep(500); |
| | | } |
| | | else { |
| | | //等待远航版打开 |
| | | Sleep(1000); |
| | | } |
| | | } |
| | | else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | } |
| | | |
| | | //如果已经打开了远航版的交易,就需要点击当日委托 |
| | | try { |
| | | tradeListCapture->selectTradeSimpleDelegate(MatOcr); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | tradeListCapture->startTradeDelegate(); |
| | | delegateBtn.SetWindowTextW(_T("暂停委托识别任务")); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //测试按钮 |
| | | void CappDlg::OnBnClickedButtonTest() |
| | | { |
| | | cv::Mat mat = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade\\Snipaste_2023-01-13_18-23-34_gray.png", cv::IMREAD_GRAYSCALE); |
| | | Json::Value array; |
| | | int len = mat.rows * mat.cols; |
| | | for (int i = 0; i < len; i++) { |
| | | array[i] = mat.data[i]; |
| | | } |
| | | Json::Value data; |
| | | data["data"] = array; |
| | | data["width"] = mat.cols; |
| | | data["height"] = mat.rows; |
| | | data["key"] = "当日委托" ; |
| | | Json::Value root; |
| | | root["data"] = data; |
| | | root["type"] = 100; |
| | | string result = JsonUtil::jsonValue2String(root); |
| | | try { |
| | | socketManager->sendMsg(result.c_str()); |
| | | } |
| | | catch (string st) { |
| | | if (1 > 0) { |
| | | //THSActionUtil::correctL2ScreenPlate(MatOcr); |
| | | //如果已经打开了远航版的交易,就需要点击当日委托 |
| | | try { |
| | | THSActionUtil::correctL2ScreenPlate(OcrUtil::mat_ocr); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | |
| | | try { |
| | | THSActionUtil::checkEnv(); |
| | | checkTHSEnv(this); |
| | | } |
| | | catch (string e) { |
| | | //打开同花顺的所有屏幕 |
| | | try { |
| | | THSActionUtil::openL2Screen(); |
| | | THSActionUtil::openSecondScreen(); |
| | | Sleep(1000); |
| | | THSActionUtil::openThirdScreen(); |
| | | Sleep(1000); |
| | | } |
| | | catch (...) { |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | try { |
| | | HWND l2 = THSActionUtil::getL2Win(); |
| | | if (l2 > 0) |
| | | { |
| | | Win32Util::showWindow(l2); |
| | | //初始化l2的各个窗口句柄 |
| | | capture->refreshHWND(); |
| | | } |
| | | |
| | | HWND second = THSActionUtil::getSecondWindow(); |
| | | if (second <= 0) { |
| | | AfxMessageBox(_T("同花顺副屏1未打开")); |
| | | return; |
| | | } |
| | | |
| | | Win32Util::showWindow(second); |
| | | |
| | | |
| | | HWND third = THSActionUtil::getThirdWindow(); |
| | | if (third <= 0) { |
| | | AfxMessageBox(_T("同花顺副屏2未打开")); |
| | | return; |
| | | } |
| | | |
| | | Win32Util::showWindow(third); |
| | | |
| | | |
| | | //设置 |
| | | DEVMODE device = Win32Util::getL2ScreenInfo(); |
| | | int device_width = device.dmPelsWidth; |
| | | int device_height = device.dmPelsHeight; |
| | | POINTL device_pos = device.dmPosition; |
| | | //最大化L2 |
| | | Win32Util::moveWin(l2, device_pos.x, device_pos.y, device_width, device_height); |
| | | //将副屏1与副屏2缩小为屏幕的一半 |
| | | Win32Util::moveWin(second, device_pos.x, device_pos.y + device_height / 2, device_width / 2 - 50, device_height / 2); |
| | | Win32Util::moveWin(third, device_pos.x + device_width / 2 + 30, device_pos.y + device_height / 2, device_width / 2 - 50, device_height / 2); |
| | | } |
| | | catch (string e) { |
| | | CString msg(e.c_str()); |
| | | catch (string st) { |
| | | CString msg(st.c_str()); |
| | | AfxMessageBox(msg); |
| | | return; |
| | | } |
| | | |
| | | |
| | | } |
| | | |