This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

updates pyrtlsdr to rtl-sdr new gain api

By: a guest on May 5th, 2012  |  syntax: Diff  |  size: 2.03 KB  |  views: 112  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --- rtlsdr.py.orig      2012-05-05 15:49:57.927996434 +0200
  2. +++ rtlsdr.py   2012-05-05 16:07:36.028005368 +0200
  3. @@ -11,6 +11,9 @@
  4.      has_numpy = False
  5.      
  6.  class BaseRtlSdr(object):
  7. +    #Gain values in tenths of a dB
  8. +    GAIN_VALUES = [-10, 15, 40, 65, 90, 115, 140, 165, 190, \
  9. +        215, 240, 290, 340, 420, 430, 450, 470, 490]
  10.      DEFAULT_GAIN = 1
  11.      DEFAULT_FC = 80e6
  12.      DEFAULT_RS = 1e6
  13. @@ -40,6 +43,7 @@
  14.          # set default state
  15.          self.set_sample_rate(self.DEFAULT_RS)
  16.          self.set_center_freq(self.DEFAULT_FC)
  17. +        self.manual_gain_mode = False
  18.          self.set_gain(self.DEFAULT_GAIN)
  19.          
  20.      def close(self):
  21. @@ -75,6 +79,21 @@
  22.          center_freq = round(reported_center_freq, -3)
  23.          
  24.          return center_freq
  25. +    
  26. +    def get_gain_mode(self):
  27. +        return self.manual_gain_mode
  28. +    
  29. +    def set_gain_mode(self, manual):
  30. +        manual = int(manual)
  31. +        
  32. +        result = librtlsdr.rtlsdr_set_tuner_gain_mode(self.dev_p, manual)        
  33. +        if result < 0:
  34. +            self.close()
  35. +            raise IOError('Error code %d when setting gain mode rate to %d'\
  36. +                          % (result, manual))
  37. +        
  38. +        self.manual_gain_mode = manual != 0
  39. +        return
  40.          
  41.      def set_sample_rate(self, rate):
  42.          rate = int(rate)
  43. @@ -103,7 +122,10 @@
  44.          return real_rate
  45.          
  46.      def set_gain(self, gain):
  47. -        gain = int(gain)
  48. +        gain = self.GAIN_VALUES[int(gain)]
  49. +        
  50. +        if not self.manual_gain_mode:
  51. +            self.set_gain_mode(True)
  52.          
  53.          result = librtlsdr.rtlsdr_set_tuner_gain(self.dev_p, gain)        
  54.          if result < 0:
  55. @@ -180,6 +202,7 @@
  56.      
  57.      center_freq = fc = property(get_center_freq, set_center_freq)
  58.      sample_rate = rs = property(get_sample_rate, set_sample_rate)
  59. +    manual_gain = property(get_gain_mode, set_gain_mode)
  60.      gain = property(get_gain, set_gain)
  61.  
  62.  # This adds async read support to base class BaseRtlSdr (don't use that one)
clone this paste RAW Paste Data