Commit a610bb91 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 f5d7b795
......@@ -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,
};
class SerialLine : public HwSerialLine
{
public:
enum MsgPart {
MsgSync, MsgCmd, MsgVal, MsgReq, MsgTerm,
};
static const double TimeoutSingle, TimeoutNormal, TimeoutMax,
TimeoutReset;
SerialLine(EspiaSerialLine& espia_ser_line);
virtual void write(const std::string& buffer,
bool no_wait = false);
virtual void read(std::string& buffer, int len,
double timeout = TimeoutDefault);
virtual void readStr(std::string& buffer, int len,
double timeout = TimeoutDefault);
virtual void getNumAvailBytes(int &avail);
void splitMsg(const std::string& msg,
std::map<MsgPart, std::string>& msg_parts) const;
private:
EspiaSerialLine& m_espia_ser_line;
bool m_multi_line_cmd;
};
Frelon(EspiaSerialLine& espia_ser_line);
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,
};
private:
SerialLine m_ser_line;
enum MultiLineCmd {
Help, Config, Dac, Volt,
Aoi,
};
} // namespace Frelon
} // namespace lima
#endif // FRELON_H
#ifndef FRELONCAMERA_H
#define FRELONCAMERA_H
#include "FrelonSerialLine.h"
namespace lima
{
namespace Frelon
{
class Camera
{
Camera(Espia::SerialLine& espia_ser_line);
private:
SerialLine m_ser_line;
};
} // namespace Frelon
} // namespace lima
#endif // FRELONCAMERA_H
#ifndef FRELONSERIALLINE_H
#define FRELONSERIALLINE_H
#include "Frelon.h"
namespace lima
{
namespace Frelon
{
class SerialLine : public HwSerialLine
{
public:
enum MsgPart {
MsgSync, MsgCmd, MsgVal, MsgReq, MsgTerm,
};
static const double TimeoutSingle, TimeoutNormal, TimeoutMax,
TimeoutReset;
SerialLine(Espia::SerialLine& espia_ser_line);
virtual void write(const std::string& buffer,
bool no_wait = false);
virtual void read(std::string& buffer, int len,
double timeout = TimeoutDefault);
virtual void readStr(std::string& buffer, int len,
double timeout = TimeoutDefault);
virtual void getNumAvailBytes(int &avail);
void splitMsg(const std::string& msg,
std::map<MsgPart, std::string>& msg_parts) const;
private:
Espia::SerialLine& m_espia_ser_line;
bool m_multi_line_cmd;
};
} // namespace Frelon
} // namespace lima
#endif // FRELONSERIALLINE_H
#include "Frelon.h"
#include "RegEx.h"
using namespace lima;
using namespace lima::Frelon;
using namespace std;
const double Frelon::SerialLine::TimeoutSingle = 0.5;
const double Frelon::SerialLine::TimeoutNormal = 2.0;
const double Frelon::SerialLine::TimeoutMax = 3.0;
const double Frelon::SerialLine::TimeoutReset = 5.0;
Frelon::SerialLine::SerialLine(EspiaSerialLine& espia_ser_line)
: m_espia_ser_line(espia_ser_line)
{
m_espia_ser_line.setLineTerm("\r\n");
m_espia_ser_line.setTimeout(TimeoutNormal);
m_multi_line_cmd = true;
}
void Frelon::SerialLine::write(const std::string& buffer, bool no_wait)
{
}
void Frelon::SerialLine::read(std::string& buffer, int len, double timeout)
{
}
void Frelon::SerialLine::readStr(std::string& buffer, int len, double timeout)
{
}
void Frelon::SerialLine::getNumAvailBytes(int &avail)
{
}
void Frelon::SerialLine::splitMsg(const string& msg,
map<MsgPart, string>& msg_parts) const
{
msg_parts.clear();
RegEx re("^(?P<sync>>)?"
"(?P<cmd>[A-Z]+)"
"((?P<req>\\?)|(?P<val>[0-9]+))?"
"(?P<term>[\r\n]+)?$");
RegEx::FullNameMatchType match;
if (!re.matchName(msg, match))
throw LIMA_HW_EXC(InvalidValue, "Invalid Frelon message");
typedef pair<MsgPart, string> KeyPair;
static const KeyPair key_list[] = {
KeyPair(MsgSync, "sync"), KeyPair(MsgCmd, "cmd"),
KeyPair(MsgVal, "val"), KeyPair(MsgReq, "req"),
KeyPair(MsgTerm, "term"),
};
static int key_len = sizeof(key_list) / sizeof(key_list[0]);
const KeyPair *it, *end = key_list + key_len;
for (it = key_list; it != end; ++it) {
const MsgPart& key = it->first;
const string& grp = it->second;
msg_parts[key] = string(match[grp].start, match[grp].end);
}
}
Frelon::Frelon(EspiaSerialLine& espia_ser_line)
: m_ser_line(espia_ser_line)
{
}
#include "FrelonCamera.h"
using namespace lima::Frelon;
using namespace std;
Camera::Camera(Espia::SerialLine& espia_ser_line)
: m_ser_line(espia_ser_line)
{
}
#include "FrelonSerialLine.h"
#include "RegEx.h"
using namespace lima::Frelon;
using namespace std;
const double SerialLine::TimeoutSingle = 0.5;
const double SerialLine::TimeoutNormal = 2.0;
const double SerialLine::TimeoutMax = 3.0;
const double SerialLine::TimeoutReset = 5.0;
SerialLine::SerialLine(Espia::SerialLine& espia_ser_line)
: m_espia_ser_line(espia_ser_line)
{
m_espia_ser_line.setLineTerm("\r\n");
m_espia_ser_line.setTimeout(TimeoutNormal);
m_multi_line_cmd = true;
}
void SerialLine::write(const std::string& buffer, bool no_wait)
{
}
void SerialLine::read(std::string& buffer, int len, double timeout)
{
}
void SerialLine::readStr(std::string& buffer, int len, double timeout)
{
}
void SerialLine::getNumAvailBytes(int &avail)
{
}
void SerialLine::splitMsg(const string& msg,
map<MsgPart, string>& msg_parts) const
{
msg_parts.clear();
RegEx re("^(?P<sync>>)?"
"(?P<cmd>[A-Z]+)"
"((?P<req>\\?)|(?P<val>[0-9]+))?"
"(?P<term>[\r\n]+)?$");
RegEx::FullNameMatchType match;
if (!re.matchName(msg, match))
throw LIMA_HW_EXC(InvalidValue, "Invalid Frelon message");
typedef pair<MsgPart, string> KeyPair;
static const KeyPair key_list[] = {
KeyPair(MsgSync, "sync"), KeyPair(MsgCmd, "cmd"),
KeyPair(MsgVal, "val"), KeyPair(MsgReq, "req"),
KeyPair(MsgTerm, "term"),
};
static int key_len = sizeof(key_list) / sizeof(key_list[0]);
const KeyPair *it, *end = key_list + key_len;
for (it = key_list; it != end; ++it) {
const MsgPart& key = it->first;
const string& grp = it->second;
msg_parts[key] = string(match[grp].start, match[grp].end);
}
}
include ../../common/espia/include/espia.inc
frelon-objs = FrelonBase.o FrelonSerialLine.o FrelonCamera.o
CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../hardware/include -I../../../common/include \
-I$(ESPIA_DRV_INCL) -Wall -pthread
all: clean Frelon.o
Frelon.o: $(frelon-objs)
$(LD) -o $@ -r $+
FrelonBase.o: Frelon.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
rm -f *.o
#include "Frelon.h"
#include "FrelonCamera.h"
#include <iostream>
using namespace lima;
using namespace std;
typedef EspiaSerialLine ESL;
typedef Espia::SerialLine ESL;
typedef Frelon::SerialLine FSL;
void print_str(const string& desc, const string& str)
......@@ -30,22 +30,29 @@ void split_msg(const FSL& frelon_ser_line, const string& msg)
void test_frelon()
{
EspiaDev espia(0);
Espia::Dev espia(0);
ESL espia_ser_line(espia);
string msg, ans;
Timestamp t0, t1;
espia_ser_line.setTimeout(FSL::TimeoutNormal);
espia_ser_line.setLineTerm("\r\n");
msg = ">C\r\n";
espia_ser_line.write(msg);
t0 = Timestamp::now();
espia_ser_line.read(ans, 10000);
t1 = Timestamp::now();
cout << "Elapsed " << (t1 - t0) << " sec" << endl;
print_str("Ans", ans);
msg = ">I?\r\n";
espia_ser_line.write(msg);
t0 = Timestamp::now();
espia_ser_line.readLine(ans, 10000, FSL::TimeoutSingle);
t1 = Timestamp::now();
cout << "Elapsed " << (t1 - t0) << " sec" << endl;
print_str("Ans", ans);
FSL frelon_ser_line(espia_ser_line);
......
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