Commit 7a5ee06b authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Operator for ID00
Browse files

Add ClockDiv and ReadoutFlags control support

parent e34bd73f
......@@ -53,6 +53,8 @@ public:
typedef Defs::Settings Settings;
typedef Defs::DACIndex DACIndex;
typedef Defs::ADCIndex ADCIndex;
typedef Defs::ClockDiv ClockDiv;
typedef Defs::ReadoutFlags ReadoutFlags;
enum State {
Idle, Init, Starting, Running, StopReq, Stopping, Stopped,
......@@ -95,11 +97,18 @@ public:
FloatList& min_val_list) = 0;
protected:
void updateCameraModel();
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
virtual bool checkSettings(Settings settings) = 0;
virtual ReadoutFlags getReadoutFlagsMask() = 0;
virtual bool checkReadoutFlags(ReadoutFlags flags,
IntList& flag_list,
bool silent = false) = 0;
virtual int getRecvPorts() = 0;
virtual void prepareAcq() = 0;
......@@ -243,6 +252,12 @@ public:
void setThresholdEnergy(int thres);
void getThresholdEnergy(int& thres);
void setClockDiv(ClockDiv clock_div);
void getClockDiv(ClockDiv& clock_div);
void setReadoutFlags(ReadoutFlags flags);
void getReadoutFlags(ReadoutFlags& flags);
void getValidReadoutFlags(IntList& flag_list, NameList& flag_name_list);
void prepareAcq();
void startAcq();
void stopAcq();
......@@ -385,6 +400,9 @@ private:
void receiverFrameFinished(FrameType frame, Receiver *recv);
void frameFinished(FrameType frame);
void addValidReadoutFlags(DebObj *deb_ptr, ReadoutFlags flags,
IntList& flag_list, NameList& flag_name_list);
template <class T>
void putNbCmd(const std::string& cmd, T val, int idx = -1)
{
......
......@@ -133,10 +133,33 @@ enum ADCIndex {
TempFPGAFR = slsDetectorDefs::TEMPERATURE_FPGA3,
};
enum ClockDiv {
FullSpeed,
HalfSpeed,
QuarterSpeed,
SuperSlowSpeed,
};
enum ReadoutFlags {
Normal = slsDetectorDefs::NORMAL_READOUT,
StoreInRAM = slsDetectorDefs::STORE_IN_RAM,
ReadHits = slsDetectorDefs::READ_HITS,
ZeroCompress = slsDetectorDefs::ZERO_COMPRESSION,
PumpProbe = slsDetectorDefs::PUMP_PROBE_MODE,
BackgndCorr = slsDetectorDefs::BACKGROUND_CORRECTIONS,
TOTMode = slsDetectorDefs::TOT_MODE,
Continous = slsDetectorDefs::CONTINOUS_RO,
Parallel = slsDetectorDefs::PARALLEL,
NonParallel = slsDetectorDefs::NONPARALLEL,
Safe = slsDetectorDefs::SAFE,
};
std::ostream& operator <<(std::ostream& os, TrigMode trig_mode);
std::ostream& operator <<(std::ostream& os, Settings settings);
std::ostream& operator <<(std::ostream& os, DACIndex dac_idx);
std::ostream& operator <<(std::ostream& os, ADCIndex adc_idx);
std::ostream& operator <<(std::ostream& os, ClockDiv clock_div);
std::ostream& operator <<(std::ostream& os, ReadoutFlags flags);
} // namespace Defs
......
......@@ -42,6 +42,7 @@ class Eiger : public Camera::Model
public:
typedef Defs::Settings Settings;
typedef Defs::ReadoutFlags ReadoutFlags;
typedef Camera::FrameType FrameType;
typedef Camera::NameList NameList;
typedef Camera::IntList IntList;
......@@ -131,6 +132,11 @@ class Eiger : public Camera::Model
protected:
virtual bool checkSettings(Settings settings);
virtual ReadoutFlags getReadoutFlagsMask();
virtual bool checkReadoutFlags(ReadoutFlags flags,
IntList& flag_list,
bool silent = false);
virtual int getRecvPorts();
virtual void prepareAcq();
......@@ -275,6 +281,8 @@ class Eiger : public Camera::Model
std::vector<BorderFactor> m_f;
};
int countFlags(ReadoutFlags flags);
void getRecvFrameDim(FrameDim& frame_dim, bool raw, bool geom);
int getPortIndex(int recv_idx, int port)
......
......@@ -70,12 +70,22 @@ public:
std::vector<double>& min_val_list /Out/) = 0;
protected:
void updateCameraModel();
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
virtual
bool checkSettings(SlsDetector::Defs::Settings settings) = 0;
virtual
SlsDetector::Defs::ReadoutFlags getReadoutFlagsMask() = 0;
virtual
bool checkReadoutFlags(
SlsDetector::Defs::ReadoutFlags flags,
std::vector<int>& flag_list,
bool silent = false) = 0;
virtual int getRecvPorts() = 0;
virtual void prepareAcq() = 0;
......@@ -181,6 +191,13 @@ public:
void setThresholdEnergy(int thres);
void getThresholdEnergy(int& thres /Out/);
void setClockDiv(SlsDetector::Defs::ClockDiv clock_div);
void getClockDiv(SlsDetector::Defs::ClockDiv& clock_div /Out/);
void setReadoutFlags(SlsDetector::Defs::ReadoutFlags flags);
void getReadoutFlags(SlsDetector::Defs::ReadoutFlags& flags /Out/);
void getValidReadoutFlags(std::vector<int>& flag_list /Out/,
std::vector<std::string>& flag_name_list /Out/);
void prepareAcq();
void startAcq();
void stopAcq();
......
......@@ -131,6 +131,27 @@ enum ADCIndex {
TempFPGAFR = TEMPERATURE_FPGA3,
};
enum ClockDiv {
FullSpeed,
HalfSpeed,
QuarterSpeed,
SuperSlowSpeed,
};
enum ReadoutFlags {
Normal = NORMAL_READOUT,
StoreInRAM = STORE_IN_RAM,
ReadHits = READ_HITS,
ZeroCompress = ZERO_COMPRESSION,
PumpProbe = PUMP_PROBE_MODE,
BackgndCorr = BACKGROUND_CORRECTIONS,
TOTMode = TOT_MODE,
Continous = CONTINOUS_RO,
Parallel = PARALLEL,
NonParallel = NONPARALLEL,
Safe = SAFE,
};
}; // namespace Defs
}; // namespace SlsDetector
......@@ -63,6 +63,11 @@ class Eiger : public SlsDetector::Camera::Model
protected:
virtual bool checkSettings(SlsDetector::Defs::Settings settings);
virtual SlsDetector::Defs::ReadoutFlags getReadoutFlagsMask();
virtual bool checkReadoutFlags(SlsDetector::Defs::ReadoutFlags flags,
std::vector<int>& flag_list,
bool silent = false);
virtual int getRecvPorts();
virtual void prepareAcq();
......
......@@ -35,8 +35,6 @@ Camera::Model::Model(Camera *cam, Type type)
{
DEB_CONSTRUCTOR();
DEB_PARAM() << DEB_VAR1(type);
m_cam->setModel(this);
}
Camera::Model::~Model()
......@@ -47,6 +45,12 @@ Camera::Model::~Model()
m_cam->setModel(NULL);
}
void Camera::Model::updateCameraModel()
{
DEB_MEMBER_FUNCT();
m_cam->setModel(this);
}
void Camera::Model::putCmd(const string& s, int idx)
{
DEB_MEMBER_FUNCT();
......@@ -596,6 +600,10 @@ void Camera::setModel(Model *model)
if (m_model)
m_model->m_cam = NULL;
m_model = model;
if (!m_model)
return;
setSettings(m_settings);
}
char *Camera::getFrameBufferPtr(FrameType frame_nb)
......@@ -817,9 +825,6 @@ void Camera::prepareAcq()
m_frame_queue.pop();
}
setSettings(m_settings);
m_model->prepareAcq();
// recv->resetAcquisitionCount()
......@@ -993,3 +998,102 @@ void Camera::getThresholdEnergy(int& thres)
DEB_RETURN() << DEB_VAR1(thres);
}
void Camera::setClockDiv(ClockDiv clock_div)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(clock_div);
m_det->setSpeed(slsDetectorDefs::CLOCK_DIVIDER, clock_div);
}
void Camera::getClockDiv(ClockDiv& clock_div)
{
DEB_MEMBER_FUNCT();
int ret = m_det->setSpeed(slsDetectorDefs::CLOCK_DIVIDER, -1);
if (ret == MultiSlsDetectorErr)
THROW_HW_ERROR(Error) << "Error getting clock divider";
clock_div = ClockDiv(ret);
DEB_RETURN() << DEB_VAR1(clock_div);
}
void Camera::setReadoutFlags(ReadoutFlags flags)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(flags);
if (!m_model)
return;
IntList flags_list;
if (!m_model->checkReadoutFlags(flags, flags_list))
THROW_HW_ERROR(InvalidValue) << DEB_VAR1(flags);
IntList::const_iterator it, end = flags_list.end();
for (it = flags_list.begin(); it != end; ++it) {
typedef slsDetectorDefs::readOutFlags DetFlags;
DetFlags det_flags = static_cast<DetFlags>(*it);
m_det->setReadOutFlags(det_flags);
}
}
void Camera::getReadoutFlags(ReadoutFlags& flags)
{
DEB_MEMBER_FUNCT();
typedef slsDetectorDefs::readOutFlags DetFlags;
DetFlags det_flags = static_cast<DetFlags>(-1);
int ret = m_det->setReadOutFlags(det_flags);
if (ret == MultiSlsDetectorErr)
THROW_HW_ERROR(Error) << "Error getting flags";
flags = ReadoutFlags(ret);
DEB_RETURN() << DEB_VAR1(flags);
}
void Camera::addValidReadoutFlags(DebObj *deb_ptr, ReadoutFlags flags,
IntList& flag_list, NameList& flag_name_list)
{
DEB_FROM_PTR(deb_ptr);
ostringstream os;
os << flags;
DEB_RETURN() << DEB_VAR2(flags, os.str());
flag_list.push_back(flags);
flag_name_list.push_back(os.str());
}
void Camera::getValidReadoutFlags(IntList& flag_list, NameList& flag_name_list)
{
DEB_MEMBER_FUNCT();
flag_list.clear();
flag_name_list.clear();
#define add_valid_flags(x) \
do { \
addValidReadoutFlags(&deb, x, flag_list, flag_name_list); \
} while (0)
if (!m_model)
return;
IntList aux_list;
ReadoutFlags flags = Defs::Normal;
if (m_model->checkReadoutFlags(flags, aux_list, true))
add_valid_flags(flags);
ReadoutFlags flag_mask = m_model->getReadoutFlagsMask();
IntList det_flags;
const unsigned int nb_bits = sizeof(ReadoutFlags) * 8;
for (unsigned int i = 0; i < nb_bits; ++i) {
int flags = (1 << i);
if (flag_mask & flags)
det_flags.push_back(flags);
}
int max_flags = (1 << det_flags.size());
for (int n = 0; n < max_flags; ++n) {
flags = ReadoutFlags(0);
for (unsigned int i = 0; i < nb_bits; ++i) {
if (n & (1 << i))
flags = ReadoutFlags(flags | det_flags[i]);
}
if (m_model->checkReadoutFlags(flags, aux_list, true))
add_valid_flags(flags);
}
}
......@@ -21,6 +21,7 @@
//###########################################################################
#include "SlsDetectorCamera.h"
#include "lima/MiscUtils.h"
using namespace std;
using namespace lima;
......@@ -143,3 +144,52 @@ ostream& lima::SlsDetector::Defs::operator <<(ostream& os, ADCIndex adc_idx)
}
return os << name;
}
ostream& lima::SlsDetector::Defs::operator <<(ostream& os, ClockDiv clock_div)
{
const char *name = "Unknown";
switch (clock_div) {
case FullSpeed: name = "FullSpeed"; break;
case HalfSpeed: name = "HalfSpeed"; break;
case QuarterSpeed: name = "QuarterSpeed"; break;
case SuperSlowSpeed: name = "SuperSlowSpeed"; break;
}
return os << name;
}
ostream& lima::SlsDetector::Defs::operator <<(ostream& os, ReadoutFlags flags)
{
#define READOUT_FLAG(x) {#x, x}
static struct FlagData {
const char *name;
ReadoutFlags flag;
} ReadoutFlagNamesCList[] = {
READOUT_FLAG(StoreInRAM),
READOUT_FLAG(ReadHits),
READOUT_FLAG(ZeroCompress),
READOUT_FLAG(PumpProbe),
READOUT_FLAG(BackgndCorr),
READOUT_FLAG(TOTMode),
READOUT_FLAG(Continous),
READOUT_FLAG(Parallel),
READOUT_FLAG(NonParallel),
READOUT_FLAG(Safe),
};
const unsigned int size = C_LIST_SIZE(ReadoutFlagNamesCList);
struct FlagData *data = ReadoutFlagNamesCList;
bool empty = true;
for (unsigned int i = 0; i < size; ++i, ++data) {
if (flags & data->flag) {
if (!empty)
os << " + ";
os << data->name;
empty = false;
}
}
if (empty)
os << ((flags == Normal) ? "Normal" : "Unknown");
return os;
}
......@@ -239,6 +239,8 @@ Eiger::Eiger(Camera *cam)
m_port_geom_list.push_back(g);
}
}
updateCameraModel();
}
Eiger::~Eiger()
......@@ -412,6 +414,66 @@ bool Eiger::checkSettings(Settings settings)
return ok;
}
Eiger::ReadoutFlags Eiger::getReadoutFlagsMask()
{
DEB_MEMBER_FUNCT();
ReadoutFlags flags = ReadoutFlags(Parallel | NonParallel | Safe |
StoreInRAM | Continous);
DEB_RETURN() << DEB_VAR1(flags);
return flags;
}
bool Eiger::checkReadoutFlags(ReadoutFlags flags, IntList& flag_list,
bool silent)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(flags, silent);
bool ok = false;
ReadoutFlags mask, result;
mask = ReadoutFlags(Parallel | NonParallel | Safe);
result = ReadoutFlags(flags & mask);
flags = ReadoutFlags(flags & ~mask);
if (countFlags(result) != 1) {
if (!silent)
DEB_ERROR() << "Invalid number of readout-mode flags";
goto out;
}
flag_list.push_back(result);
mask = ReadoutFlags(StoreInRAM | Continous);
result = ReadoutFlags(flags & mask);
flags = ReadoutFlags(flags & ~mask);
if (countFlags(result) != 1) {
if (!silent)
DEB_ERROR() << "Invalid number of store-in-mem flags";
goto out;
}
flag_list.push_back(result);
if (flags != 0) {
if (!silent)
DEB_ERROR() << "Invalid flags for Eiger: " << flags;
goto out;
}
ok = true;
out:
DEB_RETURN() << DEB_VAR1(ok);
return ok;
}
int Eiger::countFlags(ReadoutFlags flags)
{
const unsigned int nb_bits = sizeof(flags) * 8;
int count = 0;
for (unsigned int i = 0; i < nb_bits; ++i)
if (flags & (1 << i))
count++;
return count;
}
int Eiger::getRecvPorts()
{
DEB_MEMBER_FUNCT();
......
Supports Markdown
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