diff --git a/runner17/QUserInfod.dll b/runner17/QUserInfod.dll index edec2f6..91292fa 100644 Binary files a/runner17/QUserInfod.dll and b/runner17/QUserInfod.dll differ diff --git a/runner17/QUserInfod.ilk b/runner17/QUserInfod.ilk index bcb85b3..707d1d6 100644 Binary files a/runner17/QUserInfod.ilk and b/runner17/QUserInfod.ilk differ diff --git a/runner17/lpbengined.dll b/runner17/lpbengined.dll index 6773979..d817af9 100644 Binary files a/runner17/lpbengined.dll and b/runner17/lpbengined.dll differ diff --git a/runner17/lpbengined.ilk b/runner17/lpbengined.ilk index abbda67..c50fb4d 100644 Binary files a/runner17/lpbengined.ilk and b/runner17/lpbengined.ilk differ diff --git a/runner17/lpdesignerd.dll b/runner17/lpdesignerd.dll index 57dc838..62e36e1 100644 Binary files a/runner17/lpdesignerd.dll and b/runner17/lpdesignerd.dll differ diff --git a/runner17/lpdesignerd.ilk b/runner17/lpdesignerd.ilk index a513aaa..ee4541d 100644 Binary files a/runner17/lpdesignerd.ilk and b/runner17/lpdesignerd.ilk differ diff --git a/runner17/tpCam_100d.dll b/runner17/tpCam_100d.dll index f074c23..cb851a2 100644 Binary files a/runner17/tpCam_100d.dll and b/runner17/tpCam_100d.dll differ diff --git a/runner17/tpCam_100d.ilk b/runner17/tpCam_100d.ilk index 8db7b80..c6530e3 100644 Binary files a/runner17/tpCam_100d.ilk and b/runner17/tpCam_100d.ilk differ diff --git a/runner17/tpCam_120d.dll b/runner17/tpCam_120d.dll index f6a50bc..bbc7d30 100644 Binary files a/runner17/tpCam_120d.dll and b/runner17/tpCam_120d.dll differ diff --git a/runner17/tpCam_120d.ilk b/runner17/tpCam_120d.ilk index deeb3ea..c6416da 100644 Binary files a/runner17/tpCam_120d.ilk and b/runner17/tpCam_120d.ilk differ diff --git a/runner17/tpCam_140d.dll b/runner17/tpCam_140d.dll index 90bd036..8ff97d5 100644 Binary files a/runner17/tpCam_140d.dll and b/runner17/tpCam_140d.dll differ diff --git a/runner17/tpCam_160d.dll b/runner17/tpCam_160d.dll index 0154aa0..4ffb7cd 100644 Binary files a/runner17/tpCam_160d.dll and b/runner17/tpCam_160d.dll differ diff --git a/runner17/tpCam_160d.ilk b/runner17/tpCam_160d.ilk index 43ab1d6..ec073c8 100644 Binary files a/runner17/tpCam_160d.ilk and b/runner17/tpCam_160d.ilk differ diff --git a/src/lpCoreCtrl/CThread.cpp b/src/lpCoreCtrl/CThread.cpp new file mode 100644 index 0000000..588ccec --- /dev/null +++ b/src/lpCoreCtrl/CThread.cpp @@ -0,0 +1,43 @@ +#include "CThread.h" + +CThread::CThread(QObject *parent) + : QThread(parent) +{ + m_abort = false; +} + +CThread::~CThread() +{ + mutex.lock(); + m_abort = true; + mutex.unlock(); + + wait(); +} + +void CThread::startProcess() +{ + m_abort = false; + start(); +} + +void CThread::stopProcess() +{ + mutex.lock(); + m_abort = true; + mutex.unlock(); +} + +void CThread::run() +{ + while (1) { + if (m_func) + { + m_func(); + } + if(m_abort) + break; + int ms = m_sleepms > 1 ? m_sleepms : 1; + msleep(ms); + } +} diff --git a/src/lpCoreCtrl/CThread.h b/src/lpCoreCtrl/CThread.h new file mode 100644 index 0000000..71da4b7 --- /dev/null +++ b/src/lpCoreCtrl/CThread.h @@ -0,0 +1,36 @@ +#ifndef _CTHREAD_H_ +#define _CTHREAD_H_ + +#include +#include +#include +typedef std::function TaskFunc; +class CThread : public QThread +{ + Q_OBJECT + +public: + CThread(QObject *parent = 0); + ~CThread(); + void startProcess(); + void setTaskFunc(TaskFunc func) { + m_func = func; + } + void setSleepms(int m_time = 1) + { + m_sleepms = m_time; + } +public slots: + void stopProcess(); + +protected: + void run(); + +private: + bool m_abort; + QMutex mutex; + int m_sleepms{ 10 }; + TaskFunc m_func; +}; + +#endif // ! _CTHREAD_H_ diff --git a/src/lpCoreCtrl/CoreCtrl.cpp b/src/lpCoreCtrl/CoreCtrl.cpp index e1fd8e8..2c611c9 100644 --- a/src/lpCoreCtrl/CoreCtrl.cpp +++ b/src/lpCoreCtrl/CoreCtrl.cpp @@ -39,10 +39,22 @@ CCoreCtrl::CCoreCtrl(void) m_gpImgProc = new CImgProc(); ((CImgProc*)m_gpImgProc)->InitProc(); + + TaskFunc func = std::bind(&CCoreCtrl::onRunTask, this); + m_pThread = new CThread(); + m_pThread->setSleepms(50); + m_pThread->setTaskFunc(func); + m_pThread->startProcess(); } CCoreCtrl::~CCoreCtrl(void) { + if (m_pThread) + { + m_pThread->quit(); + delete m_pThread; + m_pThread = nullptr; + } IFreeCore(); if (m_gpImgProc) { @@ -72,7 +84,7 @@ int CCoreCtrl::IInitCore(class IDetectorEngine* pDE /*= NULL*/) /*创建图片处理线程*/ for (int i = 0; i < nCount; ++i) { - TaskFunc func = std::bind(&CCoreCtrl::onTaskFunc, this); + TaskFunc_Bool func = std::bind(&CCoreCtrl::onTaskFunc, this); lpThread *pThd = new lpThread(func); if( NULL == pThd ) { @@ -149,7 +161,13 @@ void CCoreCtrl::ISetTriggerMode(emTpDeviceTriggerMode triggerMode, long nFrameRa void CCoreCtrl::ISnapImage(const QStringList& camKeys) { - m_camDevManager->ISnapImage(camKeys); + //m_camDevManager->ISnapImage(camKeys); + if (camKeys.size() <= 0) + return; + CameraCtrl ctrl; + ctrl.m_ctrlType = 3; + ctrl.strCamName = camKeys.first(); + m_safeList.push_back(ctrl); } QMap CCoreCtrl::IGetCamShowNames() @@ -294,4 +312,35 @@ bool CCoreCtrl::onTaskFunc() return true; } return false; -} \ No newline at end of file +} + +void CCoreCtrl::onRunTask() +{ + if (m_safeList.getSize() > 0) { + CameraCtrl ctrl; + m_safeList.pop_front(ctrl); + if (ctrl.m_ctrlType == 0)//开始相机 外触发 + { + //onStartCamera(ctrl.strCamName); + } + else if (ctrl.m_ctrlType == 1)//停止相机 + { + //onStopCamera(ctrl.strCamName); + } + else if (ctrl.m_ctrlType == 2)//开始相机 软触发 + { + //onStartSoftCamera(ctrl.strCamName); + } + else if (ctrl.m_ctrlType == 3)//软触发一次相机 + { + //onSoftTrigerCamera(ctrl.strCamName); + m_camDevManager->ISnapImage(QStringList()< m_imgThdPool; int m_nCoreCount; @@ -71,5 +80,8 @@ private: CCameraPool* m_camDevManager{ nullptr }; IImgProc* m_gpImgProc{nullptr}; class IDetectorEngine* m_pDE{ nullptr }; + CThread *m_pThread{nullptr}; + //threadsafe_list + threadsafe_list m_safeList; }; #endif \ No newline at end of file diff --git a/src/lpCoreCtrl/lpThread.cpp b/src/lpCoreCtrl/lpThread.cpp index d3e4114..2e091aa 100644 --- a/src/lpCoreCtrl/lpThread.cpp +++ b/src/lpCoreCtrl/lpThread.cpp @@ -5,7 +5,7 @@ lpThread::lpThread(QObject *parent) : QThread(parent) } -lpThread::lpThread(TaskFunc func, QObject *parent /*= nullptr*/): QThread(parent) +lpThread::lpThread(TaskFunc_Bool func, QObject *parent /*= nullptr*/): QThread(parent) { _func = func; m_bIsRunning = false; diff --git a/src/lpCoreCtrl/lpThread.h b/src/lpCoreCtrl/lpThread.h index eddd8ce..7bcbdbe 100644 --- a/src/lpCoreCtrl/lpThread.h +++ b/src/lpCoreCtrl/lpThread.h @@ -5,12 +5,12 @@ #include #include -typedef std::function TaskFunc; +typedef std::function TaskFunc_Bool; class lpThread : public QThread { public: lpThread(QObject *parent = nullptr); - lpThread(TaskFunc func,QObject *parent = nullptr); + lpThread(TaskFunc_Bool func,QObject *parent = nullptr); ~lpThread(); void StartThread(); @@ -23,7 +23,7 @@ private: bool m_bRunSignal; bool m_bIsRunning; private: - TaskFunc _func; + TaskFunc_Bool _func; }; #endif // QTPTHREADBASE_H diff --git a/src/lpCoreCtrl/threadsafe_list.hpp b/src/lpCoreCtrl/threadsafe_list.hpp new file mode 100644 index 0000000..ec8137b --- /dev/null +++ b/src/lpCoreCtrl/threadsafe_list.hpp @@ -0,0 +1,81 @@ +/*! + * \file threadsafe_list.hpp + * \date 2018/11/30 + * + * \author pan yingdong + * Contact: bob.pan@hzleaper.com + * + * + * \note +*/ +#ifndef _THREADSAFE_LIST_H_ +#define _THREADSAFE_LIST_H_ + +#include +#include +#include +#include +#include +struct empty_list :std::exception +{ + const char* what() const throw(){ return "empty list"; }; +}; + +template +class threadsafe_list +{ +private: + std::list dataList; + mutable std::mutex m; +public: + threadsafe_list(){} + threadsafe_list(const threadsafe_list& other) + { + std::lock_guard guard(m); + dataList = other.dataList; + } + threadsafe_list& operator=(const threadsafe_list&) = delete; + bool push_back(T new_val) + { + std::lock_guard guard(m); + dataList.push_back(new_val); + return true; + } + std::shared_ptr pop_front() + { + std::lock_guard guard(m); + if (dataList.empty()) + throw empty_list(); + std::shared_ptr const res(std::make_shared(dataList.front())); + dataList.pop_front(); + return res; + } + bool pop_front(T& value) + { + std::lock_guard guard(m); + if (dataList.empty()) + { + //throw empty_list(); + return false; + } + value = dataList.front(); + dataList.pop_front(); + return true; + } + bool empty() const + { + std::lock_guard guard(m); + return dataList.empty(); + } + int getSize() const + { + std::lock_guard guard(m); + return dataList.size(); + } + void clear() { + std::lock_guard guard(m); + dataList.clear(); + } +}; +#endif + diff --git a/src/lpCoreCtrl/tpCamera/CameraPool.cpp b/src/lpCoreCtrl/tpCamera/CameraPool.cpp index c397cc0..747572f 100644 --- a/src/lpCoreCtrl/tpCamera/CameraPool.cpp +++ b/src/lpCoreCtrl/tpCamera/CameraPool.cpp @@ -406,7 +406,18 @@ void gfunc_snap_camera_image(const QString& key, class ICameraObject*& pCam, voi void CCameraPool::ISnapImage(const QStringList& camKeys) { - m_CamDevMap.iterateCall2(gfunc_snap_camera_image, (void*)(&camKeys)); + foreach(QString var, camKeys) { + QZkMutexMap::iterator it = m_CamDevMap.find(var); + if (it != m_CamDevMap.end()) + { + ICameraObject* pObj = *it; + if (pObj) + { + pObj->ISnapCamera(); + } + } + } + // m_CamDevMap.iterateCall2(gfunc_snap_camera_image, (void*)(&camKeys)); } void gfunc_send_soft_trigger(const QString& key, class ICameraObject*& pCam, void* pData) diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj index b67ea3f..a9c4fb9 100644 --- a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj @@ -12,6 +12,7 @@ + @@ -22,14 +23,31 @@ + + true + + + true + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DTPCORECTRL_LIB -DTPCORECTRL_EXPORTS -D%(PreprocessorDefinitions) "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtSerialPort" "-I$(QTDIR)\include\QtSql" "-I.\..\..\src\lpCoreCtrl" "-I.\..\..\src\lpCoreCtrl\tpCamera" "-I.\..\..\src\lpCoreCtrl\tpImgProc" "-I.\..\..\3part\libzkq\include" "-I.\..\..\3part\openssl\include" "-I.\..\..\3part\tadpole\include\tpBase" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DTPCORECTRL_LIB -DTPCORECTRL_EXPORTS -D%(PreprocessorDefinitions) "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtSerialPort" "-I$(QTDIR)\include\QtSql" "-I.\..\..\src\lpCoreCtrl" "-I.\..\..\src\lpCoreCtrl\tpCamera" "-I.\..\..\src\lpCoreCtrl\tpImgProc" "-I.\..\..\3part\libzkq\include" "-I.\..\..\3part\openssl\include" "-I.\..\..\3part\tadpole\include\tpBase" + + diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters index 9e015f2..50382b5 100644 --- a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters @@ -71,6 +71,15 @@ tpCoreCtrl + + Source Files + + + Generated Files + + + Generated Files + @@ -112,5 +121,13 @@ tpCoreCtrl + + Header Files + + + + + Header Files + \ No newline at end of file