-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdr_rtl.go
128 lines (115 loc) · 3.58 KB
/
sdr_rtl.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// {{{ Copyright (c) Paul R. Tagliamonte <[email protected]>, 2022
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. }}}
//go:build !sdr.nortl
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"hz.tools/fftw"
"hz.tools/sdr"
"hz.tools/sdr/rtl"
"hz.tools/sdr/rtl/kerberos"
"hz.tools/sdr/rtltcp"
)
func init() {
addSdr(
"rtl",
func(flags *pflag.FlagSet, prefix string) {
flags.String(prefix+"rtl-serial", "", "serial number to use")
flags.Uint(prefix+"rtl-device-index", 0, "device index to use")
flags.Bool(prefix+"rtl-bias-t", false, "Set bias-T state")
},
func(c *cobra.Command, prefix string) (sdr.Sdr, error) {
flags := c.Flags()
serial, err := flags.GetString(prefix + "rtl-serial")
if err != nil {
return nil, err
}
deviceIndex, err := flags.GetUint(prefix + "rtl-device-index")
if err != nil {
return nil, err
}
if serial != "" {
if deviceIndex != 0 {
return nil, fmt.Errorf("rfutil: can't set both serial and index")
}
deviceIndex, err = rtl.DeviceIndexBySerial(serial)
if err != nil {
return nil, err
}
}
rtlCount := rtl.DeviceCount()
if rtlCount == 0 {
return nil, fmt.Errorf("rfutil: no rtl devices found")
}
if rtlCount < deviceIndex {
return nil, fmt.Errorf("rfutil: index isn't valid")
}
dev, err := rtl.New(deviceIndex, 0)
if err != nil {
return nil, err
}
biasT, err := flags.GetBool(prefix + "rtl-bias-t")
if err != nil {
return nil, err
}
if err := dev.SetBiasT(biasT); err != nil {
return nil, err
}
return dev, nil
},
)
addSdr(
"rtltcp",
func(flags *pflag.FlagSet, prefix string) {
flags.String(prefix+"rtltcp-host", "localhost", "fqdn to connect to")
flags.Uint(prefix+"rtltcp-port", 1234, "remote port to use")
},
func(c *cobra.Command, prefix string) (sdr.Sdr, error) {
flags := c.Flags()
fqdn, err := flags.GetString(prefix + "rtltcp-host")
if err != nil {
return nil, err
}
port, err := flags.GetUint(prefix + "rtltcp-port")
if err != nil {
return nil, err
}
addr := fmt.Sprintf("%s:%d", fqdn, port)
return rtltcp.Dial("tcp", addr)
},
)
addSdr(
"kerberos-coherent",
func(flags *pflag.FlagSet, prefix string) {},
func(c *cobra.Command, prefix string) (sdr.Sdr, error) {
return kerberos.NewCoherent(fftw.Plan, 0, 1, 2, 3, 0)
},
)
addSdr(
"kerberos-offset",
func(flags *pflag.FlagSet, prefix string) {},
func(c *cobra.Command, prefix string) (sdr.Sdr, error) {
return kerberos.NewOffset(fftw.Plan, 0, 1, 2, 3, 0)
},
)
}
// vim: foldmethod=marker