ampctld communicates to a client through a TCP socket using text commands shared with ampctl. The protocol is simple, commands are sent to ampctld on one line and ampctld responds to get commands with the requested values, one per line, when successful, otherwise, it responds with one line "RPRT x", where 'x' is a negative number indicating the error code. Commands that do not return values respond with the line "RPRT x", where 'x' is '0' when successful, otherwise is a regative number indicating the error code. Each line is terminated with a newline '\n' character. This protocol is primarily for use by the NET ampctl (amplifier 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 "RPRT x" 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 ampctld directly through a TCP socket.
Keep in mind that Hamlib is BETA level software. While a lot of backend libraries lack complete amplifier 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.
Here is a summary of the supported options:
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.
Please note that the backend for the amplifier to be controlled, or the amplifier itself may not support some commands. In that case, the operation will fail with a Hamlib error code.
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, '\', to send a long command name.
Example (Perl): "print $socket "\\dump_caps\n";" to see what the amplifier's backend can do (Note: In Perl and many other languages a '\' will need to be escaped with a preceding '\' so that even though two backslash characters appear in the code, only one will be passed to ampctld. This is a possible bug, beware!).
Note: The backend for the amplifier to be controlled, or the amplifier 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.):
The Default Protocol is intended primarily for the communication between Hamlib library functions and ampctld ("NET ampctl", available using amplifier model '2').
The Extended Response Protocol is intended to be used with scripts or other programs interacting directly with ampctld as consistent feedback is provided.
Example set frequency and mode commands (Perl code (typed text shown in bold)):
print $socket "F 14250000\n"; print $socket "\\set_powerstat 1\n"; # escape leading '\'
A one line response will be sent as a reply to set commands, "RPRT x\n" where x is the Hamlib error code with '0' indicating success of the command.
Responses from ampctld 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 "RPRT x\n" is returned where x is the Hamlib error code.
Example get frequency (Perl code):
print $socket "f\n"; "14250000\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 "NET ampctl" (ampctl model 2) backend which allows applications already written for Hamlib's C API to take advantage of ampctld without the need of rewriting application code. An application's user can select amplifier model 2 ("NET ampctl") and then set amp_pathname to "localhost:4531" or other network host:port (set by the -T/-t options, respectively, above).
1. The command received by ampctld 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 "RPRT x\n" 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 amplifier 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. "Frequency: 14250000\n" when the command was prepended by '+'.
4. All commands received will be acknowledged by
ampctld
with records from rules 1 and 2. Records from rule 3 are only returned when
data values must be returned to the client.
4. All commands received will be acknowledged by ampctld 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 set_frequency command sent from the shell prompt (note the prepended '+'):
$ echo "+F 14250000" | nc -w 1 localhost 4531 set_freq: 14250000 RPRT 0
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 amplifier backend return value indicating success.
An example response to a get_freq query:
$ echo "+\get_freq" | nc -w 1 localhost 4531 get_freq: Frequency(Hz): 14250000 RPRT 0
In this case, as no value is passed to ampctld, the first line consists only of the long command name. The final line shows that the command was processed successfully by the amplifier backend.
Invoking the Extended Response Protocol requires prepending a command with a punctuation character. As shown in the examples above, prepending a '+' character to the command results in the responses being separated by a newline character ('\n'). Any other punctuation character recognized by the C ispunct() function except '\', '?', or '_' will cause that character to become the response separator and the entire response will be on one line.
Separator character summary:
For example, invoking a get_freq query with a leading ';' returns:
get_freq:;Frequency(Hz): 14250000;RPRT 0
Or, using the pipe character '|' returns:
get_freq:|Frequency(Hz): 14250000|RPRT 0
And a set_freq command prepended with a '|' returns:
set_freq: 14250000|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!
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 amplifier which is very useful for amplifier backend library development and may be requested by the developers.
$ ampctld -m 201 -r /dev/ttyUSB1 &
Start ampctld for an Elecraft KPA-1500 using COM2 on MS Windows:
$ ampctld -m 201 -r COM2
Connect to the already running ampctld and set the frequency to 14.266 MHz with a 1 second read timeout using the default protocol from the shell prompt:
$ echo "\set_freq 14266000" | nc -w 1 localhost 4531
Connect to a running ampctld with ampctl on the local host:
As ampctld does not need any greater permissions than ampctl, it is advisable to not start ampctld as "root" or another system user account in order to limit any vulnerability.
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 amplifier.
Report bugs to:
Hamlib Developer mailing list
Copyright © 2000-2010 Stephane Fillod
Copyright © 2000-2018 the Hamlib Group (various contributors)
Copyright © 2011-2020 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.