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