33 #include <boost/asio.hpp>
34 #include <boost/array.hpp>
35 #include <boost/format.hpp>
36 #include <boost/bind.hpp>
37 #include <boost/serialization/access.hpp>
38 #include <boost/archive/binary_iarchive.hpp>
39 #include <boost/shared_array.hpp>
40 #include <boost/algorithm/string.hpp>
41 #include <boost/chrono.hpp>
70 const boost::posix_time::ptime&)>
cb_aux_;
80 std::vector<boost::shared_array<const TableSincos>>
tbl_v_;
86 boost::asio::streambuf
buf_;
104 timeout_ = boost::posix_time::milliseconds(
static_cast<int64_t
>(1000 * to));
109 boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(ip), port);
133 send(std::string(
"SET:_ars=1\n"));
135 send(std::string(
"SET:_ars=0\n"));
137 [[deprecated(
"use setHorizontalInterlace() instead of setInterlace()")]]
void setInterlace(
const int itl)
143 send((boost::format(
"SET:_itl=0,%02d\n") % itl).str());
147 send((boost::format(
"SET:_itv=0,%02d\n") % itl).str());
155 send(std::string(
"GET:tblv\n"));
159 for (
int i = 0; i < itl; ++i)
161 send((boost::format(
"GET:tv%02d\n") % i).str());
168 send(std::string(
"GET:tblh\n"));
172 send(std::string(
"PNG\n"));
176 send((boost::format(
"DAT:ax=%d\n") %
static_cast<int>(
start)).str());
182 send((boost::format(
"DAT:ri=%d\n") %
static_cast<int>(
start)).str());
186 send((boost::format(
"DAT:ro=%d\n") %
static_cast<int>(
start)).str());
196 boost::asio::async_read(
socket_,
buf_, boost::asio::transfer_at_least(4),
201 boost::system::error_code ec;
221 void send(
const std::string cmd)
224 boost::asio::async_write(
socket_, boost::asio::buffer(*data),
262 template <
class DATA_TYPE>
276 const DATA_TYPE* data = boost::asio::buffer_cast<const DATA_TYPE*>(
buf_.data());
278 for (
int s = 0;
s < range_index.
nspots;
s++)
280 const double spot =
s + range_header.
spot;
281 const double h_rad = h_head + (h_tail - h_head) *
tbl_h_[spot];
282 const double h_cos = cos(h_rad);
283 const double h_sin = sin(h_rad);
285 for (
int e = index[
s]; e < index[
s + 1]; e++)
286 points[i++] = dir * data[e];
290 void onRead(
const boost::system::error_code& error)
292 const auto time_read = boost::posix_time::microsec_clock::universal_time();
293 if (error == boost::asio::error::eof)
318 const uint8_t* data = boost::asio::buffer_cast<const uint8_t*>(
buf_.data());
319 for (
size_t i = 1; i <
buf_.size() -
sizeof(uint32_t); i++)
321 const uint32_t* mark =
reinterpret_cast<const uint32_t*
>(data + i);
336 for (
int i = 0; i < 1; ++i)
344 const std::string data(boost::asio::buffer_cast<const char*>(
buf_.data()));
345 std::string message(data, 0,
header.length -
header.header_length - 1);
361 const std::string data(boost::asio::buffer_cast<const char*>(
buf_.data()));
362 std::vector<std::string> lines;
363 boost::algorithm::split(lines, data, boost::algorithm::is_any_of(
"\n\r"));
364 if (lines.size() == 0)
367 if (lines[0].compare(0, 7,
"GET:tbl") == 0 ||
368 lines[0].compare(0, 6,
"GET:tv") == 0)
370 if (lines.size() < 2)
372 std::vector<std::string> cells;
373 boost::algorithm::split(cells, lines[1], boost::algorithm::is_any_of(
","));
375 if (lines[0].compare(
"GET:tblv") == 0 ||
376 lines[0].compare(0, 6,
"GET:tv") == 0)
379 if (lines[0].compare(0, 6,
"GET:tv") == 0)
380 tv = std::stoi(lines[0].substr(6));
382 if (tv >=
static_cast<int>(
tbl_v_.size()))
387 for (
auto& cell : cells)
389 const double rad(std::strtol(cell.c_str(),
nullptr, 16) * 2.0 * M_PI / 65535.0);
390 sincos(rad, &tbl_v[i].
s, &tbl_v[i].c);
396 bool load_finished =
true;
400 load_finished =
false;
404 else if (lines[0].compare(
"GET:tblh") == 0)
408 for (
auto& cell : cells)
410 tbl_h[i] = std::strtol(cell.c_str(),
nullptr, 16) / 65535.0;
443 const vssp::RangeHeader range_header = *boost::asio::buffer_cast<const vssp::RangeHeader*>(
buf_.data());
447 range_header_v2r1 = *boost::asio::buffer_cast<const vssp::RangeHeaderV2R1*>(
454 const vssp::RangeIndex range_index = *boost::asio::buffer_cast<const vssp::RangeIndex*>(
buf_.data());
462 std::memcpy(index.get(), boost::asio::buffer_cast<const vssp::RangeIndex*>(
buf_.data()),
463 sizeof(uint16_t) * (range_index.
nspots + 1));
464 buf_.consume(index_length);
465 length -= index_length;
474 success = rangeToXYZ<vssp::DataRangeIntensity>(
475 range_header, range_header_v2r1, range_index, index, points);
479 success = rangeToXYZ<vssp::DataRangeOnly>(
480 range_header, range_header_v2r1, range_index, index, points);
488 cb_point_(
header, range_header, range_index, index, points, time_read);
495 const vssp::AuxHeader aux_header = *boost::asio::buffer_cast<const vssp::AuxHeader*>(
buf_.data());
501 for (
int i = 0; i < aux_header.
data_count; i++)
503 const vssp::AuxData* data = boost::asio::buffer_cast<const vssp::AuxData*>(
buf_.data());
510 buf_.consume(
sizeof(int32_t) * offset);
511 length -=
sizeof(int32_t) * offset;
521 buf_.consume(length);