init files
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
# 获取获取当前目录名
|
||||
get_filename_component(CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
string(TIMESTAMP RUN_TIME)
|
||||
message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME})
|
||||
|
||||
set(DLL_NAMES "CSTLightSource" "opencv")
|
||||
foreach(child ${DLL_NAMES})
|
||||
LIST(APPEND ENV_INCLUDE ${${child}_include})
|
||||
LIST(APPEND ENV_LIB ${${child}_lib})
|
||||
LIST(APPEND ENV_TARGET ${${child}_target_link})
|
||||
endforeach()
|
||||
message(" ENV_INCLUDE : " ${ENV_INCLUDE} )
|
||||
message(" ENV_LIB : " ${ENV_LIB} )
|
||||
message(" ENV_TARGET : " ${ENV_TARGET} )
|
||||
include_directories(
|
||||
|
||||
${ENV_INCLUDE}
|
||||
)
|
||||
|
||||
link_directories (
|
||||
${ENV_LIB}
|
||||
|
||||
)
|
||||
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
SET(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
FILE(GLOB HEAD_FILES "./*.h" )
|
||||
FILE(GLOB SRC_FILES "./*.cpp")
|
||||
FILE(GLOB UI_FILES "./*.ui")
|
||||
|
||||
|
||||
#find_package(Qt5 COMPONENTS Core REQUIRED)
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
|
||||
|
||||
add_library(${CURRENT_FOLDER} SHARED
|
||||
${HEAD_FILES}
|
||||
${SRC_FILES}
|
||||
${UI_FILES}
|
||||
)
|
||||
|
||||
|
||||
|
||||
set_target_properties(${CURRENT_FOLDER} PROPERTIES LINKER_LANGUAGE C
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(${CURRENT_FOLDER} PRIVATE
|
||||
${ENV_TARGET}
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
)
|
||||
|
||||
|
||||
# target_compile_definitions(${CURRENT_FOLDER} PRIVATE HD_AIDEMO_MODULE_LIBRARY)
|
||||
|
||||
|
||||
|
||||
|
||||
string(TIMESTAMP RUN_TIME)
|
||||
message( " model end : " ${CURRENT_FOLDER}:${RUN_TIME})
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "Hd_LightSourceModule_CST.h"
|
||||
|
||||
Hd_LightSourceModule_CST::Hd_LightSourceModule_CST()
|
||||
{
|
||||
}
|
||||
|
||||
Hd_LightSourceModule_CST::~Hd_LightSourceModule_CST()
|
||||
{
|
||||
DestroyIpConnection(handle);
|
||||
}
|
||||
//在这里data是CHX_XXXX 即通道几,亮度几
|
||||
bool Hd_LightSourceModule_CST::writeData(std::vector<cv::Mat>& mat, QByteArray& data)
|
||||
{
|
||||
int index = QString(data.mid(2, 1)).toInt();
|
||||
int value = QString(data.mid(4)).toInt();
|
||||
auto res = SetDigitalValue(index, value, handle);
|
||||
if (res != SUCCESS)
|
||||
{
|
||||
qCritical() << " [Error] " << "Set CST Intensity Error";
|
||||
isOpenFlag = false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//在这里params是SN
|
||||
bool Hd_LightSourceModule_CST::initParas(QByteArray& params)
|
||||
{
|
||||
if (!searchDevice())
|
||||
return false;
|
||||
if (!SNtoIP.contains(params))
|
||||
{
|
||||
qCritical() << " [Error] " << "CST Init Params Invaild";
|
||||
return false;
|
||||
}
|
||||
auto res = ConnectIP((char*)SNtoIP[params].toStdString().c_str(), 3, &handle);
|
||||
if (res != SUCCESS)
|
||||
{
|
||||
qCritical() << " [Error] " << "Connect CST Device Error";
|
||||
return false;
|
||||
}
|
||||
isOpenFlag = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hd_LightSourceModule_CST::checkStatus()
|
||||
{
|
||||
return isOpenFlag;
|
||||
}
|
||||
|
||||
bool Hd_LightSourceModule_CST::searchDevice()
|
||||
{
|
||||
//搜索设备
|
||||
Adapter_prm adapter[20];
|
||||
int length;
|
||||
GetAdapter(&length, adapter);
|
||||
Host_prm hostprm;
|
||||
int concount = 0;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int controllercount;
|
||||
memset(&hostprm, 0, sizeof(hostprm));
|
||||
GetHost(&controllercount, &hostprm, adapter[i].cIp);
|
||||
if (controllercount)
|
||||
{
|
||||
Controller_prm controlprm;
|
||||
auto res = GetConfigure(hostprm.cMac, &controlprm, adapter[i].cIp);
|
||||
SNtoIP[hostprm.cSn + 3] = controlprm.cIp;
|
||||
}
|
||||
concount += controllercount;
|
||||
}
|
||||
if(concount)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
qCritical() << " [Error] " << "CST Device Count 0";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Hd_LightSourceModule_CST* create()
|
||||
{
|
||||
qDebug() << "[INFO] " << "Hd_LightSourceModule_CST create success!";
|
||||
return new Hd_LightSourceModule_CST;
|
||||
}
|
||||
|
||||
void destory(Hd_LightSourceModule_CST* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
delete ptr;
|
||||
ptr = nullptr;
|
||||
}
|
||||
qDebug() << "[INFO] " << "Hd_LightSourceModule_CST destory success!";
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef Hd_LightSourceModule_CST_H
|
||||
#define Hd_LightSourceModule_CST_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include<opencv2/opencv.hpp>
|
||||
#include <opencv.hpp>
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include<iostream>
|
||||
#include <Windows.h>
|
||||
#include <time.h>
|
||||
#include <QScopedPointer>
|
||||
#include <QThread>
|
||||
#include <CommonToolDll.h>
|
||||
#include <ControllerDll.h>
|
||||
#include <ErrorCode.h>
|
||||
#include <sControllerDll.h>
|
||||
#include <QMap>
|
||||
#include "base.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#pragma comment(lib,"./CommonToolDll.lib")
|
||||
#pragma comment(lib,"./ControllerDll.lib")
|
||||
#pragma comment(lib,"./sControllerDll.lib")
|
||||
|
||||
|
||||
|
||||
class MyThread;
|
||||
class Hd_LightSourceModule_CST :public Base
|
||||
{
|
||||
public:
|
||||
Hd_LightSourceModule_CST();
|
||||
virtual ~Hd_LightSourceModule_CST();
|
||||
//从类中读数据到实例对象
|
||||
//bool readData(std::vector<cv::Mat>& mat, QByteArray& data);
|
||||
//实例对象把数据写入到类
|
||||
bool writeData(std::vector<cv::Mat>& mat, QByteArray& data);
|
||||
bool initParas(QByteArray& params);
|
||||
//bool run();
|
||||
bool checkStatus();
|
||||
bool searchDevice();
|
||||
private:
|
||||
MyThread *m_thread = nullptr;
|
||||
ControllerHandle handle;
|
||||
QMap<QString, QString> SNtoIP;
|
||||
bool isOpenFlag = false;
|
||||
};
|
||||
|
||||
class MyThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MyThread(QObject *parent = nullptr):m_obj(parent){}
|
||||
void run();
|
||||
private:
|
||||
QObject *m_obj;
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
Q_DECL_EXPORT Hd_LightSourceModule_CST * create();
|
||||
Q_DECL_EXPORT void destory(Hd_LightSourceModule_CST * ptr);
|
||||
}
|
||||
|
||||
#endif // Hd_LightSourceModule_CST_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef __BASECLASS_H__
|
||||
#define __BASECLASS_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
class Base :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool init_flag; //是否初始化,false,true
|
||||
bool status = true; //相机状态(判断相机是否断开连接)
|
||||
std::string paras; //传输数据
|
||||
std::vector<cv::Mat> m_mat; //传输图片
|
||||
std::string moduleName; //模块名称
|
||||
public:
|
||||
Base(){}
|
||||
virtual ~Base(){}
|
||||
virtual bool readData(std::vector<cv::Mat>&,QByteArray&){return true;}
|
||||
virtual bool writeData(std::vector<cv::Mat>&,QByteArray&){return true;}
|
||||
virtual bool initParas(QByteArray&){return true;}
|
||||
virtual bool run() {return true;}
|
||||
virtual bool checkStatus() { return true; }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
此模块只需要在调用InitParas时传入SN
|
||||
后续在writedata里传入CHX_XXXX 即通道与亮度值即可
|
||||
Reference in New Issue
Block a user