Commit e897a3ea authored by papillon's avatar papillon
Browse files

Everything is under Ctcontrol !!!



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@112 45c4679d-1946-429d-baad-37912b19538b
parent df9398c9
......@@ -4,27 +4,26 @@
#include "Constants.h"
#include "HwInterface.h"
#include "HwCap.h"
#include "CtControl.h"
namespace lima {
class CtAcquisition {
friend class CtControl;
public:
enum ShutMode {Manual,AutoPerFrame,AutoPerSequence};
enum TrigMode {Internal,ExtStart,MultExtStart,Gate,ExtStartStop};
enum AcqMode {Single,Accumulation,Concatenation};
struct Parameters {
Parameters();
void reset();
AcqMode acqMode;
int acqNbFrames;
double acqExpoTime;
int accNbFrames;
double accExpoTime;
double accMaxExpoTime;
int concatNbFrames;
double latencyTime;
TrigMode triggerMode;
ShutMode shutMode;
double shutOpenTime;
double shutCloseTime;
};
CtAcquisition(HwInterface *hw);
......@@ -32,8 +31,12 @@ class CtAcquisition {
// --- global
void setParameters(const Parameters& pars);
void getParameters(Parameters& pars) const;
void setPars(Parameters pars);
void getPars(Parameters& pars) const;
void reset();
void apply(CtControl::ApplyPolicy policy);
void sync();
// --- acq modes
......@@ -43,17 +46,16 @@ class CtAcquisition {
void setAcqNbFrames(int nframes);
void getAcqNbFrames(int& nframes) const;
void setAcqExposureTime(double acq_time);
void getAcqExposureTime(double& acq_time) const;
void setAcqExpoTime(double acq_time);
void getAcqExpoTime(double& acq_time) const;
void setAccNbFrames(int nframes);
void getAccNbFrames(int& nframes);
void setAccMaxExpoTime(double max_time);
void setAccExposureTime(double acc_time);
void getAccExposureTime(double& acc_time) const;
void getAccNbFrames(int& nframes);
void getAccExpoTime(double& acc_time);
void setConcatNbFrames(int nframes);
void getConcatNbFrames(int& nframes);
void getConcatNbFrames(int& nframes) const;
// --- common
......@@ -63,28 +65,34 @@ class CtAcquisition {
void setTriggerMode(TrigMode mode);
void getTriggerMode(TrigMode& mode) const;
// --- shutter
void setShutterMode(ShutMode mode);
void getShutterMode(ShutMode& mode) const;
void setShutterOpenTime(double open_time);
void getShutterOpenTime(double& open_time) const;
private:
void setShutterCloseTime(double close_time);
void getShutterCloseTime(double& close_time) const;
struct ChangedPars {
ChangedPars();
void set(bool);
void check(Parameters p1, Parameters p2);
// --- read-only
bool acqExpoTime;
bool acqNbFrames;
bool latencyTime;
bool triggerMode;
bool accMaxExpoTime;
};
void getReadoutTime(double& readout_time) const;
void getFrameRate(double& frame_rate) const;
void _updateAccPars();
void _setDefaultPars(Parameters* pars);
void _apply();
void _hwRead();
private:
HwSyncCtrlObj *m_hw_sync;
HwBufferCtrlObj *m_hw_buffer;
Parameters m_pars;
HwSyncCtrlObj::ValidRangesType m_valid_ranges;
Parameters m_inpars, m_hwpars;
ChangedPars m_changes;
double m_readout_time;
double m_frame_rate;
int m_acc_nframes;
double m_acc_exptime;
bool m_applied_once;
};
} // namespace lima
......
......@@ -2,6 +2,7 @@
#define CTBUFFER_H
#include "Constants.h"
#include "CtAcquisition.h"
#include "HwInterface.h"
#include "HwCap.h"
......@@ -10,9 +11,10 @@ namespace lima {
class CtBuffer {
public:
enum Mode {Linear,Circular};
struct Parameters {
Mode mode;
Parameters();
void reset();
BufferMode mode;
long nbBuffers;
short maxMemory;
};
......@@ -20,6 +22,9 @@ class CtBuffer {
CtBuffer(HwInterface *hw);
~CtBuffer();
void setPars(Parameters pars);
void getPars(Parameters& pars) const;
void setMode(BufferMode mode);
void getMode(BufferMode& mode) const;
......@@ -29,6 +34,8 @@ class CtBuffer {
void setMaxMemory(short max_memory);
void getMaxMemory(short& max_memory) const;
void setup(CtAcquisition *ct_acq);
private:
HwBufferCtrlObj *m_hw_buffer;
Parameters m_pars;
......
......@@ -8,9 +8,20 @@
namespace lima {
class CtSaving;
class CtAcquisition;
class CtBuffer;
class CtDebug;
class CtControl {
public:
enum ApplyPolicy {
All,
Changes,
HwSyncChanges,
};
struct ImageStatus {
ImageStatus();
void reset();
......@@ -29,7 +40,17 @@ namespace lima {
void startAcq();
void stopAcq();
void getAcqStatus(); // from HW
CtAcquisition* acquisition() { return m_ct_acq; }
CtSaving* saving() { return m_ct_saving; }
CtBuffer* buffer() { return m_ct_buffer; }
void setDebug(short level);
void getDebug(short& level) const;
void setApplyPolicy(ApplyPolicy policy);
void getApplyPolicy(ApplyPolicy &policy);
void getAcqStatus(HwInterface::AcqStatus& status) const; // from HW
void getImageStatus(ImageStatus& status) const;
void reset();
......@@ -39,6 +60,10 @@ namespace lima {
mutable Cond m_cond;
ImageStatus m_img_status;
CtSaving *m_ct_saving;
CtAcquisition *m_ct_acq;
CtBuffer *m_ct_buffer;
CtDebug *m_ct_debug;
ApplyPolicy m_policy;
};
} // namespace lima
......
#ifndef CTDEBUG_H
#define CTDEBUG_H
#include <string>
#include <iostream>
namespace lima {
class CtDebug {
public:
CtDebug(std::string class_name);
~CtDebug();
void setLevel(short level) { m_level= level; }
void getLevel(short& level) const { level= m_level; }
inline void trace(std::string func_name, std::string message)
{ print(0x01, func_name, "INFO", message); }
inline void warning(std::string func_name, std::string message)
{ print(0x02, func_name, "WARNING", message); }
inline void error(std::string func_name, std::string message)
{ print(0x04, func_name, "ERROR", message); }
private:
void print(short level, std::string func_name, std::string type, std::string message);
std::string m_class_name;
short m_level;
};
} // namespace lima
#endif // CTDEBUG_H
......@@ -3,10 +3,37 @@
#include "Constants.h"
#include "HwInterface.h"
#include "HwCap.h"
#include "HwDetInfoCtrlObj.h"
#include "HwBinCtrlObj.h"
namespace lima {
class BinRoi {
public:
BinRoi() : m_max_size(), m_size(), m_bin(), m_roi() {};
void setMaxSize(Size& size);
void setBin(Bin& bin);
void setRoi(Roi& roi);
void resetBin() { m_bin.reset(); }
void resetRoi() { m_roi.reset(); }
void reset() { m_bin.reset(); m_roi.reset(); }
const Bin& getBin() const { return m_bin; }
const Roi& getRoi() const { return m_roi; }
const Size& getSize() const { return m_size; }
private:
void _getBinSize(Size& size) { size= m_max_size / m_size ; }
void _updateRoi();
void _updateSize();
Size m_max_size, m_size;
Bin m_bin;
Roi m_roi;
};
class CtImage {
public:
......@@ -16,46 +43,66 @@ class CtImage {
SoftOnly,
HardAndSoft,
};
// Size, Type, Bin, XY from common
CtImage(HwInterface *hw);
~CtImage();
void getMaxImageSize(Size& size) const;
void getImageSize(Size& size) const;
void setMaxImage(Size size, ImageType type);
void getImageType(ImageType& type) const;
void getHwImageDim(FrameDim& dim) const;
void getImageDim(FrameDim& dim) const;
// --- soft
void setSoftRoi(const Roi &roi);
/* void setSoftRoi(Roi roi);
void resetSoftRoi(Roi roi);
void getSoftRoi(Roi& roi) const;
void setSoftBin(const Bin &bin);
void setSoftBin(Bin bin);
void resetSoftBin();
void getSoftBin(Bin& bin) const;
// --- hard
void setHardRoi(const Roi &roi);
void getHardRoi(Roi &roi) const;
void setHardRoi(Roi roi);
void resetHardRoi();
void getHardRoi(Roi roi);
void setHardBin(const Bin &bin);
void setHardBin(Bin bin);
void resetHardBin();
void getHardBin(Bin& bin) const;
*/
// --- wizard
void setWizardMode(WizardMode mode);
/* void setWizardMode(WizardMode mode);
void getWizardMode(WizardMode& mode) const;
void setWizardRoi(const Roi &roi);
void setWizardBin(const Bin &bin);
void setWizardRoi(Roi roi);
void setWizardBin(Bin bin);
void resetWizardRoi();
void resetWizardBin();
*/
// --- effective
void getRoi(Roi& roi) const;
void getBin(Bin& bin) const;
/* void getRoi(Roi& roi) const;
void setBin(Bin& bin) const;
void reset();
*/
private:
Roi m_soft_roi, m_hard_roi, m_eff_roi;
Bin m_soft_bin, m_hard_bin, n_eff_bin;
WizardMode m_wizard_mode;
HwDetInfoCtrlObj *m_hw_det;
HwBinCtrlObj *m_hw_bin;
// HwRoiCtrlObj *m_hw_roi;
// HwFlipCtrlObj *m_hw_flip;
bool m_has_hw_bin, m_has_hw_roi, m_has_hw_flip;
Size m_max_size, m_hw_size, m_sw_size;
ImageType m_img_type;
// BinRoi m_hw_binroi, m_sw_binroi;
// WizardMode m_wizard_mode;
};
} // namespace lima
......
#include "CtAcquisition.h"
#include "math.h"
using namespace lima;
CtAcquisition::CtAcquisition(HwInterface *hw)
{
if (!hw->getHwCtrlObj(m_hw_sync))
throw LIMA_CTL_EXC(Error, "Cannot get hardware sync object");
m_hw_sync->getValidRanges(m_valid_ranges);
m_applied_once= false;
}
CtAcquisition::~CtAcquisition()
{
}
void CtAcquisition::setPars(Parameters pars)
{
setAcqMode(pars.acqMode);
setAcqNbFrames(pars.acqNbFrames);
setAcqExpoTime(pars.acqExpoTime);
setAccMaxExpoTime(pars.accMaxExpoTime);
setConcatNbFrames(pars.concatNbFrames);
setLatencyTime(pars.latencyTime);
setTriggerMode(pars.triggerMode);
}
void CtAcquisition::getPars(Parameters& pars) const
{
pars= m_inpars;
}
void CtAcquisition::apply(CtControl::ApplyPolicy policy)
{
CtControl::ApplyPolicy use_policy;
use_policy= m_applied_once ? policy : CtControl::All;
switch (policy) {
case CtControl::All:
// --- apply all parameters
m_changes.set(1);
_apply();
break;
case CtControl::Changes:
// --- apply changed parameters (use internal soft cache)
m_changes.check(m_inpars, m_hwpars);
_apply();
break;
case CtControl::HwSyncChanges:
// --- read hw and apply changed parameters
_hwRead();
m_changes.check(m_inpars, m_hwpars);
_apply();
break;
default:
m_changes.set(1);
_apply();
}
}
void CtAcquisition::sync()
{
_hwRead();
m_inpars= m_hwpars;
}
void CtAcquisition::_hwRead()
{
int read_nframes;
m_hw_sync->getTrigMode(m_hwpars.triggerMode);
m_hw_sync->getExpTime(m_hwpars.acqExpoTime);
m_hw_sync->getLatTime(m_hwpars.latencyTime);
m_hw_sync->getNbFrames(m_hwpars.acqNbFrames);
switch (m_hwpars.acqMode) {
case Single:
m_hwpars.acqNbFrames= read_nframes;
m_hwpars.concatNbFrames= 0;
m_acc_exptime= m_hwpars.accMaxExpoTime;
m_acc_nframes= 0;
break;
case Concatenation:
// concatNbFrames unchanged (or read in buffer ??)
m_hwpars.acqNbFrames= read_nframes;
m_acc_exptime= m_hwpars.accMaxExpoTime;
m_acc_nframes= 0;
break;
case Accumulation:
m_hwpars.concatNbFrames= 0;
_updateAccPars();
m_hwpars.acqNbFrames= int(read_nframes / m_acc_nframes);
break;
}
}
void CtAcquisition::_apply()
{
if (m_changes.triggerMode) m_hw_sync->setTrigMode(m_inpars.triggerMode);
if (m_changes.latencyTime) m_hw_sync->setLatTime(m_inpars.latencyTime);
switch (m_inpars.acqMode) {
case Single:
if (m_changes.acqExpoTime) m_hw_sync->setExpTime(m_inpars.acqExpoTime);
if (m_changes.acqNbFrames) m_hw_sync->setNbFrames(m_inpars.acqNbFrames);
break;
case Concatenation:
if (m_changes.acqExpoTime) m_hw_sync->setExpTime(m_inpars.acqExpoTime);
if (m_changes.acqNbFrames) m_hw_sync->setNbFrames(m_inpars.acqNbFrames);
break;
case Accumulation:
if (m_changes.acqExpoTime || m_changes.accMaxExpoTime) {
_updateAccPars();
m_hw_sync->setExpTime(m_acc_exptime);
m_hw_sync->setNbFrames(m_inpars.acqNbFrames * m_acc_nframes);
} else if (m_changes.acqNbFrames) {
m_hw_sync->setNbFrames(m_inpars.acqNbFrames * m_acc_nframes);
}
break;
}
m_hwpars= m_inpars;
m_changes.set(0);
}
void CtAcquisition::setTriggerMode(TrigMode mode)
{
m_inpars.triggerMode= mode;
}
void CtAcquisition::getTriggerMode(TrigMode& mode) const
{
mode= m_inpars.triggerMode;
}
void CtAcquisition::setAcqMode(AcqMode mode)
{
m_inpars.acqMode= mode;
switch (m_inpars.acqMode) {
case Single:
if (m_inpars.acqNbFrames<1) m_inpars.acqNbFrames= 1;
break;
case Accumulation:
if (m_inpars.accMaxExpoTime<=0) {
m_inpars.accMaxExpoTime= m_inpars.acqExpoTime;
}
case Concatenation:
if (m_inpars.concatNbFrames<1)
m_inpars.concatNbFrames= 1;
break;
}
}
void CtAcquisition::getAcqMode(AcqMode& mode) const
{
mode= m_inpars.acqMode;
}
void CtAcquisition::setAcqNbFrames(int nframes)
{
m_inpars.acqNbFrames= nframes;
}
void CtAcquisition::getAcqNbFrames(int& nframes) const
{
nframes= m_inpars.acqNbFrames;
}
void CtAcquisition::setAcqExpoTime(double acq_time)
{
if (acq_time < m_valid_ranges.min_exp_time)
throw LIMA_CTL_EXC(InvalidValue, "Exposure time too short");
if (acq_time > m_valid_ranges.max_exp_time)
throw LIMA_CTL_EXC(InvalidValue, "Exposure time too long");
m_inpars.acqExpoTime= acq_time;
}
void CtAcquisition::getAcqExpoTime(double& acq_time) const
{
acq_time= m_inpars.acqExpoTime;
}
void CtAcquisition::getAccNbFrames(int& nframes)
{
_updateAccPars();
nframes= m_acc_nframes;
}
void CtAcquisition::setAccMaxExpoTime(double acc_time)
{
m_inpars.accMaxExpoTime= acc_time;
}
void CtAcquisition::getAccExpoTime(double& acc_time)
{
_updateAccPars();
acc_time= m_acc_exptime;
}
void CtAcquisition::_updateAccPars()
{
int acc_div;
acc_div= int(m_inpars.acqExpoTime / m_inpars.accMaxExpoTime);
if (fmod(m_inpars.acqExpoTime,m_inpars.accMaxExpoTime)) {
m_acc_nframes= acc_div + 1;
m_acc_exptime= m_inpars.acqExpoTime / m_acc_nframes;
} else {
m_acc_nframes= acc_div;
m_acc_exptime= m_inpars.accMaxExpoTime;
}
}
void CtAcquisition::setConcatNbFrames(int nframes)
{
m_inpars.concatNbFrames= nframes;
}
void CtAcquisition::getConcatNbFrames(int& nframes) const
{
nframes= m_inpars.concatNbFrames;
}
void CtAcquisition::setLatencyTime(double lat_time)
{
if (lat_time < m_valid_ranges.min_lat_time)
throw LIMA_CTL_EXC(InvalidValue, "Latency time too short");
if (lat_time > m_valid_ranges.max_lat_time)
throw LIMA_CTL_EXC(InvalidValue, "Latency time too long");
m_inpars.latencyTime= lat_time;
}
void CtAcquisition::getLatencyTime(double& time) const
{
time= m_inpars.latencyTime;
}
// ------------------
// struct Parameters
// ------------------
CtAcquisition::Parameters::Parameters()
{
reset();
}
void CtAcquisition::Parameters::reset()
{