Commit 0cc74df2 authored by ahoms's avatar ahoms
Browse files

* added static set/getXXXXFlagsNameList and enable/DisableXXXXFlags

* using DebTypeXXXX (instead of DebXXXX) for symmetry with other enums
* added static const Flags DebParams::AllFlags
* changed DebType/Fmt/Mod enums to flags; removed DebFlag global helper
* added destructors in Frelon classes
* fixed bug in Frelon::Camera::getEspiaDev creating temp. Espia::SerialLine
* fixed warnings/errors in OCopyStream constructors



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@180 45c4679d-1946-429d-baad-37912b19538b
parent 38a745c4
......@@ -99,7 +99,7 @@ int Acq::dispatchFrameCallback(struct espia_cb_data *cb_data)
DEB_PARAM_VAR1(cb_data->cb_nr);
Acq *espia = (Acq *) cb_data->data;
DEB_TRACE_VAR1(espia->getDebObjName());
DEB_TRACE_VAR1(DEB_OBJ_NAME(espia));
void (Acq::*method)(struct espia_cb_data *cb_data) = NULL;
......
......@@ -11,8 +11,11 @@ namespace Frelon
class Camera
{
DEB_CLASS_NAMESPC(DebModFrelon, "Camera", "Frelon");
public:
Camera(Espia::SerialLine& espia_ser_line);
~Camera();
SerialLine& getSerialLine();
......
......@@ -15,6 +15,7 @@ class Camera
public:
Camera(Espia::SerialLine& espia_ser_line);
~Camera();
Frelon::SerialLine& getSerialLine();
......
......@@ -14,10 +14,18 @@ const double Camera::MaxReadoutTime = 0.7;
Camera::Camera(Espia::SerialLine& espia_ser_line)
: m_ser_line(espia_ser_line)
{
DEB_CONSTRUCTOR();
m_trig_mode = IntTrig;
readRegister(NbFrames, m_nb_frames);
}
Camera::~Camera()
{
DEB_DESTRUCTOR();
}
SerialLine& Camera::getSerialLine()
{
return m_ser_line;
......@@ -25,38 +33,64 @@ SerialLine& Camera::getSerialLine()
Espia::Dev& Camera::getEspiaDev()
{
Espia::SerialLine ser_line = m_ser_line.getEspiaSerialLine();
Espia::SerialLine& ser_line = m_ser_line.getEspiaSerialLine();
Espia::Dev& dev = ser_line.getDev();
return dev;
}
void Camera::sendCmd(Cmd cmd)
{
DEB_MEMBER_FUNCT();
const string& cmd_str = CmdStrMap[cmd];
DEB_PARAM_VAR2(int(cmd), cmd_str);
if (cmd_str.empty()) {
DEB_ERROR() << "Invalid command cmd=" << cmd;
throw LIMA_HW_EXC(InvalidValue, "Invalid command");
}
string resp;
m_ser_line.sendFmtCmd(CmdStrMap[cmd], resp);
m_ser_line.sendFmtCmd(cmd_str, resp);
}
void Camera::writeRegister(Reg reg, int val)
{
DEB_MEMBER_FUNCT();
const string& reg_str = RegStrMap[reg];
DEB_PARAM_VAR3(int(reg), reg_str, val);
if (reg_str.empty()) {
DEB_ERROR() << "Invalid register reg=" << reg;
throw LIMA_HW_EXC(InvalidValue, "Invalid register");
}
ostringstream cmd;
cmd << RegStrMap[reg] << val;
cmd << reg_str << val;
string resp;
m_ser_line.sendFmtCmd(cmd.str(), resp);
}
void Camera::readRegister(Reg reg, int& val)
{
string resp, cmd = RegStrMap[reg] + "?";
m_ser_line.sendFmtCmd(cmd, resp);
DEB_MEMBER_FUNCT();
const string& reg_str = RegStrMap[reg];
DEB_PARAM_VAR2(int(reg), reg_str);
if (reg_str.empty()) {
DEB_ERROR() << "Invalid register reg=" << reg;
throw LIMA_HW_EXC(InvalidValue, "Invalid register");
}
string resp;
m_ser_line.sendFmtCmd(reg_str + "?", resp);
istringstream is(resp);
is >> val;
}
void Camera::hardReset()
{
DEB_MEMBER_FUNCT();
Espia::Dev& dev = getEspiaDev();
dev.resetLink();
DEB_TRACE() << "Reseting the camera";
sendCmd(Reset);
}
......
......@@ -197,8 +197,31 @@ void set_hw_roi(HwRoiCtrlObj *hw_roi, const Roi& set_roi, Roi& real_roi,
<< "soft_roi=" << soft_roi << endl;
}
void print_deb_flags()
{
DebParams::Flags deb_flags;
cout << hex << showbase;
deb_flags = DebParams::getTypeFlags();
cout << "TypeFlags=" << deb_flags << endl;
deb_flags = DebParams::getFormatFlags();
cout << "FormatFlags=" << deb_flags << endl;
deb_flags = DebParams::getModuleFlags();
cout << "ModuleFlags=" << deb_flags << endl;
cout << dec << noshowbase;
DebParams::NameList name_list;
name_list = DebParams::getTypeFlagsNameList();
cout << "TypeFlagsNameList=" << name_list << endl;
name_list = DebParams::getFormatFlagsNameList();
cout << "FormatFlagsNameList=" << name_list << endl;
name_list = DebParams::getModuleFlagsNameList();
cout << "ModuleFlagsNameList=" << name_list << endl;
}
void test_frelon_hw_inter(bool do_reset)
{
print_deb_flags();
Espia::Dev dev(0);
Espia::Acq acq(dev);
Espia::BufferMgr buffer_cb_mgr(acq);
......@@ -206,6 +229,9 @@ void test_frelon_hw_inter(bool do_reset)
Frelon::Camera cam(ser_line);
BufferCtrlMgr buffer_mgr(buffer_cb_mgr);
DebParams::disableModuleFlags(DebModEspiaSerial);
print_deb_flags();
cout << "Creating the Hw Interface ... " << endl;
Frelon::Interface hw_inter(acq, buffer_mgr, cam);
cout << " Done!" << endl;
......@@ -328,6 +354,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_inter.stopAcq();
print_status(hw_inter);
DebParams::disableTypeFlags(DebTypeFunct);
print_deb_flags();
set_roi = Roi(Point(267, 267), Size(501, 501));
set_hw_roi(hw_roi, set_roi, real_roi, soft_roi);
effect_frame_dim.setSize(real_roi.getSize());
......@@ -349,6 +378,9 @@ void test_frelon_hw_inter(bool do_reset)
hw_sync->setNbFrames(3);
DebParams::disableModuleFlags(DebModEspia);
print_deb_flags();
print_status(hw_inter);
acq_finished.resetFinished();
hw_inter.startAcq();
......@@ -357,6 +389,11 @@ void test_frelon_hw_inter(bool do_reset)
print_status(hw_inter);
hw_inter.stopAcq();
print_status(hw_inter);
DebParams::enableTypeFlags (DebParams::AllFlags);
DebParams::enableFormatFlags(DebParams::AllFlags);
DebParams::enableModuleFlags(DebParams::AllFlags);
print_deb_flags();
}
int main(int argc, char *argv[])
......
......@@ -17,19 +17,37 @@ namespace lima
// DebParams::checkInit (Debug.cpp) when you change these enums
enum DebType {
DebFatal, DebError, DebWarning, DebTrace,
DebFunct, DebParam, DebReturn, DebAlways,
DebTypeFatal = 1 << 0,
DebTypeError = 1 << 1,
DebTypeWarning = 1 << 2,
DebTypeTrace = 1 << 3,
DebTypeFunct = 1 << 4,
DebTypeParam = 1 << 5,
DebTypeReturn = 1 << 6,
DebTypeAlways = 1 << 7,
};
enum DebFormat {
DebFmtDateTime, DebFmtModule, DebFmtObj, DebFmtFunct,
DebFmtFileLine, DebFmtType,
DebFmtDateTime = 1 << 0,
DebFmtModule = 1 << 1,
DebFmtObj = 1 << 2,
DebFmtFunct = 1 << 3,
DebFmtFileLine = 1 << 4,
DebFmtType = 1 << 5,
};
enum DebModule {
DebModNone, DebModCommon, DebModHardware, DebModControl,
DebModSimu, DebModEspia, DebModEspiaSerial, DebModFocla,
DebModFrelon, DebModFrelonSerial, DebModMaxipix,
DebModNone = 1 << 0,
DebModCommon = 1 << 1,
DebModHardware = 1 << 2,
DebModControl = 1 << 3,
DebModSimu = 1 << 4,
DebModEspia = 1 << 5,
DebModEspiaSerial = 1 << 6,
DebModFocla = 1 << 7,
DebModFrelon = 1 << 8,
DebModFrelonSerial = 1 << 9,
DebModMaxipix = 1 << 10,
};
typedef const char *ConstStr;
......@@ -92,6 +110,9 @@ class DebParams
{
public:
typedef long long Flags;
typedef std::vector<std::string> NameList;
static const Flags AllFlags;
DebParams(DebModule mod = DebModNone,
ConstStr class_name = NULL, ConstStr name_space = NULL);
......@@ -108,14 +129,32 @@ class DebParams
bool checkModule() const;
bool checkType(DebType type) const;
static void setModuleFlags(Flags mod_flags);
static Flags getModuleFlags();
static void setTypeFlags(Flags type_flags);
static Flags getTypeFlags();
static void enableTypeFlags(Flags type_flags);
static void disableTypeFlags(Flags type_flags);
static void setFormatFlags(Flags fmt_flags);
static Flags getFormatFlags();
static void setTypeFlags(Flags type_flags);
static Flags getTypeFlags();
static void enableFormatFlags(Flags fmt_flags);
static void disableFormatFlags(Flags fmt_flags);
static void setModuleFlags(Flags mod_flags);
static Flags getModuleFlags();
static void enableModuleFlags(Flags mod_flags);
static void disableModuleFlags(Flags mod_flags);
static void setTypeFlagsNameList(const NameList& type_name_list);
static NameList getTypeFlagsNameList();
static void setFormatFlagsNameList(const NameList& fmt_name_list);
static NameList getFormatFlagsNameList();
static void setModuleFlagsNameList(const NameList& mod_name_list);
static NameList getModuleFlagsNameList();
static DebStream& getDebStream();
static AutoMutex lock();
......@@ -130,6 +169,15 @@ private:
static void checkInit();
template <class T>
static void setFlagsNameList(Flags& flags,
const std::map<T, std::string>& name_map,
const NameList& name_list);
template <class T>
static void getFlagsNameList(Flags flags,
const std::map<T, std::string>& name_map,
NameList& name_list);
static Flags s_type_flags;
static Flags s_fmt_flags;
static Flags s_mod_flags;
......@@ -147,6 +195,9 @@ private:
ConstStr m_name_space;
};
std::ostream& operator <<(std::ostream& os,
const DebParams::NameList& name_list);
/*------------------------------------------------------------------
* class DebProxy
......@@ -210,14 +261,9 @@ class DebObj
* global inline functions
*------------------------------------------------------------------*/
inline DebParams::Flags DebFlag(int val)
{
return (1LL << val);
}
inline bool DebHasFlag(DebParams::Flags flags, int val)
{
return ((flags & DebFlag(val)) != 0);
return ((flags & val) != 0);
}
/*------------------------------------------------------------------
......@@ -327,25 +373,26 @@ inline DebObj::DebObj(DebParams& deb_params, bool destructor,
m_funct_name(funct_name), m_obj_name(obj_name),
m_file_name(file_name), m_line_nr(line_nr)
{
write(DebFunct, m_file_name, m_line_nr) << "Enter";
write(DebTypeFunct, m_file_name, m_line_nr) << "Enter";
}
inline DebObj::~DebObj()
{
write(DebFunct, m_file_name, m_line_nr) << "Exit";
write(DebTypeFunct, m_file_name, m_line_nr) << "Exit";
}
inline bool DebObj::checkOut(DebType type)
{
return ((type == DebAlways) || (type == DebFatal) ||
((type == DebError) && m_deb_params->checkType(DebError)) ||
return ((type == DebTypeAlways) || (type == DebTypeFatal) ||
((type == DebTypeError) &&
m_deb_params->checkType(DebTypeError)) ||
(m_deb_params->checkModule() &&
m_deb_params->checkType(type)));
}
inline bool DebObj::checkErr(DebType type)
{
return ((type == DebFatal) || (type == DebError));
return ((type == DebTypeFatal) || (type == DebTypeError));
}
inline bool DebObj::checkAny(DebType type)
......@@ -434,52 +481,55 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
#define DEB_MSG_VAR6(type, v1, v2, v3, v4, v5, v6) \
DEB_MSG_VAR5(type, v1, v2, v3, v4, v5) << ", " #v6 "=" << v6
#define DEB_FATAL() DEB_MSG(DebFatal)
#define DEB_ERROR() DEB_MSG(DebError)
#define DEB_WARNING() DEB_MSG(DebWarning)
#define DEB_TRACE() DEB_MSG(DebTrace)
#define DEB_PARAM() DEB_MSG(DebParam)
#define DEB_RETURN() DEB_MSG(DebReturn)
#define DEB_ALWAYS() DEB_MSG(DebAlways)
#define DEB_FATAL() DEB_MSG(DebTypeFatal)
#define DEB_ERROR() DEB_MSG(DebTypeError)
#define DEB_WARNING() DEB_MSG(DebTypeWarning)
#define DEB_TRACE() DEB_MSG(DebTypeTrace)
#define DEB_PARAM() DEB_MSG(DebTypeParam)
#define DEB_RETURN() DEB_MSG(DebTypeReturn)
#define DEB_ALWAYS() DEB_MSG(DebTypeAlways)
#define DEB_PARAM_VAR1(v1) \
DEB_MSG_VAR1(DebParam, v1)
DEB_MSG_VAR1(DebTypeParam, v1)
#define DEB_PARAM_VAR2(v1, v2) \
DEB_MSG_VAR2(DebParam, v1, v2)
DEB_MSG_VAR2(DebTypeParam, v1, v2)
#define DEB_PARAM_VAR3(v1, v2, v3) \
DEB_MSG_VAR3(DebParam, v1, v2, v3)
DEB_MSG_VAR3(DebTypeParam, v1, v2, v3)
#define DEB_PARAM_VAR4(v1, v2, v3, v4) \
DEB_MSG_VAR4(DebParam, v1, v2, v3, v4)
DEB_MSG_VAR4(DebTypeParam, v1, v2, v3, v4)
#define DEB_PARAM_VAR5(v1, v2, v3, v4, v5) \
DEB_MSG_VAR5(DebParam, v1, v2, v3, v4, v5)
DEB_MSG_VAR5(DebTypeParam, v1, v2, v3, v4, v5)
#define DEB_PARAM_VAR6(v1, v2, v3, v4, v5, v6) \
DEB_MSG_VAR6(DebParam, v1, v2, v3, v4, v5, v6)
DEB_MSG_VAR6(DebTypeParam, v1, v2, v3, v4, v5, v6)
#define DEB_TRACE_VAR1(v1) \
DEB_MSG_VAR1(DebTrace, v1)
DEB_MSG_VAR1(DebTypeTrace, v1)
#define DEB_TRACE_VAR2(v1, v2) \
DEB_MSG_VAR2(DebTrace, v1, v2)
DEB_MSG_VAR2(DebTypeTrace, v1, v2)
#define DEB_TRACE_VAR3(v1, v2, v3) \
DEB_MSG_VAR3(DebTrace, v1, v2, v3)
DEB_MSG_VAR3(DebTypeTrace, v1, v2, v3)
#define DEB_TRACE_VAR4(v1, v2, v3, v4) \
DEB_MSG_VAR4(DebTrace, v1, v2, v3, v4)
DEB_MSG_VAR4(DebTypeTrace, v1, v2, v3, v4)
#define DEB_TRACE_VAR5(v1, v2, v3, v4, v5) \
DEB_MSG_VAR5(DebTrace, v1, v2, v3, v4, v5)
DEB_MSG_VAR5(DebTypeTrace, v1, v2, v3, v4, v5)
#define DEB_TRACE_VAR6(v1, v2, v3, v4, v5, v6) \
DEB_MSG_VAR6(DebTrace, v1, v2, v3, v4, v5, v6)
DEB_MSG_VAR6(DebTypeTrace, v1, v2, v3, v4, v5, v6)
#define DEB_RETURN_VAR1(v1) \
DEB_MSG_VAR1(DebReturn, v1)
DEB_MSG_VAR1(DebTypeReturn, v1)
#define DEB_RETURN_VAR2(v1, v2) \
DEB_MSG_VAR2(DebReturn, v1, v2)
DEB_MSG_VAR2(DebTypeReturn, v1, v2)
#define DEB_RETURN_VAR3(v1, v2, v3) \
DEB_MSG_VAR3(DebReturn, v1, v2, v3)
DEB_MSG_VAR3(DebTypeReturn, v1, v2, v3)
#define DEB_RETURN_VAR4(v1, v2, v3, v4) \
DEB_MSG_VAR4(DebReturn, v1, v2, v3, v4)
DEB_MSG_VAR4(DebTypeReturn, v1, v2, v3, v4)
#define DEB_RETURN_VAR5(v1, v2, v3, v4, v5) \
DEB_MSG_VAR5(DebReturn, v1, v2, v3, v4, v5)
DEB_MSG_VAR5(DebTypeReturn, v1, v2, v3, v4, v5)
#define DEB_RETURN_VAR6(v1, v2, v3, v4, v5, v6) \
DEB_MSG_VAR6(DebReturn, v1, v2, v3, v4, v5, v6)
DEB_MSG_VAR6(DebTypeReturn, v1, v2, v3, v4, v5, v6)
#define DEB_OBJ_NAME(o) \
((o)->getDebObjName())
} // namespace lima
......
......@@ -66,11 +66,17 @@ class OCopyStream : public std::ostream
typedef CopyStreamBuf::StreamList StreamList;
OCopyStream(StreamList *slist, std::ostream *altstream = NULL)
: std::ostream(&sb), sb(slist, altstream) {}
: std::ostream(NULL), sb(slist, altstream)
{
init(&sb);
}
OCopyStream::OCopyStream(const OCopyStream& other)
: std::ostream(&sb),
sb(other.sb.getStreamList(), other.sb.getAltStream()) {}
OCopyStream(const OCopyStream& other)
: std::ios(), std::ostream(NULL),
sb(other.sb.getStreamList(), other.sb.getAltStream())
{
init(&sb);
}
private:
CopyStreamBuf sb;
......
......@@ -4,19 +4,37 @@ using namespace lima;
%End
enum DebType {
DebFatal, DebError, DebWarning, DebTrace,
DebFunct, DebParam, DebReturn, DebAlways,
DebTypeFatal, // = 1 << 0,
DebTypeError, // = 1 << 1,
DebTypeWarning, // = 1 << 2,
DebTypeTrace, // = 1 << 3,
DebTypeFunct, // = 1 << 4,
DebTypeParam, // = 1 << 5,
DebTypeReturn, // = 1 << 6,
DebTypeAlways, // = 1 << 7,
};
enum DebFormat {
DebFmtDateTime, DebFmtModule, DebFmtObj, DebFmtFunct,
DebFmtFileLine, DebFmtType,
DebFmtDateTime, // = 1 << 0,
DebFmtModule, // = 1 << 1,
DebFmtObj, // = 1 << 2,
DebFmtFunct, // = 1 << 3,
DebFmtFileLine, // = 1 << 4,
DebFmtType, // = 1 << 5,
};
enum DebModule {
DebModNone, DebModCommon, DebModHardware, DebModControl,
DebModSimu, DebModEspia, DebModEspiaSerial, DebModFocla,
DebModFrelon, DebModFrelonSerial, DebModMaxipix,
DebModNone, // = 1 << 0,
DebModCommon, // = 1 << 1,
DebModHardware, // = 1 << 2,
DebModControl, // = 1 << 3,
DebModSimu, // = 1 << 4,
DebModEspia, // = 1 << 5,
DebModEspiaSerial, // = 1 << 6,
DebModFocla, // = 1 << 7,
DebModFrelon, // = 1 << 8,
DebModFrelonSerial, // = 1 << 9,
DebModMaxipix, // = 1 << 10,
};
typedef const char *ConstStr;
......@@ -36,6 +54,8 @@ using namespace lima;
typedef long long Flags;
typedef std::vector<std::string> NameList;
static const Flags AllFlags;
DebParams(DebModule mod = DebModNone,
ConstStr class_name = NULL, ConstStr name_space = NULL);
......@@ -51,23 +71,41 @@ using namespace lima;
bool checkModule() const;
bool checkType(DebType type) const;
static void setModuleFlags(Flags mod_flags);
static Flags getModuleFlags();
static void setTypeFlags(Flags type_flags);
static Flags getTypeFlags();
static void enableTypeFlags(Flags type_flags);
static void disableTypeFlags(Flags type_flags);
static void setFormatFlags(Flags fmt_flags);
static Flags getFormatFlags();
static void setTypeFlags(Flags type_flags);
static Flags getTypeFlags();
static void enableFormatFlags(Flags fmt_flags);
static void disableFormatFlags(Flags fmt_flags);
static void setModuleFlags(Flags mod_flags);
static Flags getModuleFlags();
static void enableModuleFlags(Flags mod_flags);
static void disableModuleFlags(Flags mod_flags);
static void setTypeFlagsNameList(const NameList& type_name_list);
static NameList getTypeFlagsNameList();
static void setFormatFlagsNameList(const NameList& fmt_name_list);
static NameList getFormatFlagsNameList();
static void setModuleFlagsNameList(const NameList& mod_name_list);
static NameList getModuleFlagsNameList();
static ConstStr getTypeName(DebType type);
static ConstStr getFormatName(DebFormat fmt);
static ConstStr getModuleName(DebModule mod);
};
/*------------------------------------------------------------------
* global inline functions
*------------------------------------------------------------------*/
DebParams::Flags DebFlag(int val);
bool DebHasFlag(DebParams::Flags flags, int val);
......@@ -88,6 +88,8 @@ void DebStream::RemoveError(ostream *os)
* DebParams functions
*------------------------------------------------------------------*/
const DebParams::Flags DebParams::AllFlags = 0xffffffff;
DebParams::Flags DebParams::s_type_flags;
DebParams::Flags DebParams::s_fmt_flags;
DebParams::Flags DebParams::s_mod_flags;
......@@ -112,6 +114,18 @@ DebParams::Flags DebParams::getTypeFlags()
return s_type_flags;
}
void DebParams::enableTypeFlags(Flags type_flags)
{
checkInit();
s_type_flags |= type_flags;
}
void DebParams::disableTypeFlags(Flags type_flags)
{
checkInit();
s_type_flags &= ~type_flags;
}
void DebParams::setFormatFlags(Flags fmt_flags)
{
checkInit();
......@@ -124,6 +138,18 @@ DebParams::Flags DebParams::getFormatFlags()
return s_fmt_flags;
}
void DebParams::enableFormatFlags(Flags fmt_flags)
{
checkInit();
s_fmt_flags |= fmt_flags;
}
void DebParams::disableFormatFlags(Flags fmt_flags)
{
checkInit();
s_fmt_flags &= ~fmt_flags;
}
void DebParams::setModuleFlags(Flags mod_flags)
{
checkInit();
......@@ -136,6 +162,94 @@ DebParams::Flags DebParams::getModuleFlags()
return s_mod_flags;
}
void DebParams::enableModuleFlags(Flags mod_flags)
{
checkInit();
s_mod_flags |= mod_flags;
}
void DebParams::disableModuleFlags(Flags mod_flags)
{
checkInit();
s_mod_flags &= ~mod_flags;
}