client

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 11 Imported by: 3

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

View Source
const (
	PowerStatusOff     = PowerStatus("0")
	PowerStatusOn      = PowerStatus("1")
	PowerStatusStandby = PowerStatus("2")
)
View Source
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

func Open(address string) (*Conn, error)

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

func (c *Conn) BandDown(ctx context.Context) error

BandDown switches to the next band downwards on the connected radio and the currently selected VFO.

func (*Conn) BandSelect added in v0.2.4

func (c *Conn) BandSelect(ctx context.Context, band bandplan.BandName) error

BandSelect switches to the given band on the connected radio and the currently selected VFO.

func (*Conn) BandUp

func (c *Conn) BandUp(ctx context.Context) error

BandUp switches to the next band upwards on the connected radio and the currently selected VFO.

func (*Conn) Close

func (c *Conn) Close()

Close the client connection.

func (*Conn) Closed

func (c *Conn) Closed() bool

Closed indicates if this connection is closed.

func (*Conn) Frequency

func (c *Conn) Frequency(ctx context.Context) (Frequency, error)

Frequency returns the current frequency in Hz of the connected radio on the currently selected VFO.

func (*Conn) IsPolling

func (c *Conn) IsPolling() bool

IsPolling indicates if this connection is polling the rigctld server periodically.

func (*Conn) ModeAndPassband

func (c *Conn) ModeAndPassband(ctx context.Context) (Mode, Frequency, error)

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

func (c *Conn) MorseSpeed(ctx context.Context) (float64, error)

MorseSpeed returns the current morse speed setting of the connected radio in wpm.

func (*Conn) PTT

func (c *Conn) PTT(ctx context.Context) (PTT, error)

PTT returns the current PTT state of the connected radio.

func (*Conn) PowerLevel

func (c *Conn) PowerLevel(ctx context.Context) (float64, error)

PowerLevel returns the current power level setting of the connected radio.

func (*Conn) PowerOff

func (c *Conn) PowerOff(ctx context.Context) error

PowerOff sets the power status of the connected radio to PowerStatusOff.

func (*Conn) PowerOn

func (c *Conn) PowerOn(ctx context.Context) error

PowerOn sets the power status of the connected radio to PowerStatusOn.

func (*Conn) PowerStandby

func (c *Conn) PowerStandby(ctx context.Context) error

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

func (c *Conn) RemovePolls(commands ...protocol.Command)

Remove the poll requests with the given command from the list of poll requests.

func (*Conn) SendMorse added in v0.2.0

func (c *Conn) SendMorse(ctx context.Context, text string) error

SendMorse sends the given text as morse code through the connected radio.

func (*Conn) Set

func (c *Conn) Set(ctx context.Context, longCommandName string, args ...string) error

Set executes the given hamlib set command with the given parameters.

func (*Conn) SetFrequency

func (c *Conn) SetFrequency(ctx context.Context, frequency Frequency) error

SetFrequency to the given frequency in Hz on the connected radio and the currently selected VFO.

func (*Conn) SetModeAndPassband

func (c *Conn) SetModeAndPassband(ctx context.Context, mode Mode, passband Frequency) error

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

func (c *Conn) SetMorseSpeed(ctx context.Context, wpm int) error

SetMorseSpeed sets the morse speed of the connected radio in wpm.

func (*Conn) SetPTT

func (c *Conn) SetPTT(ctx context.Context, ptt PTT) error

SetPTT sets the PTT of the connected radio.

func (*Conn) SetPowerLevel

func (c *Conn) SetPowerLevel(ctx context.Context, powerLevel float64) error

SetPowerLevel sets the power level of the connected radio.

func (*Conn) SetVFO

func (c *Conn) SetVFO(ctx context.Context, vfo VFO) error

SetVFO to the given VFO on 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) StopMorse added in v0.2.0

func (c *Conn) StopMorse(ctx context.Context) error

StopMorse stops the current morse code transmission.

func (*Conn) StopPolling

func (c *Conn) StopPolling()

StopPolling stops the polling loop.

func (*Conn) SwitchToBand

func (c *Conn) SwitchToBand(ctx context.Context, band bandplan.Band) error

SwitchToBand switches to the given frequency band on the connected radio and the currently selected VFO.

func (*Conn) VFO

func (c *Conn) VFO(ctx context.Context) (VFO, error)

VFO returns the currently selected VFO of the connected radio.

func (*Conn) WhenClosed

func (c *Conn) WhenClosed(f func())

WhenClosed will call the given callback asynchronously as soon as this connection is closed.

type Frequency

type Frequency = hamradio.Frequency

Frequency in Hz

type Mode

type Mode string

Mode represents the mode of the connected radio.

func (Mode) ToBandplanMode

func (m Mode) ToBandplanMode() bandplan.Mode

ToBandplanMode maps this Mode value to the type system of the bandplan package.

type PTT

type PTT string
const (
	PTTRx     PTT = "0"
	PTTTx     PTT = "1"
	PTTTxMic  PTT = "2"
	PTTTxData PTT = "3"
)

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

type ResponseHandler interface {
	Handle(protocol.Response)
}

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

type ResponseHandlerFunc func(protocol.Response)

ResponseHandlerFunc wraps a function matching the Handle signature to implement the ResponseHandler interface.

func (ResponseHandlerFunc) Handle

Handle the given response

type VFO

type VFO string

VFO is the currently selected VFO

const (
	VFOA    VFO = "VFOA"
	VFOB    VFO = "VFOB"
	VFOC    VFO = "VFOC"
	CurrVFO VFO = "currVFO"
	VFOVFO  VFO = "VFO"
	MEMVFO  VFO = "MEM"
	MainVFO VFO = "Main"
	SubVFO  VFO = "Sub"
	TXVFO   VFO = "TX"
	RXVFO   VFO = "RX"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL