-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththresholded.py
138 lines (109 loc) · 4.59 KB
/
thresholded.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Top Block
# Generated: Fri Feb 13 17:11:51 2015
##################################################
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import osmosdr
import wx
import time
from pushbullet import Pushbullet
class top_block(grc_wxgui.top_block_gui):
def recv_pkt(self):
pkt = 0
if self.sink_queue.count():
pkt = self.sink_queue.delete_head().to_string()
#print self.sink_queue.count()
return pkt
def packet_as_ints(self):
myInts = [x for x in bytearray(self.recv_pkt())]
return myInts
def packetsAboveZero(self):
ints=self.packet_as_ints()
#print ints
return sum(ints)
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Top Block")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 96e3
self.frequency = frequency = 433.967e6
self.threshold_factor_rise = 1
self.threshold_factor_fall = 1
##################################################
# Blocks
##################################################
self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
self.rtlsdr_source_0.set_sample_rate(samp_rate)
self.rtlsdr_source_0.set_center_freq(frequency, 0)
self.rtlsdr_source_0.set_freq_corr(0, 0)
self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
self.rtlsdr_source_0.set_gain_mode(1, 0)
self.rtlsdr_source_0.set_gain(10, 0)
self.rtlsdr_source_0.set_if_gain(20, 0)
self.rtlsdr_source_0.set_bb_gain(20, 0)
self.rtlsdr_source_0.set_antenna("", 0)
self.rtlsdr_source_0.set_bandwidth(0, 0)
self.sink_queue = gr.msg_queue()
self.blocks_threshold_ff_0 = blocks.threshold_ff(0, 0.06, 0)
#self.blocks_threshold_ff_0 = blocks.peak_detector_fb(self.threshold_factor_rise)
self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_char*1, self.sink_queue, True)
self.blocks_float_to_uchar_0 = blocks.float_to_uchar()
self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
##################################################
# Connections
##################################################
self.connect((self.rtlsdr_source_0, 0), (self.blocks_complex_to_real_0, 0))
#self.connect((self.blocks_message_sink_0, msg), (self, 0))
self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_threshold_ff_0, 0))
self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_uchar_0, 0))
self.connect((self.blocks_float_to_uchar_0, 0), (self.blocks_message_sink_0, 0))
#self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_message_sink_0, 0))
# QT sink close method reimplementation
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.rtlsdr_source_0.set_sample_rate(self.samp_rate)
def get_frequency(self):
return self.frequency
def set_frequency(self, frequency):
self.frequency = frequency
self.rtlsdr_source_0.set_center_freq(self.frequency, 0)
def dingdong():
print "dingDong"
pb.push_note("Door Bell","Ding Dong!")
if __name__ == '__main__':
import ctypes
import os
api_key='IQCoV2PuDYmXSiKbUxv9dIFQYwVeKBUQ'
pb = Pushbullet(api_key)
if os.name == 'posix':
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = top_block()
tb.Start(True)
lastTime=0
while True:
if tb.packetsAboveZero() > 0:
timeNow=time.time()
if (timeNow - lastTime) > 5:
dingdong()
lastTime=timeNow
#sleep(0.1)