2424
2525from python_hackrf import pyhackrf
2626import numpy as np
27+ cimport numpy as cnp
2728cimport cython
2829import signal
2930import time
@@ -75,18 +76,18 @@ cdef rx_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[np.uint8_t,
7576 if not run_available[device.serialno]:
7677 return - 1
7778
78- current_device_data = device_data[device.serialno]
79+ cdef dict current_device_data = device_data[device.serialno]
7980
8081 current_device_data[' byte_count' ] += valid_length
8182 current_device_data[' stream_power' ] += np.sum(buffer [:valid_length].view(np.int8).astype(np.uint64, copy = False ) ** 2 )
8283
83- to_read = valid_length
84+ cdef int to_read = valid_length
8485 if current_device_data[' num_samples' ]:
8586 if (to_read > current_device_data[' num_samples' ] * 2 ):
8687 to_read = current_device_data[' num_samples' ] * 2
8788 current_device_data[' num_samples' ] -= (to_read // 2 )
8889
89- accepted_data = (buffer [:to_read:2 ].astype(np.int8, copy = False ) / 128 + 1j * buffer [1 :to_read:2 ].astype(np.int8, copy = False ) / 128 ).astype(np.complex64)
90+ cdef cnp.ndarray accepted_data = (buffer [:to_read:2 ].astype(np.int8, copy = False ) / 128 + 1j * buffer [1 :to_read:2 ].astype(np.int8, copy = False ) / 128 ).astype(np.complex64)
9091
9192 if current_device_data[' rx_queue' ] is not None :
9293 current_device_data[' rx_queue' ].put_nowait(accepted_data)
@@ -105,13 +106,13 @@ cdef rx_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[np.uint8_t,
105106cdef tx_callback(device: pyhackrf.PyHackrfDevice, buffer : np.ndarray[np.uint8_t, 1 ], buffer_length: int , valid_length: int ):
106107 global run_available, device_data
107108
108- current_device_data = device_data[device.serialno]
109+ cdef dict current_device_data = device_data[device.serialno]
109110
110111 if current_device_data[' tx_complete' ] or not run_available[device.serialno]:
111112 return - 1 , buffer , valid_length
112113
113- to_write = buffer_length // 2
114- writed = 0
114+ cdef int to_write = buffer_length // 2
115+ cdef int writed = 0
115116 if current_device_data[' num_samples' ]:
116117 if (to_write > current_device_data[' num_samples' ]):
117118 to_write = current_device_data[' num_samples' ]
@@ -219,7 +220,7 @@ cdef tx_complete_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[np
219220 run_available[device.serialno] = False
220221 return
221222
222- current_device_data = device_data[device.serialno]
223+ cdef dict current_device_data = device_data[device.serialno]
223224
224225 current_device_data[' byte_count' ] += valid_length
225226 current_device_data[' stream_power' ] += np.sum(buffer [:valid_length].view(np.int8).astype(np.uint64, copy = False ) ** 2 )
@@ -228,7 +229,7 @@ cdef tx_complete_callback(device: pyhackrf.PyHackrfDevice, buffer: np.ndarray[np
228229cdef flush_callback(device: pyhackrf.PyHackrfDevice, success: int ):
229230 global run_available, device_data
230231
231- current_device_data = device_data[device.serialno]
232+ cdef dict current_device_data = device_data[device.serialno]
232233
233234 if success:
234235 current_device_data[' flush_complete' ] = True
@@ -259,7 +260,7 @@ def pyhackrf_transfer(frequency: int = None, sample_rate: int = 10_000_000, base
259260 if num_samples and num_samples >= SAMPLES_TO_XFER_MAX:
260261 raise RuntimeError (f' num_samples must be less than {SAMPLES_TO_XFER_MAX}' )
261262
262- current_device_data = {
263+ cdef dict current_device_data = {
263264 ' num_samples' : num_samples,
264265 ' flush_complete' : False ,
265266 ' repeat_tx' : repeat_tx,
@@ -378,8 +379,12 @@ def pyhackrf_transfer(frequency: int = None, sample_rate: int = 10_000_000, base
378379 if num_samples and print_to_console:
379380 sys.stderr.write(f' samples_to_xfer {num_samples}/{num_samples / 1e6:.3f} Mio\n ' )
380381
381- time_start = time.time()
382- time_prev = time.time()
382+ cdef double time_start = time.time()
383+ cdef double time_prev = time.time()
384+ cdef double time_difference = 0
385+ cdef int byte_count = 0
386+ cdef int stream_power = 0
387+ cdef double dB_full_scale = 0
383388 while run_available[device.serialno]:
384389 time.sleep(0.05 )
385390 time_now = time.time()
0 commit comments