protocol

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 12 Imported by: 4

Documentation

Overview

Package protocol defines and parses the rigctl commands.

See https://github.com/Hamlib/Hamlib/blob/tests/rigctl_parse.c static struct test_table for the official list of commands.

Index

Constants

View Source
const NoCommand = CommandKey("")

Variables

View Source
var (
	ShortCommands = make(map[byte]Command)
	LongCommands  = make(map[string]Command)
	Commands      = []Command{
		{
			Short:                'F',
			Long:                 "set_freq",
			Args:                 1,
			InvalidatesCommand:   "get_freq",
			SupportsExtendedMode: true,
		},
		{
			Short:                'f',
			Long:                 "get_freq",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'M',
			Long:                 "set_mode",
			Args:                 2,
			InvalidatesCommand:   "get_mode",
			SupportsExtendedMode: true,
		},
		{
			Short:                'm',
			Long:                 "get_mode",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'V',
			Long:                 "set_vfo",
			Args:                 1,
			InvalidatesCommand:   "get_vfo",
			SupportsExtendedMode: true,
		},
		{
			Short:                'v',
			Long:                 "get_vfo",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'J',
			Long:                 "set_rit",
			Args:                 1,
			InvalidatesCommand:   "get_rit",
			SupportsExtendedMode: true,
		},
		{
			Short:                'j',
			Long:                 "get_rit",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'Z',
			Long:                 "set_xit",
			Args:                 1,
			InvalidatesCommand:   "get_xit",
			SupportsExtendedMode: true,
		},
		{
			Short:                'z',
			Long:                 "get_xit",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'T',
			Long:                 "set_ptt",
			Args:                 1,
			InvalidatesCommand:   "get_ptt",
			SupportsExtendedMode: true,
		},
		{
			Short:                't',
			Long:                 "get_ptt",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                0x8b,
			Long:                 "get_dcd",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'R',
			Long:                 "set_rptr_shift",
			Args:                 1,
			InvalidatesCommand:   "get_rptr_shift",
			SupportsExtendedMode: true,
		},
		{
			Short:                'r',
			Long:                 "get_rptr_shift",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'O',
			Long:                 "set_rptr_offs",
			Args:                 1,
			InvalidatesCommand:   "get_rptr_offs",
			SupportsExtendedMode: true,
		},
		{
			Short:                'o',
			Long:                 "get_rptr_offs",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'C',
			Long:                 "set_ctcss_tone",
			Args:                 1,
			InvalidatesCommand:   "get_ctcss_tone",
			SupportsExtendedMode: true,
		},
		{
			Short:                'c',
			Long:                 "get_ctcss_tone",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'D',
			Long:                 "set_dcs_code",
			Args:                 1,
			InvalidatesCommand:   "get_dcs_code",
			SupportsExtendedMode: true,
		},
		{
			Short:                'd',
			Long:                 "get_dcs_code",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                0x90,
			Long:                 "set_ctcss_sql",
			Args:                 1,
			InvalidatesCommand:   "get_ctcss_sql",
			SupportsExtendedMode: true,
		},
		{
			Short:                0x91,
			Long:                 "get_ctcss_sql",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                0x92,
			Long:                 "set_dcs_sql",
			Args:                 1,
			InvalidatesCommand:   "get_dcs_sql",
			SupportsExtendedMode: true,
		},
		{
			Short:                0x93,
			Long:                 "get_dcs_sql",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'I',
			Long:                 "set_split_freq",
			Args:                 1,
			InvalidatesCommand:   "get_split_freq",
			SupportsExtendedMode: true,
		},
		{
			Short:                'i',
			Long:                 "get_split_freq",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'X',
			Long:                 "set_split_mode",
			Args:                 2,
			InvalidatesCommand:   "get_split_mode",
			SupportsExtendedMode: true,
		},
		{
			Short:                'x',
			Long:                 "get_split_mode",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'K',
			Long:                 "set_split_freq_mode",
			Args:                 3,
			InvalidatesCommand:   "get_split_freq_mode",
			SupportsExtendedMode: true,
		},
		{
			Short:                'k',
			Long:                 "get_split_freq_mode",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'S',
			Long:                 "set_split_vfo",
			Args:                 2,
			InvalidatesCommand:   "get_split_vfo",
			SupportsExtendedMode: true,
		},
		{
			Short:                's',
			Long:                 "get_split_vfo",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'N',
			Long:                 "set_ts",
			Args:                 1,
			InvalidatesCommand:   "get_ts",
			SupportsExtendedMode: true,
		},
		{
			Short:                'n',
			Long:                 "get_ts",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'U',
			Long:                 "set_func",
			Args:                 2,
			InvalidatesCommand:   "get_func",
			HasSubCommand:        true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'u',
			Long:                 "get_func",
			Args:                 1,
			HasSubCommand:        true,
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'L',
			Long:                 "set_level",
			Args:                 2,
			InvalidatesCommand:   "get_level",
			HasSubCommand:        true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'l',
			Long:                 "get_level",
			Args:                 1,
			HasSubCommand:        true,
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'P',
			Long:                 "set_parm",
			Args:                 2,
			InvalidatesCommand:   "get_parm",
			HasSubCommand:        true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'p',
			Long:                 "get_parm",
			Args:                 1,
			HasSubCommand:        true,
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'B',
			Long:                 "set_bank",
			Args:                 1,
			SupportsExtendedMode: true,
		},
		{
			Short:                'E',
			Long:                 "set_mem",
			Args:                 1,
			InvalidatesCommand:   "get_mem",
			SupportsExtendedMode: true,
		},
		{
			Short:                'e',
			Long:                 "get_mem",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'G',
			Long:                 "vfo_op",
			InvalidatesCommand:   "get_freq",
			Args:                 1,
			SupportsExtendedMode: true,
		},
		{
			Short: 'g',
			Long:  "scan",
			Args:  2,
		},
		{
			Short:              'H',
			Long:               "set_channel",
			Args:               1,
			InvalidatesCommand: "get_channel",
		},
		{
			Short:     'h',
			Long:      "get_channel",
			Cacheable: true,
		},
		{
			Short:                'A',
			Long:                 "set_trn",
			Args:                 1,
			InvalidatesCommand:   "get_trn",
			SupportsExtendedMode: true,
		},
		{
			Short:                'a',
			Long:                 "get_trn",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                'Y',
			Long:                 "set_ant",
			InvalidatesCommand:   "get_ant",
			SupportsExtendedMode: true,
		},
		{
			Short:                'y',
			Long:                 "get_ant",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short: '*',
			Long:  "reset",
			Args:  1,
		},
		{
			Short:                0x87,
			Long:                 "set_powerstat",
			Args:                 1,
			InvalidatesCommand:   "get_powerstat",
			SupportsExtendedMode: true,
		},
		{
			Short:                0x88,
			Long:                 "get_powerstat",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short: 0x89,
			Long:  "send_dtmf",
			Args:  1,
		},
		{
			Short: 0x8a,
			Long:  "recv_dtmf",
		},
		{
			Short:              0x8d,
			Long:               "set_twiddle",
			Args:               1,
			InvalidatesCommand: "get_twiddle",
		},
		{
			Short:     0x8e,
			Long:      "get_twiddle",
			Cacheable: true,
		},
		{
			Short: 0x94,
			Long:  "send_voice_mem",
			Args:  1,
		},
		{
			Short:      'b',
			Long:       "send_morse",
			Args:       1,
			ArgsInLine: true,
		},
		{
			Short: 0xbb,
			Long:  "stop_morse",
		},
		{
			Short: 0xbc,
			Long:  "wait_morse",
		},
		{
			Short: 'w',
			Long:  "send_cmd",
			Args:  2,
		},
		{
			Short: 'W',
			Long:  "send_cmd_rx",
			Args:  1,
		},
		{
			Short:     '_',
			Long:      "get_info",
			Cacheable: true,
		},
		{
			Short:                '1',
			Long:                 "dump_caps",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                '3',
			Long:                 "dump_conf",
			Cacheable:            true,
			SupportsExtendedMode: true,
		},
		{
			Short:                '2',
			Long:                 "power2mW",
			Args:                 3,
			SupportsExtendedMode: true,
		},
		{
			Short:                '4',
			Long:                 "mW2power",
			Args:                 3,
			SupportsExtendedMode: true,
		},
		{
			Short:                0x8f,
			Long:                 "dump_state",
			SupportsExtendedMode: true,
		},
		{
			Short:     0xf0,
			Long:      "chk_vfo",
			Cacheable: true,
		},
		{
			Short: 0xf2,
			Long:  "set_vfo_opt",
			Args:  1,
		},
		{
			Short: 0xf1,
			Long:  "halt",
		},
		{
			Short:                0x8c,
			Long:                 "pause",
			Args:                 1,
			SupportsExtendedMode: true,
		},
		{
			Short: 0x97,
			Long:  "uplink",
			Args:  1,
		},
		{
			Short:              0x95,
			Long:               "set_cache",
			Args:               1,
			InvalidatesCommand: "get_cache",
		},
		{
			Short:     0x96,
			Long:      "get_cache",
			Cacheable: true,
		},
		{
			Short: 0xf3,
			Long:  "get_vfo_info",
			Args:  1,
		},
		{
			Short: 0xf4,
			Long:  "get_vfo_list",
		},
		{
			Short: 0xf5,
			Long:  "get_rig_info",
		},
		{
			Short: 0xf6,
			Long:  "get_modes",
		},
		{
			Short: 0xf7,
			Long:  "get_mode_bandwidths",
			Args:  1,
		},
	}
)
View Source
var ChkVFOResponse = Response{
	Command: "chk_vfo",
	Data:    []string{"0"},
	Keys:    []string{""},
	Result:  "0",
}
View Source
var DumpStateResponse = Response{
	Command: "dump_state",
	Data: []string{`0
1
2
150000.000000 1500000000.000000 0x1ff -1 -1 0x10000003 0x3
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0x1ff 1
0x1ff 0
0 0
0x1e 2400
0x2 500
0x1 8000
0x1 2400
0x20 15000
0x20 8000
0x40 230000
0 0
9990
9990
10000
0
10 
10 20 30 
0xffffffffffffffff
0xffffffffffffffff
0xfffffffff7ffffff
0xffffffff83ffffff
0xffffffffffffffff
0xffffffffffffffbf
`},
	Result: "0",
}
View Source
var NoResponse = Response{}

