Definition at line 40 of file sqmctrl.cc.
References buffer, SQM::Data::counts, data, Error(), SQM::Data::freq, Time::GetAsStr(), HandleRequestTrigger(), SQM::Data::mag, SQM::Data::period, str, and SQM::Data::temp.
Referenced by ConnectionEstablished(), and StartReadReport().
43 if (bytes_received==0 || err)
45 if (err==ba::error::eof)
46 Warn(
"Connection closed by remote host.");
50 if (err && err!=ba::error::eof &&
51 err!=ba::error::basic_errors::not_connected &&
52 err!=ba::error::basic_errors::operation_aborted)
55 str <<
"Reading from " << URL() <<
": " << err.message() <<
" (" << err <<
")";
65 if (!getline(is, buffer,
'\n'))
67 Fatal(
"Received message does not contain \\n... closing connection.");
72 buffer = buffer.substr(0, buffer.size()-1);
76 Out() <<
Time().
GetAsStr(
"%H:%M:%S.%f") <<
"[" << buffer.size() <<
"]: " << buffer <<
"|" << endl;
84 boost::split(vec, buffer, boost::is_any_of(
","));
89 throw runtime_error(
"Unknown number of fields in received data");
92 throw runtime_error(
"Not a proper answer");
96 data.
mag = stof(vec[1]);
97 data.
freq = stol(vec[2]);
98 data.
counts = stol(vec[3]);
99 data.
period = stof(vec[4]);
100 data.
temp = stof(vec[5]);
106 catch (
const exception &e)
109 Warn(
"Parsing first message failed ["+
string(e.what())+
"]");
112 Error(
"Parsing received message failed ["+
string(e.what())+
"]");
113 Error(
"Received: "+buffer);
123 this, dummy::error));
virtual void Update(const SQM::Data &)
Adds some functionality to boost::posix_time::ptime for our needs.
boost::asio::deadline_timer fTrigger
boost::asio::streambuf fBuffer
void HandleRequestTrigger(const bs::error_code &error)
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const