rotctld - TCP rotator control daemon
The rotctld program is a rotator control daemon that handles client requests via TCP sockets. This allows multiple user programs to share one rotator (this needs more development). Multiple rotators can be controlled on different TCP ports by use of multiple rotctld processes. The syntax of the commands are the same as rotctl(1). It is hoped that rotctld will be especially useful for client authors using languages such as Perl, Python, PHP, and others.
rotctld communicates to a client through a TCP socket using text commands shared with rotctl. The protocol is simple, commands are sent to rotctld on one line and rotctld responds to \(lqget\(rq commands with the requested values, one per line, when successful, otherwise, it responds with one line \(lqRPRT x\(rq, where \(oqx\(cq is a negative number indicating the error code. Commands that do not return values respond with the line \(lqRPRT x\(rq, where \(oqx\(cq is \(oq0\(cq when successful, otherwise is a regative number indicating the error code. Each line is terminated with a newline \(oq\n\(cq character. This protocol is primarily for use by the NET rotctl (rotator model 2) backend.
A separate Extended Response Protocol extends the above behavior by echoing the received command string as a header, any returned values as a key: value pair, and the \(lqRPRT x\(rq string as the end of response marker which includes the Hamlib success or failure value. See the PROTOCOL section for details. Consider using this protocol for clients that will interact with rotctld directly through a TCP socket.
Keep in mind that Hamlib is BETA level software. While a lot of backend libraries lack complete rotator support, the basic functions are usually well supported.
Please report bugs and provide feedback at the e-mail address given in the BUGS section below. Patches and code enhancements sent to the same address are welcome.
This program follows the usual GNU command line syntax. Short options that take an argument may have the value follow immediately or be separated by a space. Long options starting with two dashes (\(oq-\(cq) require an \(oq=\(cq between the option and any argument.
Note: Some options may not be implemented by a given backend and will return an error. This is most likely to occur with the --set-conf and --show-conf options.
Here is a summary of the supported options:
|Select rotator model number.|
|See model list (use \(lqrotctld -l\(rq).|
|Note: rotctl (or third party software using the C API) will use rotator model 2 for NET rotctl (this model number is not used for rotctld even though it shows in the model list).|
|Use device as the file name of the port connected to the rotator.|
|Often a serial port, but could be a USB to serial adapter. Typically /dev/ttyS0, /dev/ttyS1, /dev/ttyUSB0, etc. on Linux, COM1, COM2, etc. on MS Windows. The BSD flavors and Mac OS/X have their own designations. See your system’s documentation.|
|Set serial speed to baud rate.|
|Uses maximum serial speed from rotator backend capabilities as the default.|
|Use IPADDR as the listening IP address.|
|The default is ANY.|
|Use number as the TCP listening port.|
|The default is 4533.|
|Note: As rigctld\(aqs default port is 4532, it is advisable to use odd numbered ports for rotctld, e.g. 4533, 4535, 4537, etc.|
|List all configuration parameters for the rotator defined with -m above.|
|Set rotator configuration parameter(s), e.g. stop_bits=2.|
|Use the -L option above for a list of configuration parameters for a given model number.|
|Dump capabilities for the rotator defined with -m above and exit.|
|List all rotator model numbers defined in Hamlib and exit.|
|The list is sorted by model number.|
|Note: In Linux the list can be scrolled back using Shift-PageUp/Shift-PageDown, or using the scrollbars of a virtual terminal in X or the cmd window in Windows. The output can be piped to more(1) or less(1), e.g. \(lqrotctl -l | more\(rq.|
|Set verbose mode, cumulative (see DIAGNOSTICS below).|
|Enable time stamps for the debug messages.|
|Use only in combination with the -v option as it generates no output on its own.|
|Show a summary of these options and exit.|
|Show version of rotctld and exit.|
Be aware that the backend for the rotator to be controlled, or the rotator itself may not support some commands. In that case, the operation will fail with a Hamlib error code.
Commands can be sent over the TCP socket either as a single char, or as a long command name plus the value(s) space separated on one \(oq\n\(cq terminated line. See PROTOCOL.
Since most of the Hamlib operations have a set and a get method, an upper case letter will be used for set methods whereas the corresponding lower case letter refers to the get method. Each operation also has a long name; prepend a backslash, \(oq\\(cq, to send a long command name.
Example (Perl): \(lqprint $socket "\\dump_caps\n";\(rq to see what the rotator’s backend can do (Note: In Perl and many other languages a \(oq\\(cq will need to be escaped with a preceding \(oq\\(cq so that even though two backslash characters appear in the code, only one will be passed to rotctld. This is a possible bug, beware!).
Note: The backend for the rotator to be controlled, or the rotator itself may not support some commands. In that case, the operation will fail with a Hamlib error message.
Here is a summary of the supported commands (In the case of set commands the quoted italicized string is replaced by the value in the description. In the case of get commands the quoted italicized string is the key name of the value returned.):
|P, set_pos \(aqAzimuth\(aq \(aqElevation\(aq|
|\(aqAzimuth\(aq and \(aqElevation\(aq are floating point values.|
|P 163.0 41.0|
|Note: If the rotator does not support setting elevation (most do not) supply \(lq0.0\(rq for \(aqElevation\(aq.|
|\(aqAzimuth\(aq and \(aqElevation\(aq are returned as double precision floating point values.|
|M, move \(aqDirection\(aq \(aqSpeed\(aq|
|Move the rotator in a specific direction at the given rate.|
|\(aqDirection\(aq is an integer defined as \(oq2\(cq = Up, \(oq4\(cq = Down, \(oq8\(cq = Left, and \(oq16\(cq = Right.|
|\(aqSpeed\(aq is an integer between 1 and 100.|
|Note: Not all backends that implement the move command use the Speed value. At this time only the gs232a utilizes the Speed parameter.|
|S, stop||Stop the rotator.|
|K, park||Park the rotator.|
|C, set_conf \(aqToken\(aq \(aqValue\(aq|
|Set a configuration parameter.|
|\(aqToken\(aq is a string; see the -C option and the -L output.|
|\(aqValue\(aq is a string of up to 20 characters.|
|R, reset \(aqReset\(aq|
|Reset the rotator.|
|\(aqReset\(aq accepts an integer value of \(oq1\(cq for \(lqReset All\(rq.|
|Get misc information about the rotator.|
|Returns \(aqInfo\(aq \(lqModel Name\(rq.|
|w, send_cmd \(aqCmd\(aq|
|Send a raw command string to the rotator.|
|ASCII CR is appended automatically at the end of the command for text protocols. For binary protocols, enter hexadecimal values as \(lq\0xAA\0xBB\(rq.|
These commands offer conversions of Degrees Minutes Seconds to other formats, Maidenhead square locator conversions and distance and azimuth conversions.
|L, lonlat2loc \(aqLongitude\(aq \(aqLatitude\(aq \(aqLoc Len\(aq|
|Returns the Maidenhead \(aqLocator\(aq for the given \(aqLongitude\(aq and \(aqLatitude\(aq.|
|\(aqLongitude\(aq and \(aqLatitude\(aq are floating point values.|
|\(aqLoc Len\(aq is the precision of the returned square and should be an even numbered integer value between 2 and 12.|
|L -170.0 -85.0 12|
|l, loc2lonlat \(aqLocator\(aq|
|Returns \(aqLongitude\(aq and \(aqLatitude\(aq in decimal degrees at the approximate center of the requested Maidenhead grid square.|
|\(aqLocator\(aq can be from 2 to 12 characters in length.|
|West longitude is expressed as a negative value.|
|South latitude is expressed as a negative value.|
|Longitude: -169.999983 Latitude: -84.999991|
|Note: Despite the use of double precision variables internally, some rounding error occurs.|
|D, dms2dec \(aqDegrees\(aq \(aqMinutes\(aq \(aqSeconds\(aq \(aqS/W\(aq|
|Returns \(aqDec Degrees\(aq, a signed floating point value.|
|\(aqDegrees\(aq and \(aqMinutes\(aq are integer values.|
|\(aqSeconds\(aq is a floating point value.|
|\(aqS/W\(aq is a flag with \(oq1\(cq indicating South latitude or West longitude and \(oq0\(cq North or East (the flag is needed as computers don’t recognize a signed zero even though only the \(aqDegrees\(aq value is typically signed in DMS notation).|
|d, dec2dms \(aqDec Degrees\(aq|
|Returns \(aqDegrees\(aq \(aqMinutes\(aq \(aqSeconds\(aq \(aqS/W\(aq.|
|Values are as in dms2dec above.|
|E, dmmm2dec \(aqDegrees\(aq \(aqDec Minutes\(aq \(aqS/W\(aq|
|Returns \(aqDec Degrees\(aq, a signed floating point value.|
|\(aqDegrees\(aq is an integer value.|
|\(aqDec Minutes\(aq is a floating point value.|
|\(aqS/W\(aq is a flag as in dms2dec above.|
|e, dec2dmmm \(aqDec Deg\(aq|
|Returns \(aqDegrees\(aq \(aqMinutes\(aq \(aqS/W\(aq.|
|Values are as in dmmm2dec above.|
|B, qrb \(aqLon 1\(aq \(aqLat 1\(aq \(aqLon 2\(aq \(aqLat 2\(aq|
|Returns \(aqDistance\(aq and \(aqAzimuth\(aq.|
|\(aqDistance\(aq is in km.|
|\(aqAzimuth\(aq is in degrees.|
|Supplied Lon/Lat values are signed floating point numbers.|
|A, a_sp2a_lp \(aqShort Path Deg\(aq|
|Returns \(aqLong Path Deg\(aq.|
|Both the supplied argument and returned value are floating point values within the range of 0.00 to 360.00.|
|Note: Supplying a negative value will return an error message.|
|a, d_sp2d_lp \(aqShort Path km\(aq|
|Returns \(aqLong Path km\(aq.|
|Both the supplied argument and returned value are floating point values.|
|Pause for the given whole (integer) number of \(aqSeconds\(aq before sending the next command to the rotator.|
There are two protocols in use by rotctld, the Default Protocol and the Extended Response Protocol.
The Default Protocol is intended primarily for the communication between Hamlib library functions and rotctld (\(lqNET rotctl\(rq, available using rotator model \(oq2\(cq).
The Extended Response Protocol is intended to be used with scripts or other programs interacting directly with rotctld as consistent feedback is provided.
The Default Protocol is intentionally simple. Commands are entered on a single line with any needed values. In practice, reliable results are obtained by terminating each command string with a newline character, \(oq\n\(cq.
Example set position (Perl code):
print $socket "P 135 10\n";
print $socket "\\set_pos 135 10\n"; # escape leading \(oq\\(cq
A one line response will be sent as a reply to set commands, \(lqRPRT x\n\(rq where x is the Hamlib error code with \(oq0\(cq indicating success of the command.
Responses from rotctld get commands are text values and match the same tokens used in the set commands. Each value is returned on its own line. On error the string \(lqRPRT x\n\(rq is returned where x is the Hamlib error code.
Example get position (Perl code):
print $socket "p\n";
Most get functions return one to three values. A notable exception is the dump_caps command which returns many lines of key:value pairs.
This protocol is primarily used by the \(lqNET rotctl\(rq (rotctl model 2) backend which allows applications already written for Hamlib’s C API to take advantage of rotctld without the need of rewriting application code. An application’s user can select rotator model 2 (\(lqNET rotctl\(rq) and then set rot_pathname to \(lqlocalhost:4533\(rq or other network host:port (set by the -T/-t options, respectively, above).
Extended Response Protocol
The Extended Response protocol adds several rules to the strings returned by rotctld and adds a rule for the command syntax.
For example, invoking a get_pos query with a leading \(oq;\(cq returns:
1. The command received by rotctld is echoed with its long command name followed by the value(s) (if any) received from the client terminated by the specified response separator as the first record of the response.
2. The last record of each block is the string \(lqRPRT x\n\(rq where x is the numeric return value of the Hamlib backend function that was called by the command.
3. Any records consisting of data values returned by the rotator backend are prepended by a string immediately followed by a colon then a space and then the value terminated by the response separator, e.g. \(lqAzimuth: 90.000000\n\(rq when the command was prepended by \(oq+\(cq.
4. All commands received will be acknowledged by rotctld with records from rules 1 and 2. Records from rule 3 are only returned when data values must be returned to the client.
An example response to a P command sent from the shell prompt (note the prepended \(oq+\(cq):
$ echo "+P 90 45" | nc -w 1 localhost 4533
set_pos: 90 45
set_pos: 90 45
In this case the long command name and values are returned on the first line and the second line contains the end of block marker and the numeric rotor backend return value indicating success.
An example response to a get_pos query:
$ echo "+\get_pos" | nc -w 1 localhost 4533
|Note: The \(oq\\(cq is still required for the long command name even with the ERP character.|
|In this case, as no value is passed to rotctld, the first line consists only of the long command name. The final line shows that the command was processed successfully by the rotor backend.|
|Invoking the Extended Response Protocol requires prepending a command with a punctuation character. As shown in the examples above, prepending a \(oq+\(cq character to the command results in the responses being separated by a newline character (\(oq\n\(cq). Any other punctuation character recognized by the C ispunct() function except \(oq\\(cq, \(oq?\(cq, or \(oq_\(cq will cause that character to become the response separator and the entire response will be on one line.|
|Separator character summary:|
|\(oq+\(cq||Each record of the response is appended with a newline (\(oq\n\(cq).|
|\(oq;\(cq, \(oq|\(cq, or, \(oq,\(cq|
|Each record of the response is appended by the given character resulting in entire response on one line.|
|These are common record separators for text representations of spreadsheet data, etc.|
|\(oq?\(cq||Reserved for help in rotctl.|
|\(oq_\(cq||Reserved for get_info short command|
|\(oq#\(cq||Reserved for comments when reading a command file script.|
|Note: Other punctuation characters have not been tested! Use at your own risk.|
get_pos:;Azimuth: 90.000000;Elevation: 45.000000;RPRT 0
Or, using the pipe character \(oq|\(cq returns:
get_pos:|Azimuth: 90.000000|Elevation: 45.000000|RPRT 0
And a set_pos command prepended with a \(oq|\(cq returns:
set_pos: 135 22.5|RPRT 0
Such a format will allow reading a response as a single event using a preferred response separator. Other punctuation characters have not been tested!
All commands with the exception of set_conf have been tested with the Extended Response protocol and the included testrotctld.pl Perl script.
The -v, --verbose option allows different levels of diagnostics to be output to stderr and correspond to -v for BUG, -vv for ERR, -vvv for WARN, -vvvv for VERBOSE, or -vvvvv for TRACE.
A given verbose level is useful for providing needed debugging information to the email address below. For example, TRACE output shows all of the values sent to and received from the radio which is very useful for radio backend library development and may be requested by the developers.
Start rotctld for a Hy-Gain Ham IV rotor with the Idiom Press RotorEZ board installed using a USB-to-serial adapter and backgrounding:
$ rotctld -m 401 -r /dev/ttyUSB1 &
Start rotctld for RotorEZ using COM2 on Win32:$ rotctl -m 401 -r COM2
Connect to the already running rotctld, and set position to 135.0 degrees azimuth and 30.0 degrees elevation with a 1 second read timeout from the shell prompt:
$ echo "\set_pos 135.0 30.0" | nc -w 1 localhost 4533
Connect to a running rotctld with rotctl on the local host:
$ rotctl -m 2
No authentication whatsoever; DO NOT leave this TCP port open wide to the Internet. Please ask if stronger security is needed or consider using a Secure Shell (ssh(1)) tunnel.
As rotctld does not need any greater permissions than rotctl, it is advisable to not start rotctld as \(lqroot\(rq or another system user account in order to limit any vulnerability.
The daemon is not detaching and backgrounding itself.
No method to exit the daemon so the kill(1) command must be used to terminate it.
Multiple clients using the daemon may experience contention with the connected rotator.
Report bugs to:
Hamlib Developer mailing list
This file is part of Hamlib, a project to develop a library that simplifies radio and rotator control functions for developers of software primarily of interest to radio amateurs and those interested in radio communications.
Copyright © 2000-2009 Stephane Fillod
Copyright © 2000-2018 the Hamlib Group (various contributors)
Copyright © 2011-2018 Nate Bargmann
Copyright © 2000-2018 the Hamlib Group (various contributors)
Copyright © 2011-2018 Nate Bargmann
This is free software; see the file COPYING for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Links to the Hamlib Wiki, Git repository, release archives, and daily snapshot archives: