Documentation ¶
Overview ¶
Package client provides access to rigctld servers through the Hamlib net protocol (model #2).
Connect to a local rigctld server and retrieve the current frequency:
conn, err := client.Open("") if err != nil { log.Fatal(err) } defer conn.Close() frequency, err := conn.Frequency(context.Background()) if err != nil { log.Fatal(err) } log.Printf("current frequency: %.0fHz", frequency)
Poll the current frequency periodically:
onFrequency := func(f float64) { log.Printf("current frequency: %.0fHz", f) } conn, err := client.Open("") if err != nil { log.Fatal(err) } defer conn.Close() conn.StartPolling(500 * time.Millisecond, 100 * time.Millisecond, client.PollCommand(client.OnFrequency(onFrequency)), )
Index ¶
- Constants
- type Conn
- func (c *Conn) AddPolls(requests ...PollRequest)
- func (c *Conn) BandDown(ctx context.Context) error
- func (c *Conn) BandSelect(ctx context.Context, band bandplan.BandName) error
- func (c *Conn) BandUp(ctx context.Context) error
- func (c *Conn) Close()
- func (c *Conn) Closed() bool
- func (c *Conn) Frequency(ctx context.Context) (Frequency, error)
- func (c *Conn) IsPolling() bool
- func (c *Conn) ModeAndPassband(ctx context.Context) (Mode, Frequency, error)
- func (c *Conn) MorseSpeed(ctx context.Context) (float64, error)
- func (c *Conn) PTT(ctx context.Context) (PTT, error)
- func (c *Conn) PowerLevel(ctx context.Context) (float64, error)
- func (c *Conn) PowerOff(ctx context.Context) error
- func (c *Conn) PowerOn(ctx context.Context) error
- func (c *Conn) PowerStandby(ctx context.Context) error
- func (c *Conn) PowerStatus(ctx context.Context) (PowerStatus, error)
- func (c *Conn) RemovePolls(commands ...protocol.Command)
- func (c *Conn) SendMorse(ctx context.Context, text string) error
- func (c *Conn) Set(ctx context.Context, longCommandName string, args ...string) error
- func (c *Conn) SetFrequency(ctx context.Context, frequency Frequency) error
- func (c *Conn) SetModeAndPassband(ctx context.Context, mode Mode, passband Frequency) error
- func (c *Conn) SetMorseSpeed(ctx context.Context, wpm int) error
- func (c *Conn) SetPTT(ctx context.Context, ptt PTT) error
- func (c *Conn) SetPowerLevel(ctx context.Context, powerLevel float64) error
- func (c *Conn) SetVFO(ctx context.Context, vfo VFO) error
- func (c *Conn) StartPolling(interval time.Duration, timeout time.Duration, requests ...PollRequest) error
- func (c *Conn) StopMorse(ctx context.Context) error
- func (c *Conn) StopPolling()
- func (c *Conn) SwitchToBand(ctx context.Context, band bandplan.Band) error
- func (c *Conn) VFO(ctx context.Context) (VFO, error)
- func (c *Conn) WhenClosed(f func())
- type Frequency
- type Mode
- type PTT
- type PollRequest
- type PowerStatus
- type ResponseHandler
- func OnFrequency(callback func(Frequency)) (ResponseHandler, string)
- func OnModeAndPassband(callback func(Mode, Frequency)) (ResponseHandler, string)
- func OnMorseSpeed(callback func(int)) (ResponseHandler, string, string)
- func OnPTT(callback func(PTT)) (ResponseHandler, string)
- func OnPowerLevel(callback func(float64)) (ResponseHandler, string, string)
- func OnPowerStatus(callback func(PowerStatus)) (ResponseHandler, string)
- func OnVFO(callback func(VFO)) (ResponseHandler, string)
- type ResponseHandlerFunc
- type VFO
Constants ¶
const ( PowerStatusOff = PowerStatus("0") PowerStatusOn = PowerStatus("1") PowerStatusStandby = PowerStatus("2") )
const ( ModeNone = Mode("") ModeUSB = Mode("USB") ModeLSB = Mode("LSB") ModeCW = Mode("CW") ModeCWR = Mode("CWR") ModeRTTY = Mode("RTTY") ModeRTTYR = Mode("RTTYR") ModeAM = Mode("AM") ModeFM = Mode("FM") ModeWFM = Mode("WFM") ModeAMS = Mode("AMS") ModePKTLSB = Mode("PKTLSB") ModePKTUSB = Mode("PKTUSB") ModePKTFM = Mode("PKTFM") ModeECSSLSB = Mode("ECSSLSB") ModeECSSUSB = Mode("ECSSUSB") ModeFAX = Mode("FAX") ModeSAM = Mode("SAM") ModeSAL = Mode("SAL") ModeSAH = Mode("SAH") ModeDSB = Mode("DSB") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents the Hamlib client connection to a rigctld server.
func Open ¶
Open a client connection to the rigctld server at the given address. If address is empty, "localhost:4532" is used as default.
func (*Conn) AddPolls ¶
func (c *Conn) AddPolls(requests ...PollRequest)
AddPolls while polling is already active. If there is already a poll request with the given command in the list of poll requests, the new request replaces the old one.
func (*Conn) BandDown ¶
BandDown switches to the next band downwards on the connected radio and the currently selected VFO.
func (*Conn) BandSelect ¶ added in v0.2.4
BandSelect switches to the given band on the connected radio and the currently selected VFO.
func (*Conn) BandUp ¶
BandUp switches to the next band upwards on the connected radio and the currently selected VFO.
func (*Conn) Frequency ¶
Frequency returns the current frequency in Hz of the connected radio on the currently selected VFO.
func (*Conn) IsPolling ¶
IsPolling indicates if this connection is polling the rigctld server periodically.
func (*Conn) ModeAndPassband ¶
ModeAndPassband returns the current mode and passband (in Hz) setting of the connected radio on the currently selected VFO.
func (*Conn) MorseSpeed ¶ added in v0.2.0
MorseSpeed returns the current morse speed setting of the connected radio in wpm.
func (*Conn) PowerLevel ¶
PowerLevel returns the current power level setting of the connected radio.
func (*Conn) PowerStandby ¶
PowerStandby sets the power status of the connected radio to PowerStatusStandby.
func (*Conn) PowerStatus ¶
func (c *Conn) PowerStatus(ctx context.Context) (PowerStatus, error)
PowerStatus returns the current power status of the connected radio.
func (*Conn) RemovePolls ¶
Remove the poll requests with the given command from the list of poll requests.
func (*Conn) SendMorse ¶ added in v0.2.0
SendMorse sends the given text as morse code through the connected radio.
func (*Conn) SetFrequency ¶
SetFrequency to the given frequency in Hz on the connected radio and the currently selected VFO.
func (*Conn) SetModeAndPassband ¶
SetModeAndPassband sets the mode and the passband (in Hz) of the connected radio on the currently selected VFO.
func (*Conn) SetMorseSpeed ¶ added in v0.2.0
SetMorseSpeed sets the morse speed of the connected radio in wpm.
func (*Conn) SetPowerLevel ¶
SetPowerLevel sets the power level of the connected radio.
func (*Conn) StartPolling ¶
func (c *Conn) StartPolling(interval time.Duration, timeout time.Duration, requests ...PollRequest) error
StartPolling the connected rigctld server with the given interval and timeout and the given set of requests. Poll requests can be added and removed on demand using AddPolls and RemovePolls.
func (*Conn) SwitchToBand ¶
SwitchToBand switches to the given frequency band on the connected radio and the currently selected VFO.
func (*Conn) WhenClosed ¶
func (c *Conn) WhenClosed(f func())
WhenClosed will call the given callback asynchronously as soon as this connection is closed.
type Mode ¶
type Mode string
Mode represents the mode of the connected radio.
func (Mode) ToBandplanMode ¶
ToBandplanMode maps this Mode value to the type system of the bandplan package.
type PollRequest ¶
type PollRequest struct { Command protocol.Command Args []string Handler ResponseHandler }
PollRequest contains a command with arguments that should be send perodically to a rigctld server. The given handler is used to handle the responses from the rigctld server.
func PollCommand ¶
func PollCommand(handler ResponseHandler, command string, args ...string) PollRequest
PollCommand creates a PollRequest from the given handler, command name and arguments.
func PollCommandFunc ¶
func PollCommandFunc(f func(protocol.Response), command string, args ...string) PollRequest
PollCommandFunc creates a PollRequest from the given handler function, command name and arguments.
type PowerStatus ¶
type PowerStatus string
PowerStatus represents the power status of the connected radio.
type ResponseHandler ¶
ResponseHandler is a callback to handle a response.
func OnFrequency ¶
func OnFrequency(callback func(Frequency)) (ResponseHandler, string)
OnFrequency wraps the given callback function into the ResponseHandler interface and translates the generic response to a Frequency value.
func OnModeAndPassband ¶
func OnModeAndPassband(callback func(Mode, Frequency)) (ResponseHandler, string)
OnModeAndPassband wraps the given callback function into the ResponseHandler interface and translates the generic response to mode and passband.
func OnMorseSpeed ¶ added in v0.2.0
func OnMorseSpeed(callback func(int)) (ResponseHandler, string, string)
OnMorseSpeed wraps the given callback function into the ResponseHandler interface and translates the generic response to wpm.
func OnPTT ¶
func OnPTT(callback func(PTT)) (ResponseHandler, string)
OnPTT wraps the given callback function into the ResponseHandler interface and translates the generic response to PTT state.
func OnPowerLevel ¶
func OnPowerLevel(callback func(float64)) (ResponseHandler, string, string)
OnPowerLevel wraps the given callback function into the ResponseHandler interface and translates the generic response to power level.
func OnPowerStatus ¶
func OnPowerStatus(callback func(PowerStatus)) (ResponseHandler, string)
OnPowerStatus wraps the given callback function into the ResponseHandler interface and translates the generic response into a power status.
func OnVFO ¶
func OnVFO(callback func(VFO)) (ResponseHandler, string)
OnVFO wraps the given callback function into the ResponseHandler interface and translates the generic response to a VFO value.
type ResponseHandlerFunc ¶
ResponseHandlerFunc wraps a function matching the Handle signature to implement the ResponseHandler interface.
func (ResponseHandlerFunc) Handle ¶
func (f ResponseHandlerFunc) Handle(r protocol.Response)
Handle the given response