ChimeraTK-DeviceAccess  03.18.00
Connection.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 #pragma once
4 
5 #include <boost/array.hpp>
6 #include <boost/asio.hpp>
7 #include <boost/asio/buffer.hpp>
8 #include <boost/make_shared.hpp>
9 #include <boost/shared_ptr.hpp>
10 
11 #include <chrono>
12 #include <memory>
13 #include <thread>
14 #include <vector>
15 
16 namespace ChimeraTK::Rebot {
17 
19  class Connection {
20  public:
23  Connection(std::string address, std::string port, uint32_t connectionTimeout_sec);
24 
26  void open();
27 
29  void close();
30 
32  std::vector<uint32_t> read(uint32_t numWordsToRead);
33 
35  void write(const std::vector<uint32_t>& data);
36 
38  bool isOpen();
39 
40  private:
41  std::string address_;
42  const std::string port_;
43  boost::asio::io_service ioService_;
44  boost::asio::ip::tcp::socket s_;
45  boost::asio::deadline_timer disconnectTimer_;
46  boost::asio::deadline_timer::duration_type connectionTimeout_;
47 
48  void disconnectionTimerStart();
49  void disconnectionTimerCancel(const boost::system::error_code& ec);
50  };
51 } // namespace ChimeraTK::Rebot
ChimeraTK::Rebot::Connection::close
void close()
Closes a connection with the device.
Definition: Connection.cc:50
ChimeraTK::Rebot
Definition: RebotBackend.h:26
ChimeraTK::Rebot::Connection
Handles the communication over TCP protocol with RebotDevice-based devices.
Definition: Connection.h:19
ChimeraTK::Rebot::Connection::isOpen
bool isOpen()
Get the connection state.
Definition: Connection.cc:58
ChimeraTK::Rebot::Connection::Connection
Connection(std::string address, std::string port, uint32_t connectionTimeout_sec)
Gets an IP address and port of the device but does not open the connection.
Definition: Connection.cc:13
ChimeraTK::Rebot::Connection::write
void write(const std::vector< uint32_t > &data)
Sends a std::vector of bytes to the socket.
Definition: Connection.cc:42
ChimeraTK::Rebot::Connection::open
void open()
Opens a connection to the device.
Definition: Connection.cc:17
ChimeraTK::Rebot::Connection::read
std::vector< uint32_t > read(uint32_t numWordsToRead)
Receives uint32_t words from the socket.
Definition: Connection.cc:32