Commit 21472459 authored by ahoms's avatar ahoms
Browse files

* renamed FrameInfo to HwFrameInfo; added valid_pixels field

* changed Timestamp by the full HwFrameInfo in buffer mgr frame history
* moved getStartTimestamp from HwInterface to HwBufferCtrlObj
* added SimuDetInfoCtrlObj; dummy implementation of SimuHwInterface
* allow modification of FrameDim size and image type


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@41 45c4679d-1946-429d-baad-37912b19538b
parent abf81007
......@@ -7,7 +7,35 @@
namespace lima
{
class SimuHwInterface: public HwInterface
class SimuHwInterface;
class SimuDetInfoCtrlObj : public HwDetInfoCtrlObj
{
public:
SimuDetInfoCtrlObj(Simulator& simu);
virtual ~SimuDetInfoCtrlObj();
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:
Simulator& m_simu;
bool m_iscb_act;
};
class SimuHwInterface : public HwInterface
{
public:
SimuHwInterface(Simulator& simu);
......@@ -21,15 +49,13 @@ class SimuHwInterface: public HwInterface
virtual void stopAcq();
virtual void getStatus(StatusType& status);
virtual int getNbAcquiredFrames();
virtual double getStartTimeStamp();
private:
Simulator& m_simu;
CapList m_cap_list;
SimuDetInfoCtrlObj m_det_info;
};
}
#endif // SIMUHWINTERFACE_H
......@@ -38,6 +38,7 @@ class Simulator
void getFrameDim(FrameDim& frame_dim);
Status getStatus();
int getNbAcquiredFrames();
private:
class SimuThread : public CmdThread
......@@ -54,6 +55,8 @@ class Simulator
SimuThread(Simulator& simu);
virtual void start();
int getNbAcquiredFrames();
protected:
virtual void init();
......@@ -66,6 +69,8 @@ class Simulator
};
friend class SimuThread;
void init();
SoftBufferAllocMgr m_buffer_alloc_mgr;
StdBufferCbMgr m_buffer_cb_mgr;
BufferCtrlMgr m_buffer_ctrl_mgr;
......
objs = FrameBuilder.o Simulator.o
simu-objs = FrameBuilder.o Simulator.o SimuHwInterface.o
CXX = g++
INC = -I../include -I../../../common/include -I../../../hardware/include
CXXFLAGS += $(INC) -Wall -pthread
all: clean $(objs)
all: clean Simu.o
Simu.o: $(simu-objs)
$(LD) -o $@ -r $+
clean:
rm -f $(objs)
rm -f Simu.o $(simu-objs)
......@@ -2,11 +2,119 @@
using namespace lima;
SimuDetInfoCtrlObj::SimuDetInfoCtrlObj(Simulator& simu)
: m_simu(simu)
{
m_iscb_act = false;
}
SimuDetInfoCtrlObj::~SimuDetInfoCtrlObj()
{
}
void SimuDetInfoCtrlObj::getMaxImageSize(Size& max_image_size)
{
int max_dim = 8 * 1024;
max_image_size = Size(max_dim, max_dim);
}
void SimuDetInfoCtrlObj::getDetectorImageSize(Size& det_image_size)
{
FrameDim fdim;
m_simu.getFrameDim(fdim);
det_image_size = fdim.getSize();
}
void SimuDetInfoCtrlObj::getDefImageType(ImageType& def_image_type)
{
def_image_type = Bpp16;
}
void SimuDetInfoCtrlObj::setCurrImageType(ImageType curr_image_type)
{
FrameDim fdim;
m_simu.getFrameDim(fdim);
fdim.setImageType(curr_image_type);
m_simu.setFrameDim(fdim);
}
void SimuDetInfoCtrlObj::getCurrImageType(ImageType& curr_image_type)
{
FrameDim fdim;
m_simu.getFrameDim(fdim);
curr_image_type = fdim.getImageType();
}
void SimuDetInfoCtrlObj::getPixelSize(double& pixel_size)
{
pixel_size = 1e-6;
}
void SimuDetInfoCtrlObj::getDetectorType(std::string& det_type)
{
det_type = "Simulator";
}
void SimuDetInfoCtrlObj::getDetectorModel(std::string& det_model)
{
det_model = "PeakGenerator";
}
void SimuDetInfoCtrlObj::setMaxImageSizeCallbackActive(bool cb_active)
{
m_iscb_act = cb_active;
}
SimuHwInterface::SimuHwInterface(Simulator& simu)
: m_simu(simu)
: m_simu(simu), m_det_info(simu)
{
HwCap cap = HwCap(HwCap::DetInfo, &m_det_info);
m_cap_list.push_back(cap);
}
SimuHwInterface::~SimuHwInterface()
{
}
const HwInterface::CapList& SimuHwInterface::getCapList() const
{
return m_cap_list;
}
void SimuHwInterface::reset(ResetLevel reset_level)
{
}
void SimuHwInterface::prepareAcq()
{
}
void SimuHwInterface::startAcq()
{
BufferCtrlMgr& buffer_mgr = m_simu.getBufferMgr();
buffer_mgr.setStartTimestamp(Timestamp::now());
}
void SimuHwInterface::stopAcq()
{
}
void SimuHwInterface::getStatus(StatusType& status)
{
}
int SimuHwInterface::getNbAcquiredFrames()
{
return m_simu.getNbAcquiredFrames();
}
......@@ -62,15 +62,28 @@ void Simulator::SimuThread::execStartAcq()
typedef unsigned char *BufferPtr;
BufferPtr ptr = BufferPtr(buffer_mgr.getBufferPtr(buffer_nb));
frame_builder.getNextFrame(ptr);
buffer_mgr.newFrameReady(frame_nb);
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame_nb;
buffer_mgr.newFrameReady(frame_info);
}
setStatus(Ready);
}
int Simulator::SimuThread::getNbAcquiredFrames()
{
return m_acq_frame_nb;
}
Simulator::Simulator()
: m_buffer_cb_mgr(m_buffer_alloc_mgr),
m_buffer_ctrl_mgr(m_buffer_cb_mgr),
m_thread(*this)
{
init();
}
void Simulator::init()
{
m_exp_time = 1.0;
m_nb_frames = 1;
......@@ -160,6 +173,11 @@ void Simulator::stopAcq()
m_thread.waitStatus(SimuThread::Ready);
}
int Simulator::getNbAcquiredFrames()
{
return m_thread.getNbAcquiredFrames();
}
ostream& lima::operator <<(ostream& os, Simulator& simu)
{
string status;
......
......@@ -66,7 +66,7 @@ void BufferSave::closeFile()
m_idx++;
}
void BufferSave::writeEdfHeader( const FrameInfoType& finfo )
void BufferSave::writeEdfHeader( const HwFrameInfoType& finfo )
{
time_t ctime_now;
time(&ctime_now);
......@@ -103,6 +103,7 @@ void BufferSave::writeEdfHeader( const FrameInfoType& finfo )
if (finfo.frame_timestamp.isSet())
p += sprintf(p, "time_of_frame = %.6f ;\n",
double(finfo.frame_timestamp));
p += sprintf(p, "valid_pixels = %d ;\n", finfo.valid_pixels);
int l = p - buffer;
int len = l;
......@@ -115,10 +116,10 @@ void BufferSave::writeEdfHeader( const FrameInfoType& finfo )
m_fout->write(buffer, len);
}
void BufferSave::writeFrame( const FrameInfoType& finfo )
void BufferSave::writeFrame( const HwFrameInfoType& finfo )
{
const FrameDim *fdim = finfo.frame_dim;
if (fdim == NULL)
if (!fdim)
throw LIMA_HW_EXC(InvalidValue, "Null finfo.fdim");
openFile();
......@@ -135,7 +136,7 @@ void BufferSave::writeFrame( const FrameInfoType& finfo )
bool BufferSave::isFileOpen() const
{
return (m_fout != NULL);
return bool(m_fout);
}
void BufferSave::setPrefix(const String& prefix)
......
......@@ -23,7 +23,7 @@ class BufferSave {
bool overwrite = false , int tot_file_frames = 1);
~BufferSave( );
void writeFrame( const FrameInfoType& finfo );
void writeFrame( const HwFrameInfoType& finfo );
void setPrefix(const String& prefix);
void getPrefix(String& prefix) const;
......@@ -45,7 +45,7 @@ class BufferSave {
void openFile();
void closeFile();
void writeEdfHeader( const FrameInfoType& finfo );
void writeEdfHeader( const HwFrameInfoType& finfo );
FileFormat m_format;
String m_prefix;
......@@ -55,7 +55,7 @@ class BufferSave {
bool m_overwrite;
int m_written_frames;
int m_tot_file_frames;
FrameInfoType m_last_frame;
HwFrameInfoType m_last_frame;
std::ofstream *m_fout;
};
......
std-objs = ../../../common/src/Common.o ../../../hardware/src/Hw.o
simu-objs = ../src/Simu.o
test-objs = test.o BufferSave.o
test-ext-objs = ../src/FrameBuilder.o
test-ext-objs = $(simu-objs)
testsimulator-objs = testsimulator.o BufferSave.o
testsimulator-ext-objs = ../src/Simulator.o ../src/FrameBuilder.o $(std-objs)
testsimulator-ext-objs = $(simu-objs) $(std-objs)
INC = -I../include -I../../../common/include -I../../../hardware/include
CXXFLAGS += $(INC) -Wall -pthread
......
......@@ -39,7 +39,8 @@ int main( void )
fb.getNextFrame( buffer );
Timestamp t = Timestamp::now() - start;
FrameInfoType finfo(frame_nb, buffer, &fd, t);
int pixels = Point(fd.getSize()).getArea();
HwFrameInfoType finfo(frame_nb, buffer, &fd, t, pixels);
bs.writeFrame(finfo);
}
......
......@@ -12,13 +12,13 @@ public:
TestFrameCallback(Simulator& simu, BufferSave& buffer_save)
: m_simu(simu), m_buffer_save(buffer_save) {}
protected:
virtual bool newFrameReady(const FrameInfoType& frame_info);
virtual bool newFrameReady(const HwFrameInfoType& frame_info);
private:
Simulator& m_simu;
BufferSave& m_buffer_save;
};
bool TestFrameCallback::newFrameReady(const FrameInfoType& frame_info)
bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info)
{
cout << "acq_frame_nb=" << frame_info.acq_frame_nb << ", "
<< "ts=" << frame_info.frame_timestamp << ", "
......@@ -36,6 +36,7 @@ int main(int argc, char *argv[])
FrameDim frame_dim;
simu.getFrameDim(frame_dim);
Size size = frame_dim.getSize();
BufferCtrlMgr& buffer_mgr = simu.getBufferMgr();
buffer_mgr.setFrameDim(frame_dim);
......
......@@ -139,20 +139,20 @@ class Size
{ m_xy = checkValid(m_xy / p); return *this; }
private:
static bool isValid(int i);
static bool isValidCoord(int i);
static Point checkValid(const Point& p);
Point m_xy;
};
inline bool Size::isValid(int i)
inline bool Size::isValidCoord(int i)
{
return (i >= 0);
}
inline Point Size::checkValid(const Point& p)
{
if (!(isValid(p.x) && isValid(p.y)))
if (!(isValidCoord(p.x) && isValidCoord(p.y)))
throw LIMA_COM_EXC(InvalidValue, "Invalid size");
return p;
}
......@@ -192,20 +192,20 @@ class Bin
{ m_xy = checkValid(m_xy / p); return *this; }
private:
static bool isValid(int i);
static bool isValidCoord(int i);
static Point checkValid(const Point& p);
Point m_xy;
};
inline bool Bin::isValid(int i)
inline bool Bin::isValidCoord(int i)
{
return IsPowerOf2(i);
}
inline Point Bin::checkValid(const Point& p)
{
if (!(isValid(p.x) && isValid(p.y)))
if (!(isValidCoord(p.x) && isValidCoord(p.y)))
throw LIMA_COM_EXC(InvalidValue, "Invalid binning");
return p;
}
......@@ -254,6 +254,8 @@ class Roi
Roi getBinned(const Bin& b) const;
Roi getUnbinned(const Bin& b) const;
bool isActive() const;
private:
static bool isValidCoord(int i);
static Point checkCorner(const Point& TopLeft);
......@@ -304,7 +306,6 @@ inline void Roi::setSize(const Size& size)
m_size = size;
}
inline bool Roi::isValidCoord(int i)
{
return (i >= 0);
......@@ -338,6 +339,11 @@ inline Roi Roi::getUnbinned(const Bin& b) const
return Roi(m_top_left * b, Size(m_size * b));
}
inline bool Roi::isActive() const
{
return !m_size.isEmpty();
}
inline bool operator ==(const Roi& r1, const Roi& r2)
{
......@@ -351,7 +357,6 @@ inline bool operator !=(const Roi& r1, const Roi& r2)
}
/*******************************************************************
* \class FrameDim
* \brief Class holding the Size and ImageType of a frame
......@@ -367,8 +372,14 @@ class FrameDim
FrameDim(const Size& size, ImageType type);
FrameDim(int width, int height, ImageType type);
bool isValid() const;
void setSize(const Size& size);
const Size& getSize() const;
void setImageType(ImageType image_type);
ImageType getImageType() const;
int getDepth() const;
int getMemSize() const;
......@@ -405,11 +416,26 @@ inline FrameDim::FrameDim(int width, int height, ImageType type)
m_depth = getImageTypeDepth(m_type);
}
inline bool FrameDim::isValid() const
{
return !m_size.isEmpty();
}
inline const Size& FrameDim::getSize() const
{
return m_size;
}
inline void FrameDim::setSize(const Size& size)
{
m_size = size;
}
inline void FrameDim::setImageType(ImageType image_type)
{
m_type = image_type;
}
inline ImageType FrameDim::getImageType() const
{
return m_type;
......
......@@ -31,7 +31,9 @@ public:
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual void *getFramePtr(int acq_frame_nb) = 0;
virtual Timestamp getFrameTimeStamp(int acq_frame_nb) = 0;
virtual void getStartTimestamp(Timestamp& start_ts) = 0;
virtual void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info) = 0;
virtual void registerFrameCallback(HwFrameCallback *frame_cb) = 0;
virtual void unregisterFrameCallback(HwFrameCallback *frame_cb) = 0;
......
......@@ -99,7 +99,10 @@ class BufferCbMgr : public HwFrameCallbackGen
virtual void clearBuffer(int buffer_nb) = 0;
virtual void clearAllBuffers() = 0;
virtual Timestamp getBufferTimestamp(int buffer_nb) = 0;
virtual void setStartTimestamp(Timestamp start_ts) = 0;
virtual void getStartTimestamp(Timestamp& start_ts) = 0;
virtual void getFrameInfo(int buffer_nb, HwFrameInfoType& info) = 0;
};
......@@ -131,19 +134,21 @@ class StdBufferCbMgr : public BufferCbMgr
virtual void clearBuffer(int buffer_nb);
virtual void clearAllBuffers();
virtual Timestamp getBufferTimestamp(int buffer_nb);
virtual void setStartTimestamp(Timestamp start_ts);
virtual void getStartTimestamp(Timestamp& start_ts);
virtual void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info);
void setStartTimestamp(Timestamp start_ts);
bool newFrameReady(int acq_frame_nr);
bool newFrameReady(HwFrameInfoType& frame_info);
protected:
virtual void setFrameCallbackActive(bool cb_active);
private:
typedef std::vector<Timestamp> TimestampList;
typedef std::vector<HwFrameInfoType> FrameInfoList;
BufferAllocMgr& m_alloc_mgr;
TimestampList m_ts_list;
FrameInfoList m_info_list;
Timestamp m_start_ts;
bool m_fcb_act;
};
......@@ -183,7 +188,11 @@ class BufferCtrlMgr
void *getBufferPtr(int buffer_nb);
void *getFramePtr(int acq_frame_nb);
Timestamp getFrameTimeStamp(int acq_frame_nb);
void setStartTimestamp(Timestamp start_ts);
void getStartTimestamp(Timestamp& start_ts);
void getFrameInfo(int acq_frame_nb, HwFrameInfoType& info);
void registerFrameCallback(HwFrameCallback *frame_cb);
void unregisterFrameCallback(HwFrameCallback *frame_cb);
......
......@@ -19,7 +19,7 @@ class HwMaxImageSizeCallback
protected:
virtual void maxImageSizeChanged(const Size& size,
ImageType& image_type) = 0;
ImageType image_type) = 0;
private:
friend class HwDetInfoCtrlObj;
......@@ -55,6 +55,7 @@ class HwDetInfoCtrlObj
protected:
virtual void setMaxImageSizeCallbackActive(bool cb_active) = 0;
void maxImageSizeChanged(const Size& size, ImageType image_type);
private:
HwMaxImageSizeCallback *m_max_image_size_cb;
......
......@@ -3,6 +3,7 @@
#include "SizeUtils.h"
#include "Timestamp.h"
#include "HwFrameInfo.h"
namespace lima
{
......@@ -10,32 +11,6 @@ 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;
/*******************************************************************