46 for(
size_t i=8; i<buffer_.size(); i++)
55 CoLaFrame(
const char *str) : buffer_(8+strlen(str), (char)0) {
58 buffer_[i++] = *(str++);
62 char *data = &buffer_[0];
63 *(uint32_t*)(data+0) = htonl(0x02020202);
64 *(uint32_t*)(data+4) = htonl(buffer_.size()-8);
84 Control(boost::asio::io_service& io_service,
const std::string &remote_device_ip) :
86 remote_device_ip_(remote_device_ip),
87 stream_started_(false)
96 if(!connect(remote_device_ip_,
"2112")) {
97 ROS_ERROR(
"Error on connecting to %s", remote_device_ip_.c_str());
112 ROS_DEBUG(
"Sending on sMN GetBlobClientConfig");
123 if(stream_started_)
return true;
126 ROS_DEBUG(
"Sending on sopas sMN PLAYSTART");
128 stream_started_ =
true;
136 if(!stream_started_)
return true;
139 ROS_DEBUG(
"Sending on sopas sMN PLAYSTOP");
141 stream_started_ =
false;
159 typedef boost::signals2::signal<void (const boost::shared_ptr<Data> &)>
SIG_ON_FRAME;
170 Streaming(boost::asio::io_service& io_service,
const std::string &remote_device_ip) :
172 remote_device_ip_(remote_device_ip),
185 ROS_DEBUG(
"Opening streaming socket...");
186 if(!connect(remote_device_ip_,
"2113")) {
187 ROS_DEBUG(
"Error on connecting to %s", remote_device_ip_.c_str());
193 const char HEARTBEAT_MSG[] =
"BlbReq";
195 ROS_DEBUG(
"Sending BlbReq: %s", HEARTBEAT_MSG);
196 write(std::string(HEARTBEAT_MSG,
sizeof(HEARTBEAT_MSG)-1));
203 ROS_DEBUG(
"Closing streaming connection...");
217 ROS_DEBUG(
"Reading image from stream...");
219 if(!data || size<0) {
220 ROS_DEBUG(
"Socket not connected, terminating.");
225 cur_frame_->buffer.insert(cur_frame_->buffer.end(), data, data+size );
233 const size_t actual_size = parser->actual_size(&cur_frame_->buffer[0], cur_frame_->buffer.size());
234 if(parser->read(&cur_frame_->buffer[0], actual_size)) {
244 cur_frame_->buffer.erase(cur_frame_->buffer.begin(), cur_frame_->buffer.begin()+actual_size);
249 cur_frame_.reset(
new SFrame());
250 on_data(data, size, writer);
static bool check_header(const char *data, const size_t size)
abstract connection handler to process incoming data (independent of protocol)
const std::string remote_device_ip_
boost::shared_ptr< SFrame > Ptr
boost::signals2::signal< void(const char *data, const size_t size, Any_Session *writer)> SIG_ON_DATA
incoming data with "data" of size "size" and handler to write back ("writer")
SIG_ON_FRAME & getSignal()
void on_data(const char *data, const size_t size, Any_Session *writer)
boost::signals2::signal< void(const boost::shared_ptr< Data > &)> SIG_ON_FRAME
CoLaFrame(const char *str)
Any_Session::SIG_ON_DATA on_data_
signal handler for incoming data
std::vector< char > buffer
std::vector< char > buffer_
Streaming(boost::asio::io_service &io_service, const std::string &remote_device_ip)
virtual bool connect(const std::string &path, const std::string &service)
Any_Session::SIG_ON_DATA on_data_
signal handler for incoming data
const std::string remote_device_ip_
Control(boost::asio::io_service &io_service, const std::string &remote_device_ip)
std::vector< char > finish()
void on_data(const char *data, const size_t size, Any_Session *writer)
implementation connection handler for TCP