17 #ifndef SCIP2_RESPONSE_STREAM_H 18 #define SCIP2_RESPONSE_STREAM_H 20 #include <boost/asio.hpp> 42 using Callback = boost::function<void(
43 const boost::posix_time::ptime &,
52 virtual std::string getCommandCode()
const = 0;
53 virtual void operator()(
54 const boost::posix_time::ptime &,
60 const boost::posix_time::ptime &time_read,
61 const std::string &echo_back,
62 const std::string &status,
73 cb_(time_read, echo_back, status, scan);
74 std::cout << echo_back <<
" errored with " << status << std::endl;
78 if (!std::getline(stream, stamp))
80 std::cerr <<
"Failed to get timestamp" << std::endl;
83 const uint8_t checksum = stamp.back();
87 std::cerr <<
"Wrong timestamp format" << std::endl;
92 auto it = dec.
begin();
94 if ((dec.getChecksum() & 0x3F) + 0x30 != checksum)
96 std::cerr <<
"Checksum mismatch" << std::endl;
112 return std::string(
"MD");
115 const boost::posix_time::ptime &time_read,
116 const std::string &echo_back,
117 const std::string &status,
118 std::istream &stream)
override 121 if (!readTimestamp(time_read, echo_back, status, stream, scan))
127 while (std::getline(stream, line))
129 if (line.size() == 0)
132 const uint8_t checksum = line.back();
136 std::cerr <<
"Wrong stream format" << std::endl;
140 auto it = dec.
begin();
141 for (; it != dec.
end(); ++it)
145 remain = it.getRemain();
146 if ((dec.getChecksum() & 0x3F) + 0x30 != checksum)
148 std::cerr <<
"Checksum mismatch; scan dropped" << std::endl
149 << line << std::endl;
154 cb_(time_read, echo_back, status, scan);
163 return std::string(
"ME");
166 const boost::posix_time::ptime &time_read,
167 const std::string &echo_back,
168 const std::string &status,
169 std::istream &stream)
override 172 if (!readTimestamp(time_read, echo_back, status, stream, scan))
179 while (std::getline(stream, line))
181 if (line.size() == 0)
184 const uint8_t checksum = line.back();
188 std::cerr <<
"Wrong stream format" << std::endl;
192 auto it = dec.
begin();
193 for (; it != dec.
end(); ++it)
195 scan.
ranges_.push_back((*it) >> 18);
198 remain = it.getRemain();
199 if ((dec.getChecksum() & 0x3F) + 0x30 != checksum)
201 std::cerr <<
"Checksum mismatch; scan dropped" << std::endl
202 << line << std::endl;
207 cb_(time_read, echo_back, status, scan);
213 #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)
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
boost::function< void(const boost::posix_time::ptime &, const std::string &, const std::string &, const ScanData &)> Callback
void operator()(const boost::posix_time::ptime &time_read, const std::string &echo_back, const std::string &status, std::istream &stream) override