-
Notifications
You must be signed in to change notification settings - Fork 0
/
hamlib.go
67 lines (60 loc) · 1.66 KB
/
hamlib.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
package rig
import (
"errors"
"strings"
)
var (
ErrHamlibReport = errors.New("did not receive a report from hamlib")
ErrHamlib = []error{
nil,
errors.New("hamlib: invalid parameter"),
errors.New("hamlib: invalid configuration"),
errors.New("hamlib: memory shortage"),
errors.New("hamlib: function not implemented"),
errors.New("hamlib: communication timed out"),
errors.New("hamlib: I/O error"),
errors.New("hamlib: internal error"),
errors.New("hamlib: protocol error"),
errors.New("hamlib: command rejected by rig"),
errors.New("hamlib: command performed but truncated"),
errors.New("hamlib: function not available"),
errors.New("hamlib: VFO not targetable"),
errors.New("hamlib: bus error"),
errors.New("hamlib: bus busy"),
errors.New("hamlib: invalid pointer"),
errors.New("hamlib: invalid VFO"),
errors.New("hamlib: argument out of domain"),
}
)
type hamlibRig struct {
modelName string
manufacturer string
backendVersion string
rigType string
ctcss []string
dcs []string
can map[string]bool
}
func (r *hamlibRig) parseCapabilities(c []string) error {
if r.can == nil {
r.can = make(map[string]bool)
}
for _, line := range c {
part := strings.SplitN(line, ":", 2)
if len(part) != 2 {
continue
}
key := strings.ToLower(part[0])
switch {
case key == "model name":
r.modelName = strings.TrimSpace(part[1])
case key == "mfg name":
r.manufacturer = strings.TrimSpace(part[1])
case key == "backend version":
r.backendVersion = strings.TrimSpace(part[1])
case strings.HasPrefix(key, "can "):
r.can[key[4:]] = part[1][len(part[1])-1] == 'Y'
}
}
return nil
}