-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
77 lines (68 loc) · 1.6 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package rigctld
import (
"errors"
"fmt"
)
func (s *Client) GetFreq() (Frequency, error) {
resp, err := s.writeRead("f\n")
if err != nil {
return 0, err
}
var freq Frequency
_, err = fmt.Sscanf(resp, "%d\n", &freq)
if err != nil {
return 0, err
}
return freq, nil
}
func (s *Client) SetFreq(freq Frequency) error {
resp, err := s.writeRead(fmt.Sprintf("F %d\n", freq))
if err != nil {
return err
}
var report int
_, err = fmt.Sscanf(resp, "RPRT %d\n", &report)
if err != nil {
return err
}
if report != 0 {
// TODO: Can this be more specific? Probably would have to delve into the rigctld source
return errors.New(fmt.Sprintf("rigctld error %d", report))
}
return nil
}
// GetMode returns the current mode and bandpass width of the radio.
func (s *Client) GetMode() (Mode, Frequency, error) {
resp, err := s.writeRead("m\n")
if err != nil {
return -1, 0, err
}
var modeStr string
var bandpass Frequency
_, err = fmt.Sscanf(resp, "%s\n%d\n", &modeStr, &bandpass)
if err != nil {
return -1, 0, err
}
mode, err := ModeFromString(modeStr)
if err != nil {
return -1, 0, err
}
return mode, bandpass, nil
}
func (s *Client) SetMode(mode Mode, bandpass Frequency) error {
modeStr := mode.String()
resp, err := s.writeRead(fmt.Sprintf("M %s %d\n", modeStr, bandpass))
if err != nil {
return err
}
var report int
_, err = fmt.Sscanf(resp, "RPRT %d\n", &report)
if err != nil {
return err
}
if report != 0 {
// TODO: Can this be more specific? Probably would have to delve into the rigctld source
return errors.New(fmt.Sprintf("rigctld error %d", report))
}
return nil
}