GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit e92ff84c authored by ahoms's avatar ahoms

* modified HwDetInfoCtrlObj; added MaxImageSizeCallbacks

* removed default sub-buffer manager in buffer manager constructors
* first version of simulator thread; added testsimulator



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@25 45c4679d-1946-429d-baad-37912b19538b
parent ff54f802
.PHONY: simulator
all: simulator
simulator:
make -C simulator
......@@ -2,8 +2,6 @@ MAKE_CMD = $(MAKE)
all:
$(MAKE_CMD) -C src all
test: all
$(MAKE_CMD) -C test all
clean:
......
......@@ -4,6 +4,8 @@
#include "HwBufferMgr.h"
#include "FrameBuilder.h"
#include "ThreadUtils.h"
#include "SizeUtils.h"
#include <ostream>
namespace lima
{
......@@ -29,6 +31,11 @@ class Simulator
void setExpTime(double exp_time);
void getExpTime(double& exp_time);
void setBin(Bin bin);
void getBin(Bin& bin);
Status getStatus();
private:
class SimuThread : public CmdThread
{
......@@ -41,20 +48,24 @@ class Simulator
StartAcq = MaxThreadCmd, StopAcq,
};
SimuThread(Simulator& simu);
virtual void start();
protected:
virtual void init();
virtual void execCmd(int cmd);
private:
Simulator& m_simu;
void execStartAcq();
Simulator& m_simu;
int m_acq_frame_nb;
};
friend class SimuThread;
BufferCtrlMgr m_buffer_mgr;
SoftBufferAllocMgr m_buffer_alloc_mgr;
StdBufferCbMgr m_buffer_cb_mgr;
BufferCtrlMgr m_buffer_ctrl_mgr;
FrameBuilder m_frame_builder;
double m_exp_time;
int m_nb_frames;
......@@ -62,6 +73,8 @@ class Simulator
SimuThread m_thread;
};
std::ostream& operator <<(std::ostream& os, Simulator& simu);
} // namespace lima
#endif // SIMULATOR_H
#include "Simulator.h"
#include <string>
#include <time.h>
#include <cmath>
using namespace lima;
using namespace std;
Simulator::SimuThread::SimuThread(Simulator& simu)
: m_simu(simu)
{
start();
m_acq_frame_nb = 0;
}
void Simulator::SimuThread::start()
{
CmdThread::start();
waitStatus(Ready);
}
......@@ -16,15 +26,46 @@ void Simulator::SimuThread::init()
void Simulator::SimuThread::execCmd(int cmd)
{
int status = getStatus();
switch (cmd) {
case StartAcq:
if (status != Ready)
throw LIMA_HW_EXC(InvalidValue,
"Not Ready to StartAcq");
execStartAcq();
break;
}
}
void Simulator::SimuThread::execStartAcq()
{
StdBufferCbMgr& buffer_mgr = m_simu.m_buffer_cb_mgr;
buffer_mgr.setStartTimestamp(Timestamp::now());
struct timespec treq, trem;
double exp_time = m_simu.m_exp_time;
treq.tv_sec = int(floor(exp_time));
treq.tv_nsec = int((exp_time - treq.tv_sec) * 1e9);
int nb_frames = m_simu.m_nb_frames;
int& frame_nb = m_acq_frame_nb;
for (frame_nb = 0; frame_nb < nb_frames; frame_nb++) {
setStatus(Exposure);
nanosleep(&treq, &trem);
setStatus(Readout);
}
setStatus(Ready);
}
Simulator::Simulator()
: m_thread(*this)
: m_buffer_cb_mgr(m_buffer_alloc_mgr),
m_buffer_ctrl_mgr(m_buffer_cb_mgr),
m_thread(*this)
{
m_exp_time = 1.0;
m_nb_frames = 1;
m_thread.start();
}
Simulator::~Simulator()
......@@ -33,6 +74,86 @@ Simulator::~Simulator()
BufferCtrlMgr& Simulator::getBufferMgr()
{
return m_buffer_mgr;
return m_buffer_ctrl_mgr;
}
void Simulator::setNbFrames(int nb_frames)
{
if (nb_frames < 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid nb of frames");
m_nb_frames = nb_frames;
}
void Simulator::getNbFrames(int& nb_frames)
{
nb_frames = m_nb_frames;
}
void Simulator::setExpTime(double exp_time)
{
if (exp_time <= 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid exposure time");
m_exp_time = exp_time;
}
void Simulator::getExpTime(double& exp_time)
{
exp_time = m_exp_time;
}
void Simulator::setBin(Bin bin)
{
m_frame_builder.bin_X = bin.getX();
m_frame_builder.bin_Y = bin.getY();
}
void Simulator::getBin(Bin& bin)
{
bin = Bin(m_frame_builder.bin_X, m_frame_builder.bin_Y);
}
Simulator::Status Simulator::getStatus()
{
int thread_status = m_thread.getStatus();
switch (thread_status) {
case SimuThread::Ready:
return Simulator::Ready;
case SimuThread::Exposure:
return Simulator::Exposure;
case SimuThread::Readout:
return Simulator::Readout;
default:
throw LIMA_HW_EXC(Error, "Invalid thread status");
}
}
void Simulator::startAcq()
{
m_thread.sendCmd(SimuThread::StartAcq);
m_thread.waitNotStatus(SimuThread::Ready);
}
void Simulator::stopAcq()
{
m_thread.sendCmd(SimuThread::StopAcq);
m_thread.waitStatus(SimuThread::Ready);
}
ostream& lima::operator <<(ostream& os, Simulator& simu)
{
string status;
switch (simu.getStatus()) {
case Simulator::Ready:
status = "Ready"; break;
case Simulator::Exposure:
status = "Exposure"; break;
case Simulator::Readout:
status = "Readout"; break;
default:
status = "Unknown";
}
os << "<status=" << status << ">";
return os;
}
objs = BufferSave.o
std-objs = ../../../common/src/Common.o ../../../hardware/src/Hw.o
test-objs = test.o BufferSave.o
test-ext-objs = ../src/FrameBuilder.o
CXX = g++
CXXFLAGS += -I../include -I../../../common/include -Wall
testsimulator-objs = testsimulator.o
testsimulator-ext-objs = ../src/Simulator.o ../src/FrameBuilder.o $(std-objs)
INC = -I../include -I../../../common/include -I../../../hardware/include
CXXFLAGS += $(INC) -Wall -pthread
LDFLAGS = -pthread
all: clean test testsimulator
test: $(test-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(test-ext-objs)
testsimulator: $(testsimulator-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(testsimulator-ext-objs)
clean: test-clean testsimulator-clean
test-clean:
rm -f $(test-objs) test *.edf
all: clean $(objs)
$(CXX) $(CXXFLAGS) test.cpp -o test $(objs) ../src/FrameBuilder.o
testsimulator-clean:
rm -f $(testsimulator-objs) testsimulator
clean:
rm -f $(objs) test *.edf
#include "Simulator.h"
#include <iostream>
using namespace lima;
using namespace std;
int main(int argc, char *argv[])
{
Simulator simu;
cout << "simu=" << simu << endl;
simu.startAcq();
cout << "simu=" << simu << endl;
simu.stopAcq();
cout << "simu=" << simu << endl;
return 0;
}
#include "Exceptions.h"
using namespace lima;
Exception::Exception(Layer layer, ErrorType err_type, String err_desc,
String file_name, String funct_name, int line_nr)
: m_layer(layer), m_err_type(err_type), m_err_desc(err_desc),
m_file_name(file_name), m_funct_name(funct_name), m_line_nr(line_nr)
{
}
common-objs := SizeUtils.o Timestamp.o ThreadUtils.o
common-objs := SizeUtils.o Timestamp.o ThreadUtils.o Exceptions.o
CXXFLAGS += -I../include -Wall -pthread
......
......@@ -114,7 +114,7 @@ class BufferCbMgr : public HwFrameCallbackGen
class StdBufferCbMgr : public BufferCbMgr
{
public:
StdBufferCbMgr(BufferAllocMgr *alloc_mgr = NULL);
StdBufferCbMgr(BufferAllocMgr& alloc_mgr);
virtual ~StdBufferCbMgr();
virtual Cap getCap();
......@@ -142,8 +142,7 @@ class StdBufferCbMgr : public BufferCbMgr
private:
typedef std::vector<Timestamp> TimestampList;
BufferAllocMgr *m_alloc_mgr;
bool m_int_alloc_mgr;
BufferAllocMgr& m_alloc_mgr;
TimestampList m_ts_list;
Timestamp m_start_ts;
bool m_fcb_act;
......@@ -162,7 +161,7 @@ class StdBufferCbMgr : public BufferCbMgr
class BufferCtrlMgr
{
public:
BufferCtrlMgr(BufferCbMgr *acq_buffer_mgr = NULL);
BufferCtrlMgr(BufferCbMgr& acq_buffer_mgr);
~BufferCtrlMgr();
void setFrameDim(const FrameDim& frame_dim);
......@@ -192,8 +191,8 @@ class BufferCtrlMgr
BufferCbMgr& getAcqBufferMgr();
private:
BufferCbMgr *m_acq_buffer_mgr;
bool m_int_acq_buffer_mgr;
BufferCbMgr& m_acq_buffer_mgr;
SoftBufferAllocMgr m_aux_alloc_mgr;
StdBufferCbMgr m_aux_buffer_mgr;
BufferCbMgr *m_effect_buffer_mgr;
FrameDim m_frame_dim;
......
......@@ -7,13 +7,40 @@
namespace lima
{
class HwDetInfoCtrlObj;
class HwMaxImageSizeCallback
{
public:
HwMaxImageSizeCallback() : m_det_info_ctrl_obj(NULL) {}
virtual ~HwMaxImageSizeCallback();
HwDetInfoCtrlObj *getDetInfoCtrlObj() const;
protected:
virtual void maxImageSizeChanged(const Size& size,
ImageType& image_type) = 0;
private:
friend class HwDetInfoCtrlObj;
void setDetInfoCtrlObj(HwDetInfoCtrlObj *det_info_ctrl_obj);
HwDetInfoCtrlObj *m_det_info_ctrl_obj;
};
inline HwDetInfoCtrlObj *HwMaxImageSizeCallback::getDetInfoCtrlObj() const
{
return m_det_info_ctrl_obj;
}
class HwDetInfoCtrlObj
{
public:
virtual ~HwDetInfoCtrlObj();
virtual void getMaxImageSize(Size& max_image_size) = 0;
virtual void getCurrImageSize(Size& curr_image_size) = 0;
virtual void getDetectorImageSize(Size& det_image_size) = 0;
virtual void getDefImageType(ImageType& def_image_type) = 0;
virtual void getCurrImageType(ImageType& curr_image_type) = 0;
......@@ -22,6 +49,15 @@ class HwDetInfoCtrlObj
virtual void getPixelSize(double& pixel_size) = 0;
virtual void getDetectorType(std::string& det_type) = 0;
virtual void getDetectorModel(std::string& det_model) = 0;
void registerMaxImageSizeCallback(HwMaxImageSizeCallback *cb);
void unregisterMaxImageSizeCallback(HwMaxImageSizeCallback *cb);
protected:
virtual void setMaxImageSizeCallbackActive(bool cb_active) = 0;
private:
HwMaxImageSizeCallback *m_max_image_size_cb;
};
......
......@@ -71,12 +71,12 @@ class HwFrameCallbackGen
class HwFrameCallback
{
public:
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual ~HwFrameCallback();
HwFrameCallbackGen *getFrameCallbackGen() const;
protected:
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual bool newFrameReady(const FrameInfoType& frame_info) = 0;
private:
......
......@@ -125,23 +125,27 @@ void *SoftBufferAllocMgr::getBufferPtr(int buffer_nb)
}
/*******************************************************************
* \brief BufferCbMgr destructor
*******************************************************************/
BufferCbMgr::~BufferCbMgr()
{
}
/*******************************************************************
* \brief StdBufferCbMgr constructor
*******************************************************************/
StdBufferCbMgr::StdBufferCbMgr(BufferAllocMgr *alloc_mgr)
StdBufferCbMgr::StdBufferCbMgr(BufferAllocMgr& alloc_mgr)
: m_alloc_mgr(alloc_mgr)
{
m_fcb_act = false;
m_alloc_mgr = alloc_mgr;
m_int_alloc_mgr = !alloc_mgr;
if (m_int_alloc_mgr)
m_alloc_mgr = new SoftBufferAllocMgr();
}
StdBufferCbMgr::~StdBufferCbMgr()
{
if (m_int_alloc_mgr)
delete m_alloc_mgr;
}
BufferCbMgr::Cap StdBufferCbMgr::getCap()
......@@ -151,7 +155,7 @@ BufferCbMgr::Cap StdBufferCbMgr::getCap()
int StdBufferCbMgr::getMaxNbBuffers(const FrameDim& frame_dim)
{
return m_alloc_mgr->getMaxNbBuffers(frame_dim);
return m_alloc_mgr.getMaxNbBuffers(frame_dim);
}
void StdBufferCbMgr::allocBuffers(int nb_buffers,
......@@ -167,7 +171,7 @@ void StdBufferCbMgr::allocBuffers(int nb_buffers,
releaseBuffers();
try {
m_alloc_mgr->allocBuffers(nb_buffers, frame_dim);
m_alloc_mgr.allocBuffers(nb_buffers, frame_dim);
m_ts_list.reserve(nb_buffers);
for (int i = 0; i < nb_buffers; ++i)
......@@ -180,7 +184,7 @@ void StdBufferCbMgr::allocBuffers(int nb_buffers,
void StdBufferCbMgr::releaseBuffers()
{
m_alloc_mgr->releaseBuffers();
m_alloc_mgr.releaseBuffers();
m_ts_list.clear();
}
......@@ -209,27 +213,27 @@ bool StdBufferCbMgr::newFrameReady(int acq_frame_nb)
const FrameDim& StdBufferCbMgr::getFrameDim()
{
return m_alloc_mgr->getFrameDim();
return m_alloc_mgr.getFrameDim();
}
int StdBufferCbMgr::getNbBuffers()
{
return m_alloc_mgr->getNbBuffers();
return m_alloc_mgr.getNbBuffers();
}
void *StdBufferCbMgr::getBufferPtr(int buffer_nb)
{
return m_alloc_mgr->getBufferPtr(buffer_nb);
return m_alloc_mgr.getBufferPtr(buffer_nb);
}
void StdBufferCbMgr::clearBuffer(int buffer_nb)
{
m_alloc_mgr->clearBuffer(buffer_nb);
m_alloc_mgr.clearBuffer(buffer_nb);
}
void StdBufferCbMgr::clearAllBuffers()
{
m_alloc_mgr->clearAllBuffers();
m_alloc_mgr.clearAllBuffers();
}
Timestamp StdBufferCbMgr::getBufferTimestamp(int buffer_nb)
......@@ -244,24 +248,20 @@ Timestamp StdBufferCbMgr::getBufferTimestamp(int buffer_nb)
* \brief BufferCtrlMgr constructor
*******************************************************************/
BufferCtrlMgr::BufferCtrlMgr(BufferCbMgr *acq_buffer_mgr)
BufferCtrlMgr::BufferCtrlMgr(BufferCbMgr& acq_buffer_mgr)
: m_acq_buffer_mgr(acq_buffer_mgr),
m_aux_buffer_mgr(m_aux_alloc_mgr)
{
m_acq_buffer_mgr = acq_buffer_mgr;
m_int_acq_buffer_mgr = (acq_buffer_mgr == NULL);
if (m_int_acq_buffer_mgr)
m_acq_buffer_mgr = new StdBufferCbMgr();
}
BufferCtrlMgr::~BufferCtrlMgr()
{
if (m_int_acq_buffer_mgr)
delete m_acq_buffer_mgr;
}
void BufferCtrlMgr::setFrameDim(const FrameDim& frame_dim)
{
if (frame_dim != m_frame_dim)
m_acq_buffer_mgr->releaseBuffers();
m_acq_buffer_mgr.releaseBuffers();
m_frame_dim = frame_dim;
}
......@@ -273,29 +273,33 @@ void BufferCtrlMgr::getFrameDim(FrameDim& frame_dim)
void BufferCtrlMgr::setNbBuffers(int nb_buffers)
{
if (nb_buffers == m_acq_buffer_mgr->getNbBuffers())
if (nb_buffers == m_acq_buffer_mgr.getNbBuffers())
return;
m_acq_buffer_mgr->allocBuffers(nb_buffers, m_frame_dim);
m_acq_buffer_mgr.allocBuffers(nb_buffers, m_frame_dim);
}
void BufferCtrlMgr::getNbBuffers(int& nb_buffers)
{
nb_buffers = m_acq_buffer_mgr->getNbBuffers();
nb_buffers = m_acq_buffer_mgr.getNbBuffers();
}
void BufferCtrlMgr::getMaxNbBuffers(int& max_nb_buffers)
{
max_nb_buffers = m_acq_buffer_mgr->getMaxNbBuffers(m_frame_dim);
max_nb_buffers = m_acq_buffer_mgr.getMaxNbBuffers(m_frame_dim);
}
void BufferCtrlMgr::registerFrameCallback(HwFrameCallback *frame_cb)
{
m_acq_buffer_mgr->registerFrameCallback(frame_cb);
m_acq_buffer_mgr.registerFrameCallback(frame_cb);
}
void BufferCtrlMgr::unregisterFrameCallback(HwFrameCallback *frame_cb)
{
m_acq_buffer_mgr->unregisterFrameCallback(frame_cb);
m_acq_buffer_mgr.unregisterFrameCallback(frame_cb);
}
BufferCbMgr& BufferCtrlMgr::getAcqBufferMgr()
{
return m_acq_buffer_mgr;
}
......@@ -2,6 +2,38 @@
using namespace lima;
void
HwMaxImageSizeCallback::setDetInfoCtrlObj(HwDetInfoCtrlObj *det_info_ctrl_obj)
{
m_det_info_ctrl_obj = det_info_ctrl_obj;
}
HwDetInfoCtrlObj::~HwDetInfoCtrlObj()
{
m_max_image_size_cb = NULL;
}
void
HwDetInfoCtrlObj::registerMaxImageSizeCallback(HwMaxImageSizeCallback *cb)
{
if (m_max_image_size_cb != NULL)
throw LIMA_HW_EXC(InvalidValue,
"An ImageSizeCallback already registered");
cb->setDetInfoCtrlObj(this);
m_max_image_size_cb = cb;
setMaxImageSizeCallbackActive(true);
}
void
HwDetInfoCtrlObj::unregisterMaxImageSizeCallback(HwMaxImageSizeCallback *cb)
{
if (m_max_image_size_cb != cb)
throw LIMA_HW_EXC(InvalidValue,
"ImageSizeCallback is not registered");
setMaxImageSizeCallbackActive(false);
m_max_image_size_cb = NULL;
cb->setDetInfoCtrlObj(NULL);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment