Commit 6ab2e0d1 authored by ahoms's avatar ahoms
Browse files

* removed BufferMode from the hardware layer (belongs to control)

* introduced Concat/Acc acq modes in BufferCtrlMgr (not implemented yet)
* added Simulator latency time; fixed getMax/DectectorImageSize
* added Simulator Buffer & Sync control objects
* implemented SimuHwInterface reset, start/stopAcq and getStatus



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@43 45c4679d-1946-429d-baad-37912b19538b
parent f693333f
......@@ -9,6 +9,11 @@ namespace lima
class SimuHwInterface;
/*******************************************************************
* \class SimuDetInfoCtrlObj
* \brief Control object providing simulator detector info interface
*******************************************************************/
class SimuDetInfoCtrlObj : public HwDetInfoCtrlObj
{
public:
......@@ -35,6 +40,81 @@ class SimuDetInfoCtrlObj : public HwDetInfoCtrlObj
};
/*******************************************************************
* \class SimuBufferCtrlObj
* \brief Control object providing simulator buffering interface
*******************************************************************/
class SimuBufferCtrlObj : public HwBufferCtrlObj
{
public:
SimuBufferCtrlObj(Simulator& simu);
virtual ~SimuBufferCtrlObj();
virtual void setFrameDim(const FrameDim& frame_dim);
virtual void getFramedim( FrameDim& frame_dim);
virtual void setNbBuffers(int nb_buffers);
virtual void getNbBuffers(int& nb_buffers);
virtual void setNbConcatFrames(int nb_concat_frames);
virtual void getNbConcatFrames(int& nb_concat_frames);
virtual void setNbAccFrames(int nb_acc_frames);
virtual void getNbAccFrames(int& nb_acc_frames);
virtual void getMaxNbBuffers(int& max_nb_buffers);
virtual void *getBufferPtr(int buffer_nb);
virtual void *getFramePtr(int acq_frame_nb);
virtual void getStartTimestamp(Timestamp& start_ts);
virtual void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info);
virtual void registerFrameCallback(HwFrameCallback *frame_cb);
virtual void unregisterFrameCallback(HwFrameCallback *frame_cb);
private:
Simulator& m_simu;
BufferCtrlMgr& m_buffer_mgr;
};
/*******************************************************************
* \class SimuSyncCtrlObj
* \brief Control object providing simulator synchronization interface
*******************************************************************/
class SimuSyncCtrlObj : public HwSyncCtrlObj
{
public:
SimuSyncCtrlObj(Simulator& simu);
virtual ~SimuSyncCtrlObj();
virtual void setTrigMode(TrigMode trig_mode);
virtual void getTrigMode(TrigMode& trig_mode);
virtual void setExpTime(double exp_time);
virtual void getExpTime(double& exp_time);
virtual void setLatTime(double lat_time);
virtual void getLatTime(double& lat_time);
virtual void setNbFrames(int nb_frames);
virtual void getNbFrames(int& nb_frames);
virtual void getValidRanges(ValidRangesType& valid_ranges);
private:
Simulator& m_simu;
};
/*******************************************************************
* \class SimuHwInterface
* \brief Simulator hardware interface
*******************************************************************/
class SimuHwInterface : public HwInterface
{
public:
......@@ -54,6 +134,8 @@ class SimuHwInterface : public HwInterface
Simulator& m_simu;
CapList m_cap_list;
SimuDetInfoCtrlObj m_det_info;
SimuBufferCtrlObj m_buffer;
SimuSyncCtrlObj m_sync;
};
}
......
......@@ -14,7 +14,7 @@ class Simulator
{
public:
enum Status {
Ready, Exposure, Readout,
Ready, Exposure, Readout, Latency,
};
Simulator();
......@@ -31,6 +31,9 @@ class Simulator
void setExpTime(double exp_time);
void getExpTime(double& exp_time);
void setLatTime(double lat_time);
void getLatTime(double& lat_time);
void setBin(const Bin& bin);
void getBin(Bin& bin);
......@@ -40,12 +43,16 @@ class Simulator
Status getStatus();
int getNbAcquiredFrames();
void getMaxImageSize(Size& max_image_size);
void reset();
private:
class SimuThread : public CmdThread
{
public:
enum { // Status
Ready = MaxThreadStatus, Exposure, Readout,
Ready = MaxThreadStatus, Exposure, Readout, Latency,
};
enum { // Cmd
......@@ -76,6 +83,7 @@ class Simulator
BufferCtrlMgr m_buffer_ctrl_mgr;
FrameBuilder m_frame_builder;
double m_exp_time;
double m_lat_time;
int m_nb_frames;
SimuThread m_thread;
......
......@@ -2,6 +2,10 @@
using namespace lima;
/*******************************************************************
* \brief SimuDetInfoCtrlObj constructor
*******************************************************************/
SimuDetInfoCtrlObj::SimuDetInfoCtrlObj(Simulator& simu)
: m_simu(simu)
{
......@@ -14,15 +18,14 @@ SimuDetInfoCtrlObj::~SimuDetInfoCtrlObj()
void SimuDetInfoCtrlObj::getMaxImageSize(Size& max_image_size)
{
int max_dim = 8 * 1024;
max_image_size = Size(max_dim, max_dim);
FrameDim fdim;
m_simu.getFrameDim(fdim);
det_image_size = fdim.getSize();
}
void SimuDetInfoCtrlObj::getDetectorImageSize(Size& det_image_size)
{
FrameDim fdim;
m_simu.getFrameDim(fdim);
det_image_size = fdim.getSize();
m_simu.getMaxImageSize(max_image_size);
}
void SimuDetInfoCtrlObj::getDefImageType(ImageType& def_image_type)
......@@ -66,19 +69,180 @@ void SimuDetInfoCtrlObj::setMaxImageSizeCallbackActive(bool cb_active)
}
/*******************************************************************
* \brief SimuBufferCtrlObj constructor
*******************************************************************/
SimuBufferCtrlObj::SimuBufferCtrlObj(Simulator& simu)
: m_simu(simu),
m_buffer_mgr(simu.getBufferMgr())
{
}
SimuBufferCtrlObj::~SimuBufferCtrlObj()
{
}
void SimuBufferCtrlObj::setFrameDim(const FrameDim& frame_dim)
{
m_buffer_mgr.setFrameDim(frame_dim);
}
void SimuBufferCtrlObj::getFramedim(FrameDim& frame_dim)
{
m_buffer_mgr.getFrameDim(frame_dim);
}
void SimuBufferCtrlObj::setNbBuffers(int nb_buffers)
{
m_buffer_mgr.setNbBuffers(nb_buffers);
}
void SimuBufferCtrlObj::getNbBuffers(int& nb_buffers)
{
m_buffer_mgr.getNbBuffers(nb_buffers);
}
void SimuBufferCtrlObj::setNbConcatFrames(int nb_concat_frames)
{
m_buffer_mgr.setNbConcatFrames(nb_concat_frames);
}
void SimuBufferCtrlObj::getNbConcatFrames(int& nb_concat_frames)
{
m_buffer_mgr.getNbConcatFrames(nb_concat_frames);
}
void SimuBufferCtrlObj::setNbAccFrames(int nb_acc_frames)
{
m_buffer_mgr.setNbAccFrames(nb_acc_frames);
}
void SimuBufferCtrlObj::getNbAccFrames(int& nb_acc_frames)
{
m_buffer_mgr.getNbAccFrames(nb_acc_frames);
}
void SimuBufferCtrlObj::getMaxNbBuffers(int& max_nb_buffers)
{
m_buffer_mgr.getMaxNbBuffers(max_nb_buffers);
}
void *SimuBufferCtrlObj::getBufferPtr(int buffer_nb)
{
return m_buffer_mgr.getBufferPtr(buffer_nb);
}
void *SimuBufferCtrlObj::getFramePtr(int acq_frame_nb)
{
return m_buffer_mgr.getFramePtr(acq_frame_nb);
}
void SimuBufferCtrlObj::getStartTimestamp(Timestamp& start_ts)
{
m_buffer_mgr.getStartTimestamp(start_ts);
}
void SimuBufferCtrlObj::getFrameInfo(int acq_frame_nb, HwFrameInfoType& info)
{
m_buffer_mgr.getFrameInfo(acq_frame_nb, info);
}
void SimuBufferCtrlObj::registerFrameCallback(HwFrameCallback *frame_cb)
{
m_buffer_mgr.registerFrameCallback(frame_cb);
}
void SimuBufferCtrlObj::unregisterFrameCallback(HwFrameCallback *frame_cb)
{
m_buffer_mgr.unregisterFrameCallback(frame_cb);
}
/*******************************************************************
* \brief SimuSyncCtrlObj constructor
*******************************************************************/
SimuSyncCtrlObj::SimuSyncCtrlObj(Simulator& simu)
: m_simu(simu)
{
}
SimuSyncCtrlObj::~SimuSyncCtrlObj()
{
}
void SimuSyncCtrlObj::setTrigMode(TrigMode trig_mode)
{
trig_mode = IntTrig;
}
void SimuSyncCtrlObj::getTrigMode(TrigMode& trig_mode)
{
if (trig_mode != IntTrig)
throw LIMA_HW_EXC(InvalidValue, "Invalid (external) trigger");
}
void SimuSyncCtrlObj::setExpTime(double exp_time)
{
m_simu.setExpTime(exp_time);
}
void SimuSyncCtrlObj::getExpTime(double& exp_time)
{
m_simu.getExpTime(exp_time);
}
void SimuSyncCtrlObj::setLatTime(double lat_time)
{
m_simu.setLatTime(lat_time);
}
void SimuSyncCtrlObj::getLatTime(double& lat_time)
{
m_simu.getLatTime(lat_time);
}
void SimuSyncCtrlObj::setNbFrames(int nb_frames)
{
m_simu.setNbFrames(nb_frames);
}
void SimuSyncCtrlObj::getNbFrames(int& nb_frames)
{
m_simu.getNbFrames(nb_frames);
}
void SimuSyncCtrlObj::getValidRanges(ValidRangesType& valid_ranges)
{
double min_time = 10e-9;;
double max_time = 1e6;
valid_ranges.min_exp_time = min_time;
valid_ranges.max_exp_time = max_time;
valid_ranges.min_lat_time = min_time;
valid_ranges.max_lat_time = max_time;
}
/*******************************************************************
* \brief SimuHwInterface constructor
*******************************************************************/
SimuHwInterface::SimuHwInterface(Simulator& simu)
: m_simu(simu), m_det_info(simu)
: m_simu(simu), m_det_info(simu), m_buffer(simu), m_sync(simu)
{
HwCap cap = HwCap(HwCap::DetInfo, &m_det_info);
m_cap_list.push_back(cap);
cap = HwCap(HwCap::Buffer, &m_buffer);
m_cap_list.push_back(cap);
cap = HwCap(HwCap::Sync, &m_sync);
m_cap_list.push_back(cap);
}
SimuHwInterface::~SimuHwInterface()
{
}
const HwInterface::CapList& SimuHwInterface::getCapList() const
......@@ -88,29 +252,44 @@ const HwInterface::CapList& SimuHwInterface::getCapList() const
void SimuHwInterface::reset(ResetLevel reset_level)
{
m_simu.reset();
}
void SimuHwInterface::prepareAcq()
{
}
void SimuHwInterface::startAcq()
{
BufferCtrlMgr& buffer_mgr = m_simu.getBufferMgr();
buffer_mgr.setStartTimestamp(Timestamp::now());
m_simu.startAcq();
}
void SimuHwInterface::stopAcq()
{
m_simu.stopAcq();
}
void SimuHwInterface::getStatus(StatusType& status)
{
Simulator::Status simu_status = m_simu.getStatus();
switch (simu_status) {
case Simulator::Ready:
status.acq = AcqReady;
status.det = DetIdle;
break;
case Simulator::Exposure:
status.det = Exposure;
goto Running;
case Simulator::Readout:
status.det = Readout;
goto Running;
case Simulator::Latency:
status.det = Latency;
Running:
status.acq = AcqRunning;
break;
}
status.det_mask = DetStatus(Exposure | Readout | Latency);
}
int SimuHwInterface::getNbAcquiredFrames()
......
......@@ -45,20 +45,22 @@ void Simulator::SimuThread::execStartAcq()
FrameBuilder& frame_builder = m_simu.m_frame_builder;
frame_builder.resetFrameNr();
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);
struct timespec treq, trem;
double req_time;
req_time = m_simu.m_exp_time;
if (req_time > 0) {
setStatus(Exposure);
treq.tv_sec = int(floor(req_time));
treq.tv_nsec = int((req_time - treq.tv_sec) * 1e9);
nanosleep(&treq, &trem);
}
setStatus(Readout);
int buffer_nb = frame_nb % buffer_mgr.getNbBuffers();
typedef unsigned char *BufferPtr;
BufferPtr ptr = BufferPtr(buffer_mgr.getBufferPtr(buffer_nb));
frame_builder.getNextFrame(ptr);
......@@ -66,6 +68,14 @@ void Simulator::SimuThread::execStartAcq()
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame_nb;
buffer_mgr.newFrameReady(frame_info);
req_time = m_simu.m_lat_time;
if (req_time > 0) {
setStatus(Latency);
treq.tv_sec = int(floor(req_time));
treq.tv_nsec = int((req_time - treq.tv_sec) * 1e9);
nanosleep(&treq, &trem);
}
}
setStatus(Ready);
}
......@@ -81,14 +91,15 @@ Simulator::Simulator()
m_thread(*this)
{
init();
m_thread.start();
}
void Simulator::init()
{
m_exp_time = 1.0;
m_lat_time = 0.0;
m_nb_frames = 1;
m_thread.start();
}
Simulator::~Simulator()
......@@ -100,6 +111,12 @@ BufferCtrlMgr& Simulator::getBufferMgr()
return m_buffer_ctrl_mgr;
}
void Simulator::getMaxImageSize(Size& max_image_size)
{
int max_dim = 8 * 1024;
max_image_size = Size(max_dim, max_dim);
}
void Simulator::setNbFrames(int nb_frames)
{
if (nb_frames < 0)
......@@ -126,6 +143,19 @@ void Simulator::getExpTime(double& exp_time)
exp_time = m_exp_time;
}
void Simulator::setLatTime(double lat_time)
{
if (lat_time < 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid latency time");
m_lat_time = lat_time;
}
void Simulator::getLatTime(double& lat_time)
{
lat_time = m_lat_time;
}
void Simulator::setBin(const Bin& bin)
{
m_frame_builder.setBin(bin);
......@@ -146,6 +176,13 @@ void Simulator::getFrameDim(FrameDim& frame_dim)
m_frame_builder.getFrameDim(frame_dim);
}
void Simulator::reset()
{
stopAcq();
init();
}
Simulator::Status Simulator::getStatus()
{
int thread_status = m_thread.getStatus();
......@@ -156,6 +193,8 @@ Simulator::Status Simulator::getStatus()
return Simulator::Exposure;
case SimuThread::Readout:
return Simulator::Readout;
case SimuThread::Latency:
return Simulator::Latency;
default:
throw LIMA_HW_EXC(Error, "Invalid thread status");
}
......@@ -163,6 +202,8 @@ Simulator::Status Simulator::getStatus()
void Simulator::startAcq()
{
m_buffer_ctrl_mgr.setStartTimestamp(Timestamp::now());
m_thread.sendCmd(SimuThread::StartAcq);
m_thread.waitNotStatus(SimuThread::Ready);
}
......@@ -188,6 +229,8 @@ ostream& lima::operator <<(ostream& os, Simulator& simu)
status = "Exposure"; break;
case Simulator::Readout:
status = "Readout"; break;
case Simulator::Latency:
status = "Latency"; break;
default:
status = "Unknown";
}
......
......@@ -17,7 +17,7 @@ enum AcqMode {
};
enum TrigMode {
Internal,
IntTrig,
ExtTrigSingle, ExtTrigMult,
ExtGate, ExtStartStop,
};
......
......@@ -26,9 +26,6 @@ public:
virtual void getMaxNbBuffers(int& max_nb_buffers) = 0;
virtual void setBufferMode(BufferMode buffer_mode) = 0;
virtual void getBufferMode(BufferMode& buffer_mode) = 0;
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual void *getFramePtr(int acq_frame_nb) = 0;
......
......@@ -80,7 +80,7 @@ class BufferCbMgr : public HwFrameCallbackGen
{
public:
enum Cap {
Basic=0, Concat=1, Acc=2,
Basic=0, Concat=1, Acc=2, // bit mask
};
virtual ~BufferCbMgr();
......@@ -166,6 +166,10 @@ class StdBufferCbMgr : public BufferCbMgr
class BufferCtrlMgr
{
public:
enum AcqMode {
Normal, Concat, Acc,
};
BufferCtrlMgr(BufferCbMgr& acq_buffer_mgr);
~BufferCtrlMgr();
......@@ -183,9 +187,6 @@ class BufferCtrlMgr
void getMaxNbBuffers(int& max_nb_buffers);
void setBufferMode(BufferMode buffer_mode);
void getBufferMode(BufferMode& buffer_mode);
void *getBufferPtr(int buffer_nb);
void *getFramePtr(int acq_frame_nb);
......@@ -198,8 +199,11 @@ class BufferCtrlMgr
void unregisterFrameCallback(HwFrameCallback *frame_cb);
BufferCbMgr& getAcqBufferMgr();
AcqMode getAcqMode();
private:
int m_nb_concat_frames;
int m_nb_acc_frames;
BufferCbMgr& m_acq_buffer_mgr;
SoftBufferAllocMgr m_aux_alloc_mgr;
StdBufferCbMgr m_aux_buffer_mgr;
......
......@@ -8,7 +8,7 @@ class HwCap
{
public:
enum Type {
DetInfo, Sync, Buffer, // Standard: these are mandatory
DetInfo, Buffer, Sync, // Standard: these are mandatory
Roi, Bin, Flip, // Image operations
Kinetics, FrameTransfer,// Acquisition modes
Timing, // Read only detector timmings
......@@ -28,7 +28,8 @@ public:
} // namespace lima