Skip to content

Commit f136e02

Browse files
committed
updated
1 parent e49b9e5 commit f136e02

File tree

6 files changed

+106
-81
lines changed

6 files changed

+106
-81
lines changed

python_hackrf/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def main():
5151
pyhackrf_sweep_parser.add_argument('-B', action='store_true', help='binary output. If specified = Enable')
5252
pyhackrf_sweep_parser.add_argument('-S', action='store', help='sweep style ("L" - LINEAR, "I" - INTERLEAVED). Default is INTERLEAVED', metavar='', default='I')
5353
pyhackrf_sweep_parser.add_argument('-s', action='store', help='sample rate in MHz (2, 4, 6, 8, 10, 12, 14, 16, 18, 20). Default is 20', metavar='', default=20)
54-
pyhackrf_sweep_parser.add_argument('-b', action='store', help='baseband filter bandwidth in MHz (1.75, 2.5, 3.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 15.0 20.0, 24.0, 28.0). Default is 15.0', metavar='', default=15.0)
54+
pyhackrf_sweep_parser.add_argument('-b', action='store', help='baseband filter bandwidth in MHz (1.75, 2.5, 3.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 15.0 20.0, 24.0, 28.0). Default is 15.0', metavar='')
5555
pyhackrf_sweep_parser.add_argument('-r', action='store', help='<filename> output file', metavar='')
5656

