Commit b7e2ee14 authored by ahoms's avatar ahoms
Browse files

* added Espia::Dev getCcdStatus and resetLink (with 0.5 sec sleep)

* added Frelon::Camera get/waitStatus; stop will wait for Wait status
* added Frelon::Interface getStatus and reset (miss add in last commit)



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@83 45c4679d-1946-429d-baad-37912b19538b
parent 782267ca
......@@ -18,7 +18,6 @@ class Acq : public HwFrameCallbackGen
~Acq();
typedef struct Status {
bool started;
bool running;
int run_nb;
int last_frame_nb;
......
......@@ -25,9 +25,14 @@ class Dev
void registerCallback(struct espia_cb_data& cb_data, int& cb_nr);
void unregisterCallback(int& cb_nr);
void resetLink();
void getCcdStatus(int& ccd_status);
AutoMutex acqLock();
private:
static const double ResetLinkTime;
void open(int dev_nb);
void close();
......
......@@ -19,9 +19,10 @@ class SerialLine : public HwSerialLine
SerialLine( Dev& edev, const std::string& line_term="\r",
double timeout=1.0, int block_size=0,
double block_delay=0 );
~SerialLine();
Dev& getDev();
virtual void write( const std::string& buffer, bool no_wait=false );
virtual void read( std::string& buffer, int max_len,
......
......@@ -108,8 +108,14 @@ void Acq::lastFrameCallback(struct espia_cb_data *cb_data)
AutoMutex l = acqLock();
struct img_frame_info& cb_finfo = cb_data->info.acq.cb_finfo;
if (!finished_espia_frame_info(&cb_finfo, cb_data->ret))
if (finished_espia_frame_info(&cb_finfo, cb_data->ret)) {
m_started = false;
} else {
m_last_frame_info = cb_finfo;
bool endless = (m_nb_frames == 0);
if (!endless && (cb_finfo.acq_frame_nr == m_nb_frames - 1))
m_started = false;
}
}
void Acq::userFrameCallback(struct espia_cb_data *cb_data)
......@@ -306,8 +312,7 @@ void Acq::getStatus(StatusType& status)
int acq_running = espia_acq_active(m_dev, &acq_run_nb);
CHECK_CALL(acq_running);
status.started = m_started;
status.running = acq_running;
status.running = m_started;
status.run_nb = acq_run_nb;
status.last_frame_nb = m_last_frame_info.acq_frame_nr;
}
......
......@@ -5,6 +5,8 @@ using namespace std;
#define CHECK_CALL(ret) ESPIA_CHECK_CALL(ret)
const double Dev::ResetLinkTime = 0.5;
Dev::Dev(int dev_nb)
{
m_dev_nb = Invalid;
......@@ -61,3 +63,15 @@ void Dev::unregisterCallback(int& cb_nr)
cb_nr = Invalid;
}
void Dev::resetLink()
{
CHECK_CALL(espia_reset_link(m_dev));
Sleep(ResetLinkTime);
}
void Dev::getCcdStatus(int& ccd_status)
{
unsigned char status;
CHECK_CALL(espia_ccd_status(m_dev, &status, SCDXIPCI_NO_BLOCK));
ccd_status = status;
}
......@@ -24,6 +24,12 @@ SerialLine::~SerialLine()
}
Dev& SerialLine::getDev()
{
return m_dev;
}
void SerialLine::write( const string& buffer, bool no_wait )
{
unsigned long len = buffer.size();
......
......@@ -106,6 +106,17 @@ enum {
MaxBinY = 1024,
};
enum Status {
Wait = 0x80,
Transfer = 0x40,
Exposure = 0x20,
Shutter = 0x10,
Readout = 0x08,
Latency = 0x04,
ExtStart = 0x02,
ExtStop = 0x01,
};
} // namespace Frelon
......
......@@ -63,11 +63,17 @@ class Camera
void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames);
void getStatus(Status& status);
bool waitStatus(Status& status, double timeout = 0);
void start();
void stop();
private:
static const double HorzBinSleepTime;
static const double HorzBinChangeTime;
static const double MaxReadoutTime;
Espia::Dev& getEspiaDev();
void sendCmd(Cmd cmd);
......
#ifndef FRELONINTERFACE_H
#define FRELONINTERFACE_H
#include "HwInterface.h"
#include "EspiaBufferMgr.h"
#include "FrelonCamera.h"
namespace lima
{
namespace Frelon
{
class Interface;
/*******************************************************************
* \class DetInfoCtrlObj
* \brief Control object providing Frelon detector info interface
*******************************************************************/
class DetInfoCtrlObj : public HwDetInfoCtrlObj
{
public:
DetInfoCtrlObj(Camera& cam);
virtual ~DetInfoCtrlObj();
virtual void getMaxImageSize(Size& max_image_size);
virtual void getDetectorImageSize(Size& det_image_size);
virtual void getDefImageType(ImageType& def_image_type);
virtual void getCurrImageType(ImageType& curr_image_type);
virtual void setCurrImageType(ImageType curr_image_type);
virtual void getPixelSize(double& pixel_size);
virtual void getDetectorType(std::string& det_type);
virtual void getDetectorModel(std::string& det_model);
protected:
virtual void setMaxImageSizeCallbackActive(bool cb_active);
private:
Camera& m_cam;
bool m_iscb_act;
};
/*******************************************************************
* \class BufferCtrlObj
* \brief Control object providing Frelon buffering interface
*******************************************************************/
class BufferCtrlObj : public HwBufferCtrlObj
{
public:
BufferCtrlObj(BufferCtrlMgr& buffer_mgr);
virtual ~BufferCtrlObj();
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, int concat_frame_nb = 0);
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:
BufferCtrlMgr& m_buffer_mgr;
};
/*******************************************************************
* \class SyncCtrlObj
* \brief Control object providing Frelon synchronization interface
*******************************************************************/
class SyncCtrlObj : public HwSyncCtrlObj
{
public:
SyncCtrlObj(Espia::Acq& acq, Camera& cam);
virtual ~SyncCtrlObj();
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:
Espia::Acq& m_acq;
Camera& m_cam;
};
/*******************************************************************
* \class BinCtrlObj
* \brief Control object providing simulator binning interface
*******************************************************************/
class BinCtrlObj : public HwBinCtrlObj
{
public:
BinCtrlObj(Camera& cam);
virtual ~BinCtrlObj();
virtual void setBin(const Bin& bin);
virtual void getBin(Bin& bin);
virtual void checkBin(Bin& bin);
private:
Camera& m_cam;
};
/*******************************************************************
* \class Interface
* \brief Frelon hardware interface
*******************************************************************/
class Interface : public HwInterface
{
public:
Interface(Espia::Acq& acq, BufferCtrlMgr& buffer_mgr, Camera& cam);
virtual ~Interface();
virtual const CapList& getCapList() const;
virtual void reset(ResetLevel reset_level);
virtual void prepareAcq();
virtual void startAcq();
virtual void stopAcq();
virtual void getStatus(StatusType& status);
virtual int getNbAcquiredFrames();
private:
Espia::Acq& m_acq;
BufferCtrlMgr& m_buffer_mgr;
Camera& m_cam;
CapList m_cap_list;
DetInfoCtrlObj m_det_info;
BufferCtrlObj m_buffer;
SyncCtrlObj m_sync;
BinCtrlObj m_bin;
};
} // namespace Frelon
} // namespace lima
#endif // FRELONINTERFACE_H
......@@ -31,6 +31,8 @@ class SerialLine : public HwSerialLine
SerialLine(Espia::SerialLine& espia_ser_line);
Espia::SerialLine& getEspiaSerialLine();
virtual void write(const std::string& buffer,
bool no_wait = false);
virtual void read(std::string& buffer,
......
......@@ -3,10 +3,13 @@
#include "MiscUtils.h"
#include <sstream>
using namespace lima;
using namespace lima::Frelon;
using namespace std;
const double Camera::HorzBinSleepTime = 2;
const double Camera::HorzBinChangeTime = 2.0;
const double Camera::MaxReadoutTime = 0.7;
Camera::Camera(Espia::SerialLine& espia_ser_line)
: m_ser_line(espia_ser_line)
......@@ -20,6 +23,13 @@ SerialLine& Camera::getSerialLine()
return m_ser_line;
}
Espia::Dev& Camera::getEspiaDev()
{
Espia::SerialLine ser_line = m_ser_line.getEspiaSerialLine();
Espia::Dev& dev = ser_line.getDev();
return dev;
}
void Camera::sendCmd(Cmd cmd)
{
string resp;
......@@ -44,6 +54,9 @@ void Camera::readRegister(Reg reg, int& val)
void Camera::hardReset()
{
Espia::Dev& dev = getEspiaDev();
dev.resetLink();
sendCmd(Reset);
}
......@@ -209,7 +222,7 @@ void Camera::setBin(const Bin& bin)
setRoi(roi);
writeRegister(BinHorz, bin.getX());
Sleep(HorzBinSleepTime);
Sleep(HorzBinChangeTime);
writeRegister(BinVert, bin.getY());
}
......@@ -456,6 +469,7 @@ void Camera::getRoi(Roi& hw_roi)
void Camera::setTrigMode(TrigMode trig_mode)
{
m_trig_mode = trig_mode;
setNbFrames(m_nb_frames);
}
void Camera::getTrigMode(TrigMode& trig_mode)
......@@ -535,6 +549,31 @@ void Camera::getNbFrames(int& nb_frames)
nb_frames = m_nb_frames;
}
void Camera::getStatus(Status& status)
{
Espia::Dev& dev = getEspiaDev();
int ccd_status;
dev.getCcdStatus(ccd_status);
status = Status(ccd_status);
}
bool Camera::waitStatus(Status& status, double timeout)
{
Timestamp end;
if (timeout > 0)
end = Timestamp::now() + Timestamp(timeout);
bool good_status = false;
Status curr_status;
while (!good_status && !end.isSet() || (Timestamp::now() < end)) {
getStatus(curr_status);
good_status = ((curr_status & status) == status);
}
status = curr_status;
return good_status;
}
void Camera::start()
{
TrigMode trig_mode;
......@@ -549,5 +588,13 @@ void Camera::stop()
getTrigMode(trig_mode);
if (trig_mode != ExtGate)
sendCmd(Stop);
Status status = Wait;
waitStatus(status);
FrameTransferMode ftm;
getFrameTransferMode(ftm);
if (ftm == FTM)
Sleep(MaxReadoutTime);
}
#include "FrelonInterface.h"
#include <algorithm>
using namespace lima;
using namespace lima::Espia;
using namespace lima::Frelon;
using namespace std;
/*******************************************************************
* \brief DetInfoCtrlObj constructor
*******************************************************************/
DetInfoCtrlObj::DetInfoCtrlObj(Camera& cam)
: m_cam(cam)
{
}
DetInfoCtrlObj::~DetInfoCtrlObj()
{
}
void DetInfoCtrlObj::getMaxImageSize(Size& max_image_size)
{
FrameDim max_frame_dim;
m_cam.getFrameDim(max_frame_dim);
max_image_size = max_frame_dim.getSize();
}
void DetInfoCtrlObj::getDetectorImageSize(Size& det_image_size)
{
det_image_size = MaxFrameDim.getSize();
}
void DetInfoCtrlObj::getDefImageType(ImageType& def_image_type)
{
def_image_type = MaxFrameDim.getImageType();
}
void DetInfoCtrlObj::getCurrImageType(ImageType& curr_image_type)
{
FrameDim max_frame_dim;
m_cam.getFrameDim(max_frame_dim);
curr_image_type = max_frame_dim.getImageType();
}
void DetInfoCtrlObj::setCurrImageType(ImageType curr_image_type)
{
ImageType unique_image_type;
getCurrImageType(unique_image_type);
if (curr_image_type != unique_image_type)
throw LIMA_HW_EXC(InvalidValue, "Only one image type allowed");
}
void DetInfoCtrlObj::getPixelSize(double& pixel_size)
{
bool is_frelon_4m;
m_cam.isFrelon4M(is_frelon_4m);
ChipType chip_type = is_frelon_4m ? Kodak : Atmel;
pixel_size = ChipPixelSizeMap[chip_type];
}
void DetInfoCtrlObj::getDetectorType(std::string& det_type)
{
det_type = "Frelon";
}
void DetInfoCtrlObj::getDetectorModel(std::string& det_model)
{
bool is_frelon_4m;
m_cam.isFrelon4M(is_frelon_4m);
det_model = is_frelon_4m ? "4M" : "2k";
if (!is_frelon_4m) {
bool is_frelon_2k16;
m_cam.isFrelon2k16(is_frelon_2k16);
det_model += is_frelon_2k16 ? "16" : "14";
}
bool has_taper;
m_cam.hasTaper(has_taper);
if (has_taper)
det_model += "T";
}
void DetInfoCtrlObj::setMaxImageSizeCallbackActive(bool cb_active)
{
}
/*******************************************************************
* \brief BufferCtrlObj constructor
*******************************************************************/
BufferCtrlObj::BufferCtrlObj(BufferCtrlMgr& buffer_mgr)
: m_buffer_mgr(buffer_mgr)
{
}
BufferCtrlObj::~BufferCtrlObj()
{
}
void BufferCtrlObj::setFrameDim(const FrameDim& frame_dim)
{
m_buffer_mgr.setFrameDim(frame_dim);
}
void BufferCtrlObj::getFramedim(FrameDim& frame_dim)
{
m_buffer_mgr.getFrameDim(frame_dim);
}
void BufferCtrlObj::setNbBuffers(int nb_buffers)
{
m_buffer_mgr.setNbBuffers(nb_buffers);
}
void BufferCtrlObj::getNbBuffers(int& nb_buffers)
{
m_buffer_mgr.getNbBuffers(nb_buffers);
}
void BufferCtrlObj::setNbConcatFrames(int nb_concat_frames)
{
m_buffer_mgr.setNbConcatFrames(nb_concat_frames);
}
void BufferCtrlObj::getNbConcatFrames(int& nb_concat_frames)
{
m_buffer_mgr.getNbConcatFrames(nb_concat_frames);
}
void BufferCtrlObj::setNbAccFrames(int nb_acc_frames)
{
m_buffer_mgr.setNbAccFrames(nb_acc_frames);
}
void BufferCtrlObj::getNbAccFrames(int& nb_acc_frames)
{
m_buffer_mgr.getNbAccFrames(nb_acc_frames);
}
void BufferCtrlObj::getMaxNbBuffers(int& max_nb_buffers)
{
m_buffer_mgr.getMaxNbBuffers(max_nb_buffers);
}
void *BufferCtrlObj::getBufferPtr(int buffer_nb, int concat_frame_nb)
{
return m_buffer_mgr.getBufferPtr(buffer_nb, concat_frame_nb);
}
void *BufferCtrlObj::getFramePtr(int acq_frame_nb)
{
return m_buffer_mgr.getFramePtr(acq_frame_nb);
}
void BufferCtrlObj::getStartTimestamp(Timestamp& start_ts)
{
m_buffer_mgr.getStartTimestamp(start_ts);
}
void BufferCtrlObj::getFrameInfo(int acq_frame_nb, HwFrameInfoType& info)
{
m_buffer_mgr.getFrameInfo(acq_frame_nb, info);
}
void BufferCtrlObj::registerFrameCallback(HwFrameCallback& frame_cb)
{
m_buffer_mgr.registerFrameCallback(frame_cb);
}
void BufferCtrlObj::unregisterFrameCallback(HwFrameCallback& frame_cb)
{
m_buffer_mgr.unregisterFrameCallback(frame_cb);
}
/*******************************************************************
* \brief SyncCtrlObj constructor
*******************************************************************/
SyncCtrlObj::SyncCtrlObj(Acq& acq, Camera& cam)
: m_acq(acq), m_cam(cam)
{
}