Commit f5d7b795 authored by ahoms's avatar ahoms
Browse files

* finished implementation of Frelon::SerialLine::splitCmd

* defined Frelon::SerialLine timeouts as double constants
* pass through negative (special) values in Espia sec-to/from-usec conv.
* inherit EspiaSerialLine also from Espia for common consts and methods
* removed unsigned long warning in EspiaAcq::getAcqFramePtr



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@72 45c4679d-1946-429d-baad-37912b19538b
parent 9fe527e6
......@@ -41,19 +41,22 @@ class Frelon
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);
double timeout = TimeoutDefault);
virtual void readStr(std::string& buffer, int len,
double timeout);
double timeout = TimeoutDefault);
virtual void getNumAvailBytes(int &avail);
void splitMsg(const std::string& msg,
std::map<MsgPart, std::string>& msg_parts);
std::map<MsgPart, std::string>& msg_parts) const;
private:
EspiaSerialLine& m_espia_ser_line;
......
......@@ -4,25 +4,43 @@
using namespace lima;
using namespace std;
#define FRELON_SINGLE_SER_TIMEOUT 0.5
#define FRELON_NORM_SER_TIMEOUT 1.5
#define FRELON_MAX_SER_TIMEOUT 2.0
#define FRELON_RESET_SER_TIMEOUT 5.0
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(FRELON_NORM_SER_TIMEOUT);
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)
map<MsgPart, string>& msg_parts) const
{
msg_parts.clear();
RegEx re("^(?P<pre>>)?"
RegEx re("^(?P<sync>>)?"
"(?P<cmd>[A-Z]+)"
"((?P<req>\\?)|(?P<val>[0-9]+))?"
"(?P<term>[\r\n]+)?$");
......@@ -31,8 +49,20 @@ void Frelon::SerialLine::splitMsg(const string& msg,
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-obs = ../src/Frelon.o ../../common/espia/src/Espia.o \
../../../hardware/src/Hw.o ../../../common/src/Common.o
frelon-objs = ../src/Frelon.o ../../common/espia/src/Espia.o \
../../../hardware/src/Hw.o ../../../common/src/Common.o
include ../../common/espia/include/espia.inc
......
......@@ -5,9 +5,56 @@
using namespace lima;
using namespace std;
typedef EspiaSerialLine ESL;
typedef Frelon::SerialLine FSL;
void print_str(const string& desc, const string& str)
{
cout << desc << " \"" << str << "\"" << endl;
}
void split_msg(const FSL& frelon_ser_line, const string& msg)
{
map<FSL::MsgPart, string> msg_parts;
frelon_ser_line.splitMsg(msg, msg_parts);
print_str("Msg", msg);
print_str("Sync", msg_parts[FSL::MsgSync]);
print_str("Cmd ", msg_parts[FSL::MsgCmd]);
print_str("Val ", msg_parts[FSL::MsgVal]);
print_str("Req ", msg_parts[FSL::MsgReq]);
print_str("Term", msg_parts[FSL::MsgTerm]);
cout << endl;
}
void test_frelon()
{
EspiaDev espia(0);
ESL espia_ser_line(espia);
string msg, ans;
espia_ser_line.setTimeout(FSL::TimeoutNormal);
espia_ser_line.setLineTerm("\r\n");
msg = ">C\r\n";
espia_ser_line.write(msg);
espia_ser_line.read(ans, 10000);
print_str("Ans", ans);
msg = ">I?\r\n";
espia_ser_line.write(msg);
espia_ser_line.readLine(ans, 10000, FSL::TimeoutSingle);
print_str("Ans", ans);
FSL frelon_ser_line(espia_ser_line);
msg = ">C\r\n";
split_msg(frelon_ser_line, msg);
msg = ">I?\r\n";
split_msg(frelon_ser_line, msg);
msg = "N1000";
split_msg(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