Commit 2ccaaa08 authored by ahoms's avatar ahoms
Browse files

* added Timestamp class

* moved FrameInfo outside of HwFrameCallback
* progressed in the BufferMgr class structure
* created Shutter hw capability with functions from Sync



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@20 45c4679d-1946-429d-baad-37912b19538b
parent c459eafc
......@@ -22,10 +22,6 @@ enum TrigMode {
ExtGate, ExtStartStop,
};
enum ShutMode {
Manual, AutoFrame, AutoSeq,
};
enum BufferMode {
Linear, Circular,
};
......
#ifndef TIMESTAMP_H
#define TIMESTAMP_H
#include "Exceptions.h"
namespace lima
{
class Timestamp
{
public:
Timestamp() : m_ts(Unset) {}
Timestamp(double ts) : m_ts(ts) {}
Timestamp(const Timestamp& ts) : m_ts(ts.m_ts) {}
bool isSet() const
{ return *this != Unset; }
operator double() const
{ return m_ts; }
Timestamp& operator =(const Timestamp& ts)
{ m_ts = ts.m_ts; return *this; }
Timestamp& operator +=(const Timestamp& ts)
{ validValue() += ts.validValue(); return *this; }
Timestamp& operator -=(const Timestamp& ts)
{ validValue() -= ts.validValue(); return *this; }
Timestamp& operator *=(double factor)
{ validValue() *= factor; return *this; }
Timestamp& operator /=(double factor)
{ validValue() /= factor; return *this; }
static Timestamp now();
private:
static const Timestamp Unset;
double& validValue();
const double& validValue() const;
double m_ts;
};
inline double& Timestamp::validValue()
{
if (!isSet())
throw LIMA_COM_EXC(InvalidValue, "Timestamp not set");
return m_ts;
}
inline const double& Timestamp::validValue() const
{
if (!isSet())
throw LIMA_COM_EXC(InvalidValue, "Timestamp not set");
return m_ts;
}
inline Timestamp operator +(Timestamp t1, Timestamp t2)
{
return t1 += t2;
}
inline Timestamp operator -(Timestamp t1, Timestamp t2)
{
return t1 -= t2;
}
inline Timestamp operator *(Timestamp t, double factor)
{
return t *= factor;
}
inline Timestamp operator /(Timestamp t, double factor)
{
return t /= factor;
}
}
#endif // TIMESTAMP_H
common-objs := SizeUtils.o
common-objs := SizeUtils.o Timestamp.o
CXXFLAGS += -I../include -Wall
......
#include "Timestamp.h"
#include "Exceptions.h"
#include <sys/time.h>
#include <iostream>
using namespace lima;
const Timestamp Timestamp::Unset = -12345678901234567890.1234567890;
Timestamp Timestamp::now()
{
struct timeval t;
if (gettimeofday(&t, NULL) < 0)
throw LIMA_HW_EXC(Error, "Error calling gettimeofday");
return t.tv_sec + t.tv_usec * 1e-6;
}
......@@ -6,7 +6,7 @@
namespace lima
{
class HwBufferCtrlObj : public HwFrameCallbackGen
class HwBufferCtrlObj
{
public:
HwBufferCtrlObj();
......@@ -29,10 +29,12 @@ public:
virtual void setBufferMode(BufferMode buffer_mode) = 0;
virtual void getBufferMode(BufferMode& buffer_mode) = 0;
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual void *getFramePtr(int acq_frame_nb) = 0;
virtual double getFrameTimeStamp(int acq_frame_nb) = 0;
virtual Timestamp getFrameTimeStamp(int acq_frame_nb) = 0;
virtual void registerFrameCallback(HwFrameCallback *frame_cb) = 0;
virtual void unregisterFrameCallback(HwFrameCallback *frame_cb) = 0;
};
} // namespace lima
......
......@@ -9,37 +9,56 @@
namespace lima
{
class BaseBufferMgr : HwFrameCallbackGen
/*******************************************************************
* \class BufferAllocMgr
* \brief Abstract class defining interface for buffer allocation
*
* Specifies the basic functionality for allocating frame buffers
*******************************************************************/
class BufferAllocMgr
{
public:
virtual ~BufferAllocMgr();
virtual int getMaxNbBuffers(const FrameDim& frame_dim) = 0;
virtual void allocBuffers(int nb_buffers,
const FrameDim& frame_dim) = 0;
virtual const FrameDim& getFrameDim() = 0;
virtual int getNbBuffers() = 0;
virtual void releaseBuffers() = 0;
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual double getBufferTimestamp(int buffer_nb) = 0;
virtual void clearBuffer(int buffer_nb);
virtual void clearAllBuffers();
};
class SoftBufferMgr : public BaseBufferMgr
/*******************************************************************
* \class SoftBufferAllocMgr
* \brief Simple full software implementation of BufferAllocMgr
*
* This classes uses new and delete to allocate the memory buffers
*******************************************************************/
class SoftBufferAllocMgr : public BufferAllocMgr
{
public:
SoftBufferMgr();
virtual ~SoftBufferMgr();
SoftBufferAllocMgr();
virtual ~SoftBufferAllocMgr();
static int getSystemMem(int& mem_unit);
virtual int getMaxNbBuffers(const FrameDim& frame_dim);
virtual void allocBuffers(int nb_buffers,
const FrameDim& frame_dim);
virtual const FrameDim& getFrameDim() const;
virtual int getNbBuffers() const;
virtual const FrameDim& getFrameDim();
virtual int getNbBuffers();
virtual void releaseBuffers();
virtual void *getBufferPtr(int buffer_nb) const;
virtual double getBufferTimestamp(int buffer_nb);
virtual void *getBufferPtr(int buffer_nb);
private:
typedef std::vector<char *> BufferList;
typedef BufferList::const_iterator BufferListCIt;
......@@ -48,43 +67,125 @@ class SoftBufferMgr : public BaseBufferMgr
BufferList m_buffer_list;
};
inline const FrameDim& SoftBufferMgr::getFrameDim() const
{
return m_frame_dim;
}
inline int SoftBufferMgr::getNbBuffers() const
{
return m_buffer_list.size();
}
/*******************************************************************
* \class BufferCbMgr
* \brief Abstract class with interface for buffer alloc. and callbacks
*
* Specifies the basic functionality for allocating frame buffers and
* for managing the frame callbacks
*******************************************************************/
inline void *SoftBufferMgr::getBufferPtr(int buffer_nb) const
class BufferCbMgr : public HwFrameCallbackGen
{
return m_buffer_list[buffer_nb];
}
public:
enum Cap {
Concat=1, Acc=2,
};
inline double SoftBufferMgr::getBufferTimestamp(int buffer_nb)
{
return 0;
}
virtual ~BufferCbMgr();
virtual Cap getCap() = 0;
virtual int getMaxNbBuffers(const FrameDim& frame_dim) = 0;
virtual void allocBuffers(int nb_buffers,
const FrameDim& frame_dim) = 0;
virtual const FrameDim& getFrameDim() = 0;
virtual int getNbBuffers() = 0;
virtual void releaseBuffers() = 0;
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual void clearBuffer(int buffer_nb) = 0;
virtual void clearAllBuffers() = 0;
class ConcatBufferMgr : public BaseBufferMgr
virtual Timestamp getBufferTimestamp(int buffer_nb) = 0;
};
/*******************************************************************
* \class StdBufferCbMgr
* \brief Class providing standard buffer cb functionality
*
* This class implements the normal buffer mode using a basic
* BufferAllocMgr
*******************************************************************/
class StdBufferCbMgr : public BufferCbMgr
{
public:
StdBufferCbMgr(BufferAllocMgr *alloc_mgr = NULL);
virtual ~StdBufferCbMgr();
virtual Cap getCap();
virtual int getMaxNbBuffers(const FrameDim& frame_dim);
virtual void allocBuffers(int nb_buffers,
const FrameDim& frame_dim);
virtual const FrameDim& getFrameDim() const;
virtual int getNbBuffers() const;
virtual void releaseBuffers();
virtual void *getBufferPtr(int buffer_nb) const;
virtual Timestamp getBufferTimestamp(int buffer_nb) const;
void setStartTimestamp(Timestamp start_ts);
bool newFrameReady(int acq_frame_nr);
protected:
virtual void setFrameCallbackActive(bool cb_active);
private:
typedef std::vector<Timestamp> TimestampList;
BufferAllocMgr *m_alloc_mgr;
bool m_int_alloc_mgr;
TimestampList m_ts_list;
Timestamp m_start_ts;
bool m_fcb_act;
};
class AccBufferMgr : public BaseBufferMgr
/*******************************************************************
* \class BufferCtrlMgr
* \brief Class providing full buffer functionality for a given hardware
*
* This class implements all the buffer functionality required by the
* hardware buffer interface. It can use different kinds of acq. buffer
* managers and complement their missing functionality.
*******************************************************************/
class BufferCtrlMgr
{
public:
void setFrameDim(const FrameDim& frame_dim);
void getFramedim( FrameDim& frame_dim);
void setNbBuffers(int nb_buffers);
void getNbBuffers(int& nb_buffers);
void setNbConcatFrames(int nb_concat_frames);
void getNbConcatFrames(int& nb_concat_frames);
void setNbAccFrames(int nb_acc_frames);
void getNbAccFrames(int& nb_acc_frames);
void getMaxNbBuffers(int& max_nb_buffers);
void setBufferMode(BufferMode buffer_mode);
void getBufferMode(BufferMode& buffer_mode);
void *getBufferPtr(int buffer_nb);
void *getFramePtr(int acq_frame_nb);
Timestamp getFrameTimeStamp(int acq_frame_nb);
void registerFrameCallback(HwFrameCallback *frame_cb);
void unregisterFrameCallback(HwFrameCallback *frame_cb);
};
} // namespace lima
#endif // HWBUFFERMGR_H
......@@ -13,6 +13,7 @@ public:
Roi, Bin, Flip, // Image operations
Kinetics, FrameTransfer,// Acquisition modes
Timing, // Read only detector timmings
Shutter, // Shutter control
SerialLine, // Generic detector serial line
};
......
......@@ -2,6 +2,7 @@
#define HWFRAMECALLBACK_H
#include "SizeUtils.h"
#include "Timestamp.h"
namespace lima
{
......@@ -9,6 +10,32 @@ namespace lima
class HwFrameCallback;
extern const double UnsetTimestamp;
/*******************************************************************
* \typedef FrameInfoType
* \brief Structure containing information about acquired frame
*
*
*******************************************************************/
typedef struct FrameInfo {
int acq_frame_nb;
void *frame_ptr;
const FrameDim *frame_dim;
Timestamp frame_timestamp;
FrameInfo()
: acq_frame_nb(-1), frame_ptr(NULL), frame_dim(),
frame_timestamp() {}
FrameInfo(int frame_nb, void *ptr, const FrameDim *dim,
Timestamp timestamp)
: acq_frame_nb(frame_nb), frame_ptr(ptr), frame_dim(dim),
frame_timestamp(timestamp) {}
} FrameInfoType;
/*******************************************************************
* \class HwFrameCallbackGen
* \brief Abstract class with interface for frame callback generation
......@@ -28,6 +55,7 @@ class HwFrameCallbackGen
protected:
HwFrameCallbackGen();
virtual void setFrameCallbackActive(bool cb_active) = 0;
bool newFrameReady(const FrameInfoType& frame_info);
private:
HwFrameCallback *m_frame_cb;
......@@ -43,18 +71,12 @@ class HwFrameCallbackGen
class HwFrameCallback
{
public:
typedef struct FrameInfo {
int acq_frame_nb;
void *frame_ptr;
const FrameDim& frame_dim;
double frame_time_stamp;
} FrameInfoType;
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual ~HwFrameCallback();
HwFrameCallbackGen *getFrameCallbackGen() const;
protected:
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual bool newFrameReady(const FrameInfoType& frame_info) = 0;
private:
......
#ifndef HWSHUTTERCTRLOBJ_H
#define HWSHUTTERCTRLOBJ_H
#include "Constants.h"
namespace lima
{
class HwShutterCtrlObj
{
public:
enum Mode {
Manual, AutoFrame, AutoSeq,
};
HwShutterCtrlObj();
virtual ~HwShutterCtrlObj();
virtual void setMode(Mode mode) = 0;
virtual void getMode(Mode& mode) = 0;
virtual void setState(bool open) = 0;
virtual void getState(bool& open) = 0;
virtual void setOpenTime (double shut_open_time) = 0;
virtual void getOpenTime (double& shut_open_time) = 0;
virtual void setCloseTime(double shut_close_time) = 0;
virtual void getCloseTime(double& shut_close_time) = 0;
private:
};
} // namespace lima
#endif // HWSHUTTERCTRLOBJ_H
......@@ -6,9 +6,15 @@
namespace lima
{
class HwSyncCtrlObj
{
public:
typedef struct ValidRanges {
double min_exp_time, max_exp_time;
double min_lat_time, max_lat_time;
} ValidRangesType;
HwSyncCtrlObj();
virtual ~HwSyncCtrlObj();
......@@ -21,20 +27,11 @@ public:
virtual void setLatTime(double lat_time) = 0;
virtual void getLatTime(double& lat_time) = 0;
virtual void setShutMode(ShutMode shut_mode) = 0;
virtual void getShutMode(ShutMode& shut_mode) = 0;
virtual void setShutState(bool shut_open) = 0;
virtual void getShutState(bool& shut_open) = 0;
virtual void setShutOpenTime (double shut_open_time) = 0;
virtual void getShutOpenTime (double& shut_open_time) = 0;
virtual void setShutCloseTime(double shut_close_time) = 0;
virtual void getShutCloseTime(double& shut_close_time) = 0;
virtual void setNbFrames(int nb_frames) = 0;
virtual void getNbFrames(int& nb_frames) = 0;
virtual const ValidRangesType& getValidRanges() = 0;
private:
};
......
#include "HwBufferMgr.h"
#include <sys/sysinfo.h>
#include <limits.h>
using namespace lima;
SoftBufferMgr::SoftBufferMgr()
/*******************************************************************
* \brief BufferAllocMgr destructor
*******************************************************************/
BufferAllocMgr::~BufferAllocMgr()
{
}
void BufferAllocMgr::clearBuffer(int buffer_nb)
{
void *ptr = getBufferPtr(buffer_nb);
const FrameDim& frame_dim = getFrameDim();
memset(ptr, 0, frame_dim.getMemSize());
}
void BufferAllocMgr::clearAllBuffers()
{
for (int i = 0; i < getNbBuffers(); i++)
clearBuffer(i);
}
SoftBufferMgr::~SoftBufferMgr()
/*******************************************************************
* \brief SoftBufferAllocMgr constructor
*******************************************************************/
SoftBufferAllocMgr::SoftBufferAllocMgr()
{
}
SoftBufferAllocMgr::~SoftBufferAllocMgr()
{
releaseBuffers();
}
int SoftBufferMgr::getMaxNbBuffers(const FrameDim& frame_dim)
int SoftBufferAllocMgr::getSystemMem(int& mem_unit)
{
return 0;
if (mem_unit < 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid mem_unit value");
struct sysinfo s_info;
if (sysinfo(&s_info) < 0)
throw LIMA_HW_EXC(Error, "Error calling sysinfo");
long long tot_mem = s_info.totalram;
tot_mem *= s_info.mem_unit;
if (mem_unit == 0)
mem_unit = s_info.mem_unit;
long long mem_blocks = tot_mem / mem_unit;
if (mem_blocks > INT_MAX)
throw LIMA_HW_EXC(Error, "Too much memory to be described "
"with the given mem_unit");
return mem_blocks;
}
int SoftBufferAllocMgr::getMaxNbBuffers(const FrameDim& frame_dim)
{
int frame_size = frame_dim.getMemSize();
if (frame_size <= 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid FrameDim");
long long tot_buffers = getSystemMem(frame_size);
return tot_buffers * 3 / 4;
}
void SoftBufferMgr::allocBuffers(int nb_buffers,
void SoftBufferAllocMgr::allocBuffers(int nb_buffers,
const FrameDim& frame_dim)
{
int frame_size = frame_dim.getMemSize();
if (frame_size <= 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid FrameDim");
BufferList& bl = m_buffer_list;
bl.reserve(nb_buffers);
if ((frame_dim == m_frame_dim) && (nb_buffers == getNbBuffers()))
return;
releaseBuffers();
int max_buffers = getMaxNbBuffers(frame_dim);
if ((nb_buffers < 1) || (nb_buffers > max_buffers))
throw LIMA_HW_EXC(InvalidValue, "Invalid number of buffers");
try {
for (int i = 0; i < nb_buffers; ++i)
bl.push_back(new char[frame_size]);
m_buffer_list.reserve(nb_buffers);
for (int i = 0; i < nb_buffers; ++i)