Commit e92ff84c authored by ahoms's avatar ahoms
Browse files

* 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) ...@@ -2,8 +2,6 @@ MAKE_CMD = $(MAKE)
all: all:
$(MAKE_CMD) -C src all $(MAKE_CMD) -C src all
test: all
$(MAKE_CMD) -C test all $(MAKE_CMD) -C test all
clean: clean:
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "HwBufferMgr.h" #include "HwBufferMgr.h"
#include "FrameBuilder.h" #include "FrameBuilder.h"
#include "ThreadUtils.h" #include "ThreadUtils.h"
#include "SizeUtils.h"
#include <ostream>
namespace lima namespace lima
{ {
...@@ -29,6 +31,11 @@ class Simulator ...@@ -29,6 +31,11 @@ class Simulator
void setExpTime(double exp_time); void setExpTime(double exp_time);
void getExpTime(double& exp_time); void getExpTime(double& exp_time);
void setBin(Bin bin);
void getBin(Bin& bin);
Status getStatus();
private: private:
class SimuThread : public CmdThread class SimuThread : public CmdThread
{ {
...@@ -41,20 +48,24 @@ class Simulator ...@@ -41,20 +48,24 @@ class Simulator
StartAcq = MaxThreadCmd, StopAcq, StartAcq = MaxThreadCmd, StopAcq,
}; };
SimuThread(Simulator& simu); SimuThread(Simulator& simu);
virtual void start();
protected: protected:
virtual void init(); virtual void init();
virtual void execCmd(int cmd); virtual void execCmd(int cmd);
private: private:
Simulator& m_simu; void execStartAcq();
Simulator& m_simu;
int m_acq_frame_nb;
}; };
friend class SimuThread; 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; FrameBuilder m_frame_builder;
double m_exp_time; double m_exp_time;
int m_nb_frames; int m_nb_frames;
...@@ -62,6 +73,8 @@ class Simulator ...@@ -62,6 +73,8 @@ class Simulator
SimuThread m_thread; SimuThread m_thread;
}; };
std::ostream& operator <<(std::ostream& os, Simulator& simu);
} // namespace lima } // namespace lima
#endif // SIMULATOR_H #endif // SIMULATOR_H
#include "Simulator.h" #include "Simulator.h"
#include <string>
#include <time.h>
#include <cmath>
using namespace lima; using namespace lima;
using namespace std;
Simulator::SimuThread::SimuThread(Simulator& simu) Simulator::SimuThread::SimuThread(Simulator& simu)
: m_simu(simu) : m_simu(simu)
{ {
start(); m_acq_frame_nb = 0;
}
void Simulator::SimuThread::start()
{
CmdThread::start();
waitStatus(Ready); waitStatus(Ready);
} }
...@@ -16,15 +26,46 @@ void Simulator::SimuThread::init() ...@@ -16,15 +26,46 @@ void Simulator::SimuThread::init()
void Simulator::SimuThread::execCmd(int cmd) 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() 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_exp_time = 1.0;
m_nb_frames = 1; m_nb_frames = 1;
m_thread.start();
} }
Simulator::~Simulator() Simulator::~Simulator()
...@@ -33,6 +74,86 @@ Simulator::~Simulator() ...@@ -33,6 +74,86 @@ Simulator::~Simulator()
BufferCtrlMgr& Simulator::getBufferMgr() 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++ testsimulator-objs = testsimulator.o
CXXFLAGS += -I../include -I../../../common/include -Wall 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) testsimulator-clean:
$(CXX) $(CXXFLAGS) test.cpp -o test $(objs) ../src/FrameBuilder.o 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 CXXFLAGS += -I../include -Wall -pthread
......
...@@ -114,7 +114,7 @@ class BufferCbMgr : public HwFrameCallbackGen ...@@ -114,7 +114,7 @@ class BufferCbMgr : public HwFrameCallbackGen
class StdBufferCbMgr : public BufferCbMgr class StdBufferCbMgr : public BufferCbMgr
{ {
public: public:
StdBufferCbMgr(BufferAllocMgr *alloc_mgr = NULL); StdBufferCbMgr(BufferAllocMgr& alloc_mgr);
virtual ~StdBufferCbMgr(); virtual ~StdBufferCbMgr();
virtual Cap getCap(); virtual Cap getCap();
...@@ -142,8 +142,7 @@ class StdBufferCbMgr : public BufferCbMgr ...@@ -142,8 +142,7 @@ class StdBufferCbMgr : public BufferCbMgr
private: private:
typedef std::vector<Timestamp> TimestampList; typedef std::vector<Timestamp> TimestampList;
BufferAllocMgr *m_alloc_mgr; BufferAllocMgr& m_alloc_mgr;
bool m_int_alloc_mgr;
TimestampList m_ts_list; TimestampList m_ts_list;
Timestamp m_start_ts; Timestamp m_start_ts;
bool m_fcb_act; bool m_fcb_act;
...@@ -162,7 +161,7 @@ class StdBufferCbMgr : public BufferCbMgr ...@@ -162,7 +161,7 @@ class StdBufferCbMgr : public BufferCbMgr
class BufferCtrlMgr class BufferCtrlMgr
{ {
public: public:
BufferCtrlMgr(BufferCbMgr *acq_buffer_mgr = NULL); BufferCtrlMgr(BufferCbMgr& acq_buffer_mgr);
~BufferCtrlMgr(); ~BufferCtrlMgr();
void setFrameDim(const FrameDim& frame_dim); void setFrameDim(const FrameDim& frame_dim);
...@@ -192,8 +191,8 @@ class BufferCtrlMgr ...@@ -192,8 +191,8 @@ class BufferCtrlMgr
BufferCbMgr& getAcqBufferMgr(); BufferCbMgr& getAcqBufferMgr();
private: private:
BufferCbMgr *m_acq_buffer_mgr; BufferCbMgr& m_acq_buffer_mgr;
bool m_int_acq_buffer_mgr; SoftBufferAllocMgr m_aux_alloc_mgr;
StdBufferCbMgr m_aux_buffer_mgr; StdBufferCbMgr m_aux_buffer_mgr;
BufferCbMgr *m_effect_buffer_mgr; BufferCbMgr *m_effect_buffer_mgr;
FrameDim m_frame_dim; FrameDim m_frame_dim;
......
...@@ -7,13 +7,40 @@ ...@@ -7,13 +7,40 @@
namespace lima 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 class HwDetInfoCtrlObj
{ {
public: public:
virtual ~HwDetInfoCtrlObj(); virtual ~HwDetInfoCtrlObj();
virtual void getMaxImageSize(Size& max_image_size) = 0; 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 getDefImageType(ImageType& def_image_type) = 0;
virtual void getCurrImageType(ImageType& curr_image_type) = 0; virtual void getCurrImageType(ImageType& curr_image_type) = 0;
...@@ -22,6 +49,15 @@ class HwDetInfoCtrlObj ...@@ -22,6 +49,15 @@ class HwDetInfoCtrlObj
virtual void getPixelSize(double& pixel_size) = 0; virtual void getPixelSize(double& pixel_size) = 0;
virtual void getDetectorType(std::string& det_type) = 0; virtual void getDetectorType(std::string& det_type) = 0;
virtual void getDetectorModel(std::string& det_model) = 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 ...@@ -71,12 +71,12 @@ class HwFrameCallbackGen
class HwFrameCallback class HwFrameCallback
{ {
public: public:
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual ~HwFrameCallback(); virtual ~HwFrameCallback();
HwFrameCallbackGen *getFrameCallbackGen() const; HwFrameCallbackGen *getFrameCallbackGen() const;
protected: protected:
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual bool newFrameReady(const FrameInfoType& frame_info) = 0; virtual bool newFrameReady(const FrameInfoType& frame_info) = 0;
private: private:
......
...@@ -125,23 +125,27 @@ void *SoftBufferAllocMgr::getBufferPtr(int buffer_nb) ...@@ -125,23 +125,27 @@ void *SoftBufferAllocMgr::getBufferPtr(int buffer_nb)
} }
/*******************************************************************
* \brief BufferCbMgr destructor
*******************************************************************/
BufferCbMgr::~BufferCbMgr()
{
}
/******************************************************************* /*******************************************************************
* \brief StdBufferCbMgr constructor * \brief StdBufferCbMgr constructor
*******************************************************************/ *******************************************************************/
StdBufferCbMgr::StdBufferCbMgr(BufferAllocMgr *alloc_mgr) StdBufferCbMgr::StdBufferCbMgr(BufferAllocMgr& alloc_mgr)
: m_alloc_mgr(alloc_mgr)
{ {
m_fcb_act = false; 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() StdBufferCbMgr::~StdBufferCbMgr()
{ {
if (m_int_alloc_mgr)
delete m_alloc_mgr;
} }
BufferCbMgr::Cap StdBufferCbMgr::getCap() BufferCbMgr::Cap StdBufferCbMgr::getCap()
...@@ -151,7 +155,7 @@ BufferCbMgr::Cap StdBufferCbMgr::getCap() ...@@ -151,7 +155,7 @@ BufferCbMgr::Cap StdBufferCbMgr::getCap()
int StdBufferCbMgr::getMaxNbBuffers(const FrameDim& frame_dim) 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, void StdBufferCbMgr::allocBuffers(int nb_buffers,
...@@ -167,7 +171,7 @@ void StdBufferCbMgr::allocBuffers(int nb_buffers, ...@@ -167,7 +171,7 @@ void StdBufferCbMgr::allocBuffers(int nb_buffers,
releaseBuffers(); releaseBuffers();
try { try {
m_alloc_mgr->allocBuffers(nb_buffers, frame_dim); m_alloc_mgr.allocBuffers(nb_buffers, frame_dim);
m_ts_list.reserve(nb_buffers); m_ts_list.reserve(nb_buffers);
for (int i = 0; i < nb_buffers; ++i) for (int i = 0; i < nb_buffers; ++i)
...@@ -180,7 +184,7 @@ void StdBufferCbMgr::allocBuffers(int nb_buffers, ...@@ -180,7 +184,7 @@ void StdBufferCbMgr::allocBuffers(int nb_buffers,
void StdBufferCbMgr::releaseBuffers() void StdBufferCbMgr::releaseBuffers()
{ {
m_alloc_mgr->releaseBuffers(); m_alloc_mgr.releaseBuffers();
m_ts_list.clear(); m_ts_list.clear();
} }
...@@ -209,27 +213,27 @@ bool StdBufferCbMgr::newFrameReady(int acq_frame_nb) ...@@ -209,27 +213,27 @@ bool StdBufferCbMgr::newFrameReady(int acq_frame_nb)
const FrameDim& StdBufferCbMgr::getFrameDim() const FrameDim& StdBufferCbMgr::getFrameDim()
{ {
return m_alloc_mgr->getFrameDim(); return m_alloc_mgr.getFrameDim();
} }