MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
tcp_connection.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
6 
7 #include <string>
8 
9 namespace microstrain
10 {
11  namespace connections
12  {
16 
22  {
23  public:
24  static constexpr const char* TYPE = "TCP";
25 
26  TcpConnection() = default;
27  TcpConnection(const std::string& hostname, uint16_t port);
28  ~TcpConnection() override;
29 
30  TcpConnection(const TcpConnection&) = delete;
31  TcpConnection& operator=(const TcpConnection&) = delete;
32 
33  bool recvFromDevice(uint8_t* buffer, size_t max_length, unsigned int wait_time_ms, size_t* length_out, EmbeddedTimestamp* timestamp_out) override;
34  bool sendToDevice(const uint8_t* data, size_t length) override;
35 
36  bool isConnected() const override;
37  bool connect() override;
38  bool disconnect() override;
39 
40  void connectionInfo(std::string& host_name, uint32_t& port) const
41  {
42  host_name = mHostname;
43  port = mPort;
44  };
45 
46  private:
47  tcp_socket mSocket;
48  std::string mHostname;
49  uint16_t mPort = 0;
50 
51  public:
52  const char* interfaceName() const override { return mHostname.c_str(); }
53  uint32_t parameter() const override { return mPort; }
54  };
55 
58  } // namespace microstrain
59 } // namespace connections
microstrain::connections::TcpConnection::recvFromDevice
bool recvFromDevice(uint8_t *buffer, size_t max_length, unsigned int wait_time_ms, size_t *length_out, EmbeddedTimestamp *timestamp_out) override
Receives bytes from the device.
Definition: tcp_connection.cpp:67
microstrain::connections::TcpConnection::sendToDevice
bool sendToDevice(const uint8_t *data, size_t length) override
Sends bytes to the device.
Definition: tcp_connection.cpp:77
microstrain::connections::TcpConnection::parameter
uint32_t parameter() const override
Definition: tcp_connection.hpp:53
microstrain::connections::TcpConnection::TYPE
static constexpr const char * TYPE
Definition: tcp_connection.hpp:24
microstrain::connections::TcpConnection::isConnected
bool isConnected() const override
Check if the socket is connected.
Definition: tcp_connection.cpp:39
microstrain::connections::TcpConnection::disconnect
bool disconnect() override
Disconnect from the socket.
Definition: tcp_connection.cpp:58
microstrain::connections::TcpConnection::connectionInfo
void connectionInfo(std::string &host_name, uint32_t &port) const
Definition: tcp_connection.hpp:40
microstrain::connections::TcpConnection::connect
bool connect() override
Connect to the socket.
Definition: tcp_connection.cpp:47
microstrain::connections::TcpConnection::operator=
TcpConnection & operator=(const TcpConnection &)=delete
connection.hpp
microstrain::connections::TcpConnection
Can be used on Windows, OSX, or linux to communicate with a MIP device over TCP.
Definition: tcp_connection.hpp:21
tcp_socket
Definition: tcp_socket.h:35
microstrain::connections::TcpConnection::interfaceName
const char * interfaceName() const override
Definition: tcp_connection.hpp:52
microstrain::EmbeddedTimestamp
C::microstrain_embedded_timestamp EmbeddedTimestamp
Definition: embedded_time.hpp:9
microstrain::connections::TcpConnection::TcpConnection
TcpConnection()=default
microstrain::Connection
Represents a type of connection.
Definition: connection.hpp:24
microstrain::connections::TcpConnection::~TcpConnection
~TcpConnection() override
Closes the underlying TCP socket.
Definition: tcp_connection.cpp:30
microstrain
Definition: embedded_time.h:8
tcp_socket.h