17 #ifndef SCIP2_RESPONSE_STREAM_H 18 #define SCIP2_RESPONSE_STREAM_H 20 #include <boost/asio.hpp> 43 using Callback = boost::function<void(
44 const boost::posix_time::ptime&,
53 virtual std::string getCommandCode()
const = 0;
54 virtual void operator()(
55 const boost::posix_time::ptime&,
61 const boost::posix_time::ptime& time_read,
62 const std::string& echo_back,
63 const std::string& status,
72 if (!std::getline(stream, stamp))
77 const uint8_t checksum = stamp.back();
86 auto it = dec.
begin();
88 if ((dec.getChecksum() & 0x3F) + 0x30 != checksum)
106 return std::string(
"MD");
109 const boost::posix_time::ptime& time_read,
110 const std::string& echo_back,
111 const std::string& status,
112 std::istream& stream)
override 115 if (!readTimestamp(time_read, echo_back, status, stream, scan))
118 cb_(time_read, echo_back, status, scan);
125 while (std::getline(stream, line))
127 if (line.size() == 0)
130 const uint8_t checksum = line.back();
138 auto it = dec.
begin();
139 for (; it != dec.
end(); ++it)
143 remain = it.getRemain();
144 if ((dec.getChecksum() & 0x3F) + 0x30 != checksum)
146 logger::error() <<
"Checksum mismatch; scan dropped" << std::endl
147 << line << std::endl;
152 cb_(time_read, echo_back, status, scan);
161 return std::string(
"ME");
164 const boost::posix_time::ptime& time_read,
165 const std::string& echo_back,
166 const std::string& status,
167 std::istream& stream)
override 170 if (!readTimestamp(time_read, echo_back, status, stream, scan))
173 cb_(time_read, echo_back, status, scan);
181 while (std::getline(stream, line))
183 if (line.size() == 0)
186 const uint8_t checksum = line.back();
194 auto it = dec.
begin();
195 for (; it != dec.
end(); ++it)
197 scan.
ranges_.push_back((*it) >> 18);
200 remain = it.getRemain();
201 if ((dec.getChecksum() & 0x3F) + 0x30 != checksum)
203 logger::error() <<
"Checksum mismatch; scan dropped" << std::endl
204 << line << std::endl;
209 cb_(time_read, echo_back, status, scan);
215 #endif // SCIP2_RESPONSE_STREAM_H
std::vector< int32_t > ranges_
void registerCallback(Callback cb)
bool readTimestamp(const boost::posix_time::ptime &time_read, const std::string &echo_back, const std::string &status, std::istream &stream, ScanData &scan)
boost::function< void(const boost::posix_time::ptime &, const std::string &, const std::string &, const ScanData &)> Callback
std::vector< int32_t > intensities_
std::string getCommandCode() const
void operator()(const boost::posix_time::ptime &time_read, const std::string &echo_back, const std::string &status, std::istream &stream) override
std::string getCommandCode() const
void operator()(const boost::posix_time::ptime &time_read, const std::string &echo_back, const std::string &status, std::istream &stream) override