949 lines
25 KiB
C++
949 lines
25 KiB
C++
#include "Logic_hdataprocess.h"
|
|
|
|
HSnData::HSnData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
void HSnData::addSnVector(QVector<QString> snVec)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
stationName;
|
|
if(queue_vector_sn.isEmpty())
|
|
{
|
|
queue_vector_sn.append(snVec);
|
|
}
|
|
else
|
|
{
|
|
QVector<QString> vec_str = queue_vector_sn.last();
|
|
if (!vec_str.isEmpty())
|
|
{
|
|
//if (!vec_str[0].contains(snVec[0])) //demo流程重入检查也可以
|
|
//{
|
|
// queue_vector_sn.append(snVec);
|
|
//}
|
|
/*else
|
|
std::cout << "HSnData::addSnVector err" << std::endl;*/
|
|
}
|
|
}
|
|
}
|
|
|
|
QString HSnData::getSnAndDelete()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if ( queue_vector_sn.isEmpty() )
|
|
{
|
|
QString tmpDate = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz");
|
|
return "nullSnInfo_" + tmpDate;
|
|
}
|
|
else
|
|
{
|
|
QVector<QString> vec_sn = queue_vector_sn.dequeue();
|
|
if (vec_sn.isEmpty())
|
|
{
|
|
QString tmpDate = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz");
|
|
return "nullSnInfo_" + tmpDate;
|
|
}
|
|
else
|
|
{
|
|
return vec_sn.at(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
QVector<QString> HSnData::getFirstValue()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if (queue_vector_sn.isEmpty())
|
|
{
|
|
QVector<QString> sn;
|
|
QString tmpDate = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz");
|
|
sn.append("nullSnInfo_" + tmpDate);
|
|
return sn;
|
|
}
|
|
else
|
|
{
|
|
return queue_vector_sn.first();
|
|
}
|
|
}
|
|
|
|
// -3 删除sn
|
|
bool HSnData::deleteSnData( QString sndata )
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if ( sndata.isEmpty() )
|
|
return false;
|
|
|
|
int delete_index = -1;
|
|
for ( int iii = 0; iii < queue_vector_sn.size(); iii++ )
|
|
{
|
|
if ( sndata == queue_vector_sn.at(iii).at(0) )
|
|
{
|
|
delete_index = iii;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 删除 sn 数据
|
|
if (delete_index != -1)
|
|
{
|
|
queue_vector_sn.removeAt(delete_index);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool HSnData::deleteNgSnData(QString sndata)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if (sndata.isEmpty())
|
|
return false;
|
|
|
|
int delete_index = -1;
|
|
for (int iii = 0; iii < queue_ng_sn_data.size(); iii++)
|
|
{
|
|
if (sndata == queue_ng_sn_data.at(iii) )
|
|
{
|
|
delete_index = iii;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 删除 sn 数据
|
|
if (delete_index != -1)
|
|
{
|
|
queue_ng_sn_data.removeAt(delete_index);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// sn容器队列中提取数据
|
|
QVector<QString> HSnData::getSnVector(int index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
QVector<QString> snData;
|
|
if ( queue_vector_sn.isEmpty() )
|
|
{
|
|
return snData;
|
|
}
|
|
if ( queue_vector_sn.length() > index )
|
|
{
|
|
return queue_vector_sn[index];
|
|
}
|
|
else
|
|
{
|
|
qCritical() << __FUNCTION__ << " line: " << __LINE__ << " index:" << index << " queue_vector_sn len:" << queue_vector_sn.length() << " get sn data is error! ";
|
|
return snData;
|
|
}
|
|
}
|
|
|
|
bool HSnData::checkSnData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
return queue_vector_sn.isEmpty() ? true : false;
|
|
}
|
|
|
|
|
|
bool HSnData::SetDeleteSnIndex(int index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
delete_sn_index = index;
|
|
return true;
|
|
}
|
|
void HSnData::addNgSn(QString sn)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
queue_ng_sn_data.append(sn);
|
|
}
|
|
|
|
bool HSnData::deleteNgSn()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if (queue_ng_sn_data.size() > 0)
|
|
{
|
|
queue_ng_sn_data.dequeue();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool HSnData::checkNgSn(QString sn)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
foreach(QString m_sn, queue_ng_sn_data)
|
|
{
|
|
if (m_sn == sn)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool HSnData::removeOne()
|
|
{
|
|
QMutexLocker locker( m_mutex );
|
|
delete_sn_index++;
|
|
if(queue_vector_sn.isEmpty())
|
|
return false;
|
|
if ( !queue_vector_sn.isEmpty() && delete_sn_index == queue_vector_sn.first().length() )
|
|
{
|
|
delete_sn_index = 0;
|
|
queue_vector_sn.dequeue();
|
|
return true;
|
|
}
|
|
if(delete_sn_index == queue_vector_sn.first().length())
|
|
return false;
|
|
|
|
return false;
|
|
}
|
|
|
|
void HSnData::clearData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
queue_vector_sn.clear();
|
|
}
|
|
|
|
|
|
void HSnData::setTaskDoneFlag(bool flag)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
taskDoneFlag = flag;
|
|
}
|
|
bool HSnData::getTaskDoneFlag()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
return taskDoneFlag;
|
|
}
|
|
|
|
|
|
HCameraData::HCameraData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
HCameraData::~HCameraData()
|
|
{
|
|
if (m_mutex)
|
|
{
|
|
delete m_mutex;
|
|
m_mutex = nullptr;
|
|
}
|
|
|
|
foreach(QVector<QQueue<SnCameraData>*> vector_queue_mat_ptr, vector_vector_queue_mat_ptr)
|
|
{
|
|
for (int i = 0; i < vector_queue_mat_ptr.size(); i++)
|
|
{
|
|
if (vector_queue_mat_ptr.at(i))
|
|
{
|
|
delete vector_queue_mat_ptr.at(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool HCameraData::initCameraVectorQueue(int camera_channel_num, int num)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if (num <= 0 )
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " num is error! num:" << num;
|
|
return false;
|
|
}
|
|
|
|
for (int vvv = 0; vvv < camera_channel_num; vvv++)
|
|
{
|
|
QVector<QQueue<SnCameraData>*> vector_queue_mat_ptr;
|
|
image_queue_num = num;
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
QQueue<SnCameraData>* queue_mats_ptr = new QQueue<SnCameraData>;
|
|
vector_queue_mat_ptr.append(queue_mats_ptr);
|
|
}
|
|
vector_vector_queue_mat_ptr.append(vector_queue_mat_ptr);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
bool HCameraData::checkImageData(QString index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
|
|
bool check_flag = false;
|
|
for (int vvv = 0; vvv < vector_vector_queue_mat_ptr.size(); vvv++)
|
|
{
|
|
QVector<QQueue<SnCameraData>*> vector_queue_mat_ptr = vector_vector_queue_mat_ptr.at(vvv);
|
|
if (!vector_queue_mat_ptr.isEmpty())
|
|
{
|
|
int m_value = index.toInt();
|
|
if (vector_queue_mat_ptr.isEmpty() || vector_queue_mat_ptr.size() <= m_value)
|
|
continue;
|
|
|
|
QQueue<SnCameraData>* queue_ptr = vector_queue_mat_ptr.at(m_value);
|
|
if (queue_ptr)
|
|
{
|
|
if (!queue_ptr->isEmpty())
|
|
{
|
|
check_flag = true; // 获取数据
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return check_flag;
|
|
}
|
|
|
|
SnCameraData HCameraData::getCameraImageData(QString m_index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
SnCameraData picVec;
|
|
int index = m_index.toInt();
|
|
for (int vvv = 0; vvv < vector_vector_queue_mat_ptr.size(); vvv++)
|
|
{
|
|
QVector<QQueue<SnCameraData>*> vector_queue_mat_ptr = vector_vector_queue_mat_ptr.at(vvv);
|
|
if (!vector_queue_mat_ptr.isEmpty())
|
|
{
|
|
int index = m_index.toInt();
|
|
if (vector_queue_mat_ptr.size() > index && index >= 0)
|
|
{
|
|
QQueue<SnCameraData>* queue_ptr = vector_queue_mat_ptr.at(index);
|
|
if (queue_ptr)
|
|
{
|
|
if (!queue_ptr->isEmpty())
|
|
{
|
|
picVec = queue_ptr->dequeue();
|
|
return picVec;
|
|
}
|
|
if((*queue_ptr).size()>10)
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << " (*queue_ptr).sieze()>10::" << (*queue_ptr).size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return picVec;
|
|
}
|
|
|
|
void HCameraData::clearData(QString channel_index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
|
|
int m_channel_index = 0;
|
|
if (!channel_index.isEmpty())
|
|
{
|
|
m_channel_index = channel_index.toInt();
|
|
}
|
|
|
|
if (m_channel_index >= vector_vector_queue_mat_ptr.size() || m_channel_index < 0)
|
|
{
|
|
m_channel_index = 0;
|
|
}
|
|
QVector<QQueue<SnCameraData>*> vector_queue_mat_ptr = vector_vector_queue_mat_ptr.at(m_channel_index);
|
|
|
|
if (!vector_queue_mat_ptr.isEmpty())
|
|
{
|
|
int size = vector_queue_mat_ptr.size();
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
QQueue<SnCameraData>* queue_ptr = vector_queue_mat_ptr.at(i);
|
|
queue_ptr->clear();
|
|
}
|
|
// 清理下标
|
|
m_index = 0;
|
|
}
|
|
}
|
|
//添加图像数据、sn数据,通道数据、拍照面描述
|
|
bool HCameraData::addImageData(QString channel_index, QVector<QString> vector_sn, std::vector<cv::Mat> m_mat, QString Surface)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
|
|
int m_channel_index = 0;
|
|
if (!channel_index.isEmpty())
|
|
{
|
|
m_channel_index = channel_index.toInt();
|
|
}
|
|
|
|
if (m_channel_index >= vector_vector_queue_mat_ptr.size() || m_channel_index < 0)
|
|
{
|
|
m_channel_index = 0;
|
|
}
|
|
|
|
//重点
|
|
QVector<QQueue<SnCameraData>*> vector_queue_mat_ptr = vector_vector_queue_mat_ptr.at(m_channel_index);
|
|
if (!vector_queue_mat_ptr.isEmpty())
|
|
{
|
|
SnCameraData sn_Image;
|
|
//sn_Image.vector_mat = m_mat;
|
|
for (int i = 0; i < m_mat.size(); i++)
|
|
{
|
|
cv::Mat img = cv::Mat();;
|
|
m_mat.at(i).copyTo(img);
|
|
sn_Image.vector_mat.push_back(img);
|
|
}
|
|
sn_Image.vector_snData = vector_sn;
|
|
sn_Image.Surface = Surface;
|
|
if (vector_queue_mat_ptr.at(m_index))
|
|
{
|
|
vector_queue_mat_ptr.at(m_index)->append(sn_Image);
|
|
if (image_queue_num > 1)
|
|
{
|
|
m_index++;
|
|
if (m_index >= image_queue_num)
|
|
{
|
|
m_index = 0;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
QVector<QString> HCameraData::getSnInfo(QVector<QString> snVec)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if ( image_queue_num == 1 || readSnFormatArray.isEmpty() || snVec.isEmpty())
|
|
{
|
|
return snVec;
|
|
}
|
|
else
|
|
{
|
|
QVector<QString> snData;
|
|
for ( int pos = 0; pos < readSnFormatArray.size(); pos++)
|
|
{
|
|
QJsonArray array = readSnFormatArray.at(pos).toObject().value("第几张图").toArray();
|
|
for (int vvv = 0; vvv < array.size(); vvv++)
|
|
{
|
|
QString task_index = array.at(vvv).toString();
|
|
if ( m_index == task_index.toInt())
|
|
{
|
|
snData.append(snVec.at(pos));
|
|
return snData;
|
|
}
|
|
}
|
|
}
|
|
return snData;
|
|
}
|
|
}
|
|
|
|
// 存储算法结果的数据
|
|
HAlgorithmData::HAlgorithmData()
|
|
{
|
|
m_algorith_mutex = new QMutex;
|
|
}
|
|
|
|
HAlgorithmData::~HAlgorithmData()
|
|
{
|
|
if (m_algorith_mutex)
|
|
{
|
|
delete m_algorith_mutex;
|
|
m_algorith_mutex = nullptr;
|
|
}
|
|
}
|
|
|
|
void HAlgorithmData::setDeleteResultMap(QMap<QString, Algorithm_Result_Data_index> map)
|
|
{
|
|
QMutexLocker locker(m_algorith_mutex);
|
|
map_delete_Result_index = map; //实际为空?
|
|
}
|
|
|
|
//添加SN匹配
|
|
QByteArray HAlgorithmData::getAlgorithmData(QString SNdataTime,QString cameraName_and_index, QString algorithm_result_index)
|
|
{
|
|
QByteArray result_byte= "";
|
|
QMutexLocker locker(m_algorith_mutex);
|
|
|
|
if (cameraName_and_index.contains("algorithm"))
|
|
{
|
|
for (int i = 0; i < algorithm_resultData_S.size(); i++)
|
|
{
|
|
if (algorithm_resultData_S[i].key_index.contains(cameraName_and_index)
|
|
&& algorithm_resultData_S[i].SN_dataTime == SNdataTime)
|
|
{
|
|
Algorithm_Result_Data value = algorithm_resultData_S[i];
|
|
algorithm_resultData_S.removeAt(i);
|
|
return value.byteArray;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < algorithm_resultData_S.size(); i++)
|
|
{
|
|
if (algorithm_resultData_S[i].key_index.contains(cameraName_and_index)
|
|
&& algorithm_resultData_S[i].SN_dataTime == SNdataTime)
|
|
{
|
|
//删除algorithm_resultData_S对应数据,
|
|
return getIndexData(algorithm_resultData_S[i],i, algorithm_result_index);
|
|
}
|
|
}
|
|
|
|
}
|
|
return "";
|
|
}
|
|
|
|
QByteArray HAlgorithmData::getIndexData(Algorithm_Result_Data result_data, int result_index, QString algorithm_result_index)
|
|
{
|
|
//qDebug() << __FUNCTION__ << " line: " << __LINE__ << " algorithmKey:" << algorithmKey << " cameraName_and_index: " << cameraName_and_index << " result_data.byte len:" << result_data.byte.length();
|
|
|
|
Algorithm_Result_Data_index index_pack;
|
|
if (map_delete_Result_index.keys().contains(result_data.key_index))
|
|
{
|
|
index_pack = map_delete_Result_index.value(result_data.key_index);
|
|
}
|
|
QString cameraName_and_index = result_data.key_index;
|
|
QByteArray index_byte;
|
|
QStringList list = cameraName_and_index.split("_");
|
|
if (list.size() != 2)
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " check list value is error! list len:" << list.length();
|
|
return "";
|
|
}
|
|
QString cameraName = list.at(0);
|
|
QString task_index = list.at(1);
|
|
//Logic_taskthread运行算法/汇总模块后,返回的数据
|
|
QByteArray byte = result_data.byteArray;
|
|
//result_data.byte转
|
|
QByteArrayList vec_Data;
|
|
vec_Data = byte.split('#');
|
|
|
|
if (vec_Data.isEmpty())
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " get vec_Data is null! ";
|
|
return "";
|
|
}
|
|
|
|
if (vec_Data.size() < algorithm_result_index.toInt())
|
|
{
|
|
qCritical() << __FUNCTION__ << " line: " << __LINE__ << " algorithmKey:" << algorithmKey << " get Index Data is error!";
|
|
return index_byte;
|
|
}
|
|
|
|
index_byte = vec_Data[algorithm_result_index.toInt()];// byte;// QByteArray::fromStdString(sendMsg);
|
|
|
|
// 删除map中的数据
|
|
if (vec_Data.size() == 1)
|
|
{
|
|
algorithm_resultData_S.removeAt(result_index);
|
|
//map_algorithm_resultData.remove(cameraName_and_index);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmKey:" << algorithmKey << " remove cameraName_and_index " << cameraName_and_index;
|
|
}
|
|
else
|
|
{
|
|
if (index_pack.get_result_index == vec_Data.size())
|
|
{
|
|
algorithm_resultData_S.removeAt(result_index);
|
|
//map_algorithm_resultData.remove(cameraName_and_index);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmKey:" << algorithmKey << " remove cameraName_and_index " << cameraName_and_index;
|
|
index_pack.get_result_index = 0;
|
|
}
|
|
else if (index_pack.get_result_index == index_pack.delete_Result_index)
|
|
{
|
|
algorithm_resultData_S.removeAt(result_index);
|
|
//map_algorithm_resultData.remove(cameraName_and_index);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmKey:" << algorithmKey << " remove cameraName_and_index " << cameraName_and_index;
|
|
index_pack.get_result_index = 0;
|
|
}
|
|
index_pack.get_result_index++;
|
|
map_delete_Result_index.insert(cameraName_and_index, index_pack); // 替换
|
|
//delete_Result_index_S[Result_Data_index] = index_pack;
|
|
}
|
|
return index_byte;
|
|
}
|
|
|
|
void HAlgorithmData::clearData()
|
|
{
|
|
QMutexLocker locker(m_algorith_mutex);
|
|
algorithm_resultData_S.clear();
|
|
|
|
//什么作用
|
|
QList<QString> keyList = map_delete_Result_index.keys();
|
|
for (int i = 0; i < keyList.size(); i++)
|
|
{
|
|
Algorithm_Result_Data_index index_pack = map_delete_Result_index.value(keyList[i]);
|
|
index_pack.get_result_index = 1; // 恢复下标 只获取自增的下标 20230318
|
|
map_delete_Result_index.insert(keyList[i],index_pack);
|
|
}
|
|
}
|
|
|
|
|
|
bool HAlgorithmData::checkAlgorithmData(QString cameraName_and_index, QString SNdataTime)
|
|
{
|
|
QMutexLocker locker(m_algorith_mutex);
|
|
for (int i = 0; i < algorithm_resultData_S.size(); i++)
|
|
{
|
|
if (algorithm_resultData_S[i].key_index.contains(cameraName_and_index)
|
|
&& algorithm_resultData_S[i].SN_dataTime == SNdataTime)
|
|
return true;
|
|
}
|
|
|
|
return false;;
|
|
}
|
|
|
|
|
|
|
|
void HAlgorithmData::addAlgorithmData(QString cameraName_and_index, Algorithm_Result_Data result_data)
|
|
{
|
|
QMutexLocker locker(m_algorith_mutex);
|
|
result_data.key_index = cameraName_and_index;
|
|
//map_algorithm_resultData.insert(cameraName_and_index, result_data);
|
|
if (algorithm_resultData_S.size() > 1000)
|
|
algorithm_resultData_S.dequeue();
|
|
algorithm_resultData_S.enqueue(result_data);
|
|
}
|
|
|
|
/********************************/
|
|
HAlgorithmExecData::HAlgorithmExecData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
HAlgorithmExecData::~HAlgorithmExecData()
|
|
{
|
|
if (m_mutex)
|
|
{
|
|
delete m_mutex;
|
|
m_mutex = nullptr;
|
|
}
|
|
}
|
|
|
|
bool HAlgorithmExecData::getDetectData(testData& picVec)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
bool result = true;
|
|
if (!m_detectData.isEmpty())
|
|
{
|
|
testData picVec1 = m_detectData.head();
|
|
//testData picVec1 = m_detectData.dequeue();
|
|
|
|
picVec.cameraName = picVec1.cameraName; // 提取名称
|
|
picVec.task_index = picVec1.task_index; // 任务下标
|
|
picVec.byteArray = picVec1.byteArray;
|
|
for (int i = 0; i < m_detectData.head().dstImageMat.size(); i++)
|
|
{
|
|
cv::Mat img = cv::Mat();
|
|
m_detectData.head().dstImageMat.at(i).copyTo(img);
|
|
picVec.dstImageMat.push_back(img);
|
|
m_detectData.head().dstImageMat[i] = cv::Mat();
|
|
m_detectData.head().dstImageMat[i].release();
|
|
}
|
|
//picVec.dstImageMat.assign(picVec1.dstImageMat.begin(), picVec1.dstImageMat.end());
|
|
}
|
|
else
|
|
result = false;
|
|
|
|
return result;
|
|
}
|
|
|
|
bool HAlgorithmExecData::deleteDetectData()
|
|
{
|
|
bool result = false;
|
|
QMutexLocker locker(m_mutex);
|
|
if (!m_detectData.isEmpty())
|
|
{
|
|
m_detectData.dequeue();
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void HAlgorithmExecData::addDetectData(testData detectData)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
m_detectData.append(detectData);
|
|
}
|
|
|
|
void HAlgorithmExecData::clearData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
m_detectData.clear();
|
|
}
|
|
|
|
QMutex* station_mutex;
|
|
|
|
/*********************************/
|
|
HStationData::HStationData()
|
|
{
|
|
station_mutex = new QMutex;
|
|
}
|
|
|
|
HStationData::~HStationData()
|
|
{
|
|
/*if (station_mutex)
|
|
{
|
|
delete station_mutex;
|
|
station_mutex = nullptr;
|
|
}*/
|
|
|
|
foreach(HCameraData * ptr, camera_list_Ptr)
|
|
{
|
|
if (ptr)
|
|
{
|
|
delete ptr;
|
|
ptr = nullptr;
|
|
}
|
|
}
|
|
foreach(QQueue<cv::Mat>* ptr, saveImage_qqueue_ptr)
|
|
{
|
|
if (ptr)
|
|
{
|
|
delete ptr;
|
|
ptr = nullptr;
|
|
}
|
|
}
|
|
for each (QMutex * ptr in saveImageMutex_list_ptr)
|
|
{
|
|
if (ptr)
|
|
{
|
|
delete ptr;
|
|
ptr = nullptr;
|
|
}
|
|
}
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << " ~HStationData success!";
|
|
}
|
|
|
|
bool HStationData::checkCameraData(QString cameraKey, QString index)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
HCameraData* camera_ptr = nullptr;
|
|
QString stationName = stationKey;
|
|
int s = camera_list_Ptr.size();
|
|
foreach(HCameraData * ptr, camera_list_Ptr)
|
|
{
|
|
if (ptr->getCameraKey() == cameraKey)
|
|
{
|
|
camera_ptr = ptr;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (camera_ptr)
|
|
{
|
|
if (camera_ptr->checkImageData(index))
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 获取相机数据
|
|
HCameraData* HStationData::getCameraData(QString cameraKey)
|
|
{
|
|
QMutexLocker locker(station_mutex); //不加锁会访问冲突
|
|
foreach(HCameraData * ptr,camera_list_Ptr)
|
|
{
|
|
if (ptr->getCameraKey() == cameraKey)
|
|
return ptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
// 添加相机数据
|
|
void HStationData::addCameraData(HCameraData* cameraData)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
camera_list_Ptr.append(cameraData);
|
|
int s = camera_list_Ptr.size();
|
|
return;
|
|
}
|
|
|
|
|
|
// 添加算法数据
|
|
void HStationData::addAlgorithmData(HAlgorithmData* algorithmData)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
algotithmlist_Ptr.append(algorithmData);
|
|
}
|
|
|
|
// 获取 算法指针
|
|
HAlgorithmData* HStationData::getAlgorithmData(QString algorithmKey)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
foreach(HAlgorithmData * ptr, algotithmlist_Ptr)
|
|
{
|
|
if (ptr->getAlgorithmKey() == algorithmKey)
|
|
return ptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
//触发条件,序号列表,SN_datatime
|
|
bool HStationData::checkAlgorithmResultData(QString algorithmKey, QString index,QString SN_datatime)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
HAlgorithmData* algorithm_ptr = nullptr;
|
|
foreach(HAlgorithmData * m_ptr, algotithmlist_Ptr)
|
|
{
|
|
if (m_ptr->getAlgorithmKey() == algorithmKey)
|
|
{
|
|
algorithm_ptr = m_ptr;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (algorithm_ptr)
|
|
{
|
|
if (algorithm_ptr->checkAlgorithmData(index, SN_datatime))
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//算法超时,添加配置文件读到的NG_data
|
|
void HStationData::addAlgorithmResultData(QString algorithmKey, QString index, QByteArray NG_data, QString SN_datatime)
|
|
{
|
|
HAlgorithmData* algorithm_ptr = nullptr;
|
|
foreach(HAlgorithmData * m_ptr, algotithmlist_Ptr)
|
|
{
|
|
if (m_ptr->getAlgorithmKey() == algorithmKey)
|
|
{
|
|
algorithm_ptr = m_ptr;
|
|
break;
|
|
}
|
|
}
|
|
Algorithm_Result_Data result_data;
|
|
result_data.byteArray = NG_data;
|
|
result_data.SN_dataTime = SN_datatime;
|
|
|
|
if (algorithm_ptr)
|
|
{
|
|
QString cameraName_and_index = algorithmKey + "_" + NG_data;
|
|
algorithm_ptr->addAlgorithmData(cameraName_and_index, result_data);
|
|
}
|
|
}
|
|
/**************************************/
|
|
|
|
void HStationData::addAlgorithmExecData(HAlgorithmExecData* algorithmData)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
algotithmExecList_Ptr.append(algorithmData);
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algotithmlist_Ptr len:" << algotithmlist_Ptr.length();
|
|
}
|
|
|
|
//新料来了,清容器数据;
|
|
//根据项目情况,考虑是否清检测容器数据。清,检测超时,数据缺失;不清,连续检测超时,内存溢出
|
|
void HStationData::clearData(QString channelIndex, QStringList cameraList)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
if (channelIndex == "all")
|
|
{
|
|
for (int i = 0; i < camera_list_Ptr.size(); i++)
|
|
camera_list_Ptr[i]->clearData(channelIndex);
|
|
|
|
for (int i = 0; i < sndata_list.size(); i++)
|
|
sndata_list[i]->clearData();
|
|
for (int i = 0; i < algotithmExecList_Ptr.size(); i++)
|
|
algotithmExecList_Ptr[i]->clearData();
|
|
for (int i = 0; i < algotithmlist_Ptr.size(); i++)
|
|
algotithmlist_Ptr[i]->clearData();
|
|
}
|
|
|
|
for (int i = 0; i < camera_list_Ptr.size(); i++)
|
|
for(int j=0;j< cameraList.size();j++)
|
|
if(cameraList[j]== camera_list_Ptr[i]->getCameraKey())
|
|
camera_list_Ptr[i]->clearData(channelIndex);
|
|
|
|
//sndata_list[channelIndex.toInt()]->clearData();
|
|
if(sndata_list.size()> channelIndex.toInt())
|
|
if (sndata_list[channelIndex.toInt()] != nullptr)
|
|
sndata_list[channelIndex.toInt()]->clearData();
|
|
/*if (m_snData != nullptr)
|
|
m_snData->clearData();*/
|
|
//根据项目情况,考虑是否清检测容器数据。
|
|
/*for (int i = 0; i < algotithmExecList_Ptr.size(); i++)
|
|
for (int j = 0; j < cameraList.size(); j++)
|
|
if(algotithmExecList_Ptr[i]->cameraList.contains(cameraList[j]))
|
|
algotithmExecList_Ptr[i]->clearData();*/
|
|
|
|
//for (int i = 0; i < algotithmlist_Ptr.size(); i++)
|
|
// algotithmlist_Ptr[i]->clearData();
|
|
}
|
|
|
|
void HStationData::clearCameraData(QString key, QString channelIndex)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
for (int i = 0; i < camera_list_Ptr.size(); i++)
|
|
{
|
|
QString cameraKey = camera_list_Ptr[i]->getCameraKey();
|
|
if (cameraKey.contains(key))
|
|
{
|
|
camera_list_Ptr[i]->clearData(channelIndex);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
////修改报警、复位逻辑。。
|
|
void HStationData::clearAlgorithmData(QString key)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
for (int i = 0; i < algotithmlist_Ptr.size(); i++)
|
|
{
|
|
QString algotithmKey = algotithmlist_Ptr[i]->getAlgorithmKey();
|
|
if ( algotithmKey == key)
|
|
{
|
|
algotithmlist_Ptr[i]->clearData();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void HStationData::clearAlgorithmExecData(QString key)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
for (int i = 0; i < algotithmExecList_Ptr.size(); i++)
|
|
{
|
|
QString m_key = algotithmExecList_Ptr[i]->getAlgorithmName();
|
|
if (m_key == key )
|
|
{
|
|
algotithmExecList_Ptr[i]->clearData();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void HStationData::clearSnData(int index)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
if (!sndata_list.isEmpty())
|
|
{
|
|
HSnData* sn_data = sndata_list.at(index);
|
|
if (sn_data)
|
|
{
|
|
sndata_list.at(index)->clearData();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void HStationData::set_trigger_signal(QString trigger_signal)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
station_trigger_signal = trigger_signal;
|
|
}
|
|
QString HStationData::get_trigger_signal()
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
return station_trigger_signal;
|
|
}
|
|
|
|
|
|
HAlgorithmExecData* HStationData::getAlgorithmExecData(QString algorithmKey)
|
|
{
|
|
QMutexLocker locker(station_mutex);
|
|
foreach(HAlgorithmExecData * ptr, algotithmExecList_Ptr)
|
|
{
|
|
if (ptr->getAlgorithmName() == algorithmKey)
|
|
return ptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|