class

Kozai::Hamlib

Inherits Reference < Object

The line-oriented TCP protocol shared by hamlib's rotctld and rigctld.

Both daemons speak the same shape of conversation: send one line, read one or more lines back, where a command that returns no data answers RPRT 0 and a failure answers RPRT with a negative error number.

NOTE: this talks to hamlib over a socket rather than linking libhamlib. That is a deliberate constraint of this project — no C libraries, no FFI, no lib blocks anywhere in src/ — and it turns out to be the better design regardless. rotctld already exists on every station that has hamlib, it already handles the serial port and the dozens of rotator models, and a crash in a rotator driver takes down a separate process instead of the prediction daemon. The cost is a socket; the gain is that this program has no build-time dependency on anyone's C library version.

:nodoc:

Constants

DEFAULT_TIMEOUT = 3.seconds

How long to wait for a daemon to answer before giving up.

Constructors

new(host : String, port : Int32, timeout : Time::Span = DEFAULT_TIMEOUT)
Source

Instance methods

check(reply : String, command : String) : Nil

Raises unless reply is hamlib's success status.

NOTE: RPRT 0 means success; anything else is a negative hamlib error code. Some builds answer a successful set command with an empty line instead, which is accepted rather than treated as a fault.

Source
close

Closes the connection, ignoring any error while doing so.

Source
command(command : String) : Nil

Sends a command that returns only a status line.

Raises IO::Error if the daemon reports a failure.

Source
connect

Opens the connection if it is not already open.

Raises IO::Error or Socket::Error if the daemon cannot be reached; the callers in Rotator and Radio translate those into their own ConnectionError.

Source
connected?

Whether a socket is currently open.

Source
host

Host the daemon is listening on.

Source
port

Port the daemon is listening on.

Source
request(command : String, lines : Int32 = 1) : Array(String)

Sends command and reads lines lines of response.

On any socket error the connection is dropped so that the next call reconnects rather than reusing a half-dead socket.

Source
timeout

Read and connect timeout.

Source