Commit ac852f61 authored by ahoms's avatar ahoms
Browse files

* added Frelon Reg, Cmd and MultiLineCmd global string maps

* finished Frelon::SerialLine with automatic selection of readLine
  timeout depending of multi-line and Reset cmd detection in last write
* using std:;string::size() instead of length() (Espia::SerialLine)



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@74 45c4679d-1946-429d-baad-37912b19538b
parent e818688d
......@@ -31,7 +31,7 @@ class SerialLine : public HwSerialLine
const std::string& term,
double timeout=TimeoutDefault );
void flush();
virtual void flush();
virtual void getNumAvailBytes( int &avail_bytes );
......
......@@ -26,7 +26,7 @@ SerialLine::~SerialLine()
void SerialLine::write( const string& buffer, bool no_wait )
{
unsigned long len = buffer.length();
unsigned long len = buffer.size();
char *ptr = len ? (char *) buffer.data() : NULL;
int block_size; getBlockSize(block_size);
double block_delay; getBlockDelay(block_delay);
......@@ -58,7 +58,7 @@ void SerialLine::readStr( string& buffer, int max_len,
unsigned long tmout = Sec2USec(checkDefTimeout(timeout));
CHECK_CALL( espia_ser_read_str(m_dev, ptr, &ret_len, term_ptr,
term.length(), tmout) );
term.size(), tmout) );
buffer.resize(ret_len);
}
......
......@@ -25,15 +25,21 @@ enum Reg {
Version, SerNr, Warn,
};
extern std::map<Reg, std::string> RegStrMap;
enum Cmd {
Reset, Start, Stop, Save,
};
extern std::map<Cmd, std::string> CmdStrMap;
enum MultiLineCmd {
Help, Config, Dac, Volt,
Aoi,
};
extern std::map<MultiLineCmd, std::string> MultiLineCmdStrMap;
} // namespace Frelon
......
......@@ -16,26 +16,38 @@ class SerialLine : public HwSerialLine
MsgSync, MsgCmd, MsgVal, MsgReq, MsgTerm,
};
static const double TimeoutSingle, TimeoutNormal, TimeoutMax,
static const double TimeoutSingle, TimeoutNormal, TimeoutMultiLine,
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,
virtual void read(std::string& buffer, int max_len,
double timeout = TimeoutDefault);
virtual void readStr(std::string& buffer, int len,
virtual void readStr(std::string& buffer, int max_len,
const std::string& term,
double timeout = TimeoutDefault);
virtual void readLine(std::string& buffer, int max_len,
double timeout = TimeoutDefault);
virtual void readSingleLine(std::string& buffer, int max_len,
double timeout = TimeoutDefault);
virtual void readMultiLine(std::string& buffer, int max_len);
virtual void flush();
virtual void getNumAvailBytes(int &avail);
virtual void setTimeout(double timeout);
virtual void getTimeout(double& timeout) const;
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;
bool m_reset_cmd;
};
......
......@@ -3,4 +3,80 @@
using namespace lima::Frelon;
using namespace std;
typedef pair<Reg, string> RegPair;
static const RegPair RegStrList[] = {
RegPair(NrFrames, "N"),
RegPair(ExpTime, "I"),
RegPair(ShutCloseTime, "F"),
RegPair(LatencyTime, "T"),
RegPair(RoiLineBegin, "RLB"),
RegPair(RoiLineWidth, "RLW"),
RegPair(RoiPixelBegin, "RPB"),
RegPair(RoiPixelWidth, "RPW"),
RegPair(ChanMode, "M"),
RegPair(TimeUnit, "Z"),
RegPair(RoiEnable, "R"),
RegPair(RoiFast, "RF"),
RegPair(AntiBloom, "BL"),
RegPair(BinVert, "BV"),
RegPair(BinHorz, "BH"),
RegPair(ConfigHD, "CNF"),
RegPair(RoiKinetic, "SPE"),
RegPair(ShutEnable, "U"),
RegPair(HardTrigDisable,"HTD"),
RegPair(PixelFreq, "P"),
RegPair(LineFreq, "L"),
RegPair(Flip, "FLI"),
RegPair(IntCalib, "IE"),
RegPair(DisplayImage, "X"),
RegPair(AdcFloatDiode, "ADS"),
RegPair(AdcSignal, "ASS"),
RegPair(DarkPixelCalib, "DPE"),
RegPair(DarkPixelMode, "DPM"),
RegPair(ChanControl, "CCS"),
RegPair(Mire, "MIR"),
RegPair(AoiLineBegin, "ALB"),
RegPair(AoiLineWidth, "ALW"),
RegPair(AoiPixelBegin, "APB"),
RegPair(AoiPixelWidth, "APW"),
RegPair(AoiImageHeight, "IMH"),
RegPair(AoiImageWidth, "IMW"),
RegPair(ChanOnImage, "COI"),
RegPair(ChanOnCcd, "COC"),
RegPair(Version, "VER"),
RegPair(SerNr, "SN"),
RegPair(Warn, "W"),
};
static int RegStrListLen = sizeof(RegStrList) / sizeof(RegStrList[0]);
map<Reg, string> lima::Frelon::RegStrMap(RegStrList, (RegStrList +
RegStrListLen));
typedef pair<Cmd, string> CmdPair;
static const CmdPair CmdStrList[] = {
CmdPair(Reset, "RST"),
CmdPair(Start, "S"),
CmdPair(Stop, "O"),
CmdPair(Save, "SAV"),
};
static int CmdStrListLen = sizeof(CmdStrList) / sizeof(CmdStrList[0]);
map<Cmd, string> lima::Frelon::CmdStrMap(CmdStrList, (CmdStrList +
CmdStrListLen));
typedef pair<MultiLineCmd, string> MLCmdPair;
static const MLCmdPair MLCmdStrList[] = {
MLCmdPair(Help, "H"),
MLCmdPair(Config, "C"),
MLCmdPair(Dac, "D"),
MLCmdPair(Volt, "V"),
MLCmdPair(Aoi, "AOI"),
};
static int MLCmdStrListLen = sizeof(MLCmdStrList) / sizeof(MLCmdStrList[0]);
static const MLCmdPair *MLCmdStrEnd = MLCmdStrList + MLCmdStrListLen;
map<MultiLineCmd, string> lima::Frelon::MultiLineCmdStrMap(MLCmdStrList,
MLCmdStrEnd);
......@@ -4,10 +4,10 @@
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;
const double SerialLine::TimeoutSingle = 0.5;
const double SerialLine::TimeoutNormal = 2.0;
const double SerialLine::TimeoutMultiLine = 3.0;
const double SerialLine::TimeoutReset = 5.0;
SerialLine::SerialLine(Espia::SerialLine& espia_ser_line)
......@@ -15,26 +15,108 @@ SerialLine::SerialLine(Espia::SerialLine& espia_ser_line)
{
m_espia_ser_line.setLineTerm("\r\n");
m_espia_ser_line.setTimeout(TimeoutNormal);
m_multi_line_cmd = true;
m_multi_line_cmd = false;
m_reset_cmd = false;
}
void SerialLine::write(const std::string& buffer, bool no_wait)
void SerialLine::write(const string& buffer, bool no_wait)
{
map<MsgPart, string> msg_parts;
splitMsg(buffer, msg_parts);
const string& cmd = msg_parts[MsgCmd];
m_multi_line_cmd = false;
m_reset_cmd = (cmd == CmdStrMap[Reset]);
if (!m_reset_cmd) {
map<MultiLineCmd, string>::const_iterator it, end;
end = MultiLineCmdStrMap.end();
for (it = MultiLineCmdStrMap.begin(); it != end; ++it) {
if (it->second == cmd) {
m_multi_line_cmd = true;
break;
}
}
}
string sync = !msg_parts[MsgSync].size() ? ">" : "";
string term = !msg_parts[MsgTerm].size() ? "\r\n" : "";
string msg = sync + buffer + term;
m_espia_ser_line.write(msg, no_wait);
}
void SerialLine::read(string& buffer, int max_len, double timeout)
{
m_espia_ser_line.read(buffer, max_len, timeout);
}
void SerialLine::read(std::string& buffer, int len, double timeout)
void SerialLine::readStr(string& buffer, int max_len,
const string& term, double timeout)
{
m_espia_ser_line.readStr(buffer, max_len, term, timeout);
}
void SerialLine::readStr(std::string& buffer, int len, double timeout)
void SerialLine::readLine(string& buffer, int max_len, double timeout)
{
if ((timeout == TimeoutDefault) && (m_multi_line_cmd))
readMultiLine(buffer, max_len);
else
readSingleLine(buffer, max_len, timeout);
}
void SerialLine::readSingleLine(string& buffer, int max_len, double timeout)
{
if ((timeout == TimeoutDefault) && (m_reset_cmd)) {
timeout = TimeoutReset;
m_reset_cmd = false;
}
m_espia_ser_line.readLine(buffer, max_len, timeout);
}
#include <iostream>
void SerialLine::readMultiLine(string& buffer, int max_len)
{
Timestamp timeout = Timestamp::now() + Timestamp(TimeoutMultiLine);
buffer.clear();
while (Timestamp::now() < timeout) {
string ans;
int len = max_len - buffer.size();
try {
m_espia_ser_line.readLine(ans, len, TimeoutSingle);
buffer += ans;
} catch (Exception e) {
if (!buffer.empty())
break;
}
}
if (buffer.empty())
throw LIMA_HW_EXC(Error, "Timeout reading Frelon multi line");
}
void SerialLine::flush()
{
m_espia_ser_line.flush();
}
void SerialLine::getNumAvailBytes(int &avail)
{
m_espia_ser_line.getNumAvailBytes(avail);
}
void SerialLine::setTimeout(double timeout)
{
m_espia_ser_line.setTimeout(timeout);
}
void SerialLine::getTimeout(double& timeout) const
{
m_espia_ser_line.getTimeout(timeout);
}
void SerialLine::splitMsg(const string& msg,
map<MsgPart, string>& msg_parts) const
{
......
......@@ -28,40 +28,40 @@ void split_msg(const FSL& frelon_ser_line, const string& msg)
cout << endl;
}
void test_frelon()
void frelon_cmd(FSL& frelon_ser_line, const string& cmd)
{
Espia::Dev espia(0);
ESL espia_ser_line(espia);
string msg, ans;
Timestamp t0, t1;
split_msg(frelon_ser_line, cmd);
frelon_ser_line.write(cmd);
espia_ser_line.setTimeout(FSL::TimeoutNormal);
espia_ser_line.setLineTerm("\r\n");
Timestamp t0, t1;
string ans;
int max_len = 10000;
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);
frelon_ser_line.readLine(ans, max_len);
t1 = Timestamp::now();
cout << "Elapsed " << (t1 - t0) << " sec" << endl;
print_str("Ans", ans);
}
void test_frelon()
{
Espia::Dev espia(0);
ESL espia_ser_line(espia);
FSL frelon_ser_line(espia_ser_line);
frelon_ser_line.flush();
string msg;
msg = "RST";
frelon_cmd(frelon_ser_line, msg);
msg = ">C\r\n";
split_msg(frelon_ser_line, msg);
frelon_cmd(frelon_ser_line, msg);
msg = ">I?\r\n";
split_msg(frelon_ser_line, msg);
msg = "N1000";
split_msg(frelon_ser_line, msg);
frelon_cmd(frelon_ser_line, msg);
}
......
Supports Markdown
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