Commit 3dec410a authored by ahoms's avatar ahoms
Browse files

* implemented ostream << Exception for better debugging

* added Size and Roi alignment methods
* added FrameBuilder and Simulator checkBin,
  raise an exception if setBin is not valid
* using FrameBuilder getMaxImageSize
* added HwBinCtrlObj and the corresponding SimuBinCtrlObj


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@47 45c4679d-1946-429d-baad-37912b19538b
parent 93e0754a
......@@ -28,6 +28,7 @@ class FrameBuilder {
void getBin( Bin &bin ) const;
void setBin( const Bin &bin );
void checkBin( Bin &bin ) const;
void getRoi( Roi &roi ) const;
void setRoi( const Roi &roi );
......
......@@ -110,6 +110,26 @@ class SimuSyncCtrlObj : public HwSyncCtrlObj
};
/*******************************************************************
* \class SimuBinCtrlObj
* \brief Control object providing simulator binning interface
*******************************************************************/
class SimuBinCtrlObj : public HwBinCtrlObj
{
public:
SimuBinCtrlObj(Simulator& simu);
virtual ~SimuBinCtrlObj();
virtual void setBin(const Bin& bin);
virtual void getBin(Bin& bin);
virtual void checkBin(Bin& bin);
private:
Simulator& m_simu;
};
/*******************************************************************
* \class SimuHwInterface
* \brief Simulator hardware interface
......@@ -136,6 +156,7 @@ class SimuHwInterface : public HwInterface
SimuDetInfoCtrlObj m_det_info;
SimuBufferCtrlObj m_buffer;
SimuSyncCtrlObj m_sync;
SimuBinCtrlObj m_bin;
};
}
......
......@@ -36,6 +36,7 @@ class Simulator
void setBin(const Bin& bin);
void getBin(Bin& bin);
void checkBin(Bin& bin);
void setFrameDim(const FrameDim& frame_dim);
void getFrameDim(FrameDim& frame_dim);
......
......@@ -50,10 +50,14 @@ void FrameBuilder::checkValid( const FrameDim &frame_dim, const Bin &bin,
Size max_size;
getMaxImageSize( max_size );
Bin valid_bin = bin;
checkBin(valid_bin);
if (valid_bin != bin)
throw LIMA_HW_EXC(InvalidValue, "Invalid bin");
if( (frame_dim.getSize().getWidth() > max_size.getWidth()) ||
(frame_dim.getSize().getHeight() > max_size.getHeight()) )
throw Exception( Hardware, InvalidValue, "Frame size too big",
__FILE__, __FUNCTION__, __LINE__ );
throw LIMA_HW_EXC(InvalidValue, "Frame size too big");
FrameDim bin_dim = frame_dim / bin;
......@@ -109,6 +113,14 @@ void FrameBuilder::setBin( const Bin &bin )
}
void FrameBuilder::checkBin( Bin &bin ) const
{
if ((bin == Bin(1,1)) || (bin == Bin(1,2)) || (bin == Bin(2,1)))
bin = Bin(1,1);
else
bin = Bin(2,2);
}
void FrameBuilder::getRoi( Roi &roi ) const
{
roi = m_roi;
......
......@@ -224,12 +224,42 @@ void SimuSyncCtrlObj::getValidRanges(ValidRangesType& valid_ranges)
}
/*******************************************************************
* \brief SimuBinCtrlObj constructor
*******************************************************************/
SimuBinCtrlObj::SimuBinCtrlObj(Simulator& simu)
: m_simu(simu)
{
}
SimuBinCtrlObj::~SimuBinCtrlObj()
{
}
void SimuBinCtrlObj::setBin(const Bin& bin)
{
m_simu.setBin(bin);
}
void SimuBinCtrlObj::getBin(Bin& bin)
{
m_simu.getBin(bin);
}
void SimuBinCtrlObj::checkBin(Bin& bin)
{
m_simu.checkBin(bin);
}
/*******************************************************************
* \brief SimuHwInterface constructor
*******************************************************************/
SimuHwInterface::SimuHwInterface(Simulator& simu)
: m_simu(simu), m_det_info(simu), m_buffer(simu), m_sync(simu)
: m_simu(simu), m_det_info(simu), m_buffer(simu), m_sync(simu),
m_bin(simu)
{
HwDetInfoCtrlObj *det_info = &m_det_info;
m_cap_list.push_back(HwCap(det_info));
......@@ -239,6 +269,9 @@ SimuHwInterface::SimuHwInterface(Simulator& simu)
HwSyncCtrlObj *sync = &m_sync;
m_cap_list.push_back(HwCap(sync));
HwBinCtrlObj *bin = &m_bin;
m_cap_list.push_back(HwCap(bin));
}
SimuHwInterface::~SimuHwInterface()
......
......@@ -113,8 +113,7 @@ BufferCtrlMgr& Simulator::getBufferMgr()
void Simulator::getMaxImageSize(Size& max_image_size)
{
int max_dim = 8 * 1024;
max_image_size = Size(max_dim, max_dim);
m_frame_builder.getMaxImageSize(max_image_size);
}
void Simulator::setNbFrames(int nb_frames)
......@@ -166,6 +165,11 @@ void Simulator::getBin(Bin& bin)
m_frame_builder.getBin(bin);
}
void Simulator::checkBin(Bin& bin)
{
m_frame_builder.checkBin(bin);
}
void Simulator::setFrameDim(const FrameDim& frame_dim)
{
m_frame_builder.setFrameDim(frame_dim);
......
......@@ -51,7 +51,7 @@ int main( void )
return 0;
} catch (Exception &e) {
cout << "Exception: " << e.getErrDesc() << endl;
cerr << e << endl;
return -1;
}
}
......@@ -38,7 +38,7 @@ void print_status(SimuHwInterface& simu_hw)
cout << "status=" << status << endl;
}
int main(int argc, char *argv[])
void test_simu_hw_interface()
{
Simulator simu;
SimuHwInterface simu_hw(simu);
......@@ -54,8 +54,8 @@ int main(int argc, char *argv[])
HwSyncCtrlObj *hw_sync;
simu_hw.getHwCtrlObj(hw_sync);
// HwBinCtrlObj *hw_bin;
// simu_hw.getCtrlObj(hw_bin);
HwBinCtrlObj *hw_bin;
simu_hw.getHwCtrlObj(hw_bin);
Size size;
hw_det_info->getMaxImageSize(size);
......@@ -63,9 +63,8 @@ int main(int argc, char *argv[])
hw_det_info->getCurrImageType(image_type);
FrameDim frame_dim(size, image_type);
Bin bin;
// if (hw_bin)
// hw_bin->getBin(bin);
Bin bin(1);
hw_bin->setBin(bin);
FrameDim effect_frame_dim = frame_dim / bin;
hw_buffer->setFrameDim(effect_frame_dim);
......@@ -95,5 +94,38 @@ int main(int argc, char *argv[])
simu_hw.stopAcq();
print_status(simu_hw);
bool raised_exception = false;
try {
bin = Bin(2, 1);
hw_bin->setBin(bin);
} catch (Exception) {
raised_exception = true;
}
if (raised_exception)
cout << "Exception was raised OK!" << endl;
else
throw LIMA_HW_EXC(Error, "Did not raise bad bin exception");
bin = Bin(2, 2);
hw_bin->setBin(bin);
effect_frame_dim = frame_dim / bin;
hw_buffer->setFrameDim(effect_frame_dim);
hw_buffer->setNbBuffers(10);
print_status(simu_hw);
simu_hw.startAcq();
print_status(simu_hw);
simu_hw.stopAcq();
print_status(simu_hw);
}
int main(int argc, char *argv[])
{
try {
test_simu_hw_interface();
} catch (Exception e) {
cerr << "LIMA Exception:" << e << endl;
}
return 0;
}
......@@ -2,6 +2,7 @@
#define EXCEPTIONS_H
#include <string>
#include <ostream>
namespace lima
{
......@@ -24,7 +25,7 @@ class Exception
String file_name, String funct_name, int line_nr);
String &getErrDesc();
String getErrMsg() const;
private:
Layer m_layer;
......@@ -35,6 +36,10 @@ class Exception
int m_line_nr;
};
std::ostream& operator <<(std::ostream& os, Layer layer);
std::ostream& operator <<(std::ostream& os, ErrorType err_type);
std::ostream& operator <<(std::ostream& os, const Exception& e);
#define LIMA_EXC(layer, err_type, err_desc) \
Exception(layer, err_type, err_desc, __FILE__, __FUNCTION__, __LINE__)
......
......@@ -141,6 +141,9 @@ class Size
Size& operator /=(const Point& p)
{ m_xy = checkValid(m_xy / p); return *this; }
void alignTo(const Point& p, AlignDir align_dir)
{ m_xy.alignTo(p, align_dir); }
private:
static bool isValidCoord(int i);
static Point checkValid(const Point& p);
......@@ -273,6 +276,9 @@ class Roi
bool isActive() const;
void alignSizeTo(const Point& p, AlignDir align_dir);
void alignCornersTo(const Point& p, AlignDir align_dir);
private:
static bool isValidCoord(int i);
static Point checkCorner(const Point& TopLeft);
......@@ -373,6 +379,21 @@ inline bool Roi::isActive() const
return !m_size.isEmpty();
}
inline void Roi::alignSizeTo(const Point& p, AlignDir align_dir)
{
m_size.alignTo(p, align_dir);
}
inline void Roi::alignCornersTo(const Point& p, AlignDir align_dir)
{
Point br = getBottomRight() + 1;
AlignDir tl_align_dir = (align_dir == Floor) ? Ceil : Floor;
m_top_left.alignTo(p, tl_align_dir);
br.alignTo(p, align_dir);
m_size = br - m_top_left;
}
inline bool operator ==(const Roi& r1, const Roi& r2)
{
......
#include <string>
#include "Exceptions.h"
#include <sstream>
using namespace lima;
using namespace std;
......@@ -12,7 +13,40 @@ Exception::Exception(Layer layer, ErrorType err_type, String err_desc,
}
string & Exception::getErrDesc()
Exception::String Exception::getErrMsg() const
{
ostringstream os;
os << m_layer << ": "
<< m_funct_name << "(" << m_file_name << ", "
<< m_line_nr << "): "
<< m_err_type << ": " << m_err_desc;
return os.str();
}
std::ostream& lima::operator <<(std::ostream& os, Layer layer)
{
return m_err_desc;
string name = "Unknown";
switch (layer) {
case Common: name = "Common"; break;
case Control: name = "Control"; break;
case Hardware: name = "Hardware"; break;
}
return os << name;
}
std::ostream& lima::operator <<(std::ostream& os, ErrorType err_type)
{
string name = "Unknown";
switch (err_type) {
case InvalidValue: name = "InvalidValue"; break;
case NotSupported: name = "NotSupported"; break;
case Error: name = "Error"; break;
}
return os << name;
}
std::ostream& lima::operator <<(std::ostream& os, const Exception& e)
{
return os << e.getErrMsg();
}
#ifndef HWBINCTRLOBJ_H
#define HWBINCTRLOBJ_H
#include "SizeUtils.h"
namespace lima
{
class HwBinCtrlObj
{
public:
virtual ~HwBinCtrlObj();
virtual void setBin(const Bin& bin) = 0;
virtual void getBin(Bin& bin) = 0;
virtual void checkBin(Bin& bin) = 0;
};
} // namespace lima
#endif // HWBINCTRLOBJ_H
......@@ -46,6 +46,6 @@ public:
#include "HwDetInfoCtrlObj.h"
#include "HwBufferCtrlObj.h"
#include "HwSyncCtrlObj.h"
#include "HwBinCtrlObj.h"
#endif // HWCAP_H
#include "HwBinCtrlObj.h"
using namespace lima;
HwBinCtrlObj::~HwBinCtrlObj()
{
}
......@@ -22,4 +22,10 @@ HwCap::Type HwCap::getTypeFromCtrlObj<>(HwSyncCtrlObj *p)
return Sync;
}
template <>
HwCap::Type HwCap::getTypeFromCtrlObj<>(HwBinCtrlObj *p)
{
return Bin;
}
} // namespace lima
hw-objs := HwInterface.o HwCap.o HwSyncCtrlObj.o HwFrameInfo.o \
HwFrameCallback.o HwBufferCtrlObj.o HwBufferMgr.o \
HwShutterCtrlObj.o HwDetInfoCtrlObj.o
HwShutterCtrlObj.o HwDetInfoCtrlObj.o HwBinCtrlObj.o
CXXFLAGS += -I../include -I../../common/include -Wall -pthread
......
Markdown is supported
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