Commit 9d856951 authored by ahoms's avatar ahoms
Browse files

* using templates in HwCap based on CtrlObjPtr type to avoid void pointers

* added ostream& operator << for classes in SizeUtils, Constants, HwFrameInfo
* added testsimuhwinterface using generic HwInterface only
* fixed bug in SimuDetInfoCtrlObj that swapping Max/DetectorImageSize



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@45 45c4679d-1946-429d-baad-37912b19538b
parent 4c666eda
......@@ -20,12 +20,12 @@ void SimuDetInfoCtrlObj::getMaxImageSize(Size& max_image_size)
{
FrameDim fdim;
m_simu.getFrameDim(fdim);
det_image_size = fdim.getSize();
max_image_size = fdim.getSize();
}
void SimuDetInfoCtrlObj::getDetectorImageSize(Size& det_image_size)
{
m_simu.getMaxImageSize(max_image_size);
m_simu.getMaxImageSize(det_image_size);
}
void SimuDetInfoCtrlObj::getDefImageType(ImageType& def_image_type)
......@@ -231,14 +231,14 @@ void SimuSyncCtrlObj::getValidRanges(ValidRangesType& valid_ranges)
SimuHwInterface::SimuHwInterface(Simulator& simu)
: m_simu(simu), m_det_info(simu), m_buffer(simu), m_sync(simu)
{
HwCap cap = HwCap(HwCap::DetInfo, &m_det_info);
m_cap_list.push_back(cap);
HwDetInfoCtrlObj *det_info = &m_det_info;
m_cap_list.push_back(HwCap(det_info));
cap = HwCap(HwCap::Buffer, &m_buffer);
m_cap_list.push_back(cap);
HwBufferCtrlObj *buffer = &m_buffer;
m_cap_list.push_back(HwCap(buffer));
cap = HwCap(HwCap::Sync, &m_sync);
m_cap_list.push_back(cap);
HwSyncCtrlObj *sync = &m_sync;
m_cap_list.push_back(HwCap(sync));
}
SimuHwInterface::~SimuHwInterface()
......
......@@ -8,11 +8,14 @@ test-ext-objs = $(simu-objs)
testsimulator-objs = testsimulator.o BufferSave.o
testsimulator-ext-objs = $(simu-objs) $(std-objs)
testsimuhwinterface-objs = testsimuhwinterface.o BufferSave.o
testsimuhwinterface-ext-objs = $(simu-objs) $(std-objs)
INC = -I../include -I../../../common/include -I../../../hardware/include
CXXFLAGS += $(INC) -Wall -pthread
LDFLAGS = -pthread
all: clean test testsimulator
all: clean test testsimulator testsimuhwinterface
test: $(test-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(test-ext-objs) $(std-objs)
......@@ -20,11 +23,11 @@ test: $(test-objs)
testsimulator: $(testsimulator-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(testsimulator-ext-objs)
clean: test-clean testsimulator-clean
testsimuhwinterface: $(testsimuhwinterface-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(testsimuhwinterface-ext-objs)
test-clean:
clean:
rm -f $(test-objs) test *.edf
testsimulator-clean:
rm -f $(testsimulator-objs) testsimulator
rm -f $(testsimuhwinterface-objs) testsimuhwinterface
#include "SimuHwInterface.h"
#include "BufferSave.h"
#include <iostream>
using namespace lima;
using namespace std;
class TestFrameCallback : public HwFrameCallback
{
public:
TestFrameCallback(SimuHwInterface& simu_hw, BufferSave& buffer_save)
: m_simu_hw(simu_hw), m_buffer_save(buffer_save) {}
protected:
virtual bool newFrameReady(const HwFrameInfoType& frame_info);
private:
SimuHwInterface& m_simu_hw;
BufferSave& m_buffer_save;
};
bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info)
{
HwInterface::Status status;
m_simu_hw.getStatus(status);
cout << "In callback:" << endl
<< " frame_info=" << frame_info << endl
<< " status=" << status << endl;
m_buffer_save.writeFrame(frame_info);
return true;
}
void print_status(SimuHwInterface& simu_hw)
{
HwInterface::Status status;
simu_hw.getStatus(status);
cout << "status=" << status << endl;
}
int main(int argc, char *argv[])
{
Simulator simu;
SimuHwInterface simu_hw(simu);
BufferSave buffer_save(BufferSave::EDF);
TestFrameCallback cb(simu_hw, buffer_save);
HwDetInfoCtrlObj *hw_det_info;
simu_hw.getHwCtrlObj(hw_det_info);
HwBufferCtrlObj *hw_buffer;
simu_hw.getHwCtrlObj(hw_buffer);
HwSyncCtrlObj *hw_sync;
simu_hw.getHwCtrlObj(hw_sync);
// HwBinCtrlObj *hw_bin;
// simu_hw.getCtrlObj(hw_bin);
Size size;
hw_det_info->getMaxImageSize(size);
ImageType image_type;
hw_det_info->getCurrImageType(image_type);
FrameDim frame_dim(size, image_type);
Bin bin;
// if (hw_bin)
// hw_bin->getBin(bin);
FrameDim effect_frame_dim = frame_dim / bin;
hw_buffer->setFrameDim(effect_frame_dim);
hw_buffer->setNbBuffers(10);
hw_buffer->registerFrameCallback(&cb);
print_status(simu_hw);
simu_hw.startAcq();
print_status(simu_hw);
simu_hw.stopAcq();
print_status(simu_hw);
hw_sync->setExpTime(5);
print_status(simu_hw);
simu_hw.startAcq();
print_status(simu_hw);
simu_hw.stopAcq();
print_status(simu_hw);
hw_sync->setExpTime(2);
hw_sync->setNbFrames(3);
print_status(simu_hw);
simu_hw.startAcq();
print_status(simu_hw);
simu_hw.stopAcq();
print_status(simu_hw);
return 0;
}
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <ostream>
namespace lima
{
......@@ -8,24 +10,34 @@ enum AlignDir {
Floor, Ceil,
};
std::ostream& operator <<(std::ostream& os, AlignDir align_dir);
enum ImageType {
Bpp8, Bpp10, Bpp12, Bpp14, Bpp16, Bpp32
};
std::ostream& operator <<(std::ostream& os, ImageType image_type);
enum AcqMode {
Single, Accumulation, Concatenation,
};
std::ostream& operator <<(std::ostream& os, AcqMode acq_mode);
enum TrigMode {
IntTrig,
ExtTrigSingle, ExtTrigMult,
ExtGate, ExtStartStop,
};
std::ostream& operator <<(std::ostream& os, TrigMode trig_mode);
enum BufferMode {
Linear, Circular,
};
std::ostream& operator <<(std::ostream& os, BufferMode buffer_mode);
} // namespace lima
#endif // CONSTANTS_H
......@@ -3,6 +3,7 @@
#include "Constants.h"
#include "Exceptions.h"
#include <ostream>
namespace lima
{
......@@ -95,6 +96,8 @@ inline bool operator !=(const Point& p1, const Point& p2)
return !(p1 == p2);
}
std::ostream& operator <<(std::ostream& os, const Point& p);
/*******************************************************************
* \class Size
......@@ -157,6 +160,8 @@ inline Point Size::checkValid(const Point& p)
return p;
}
std::ostream& operator <<(std::ostream& os, const Size& s);
/*******************************************************************
* \class Bin
......@@ -216,6 +221,8 @@ inline Point Bin::checkValid(const Point& p)
return p;
}
std::ostream& operator <<(std::ostream& os, const Bin& bin);
/*******************************************************************
* \class Roi
......@@ -228,7 +235,8 @@ inline Point Bin::checkValid(const Point& p)
class Roi
{
public:
Roi();
Roi() {}
Roi(const Point& top_left, const Size& size)
: m_top_left(checkCorner(top_left)),
m_size(size) {}
......@@ -377,6 +385,8 @@ inline bool operator !=(const Roi& r1, const Roi& r2)
return !(r1 == r2);
}
std::ostream& operator <<(std::ostream& os, const Roi& roi);
/*******************************************************************
* \class FrameDim
......@@ -524,6 +534,9 @@ inline FrameDim operator /(const FrameDim& fdim, const Bin& bin)
return bin_fdim /= bin;
}
std::ostream& operator <<(std::ostream& os, const FrameDim& fdim);
} // namespace lima
#endif // SIZEUTILS_H
#include "Constants.h"
using namespace lima;
using namespace std;
ostream& lima::operator <<(ostream& os, AlignDir align_dir)
{
const char *name = "Unknown";
switch (align_dir) {
case Floor: name = "Floor"; break;
case Ceil: name = "Ceil"; break;
}
return os << name;
}
ostream& lima::operator <<(ostream& os, ImageType image_type)
{
const char *name = "Unknown";
switch (image_type) {
case Bpp8: name = "Bpp8"; break;
case Bpp10: name = "Bpp10"; break;
case Bpp12: name = "Bpp12"; break;
case Bpp14: name = "Bpp14"; break;
case Bpp16: name = "Bpp16"; break;
case Bpp32: name = "Bpp32"; break;
}
return os << name;
}
ostream& lima::operator <<(ostream& os, AcqMode acq_mode)
{
const char *name = "Unknown";
switch (acq_mode) {
case Single: name = "Single"; break;
case Accumulation: name = "Accumulation"; break;
case Concatenation: name = "Concatenation"; break;
}
return os << name;
}
ostream& lima::operator <<(ostream& os, TrigMode trig_mode)
{
const char *name = "Unknown";
switch (trig_mode) {
case IntTrig: name = "IntTrig"; break;
case ExtTrigSingle: name = "ExtTrigSingle"; break;
case ExtTrigMult: name = "ExtTrigMult"; break;
case ExtGate: name = "ExtGate"; break;
case ExtStartStop: name = "ExtStartStop"; break;
}
return os << name;
}
ostream& lima::operator <<(ostream& os, BufferMode buffer_mode)
{
const char *name = "Unknown";
switch (buffer_mode) {
case Linear: name = "Linear"; break;
case Circular: name = "Circular"; break;
}
return os << name;
}
common-objs := SizeUtils.o Timestamp.o ThreadUtils.o Exceptions.o
common-objs := Constants.o SizeUtils.o Timestamp.o ThreadUtils.o Exceptions.o
CXXFLAGS += -I../include -Wall -pthread
......
#include "SizeUtils.h"
using namespace lima;
using std::min;
using std::max;
using namespace std;
/*******************************************************************
......@@ -23,6 +21,22 @@ void Point::alignTo(const Point& p, AlignDir align_dir)
*this *= p;
}
ostream& lima::operator <<(ostream& os, const Point& p)
{
return os << "<" << p.x << "," << p.y << ">";
}
ostream& lima::operator <<(ostream& os, const Size& s)
{
return os << "<" << s.getWidth() << "x" << s.getHeight() << ">";
}
ostream& lima::operator <<(ostream& os, const Bin& bin)
{
return os << "<" << bin.getX() << "x" << bin.getY() << ">";
}
/*******************************************************************
* \brief Set the roi by giving to arbitrary (diagonal) corners
......@@ -41,6 +55,11 @@ void Roi::setCorners(const Point& p1, const Point& p2)
m_size = bottom_right + 1 - m_top_left;
}
ostream& lima::operator <<(ostream& os, const Roi& roi)
{
return os << roi.getTopLeft() << "-" << roi.getSize();
}
int FrameDim::getImageTypeBpp(ImageType type)
{
switch (type) {
......@@ -72,9 +91,9 @@ int FrameDim::getImageTypeDepth(ImageType type)
}
}
Roi::Roi()
ostream& lima::operator <<(ostream& os, const FrameDim& fdim)
{
m_top_left = Point(0, 0);
m_size = Size(0, 0);
const Size& size = fdim.getSize();
return os << "<" << size.getWidth() << "x" << size.getHeight() << "x"
<< fdim.getDepth() << "-" << fdim.getImageType() << ">";
}
#ifndef HWCAP_H
#define HWCAP_H
#include "Constants.h"
namespace lima
{
......@@ -16,10 +18,23 @@ public:
SerialLine, // Generic detector serial line
};
HwCap(Type type, void *ctrl_obj);
template <class CtrlObj>
HwCap(CtrlObj *ctrl_obj) : m_ctrl_obj(ctrl_obj)
{ m_type = getTypeFromCtrlObj(ctrl_obj); }
Type getType() const
{ return m_type; }
Type getType() const;
void *getCtrlObj() const;
template <class CtrlObj>
static Type getTypeFromCtrlObj(CtrlObj *ctrl_obj);
template <class CtrlObj>
bool getCtrlObj(CtrlObj *& ctrl_obj) const
{
bool ok = (m_type == getTypeFromCtrlObj(ctrl_obj));
ctrl_obj = ok ? (CtrlObj *) m_ctrl_obj : NULL;
return ok;
}
private:
Type m_type;
......@@ -32,4 +47,5 @@ public:
#include "HwBufferCtrlObj.h"
#include "HwSyncCtrlObj.h"
#endif // HWCAP_H
#ifndef HWFRAMEINFO_H
#define HWFRAMEINFO_H
#include "SizeUtils.h"
#include "Timestamp.h"
#include <ostream>
namespace lima
{
......@@ -28,6 +32,7 @@ typedef struct HwFrameInfo {
frame_timestamp(timestamp), valid_pixels(pixels) {}
} HwFrameInfoType;
std::ostream& operator <<(std::ostream& os, const HwFrameInfoType& info);
}
......
......@@ -3,6 +3,7 @@
#include "HwCap.h"
#include <vector>
#include <ostream>
namespace lima
{
......@@ -41,9 +42,11 @@ class HwInterface
HwInterface();
virtual ~HwInterface();
const HwCap *getCapOfType(HwCap::Type cap_type) const;
virtual const CapList& getCapList() const = 0;
template <class CtrlObj>
bool getHwCtrlObj(CtrlObj *& ctrl_obj_ptr) const;
virtual void reset(ResetLevel reset_level) = 0;
virtual void prepareAcq() = 0;
virtual void startAcq() = 0;
......@@ -52,6 +55,28 @@ class HwInterface
virtual int getNbAcquiredFrames() = 0;
};
template <class CtrlObj>
bool HwInterface::getHwCtrlObj(CtrlObj *& ctrl_obj) const
{
const CapList& cap_list = getCapList();
typedef CapList::const_iterator It;
for (It i = cap_list.begin(); i != cap_list.end(); ++i)
if (i->getCtrlObj(ctrl_obj))
return true;
ctrl_obj = NULL;
return false;
}
std::ostream& operator <<(std::ostream& os,
HwInterface::AcqStatus acq_status);
std::ostream& operator <<(std::ostream& os,
HwInterface::DetStatus det_status);
std::ostream& operator <<(std::ostream& os,
const HwInterface::StatusType& status);
} // namespace lima
#endif // HWINTERFACE_H
#include "HwCap.h"
using namespace lima;
namespace lima
{
HwCap::HwCap(Type type, void *ctrl_obj)
template <>
HwCap::Type HwCap::getTypeFromCtrlObj<>(HwDetInfoCtrlObj *p)
{
m_type = type;
m_ctrl_obj = ctrl_obj;
return DetInfo;
}
HwCap::Type HwCap::getType() const
template <>
HwCap::Type HwCap::getTypeFromCtrlObj<>(HwBufferCtrlObj *p)
{
return m_type;
return Buffer;
}
void *HwCap::getCtrlObj() const
template <>
HwCap::Type HwCap::getTypeFromCtrlObj<>(HwSyncCtrlObj *p)
{
return m_ctrl_obj;
return Sync;
}
} // namespace lima
#include "HwFrameInfo.h"
using namespace lima;
using namespace std;
ostream& lima::operator <<(ostream& os, const HwFrameInfoType& info)
{
os << "<"
<< "acq_frame_nb=" << info.acq_frame_nb << ", "
<< "frame_ptr=" << info.frame_ptr << ", "
<< "frame_dim=" << *info.frame_dim << ", "
<< "time_stamp=" << info.frame_timestamp << ", "
<< "valid_pixels=" << info.valid_pixels
<< ">";
return os;
}
#include "HwInterface.h"
using namespace lima;
using namespace std;
HwInterface::HwInterface()
{
......@@ -10,14 +11,59 @@ HwInterface::~HwInterface()
{
}
const HwCap *HwInterface::getCapOfType(HwCap::Type cap_type) const
ostream& lima::operator <<(ostream& os,
HwInterface::AcqStatus acq_status)
{
const CapList& cap_list = getCapList();
string name = "Unknown";
switch (acq_status) {
case HwInterface::AcqReady: name = "AcqReady"; break;
case HwInterface::AcqRunning: name = "AcqRunning"; break;
case HwInterface::AcqFault: name = "AcqFault"; break;
}
return os << name;
}
void AddToken(string& str, const string& token, const string& sep)
{
if (str.length() > 0)
str += sep;
str += token;
}
typedef CapList::const_iterator It;
for (It i = cap_list.begin(); i != cap_list.end(); ++i)
if (i->getType() == cap_type)
return &(*i);
ostream& lima::operator <<(ostream& os,
HwInterface::DetStatus det_status)
{
if (det_status == HwInterface::DetIdle)
return os << "Idle";
return NULL;
string name, sep = "+";
if (det_status & HwInterface::DetFault)
AddToken(name, "DetFault", sep);
if (det_status & HwInterface::WaitForTrigger)
AddToken(name, "WaitForTrigger", sep);
if (det_status & HwInterface::ShutterOpen)