-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscanning_receiver.py
118 lines (92 loc) · 3.61 KB
/
scanning_receiver.py
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
#!/usr/bin/env python
# Copyright 2019,2020 Radiocapture LLC - Radiocapture.com
from gnuradio import filter, analog
from gnuradio import gr
from gnuradio import blocks
from gnuradio.filter import firdes
import time
import threading
from logging_receiver import logging_receiver
class scanning_receiver(gr.hier_block2):
def __init__(self, system, top_block, block_id):
gr.hier_block2.__init__(self, "scanning_receiver",
gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature(0, 0, 0)) # Output signature
##################################################
# Variables
##################################################
self.hang_time = 0.5
self.channel_rate = 12500
self.tb = top_block
self.block_id = block_id
self.system = system
print self.system
self.system_id = system['id']
self.channels = system['channels']
##################################################
# Threads
##################################################
receive_engine = threading.Thread(target=self.receive_engine)
receive_engine.daemon = True
receive_engine.start()
##################################################
# Blocks
##################################################
self.source = self
#self.complex_to_mag_squared = blocks.complex_to_mag_squared(1)
#self.probe = blocks.probe_signal_f()
self.squelch = analog.simple_squelch_cc(self.system['threshold'], 0.1)
self.sink = blocks.null_sink(gr.sizeof_gr_complex*1)
##################################################
# Connections
##################################################
#self.connect(self, self.complex_to_mag_squared, self.probe)
self.connect(self, self.squelch, self.sink)
def call_progress(self, freq):
self.tb.ar_lock.acquire()
for r in self.tb.active_receivers:
if(r.cdr != {} and r.cdr['system_id'] == self.system['id'] and r.cdr['system_channel_local'] == freq and r.in_use == True):
r.activity()
self.tb.ar_lock.release()
return None
#new call, either find empty receiver or create a new one, then insert into call table
try:
allocated_receiver = self.tb.connect_channel(int(freq), int(self.channel_rate))
except:
self.tb.ar_lock.release()
return False
allocated_receiver.set_rate(self.channel_rate)
if self.system['modulation'] == 'p25':
allocated_receiver.configure_blocks('p25')
elif self.system['modulation'] == 'provoice':
allocated_receiver.configure_blocks('provoice')
else:
allocated_receiver.configure_blocks('analog')
cdr = {
'system_id': self.system['id'],
'system_group_local': freq,
'system_user_local': 0,
'system_channel_local': freq,
'type': 'group',
'hang_time': self.hang_time
}
allocated_receiver.open(cdr)
self.tb.ar_lock.release()
###################################################################################################
def receive_engine(self):
print 'scanning_receiver: receive_engine() startup'
print self.channels
#time.sleep(3)
if len(self.channels) > 1:
raise Exception('scan: canner ghetto rig, 1 channel per scanner pls')
while(True):
for key,freq in self.channels.iteritems():
time.sleep(0.010)
#if self.probe.level() > 3.0e-4:
if self.squelch.unmuted():
self.call_progress(freq)
# print '*Freq: %s Level: %s' % (freq, self.probe.level())
#elif self.probe.level() > 9.0e-7:
# print ' Freq: %s Level: %s' % (freq, self.probe.level())
#else:
#print 'scan: Freq: %s Level: %s' % (freq, self.probe.level())