Commit 09ec5303 authored by ahoms's avatar ahoms
Browse files

* moved HwInterface::Acq/DetStatus to the global lima namespace

* added ImageStatusCallback to CtControl
* fixed the CtBuffer to avoid multiple FrameCallback allocations



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@194 45c4679d-1946-429d-baad-37912b19538b
parent 316cfe27
......@@ -549,25 +549,26 @@ void Interface::getStatus(StatusType& status)
m_acq.getStatus(acq);
status.acq = acq.running ? AcqRunning : AcqReady;
static const DetStatus det_mask = (WaitForTrigger | Exposure |
ShutterClose | ChargeShift |
Readout | Latency);
static const DetStatus det_mask =
(DetWaitForTrigger | DetExposure | DetShutterClose |
DetChargeShift | DetReadout | DetLatency);
status.det_mask = det_mask;
status.det = DetIdle;
Frelon::Status cam;
m_cam.getStatus(cam);
if (cam & Frelon::Wait)
status.det |= WaitForTrigger;
status.det |= DetWaitForTrigger;
if (cam & Frelon::Exposure)
status.det |= Exposure;
status.det |= DetExposure;
if (cam & Frelon::Shutter)
status.det |= ShutterClose;
status.det |= DetShutterClose;
if (cam & Frelon::Transfer)
status.det |= ChargeShift;
status.det |= DetChargeShift;
if (cam & Frelon::Readout)
status.det |= Readout;
status.det |= DetReadout;
if (cam & Frelon::Latency)
status.det |= Latency;
status.det |= DetLatency;
DEB_RETURN() << DEB_VAR1(status);
}
......
......@@ -2,11 +2,62 @@
#include "CtControl.h"
#include "CtAcquisition.h"
#include "CtImage.h"
#include "CtSaving.h"
#include "AcqState.h"
using namespace lima;
DEB_GLOBAL(DebModTest);
class ImageStatusCallback : public CtControl::ImageStatusCallback
{
DEB_CLASS(DebModTest, "ImageStatusCallback");
public:
ImageStatusCallback(CtControl& ct, AcqState& acq_state);
virtual ~ImageStatusCallback();
protected:
virtual void imageStatusChanged(
const CtControl::ImageStatus& img_status);
private:
CtControl& m_ct;
AcqState& m_acq_state;
int m_nb_frames;
};
ImageStatusCallback::ImageStatusCallback(CtControl& ct, AcqState& acq_state)
: m_ct(ct), m_acq_state(acq_state)
{
DEB_CONSTRUCTOR();
}
ImageStatusCallback::~ImageStatusCallback()
{
DEB_DESTRUCTOR();
}
void ImageStatusCallback::imageStatusChanged(
const CtControl::ImageStatus& img_status)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(img_status);
int last_acq_frame_nb = img_status.LastImageAcquired;
int last_saved_frame_nb = img_status.LastImageSaved;
if (last_acq_frame_nb == 0) {
CtAcquisition *ct_acq = m_ct.acquisition();
ct_acq->getAcqNbFrames(m_nb_frames);
}
if (last_saved_frame_nb == m_nb_frames - 1) {
DEB_TRACE() << "Acquisition finished!";
m_acq_state.set(AcqState::Finished);
}
}
void test_frelon_control()
{
......@@ -26,11 +77,15 @@ void test_frelon_control()
Frelon::Interface hw_inter(acq, buffer_mgr, cam);
DEB_TRACE() << "Done!";
CtControl control(&hw_inter);
CtAcquisition *ct_acq = control.acquisition();
CtSaving *ct_saving = control.saving();
CtImage *ct_image = control.image();
CtBuffer *ct_buffer = control.buffer();
AutoPtr<CtControl> ct = new CtControl(&hw_inter);
CtAcquisition *ct_acq = ct->acquisition();
CtSaving *ct_save = ct->saving();
CtImage *ct_image = ct->image();
// CtBuffer *ct_buffer = ct->buffer();
AcqState acq_state;
ImageStatusCallback img_status_cb(*ct, acq_state);
ct->registerImageStatusCallback(img_status_cb);
AcqMode acq_mode;
ct_acq->getAcqMode(acq_mode);
......@@ -56,9 +111,41 @@ void test_frelon_control()
ct_acq->getAcqExpoTime(exp_time);
DEB_TRACE() << "Default " << DEB_VAR1(exp_time);
int nb_frame;
ct_acq->getAcqNbFrames(nb_frame);
DEB_TRACE() << "Default " << DEB_VAR1(nb_frame);
int nb_frames;
ct_acq->getAcqNbFrames(nb_frames);
DEB_TRACE() << "Default " << DEB_VAR1(nb_frames);
ct_save->setDirectory(".");
ct_save->setPrefix("img");
ct_save->setSuffix(".edf");
ct_save->setNextNumber(0);
ct_save->setFormat(CtSaving::EDF);
ct_save->setSavingMode(CtSaving::AutoFrame);
ct_save->setFramesPerFile(1);
DEB_TRACE() << "Preparing acquisition";
ct->prepareAcq();
acq_state.set(AcqState::Running);
DEB_TRACE() << "Starting acquisition";
ct->startAcq();
acq_state.waitNot(AcqState::Running);
DEB_TRACE() << "Acquisition finished";
exp_time = 1e-6;
DEB_TRACE() << "Setting " << DEB_VAR1(exp_time);
ct_acq->setAcqExpoTime(exp_time);
nb_frames = 200;
DEB_TRACE() << "Setting " << DEB_VAR1(nb_frames);
ct_acq->setAcqNbFrames(nb_frames);
DEB_TRACE() << "Preparing acquisition";
ct->prepareAcq();
acq_state.set(AcqState::Running);
DEB_TRACE() << "Starting acquisition";
ct->startAcq();
acq_state.waitNot(AcqState::Running);
DEB_TRACE() << "Acquisition finished";
}
......
......@@ -324,18 +324,18 @@ void SimuHwInterface::getStatus(StatusType& status)
status.det = DetIdle;
break;
case Simulator::Exposure:
status.det = Exposure;
status.det = DetExposure;
goto Running;
case Simulator::Readout:
status.det = Readout;
status.det = DetReadout;
goto Running;
case Simulator::Latency:
status.det = Latency;
status.det = DetLatency;
Running:
status.acq = AcqRunning;
break;
}
status.det_mask = Exposure | Readout | Latency;
status.det_mask = DetExposure | DetReadout | DetLatency;
}
int SimuHwInterface::getNbHwAcquiredFrames()
......
......@@ -38,6 +38,29 @@ enum BufferMode {
std::ostream& operator <<(std::ostream& os, BufferMode buffer_mode);
enum AcqStatus {
AcqReady, AcqRunning, AcqFault,
};
std::ostream& operator <<(std::ostream& os, AcqStatus acq_status);
enum DetStatus {
DetIdle = 0x00,
DetFault = 0x01,
DetWaitForTrigger = 0x02,
DetShutterOpen = 0x04,
DetExposure = 0x08,
DetShutterClose = 0x10,
DetChargeShift = 0x20,
DetReadout = 0x40,
DetLatency = 0x80,
};
DetStatus operator | (DetStatus s1, DetStatus s2);
DetStatus& operator |=(DetStatus& s1, DetStatus s2);
std::ostream& operator <<(std::ostream& os, DetStatus det_status);
} // namespace lima
#endif // CONSTANTS_H
......@@ -19,3 +19,20 @@ enum TrigMode {
enum BufferMode {
Linear, Circular,
};
enum AcqStatus {
AcqReady, AcqRunning, AcqFault,
};
enum DetStatus {
DetIdle = 0x00,
DetFault = 0x01,
DetWaitForTrigger = 0x02,
DetShutterOpen = 0x04,
DetExposure = 0x08,
DetShutterClose = 0x10,
DetChargeShift = 0x20,
DetReadout = 0x40,
DetLatency = 0x80,
};
......@@ -61,3 +61,56 @@ ostream& lima::operator <<(ostream& os, BufferMode buffer_mode)
return os << name;
}
ostream& lima::operator <<(ostream& os, AcqStatus acq_status)
{
string name = "Unknown";
switch (acq_status) {
case AcqReady: name = "AcqReady"; break;
case AcqRunning: name = "AcqRunning"; break;
case AcqFault: name = "AcqFault"; break;
}
return os << name;
}
void AddToken(string& str, const string& token, const string& sep)
{
if (str.length() > 0)
str += sep;
str += token;
}
ostream& lima::operator <<(ostream& os, DetStatus det_status)
{
if (det_status == DetIdle)
return os << "Idle";
string name, sep = "+";
if (det_status & DetFault)
AddToken(name, "Fault", sep);
if (det_status & DetWaitForTrigger)
AddToken(name, "WaitForTrigger", sep);
if (det_status & DetShutterOpen)
AddToken(name, "ShutterOpen", sep);
if (det_status & DetExposure)
AddToken(name, "Exposure", sep);
if (det_status & DetShutterClose)
AddToken(name, "ShutterClose", sep);
if (det_status & DetChargeShift)
AddToken(name, "ChargeShift", sep);
if (det_status & DetReadout)
AddToken(name, "Readout", sep);
if (det_status & DetLatency)
AddToken(name, "Latency", sep);
return os << name;
}
DetStatus lima::operator |(DetStatus s1, DetStatus s2)
{
return DetStatus(int(s1) | int(s2));
}
DetStatus& lima::operator |=(DetStatus& s1, DetStatus s2)
{
return s1 = s1 | s2;
}
......@@ -48,6 +48,22 @@ namespace lima
long LastCounterReady;
};
class ImageStatusCallback
{
DEB_CLASS_NAMESPC(DebModControl,"Control::ImageStatusCallback",
"Control");
public:
ImageStatusCallback();
virtual ~ImageStatusCallback();
protected:
virtual void imageStatusChanged(const ImageStatus& img_status) = 0;
private:
friend class CtControl;
void setImageStatusCallbackGen(CtControl *cb_gen);
CtControl *m_cb_gen;
};
CtControl(HwInterface *hw);
~CtControl();
......@@ -63,7 +79,7 @@ namespace lima
void setApplyPolicy(ApplyPolicy policy);
void getApplyPolicy(ApplyPolicy &policy) const;
void getAcqStatus(HwInterface::AcqStatus& status) const; // from HW
void getAcqStatus(AcqStatus& status) const; // from HW
void getImageStatus(ImageStatus& status) const;
void ReadImage(Data&,long frameNumber = -1);
......@@ -71,6 +87,9 @@ namespace lima
void reset();
void registerImageStatusCallback(ImageStatusCallback& cb);
void unregisterImageStatusCallback(ImageStatusCallback& cb);
protected:
void newFrameReady(Data& data);
void newFrameToSave(Data& data);
......@@ -117,7 +136,10 @@ namespace lima
ApplyPolicy m_policy;
bool m_ready;
bool m_autosave;
ImageStatusCallback *m_img_status_cb;
};
inline std::ostream& operator<<(std::ostream &os,
const CtControl::ImageStatus &status)
{
......
......@@ -22,6 +22,15 @@ using namespace lima;
long LastCounterReady;
};
class ImageStatusCallback
{
public:
ImageStatusCallback();
virtual ~ImageStatusCallback();
protected:
virtual void imageStatusChanged(const CtControl::ImageStatus& status)=0;
};
CtControl(HwInterface *hw);
~CtControl();
......@@ -37,13 +46,17 @@ using namespace lima;
void setApplyPolicy(ApplyPolicy policy);
void getApplyPolicy(ApplyPolicy &policy /Out/) const;
void getAcqStatus(HwInterface::AcqStatus& status /Out/) const; // from HW
void getAcqStatus(AcqStatus& status /Out/) const; // from HW
void getImageStatus(ImageStatus &imageStatus /Out/) const;
void ReadImage(Data&,long frameNumber = -1);
void ReadBaseImage(Data&,long frameNumber = -1);
void reset();
void registerImageStatusCallback(ImageStatusCallback& cb);
void unregisterImageStatusCallback(ImageStatusCallback& cb);
protected:
void newFrameReady(Data& data);
void newFrameToSave(Data& data);
......
......@@ -34,20 +34,21 @@ void CtBuffer::registerFrameCallback(CtControl *ct)
{
DEB_MEMBER_FUNCT();
m_frame_cb= new CtBufferFrameCB(ct);
m_hw_buffer->registerFrameCallback(*m_frame_cb);
if (m_frame_cb == NULL) {
m_frame_cb= new CtBufferFrameCB(ct);
m_hw_buffer->registerFrameCallback(*m_frame_cb);
}
}
void CtBuffer::unregisterFrameCallback()
{
DEB_MEMBER_FUNCT();
if (m_frame_cb != NULL)
{
m_hw_buffer->unregisterFrameCallback(*m_frame_cb);
delete m_frame_cb;
m_frame_cb= NULL;
}
if (m_frame_cb != NULL) {
m_hw_buffer->unregisterFrameCallback(*m_frame_cb);
delete m_frame_cb;
m_frame_cb= NULL;
}
}
void CtBuffer::setPars(Parameters pars)
......
......@@ -80,7 +80,8 @@ CtControl::CtControl(HwInterface *hw) :
m_base_images_ready(CtControl::ltData()),
m_images_ready(CtControl::ltData()),
m_policy(All), m_ready(false),
m_autosave(false)
m_autosave(false),
m_img_status_cb(NULL)
{
DEB_CONSTRUCTOR();
......@@ -102,6 +103,9 @@ CtControl::~CtControl()
{
DEB_DESTRUCTOR();
if (m_img_status_cb)
unregisterImageStatusCallback(*m_img_status_cb);
delete m_ct_saving;
delete m_ct_acq;
delete m_ct_image;
......@@ -202,7 +206,7 @@ void CtControl::stopAcq()
DEB_TRACE() << "Hardware Acquisition Stopped";
}
void CtControl::getAcqStatus(HwInterface::AcqStatus& status) const
void CtControl::getAcqStatus(AcqStatus& status) const
{
DEB_MEMBER_FUNCT();
......@@ -287,6 +291,9 @@ void CtControl::newFrameReady(Data& fdata)
m_img_status.LastBaseImageReady = m_img_status.LastImageAcquired = fdata.frameNumber;
}
if (m_img_status_cb)
m_img_status_cb->imageStatusChanged(m_img_status);
}
void CtControl::newBaseImageReady(Data &aData)
......@@ -296,6 +303,7 @@ void CtControl::newBaseImageReady(Data &aData)
AutoMutex aLock(m_cond.mutex());
long expectedImageReady = m_img_status.LastBaseImageReady + 1;
bool img_status_changed = false;
if(aData.frameNumber == expectedImageReady)
{
while(!m_base_images_ready.empty())
......@@ -313,6 +321,8 @@ void CtControl::newBaseImageReady(Data &aData)
m_img_status.LastBaseImageReady = expectedImageReady;
if(!m_op_ext_link_task_active)
m_img_status.LastImageReady = expectedImageReady;
img_status_changed = true;
}
else
m_base_images_ready.insert(aData);
......@@ -322,6 +332,11 @@ void CtControl::newBaseImageReady(Data &aData)
aLock.unlock();
newFrameToSave(aData);
}
aLock.unlock();
if (img_status_changed && m_img_status_cb)
m_img_status_cb->imageStatusChanged(m_img_status);
}
void CtControl::newImageReady(Data &aData)
......@@ -331,6 +346,7 @@ void CtControl::newImageReady(Data &aData)
AutoMutex aLock(m_cond.mutex());
long expectedImageReady = m_img_status.LastImageReady + 1;
bool img_status_changed = false;
if(aData.frameNumber == expectedImageReady)
{
while(!m_images_ready.empty())
......@@ -346,6 +362,8 @@ void CtControl::newImageReady(Data &aData)
break;
}
m_img_status.LastImageReady = expectedImageReady;
img_status_changed = true;
}
else
m_images_ready.insert(aData);
......@@ -355,6 +373,11 @@ void CtControl::newImageReady(Data &aData)
aLock.unlock();
newFrameToSave(aData);
}
aLock.unlock();
if (m_img_status_cb && img_status_changed)
m_img_status_cb->imageStatusChanged(m_img_status);
}
void CtControl::newCounterReady(Data&)
......@@ -372,6 +395,10 @@ void CtControl::newImageSaved(Data&)
DEB_MEMBER_FUNCT();
AutoMutex aLock(m_cond.mutex());
++m_img_status.LastImageSaved;
aLock.unlock();
if (m_img_status_cb)
m_img_status_cb->imageStatusChanged(m_img_status);
}
void CtControl::newFrameToSave(Data& fdata)
......@@ -384,6 +411,35 @@ void CtControl::newFrameToSave(Data& fdata)
m_ct_saving->frameReady(fdata);
}
void CtControl::registerImageStatusCallback(ImageStatusCallback& cb)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(&cb, m_img_status_cb);
if (m_img_status_cb) {
DEB_ERROR() << "ImageStatusCallback already registered";
throw LIMA_CTL_EXC(InvalidValue, "ImageStatusCallback already registered");
}
cb.setImageStatusCallbackGen(this);
m_img_status_cb = &cb;
}
void CtControl::unregisterImageStatusCallback(ImageStatusCallback& cb)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(&cb, m_img_status_cb);
if (m_img_status_cb != &cb) {
DEB_ERROR() << "ImageStatusCallback not registered";
throw LIMA_CTL_EXC(InvalidValue, "ImageStatusCallback not registered");
}
m_img_status_cb = NULL;
cb.setImageStatusCallbackGen(NULL);
}
// ----------------------------------------------------------------------------
// Struct ImageStatus
// ----------------------------------------------------------------------------
......@@ -405,3 +461,27 @@ void CtControl::ImageStatus::reset()
DEB_TRACE() << *this;
}
// ----------------------------------------------------------------------------
// class ImageStatus
// ----------------------------------------------------------------------------
CtControl::ImageStatusCallback::ImageStatusCallback()
: m_cb_gen(NULL)
{
DEB_CONSTRUCTOR();
}
CtControl::ImageStatusCallback::~ImageStatusCallback()
{
DEB_DESTRUCTOR();
if (m_cb_gen)
m_cb_gen->unregisterImageStatusCallback(*this);
}
void
CtControl::ImageStatusCallback::setImageStatusCallbackGen(CtControl *cb_gen)
{
DEB_MEMBER_FUNCT();
m_cb_gen = cb_gen;
}
......@@ -15,22 +15,6 @@ class HwInterface
public:
typedef std::vector<HwCap> CapList;
enum AcqStatus {
AcqReady, AcqRunning, AcqFault,
};
enum DetStatus {
DetIdle = 0x00,
DetFault = 0x01,
WaitForTrigger = 0x02,
ShutterOpen = 0x04,
Exposure = 0x08,
ShutterClose = 0x10,
ChargeShift = 0x20,
Readout = 0x40,
Latency = 0x80,
};
typedef struct Status {
AcqStatus acq;
DetStatus det;
......@@ -73,15 +57,6 @@ bool HwInterface::getHwCtrlObj(CtrlObj *& ctrl_obj) const
return false;
}
HwInterface::DetStatus operator | (HwInterface::DetStatus s1,
HwInterface::DetStatus s2);
HwInterface::DetStatus& operator |=(HwInterface::DetStatus& s1,
</