5757
pyhackrf_transfer_parser = subparsers.add_parser(
@@ -72,7 +72,7 @@ def main():
7272
pyhackrf_transfer_parser.add_argument('-s', action='store', help='sample rate in MHz (2, 4, 6, 8, 10, 12, 14, 16, 18, 20). Default is 10', metavar='', default=10)
7373
pyhackrf_transfer_parser.add_argument('-N', action='store', help='number of samples to transfer (default is unlimited)', metavar='')
7474
pyhackrf_transfer_parser.add_argument('-R', action='store_true', help='repeat TX mode. Fefault is off')
75-
pyhackrf_transfer_parser.add_argument('-b', action='store', help='baseband filter bandwidth in MHz (1.75, 2.5, 3.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 15.0 20.0, 24.0, 28.0). Default is 15.0', metavar='', default=15.0)
75+
pyhackrf_transfer_parser.add_argument('-b', action='store', help='baseband filter bandwidth in MHz (1.75, 2.5, 3.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 15.0 20.0, 24.0, 28.0). Default is 15.0', metavar='')
7676
pyhackrf_transfer_parser.add_argument('-H', action='store_true', help='synchronize RX/TX to external trigger input')
7777

7878
if len(sys.argv) == 1:
@@ -242,7 +242,7 @@ def main():
242242
pyhackrf_sweep.pyhackrf_sweep(
243243
frequencies=frequencies,
244244
sample_rate=int(args.s) * 1e6,
245-
baseband_filter_bandwidth=float(args.b) * 1e6,
245+
baseband_filter_bandwidth=float(args.b) * 1e6 if args.b is not None else None,
246246
lna_gain=int(args.l),
247247
vga_gain=int(args.g),
248248
bin_width=int(args.w),

python_hackrf/pyhackrf_tools/pyhackrf_sweep.pyx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ AVAILABLE_BASEBAND_FILTER_BANDWIDTHS = (1_750_000, 2_500_000, 3_500_000, 5_000_0
5252
INTERLEAVED_OFFSET_RATIO = 0.375
5353
LINEAR_OFFSET_RATIO = 0.5
5454

55-
run_available = {}
56-
device_data = {}
55+
cdef dict run_available = {}
56+
cdef dict device_data = {}
5757

5858

5959
def sigint_callback_handler(sig, frame):
6060
global run_available
6161
for device in run_available.keys():
6262
run_available[device] = False
63-
sys.stderr.write('\n')
6463

6564

6665
def init_signals():
@@ -80,7 +79,7 @@ cdef sweep_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[:], buff
8079
timestamp = datetime.datetime.now()
8180
time_str = timestamp.strftime('%Y-%m-%d, %H:%M:%S.%f')
8281

83-
current_device_data = device_data[device.pyhackrf_serialno_read()]
82+
current_device_data = device_data[device.uuid]
8483
norm_factor = 1.0 / current_device_data['fft_size']
8584
data_length = current_device_data['fft_size'] * 2
8685
sweep_style = current_device_data['sweep_style']
@@ -109,14 +108,14 @@ cdef sweep_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[:], buff
109108
if current_device_data['sweep_started']:
110109
current_device_data['sweep_count'] += 1
111110
if (
112-
current_device_data['one_shot_mode'] or
111+
current_device_data['one_shot'] or
113112
current_device_data['num_sweeps'] == current_device_data['sweep_count']
114113
):
115-
run_available[device.pyhackrf_serialno_read()] = False
116-
117-
current_device_data['sweep_started'] = True
114+
run_available[device.uuid] = False
115+
else:
116+
current_device_data['sweep_started'] = True
118117

119-
if not run_available[device.pyhackrf_serialno_read()]:
118+
if not run_available[device.uuid]:
120119
return -1
121120

122121
if not current_device_data['sweep_started']:
@@ -206,7 +205,7 @@ cdef sweep_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[:], buff
206205
return 0
207206

208207

209-
def pyhackrf_sweep(frequencies: list = None, sample_rate: int = 20_000_000, baseband_filter_bandwidth: int = 15_000_000,
208+
def pyhackrf_sweep(frequencies: list = None, sample_rate: int = 20_000_000, baseband_filter_bandwidth: int = None,
210209
lna_gain: int = 16, vga_gain: int = 20, bin_width: int = 100_000, amp_enable: bool = False, antenna_enable: bool = False,
211210
sweep_style: pyhackrf.py_sweep_style = pyhackrf.py_sweep_style.INTERLEAVED, serial_number: str = None,
212211
binary_output: bool = False, one_shot: bool = False, num_sweeps: int = None,
@@ -223,10 +222,10 @@ def pyhackrf_sweep(frequencies: list = None, sample_rate: int = 20_000_000, base
223222
else:
224223
device = pyhackrf.pyhackrf_open_by_serial(serial_number)
225224

226-
run_available[device.pyhackrf_serialno_read()] = True
225+
run_available[device.uuid] = True
227226

228227
sample_rate = int(sample_rate) if int(sample_rate) in AVAILABLE_SAMPLING_RATES else 20_000_000
229-
baseband_filter_bandwidth = int(baseband_filter_bandwidth) if int(baseband_filter_bandwidth) in AVAILABLE_BASEBAND_FILTER_BANDWIDTHS else pyhackrf.pyhackrf_compute_baseband_filter_bw(int(baseband_filter_bandwidth))
228+
baseband_filter_bandwidth = int(baseband_filter_bandwidth) if baseband_filter_bandwidth in AVAILABLE_BASEBAND_FILTER_BANDWIDTHS else pyhackrf.pyhackrf_compute_baseband_filter_bw(int(sample_rate * .75))
230229

231230
current_device_data = {
232231
'sweep_style': sweep_style if sweep_style in pyhackrf.py_sweep_style else pyhackrf.py_sweep_style.INTERLEAVED,
@@ -319,14 +318,14 @@ def pyhackrf_sweep(frequencies: list = None, sample_rate: int = 20_000_000, base
319318
current_device_data['start_frequency'] = int(frequencies[0] * 1e6)
320319
current_device_data['fft_size'] = fft_size
321320
current_device_data['window'] = np.hanning(fft_size)
322-
device_data[device.pyhackrf_serialno_read()] = current_device_data
321+
device_data[device.uuid] = current_device_data
323322

324323
device.pyhackrf_init_sweep(frequencies, num_ranges, pyhackrf.PY_BYTES_PER_BLOCK, int(TUNE_STEP * 1e6), OFFSET, current_device_data['sweep_style'])
325324
device.pyhackrf_start_rx_sweep()
326325

327326
time_start = time.time()
328327
time_prev = time.time()
329-
while device.pyhackrf_is_streaming() and run_available[device.pyhackrf_serialno_read()]:
328+
while device.pyhackrf_is_streaming() and run_available[device.uuid]:
330329
time.sleep(0.05)
331330
time_now = time.time()
332331
time_difference = time_now - time_prev
@@ -346,10 +345,10 @@ def pyhackrf_sweep(frequencies: list = None, sample_rate: int = 20_000_000, base
346345
current_device_data['file'].close()
347346

348347
if print_to_console:
349-
if not run_available[device.pyhackrf_serialno_read()]:
350-
sys.stderr.write('Exiting...\n')
348+
if not run_available[device.uuid]:
349+
sys.stderr.write('\nExiting...\n')
351350
else:
352-
sys.stderr.write('Exiting... [ pyhackrf streaming stopped ]\n')
351+
sys.stderr.write('\nExiting... [ pyhackrf streaming stopped ]\n')
353352

354353
time_now = time.time()
355354
time_difference = time_now - time_prev
@@ -359,8 +358,8 @@ def pyhackrf_sweep(frequencies: list = None, sample_rate: int = 20_000_000, base
359358
if print_to_console:
360359
sys.stderr.write(f'Total sweeps: {current_device_data["sweep_count"]} in {time_now - time_start:.5f} seconds ({sweep_rate :.2f} sweeps/second)\n')
361360

362-
device_data.pop(device.get_hackrf_device_double_ptr(), None)
363-
run_available.pop(device.get_hackrf_device_double_ptr(), None)
361+
device_data.pop(device.uuid, None)
362+
run_available.pop(device.uuid, None)
364363

365364
try:
366365
device.pyhackrf_close()

0 commit comments

Comments
 (0)