Commit a355c379 authored by Yuelong Yu's avatar Yuelong Yu
Browse files

Initial Commit

parents
bin
build
.vscode
\ No newline at end of file
cmake_minimum_required(VERSION 3.0.2)
project(pcosdk)
set(MAJOR_VERSION 0)
set(MINOR_VERSION 1)
set(LIBRARY_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin")
#lib output path
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
message(STATUS "library output path is:${LIBRARY_OUTPUT_PATH}")
#install path
set(CMAKE_INSTALL_LIB_PATH "${CMAKE_INSTALL_PREFIX}/lib/pcosdk")
set(CMAKE_INSTALL_INC_PATH "${CMAKE_INSTALL_PREFIX}/include/pcosdk")
message(STATUS "install path is:${CMAKE_INSTALL_PREFIX}")
#add module
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
message(STATUS "module path is:${CMAKE_MODULE_PATH}")
find_package(SISO)
#include directories
include_directories("${PROJECT_SOURCE_DIR}"
${SISO_INC_DIRS})
link_directories(${SISO_LIB_DIRS})
#check compiler ID
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
#message(${CMAKE_CXX_COMPILER_ID})
#message(${CMAKE_CXX_COMPILER_VERSION})
#require at least gcc 4.4
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.3)
message(FATAL_ERROR "GCC version must be at least 6.3!")
endif()
else()
message(FATAL_ERROR "The script is only tested under GNU g++ compiler")
endif()
#define build type, by default is release
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to DEBUG")
set(CMAKE_BUILD_TYPE "DEBUG")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
#set gcc flags
if(CMAKE_COMPILER_IS_GNUCXX)
if("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -fPIC -pthread -D_REENTRANT")
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -std=c++11 -fPIC -pthread -D_REENTRANT")
endif()
endif()
add_subdirectory("api")
add_subdirectory("pcome4")
add_subdirectory("pcoclhs")
add_subdirectory("apiloader")
set(DEV_HEADERS
PcoInterfaces.h)
#install header files
install(FILES ${DEV_HEADERS} DESTINATION "${CMAKE_INSTALL_INC_PATH}")
#pragma once
#include <iostream>
#include <memory>
#include <vector>
namespace PcoNS
{
using namespace std;
/**
* @brief error code
*/
enum ERROR_PCO
{
OK, /* 0 */
DOES_NOT_SUPPORT, /* 1 */
OPEN_ERROR, /* 2 */
CLOSE_ERROR, /* 3 */
GET_ERROR, /* 4 */
SET_ERROR, /* 5 */
START_ERROR, /* 6 */
RECORD_ERROR, /* 7 */
STOP_ERROR, /* 8 */
INVALID_VALUE /* 9 */
};
/**
* @brief pco interfaces
* wrapper of pco lib interfaces
* Now it only supports PCO camera with camlink interface
*/
class PcoInterfaces
{
public:
//static unique_ptr<PcoInterfaces> Instance();
PcoInterfaces() = default;
/**
* @brief destructor
*/
virtual ~PcoInterfaces() = default;
/**
* @brief open camera
* @return error code. 0 is OK see @ERROR
*/
virtual int OpenCamera() = 0;
/**
* @brief close camera
* @return error code. 0 is OK. see @ERROR
*/
virtual int CloseCamera() = 0;
/**
* @brief get module name
* @return name of module
*/
virtual const string GetModuleName() = 0;
/**
* @brief get camera max size
* @param x width
* @param y height
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetCameraMaxSize(int& x, int& y) = 0;
/**
* @brief get recording state
* @param recording state
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetRecordingState(short& shRecordingState) = 0;
/**
* @brief set recording state
* @param recording state
* @return error code. 0 is OK. see @ERROR
*/
virtual int SetRecordingState(short shRecordingState) = 0;
/**
* @brief request the current camera and power supply temperatures.
* Power supply temperature is not available with all cameras.
* If it is not available, the temperature will show 0.
* In case the sensor temperature is not available it will show 0x8000.
* @param ccd temperature
* @param camera temperature
* @param power device temperature
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetTemperature(short& shCCDTemperature,short& shCameraTemperature,short& shPowerDeviceTemperature) = 0;
/**
* @brief get/set the temperature set point for cooling the image sensor
* (only available for cooled cameras).
* If min. cooling set point (in ◦ C)
* and max. cooling set point (in ◦ C) are zero,
* then cooling is not available.
* @param temperature in Celsius
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetCoolingSetpointTemperature(short& shTemperature) = 0;
virtual int SetCoolingSetpointTemperature(short shTemperature) = 0;
/**
* @brief get/set binning
* @param bin horizontal
* @param bin vertical
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetBinning(short& shBinHorz,short& shBinVert) = 0;
virtual int SetBinning(short shBinHorz,short shBinVert) = 0;
/**
* @brief get/set ROI
* @param X0
* @param Y0
* @param X1
* @param Y1
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetROI(short& shX0,short& shY0,short& shX1,short& shY1) = 0;
virtual int SetROI(short shX0,short shY0,short shX1,short shY1) = 0;
/**
* @brief get step of ROI
* @param step on X dimension
* @param step on Y dimension
*/
virtual int GetROIStep(short& shXstep,short& shYstep) = 0;
/**
* @brief get/set active loopup table in the camera, if available.
* only available with pco.edge
* @param define LUT to be activated,0x0000 for no LUT
* @param offset:11bit value for fixed offset substraction
* before transferrring the data via the lookuptable
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetLUT(short& shIdentifier,short& shParam) = 0;
virtual int SetLUT(short shIdentifier,short shParam) = 0;
/**
* @brief get the actual size of images.
* @param size X
* @param size Y
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetSizes(short& shX,short& shY) = 0;
/**
* @brief get/set trigger mode
* @param trigger mode
* 0x0000: auto trigger
* 0x0001: software trigger
* 0x0002: external exposure and software trigger
* 0x0003: external exposure control
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetTriggerMode(short& shTriggerMode) = 0;
virtual int SetTriggerMode(short shTriggerMode) = 0;
/**
* @brief get/set pixel rate of the camera
* @param pixel rate MHz
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetPixelRate(int& nPixelRate) = 0;
virtual int SetPixelRate(int nPixelRate) = 0;
/**
* @brief set the adc operation mode of the camera, if available
* @param adc operation mode
* 0x0001: 1 ADC
* 0x0002: 2 ADCs
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetADCOperation(short& shADCNum) = 0;
virtual int SetADCOperation(short shADCNum) = 0;
/**
* @brief get/set time stamp mode
* @param mode of time stamp
* 0x0000:no time stamp
* 0x0001:BCD coded stamp in the first 14pixel
* 0x0002:BCD coded stamp in the first 14pixel+ASCIItext
* 0x0003:ASCII text only
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetTimestampMode(short& shMode) = 0;
virtual int SetTimestampMode(short shMode) = 0;
/**
* @brief get/set exposure time
* @param exposure time. unit:second
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetExposureTime(double& dExpTime) = 0;
virtual int SetExposureTime(double dExpTime) = 0;
/**
* @brief get/set delay time
* @param delay time. unit:second
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetDelayTime(double& dDelayTime) = 0;
virtual int SetDelayTime(double dDelayTime) = 0;
/**
* @brief get run time for each image
* @return run time for each image unit:second
*/
virtual double GetCOCRuntime() = 0;
/**
* @brief Gets the busy state of the camera.
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetCameraBusyStatus(short& shCameraBusyStatus) = 0;
/**
* @brief force a software trigger to the camera
* @param whether a trigger occurred or not
* @return error code. 0 is OK. see @ERROR
*/
virtual int ForceTrigger(short& shTrigger) = 0;
/**
* @brief set storage mode.
* Not all camera support this
* @param storage mode
* - 0 : Recorder
* - images are recorded and stored within the
* internal camera memory camRAM
* - live View transfers the most recent image
* to the PC (for viewing/monitoring)
* - indexed or total image readout after the
* recording has been stopped
* - 1 : FIFO
* - all images taken are transferred to the PC
* in chronological order
* - camera memory (camRAM) is used as a huge FIFO buffer to
* bypass short data transmission bottlenecks
* - if buffer overflows, the oldest images are overwritten
* - if set recorder = [stop] is sent, recording
* is stopped and the transfer of the current
* image to the PC is finished. Images not
* read are stored within the segment and
* can be read with the ReadImageFrom-Segment command.
* @return error code. 0 is OK. see @ERROR
*/
virtual int SetStorageMode(short shStorageMode) = 0;
/**
* @brief get recorder mode not all cameras support this
* @param shRecorderMode
* 0 : recorder mode + sequence buffer
* 1 : recorder mode + ring buffer
* 2 : FIFO mode
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetRecorderMode(short& shRecorderMode) = 0;
/**
* @brief set recorder mode not all cameras support this
* @param shRecorderMode
* 0 : recorder mode + sequence buffer
* 1 : recorder mode + ring buffer
* 2 : FIFO mode
* @return error code. 0 is OK. see @ERROR
*/
virtual int SetRecorderMode(short shRecorderMode) = 0;
/**
* @brief clear ram segment
Not all camera support this
* @return error code. 0 is OK. see @ERROR
*/
virtual int ClearRAMSegment() = 0;
/**
* @brief start acquisition
* @param frame numbers to acquire. Default value is 0.
* @return error code. 0 is OK. see @ERROR
*/
virtual int StartAcq(int nFrameNumbers = 0) = 0;
/**
* @brief stop acquisition
* @param frame numbers to acquire
* @return error code. 0 is OK. see @ERROR
*/
virtual int StopAcq() = 0;
/**
* @brief get one image
* @param image data
* @param image width
* @param image height
* @return error code. 0 is OK. see @ERROR
*/
virtual int GetImageData(vector<short>& vImg,int& nX,int& nY) = 0;
};
}
\ No newline at end of file
set(PCO_SDK_NAME "pcosdk")
set(SDK_LIBRARY_VERSION "0.1")
include_directories("${PROJECT_SOURCE_DIR}"
${PCOSDK_INC_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
"../api")
#link_directories(${PCOSDK_LIB_DIRS})
link_directories("/home/yuelong/lib.local/lib/pcosdk")
message(status ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB SDK_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB SDK_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
set(SDK_SHARED_FLAGS)
message(${SDK_SRC})
add_library(${PCO_SDK_NAME} SHARED ${SDK_SRC})
target_link_libraries(${PCO_SDK_NAME} ${SDK_SHARED_FLAGS})
set_target_properties(${PCO_SDK_NAME} PROPERTIES VERSION "${SDK_LIBRARY_VERSION}")
set(SDK_HEADERS
PcoAPILoader.h)
#install header files
install(FILES ${SDK_HEADERS} DESTINATION "${CMAKE_INSTALL_INC_PATH}")
#install target
install(TARGETS ${PCO_SDK_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIB_PATH})
\ No newline at end of file
#include "PcoAPILoader.h"
#include "PcoInterfaces.h"
#include "SharedLibLoader.h"
namespace PcoNS
{
sptr_ipco PcoAPILoader::GetCamera(std::string& lib_path)
{
sptr_ipco pco;
SLLoaderNS::SharedLibLoader<PcoInterfaces> pco_loader;
// try pcome4 first
std::string libpcome4 = lib_path + "/" + libname_pcome4;
if((pco_loader.OpenLib(libpcome4)) &&
(pco = pco_loader.GetInstance()) &&
(pco->OpenCamera() == 0))
return pco;
else
pco_loader.CloseLib();
//try pco clhs then
std::string libpcoclhs = lib_path + "/" + libname_pcoclhs;
if((pco_loader.OpenLib(libpcoclhs)) &&
(pco = pco_loader.GetInstance()) &&
(pco->OpenCamera() == 0))
return pco;
else
pco_loader.CloseLib();
return nullptr;
}
}
\ No newline at end of file
#pragma once
#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <dlfcn.h>
namespace PcoNS
{
class PcoInterfaces;
typedef std::shared_ptr<PcoInterfaces> sptr_ipco;
const std::string libname_pcome4 = std::string("libpcome4.so");
const std::string libname_pcoclhs = std::string("libpcoclhs.so");
class PcoAPILoader
{
public:
sptr_ipco GetCamera(std::string& lib_path);
};
}
\ No newline at end of file
#pragma once
#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <dlfcn.h>
namespace SLLoaderNS
{
using namespace std;
template<class T>
class SharedLibLoader
{
public:
SharedLibLoader(string user_constructor = "constructor",string user_destructor = "destructor")
:m_handle(nullptr),m_constructor(user_constructor),m_destructor(user_destructor)
{
}
~SharedLibLoader() = default;
bool OpenLib(string& libpath)
{
m_handle = dlopen(libpath.c_str(),RTLD_LAZY|RTLD_NOW);
if(!m_handle)
return false;
return true;
}
bool CloseLib()
{
if(dlclose(m_handle) != 0)
return false;
return true;
}
shared_ptr<T> GetInstance()
{
using allocClass = T *(*)();
using deleteClass = void (*)(T *);
auto allocFunc = reinterpret_cast<allocClass>(
dlsym(m_handle, m_constructor.c_str()));
auto deleteFunc = reinterpret_cast<deleteClass>(
dlsym(m_handle, m_destructor.c_str()));
if (!allocFunc || !deleteFunc) {
CloseLib();
std::cerr << dlerror() << std::endl;
}
return std::shared_ptr<T>(
allocFunc(),
[deleteFunc](T *p){ deleteFunc(p); });
}
private:
void* m_handle;
string m_constructor,m_destructor;
};
}
\ No newline at end of file
#find pco
find_path(PCO_INC_DIRS NAMES Cpco_com_cl_me4.h Cpco_grab_cl_me4.h Cpco_com.h
PATHS
/usr/include
/usr/local/include
/home/yuelong/lib.local/include/pco/me4
)
#path of pco path
find_library(PCO_LIB_DIRS NAMES pcocam_me4 pcofile pcolog reorderfunc
PATHS
/usr/lib/
/usr/local/lib
/home/yuelong/lib.local/lib/pco/me4
)
if(PCO_INC_DIRS AND PCO_LIB_DIRS)
SET(PCO_LIB_FOUND TRUE)
endif(PCO_INC_DIRS AND PCO_LIB_DIRS)
if(NOT PCO_LIB_FOUND)
message(FATAL_ERROR "cannot find corresponding PCO libraries.")
else(NOT PCO_LIB_FOUND)
message(STATUS "pco include path:${PCO_INC_DIRS}")
message(STATUS "pco lib path:${PCO_LIB_DIRS}")
endif(NOT PCO_LIB_FOUND)
#find pcoclhs
find_path(PCOCLHS_INC_DIRS NAMES Cpco_grab_clhs.h Cpco_com.h
PATHS
/usr/include
/usr/local/include
/home/yuelong/lib.local/include/pco/clhs
)
#path of pcoclhs path
find_library(PCOCLHS_LIB_DIRS NAMES pcocam_clhs pcoclhs pcofile pcolog
PATHS
/usr/lib/
/usr/local/lib
/home/yuelong/lib.local/lib/pco/clhs
)
if(PCOCLHS_INC_DIRS AND PCOCLHS_LIB_DIRS)
SET(PCOCLHS_LIB_FOUND TRUE)
endif(PCOCLHS_INC_DIRS AND PCOCLHS_LIB_DIRS)
if(NOT PCOCLHS_LIB_FOUND)
message(FATAL_ERROR "cannot find corresponding libraries.")
else(NOT PCOCLHS_LIB_FOUND)
message(STATUS "pcoclhs include path:${PCOCLHS_INC_DIRS}")
message(STATUS "pcoclhs lib path:${PCOCLHS_LIB_DIRS}")
endif(NOT PCOCLHS_LIB_FOUND)
<
#find siso
find_path(SISO_INC_DIRS NAMES clser.h
PATHS
/usr/include
/usr/local/include
/home/yuelong/lib.local/include/siso560
)
#path of pco path
find_library(SISO_LIB_DIRS NAMES fglib5 clsersis haprt
PATHS