bin/pwn_gqrx_scanner in pwn-0.5.54 vs bin/pwn_gqrx_scanner in pwn-0.5.55

- old
+ new

@@ -29,33 +29,45 @@ options.on('-AFLOAT', '--audio-gain=FLOAT', '<Optional - Set audio gain -80.0 to 50.0 (Defaults to 1.0)>') do |a| opts[:audio_gain_db] = a end - options.on('-BHZ', '--bandwidth=HZ', '<Optional - Set Bandwidth (Defaults to 200.000)>') do |b| + options.on('-bHZ', '--bandwidth=HZ', '<Optional - Set Bandwidth (Defaults to 200.000)>') do |b| opts[:bandwidth] = b end options.on('-DMODE', '--demodulator-mode=MODE', '<Optional - Set Demodulator ModeOFF | RAW | AM | FM | WFM | WFM_ST | WFM_ST_OIRT | LSB |USB | CW | CWL | CWU (Defaults to WFM_ST)>') do |d| opts[:demodulator_mode] = d end - options.on('-LFLOAT', '--lock-freq-duration=FLOAT', '<Optional - Duration to lock onto Freqency when Strength < --strength value (Defaults to 3)>') do |l| + options.on('-PINT', '--precision=INT', '<Optional - Precision of Frequency 1-12 (Defaults to 6)>') do |p| + opts[:precision] = p + end + + options.on('-SFLOAT', '--strength-lock=FLOAT', '<Optional - Strength to trigger lock on frequency (Defaults to -55.0)>') do |s| + opts[:strength_lock] = s + end + + options.on('-LFLOAT', '--lock-freq-duration=FLOAT', '<Optional - Duration to lock onto Freqency when Strength < --strength-lock value (Defaults to 5.0)>') do |l| opts[:lock_on_freq_duration] = l end - options.on('-QFLOAT', '--squelch=FLOAT', '<Optional - Squelch Threshold -150 to 0(Defaults to -63.0)>') do |q| + options.on('-QFLOAT', '--squelch=FLOAT', '<Optional - Squelch Threshold -65.0 to 0(Defaults to -150.0)>') do |q| opts[:squelch] = q end - options.on('-PINT', '--precision=INT', '<Optional - Precision of Frequency 1-12 (Defaults to 6)>') do |p| - opts[:precision] = p + options.on('-RFLOAT', '--rf-gain=FLOAT', '<Optional - RF Gain 0.0-16.0(Defaults to 16.0)>') do |r| + opts[:rf_gain] = r end - options.on('-SFLOAT', '--strength=FLOAT', '<Optional - Strength to trigger sleep (Defaults to -63.3)>') do |s| - opts[:strength] = s + options.on('-IFLOAT', '--intermediate-gain=FLOAT', '<Optional - Intermediate Gain 0.0-40.0 (Defaults to 40.0)>') do |i| + opts[:intermediate_gain] = i end + + options.on('-BFLOAT', '--basedband-gain=FLOAT', '<Optional - Baseband Gain 0.0-62.0 (Defaults to 0.0)>') do |b| + opts[:baseband_gain] = b + end end.parse! if opts.empty? puts `#{$PROGRAM_NAME} --help` exit 1 @@ -140,11 +152,11 @@ gqrx_sock.write("#{cmd}\n") response = [] got_freq = false # Read all responses from gqrx_sock.write - timeout = 0.01 if timeout.nil? + timeout = 0.03 if timeout.nil? begin response.push(gqrx_sock.readline.chomp) while gqrx_sock.wait_readable(timeout) raise IOError if response.empty? rescue IOError timeout += 0.001 @@ -176,11 +188,11 @@ gqrx_sock = opts[:gqrx_sock] demodulator_mode = opts[:demodulator_mode] bandwidth = opts[:bandwidth] this_freq = opts[:this_freq] lock_on_freq_duration = opts[:lock_on_freq_duration] - strength = opts[:strength] + strength_lock = opts[:strength_lock] demod_n_passband = gqrx_cmd( gqrx_sock: gqrx_sock, cmd: 'm' ) @@ -194,36 +206,54 @@ current_freq = gqrx_cmd( gqrx_sock: gqrx_sock, cmd: 'f' ) + audio_gain_db = gqrx_cmd( + gqrx_sock: gqrx_sock, + cmd: 'l AF' + ).to_f + current_strength = gqrx_cmd( gqrx_sock: gqrx_sock, cmd: 'l STRENGTH' ).to_f current_squelch = gqrx_cmd( gqrx_sock: gqrx_sock, cmd: 'l SQL' ).to_f - audio_gain_db = gqrx_cmd( + rf_gain = gqrx_cmd( gqrx_sock: gqrx_sock, - cmd: 'l AF' + cmd: 'l RF_GAIN' ).to_f + if_gain = gqrx_cmd( + gqrx_sock: gqrx_sock, + cmd: 'l IF_GAIN' + ).to_f + + bb_gain = gqrx_cmd( + gqrx_sock: gqrx_sock, + cmd: 'l BB_GAIN' + ).to_f + init_freq_hash = { demod_mode_n_passband: demod_n_passband, frequency: current_freq, audio_gain_db: audio_gain_db, squelch: current_squelch, + rf_gain: rf_gain, + if_gain: if_gain, + bb_gain: bb_gain, strength: current_strength, - trigger_lock_on_freq_strength: strength + strength_trigger_lock_on_freq: strength_lock } puts JSON.pretty_generate(init_freq_hash) - sleep lock_on_freq_duration if current_strength < strength + sleep lock_on_freq_duration if current_strength > strength_lock init_freq_hash end def scan_range(opts = {}) @@ -232,11 +262,11 @@ bandwidth = opts[:bandwidth] start_freq = opts[:start_freq] target_freq = opts[:target_freq] precision = opts[:precision] lock_on_freq_duration = opts[:lock_on_freq_duration] - strength = opts[:strength] + strength_lock = opts[:strength_lock] multiplier = 10**(precision - 1) if start_freq > target_freq start_freq.downto(target_freq) do |this_freq| next unless (i % multiplier).zero? @@ -245,11 +275,11 @@ gqrx_sock: gqrx_sock, demodulator_mode: demodulator_mode, bandwidth: bandwidth, this_freq: this_freq, lock_on_freq_duration: lock_on_freq_duration, - strength: strength + strength_lock: strength_lock ) end else this_freq = start_freq while this_freq <= target_freq @@ -257,11 +287,11 @@ gqrx_sock: gqrx_sock, demodulator_mode: demodulator_mode, bandwidth: bandwidth, this_freq: this_freq, lock_on_freq_duration: lock_on_freq_duration, - strength: strength + strength_lock: strength_lock ) this_freq += multiplier end end @@ -299,11 +329,19 @@ gqrx_sock: gqrx_sock, cmd: "M #{demodulator_mode} #{bandwidth}", resp_ok: 'RPRT 0' ) - squelch = opts[:squelch] ||= -63.0 + audio_gain_db = opts[:audio_gain_db] ||= 1.0 + audio_gain_db = audio_gain_db.to_f + audio_gain_db_resp = gqrx_cmd( + gqrx_sock: gqrx_sock, + cmd: "L AF #{audio_gain_db}", + resp_ok: 'RPRT 0' + ) + + squelch = opts[:squelch] ||= -65.0 squelch = squelch.to_f squelch_resp = gqrx_cmd( gqrx_sock: gqrx_sock, cmd: "L SQL #{squelch}", resp_ok: 'RPRT 0' @@ -311,24 +349,40 @@ precision = opts[:precision] ||= 6 precision = precision.to_i raise "ERROR: Invalid precision: #{precision}" unless (1..12).include?(precision) - lock_on_freq_duration = opts[:lock_on_freq_duration] ||= 3 + lock_on_freq_duration = opts[:lock_on_freq_duration] ||= 5.0 lock_on_freq_duration = lock_on_freq_duration.to_f - strength = opts[:strength] ||= -63.3 - strength = strength.to_f + strength_lock = opts[:strength_lock] ||= -55.0 + strength_lock = strength_lock.to_f - audio_gain_db = opts[:audio_gain_db] ||= 1.0 - audio_gain_db = audio_gain_db.to_f - audio_gain_db_resp = gqrx_cmd( + rf_gain = opts[:rf_gain] ||= 16.0 + rf_gain = rf_gain.to_f + squelch_resp = gqrx_cmd( gqrx_sock: gqrx_sock, - cmd: "L AF #{audio_gain_db}", + cmd: "L RF_GAIN #{rf_gain}", resp_ok: 'RPRT 0' ) + intermediate_gain = opts[:intermediate_gain] ||= 40.0 + intermediate_gain = intermediate_gain.to_f + squelch_resp = gqrx_cmd( + gqrx_sock: gqrx_sock, + cmd: "L IF_GAIN #{intermediate_gain}", + resp_ok: 'RPRT 0' + ) + + baseband_gain = opts[:baseband_gain] ||= 0.0 + baseband_gain = baseband_gain.to_f + squelch_resp = gqrx_cmd( + gqrx_sock: gqrx_sock, + cmd: "L BB_GAIN #{baseband_gain}", + resp_ok: 'RPRT 0' + ) + s_freq_pretty = start_freq.to_s.chars.insert(-4, '.').insert(-8, '.').join t_freq_pretty = target_freq.to_s.chars.insert(-4, '.').insert(-8, '.').join puts "*** Scanning from #{s_freq_pretty} to #{t_freq_pretty}" scan_range( @@ -336,10 +390,10 @@ demodulator_mode: demodulator_mode, start_freq: start_freq, target_freq: target_freq, precision: precision, lock_on_freq_duration: lock_on_freq_duration, - strength: strength, + strength_lock: strength_lock, squelch: squelch ) puts 'Scan Complete.' rescue StandardError => e raise e