-
Notifications
You must be signed in to change notification settings - Fork 0
/
uhd_utils.py
executable file
·58 lines (42 loc) · 1.64 KB
/
uhd_utils.py
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
import json
import uhd
class USRPParams:
_params = {
"sampling_rate": 1e6,
"gain": 76,
"channel": 0,
"freq": 900e6,
"args": ""
}
def set_param(self, param: str, value: any):
self._params[param] = value
def get_param(self, param: str) -> any:
return self._params[param]
def export_config(self, path: str):
with open(path, "w") as f:
json.dump(self._params, f)
def import_config(self, path: str):
with open(path, "r") as f:
self._params = json.load(f)
def init_usrp_rx(params: USRPParams) -> uhd.usrp.MultiUSRP:
channel_id = params.get_param("channel")
usrp = uhd.usrp.MultiUSRP()
usrp.set_rx_rate(params.get_param("sampling_rate"), channel_id)
usrp.set_rx_freq(uhd.types.TuneRequest(
params.get_param("freq")), channel_id)
usrp.set_rx_gain(params.get_param("gain"), channel_id)
return usrp
def init_usrp_streamer_rx(usrp: uhd.usrp.MultiUSRP) -> uhd.libpyuhd.usrp.rx_streamer:
st_args = uhd.usrp.StreamArgs("fc32", "sc16")
return usrp.get_rx_stream(st_args)
def init_usrp_tx(params: USRPParams) -> uhd.usrp.MultiUSRP:
channel_id = params.get_param("channel")
usrp = uhd.usrp.MultiUSRP()
usrp.set_tx_rate(params.get_param("sampling_rate"), channel_id)
usrp.set_tx_freq(uhd.types.TuneRequest(
params.get_param("freq")), channel_id)
usrp.set_tx_gain(params.get_param("gain"), channel_id)
return usrp
def init_usrp_streamer_tx(usrp: uhd.usrp.MultiUSRP) -> uhd.libpyuhd.usrp.tx_streamer:
st_args = uhd.usrp.StreamArgs("fc32", "sc16")
return usrp.get_tx_stream(st_args)