Commit e818688d authored by ahoms's avatar ahoms
Browse files

* moved Espia and Frelon classes to namespaces; renamed classes to

  Espia::Dev, Espia::Acq, Espia::SerialLine,
  Frelon::SerialLine and Frelon::Camera



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@73 45c4679d-1946-429d-baad-37912b19538b
parent 8e5d164f
......@@ -9,47 +9,43 @@
namespace lima
{
class Espia
namespace Espia
{
public:
enum {
Invalid = -1,
NoBlock = 0,
BlockForever = -1,
MetaDev = SCDXIPCI_META_DEV,
};
unsigned long sec2usec(double sec);
double usec2sec(unsigned long usec);
static void throwError(int ret, std::string file, std::string func,
int line);
enum {
Invalid = -1,
NoBlock = 0,
BlockForever = -1,
MetaDev = SCDXIPCI_META_DEV,
};
#define ESPIA_CHECK_CALL(ret) \
do { \
int aux_ret = (ret); \
if (aux_ret < 0) \
Espia::throwError(aux_ret, __FILE__, \
__FUNCTION__, __LINE__); \
} while (0)
inline unsigned long Espia::sec2usec(double sec)
inline unsigned long Sec2USec(double sec)
{
if (sec > 0)
sec *= 1e6;
return (unsigned long) sec;
}
inline double Espia::usec2sec(unsigned long usec)
inline double USec2Sec(unsigned long usec)
{
if (usec > 0)
return usec * 1e-6;
return usec;
}
void ThrowError(int ret, std::string file, std::string func, int line);
#define ESPIA_CHECK_CALL(espia_ret) \
do { \
int aux_ret = (espia_ret); \
if (aux_ret < 0) \
Espia::ThrowError(aux_ret, __FILE__, \
__FUNCTION__, __LINE__); \
} while (0)
} // namespace Espia
} // namespace lima
......
......@@ -7,11 +7,14 @@
namespace lima
{
class EspiaAcq : public Espia
namespace Espia
{
class Acq
{
public:
EspiaAcq(EspiaDev& dev);
~EspiaAcq();
Acq(Dev& dev);
~Acq();
typedef struct AcqStatus {
bool acq_started;
......@@ -60,7 +63,7 @@ class EspiaAcq : public Espia
AutoMutex acqLock();
EspiaDev& m_dev;
Dev& m_dev;
FrameDim m_frame_dim;
int m_nb_buffers;
......@@ -75,43 +78,44 @@ class EspiaAcq : public Espia
int m_last_frame_cb_nr;
};
inline bool EspiaAcq::hasVirtualBuffers()
inline bool Acq::hasVirtualBuffers()
{
return m_real_frame_factor != 1;
}
inline int EspiaAcq::realBufferNb(int virt_buffer, int virt_frame)
inline int Acq::realBufferNb(int virt_buffer, int virt_frame)
{
return virt_buffer / m_real_frame_factor;
}
inline int EspiaAcq::realFrameNb (int virt_buffer, int virt_frame)
inline int Acq::realFrameNb (int virt_buffer, int virt_frame)
{
return virt_buffer % m_real_frame_factor + virt_frame;
}
inline int EspiaAcq::virtBufferNb(int real_buffer, int real_frame)
inline int Acq::virtBufferNb(int real_buffer, int real_frame)
{
return (real_buffer * m_real_frame_factor +
real_frame / m_buffer_frames);
}
inline int EspiaAcq::virtFrameNb (int real_buffer, int real_frame)
inline int Acq::virtFrameNb (int real_buffer, int real_frame)
{
return real_frame % m_buffer_frames;
}
inline void EspiaAcq::getStartTimestamp(Timestamp& start_ts)
inline void Acq::getStartTimestamp(Timestamp& start_ts)
{
start_ts = m_start_ts;
}
inline AutoMutex EspiaAcq::acqLock()
inline AutoMutex Acq::acqLock()
{
return m_dev.acqLock();
}
} // namespace Espia
} // namespace lima
......
......@@ -9,11 +9,14 @@
namespace lima
{
class EspiaDev : public Espia
namespace Espia
{
class Dev
{
public:
EspiaDev(int dev_nb);
~EspiaDev();
Dev(int dev_nb);
~Dev();
operator espia_t();
......@@ -34,21 +37,24 @@ class EspiaDev : public Espia
Mutex m_acq_mutex;
};
inline EspiaDev::operator espia_t()
inline Dev::operator espia_t()
{
return m_dev;
}
inline bool EspiaDev::isMeta()
inline bool Dev::isMeta()
{
return (m_dev_nb == MetaDev);
}
inline AutoMutex EspiaDev::acqLock()
inline AutoMutex Dev::acqLock()
{
return AutoMutex(m_acq_mutex, AutoMutex::Locked);
}
} // namespace Espia
} // namespace lima
#endif // ESPIADEV_H
......@@ -7,17 +7,20 @@
#include "EspiaDev.h"
namespace lima {
namespace lima
{
namespace Espia
{
class EspiaSerialLine : public HwSerialLine, public Espia
class SerialLine : public HwSerialLine
{
public :
EspiaSerialLine( EspiaDev& edev, const std::string& line_term="\r",
double timeout=1.0, int block_size=0,
double block_delay=0 );
SerialLine( Dev& edev, const std::string& line_term="\r",
double timeout=1.0, int block_size=0,
double block_delay=0 );
~EspiaSerialLine();
~SerialLine();
virtual void write( const std::string& buffer, bool no_wait=false );
......@@ -33,10 +36,12 @@ class EspiaSerialLine : public HwSerialLine, public Espia
virtual void getNumAvailBytes( int &avail_bytes );
private :
EspiaDev& m_dev;
Dev& m_dev;
};
}
} // namespace Espia
} // namespace lima
#endif /* ESPIASERIALLINE_H */
#include "Espia.h"
using namespace lima;
using namespace lima::Espia;
using namespace std;
void Espia::throwError(int ret, string file, string func, int line)
void lima::Espia::ThrowError(int ret, string file, string func, int line)
{
string err_desc = string("Espia: ") + espia_strerror(ret);
throw Exception(Hardware, Error, err_desc, file, func, line);
......
#include "EspiaAcq.h"
#include "MemUtils.h"
using namespace lima;
using namespace lima::Espia;
#define CHECK_CALL(ret) ESPIA_CHECK_CALL(ret)
#define ESPIA_MIN_BUFFER_SIZE (128 * 1024)
EspiaAcq::EspiaAcq(EspiaDev& dev)
Acq::Acq(Dev& dev)
: m_dev(dev)
{
m_nb_buffers = m_buffer_frames = 0;
......@@ -23,21 +23,21 @@ EspiaAcq::EspiaAcq(EspiaDev& dev)
registerLastFrameCb();
}
EspiaAcq::~EspiaAcq()
Acq::~Acq()
{
bufferFree();
unregisterLastFrameCb();
}
int EspiaAcq::dispatchFrameCb(struct espia_cb_data *cb_data)
int Acq::dispatchFrameCb(struct espia_cb_data *cb_data)
{
EspiaAcq *espia = (EspiaAcq *) cb_data->data;
Acq *espia = (Acq *) cb_data->data;
void (EspiaAcq::*method)(struct espia_cb_data *cb_data) = NULL;
void (Acq::*method)(struct espia_cb_data *cb_data) = NULL;
int& cb_nr = cb_data->cb_nr;
if (cb_nr == espia->m_last_frame_cb_nr)
method = &EspiaAcq::lastFrameCb;
method = &Acq::lastFrameCb;
if (method) {
try {
......@@ -50,7 +50,7 @@ int EspiaAcq::dispatchFrameCb(struct espia_cb_data *cb_data)
return ESPIA_OK;
}
void EspiaAcq::registerLastFrameCb()
void Acq::registerLastFrameCb()
{
if (m_last_frame_cb_nr != Invalid)
return;
......@@ -70,7 +70,7 @@ void EspiaAcq::registerLastFrameCb()
m_dev.registerCallback(cb_data, m_last_frame_cb_nr);
}
void EspiaAcq::unregisterLastFrameCb()
void Acq::unregisterLastFrameCb()
{
if (m_last_frame_cb_nr == Invalid)
return;
......@@ -78,7 +78,7 @@ void EspiaAcq::unregisterLastFrameCb()
m_dev.unregisterCallback(m_last_frame_cb_nr);
}
void EspiaAcq::lastFrameCb(struct espia_cb_data *cb_data)
void Acq::lastFrameCb(struct espia_cb_data *cb_data)
{
AutoMutex l = acqLock();
......@@ -87,8 +87,8 @@ void EspiaAcq::lastFrameCb(struct espia_cb_data *cb_data)
m_last_frame_info = cb_finfo;
}
void EspiaAcq::bufferAlloc(const FrameDim& frame_dim, int& nb_buffers,
int buffer_frames)
void Acq::bufferAlloc(const FrameDim& frame_dim, int& nb_buffers,
int buffer_frames)
{
if (!frame_dim.isValid() || (nb_buffers <= 0) || (buffer_frames <= 0))
throw LIMA_HW_EXC(InvalidValue, "Invalid frame_dim, "
......@@ -133,7 +133,7 @@ void EspiaAcq::bufferAlloc(const FrameDim& frame_dim, int& nb_buffers,
m_real_frame_size = real_frame_size;
}
void EspiaAcq::bufferFree()
void Acq::bufferFree()
{
if ((m_nb_buffers == 0) || (m_buffer_frames == 0))
return;
......@@ -147,22 +147,22 @@ void EspiaAcq::bufferFree()
m_real_frame_factor = m_real_frame_size = 0;
}
void EspiaAcq::getFrameDim(FrameDim& frame_dim)
void Acq::getFrameDim(FrameDim& frame_dim)
{
frame_dim = m_frame_dim;
}
void EspiaAcq::getNbBuffers(int& nb_buffers)
void Acq::getNbBuffers(int& nb_buffers)
{
nb_buffers = m_nb_buffers;
}
void EspiaAcq::getBufferFrames(int& buffer_frames)
void Acq::getBufferFrames(int& buffer_frames)
{
buffer_frames = m_buffer_frames;
}
void *EspiaAcq::getBufferFramePtr(int buffer_nb, int frame_nb)
void *Acq::getBufferFramePtr(int buffer_nb, int frame_nb)
{
int real_buffer = realBufferNb(buffer_nb, frame_nb);
int real_frame = realFrameNb(buffer_nb, frame_nb);
......@@ -171,7 +171,7 @@ void *EspiaAcq::getBufferFramePtr(int buffer_nb, int frame_nb)
return ptr;
}
void *EspiaAcq::getAcqFramePtr(int acq_frame_nb)
void *Acq::getAcqFramePtr(int acq_frame_nb)
{
unsigned long buffer_nb = ESPIA_ACQ_ANY;
void *ptr;
......@@ -179,7 +179,7 @@ void *EspiaAcq::getAcqFramePtr(int acq_frame_nb)
return ptr;
}
void EspiaAcq::getFrameInfo(int acq_frame_nb, HwFrameInfoType& info)
void Acq::getFrameInfo(int acq_frame_nb, HwFrameInfoType& info)
{
struct img_frame_info finfo;
finfo.buffer_nr = ESPIA_ACQ_ANY;
......@@ -191,8 +191,8 @@ void EspiaAcq::getFrameInfo(int acq_frame_nb, HwFrameInfoType& info)
real2virtFrameInfo(finfo, info);
}
void EspiaAcq::real2virtFrameInfo(const struct img_frame_info& real_info,
HwFrameInfoType& virt_info)
void Acq::real2virtFrameInfo(const struct img_frame_info& real_info,
HwFrameInfoType& virt_info)
{
char *buffer_ptr = (char *) real_info.buffer_ptr;
int frame_offset = real_info.frame_nr * m_real_frame_size;
......@@ -200,11 +200,11 @@ void EspiaAcq::real2virtFrameInfo(const struct img_frame_info& real_info,
virt_info.acq_frame_nb = real_info.acq_frame_nr;
virt_info.frame_ptr = buffer_ptr + frame_offset;
virt_info.frame_dim = &m_frame_dim;
virt_info.frame_timestamp = usec2sec(real_info.time_us);
virt_info.frame_timestamp = USec2Sec(real_info.time_us);
virt_info.valid_pixels = real_info.pixels;
}
void EspiaAcq::resetFrameInfo(struct img_frame_info& frame_info)
void Acq::resetFrameInfo(struct img_frame_info& frame_info)
{
frame_info.buffer_ptr = NULL;
frame_info.buffer_nr = SCDXIPCI_INVALID;
......@@ -215,7 +215,7 @@ void EspiaAcq::resetFrameInfo(struct img_frame_info& frame_info)
frame_info.pixels = 0;
}
void EspiaAcq::setNbFrames(int nb_frames)
void Acq::setNbFrames(int nb_frames)
{
if (nb_frames < 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid nb of frames");
......@@ -223,12 +223,12 @@ void EspiaAcq::setNbFrames(int nb_frames)
m_nb_frames = nb_frames;
}
void EspiaAcq::getNbFrames(int& nb_frames)
void Acq::getNbFrames(int& nb_frames)
{
nb_frames = m_nb_frames;
}
void EspiaAcq::startAcq()
void Acq::startAcq()
{
AutoMutex l = acqLock();
......@@ -243,7 +243,7 @@ void EspiaAcq::startAcq()
m_started = true;
}
void EspiaAcq::stopAcq()
void Acq::stopAcq()
{
AutoMutex l = acqLock();
......@@ -255,7 +255,7 @@ void EspiaAcq::stopAcq()
m_started = false;
}
void EspiaAcq::getAcqStatus(AcqStatusType& acq_status)
void Acq::getAcqStatus(AcqStatusType& acq_status)
{
AutoMutex l = acqLock();
......
#include "EspiaDev.h"
using namespace lima;
using namespace lima::Espia;
using namespace std;
#define CHECK_CALL(ret) ESPIA_CHECK_CALL(ret)
EspiaDev::EspiaDev(int dev_nb)
Dev::Dev(int dev_nb)
{
m_dev_nb = Invalid;
m_dev = ESPIA_DEV_INVAL;
......@@ -13,12 +13,12 @@ EspiaDev::EspiaDev(int dev_nb)
open(dev_nb);
}
EspiaDev::~EspiaDev()
Dev::~Dev()
{
close();
}
void EspiaDev::open(int dev_nb)
void Dev::open(int dev_nb)
{
if (dev_nb == m_dev_nb)
return;
......@@ -29,7 +29,7 @@ void EspiaDev::open(int dev_nb)
m_dev_nb = dev_nb;
}
void EspiaDev::close()
void Dev::close()
{
if (m_dev_nb == Invalid)
return;
......@@ -40,7 +40,7 @@ void EspiaDev::close()
m_dev_nb = Invalid;
}
void EspiaDev::registerCallback(struct espia_cb_data& cb_data, int& cb_nr)
void Dev::registerCallback(struct espia_cb_data& cb_data, int& cb_nr)
{
CHECK_CALL(espia_register_callback(m_dev, &cb_data, &cb_nr));
......@@ -54,7 +54,7 @@ void EspiaDev::registerCallback(struct espia_cb_data& cb_data, int& cb_nr)
}
void EspiaDev::unregisterCallback(int& cb_nr)
void Dev::unregisterCallback(int& cb_nr)
{
CHECK_CALL(espia_unregister_callback(m_dev, cb_nr));
......
#include "EspiaSerialLine.h"
#include "Espia.h"
using namespace lima;
using namespace lima::Espia;
using namespace std;
#define CHECK_CALL(ret) ESPIA_CHECK_CALL(ret)
EspiaSerialLine::EspiaSerialLine( EspiaDev& edev, const string& line_term,
double timeout, int block_size,
double block_delay ) :
SerialLine::SerialLine( Dev& edev, const string& line_term,
double timeout, int block_size,
double block_delay ) :
HwSerialLine(line_term, timeout, block_size, block_delay),
m_dev(edev)
{
if( edev.isMeta() )
throw LIMA_HW_EXC(NotSupported, "Can't create an "
"EspiaSerialLine for a meta-device");
"SerialLine for a meta-device");
}
EspiaSerialLine::~EspiaSerialLine()
SerialLine::~SerialLine()
{
}
void EspiaSerialLine::write( const string& buffer, bool no_wait )
void SerialLine::write( const string& buffer, bool no_wait )
{
unsigned long len = buffer.length();
char *ptr = len ? (char *) buffer.data() : NULL;
......@@ -32,30 +32,30 @@ void EspiaSerialLine::write( const string& buffer, bool no_wait )
double block_delay; getBlockDelay(block_delay);
CHECK_CALL( espia_ser_write(m_dev, ptr, &len, block_size,
sec2usec(block_delay), !no_wait) );
Sec2USec(block_delay), !no_wait) );
}
void EspiaSerialLine::read( string& buffer, int max_len, double timeout )
void SerialLine::read( string& buffer, int max_len, double timeout )
{
buffer.resize(max_len);
char *ptr = max_len ? (char *) buffer.data() : NULL;
unsigned long ret_len = max_len;
unsigned long tmout = sec2usec(checkDefTimeout(timeout));
unsigned long tmout = Sec2USec(checkDefTimeout(timeout));
CHECK_CALL( espia_ser_read(m_dev, ptr, &ret_len, tmout) );
buffer.resize(ret_len);
}
void EspiaSerialLine::readStr( string& buffer, int max_len,
const string& term, double timeout )
void SerialLine::readStr( string& buffer, int max_len,
const string& term, double timeout )
{
buffer.resize(max_len);
char *ptr = max_len ? (char *) buffer.data() : NULL;
char *term_ptr = (char *) term.data();
unsigned long ret_len = max_len;
unsigned long tmout = sec2usec(checkDefTimeout(timeout));
unsigned long tmout = Sec2USec(checkDefTimeout(timeout));
CHECK_CALL( espia_ser_read_str(m_dev, ptr, &ret_len, term_ptr,
term.length(), tmout) );
......@@ -63,13 +63,13 @@ void EspiaSerialLine::readStr( string& buffer, int max_len,
}
void EspiaSerialLine::flush()
void SerialLine::flush()
{
CHECK_CALL(espia_ser_flush(m_dev));
}
void EspiaSerialLine::getNumAvailBytes( int &avail_bytes )
void SerialLine::getNumAvailBytes( int &avail_bytes )
{
unsigned long ret_bytes = 0;
......
......@@ -8,70 +8,35 @@
namespace lima
{
class Frelon
namespace Frelon
{
public:
enum Reg {
NrFrames, ExpTime, ShutCloseTime, LatencyTime,
RoiLineBegin, RoiLineWidth, RoiPixelBegin, RoiPixelWidth,
ChanMode, TimeUnit, RoiEnable, RoiFast,
AntiBloom, BinVert, BinHorz, ConfigHD,
RoiKinetic, ShutEnable, HardTrigDisable,
PixelFreq, LineFreq, Flip, IntCalib,
DisplayImage, AdcFloatDiode, AdcSignal,
DarkPixelCalib, DarkPixelMode, ChanControl, Mire,
AoiLineBegin, AoiLineWidth, AoiPixelBegin, AoiPixelWidth,
AoiImageHeight, AoiImageWidth, ChanOnImage, ChanOnCcd,
Version, SerNr, Warn,
};
enum Cmd {
Reset, Start, Stop, Save,
};
enum MultiLineCmd {
Help, Config, Dac, Volt,
Aoi,