Class TcpTransport

Inheritance Relationships

Base Type

Class Documentation

class TcpTransport : public flir_ptu_driver::Transport

TCP/IP implementation of the PTU Transport interface.

Establishes a blocking IPv4 TCP connection to a FLIR PTU’s network port (typically 4000) and exposes the line-oriented byte stream expected by PTU. Intended as a drop-in replacement for SerialTransport when the unit is reached over Ethernet rather than RS-232.

Public Functions

TcpTransport(const std::string &host, int port)

Construct a TCP transport for a PTU at host : port.

The socket is not opened until open() is called.

Parameters:
  • host – Hostname or dotted-quad IPv4 address of the PTU.

  • port – TCP port the PTU is listening on (typically 4000).

~TcpTransport() override

Closes the socket if still open and releases any resources.

virtual bool open() override

Resolve the host and open a TCP connection to the PTU.

Returns:

true if the connection was established, false on error.

virtual void close() override

Close the socket. Safe to call when already closed.

virtual bool isOpen() const override
Returns:

true while the underlying socket is connected.

virtual void write(const std::string &data) override

Send raw bytes to the PTU.

Parameters:

data – Bytes to write; sent as-is with no framing or escaping.

virtual std::string readline(size_t max_len = 255, char eol = '\n') override

Read a single line terminated by eol from the PTU.

Blocks until either a terminator is seen, max_len bytes have been accumulated, or the socket reports an error. The returned string includes the terminator when one was received.

Parameters:
  • max_len – Maximum number of bytes to accumulate before returning.

  • eol – Byte that delimits a line.

virtual std::string read(size_t size) override

Read exactly size bytes from the socket.

Blocks until the requested count has been read or the socket is closed.

virtual size_t available() override
Returns:

Number of bytes currently buffered and immediately readable.

virtual void flush() override

Discard any bytes pending in the receive buffer.

void drainBanner()

Consume the multi-line greeting banner emitted by the PTU on connect so that subsequent reads start at command responses.