1
1
cimport urh.dev.native.lib.chackrf as chackrf
2
+ from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
2
3
from libc.stdlib cimport malloc
3
4
import time
4
5
@@ -70,21 +71,21 @@ ELSE:
70
71
cpdef get_device_list():
71
72
return None
72
73
73
- cpdef setup(str serial):
74
+ cpdef int setup(str serial):
74
75
"""
75
76
Convenience method for init + open. This one is used by HackRF class.
76
77
:return:
77
78
"""
78
79
init()
79
80
return open (serial)
80
81
81
- cpdef init():
82
+ cpdef int init():
82
83
return chackrf.hackrf_init()
83
84
84
- cpdef exit():
85
+ cpdef int exit():
85
86
return chackrf.hackrf_exit()
86
87
87
- cpdef close():
88
+ cpdef int close():
88
89
return chackrf.hackrf_close(_c_device)
89
90
90
91
cpdef int start_rx_mode(callback):
@@ -93,42 +94,25 @@ cpdef int start_rx_mode(callback):
93
94
f = callback
94
95
return chackrf.hackrf_start_rx(_c_device, _c_callback_recv, NULL )
95
96
96
- cpdef stop_rx_mode():
97
+ cpdef int stop_rx_mode():
97
98
global RUNNING
98
99
RUNNING = - 1
99
100
time.sleep(TIMEOUT)
100
101
return chackrf.hackrf_stop_rx(_c_device)
101
102
102
- cpdef start_tx_mode(callback):
103
+ cpdef int start_tx_mode(callback):
103
104
global f, RUNNING
104
105
RUNNING = 0
105
106
f = callback
106
107
return chackrf.hackrf_start_tx(_c_device, _c_callback_send, NULL )
107
108
108
- cpdef stop_tx_mode():
109
+ cpdef int stop_tx_mode():
109
110
global RUNNING
110
111
RUNNING = - 1
111
112
time.sleep(TIMEOUT)
112
113
return chackrf.hackrf_stop_tx(_c_device)
113
114
114
- cpdef board_id_read():
115
- cdef unsigned char value
116
- ret = chackrf.hackrf_board_id_read(_c_device, & value)
117
- if ret == hackrf_success:
118
- return value
119
- else :
120
- return " "
121
-
122
- cpdef version_string_read():
123
- cdef char * version = < char * > malloc(20 * sizeof(char ))
124
- cdef unsigned char length = 20
125
- ret = chackrf.hackrf_version_string_read(_c_device, version, length)
126
- if ret == hackrf_success:
127
- return version.decode(' UTF-8' )
128
- else :
129
- return " "
130
-
131
- cpdef set_freq(freq_hz):
115
+ cpdef int set_freq(freq_hz):
132
116
time.sleep(TIMEOUT)
133
117
return chackrf.hackrf_set_freq(_c_device, freq_hz)
134
118
@@ -140,35 +124,39 @@ cpdef is_streaming():
140
124
else :
141
125
return False
142
126
143
- cpdef set_rf_gain(value):
144
- """ Enable or disable RF amplifier """
127
+ cpdef int set_amp_enable(value):
145
128
time.sleep(TIMEOUT)
129
+ cdef uint8_t val = 1 if value else 0
130
+ return chackrf.hackrf_set_amp_enable(_c_device, val)
131
+
132
+ cpdef int set_rf_gain(value):
133
+ """ Enable or disable RF amplifier """
146
134
return set_amp_enable(value)
147
135
148
- cpdef set_if_rx_gain(value):
136
+ cpdef int set_if_rx_gain(value):
149
137
""" Sets the LNA gain, in 8Db steps, maximum value of 40 """
150
138
time.sleep(TIMEOUT)
151
139
return chackrf.hackrf_set_lna_gain(_c_device, value)
152
140
153
- cpdef set_if_tx_gain(value):
141
+ cpdef int set_if_tx_gain(value):
154
142
""" Sets the txvga gain, in 1db steps, maximum value of 47 """
155
143
time.sleep(TIMEOUT)
156
144
return chackrf.hackrf_set_txvga_gain(_c_device, value)
157
145
158
- cpdef set_baseband_gain(value):
146
+ cpdef int set_baseband_gain(value):
159
147
""" Sets the vga gain, in 2db steps, maximum value of 62 """
160
148
time.sleep(TIMEOUT)
161
149
return chackrf.hackrf_set_vga_gain(_c_device, value)
162
150
163
- cpdef set_sample_rate(sample_rate):
151
+ cpdef int set_sample_rate(sample_rate):
164
152
time.sleep(TIMEOUT)
165
153
return chackrf.hackrf_set_sample_rate(_c_device, sample_rate)
166
154
167
- cpdef set_amp_enable(value ):
155
+ cpdef int set_bias_tee(on_or_off ):
168
156
time.sleep(TIMEOUT)
169
- cdef bint val = 1 if value else 0
170
- return chackrf.hackrf_set_amp_enable (_c_device, val )
157
+ cdef uint8_t bias_tee = 1 if on_or_off else 0
158
+ return chackrf.hackrf_set_antenna_enable (_c_device, bias_tee )
171
159
172
- cpdef set_baseband_filter_bandwidth(bandwidth_hz):
160
+ cpdef int set_baseband_filter_bandwidth(bandwidth_hz):
173
161
time.sleep(TIMEOUT)
174
162
return chackrf.hackrf_set_baseband_filter_bandwidth(_c_device, bandwidth_hz)
0 commit comments