Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes to adapt to Python 3 on GNURadio 3.8 #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/am_flow_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
print("Warning: failed to XInitThreads()")

from PyQt4 import Qt
from gnuradio import analog
Expand Down
12 changes: 6 additions & 6 deletions apps/cursesgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def draw_spectrum(self, data):
# Clear previous contents, draw border, and title
self.win.clear()
self.win.border(0)
self.win.addnstr(0, self.dims[1]/2-4, "SPECTRUM", 8,
self.win.addnstr(0, int(self.dims[1]/2-4), "SPECTRUM", 8,
curses.color_pair(4))

# Draw the bars
Expand Down Expand Up @@ -191,7 +191,7 @@ def draw_channels(self, gui_tuned_channels):
# Clear previous contents, draw border, and title
self.win.clear()
self.win.border(0)
self.win.addnstr(0, self.dims[1]/2-4, "CHANNELS", 8,
self.win.addnstr(0, int(self.dims[1]/2-4), "CHANNELS", 8,
curses.color_pair(4))

# Limit the displayed channels to no more than two rows
Expand Down Expand Up @@ -247,7 +247,7 @@ def draw_channels(self, gui_lockout_channels):
# Clear previous contents, draw border, and title
self.win.clear()
self.win.border(0)
self.win.addnstr(0, self.dims[1]/2-3, "LOCKOUT", 7,
self.win.addnstr(0, int(self.dims[1]/2-3), "LOCKOUT", 7,
curses.color_pair(4))

# Draw the lockout channels
Expand Down Expand Up @@ -354,7 +354,7 @@ def draw_rx(self):
# Clear previous contents, draw border, and title
self.win.clear()
self.win.border(0)
self.win.addnstr(0, self.dims[1]/2-4, "RECEIVER", 8,
self.win.addnstr(0, int(self.dims[1]/2-4), "RECEIVER", 8,
curses.color_pair(4))

# Draw the receiver info prefix fields
Expand All @@ -380,7 +380,7 @@ def draw_rx(self):
self.win.addnstr(10, 1, text, 15)

# Draw the receiver info suffix fields
if self.freq_entry <> 'None':
if self.freq_entry != 'None':
text = self.freq_entry
else:
text = '{:.3f}'.format((self.center_freq)/1E6)
Expand Down Expand Up @@ -471,7 +471,7 @@ def proc_keyb_hard(self, keyb):
pass
self.freq_entry = 'None'
return True
elif self.freq_entry <> 'None' and (keyb - 48 in range (10) or keyb == ord('.')):
elif self.freq_entry != 'None' and (keyb - 48 in range (10) or keyb == ord('.')):
# build up frequency from 1-9 and '.'
self.freq_entry = self.freq_entry + chr(keyb)
return False
Expand Down
26 changes: 13 additions & 13 deletions apps/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,30 @@ def main():
""" Tests the functions in this module"""

# Test avg_freq()
print "Testing avg_freq()"
print("Testing avg_freq()")
data = np.array([0, 1, 1, 0])
print "Input spectrum data is " + str(data)
print("Input spectrum data is " + str(data))
result = avg_freq(data)
print "Average frequency is " + str(result)
print("Average frequency is " + str(result))
if result == 1.5:
print "Test Pass"
print("Test Pass")
else:
print "Test Fail"
print ""
print("Test Fail")
print("")

# Test channel_estimate()
print "Testing channel_estimate()"
print("Testing channel_estimate()")
data = np.array([0, 1, 1, 0, 0, 1, 1, 1])
threshold = 0.5
print "Input spectrum data is " + str(data)
print "Threshold is " + str(threshold)
print("Input spectrum data is " + str(data))
print("Threshold is " + str(threshold))
result = channel_estimate(data, threshold)
print "Channels at " + str(result)
print("Channels at " + str(result))
if result == [1.5, 6.0]:
print "Test Pass"
print("Test Pass")
else:
print "Test Fail"
print ""
print("Test Fail")
print("")


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions apps/ham2mon.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def main(screen):
PARSER = parser.CLParser()
if len(PARSER.parser_args) != 0:
PARSER.print_help() #pylint: disable=maybe-no-member
raise SystemExit, 1
raise(SystemExit, 1)
else:
curses.wrapper(main)
except KeyboardInterrupt:
pass
except RuntimeError:
print ""
print "RuntimeError: SDR hardware not detected or insufficient USB permissions. Try running as root."
print ""
print("")
print("RuntimeError: SDR hardware not detected or insufficient USB permissions. Try running as root.")
print("")

2 changes: 1 addition & 1 deletion apps/nbfm_flow_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
print("Warning: failed to XInitThreads()")

from PyQt4 import Qt
from gnuradio import analog
Expand Down
36 changes: 18 additions & 18 deletions apps/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,24 @@ def main():

if len(parser.parser_args) != 0:
parser.print_help() #pylint: disable=maybe-no-member
raise SystemExit, 1

print "hw_args: " + parser.hw_args
print "num_demod: " + str(parser.num_demod)
print "type_demod: " + str(parser.type_demod)
print "center_freq: " + str(parser.center_freq)
print "ask_samp_rate: " + str(parser.ask_samp_rate)
print "gain_db: " + str(parser.gain_db)
print "if_gain_db: " + str(parser.if_gain_db)
print "bb_gain_db: " + str(parser.bb_gain_db)
print "squelch_db: " + str(parser.squelch_db)
print "volume_db: " + str(parser.volume_db)
print "threshold_db: " + str(parser.threshold_db)
print "record: " + str(parser.record)
print "lockout_file_name: " + str(parser.lockout_file_name)
print "priority_file_name: " + str(parser.priority_file_name)
print "freq_correction: " + str(parser.freq_correction)
print "audio_bps: " + str(parser.audio_bps)
raise(SystemExit, 1)

print("hw_args: " + parser.hw_args)
print("num_demod: " + str(parser.num_demod))
print("type_demod: " + str(parser.type_demod))
print("center_freq: " + str(parser.center_freq))
print("ask_samp_rate: " + str(parser.ask_samp_rate))
print("gain_db: " + str(parser.gain_db))
print("if_gain_db: " + str(parser.if_gain_db))
print("bb_gain_db: " + str(parser.bb_gain_db))
print("squelch_db: " + str(parser.squelch_db))
print("volume_db: " + str(parser.volume_db))
print("threshold_db: " + str(parser.threshold_db))
print("record: " + str(parser.record))
print("lockout_file_name: " + str(parser.lockout_file_name))
print("priority_file_name: " + str(parser.priority_file_name))
print("freq_correction: " + str(parser.freq_correction))
print("audio_bps: " + str(parser.audio_bps))


if __name__ == '__main__':
Expand Down
18 changes: 9 additions & 9 deletions apps/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,14 @@ def main():
center_freq = 144.5E6
receiver.set_center_freq(center_freq)
receiver.set_gain(10)
print "\n"
print "Started %s at %.3f Msps" % (hw_args, receiver.samp_rate/1E6)
print "RX at %.3f MHz with %d dB gain" % (receiver.center_freq/1E6,
receiver.gain_db)
print("\n")
print("Started %s at %.3f Msps" % (hw_args, receiver.samp_rate/1E6))
print("RX at %.3f MHz with %d dB gain" % (receiver.center_freq/1E6,
receiver.gain_db))
receiver.set_squelch(-60)
receiver.set_volume(0)
print "%d demods of type %d at %d dB squelch and %d dB volume" % \
(num_demod, type_demod, receiver.squelch_db, receiver.volume_db)
print("%d demods of type %d at %d dB squelch and %d dB volume" % \
(num_demod, type_demod, receiver.squelch_db, receiver.volume_db))

# Create some baseband channels to tune based on 144 MHz center
channels = np.zeros(num_demod)
Expand All @@ -622,9 +622,9 @@ def main():

# Print demodulator info
for idx, channel in enumerate(channels):
print "Tuned demod %d to %.3f MHz" % (idx,
print("Tuned demod %d to %.3f MHz" % (idx,
(channel+receiver.center_freq)
/1E6)
/1E6))

while 1:
# No need to go faster than 10 Hz rate of GNU Radio probe
Expand All @@ -633,7 +633,7 @@ def main():

# Grab the FFT data and print max value
spectrum = receiver.probe_signal_vf.level()
print "Max spectrum of %.3f" % (np.max(spectrum))
print("Max spectrum of %.3f" % (np.max(spectrum)))

# Stop the receiver
receiver.stop()
Expand Down
19 changes: 11 additions & 8 deletions apps/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

@author: madengr
"""
import __builtin__
try:
import builtins
except:
import __builtin__
import receiver as recvr
import estimate
import parser as prsr
Expand Down Expand Up @@ -348,7 +351,7 @@ def main():

if len(parser.parser_args) != 0:
parser.print_help() #pylint: disable=maybe-no-member
raise SystemExit, 1
raise(SystemExit, 1)

# Create scanner object
ask_samp_rate = parser.ask_samp_rate
Expand All @@ -369,14 +372,14 @@ def main():
scanner.set_gain(parser.gain_db)
scanner.set_if_gain(parser.if_gain_db)
scanner.set_bb_gain(parser.bb_gain_db)
print "\n"
print "Started %s at %.3f Msps" % (hw_args, scanner.samp_rate/1E6)
print "RX at %.3f MHz with %d dB gain" % (scanner.center_freq/1E6,
scanner.gain_db)
print("\n")
print("Started %s at %.3f Msps" % (hw_args, scanner.samp_rate/1E6))
print("RX at %.3f MHz with %d dB gain" % (scanner.center_freq/1E6,
scanner.gain_db))
scanner.set_squelch(parser.squelch_db)
scanner.set_volume(parser.volume_db)
print "%d demods of type %d at %d dB squelch and %d dB volume" % \
(num_demod, type_demod, scanner.squelch_db, scanner.volume_db)
print("%d demods of type %d at %d dB squelch and %d dB volume" % \
(num_demod, type_demod, scanner.squelch_db, scanner.volume_db))

# Create this epmty list to allow printing to screen
old_gui_tuned_channels = []
Expand Down