Commit d3c38413 authored by ahoms's avatar ahoms
Browse files

* formalized stripe concatenation in HwBufferMgr

* implemented frame accumulation (callbacks) in BufferCtrlMgr
* added HwRoiCtrlObj, implemented Frelon Rois
* using SoftRoi processlib task in testfreloninterface
* moved checkBin to Frelon::Camera
* added Roi-of-Roi (subRoi) management
* fixed and added new sip files; first full lima module in Python
* implemented some missing functions (HwShutterCtrlObj, BufferSave)
* added LimaConvertor.h with HwCap to CtrlObj conversion
* added global build directory with liblima.so; compiling code with -fPIC
* added HwFrameInfo::isValid method



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@110 45c4679d-1946-429d-baad-37912b19538b
parent 1ac72926
sub-dirs = third-party control common hardware camera sub-dirs = third-party control common hardware camera build
include global.inc include global.inc
lima-objs := ../common/src/Common.o \
../hardware/src/Hw.o \
../control/src/Ct.o \
../camera/simulator/src/Simu.o \
../camera/common/espia/src/Espia.o \
../camera/frelon/src/Frelon.o
OS := $(shell /csadmin/common/scripts/get_os.share)
ifeq ($(OS),redhate5)
ARCH := $(shell /csadmin/common/scripts/get_esrflinux --architecture)
else
ARCH :=
endif
LDFLAGS += -L../third-party/Processlib/build \
-L /users/blissadm/driver/$(OS)/lib/$(ARCH)
LDLIBS += -lprocesslib -lespia
liblima.so: $(lima-objs)
$(CXX) -shared -o $@ -fPIC $+ $(LDFLAGS) $(LDLIBS)
...@@ -18,15 +18,16 @@ class BufferMgr : public BufferCbMgr ...@@ -18,15 +18,16 @@ class BufferMgr : public BufferCbMgr
virtual Cap getCap(); virtual Cap getCap();
virtual int getMaxNbBuffers(const FrameDim& frame_dim); virtual int getMaxNbBuffers(const FrameDim& frame_dim,
virtual void allocBuffers(int nb_buffers, int concat_frames, int nb_concat_frames);
virtual void allocBuffers(int nb_buffers, int nb_concat_frames,
const FrameDim& frame_dim); const FrameDim& frame_dim);
virtual const FrameDim& getFrameDim(); virtual const FrameDim& getFrameDim();
virtual void getNbBuffers(int& nb_buffers); virtual void getNbBuffers(int& nb_buffers);
virtual void getNbConcatFrames(int& nb_concat_frames); virtual void getNbConcatFrames(int& nb_concat_frames);
virtual void releaseBuffers(); virtual void releaseBuffers();
virtual void *getBufferPtr(int buffer_nb, int concat_frame_nb = 0); virtual void *getBufferPtr(int buffer_nb, int concat_frame_nb);
virtual void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info); virtual void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info);
......
namespace Espia
{
class Acq
{
%TypeHeaderCode
#include <EspiaDev.h>
#include <EspiaAcq.h>
using namespace lima;
%End
public:
Acq(Espia::Dev& dev);
~Acq();
// typedef struct Status {
// bool running;
// int run_nb;
// int last_frame_nb;
// } StatusType;
void bufferAlloc(int& nb_buffers, int nb_buffer_frames,
const FrameDim& frame_dim);
void bufferFree();
const FrameDim& getFrameDim();
void getNbBuffers(int& nb_buffers);
void getNbBufferFrames(int& nb_buffer_frames);
void *getBufferFramePtr(int buffer_nb, int frame_nb = 0);
void *getAcqFramePtr(int acq_frame_nb);
void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info);
void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames);
void start();
void stop();
// void getStatus(StatusType& status);
void getStartTimestamp(Timestamp& start_ts);
protected:
virtual void setFrameCallbackActive(bool cb_active);
};
}; // namespace Espia
namespace Espia
{
class Dev
{
%TypeHeaderCode
#include <EspiaDev.h>
using namespace lima;
%End
public:
Dev(int dev_nb);
~Dev();
bool isMeta();
void resetLink();
void getCcdStatus(int& ccd_status);
void getDrvOption( const std::string &opt_name, int &val /Out/);
void setDrvOption( const std::string &opt_name, int new_val,
int &old_val /Out/);
};
}; // namespace Espia
...@@ -20,15 +20,18 @@ BufferMgr::Cap BufferMgr::getCap() ...@@ -20,15 +20,18 @@ BufferMgr::Cap BufferMgr::getCap()
return Basic | Concat; return Basic | Concat;
} }
int BufferMgr::getMaxNbBuffers(const FrameDim& frame_dim) int BufferMgr::getMaxNbBuffers(const FrameDim& frame_dim,
int nb_concat_frames)
{ {
return GetDefMaxNbBuffers(frame_dim); FrameDim buffer_frame_dim;
getBufferFrameDim(frame_dim, nb_concat_frames, buffer_frame_dim);
return GetDefMaxNbBuffers(buffer_frame_dim);
} }
void BufferMgr::allocBuffers(int nb_buffers, int concat_frames, void BufferMgr::allocBuffers(int nb_buffers, int nb_concat_frames,
const FrameDim& frame_dim) const FrameDim& frame_dim)
{ {
m_acq.bufferAlloc(nb_buffers, concat_frames, frame_dim); m_acq.bufferAlloc(nb_buffers, nb_concat_frames, frame_dim);
} }
const FrameDim& BufferMgr::getFrameDim() const FrameDim& BufferMgr::getFrameDim()
......
...@@ -6,7 +6,7 @@ include ../include/espia.inc ...@@ -6,7 +6,7 @@ include ../include/espia.inc
CXXFLAGS = -I../include \ CXXFLAGS = -I../include \
-I../../../../hardware/include -I../../../../common/include \ -I../../../../hardware/include -I../../../../common/include \
-I$(ESPIA_DRV_INCL) -Wall -I$(ESPIA_DRV_INCL) -Wall -pthread -fPIC
all: clean Espia.o all: clean Espia.o
......
...@@ -41,6 +41,7 @@ class Camera ...@@ -41,6 +41,7 @@ class Camera
void setFlip(const Point& flip); void setFlip(const Point& flip);
void getFlip(Point& flip); void getFlip(Point& flip);
void checkBin(Bin& bin);
void setBin(const Bin& bin); void setBin(const Bin& bin);
void getBin(Bin& bin); void getBin(Bin& bin);
......
...@@ -134,6 +134,26 @@ class BinCtrlObj : public HwBinCtrlObj ...@@ -134,6 +134,26 @@ class BinCtrlObj : public HwBinCtrlObj
}; };
/*******************************************************************
* \class RoiCtrlObj
* \brief Control object providing Frelon Roi interface
*******************************************************************/
class RoiCtrlObj : public HwRoiCtrlObj
{
public:
RoiCtrlObj(Camera& cam);
virtual ~RoiCtrlObj();
virtual void checkRoi(const Roi& set_roi, Roi& hw_roi);
virtual void setRoi(const Roi& set_roi);
virtual void getRoi(Roi& hw_roi);
private:
Camera& m_cam;
};
/******************************************************************* /*******************************************************************
* \class Interface * \class Interface
* \brief Frelon hardware interface * \brief Frelon hardware interface
...@@ -164,6 +184,7 @@ class Interface : public HwInterface ...@@ -164,6 +184,7 @@ class Interface : public HwInterface
BufferCtrlObj m_buffer; BufferCtrlObj m_buffer;
SyncCtrlObj m_sync; SyncCtrlObj m_sync;
BinCtrlObj m_bin; BinCtrlObj m_bin;
RoiCtrlObj m_roi;
}; };
......
...@@ -208,6 +208,13 @@ void Camera::getFlip(Point& flip) ...@@ -208,6 +208,13 @@ void Camera::getFlip(Point& flip)
flip.y = (flip_mode >> 0) & 1; flip.y = (flip_mode >> 0) & 1;
} }
void Camera::checkBin(Bin& bin)
{
int bin_x = min(bin.getX(), int(MaxBinX));
int bin_y = min(bin.getY(), int(MaxBinY));
bin = Bin(bin_x, bin_y);
}
void Camera::setBin(const Bin& bin) void Camera::setBin(const Bin& bin)
{ {
if ((bin.getX() > 8) || (bin.getY() > 1024)) if ((bin.getX() > 8) || (bin.getY() > 1024))
......
...@@ -261,9 +261,36 @@ void BinCtrlObj::getBin(Bin& bin) ...@@ -261,9 +261,36 @@ void BinCtrlObj::getBin(Bin& bin)
void BinCtrlObj::checkBin(Bin& bin) void BinCtrlObj::checkBin(Bin& bin)
{ {
int bin_x = min(bin.getX(), int(MaxBinX)); m_cam.checkBin(bin);
int bin_y = min(bin.getY(), int(MaxBinY)); }
bin = Bin(bin_x, bin_y);
/*******************************************************************
* \brief RoiCtrlObj constructor
*******************************************************************/
RoiCtrlObj::RoiCtrlObj(Camera& cam)
: m_cam(cam)
{
}
RoiCtrlObj::~RoiCtrlObj()
{
}
void RoiCtrlObj::checkRoi(const Roi& set_roi, Roi& hw_roi)
{
m_cam.checkRoi(set_roi, hw_roi);
}
void RoiCtrlObj::setRoi(const Roi& roi)
{
m_cam.setRoi(roi);
}
void RoiCtrlObj::getRoi(Roi& roi)
{
m_cam.getRoi(roi);
} }
...@@ -274,7 +301,8 @@ void BinCtrlObj::checkBin(Bin& bin) ...@@ -274,7 +301,8 @@ void BinCtrlObj::checkBin(Bin& bin)
Interface::Interface(Acq& acq, BufferCtrlMgr& buffer_mgr, Interface::Interface(Acq& acq, BufferCtrlMgr& buffer_mgr,
Camera& cam) Camera& cam)
: m_acq(acq), m_buffer_mgr(buffer_mgr), m_cam(cam), : m_acq(acq), m_buffer_mgr(buffer_mgr), m_cam(cam),
m_det_info(cam), m_buffer(buffer_mgr), m_sync(acq, cam), m_bin(cam) m_det_info(cam), m_buffer(buffer_mgr), m_sync(acq, cam),
m_bin(cam), m_roi(cam)
{ {
HwDetInfoCtrlObj *det_info = &m_det_info; HwDetInfoCtrlObj *det_info = &m_det_info;
m_cap_list.push_back(HwCap(det_info)); m_cap_list.push_back(HwCap(det_info));
...@@ -288,6 +316,9 @@ Interface::Interface(Acq& acq, BufferCtrlMgr& buffer_mgr, ...@@ -288,6 +316,9 @@ Interface::Interface(Acq& acq, BufferCtrlMgr& buffer_mgr,
HwBinCtrlObj *bin = &m_bin; HwBinCtrlObj *bin = &m_bin;
m_cap_list.push_back(HwCap(bin)); m_cap_list.push_back(HwCap(bin));
HwRoiCtrlObj *roi = &m_roi;
m_cap_list.push_back(HwCap(roi));
reset(SoftReset); reset(SoftReset);
} }
...@@ -315,6 +346,7 @@ void Interface::reset(ResetLevel reset_level) ...@@ -315,6 +346,7 @@ void Interface::reset(ResetLevel reset_level)
m_sync.setTrigMode(IntTrig); m_sync.setTrigMode(IntTrig);
m_bin.setBin(Bin(1)); m_bin.setBin(Bin(1));
m_roi.setRoi(Roi());
Size image_size; Size image_size;
m_det_info.getMaxImageSize(image_size); m_det_info.getMaxImageSize(image_size);
......
...@@ -5,7 +5,7 @@ frelon-objs = FrelonBase.o FrelonSerialLine.o FrelonCamera.o FrelonInterface.o ...@@ -5,7 +5,7 @@ frelon-objs = FrelonBase.o FrelonSerialLine.o FrelonCamera.o FrelonInterface.o
CXXFLAGS = -I../include -I../../common/espia/include \ CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../hardware/include -I../../../common/include \ -I../../../hardware/include -I../../../common/include \
-I$(ESPIA_DRV_INCL) -Wall -pthread -I$(ESPIA_DRV_INCL) -Wall -pthread -fPIC
all: clean Frelon.o all: clean Frelon.o
......
...@@ -11,6 +11,7 @@ CXXFLAGS = -I../include -I../../common/espia/include \ ...@@ -11,6 +11,7 @@ CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../hardware/include -I../../../common/include \ -I../../../hardware/include -I../../../common/include \
-I../../../control/include/ \ -I../../../control/include/ \
-I../../../third-party/Processlib/core/include \ -I../../../third-party/Processlib/core/include \
-I../../../third-party/Processlib/tasks/include \
-I$(ESPIA_DRV_INCL) -Wall -pthread -I$(ESPIA_DRV_INCL) -Wall -pthread
all: clean testfrelon testfreloninterface all: clean testfrelon testfreloninterface
......
...@@ -2,27 +2,74 @@ ...@@ -2,27 +2,74 @@
#include "PoolThreadMgr.h" #include "PoolThreadMgr.h"
#include "CtSaving.h" #include "CtSaving.h"
#include "Data.h" #include "Data.h"
#include "TaskMgr.h"
#include "TaskEventCallback.h"
#include "SoftRoi.h"
#include <iostream> #include <iostream>
using namespace lima; using namespace lima;
using namespace std; using namespace std;
using namespace Tasks;
class TestFrameCallback : public HwFrameCallback class SoftRoiCallback : public TaskEventCallback
{ {
public: public:
TestFrameCallback(Frelon::Interface& hw_inter, CtSaving& buffer_save, SoftRoiCallback(Frelon::Interface& hw_inter, CtSaving& buffer_save,
Cond& acq_finished) Cond& acq_finished)
: m_hw_inter(hw_inter), m_buffer_save(buffer_save), : m_hw_inter(hw_inter), m_buffer_save(buffer_save),
m_acq_finished(acq_finished) {} m_acq_finished(acq_finished) {}
protected:
virtual bool newFrameReady(const HwFrameInfoType& frame_info); virtual void finnished(Data& data);
private: private:
Frelon::Interface& m_hw_inter; Frelon::Interface& m_hw_inter;
CtSaving& m_buffer_save; CtSaving& m_buffer_save;
Cond& m_acq_finished; Cond& m_acq_finished;
}; };
void SoftRoiCallback::finnished(Data& data)
{
m_buffer_save.frameReady(data);
HwSyncCtrlObj *hw_sync;
m_hw_inter.getHwCtrlObj(hw_sync);
int nb_frames;
hw_sync->getNbFrames(nb_frames);
if (data.frameNumber == nb_frames - 1) {
m_acq_finished.signal();
m_buffer_save.resetLastFrameNb();
}
}
class TestFrameCallback : public HwFrameCallback
{
public:
TestFrameCallback(Frelon::Interface& hw_inter, Roi& soft_roi,
CtSaving& buffer_save, Cond& acq_finished)
: m_hw_inter(hw_inter), m_soft_roi(soft_roi)
{
m_roi_cb = new SoftRoiCallback(hw_inter, buffer_save,
acq_finished);
m_roi_task = new SoftRoi();
}
~TestFrameCallback()
{
m_roi_task->unref();
m_roi_cb->unref();
}
protected:
virtual bool newFrameReady(const HwFrameInfoType& frame_info);
private:
Frelon::Interface& m_hw_inter;
Roi& m_soft_roi;
SoftRoi *m_roi_task;
SoftRoiCallback *m_roi_cb;
};
bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info) bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info)
{ {
int nb_acq_frames = m_hw_inter.getNbAcquiredFrames(); int nb_acq_frames = m_hw_inter.getNbAcquiredFrames();
...@@ -34,27 +81,35 @@ bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info) ...@@ -34,27 +81,35 @@ bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info)
<< " nb_acq_frames=" << nb_acq_frames << endl << " nb_acq_frames=" << nb_acq_frames << endl
<< " status=" << status << endl; << " status=" << status << endl;
Data aNewData = Data(); Data data = Data();
aNewData.frameNumber = frame_info.acq_frame_nb; data.frameNumber = frame_info.acq_frame_nb;
const Size &aSize = frame_info.frame_dim->getSize(); const Size &aSize = frame_info.frame_dim->getSize();
aNewData.width = aSize.getWidth(); data.width = aSize.getWidth();
aNewData.height = aSize.getHeight(); data.height = aSize.getHeight();
aNewData.type = Data::UINT16; data.type = Data::UINT16;
Buffer *aNewBuffer = new Buffer(); Buffer *buffer = new Buffer();
aNewBuffer->owner = Buffer::MAPPED; buffer->owner = Buffer::MAPPED;
aNewBuffer->data = (void*)frame_info.frame_ptr; buffer->data = (void*)frame_info.frame_ptr;
aNewData.setBuffer(aNewBuffer); data.setBuffer(buffer);
aNewBuffer->unref(); buffer->unref();
m_buffer_save.frameReady(aNewData); if (m_soft_roi.isActive()) {
Point tl = m_soft_roi.getTopLeft();
HwSyncCtrlObj *hw_sync; Point br = m_soft_roi.getBottomRight();
m_hw_inter.getHwCtrlObj(hw_sync); m_roi_task->setRoi(tl.x, br.x, tl.y, br.y);
int nb_frames;
hw_sync->getNbFrames(nb_frames); m_roi_task->setEventCallback(m_roi_cb);
if (frame_info.acq_frame_nb == nb_frames - 1)
m_acq_finished.signal(); TaskMgr *task_mgr = new TaskMgr();
task_mgr->setLinkTask(0, m_roi_task);
task_mgr->setInputData(data);
cout << " adding SoftRoi task!" << endl;
PoolThreadMgr::get().addProcess(task_mgr);
} else {
m_roi_cb->finnished(data);
}
return true; return true;
} }
...@@ -67,6 +122,24 @@ void print_status(Frelon::Interface& hw_inter) ...@@ -67,6 +122,24 @@ void print_status(Frelon::Interface& hw_inter)
cout << "status=" << status << endl; cout << "status=" << status << endl;
} }
void set_hw_roi(HwRoiCtrlObj *hw_roi, const Roi& set_roi, Roi& real_roi,
Roi& soft_roi)
{
hw_roi->setRoi(set_roi);
hw_roi->getRoi(real_roi);
if (real_roi == set_roi) {
soft_roi.reset();
} else if (real_roi.isActive() && !set_roi.isActive()) {
soft_roi = real_roi;
} else {
soft_roi = real_roi.subRoiAbs2Rel(set_roi);
}
cout << "set_roi=" << set_roi << ", real_roi=" << real_roi << ", "
<< "soft_roi=" << soft_roi << endl;
}
void test_frelon_hw_inter(bool do_reset) void test_frelon_hw_inter(bool do_reset)
{ {
Espia::Dev dev(0); Espia::Dev dev(0);
...@@ -87,13 +160,15 @@ void test_frelon_hw_inter(bool do_reset) ...@@ -87,13 +160,15 @@ void test_frelon_hw_inter(bool do_reset)
saving_par.prefix = "img"; saving_par.prefix = "img";
saving_par.suffix = ".edf"; saving_par.suffix = ".edf";
saving_par.nextNumber = 0; saving_par.nextNumber = 0;
saving_par.fileFormat = CtSaving::EDF;
saving_par.savingMode = CtSaving::AutoFrame; saving_par.savingMode = CtSaving::AutoFrame;
saving_par.overwritePolicy = CtSaving::Overwrite; saving_par.overwritePolicy = CtSaving::Overwrite;
saving_par.framesPerFile = 1; saving_par.framesPerFile = 1;
buffer_save.setParameters(saving_par); buffer_save.setParameters(saving_par);
Roi soft_roi;
Cond acq_finished; Cond acq_finished;
TestFrameCallback cb(hw_inter, buffer_save, acq_finished); TestFrameCallback cb(hw_inter, soft_roi, buffer_save, acq_finished);
HwDetInfoCtrlObj *hw_det_info; HwDetInfoCtrlObj *hw_det_info;
hw_inter.getHwCtrlObj(hw_det_info); hw_inter.getHwCtrlObj(hw_det_info);
...@@ -107,6 +182,9 @@ void test_frelon_hw_inter(bool do_reset) ...@@ -107,6 +182,9 @@ void test_frelon_hw_inter(bool do_reset)
HwBinCtrlObj *hw_bin; HwBinCtrlObj *hw_bin;
hw_inter.getHwCtrlObj(hw_bin); hw_inter.getHwCtrlObj(hw_bin);
HwRoiCtrlObj *hw_roi;
hw_inter.getHwCtrlObj(hw_roi);
if (do_reset) { if (do_reset) {
cout << "Reseting the hardware ... " << endl; cout << "Reseting the hardware ... " << endl;
hw_inter.reset(HwInterface::HardReset); hw_inter.reset(HwInterface::HardReset);
...@@ -122,6 +200,9 @@ void test_frelon_hw_inter(bool do_reset) ...@@ -122,6 +200,9 @@ void test_frelon_hw_inter(bool do_reset)
Bin bin(1); Bin bin(1);
hw_bin->setBin(bin); hw_bin->setBin(bin);
Roi set_roi, real_roi;