Files
handleaiuinew/HanddleAI/HandleAiUi-new/back/triggerManager.cpp
T

221 lines
8.9 KiB
C++
Raw Normal View History

2024-05-21 23:54:22 +08:00
#include <triggerManager.h>
2024-05-22 01:32:43 +08:00
#include <threadPoolManager.h>
#include <backStruct.h>
2024-05-22 01:32:43 +08:00
#include <cameraManager.h>
2024-08-07 09:16:35 +00:00
#include <uiModule/uiModule_switchProduct.h>
#include <appCore.hpp>
#include <detProcess.hpp>
#include <lightSource.hpp>
#define debugTesting 0
void triggerManager::initialization(detProcess* _detProcessIn)
{
2024-08-07 09:16:35 +00:00
_detProcess = _detProcessIn;
dManager = &_detProcessIn->_detDataManager;
_cameraManager = &_detProcessIn->_cameraManager;
_threadManager = &_detProcessIn->_threadManager;
_lightSourceManager = &_detProcessIn->_lightSourceManager;
2024-08-07 09:16:35 +00:00
startPos = _core._appConfig._triggerStruct.startPos;
triggerFileName = QString::fromStdString(_core._appConfig._triggerStruct.modelName);
IpAndPort = QString::fromStdString(_core._appConfig._triggerStruct.initStr);
readAllCmd = QByteArray::fromStdString(_core._appConfig._triggerStruct.readAllCmd);
triggerFileName = QString::fromStdString(_core._appConfig._triggerStruct.modelName);
sleepTime = _core._appConfig._triggerStruct.sleepTime;
readNum = _core._appConfig._triggerStruct.readNum;
writeType = _core._appConfig._triggerStruct.writeType;
m_lib = new QLibrary(triggerFileName);
libLoadedflag = m_lib->load();
if (!m_lib->isLoaded())
{
2024-08-07 09:16:35 +00:00
emit _core._qtFunc.sendErrorToMainwindow(dllNotFound);
emit _core._qtFunc.sendInitString("找不到" + triggerFileName);
return;
}
2024-08-07 09:16:35 +00:00
}
void triggerManager::connectHost()
{
if (init == true)
return;
if (libLoadedflag)
{
CreateFunction createFun = (CreateFunction)m_lib->resolve("create");
ReleaseFunction releaseFun = (ReleaseFunction)m_lib->resolve("destory");
bool initFailure = false;
if (createFun && releaseFun)
{
trigger = createFun();
destory_finstcp = releaseFun;
2024-08-07 09:16:35 +00:00
QByteArray initByte =
QByteArray::fromStdString
("sleeptime_"+std::to_string(sleepTime)
+ "_readnum_" + std::to_string(readNum)
+ "_writetype_" + writeType);
trigger->reciveData(vec_mat, QByteArray(IpAndPort.toUtf8()));
2024-08-07 09:16:35 +00:00
emit _core._qtFunc.sendInitString(triggerFileName + "连接到" + IpAndPort);
initFailure = trigger->initParas(initByte);
2024-08-07 09:16:35 +00:00
this->start();
}
if (initFailure == false)
{
2024-08-07 09:16:35 +00:00
emit _core._qtFunc.sendErrorToMainwindow(triggerInitFailure);
delete m_lib;
m_lib = nullptr;
2024-08-07 09:16:35 +00:00
emit _core._qtFunc.sendInitString(triggerFileName + "初始化失败");
return;
}
else
{
2024-08-07 09:16:35 +00:00
init = true;
emit _core._qtFunc.sendInitString(triggerFileName + "成功");
}
}
}
2024-08-07 09:16:35 +00:00
void triggerManager::reciveCommond()
{
//auto start = std::chrono::high_resolution_clock::now();
if (!sendFinsMsg(readAllCmd))
qCritical() << "[TCP] " << " finstcp_ptr reciveData error!";
QByteArray readByte;
if (!reciveFinsMsg(readByte))
qCritical() << "[TCP] " << " finstcp_ptr sendData error!";
tLocker.reFreshLocker(readByte);//经过检查后再触发
//auto end = std::chrono::high_resolution_clock::now();
//auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
//std::cout << "cost: " << duration.count() << " mm" << std::endl;
decodeCameraCMD(readByte);
//workThread->snDatas.checkSnFromWaittingVec(readByte);
}
2024-05-21 23:54:22 +08:00
void triggerManager::decodeCameraCMD(QByteArray byte)
{
2024-05-23 15:06:03 +08:00
#if debugTesting
2024-08-07 09:16:35 +00:00
//{
correctionData = new correctionStruct();
//correctionData->in_X_X0Y = { 536.37,657.3,351.32 };
//correctionData->in_Y_X0Y = { -1383.29,-1234.18,-1242.13 };
//correctionData->in_Z_X0Y = { -131.51,-131.51,-131.51 };
//correctionData->in_Z_X0Y_Value = { -78.6552,-78.6552,-78.6552 };
//correctionData->in_X_X0Z = { 615.24,191.31,191.5 };
//correctionData->in_Y_X0Z = { -372.66,-372.66,-372.66 };
//correctionData->in_Z_X0Z = { -925.76,-928.33,-1001.64 };
//correctionData->in_Y_X0Z_Value = { -79.4859,-79.4859,-79.4859 };
//correctionData->in_X_Y0Z = { -213.89,-213.89,-213.89 };
//correctionData->in_Y_Y0Z = { -1006.12,-1083.8,-1005.4 };
//correctionData->in_Z_Y0Z = { -602.89,-620.53,-740.52 };
//correctionData->in_X_Y0Z_Value = { 80.9952,80.9952,80.9952 };
correctionData->in_X_X0Y = { 536.37,657.3,351.32 };
correctionData->in_Y_X0Y = {-1383.29,-1234.18,-1242.13 };
correctionData->in_Z_X0Y = { -131.51,-130.61,-130.66 };
correctionData->in_Z_X0Y_Value = { -78.6552,-82.3836,-83.4522 };
correctionData->in_X_X0Z = { 615.24,191.31,191.5};
correctionData->in_Y_X0Z = { -372.66,-370.9,-370.18};
correctionData->in_Z_X0Z = { -925.76,-928.33,-1001.64 };
correctionData->in_Y_X0Z_Value = { -79.4859,-79.4859,-79.8369};
correctionData->in_X_Y0Z = { -213.89,-209.83,-212.4 };
correctionData->in_Y_Y0Z = { -1006.12,-1083.8,-1005.4 };
correctionData->in_Z_Y0Z = { -602.89,-620.53,-740.52 };
correctionData->in_X_Y0Z_Value = { 80.9952,84.006,81.1005 };
// correctionData = new correctionStruct();
//correctionData->in_X_X0Y = { -258.71,-447.8,-447.2 };
//correctionData->in_Y_X0Y = { -1099.67,-1133.42,-938.83 };
//correctionData->in_Z_X0Y = { 711.77,711.62,711.730000 };
//correctionData->in_Z_X0Y_Value = { 63.9795,64.5333,65.859300 };
//correctionData->in_X_X0Z = { -402.3,-455.91,-236.75 };
//correctionData->in_Y_X0Z = { -539.46,-536.21,-536.2 };
//correctionData->in_Z_X0Z = { -418.88,425.12,425.13 };
//correctionData->in_Y_X0Z_Value = { 118.15,-228.19,-256.5 };
//correctionData->in_X_Y0Z = { 395.250000,395.23,328.34 };
//correctionData->in_Y_Y0Z = { -1147.29,-1147.28,-940.82 };
//correctionData->in_Z_Y0Z = { 118.15,-228.19,-256.5 };
//correctionData->in_X_Y0Z_Value = { -36.652200,-36.7302,41.0436 };
std::shared_ptr <detData> data = dManager->insertDetData("181964", "TEST", 0, 0);
data->_productDataStruct = _appConfig->productDatas[0];
data->imgAmountMin = 0;
data->correctionData = correctionData;
_threadManager->addTask(data);//添加任务
correctionData = nullptr;
//}
2024-05-22 01:32:43 +08:00
//if (checkTrigger(1, 2, byte) == true)
{
2024-05-27 00:22:42 +08:00
//std::shared_ptr <detData> data = dManager->insertDetData("Camera1" , "TEST", 0 , 0);
//data->correctionData = correctionData;
//_threadManager->addTask(data);//添加任务
//auto camera = _cameraManager->getCamera("123");
//if(camera != nullptr)
// camera->captureImage(data);
2024-05-22 01:32:43 +08:00
}
//if (checkTrigger(2, 2, byte) == true)
{
2024-08-07 09:16:35 +00:00
//std::shared_ptr <detData> data = dManager->insertDetData("Camera1", "TEST", 1, 1);
//data->correctionData = correctionData;
//data->oriImgs.push_back(cv::imread("E://Cisco2-2024//TestImg//HFFGG6534_1_1_Battlestar20240326_180201.bmp",-1));
//_threadManager->addTask(data);//添加任务
2024-05-27 00:22:42 +08:00
//auto camera = _cameraManager->getCamera("123");
//if (camera != nullptr)
// camera->captureImage(data);
2024-05-22 01:32:43 +08:00
}
2024-08-07 09:16:35 +00:00
//auto camera = _cameraManager->getCamera("181964");
//if (camera != nullptr)
// camera->trigger();
//double rangeData = _cameraManager->cameras.find("181964")->second->getCameraValue();
QThread::msleep(10000000);
2024-05-22 01:32:43 +08:00
return;
2024-05-23 15:06:03 +08:00
#endif
#if debugTesting == 0
if (byte.isEmpty())
return;
double cameraData = 0;
2024-08-07 09:16:35 +00:00
//算法测试
#if 0
if (checkTrigger(1, 1, byte) == true)
{
2024-08-07 09:16:35 +00:00
correctionData = new correctionStruct();
correctionData->in_X_X0Y = { -258.71,-447.8,-447.2 };
correctionData->in_Y_X0Y = { -1099.67,-1133.42,-938.83 };
correctionData->in_Z_X0Y = { 711.77,711.62,711.730000 };
correctionData->in_Z_X0Y_Value = { 63.9795,64.5333,65.859300 };
correctionData->in_X_X0Z = { -402.3,-455.91,-236.75 };
correctionData->in_Y_X0Z = { -539.46,-536.21,-536.2 };
correctionData->in_Z_X0Z = { -418.88,425.12,425.13 };
correctionData->in_Y_X0Z_Value = { 118.15,-228.19,-256.5 };
correctionData->in_X_Y0Z = { 395.250000,395.23,328.34 };
correctionData->in_Y_Y0Z = { -1147.29,-1147.28,-940.82 };
correctionData->in_Z_Y0Z = { 118.15,-228.19,-256.5 };
correctionData->in_X_Y0Z_Value = { -36.652200,-36.7302,41.0436 };
2024-05-22 16:47:14 +08:00
std::shared_ptr <detData> data = dManager->insertDetData("Camera1", "correctionDataThread", "TEST", 0);
data->correctionData = correctionData;
2024-05-22 01:32:43 +08:00
_threadManager->addTask(data);//添加任务
correctionData = nullptr;
2024-08-07 09:16:35 +00:00
}
2024-08-07 09:16:35 +00:00
#endif
#endif
2024-08-07 09:16:35 +00:00
checkCallbackAndTrigger(byte);
}
2024-05-22 01:32:43 +08:00
int triggerManager::getValue(int dmPos, QByteArray byte)
{
2024-08-07 09:16:35 +00:00
int triggerPos = (dmPos - startPos) * 2;
if (byte.size() < triggerPos)
2024-05-22 01:32:43 +08:00
return false;
int val1 = byte.at(triggerPos) * 256;
int val2 = static_cast<unsigned char>(byte.at(triggerPos + 1));
return val1 + val2;
}