-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfunc.py
More file actions
executable file
·205 lines (181 loc) · 5.89 KB
/
func.py
File metadata and controls
executable file
·205 lines (181 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import threading,signal ,traceback
import random,ctypes,math,time,copy,Queue
import numpy
from dsp import common
from GlobalData import *
from common import Rx,Tx
_funclist = {}
def reg_func(func,param_types,param_defaults):
ret = False
try:
_funclist[func.__name__]=(func,param_types,param_defaults)
ret = True
except:
traceback.print_exc()
return ret
def get_func(name):
if name in _funclist:
return _funclist[name]
else:
return None
def call_func(name,params):
ret = None
try:
ret = _funclist[name][0](params)
except:
traceback.print_exc()
return ret
### api - program
# params:page as int ,count as int
# ret:total_page as int,total as int,programs as array
def hackrf_reconf():
hackrf.set_freq(hackrf_settings.centre_frequency)
hackrf.set_sample_rate(hackrf_settings.sample_rate)
hackrf_settings.bb_bandwidth = hackrf.compute_baseband_filter_bw_round_down_lt(hackrf_settings.sample_rate)
hackrf.set_baseband_filter_bandwidth(hackrf_settings.bb_bandwidth)
hackrf.set_amp_enable(False)
hackrf.set_lna_gain(hackrf_settings.if_gain)
hackrf.set_vga_gain(hackrf_settings.bb_gain)
hackrf_settings.name = hackrf.NAME_LIST[hackrf.board_id_read()]
hackrf_settings.version = hackrf.version_string_read()
def test(params):
ret = dict()
ret['count'] = 100
ret['retstr'] = "hello word"
return ret
def reset(params):
ret = dict()
try:
stop(None)
hackrf_settings.current_status = 0
hackrf.close()
hackrf.open()
hackrf_reconf()
ret['ret'] = 'ok'
except:
ret['ret'] = 'fail'
return ret
def get_board_data(params):
ret = dict()
ret['board_name'] = hackrf_settings.name
ret['version'] = hackrf_settings.version
ret['serial_nr'] = hackrf_settings.serial_num
return ret
def set_centre_frequency(params):
ret = dict()
hackrf_settings.centre_frequency = int(params['centre_frequency'])
hackrf.set_freq(hackrf_settings.centre_frequency)
return ret
def waterfall(params):
ret = dict()
ret['centre_frequency'] = hackrf_settings.centre_frequency
ret['sample_rate'] = hackrf_settings.sample_rate
ret['data'] = Rx.get_spectrum()
ret['exit'] = 0
return ret
def get_control_options(params):
ret = dict()
ret['centre_frequency'] =hackrf_settings.centre_frequency
ret['sample_rate'] =hackrf_settings.sample_rate
ret['rf_gain'] = hackrf_settings.rf_gain
ret['if_gain'] = hackrf_settings.if_gain
ret['bb_gain'] = hackrf_settings.bb_gain
ret['demodulator'] = hackrf_settings.modulation
ret['bb_bandwidth'] = hackrf_settings.bb_bandwidth
ret['squelch_threshold'] = 10
ret['current_status'] = hackrf_settings.current_status
ret['fft_rate'] = hackrf_settings.fft_rate
ret['fft_size'] = hackrf_settings.fft_size
return ret
def demodulator(params):
ret = dict()
print params['demodulator']
hackrf_settings.modulation = params['demodulator']
return ret
def set_bb_bandwidth(params):
ret = dict()
hackrf_settings.bb_bandwidth = int(params['value'])
hackrf.set_baseband_filter_bandwidth(hackrf_settings.bb_bandwidth)
return ret
def set_sample_rate(params):
ret = dict()
hackrf_settings.sample_rate = int(params['value'])
hackrf.set_sample_rate(hackrf_settings.sample_rate)
#automatically set baseband bandwidth
hackrf_settings.bb_bandwidth = hackrf.compute_baseband_filter_bw_round_down_lt(hackrf_settings.sample_rate)
hackrf.set_baseband_filter_bandwidth(hackrf_settings.bb_bandwidth)
return ret
def set_rf_gain(params):
ret = dict()
hackrf_settings.rf_gain = int(params['value'])
if hackrf_settings.rf_gain != 0:
hackrf.set_amp_enable(True)
else:
hackrf.set_amp_enable(False)
return ret
def set_if_gain(params):
ret = dict()
hackrf_settings.if_gain = int(params['value'])
hackrf.set_lna_gain(hackrf_settings.if_gain)
return ret
def set_bb_gain(params):
ret = dict()
hackrf_settings.bb_gain = int(params['value'])
hackrf.set_vga_gain(hackrf_settings.bb_gain)
return ret
def set_fft_size(params):
ret = dict()
hackrf_settings.fft_size = int(params['value'])
return ret
def set_fft_rate(params):
ret = dict()
hackrf_settings.fft_rate = int(params['value'])
return ret
def start_rx(params):
ret = dict()
if hackrf_settings.current_status == 1:
return
hackrf_settings.rx_thread = Rx.RxThread()
hackrf_settings.rx_thread.setDaemon(True)
hackrf_settings.rx_thread.start()
if hackrf_settings.current_status == 0:
hackrf.start_rx_mode(Rx.rx_callback_fun)
hackrf_settings.current_status = 1
return ret
def start_tx(params):
ret = dict()
if hackrf_settings.current_status == 2:
return
if hackrf_settings.current_status == 0:
hackrf.start_tx_mode(rx_callback_fun)
hackrf_settings.current_status = 2
return ret
def stop(params):
ret = dict()
if hackrf_settings.current_status == 1:
hackrf_settings.rx_thread.running = False
hackrf_settings.rx_thread.join()
hackrf.stop_rx_mode()
hackrf.close()
hackrf.open()
elif hackrf_settings.current_status == 2:
hackrf.stop_tx_mode()
hackrf_settings.current_status = 0
return ret
reg_func(test,{},{})
reg_func(get_board_data,{},{})
reg_func(set_centre_frequency,{},{})
reg_func(set_sample_rate,{},{})
reg_func(get_control_options,{},{})
reg_func(demodulator,{},{})
reg_func(set_bb_bandwidth,{},{})
reg_func(set_rf_gain,{},{})
reg_func(set_if_gain,{},{})
reg_func(set_bb_gain,{},{})
reg_func(waterfall,{},{})
reg_func(set_fft_size,{},{})
reg_func(set_fft_rate,{},{})
reg_func(start_rx,{},{})
reg_func(start_tx,{},{})
reg_func(stop,{},{})
reg_func(reset,{},{})