Commit 65d2b9e0 authored by ahoms's avatar ahoms

* fixed Frelon::Camera::setBin to wait for both Horz/Vert change

* differentiate set_roi and real_roi in CtHwBinRoi
* wait for m_ready_flag in CtSaving::resetLastFrameNb,
  call it during CtControl::prepareAcq if autosave
* find next_frame in CtSaving::_save_finished instead of m_frame_datas.begin()
* removed unregister Frame/MaxImageSizeCallback in destructors, 
  it is automatically done when deleting the callbacks
* check !roi.isEmpty() when recalculating CtSw/HwBinRoi setMaxSize/Bin
* changed AcqState::State to bit mask, allow to wait for a combination 
  of flags, renamed Running to Acquiring, added Saving
* improved testfreloncontrol[.py] with FrelonAcq
* restore ostream original parameters (width, fill) after Debug heading
* added virtual XXCallbackGen setXXCallbackActive, called in base destruct.



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@196 45c4679d-1946-429d-baad-37912b19538b
parent f223f817
......@@ -79,7 +79,7 @@ class Camera : public HwMaxImageSizeCallbackGen
virtual void setMaxImageSizeCallbackActive(bool cb_active);
private:
static const double HorzBinChangeTime;
static const double BinChangeTime;
static const double MaxReadoutTime;
Espia::Dev& getEspiaDev();
......
......@@ -7,8 +7,8 @@ using namespace lima;
using namespace lima::Frelon;
using namespace std;
const double Camera::HorzBinChangeTime = 2.0;
const double Camera::MaxReadoutTime = 0.7;
const double Camera::BinChangeTime = 2.0;
const double Camera::MaxReadoutTime = 0.7;
Camera::Camera(Espia::SerialLine& espia_ser_line)
......@@ -372,9 +372,10 @@ void Camera::setBin(const Bin& bin)
setRoi(roi);
writeRegister(BinHorz, bin.getX());
DEB_TRACE() << "Sleeping " << DEB_VAR1(HorzBinChangeTime);
Sleep(HorzBinChangeTime);
writeRegister(BinVert, bin.getY());
DEB_TRACE() << "Sleeping " << DEB_VAR1(BinChangeTime);
Sleep(BinChangeTime);
}
void Camera::getBin(Bin& bin)
......
......@@ -6,6 +6,7 @@
#include "AcqState.h"
using namespace lima;
using namespace std;
DEB_GLOBAL(DebModTest);
......@@ -29,7 +30,7 @@ private:
};
ImageStatusCallback::ImageStatusCallback(CtControl& ct, AcqState& acq_state)
: m_ct(ct), m_acq_state(acq_state)
: m_ct(ct), m_acq_state(acq_state), m_nb_frames(0)
{
DEB_CONSTRUCTOR();
}
......@@ -53,99 +54,262 @@ void ImageStatusCallback::imageStatusChanged(
ct_acq->getAcqNbFrames(m_nb_frames);
}
if ((last_acq_frame_nb == m_nb_frames - 1) &&
(m_acq_state.get() == AcqState::Acquiring)) {
DEB_ALWAYS() << "All frames acquired!";
m_acq_state.set(AcqState::Saving);
}
if (last_saved_frame_nb == m_nb_frames - 1) {
DEB_TRACE() << "Acquisition finished!";
DEB_ALWAYS() << "All frames saved!";
m_acq_state.set(AcqState::Finished);
}
}
void test_frelon_control()
class FrelonAcq
{
DEB_GLOBAL_FUNCT();
DEB_CLASS(DebModTest, "FrelonAcq");
public:
FrelonAcq(int espia_dev_nb);
~FrelonAcq();
// DebParams::disableModuleFlags(DebParams::AllFlags);
DebParams::enableModuleFlags(DebModTest);
Espia::Dev dev(0);
Espia::Acq acq(dev);
Espia::BufferMgr buffer_cb_mgr(acq);
Espia::SerialLine ser_line(dev);
Frelon::Camera cam(ser_line);
BufferCtrlMgr buffer_mgr(buffer_cb_mgr);
DEB_ALWAYS() << "Creating the Hw Interface ...";
Frelon::Interface hw_inter(acq, buffer_mgr, cam);
DEB_TRACE() << "Done!";
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);
void initSaving(string dir, string prefix, string suffix, int idx,
CtSaving::FileFormat fmt, CtSaving::SavingMode mode,
int frames_per_file);
void setExpTime(double exp_time);
void setNbAcqFrames(int nb_acq_frames);
void start();
void wait();
void run();
void setBin(Bin& bin);
void setRoi(Roi& roi);
private:
void printDefaults();
Espia::Dev m_edev;
Espia::Acq m_acq;
Espia::BufferMgr m_buffer_cb_mgr;
Espia::SerialLine m_eserline;
Frelon::Camera m_cam;
BufferCtrlMgr m_buffer_mgr;
Frelon::Interface m_hw_inter;
AcqState m_acq_state;
CtControl *m_ct;
CtAcquisition *m_ct_acq;
CtSaving *m_ct_saving;
CtImage *m_ct_image;
CtBuffer *m_ct_buffer;
ImageStatusCallback *m_img_status_cb;
};
FrelonAcq::FrelonAcq(int espia_dev_nb)
: m_edev(espia_dev_nb),
m_acq(m_edev),
m_buffer_cb_mgr(m_acq),
m_eserline(m_edev),
m_cam(m_eserline),
m_buffer_mgr(m_buffer_cb_mgr),
m_hw_inter(m_acq, m_buffer_mgr, m_cam),
m_ct(NULL), m_img_status_cb(NULL)
{
DEB_CONSTRUCTOR();
AutoPtr<CtControl> ct = new CtControl(&m_hw_inter);
m_ct_acq = ct->acquisition();
m_ct_saving = ct->saving();
m_ct_image = ct->image();
m_ct_buffer = ct->buffer();
printDefaults();
AutoPtr<ImageStatusCallback> img_status_cb;
img_status_cb = new ImageStatusCallback(*ct, m_acq_state);
ct->registerImageStatusCallback(*img_status_cb);
DEB_TRACE() << "All is OK!";
m_ct = ct.forget();
m_img_status_cb = img_status_cb.forget();
}
FrelonAcq::~FrelonAcq()
{
DEB_DESTRUCTOR();
delete m_img_status_cb;
delete m_ct;
}
void FrelonAcq::printDefaults()
{
DEB_MEMBER_FUNCT();
AcqMode acq_mode;
ct_acq->getAcqMode(acq_mode);
m_ct_acq->getAcqMode(acq_mode);
DEB_TRACE() << "Default " << DEB_VAR1(acq_mode);
ImageType image_type;
ct_image->getImageType(image_type);
m_ct_image->getImageType(image_type);
DEB_TRACE() << "Default " << DEB_VAR1(image_type);
Size max_size;
ct_image->getMaxImageSize(max_size);
m_ct_image->getMaxImageSize(max_size);
DEB_TRACE() << "Default " << DEB_VAR1(max_size);
CtImage::ImageOpMode img_op_mode;
m_ct_image->getMode(img_op_mode);
DEB_TRACE() << "Default " << DEB_VAR1(img_op_mode);
Bin bin;
ct_image->getBin(bin);
m_ct_image->getBin(bin);
DEB_TRACE() << "Default " << DEB_VAR1(bin);
Roi roi;
ct_image->getRoi(roi);
m_ct_image->getRoi(roi);
DEB_TRACE() << "Default " << DEB_VAR1(roi);
double exp_time;
ct_acq->getAcqExpoTime(exp_time);
m_ct_acq->getAcqExpoTime(exp_time);
DEB_TRACE() << "Default " << DEB_VAR1(exp_time);
int nb_frames;
ct_acq->getAcqNbFrames(nb_frames);
m_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);
void FrelonAcq::start()
{
DEB_MEMBER_FUNCT();
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);
m_ct->prepareAcq();
m_acq_state.set(AcqState::Acquiring);
DEB_TRACE() << "Starting acquisition";
ct->startAcq();
acq_state.waitNot(AcqState::Running);
m_ct->startAcq();
}
void FrelonAcq::wait()
{
DEB_MEMBER_FUNCT();
m_acq_state.waitNot(AcqState::Acquiring | AcqState::Saving);
DEB_TRACE() << "Acquisition finished";
}
void FrelonAcq::run()
{
DEB_MEMBER_FUNCT();
start();
wait();
}
void FrelonAcq::initSaving(string dir, string prefix, string suffix, int idx,
CtSaving::FileFormat fmt, CtSaving::SavingMode mode,
int frames_per_file)
{
DEB_MEMBER_FUNCT();
m_ct_saving->setDirectory(dir);
m_ct_saving->setPrefix(prefix);
m_ct_saving->setSuffix(suffix);
m_ct_saving->setNextNumber(idx);
m_ct_saving->setFormat(fmt);
m_ct_saving->setSavingMode(mode);
m_ct_saving->setFramesPerFile(frames_per_file);
}
void FrelonAcq::setExpTime(double exp_time)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(exp_time);
m_ct_acq->setAcqExpoTime(exp_time);
}
void FrelonAcq::setNbAcqFrames(int nb_acq_frames)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(nb_acq_frames);
m_ct_acq->setAcqNbFrames(nb_acq_frames);
}
void FrelonAcq::setBin(Bin& bin)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(bin);
m_ct_image->setBin(bin);
}
void FrelonAcq::setRoi(Roi& roi)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(roi);
m_ct_image->setRoi(roi);
}
void test_frelon_control(bool enable_debug = false)
{
DEB_GLOBAL_FUNCT();
if (!enable_debug) {
DebParams::disableModuleFlags(DebParams::AllFlags);
}
DEB_ALWAYS() << "Creating FrelonAcq";
int espia_dev_nb = 0;
FrelonAcq acq(espia_dev_nb);
DEB_ALWAYS() << "Done!";
acq.initSaving("data", "img", ".edf", 0, CtSaving::EDF,
CtSaving::AutoFrame, 1);
DEB_ALWAYS() << "First run with default pars";
acq.run();
DEB_ALWAYS() << "Done!";
double exp_time = 1e-6;
acq.setExpTime(exp_time);
int nb_acq_frames = 500;
acq.setNbAcqFrames(nb_acq_frames);
DEB_ALWAYS() << "Run " << DEB_VAR2(exp_time, nb_acq_frames);
acq.run();
DEB_ALWAYS() << "Done!";
Bin bin(2);
acq.setBin(bin);
nb_acq_frames = 5;
acq.setNbAcqFrames(nb_acq_frames);
DEB_ALWAYS() << "Run " << DEB_VAR2(bin, nb_acq_frames);
acq.run();
DEB_ALWAYS() << "Done!";
Roi roi = Roi(Point(256, 256), Size(512, 512));
acq.setRoi(roi);
DEB_ALWAYS() << "Run " << DEB_VAR1(roi);
acq.run();
DEB_ALWAYS() << "Done!";
roi = Roi(Point(267, 267), Size(501, 501));
acq.setRoi(roi);
DEB_ALWAYS() << "Run " << DEB_VAR1(roi);
acq.run();
DEB_ALWAYS() << "Done!";
}
......@@ -153,8 +317,13 @@ int main(int argc, char *argv[])
{
DEB_GLOBAL_FUNCT();
string par;
if (argc > 1)
par = argv[1];
bool enable_debug = (par == "debug");
try {
test_frelon_control();
test_frelon_control(enable_debug);
} catch (Exception& e) {
DEB_ERROR() << "LIMA Exception: " << e;
}
......
import os, sys, string
import lima
class ImageStatusCallback(lima.CtControl.ImageStatusCallback):
def __init__(self, ct, acq_state):
lima.CtControl.ImageStatusCallback(self)
self.m_ct = ct
self.m_acq_state = acq_state
self.m_nb_frames = 0
def imageStatusChanged(self, img_status):
last_acq_frame_nb = img_status.LastImageAcquired;
last_saved_frame_nb = img_status.LastImageSaved;
if last_acq_frame_nb == 0:
ct_acq = m_ct.acquisition()
self.m_nb_frames = ct_acq.getAcqNbFrames()
if (last_acq_frame_nb == m_nb_frames - 1) and \
(self.m_acq_state.get() == lima.AcqState.Acquiring):
print "All frames acquired!"
m_acq_state.set(lima.AcqState.Saving)
if last_saved_frame_nb == nb_frames - 1:
print "All frames saved!"
m_acq_state.set(lima.AcqState.Finished)
class FrelonAcq:
def __init__(self, espia_dev_nb):
self.m_edev = lima.Espia.Dev(espia_dev_nb)
self.m_acq = lima.Espia.Acq(self.m_edev)
self.m_buffer_cb_mgr = lima.Espia.BufferMgr(self.m_acq)
self.m_eserline = lima.Espia.SerialLine(self.m_edev)
self.m_cam = lima.Frelon.Camera(self.m_eserline)
self.m_buffer_mgr = lima.BufferCtrlMgr(self.m_buffer_cb_mgr)
self.m_hw_inter = lima.Frelon.Interface(self.m_acq,
self.m_buffer_mgr,
self.m_cam)
self.m_acq_state = lima.AcqState()
self.m_ct = lima.CtControl(self.m_hw_inter)
self.m_ct_acq = self.m_ct.acquisition()
self.m_ct_saving = self.m_ct.saving()
self.m_ct_image = self.m_ct.image()
self.m_ct_buffer = self.m_ct.buffer()
def test_frelon_control(enable_debug):
acq = FrelonAcq(0)
def main(argv):
enable_debug = False
if len(argv) > 1:
enable_debug = (argv[1] == 'debug')
test_frelon_control(enable_debug)
if __name__ == '__main__':
main(sys.argv)
......@@ -385,9 +385,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_buffer->registerFrameCallback(cb);
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......@@ -396,9 +396,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_sync->setExpTime(5);
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......@@ -408,9 +408,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_sync->setNbFrames(3);
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......@@ -437,9 +437,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_buffer->setNbBuffers(10);
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......@@ -452,9 +452,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_buffer->setNbBuffers(10);
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......@@ -470,9 +470,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_buffer->setNbBuffers(10);
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......@@ -488,9 +488,9 @@ void test_frelon_hw_inter(bool do_reset)
print_deb_flags();
print_status(hw_inter);
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
PoolThreadMgr::get().wait();
print_status(hw_inter);
hw_inter.stopAcq();
......
......@@ -199,11 +199,11 @@ def main(argv):
hw_sync.setNbFrames(3)
print "Starting Acquisition"
acq_state.set(lima.AcqState.Running)
acq_state.set(lima.AcqState.Acquiring)
hw_inter.startAcq()
print "Waiting acq finished..."
acq_state.waitNot(lima.AcqState.Running)
acq_state.waitNot(lima.AcqState.Acquiring)
print "Acq finished!!"
print "Stopping Acquisition"
......
......@@ -188,9 +188,9 @@ void test_frelon_spectroscopy()
DEB_ALWAYS() << "Starting acquisition";
t0 = Timestamp::now();
acq_state.set(AcqState::Running);
acq_state.set(AcqState::Acquiring);
hw_inter.startAcq();
acq_state.waitNot(AcqState::Running);
acq_state.waitNot(AcqState::Acquiring);
t1 = Timestamp::now();
if (acq_state.get() == AcqState::Aborted) {
DEB_ERROR() << "Acquisition aborted!";
......
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