@@ -52,15 +52,14 @@ AVAILABLE_BASEBAND_FILTER_BANDWIDTHS = (1_750_000, 2_500_000, 3_500_000, 5_000_0
5252INTERLEAVED_OFFSET_RATIO = 0.375
5353LINEAR_OFFSET_RATIO = 0.5
5454
55- run_available = {}
56- device_data = {}
55+ cdef dict run_available = {}
56+ cdef dict device_data = {}
5757
5858
5959def 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
6665def 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(' \n Exiting ...\n ' )
351350 else :
352- sys.stderr.write(' Exiting ... [ pyhackrf streaming stopped ]\n ' )
351+ sys.stderr.write(' \n Exiting ... [ 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