Skip to content

Commit 2a86699

Browse files
authored
Fix setting of bias tee with rtl_tcp (#1169)
* Fix setting of bias tee with rtl_tcp * black
1 parent cebcf92 commit 2a86699

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/urh/dev/native/RTLSDRTCP.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@
1010
class RTLSDRTCP(Device):
1111
MAXDATASIZE = 65536
1212
ENDIAN = "big"
13-
RTL_TCP_CONSTS = [
14-
"NULL",
15-
"centerFreq",
16-
"sampleRate",
17-
"tunerGainMode",
18-
"tunerGain",
19-
"freqCorrection",
20-
"tunerIFGain",
21-
"testMode",
22-
"agcMode",
23-
"directSampling",
24-
"offsetTuning",
25-
"rtlXtalFreq",
26-
"tunerXtalFreq",
27-
"gainByIndex",
28-
"bandwidth",
29-
"biasTee",
30-
]
13+
RTL_TCP_CONSTS = {
14+
"centerFreq": 0x01,
15+
"sampleRate": 0x02,
16+
"tunerGainMode": 0x03,
17+
"tunerGain": 0x04,
18+
"freqCorrection": 0x05,
19+
"tunerIFGain": 0x06,
20+
"testMode": 0x07,
21+
"agcMode": 0x08,
22+
"directSampling": 0x09,
23+
"offsetTuning": 0x0A,
24+
"rtlXtalFreq": 0x0B,
25+
"tunerXtalFreq": 0x0C,
26+
"gainByIndex": 0x0D,
27+
# At least two rtl_tcp implementations agree on the biasTee value.
28+
# See https://github.com/pinkavaj/rtl-sdr/blob/master/include/rtl_tcp.h#L50
29+
# See https://gitea.osmocom.org/sdr/rtl-sdr/src/branch/master/src/rtl_tcp.c
30+
"biasTee": 0x0E,
31+
# Only pinkavaj/rtl-sdr has a bandwidth constant; osmocom does not.
32+
# As a result, bandwidth commands will do nothing when using osmocom's rtl_tcp.
33+
"bandwidth": 0x40,
34+
}
3135

3236
DATA_TYPE = np.int8
3337

@@ -42,6 +46,7 @@ def receive_sync(
4246
gain: int,
4347
freq_correction: int,
4448
direct_sampling_mode: int,
49+
bias_tee_enabled: bool,
4550
device_ip: str,
4651
port: int,
4752
):
@@ -57,6 +62,7 @@ def receive_sync(
5762
sdr.set_parameter(
5863
"directSampling", int(direct_sampling_mode), ctrl_connection
5964
)
65+
sdr.set_parameter("biasTee", int(bias_tee_enabled), ctrl_connection)
6066
# Gain has to be set last, otherwise it does not get considered by RTL-SDR
6167
sdr.set_parameter("tunerGain", int(gain), ctrl_connection)
6268
exit_requested = False
@@ -152,6 +158,7 @@ def receive_process_arguments(self):
152158
self.gain,
153159
self.freq_correction,
154160
self.direct_sampling_mode,
161+
self.bias_tee_enabled,
155162
self.device_ip,
156163
self.port,
157164
)
@@ -239,7 +246,7 @@ def set_parameter(
239246
self, param: str, value: int, ctrl_connection
240247
): # returns error (True/False)
241248
if self.socket_is_open:
242-
msg = self.RTL_TCP_CONSTS.index(param).to_bytes(
249+
msg = self.RTL_TCP_CONSTS[param].to_bytes(
243250
1, self.ENDIAN
244251
) # Set param at bits 0-7
245252
msg += value.to_bytes(4, self.ENDIAN) # Set value at bits 8-39

0 commit comments

Comments
 (0)