Functions

This section is empty.

Types

type Command

type Command struct {
	Short                byte
	Long                 string
	Args                 int
	ArgsInLine           bool
	InvalidatesCommand   string
	HasSubCommand        bool
	SupportsExtendedMode bool
	Cacheable            bool
}

func LongCommand

func LongCommand(s string) Command

func ShortCommand

func ShortCommand(s string) Command

type CommandKey

type CommandKey string

type PollRequest

type PollRequest struct {
	Command Command
	Args    []string
	Handler ResponseHandler
}

func PollCommand

func PollCommand(handler ResponseHandler, command string, args ...string) PollRequest

func PollCommandFunc

func PollCommandFunc(f func(Request, Response) error, command string, args ...string) PollRequest

type Request

type Request struct {
	Command
	ExtendedSeparator string
	Args              []string
}

func (*Request) ExtendedFormat

func (r *Request) ExtendedFormat() string

func (*Request) InvalidatedKey

func (r *Request) InvalidatedKey() CommandKey

func (*Request) Key

func (r *Request) Key() CommandKey

func (*Request) LongFormat

func (r *Request) LongFormat() string

type RequestReader

type RequestReader interface {
	ReadRequest() (Request, error)
}

func NewRequestReader

func NewRequestReader(r io.Reader) RequestReader

