blob: fb5ae300ac26c36b61ff86ac58950606255bba38 [file] [log] [blame]
#!/usr/bin/python
import ctypes
from distutils.version import StrictVersion
import os
import sys
import time
from gnuradio import gr
from PyQt4 import Qt
# Import modules from gnuradio-companion generated files.
from bandpass_recorder_file import bandpass_recorder_file
from bandpass_recorder_gui import bandpass_recorder_gui
if __name__ == '__main__':
# Checks if libX11 works properly.
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print 'Warning: failed to XInitThreads()'
# Check and parse arguments.
if len(sys.argv) != 2:
print 'usage: ./bandpass_recorder_final.py filename\n'
sys.exit(1)
if StrictVersion(Qt.qVersion()) >= StrictVersion('4.5.0'):
Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui', 'style', 'raster'))
qapp = Qt.QApplication(sys.argv)
# Start the GUI
gui_block = bandpass_recorder_gui()
gui_block.start()
gui_block.show()
# Define callback behaviour for the gui_block: starts the file_block and begins
# recording once the gui_block is closed.
def begin_recording():
# Retrieve parameters
gain = gui_block.get_gain()
freq = gui_block.get_freq()
width = gui_block.get_width()
record_time = gui_block.get_record_time() / 1000.0
# Stop the gui
gui_block.stop()
gui_block.wait()
# Start the file recorder
file_block = bandpass_recorder_file()
print 'recording... ({0} seconds)\n'.format(record_time)
# Set parameters
file_block.set_gain(gain)
file_block.set_freq(freq)
file_block.set_width(width)
file_block.start()
# Run the recording for the specified time.
time.sleep(record_time)
file_block.stop()
file_block.wait()
# Rename output file
try:
os.rename('recorder.out', sys.argv[1])
except OSError as e:
print '\nOSError [{0}]: {1}'.format(e.errno, e.strerror)
print 'Recording stored in \'recorder.out\'\n'
qapp.connect(qapp, Qt.SIGNAL('aboutToQuit()'), begin_recording)
qapp.exec_()