Commit d3c38413 authored by ahoms's avatar ahoms

* 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
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
virtual Cap getCap();
virtual int getMaxNbBuffers(const FrameDim& frame_dim);
virtual void allocBuffers(int nb_buffers, int concat_frames,
virtual int getMaxNbBuffers(const FrameDim& frame_dim,
int nb_concat_frames);
virtual void allocBuffers(int nb_buffers, int nb_concat_frames,
const FrameDim& frame_dim);
virtual const FrameDim& getFrameDim();
virtual void getNbBuffers(int& nb_buffers);
virtual void getNbConcatFrames(int& nb_concat_frames);
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);
......
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()
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)
{
m_acq.bufferAlloc(nb_buffers, concat_frames, frame_dim);
m_acq.bufferAlloc(nb_buffers, nb_concat_frames, frame_dim);
}
const FrameDim& BufferMgr::getFrameDim()
......
......@@ -6,7 +6,7 @@ include ../include/espia.inc
CXXFLAGS = -I../include \
-I../../../../hardware/include -I../../../../common/include \
-I$(ESPIA_DRV_INCL) -Wall
-I$(ESPIA_DRV_INCL) -Wall -pthread -fPIC
all: clean Espia.o
......
......@@ -41,6 +41,7 @@ class Camera
void setFlip(const Point& flip);
void getFlip(Point& flip);
void checkBin(Bin& bin);
void setBin(const Bin& bin);
void getBin(Bin& bin);
......
......@@ -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
* \brief Frelon hardware interface
......@@ -164,6 +184,7 @@ class Interface : public HwInterface
BufferCtrlObj m_buffer;
SyncCtrlObj m_sync;
BinCtrlObj m_bin;
RoiCtrlObj m_roi;
};
......
......@@ -208,6 +208,13 @@ void Camera::getFlip(Point& flip)
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)
{
if ((bin.getX() > 8) || (bin.getY() > 1024))
......
......@@ -261,9 +261,36 @@ void BinCtrlObj::getBin(Bin& bin)
void BinCtrlObj::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);
m_cam.checkBin(bin);
}
/*******************************************************************
* \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)
Interface::Interface(Acq& acq, BufferCtrlMgr& buffer_mgr,
Camera& 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;
m_cap_list.push_back(HwCap(det_info));
......@@ -288,6 +316,9 @@ Interface::Interface(Acq& acq, BufferCtrlMgr& buffer_mgr,
HwBinCtrlObj *bin = &m_bin;
m_cap_list.push_back(HwCap(bin));
HwRoiCtrlObj *roi = &m_roi;
m_cap_list.push_back(HwCap(roi));
reset(SoftReset);
}
......@@ -315,6 +346,7 @@ void Interface::reset(ResetLevel reset_level)
m_sync.setTrigMode(IntTrig);
m_bin.setBin(Bin(1));
m_roi.setRoi(Roi());
Size image_size;
m_det_info.getMaxImageSize(image_size);
......
......@@ -5,7 +5,7 @@ frelon-objs = FrelonBase.o FrelonSerialLine.o FrelonCamera.o FrelonInterface.o
CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../hardware/include -I../../../common/include \
-I$(ESPIA_DRV_INCL) -Wall -pthread
-I$(ESPIA_DRV_INCL) -Wall -pthread -fPIC
all: clean Frelon.o
......
......@@ -11,6 +11,7 @@ CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../hardware/include -I../../../common/include \
-I../../../control/include/ \
-I../../../third-party/Processlib/core/include \
-I../../../third-party/Processlib/tasks/include \
-I$(ESPIA_DRV_INCL) -Wall -pthread
all: clean testfrelon testfreloninterface
......
......@@ -2,27 +2,74 @@
#include "PoolThreadMgr.h"
#include "CtSaving.h"
#include "Data.h"
#include "TaskMgr.h"
#include "TaskEventCallback.h"
#include "SoftRoi.h"
#include <iostream>
using namespace lima;
using namespace std;
using namespace Tasks;
class TestFrameCallback : public HwFrameCallback
class SoftRoiCallback : public TaskEventCallback
{
public:
TestFrameCallback(Frelon::Interface& hw_inter, CtSaving& buffer_save,
Cond& acq_finished)
SoftRoiCallback(Frelon::Interface& hw_inter, CtSaving& buffer_save,
Cond& acq_finished)
: m_hw_inter(hw_inter), m_buffer_save(buffer_save),
m_acq_finished(acq_finished) {}
protected:
virtual bool newFrameReady(const HwFrameInfoType& frame_info);
virtual void finnished(Data& data);
private:
Frelon::Interface& m_hw_inter;
CtSaving& m_buffer_save;
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)
{
int nb_acq_frames = m_hw_inter.getNbAcquiredFrames();
......@@ -34,27 +81,35 @@ bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info)
<< " nb_acq_frames=" << nb_acq_frames << endl
<< " status=" << status << endl;
Data aNewData = Data();
aNewData.frameNumber = frame_info.acq_frame_nb;
Data data = Data();
data.frameNumber = frame_info.acq_frame_nb;
const Size &aSize = frame_info.frame_dim->getSize();
aNewData.width = aSize.getWidth();
aNewData.height = aSize.getHeight();
aNewData.type = Data::UINT16;
data.width = aSize.getWidth();
data.height = aSize.getHeight();
data.type = Data::UINT16;
Buffer *aNewBuffer = new Buffer();
aNewBuffer->owner = Buffer::MAPPED;
aNewBuffer->data = (void*)frame_info.frame_ptr;
aNewData.setBuffer(aNewBuffer);
aNewBuffer->unref();
m_buffer_save.frameReady(aNewData);
HwSyncCtrlObj *hw_sync;
m_hw_inter.getHwCtrlObj(hw_sync);
int nb_frames;
hw_sync->getNbFrames(nb_frames);
if (frame_info.acq_frame_nb == nb_frames - 1)
m_acq_finished.signal();
Buffer *buffer = new Buffer();
buffer->owner = Buffer::MAPPED;
buffer->data = (void*)frame_info.frame_ptr;
data.setBuffer(buffer);
buffer->unref();
if (m_soft_roi.isActive()) {
Point tl = m_soft_roi.getTopLeft();
Point br = m_soft_roi.getBottomRight();
m_roi_task->setRoi(tl.x, br.x, tl.y, br.y);
m_roi_task->setEventCallback(m_roi_cb);
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;
}
......@@ -67,6 +122,24 @@ void print_status(Frelon::Interface& hw_inter)
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)
{
Espia::Dev dev(0);
......@@ -87,13 +160,15 @@ void test_frelon_hw_inter(bool do_reset)
saving_par.prefix = "img";
saving_par.suffix = ".edf";
saving_par.nextNumber = 0;
saving_par.fileFormat = CtSaving::EDF;
saving_par.savingMode = CtSaving::AutoFrame;
saving_par.overwritePolicy = CtSaving::Overwrite;
saving_par.framesPerFile = 1;
buffer_save.setParameters(saving_par);
Roi soft_roi;
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;
hw_inter.getHwCtrlObj(hw_det_info);
......@@ -107,6 +182,9 @@ void test_frelon_hw_inter(bool do_reset)
HwBinCtrlObj *hw_bin;
hw_inter.getHwCtrlObj(hw_bin);
HwRoiCtrlObj *hw_roi;
hw_inter.getHwCtrlObj(hw_roi);
if (do_reset) {
cout << "Reseting the hardware ... " << endl;
hw_inter.reset(HwInterface::HardReset);
......@@ -122,6 +200,9 @@ void test_frelon_hw_inter(bool do_reset)
Bin bin(1);
hw_bin->setBin(bin);
Roi set_roi, real_roi;
set_hw_roi(hw_roi, set_roi, real_roi, soft_roi);
FrameDim effect_frame_dim = frame_dim / bin;
hw_buffer->setFrameDim(effect_frame_dim);
hw_buffer->setNbBuffers(10);
......@@ -130,6 +211,7 @@ void test_frelon_hw_inter(bool do_reset)
print_status(hw_inter);
hw_inter.startAcq();
acq_finished.wait();
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
......@@ -139,6 +221,7 @@ void test_frelon_hw_inter(bool do_reset)
print_status(hw_inter);
hw_inter.startAcq();
acq_finished.wait();
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
......@@ -149,6 +232,7 @@ void test_frelon_hw_inter(bool do_reset)
print_status(hw_inter);
hw_inter.startAcq();
acq_finished.wait();
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
......@@ -178,6 +262,34 @@ void test_frelon_hw_inter(bool do_reset)
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
set_roi = Roi(Point(256, 256), Size(512, 512));
set_hw_roi(hw_roi, set_roi, real_roi, soft_roi);
effect_frame_dim.setSize(real_roi.getSize());
hw_buffer->setFrameDim(effect_frame_dim);
hw_buffer->setNbBuffers(10);
print_status(hw_inter);
hw_inter.startAcq();
acq_finished.wait();
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
set_roi = Roi(Point(267, 267), Size(501, 501));
set_hw_roi(hw_roi, set_roi, real_roi, soft_roi);
effect_frame_dim.setSize(real_roi.getSize());
hw_buffer->setFrameDim(effect_frame_dim);
hw_buffer->setNbBuffers(10);
print_status(hw_inter);
hw_inter.startAcq();
acq_finished.wait();
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
}
int main(int argc, char *argv[])
......
......@@ -3,7 +3,7 @@ simu-objs = FrameBuilder.o Simulator.o SimuHwInterface.o
CXX = g++
INC = -I../include -I../../../common/include -I../../../hardware/include
CXXFLAGS += $(INC) -Wall -pthread
CXXFLAGS += $(INC) -Wall -pthread -fPIC
all: clean Simu.o
......
......@@ -60,12 +60,13 @@ void Simulator::SimuThread::execStartAcq()
}
setStatus(Readout);
int nb_buffers;
buffer_mgr.getNbBuffers(nb_buffers);
int buffer_nb = frame_nb % nb_buffers;
int buffer_nb, concat_frame_nb;
buffer_mgr.acqFrameNb2BufferNb(frame_nb, buffer_nb,
concat_frame_nb);
void *ptr = buffer_mgr.getBufferPtr(buffer_nb,
concat_frame_nb);
typedef unsigned char *BufferPtr;
BufferPtr ptr = BufferPtr(buffer_mgr.getBufferPtr(buffer_nb));
frame_builder.getNextFrame(ptr);
frame_builder.getNextFrame(BufferPtr(ptr));
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame_nb;
......
......@@ -354,6 +354,9 @@ class Roi
void alignSizeTo(const Point& p, AlignDir align_dir);
void alignCornersTo(const Point& p, AlignDir align_dir);
Roi subRoiRel2Abs(const Roi& rel_sub_roi) const;
Roi subRoiAbs2Rel(const Roi& abs_sub_roi) const;
private:
static bool isValidCoord(int i);
static Point checkCorner(const Point& TopLeft);
......
......@@ -84,6 +84,11 @@ void BufferSave::closeFile()
m_idx++;
}
void BufferSave::getOpenFileName(std::string& file_name) const
{
file_name = m_file_name;
}
void BufferSave::writeEdfHeader( const HwFrameInfoType& finfo )
{
time_t ctime_now;
......
......@@ -2,7 +2,7 @@
common-objs := Constants.o SizeUtils.o Timestamp.o ThreadUtils.o Exceptions.o \
BufferSave.o MemUtils.o RegEx.o
CXXFLAGS += -I../include -I../../hardware/include -Wall -pthread
CXXFLAGS += -I../include -I../../hardware/include -Wall -pthread -fPIC
all: clean Common.o
......
......@@ -47,6 +47,7 @@ const Corner lima::TopRight (Right, Top);
const Corner lima::BottomLeft (Left, Bottom);
const Corner lima::BottomRight(Right, Bottom);
/*******************************************************************
* \brief X/YBorder and Corner ostream << operators
*******************************************************************/
......@@ -99,6 +100,23 @@ void Roi::setCorners(const Point& p1, const Point& p2)
m_size = bottom_right + 1 - m_top_left;
}
Roi Roi::subRoiRel2Abs(const Roi& rel_sub_roi) const
{
Roi aux(0, getSize());