type Response

type Response struct {
	Command CommandKey
	Data    []string
	Keys    []string
	Result  string
}

func GetFreqResponse

func GetFreqResponse(frequency int) Response

func GetModeResponse

func GetModeResponse(mode string, passband int) Response

func GetPTTResponse

func GetPTTResponse(enabled bool) Response

func GetSplitFreqResponse

func GetSplitFreqResponse(frequency int) Response

func GetSplitModeResponse

func GetSplitModeResponse(mode string, passband int) Response

func GetSplitVFOResponse

func GetSplitVFOResponse(enabled bool, txVFO string) Response

func GetVFOResponse

func GetVFOResponse(vfo string) Response

func OKResponse

func OKResponse(cmd CommandKey) Response

func (*Response) ExtendedFormat

func (r *Response) ExtendedFormat(separator string) string

func (*Response) Format

func (r *Response) Format() string

type ResponseHandler

type ResponseHandler interface {
	Handle(Request, Response) error
}

type ResponseHandlerFunc

type ResponseHandlerFunc func(Request, Response) error

func (ResponseHandlerFunc) Handle

func (f ResponseHandlerFunc) Handle(request Request, response Response) error

type ResponseReader

type ResponseReader interface {
	ReadResponse(bool) (Response, error)
}

func NewResponseReader

func NewResponseReader(r io.Reader) ResponseReader

type Transceiver

type Transceiver struct {
	// contains filtered or unexported fields
}

func NewPollingTransceiver

func NewPollingTransceiver(rw io.ReadWriter, interval time.Duration, timeout time.Duration, requests ...PollRequest) *Transceiver

func NewTransceiver

func NewTransceiver(rw io.ReadWriter) *Transceiver

func (*Transceiver) Close

func (t *Transceiver) Close()

func (*Transceiver) Send

func (t *Transceiver) Send(ctx context.Context, req Request) (Response, error)

func (*Transceiver) WhenDone

func (t *Transceiver) WhenDone(f func())

Jump to

Keyboard shortcuts

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