Commit c6aaca8b authored by ahoms's avatar ahoms
Browse files

* added camera/common/espia with basic Espia object

* using std::string everywhere instead of String



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@51 45c4679d-1946-429d-baad-37912b19538b
parent b49be161
.PHONY: simulator .PHONY: simulator common
all: simulator all: simulator common
simulator: simulator:
make -C simulator make -C simulator
common:
make -C common
.PHONY: espia
all: espia
espia:
make -C espia
#ifndef ESPIA_H
#define ESPIA_H
#include "Exceptions.h"
#include "espia_lib.h"
#include <string>
namespace lima
{
class Espia
{
public:
enum {
Invalid = -1,
};
Espia(int dev_nr);
~Espia();
void serWrite(const std::string& buffer,
int block_size = 0, double block_delay = 0,
bool no_wait = false);
void serRead(std::string& buffer, int& len, double timeout);
void serReadStr(std::string& buffer, int& len,
const std::string& term, double timeout);
static void throwError(int ret, std::string file, std::string func,
int line);
private:
void open(int dev_nr);
void close();
int m_dev_nr;
espia_t m_dev;
};
#define ESPIA_CHECK_CALL(ret) \
do { \
int aux_ret = (ret); \
if (aux_ret < 0) \
Espia::throwError(aux_ret, __FILE__, \
__FUNCTION__, __LINE__); \
} while (0)
} // namespace lima
#endif // ESPIA_H
#include "Espia.h"
using namespace lima;
using namespace std;
#define CHECK_CALL(ret) ESPIA_CHECK_CALL(ret)
Espia::Espia(int dev_nr)
: m_dev_nr(Invalid), m_dev(ESPIA_DEV_INVAL)
{
open(dev_nr);
}
Espia::~Espia()
{
close();
}
void Espia::open(int dev_nr)
{
if (dev_nr == m_dev_nr)
return;
close();
CHECK_CALL(espia_open(dev_nr, &m_dev));
m_dev_nr = dev_nr;
}
void Espia::close()
{
if (m_dev_nr == Invalid)
return;
CHECK_CALL(espia_close(m_dev));
m_dev = ESPIA_DEV_INVAL;
m_dev_nr = Invalid;
}
void 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);
}
ESPIA_DRV_BASE = /segfs/bliss/source/driver/linux-2.6/espia
ESPIA_DRV_INC = $(ESPIA_DRV_BASE)/src
CXXFLAGS = -I../include -I../../../../hardware/include \
-I../../../../common/include -I$(ESPIA_DRV_INC)
all: clean Espia.o
clean:
rm -f *.o
#include "SimuHwInterface.h" #include "SimuHwInterface.h"
using namespace lima; using namespace lima;
using namespace std;
/******************************************************************* /*******************************************************************
* \brief SimuDetInfoCtrlObj constructor * \brief SimuDetInfoCtrlObj constructor
...@@ -53,12 +54,12 @@ void SimuDetInfoCtrlObj::getPixelSize(double& pixel_size) ...@@ -53,12 +54,12 @@ void SimuDetInfoCtrlObj::getPixelSize(double& pixel_size)
pixel_size = 1e-6; pixel_size = 1e-6;
} }
void SimuDetInfoCtrlObj::getDetectorType(std::string& det_type) void SimuDetInfoCtrlObj::getDetectorType(string& det_type)
{ {
det_type = "Simulator"; det_type = "Simulator";
} }
void SimuDetInfoCtrlObj::getDetectorModel(std::string& det_model) void SimuDetInfoCtrlObj::getDetectorModel(string& det_model)
{ {
det_model = "PeakGenerator"; det_model = "PeakGenerator";
} }
......
...@@ -15,17 +15,16 @@ class BufferSave { ...@@ -15,17 +15,16 @@ class BufferSave {
Raw, EDF, Raw, EDF,
}; };
typedef std::string String; BufferSave( FileFormat format = Raw,
const std::string& prefix = "img",
BufferSave( FileFormat format = Raw, const String& prefix = "img", int idx = 0, const std::string& suffix = "",
int idx = 0, const String& suffix = "",
bool overwrite = false , int tot_file_frames = 1); bool overwrite = false , int tot_file_frames = 1);
~BufferSave( ); ~BufferSave( );
void writeFrame( const HwFrameInfoType& finfo ); void writeFrame( const HwFrameInfoType& finfo );
void setPrefix(const String& prefix); void setPrefix(const std::string& prefix);
void getPrefix(String& prefix) const; void getPrefix(std::string& prefix) const;
void setFormat(FileFormat format); void setFormat(FileFormat format);
void getFormat(FileFormat& format) const; void getFormat(FileFormat& format) const;
...@@ -36,21 +35,21 @@ class BufferSave { ...@@ -36,21 +35,21 @@ class BufferSave {
void setTotFileFrames(int tot_file_frames); void setTotFileFrames(int tot_file_frames);
void getTotFileFrames(int& tot_file_frames) const; void getTotFileFrames(int& tot_file_frames) const;
void getOpenFileName(String& file_name) const; void getOpenFileName(std::string& file_name) const;
bool isFileOpen() const; bool isFileOpen() const;
private: private:
String getDefSuffix() const; std::string getDefSuffix() const;
void openFile(); void openFile();
void closeFile(); void closeFile();
void writeEdfHeader( const HwFrameInfoType& finfo ); void writeEdfHeader( const HwFrameInfoType& finfo );
FileFormat m_format; FileFormat m_format;
String m_prefix; std::string m_prefix;
int m_idx; int m_idx;
String m_suffix; std::string m_suffix;
String m_file_name; std::string m_file_name;
bool m_overwrite; bool m_overwrite;
int m_written_frames; int m_written_frames;
int m_tot_file_frames; int m_tot_file_frames;
......
#ifndef EXCEPTIONS_H #ifndef EXCEPTIONS_H
#define EXCEPTIONS_H #define EXCEPTIONS_H
#include <string> #include <string.h>
#include <ostream> #include <ostream>
namespace lima namespace lima
...@@ -19,20 +19,18 @@ enum ErrorType { ...@@ -19,20 +19,18 @@ enum ErrorType {
class Exception class Exception
{ {
public: public:
typedef std::string String; Exception(Layer layer, ErrorType err_type, std::string err_desc,
std::string file_name, std::string funct_name, int line_nr);
Exception(Layer layer, ErrorType err_type, String err_desc,
String file_name, String funct_name, int line_nr);
std::string getErrMsg() const;
String getErrMsg() const;
private: private:
Layer m_layer; Layer m_layer;
ErrorType m_err_type; ErrorType m_err_type;
String m_err_desc; std::string m_err_desc;
String m_file_name; std::string m_file_name;
String m_funct_name; std::string m_funct_name;
int m_line_nr; int m_line_nr;
}; };
......
...@@ -15,8 +15,8 @@ using namespace std; ...@@ -15,8 +15,8 @@ using namespace std;
#define EDF_HEADER_BUFFER_LEN (10 * EDF_HEADER_LEN) #define EDF_HEADER_BUFFER_LEN (10 * EDF_HEADER_LEN)
BufferSave::BufferSave( FileFormat format, const String& prefix, int idx, BufferSave::BufferSave( FileFormat format, const string& prefix, int idx,
const String& suffix, bool overwrite, const string& suffix, bool overwrite,
int tot_file_frames ) int tot_file_frames )
: m_format(format), m_prefix(prefix), m_idx(idx), m_suffix(suffix), : m_format(format), m_prefix(prefix), m_idx(idx), m_suffix(suffix),
m_overwrite(overwrite), m_tot_file_frames(tot_file_frames) m_overwrite(overwrite), m_tot_file_frames(tot_file_frames)
...@@ -33,7 +33,7 @@ BufferSave::~BufferSave( ) ...@@ -33,7 +33,7 @@ BufferSave::~BufferSave( )
closeFile(); closeFile();
} }
BufferSave::String BufferSave::getDefSuffix() const string BufferSave::getDefSuffix() const
{ {
return (m_format == EDF) ? ".edf" : ".raw"; return (m_format == EDF) ? ".edf" : ".raw";
} }
...@@ -139,7 +139,7 @@ bool BufferSave::isFileOpen() const ...@@ -139,7 +139,7 @@ bool BufferSave::isFileOpen() const
return bool(m_fout); return bool(m_fout);
} }
void BufferSave::setPrefix(const String& prefix) void BufferSave::setPrefix(const string& prefix)
{ {
if (prefix == m_prefix) if (prefix == m_prefix)
return; return;
...@@ -150,7 +150,7 @@ void BufferSave::setPrefix(const String& prefix) ...@@ -150,7 +150,7 @@ void BufferSave::setPrefix(const String& prefix)
m_prefix = prefix; m_prefix = prefix;
} }
void BufferSave::getPrefix(String& prefix) const void BufferSave::getPrefix(string& prefix) const
{ {
prefix = m_prefix; prefix = m_prefix;
} }
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
using namespace lima; using namespace lima;
using namespace std; using namespace std;
Exception::Exception(Layer layer, ErrorType err_type, String err_desc, Exception::Exception(Layer layer, ErrorType err_type, string err_desc,
String file_name, String funct_name, int line_nr) string file_name, string funct_name, int line_nr)
: m_layer(layer), m_err_type(err_type), m_err_desc(err_desc), : m_layer(layer), m_err_type(err_type), m_err_desc(err_desc),
m_file_name(file_name), m_funct_name(funct_name), m_line_nr(line_nr) m_file_name(file_name), m_funct_name(funct_name), m_line_nr(line_nr)
{ {
} }
Exception::String Exception::getErrMsg() const string Exception::getErrMsg() const
{ {
ostringstream os; ostringstream os;
os << m_layer << ": " os << m_layer << ": "
...@@ -23,7 +23,7 @@ Exception::String Exception::getErrMsg() const ...@@ -23,7 +23,7 @@ Exception::String Exception::getErrMsg() const
return os.str(); return os.str();
} }
std::ostream& lima::operator <<(std::ostream& os, Layer layer) ostream& lima::operator <<(ostream& os, Layer layer)
{ {
string name = "Unknown"; string name = "Unknown";
switch (layer) { switch (layer) {
...@@ -34,7 +34,7 @@ std::ostream& lima::operator <<(std::ostream& os, Layer layer) ...@@ -34,7 +34,7 @@ std::ostream& lima::operator <<(std::ostream& os, Layer layer)
return os << name; return os << name;
} }
std::ostream& lima::operator <<(std::ostream& os, ErrorType err_type) ostream& lima::operator <<(ostream& os, ErrorType err_type)
{ {
string name = "Unknown"; string name = "Unknown";
switch (err_type) { switch (err_type) {
...@@ -45,7 +45,7 @@ std::ostream& lima::operator <<(std::ostream& os, ErrorType err_type) ...@@ -45,7 +45,7 @@ std::ostream& lima::operator <<(std::ostream& os, ErrorType err_type)
return os << name; return os << name;
} }
std::ostream& lima::operator <<(std::ostream& os, const Exception& e) ostream& lima::operator <<(ostream& os, const Exception& e)
{ {
return os << e.getErrMsg(); return os << e.getErrMsg();
} }
......
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