Class: TurtleShell::Device
- Inherits:
-
Object
- Object
- TurtleShell::Device
- Defined in:
- lib/turtleshell/device.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #center_frequency ⇒ Object
- #center_frequency=(freq) ⇒ Object
- #close_device ⇒ Object
- #gain ⇒ Object
- #gain=(gain) ⇒ Object
-
#get_available_gains ⇒ Object
most devices only support a finite number of gain values.
-
#initialize(n = 0) ⇒ Device
constructor
A new instance of Device.
-
#read_samples(number_of_samples = 1024) ⇒ Object
read specified number of complex samples from tuner real and imaginary parts are normalized between [-1, 1].
-
#read_samples_async(number_of_samples = 1024, &block) ⇒ Object
read specified number of complex samples from tuner into a block real and imaginary parts are normalized between [-1, 1].
- #sample_rate ⇒ Object
- #sample_rate=(rate) ⇒ Object
Constructor Details
#initialize(n = 0) ⇒ Device
Returns a new instance of Device.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/turtleshell/device.rb', line 8 def initialize(n = 0) raise ArgumentError.new('TurtleShell::Device.new expects a number') unless n.is_a? Fixnum unless raw_device_attrs = TurtleShell::RTLSDR.nth_device(n) raise TurtleShell::DeviceNotFoundError end @name = raw_device_attrs[:name] @device = raw_device_attrs[:device] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/turtleshell/device.rb', line 6 def name @name end |
Class Method Details
.device_with_name(name) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/turtleshell/device.rb', line 19 def self.device_with_name(name) unless index = TurtleShell.all_devices.index(name) raise ArgumentError.new('No device with that name') end new(index) end |
Instance Method Details
#center_frequency ⇒ Object
35 36 37 |
# File 'lib/turtleshell/device.rb', line 35 def center_frequency TurtleShell::RTLSDR.get_center_freq(@device) end |
#center_frequency=(freq) ⇒ Object
39 40 41 |
# File 'lib/turtleshell/device.rb', line 39 def center_frequency=(freq) TurtleShell::RTLSDR.set_center_freq(@device, freq) end |
#close_device ⇒ Object
83 84 85 86 87 |
# File 'lib/turtleshell/device.rb', line 83 def close_device unless @device.nil? TurtleShell::RTLSDR.close_device(@device) end end |
#gain ⇒ Object
43 44 45 |
# File 'lib/turtleshell/device.rb', line 43 def gain TurtleShell::RTLSDR.get_gain(@device) end |
#gain=(gain) ⇒ Object
47 48 49 |
# File 'lib/turtleshell/device.rb', line 47 def gain=(gain) TurtleShell::RTLSDR.set_gain(@device, gain) end |
#get_available_gains ⇒ Object
most devices only support a finite number of gain values
52 53 54 |
# File 'lib/turtleshell/device.rb', line 52 def get_available_gains TurtleShell::RTLSDR.get_tuner_gains(@device) end |
#read_samples(number_of_samples = 1024) ⇒ Object
read specified number of complex samples from tuner real and imaginary parts are normalized between [-1, 1]
58 59 60 61 62 |
# File 'lib/turtleshell/device.rb', line 58 def read_samples(number_of_samples = 1024) number_of_bytes = 2 * number_of_samples raw_data = read_bytes(number_of_bytes) packed_bytes_to_complex(raw_data) end |
#read_samples_async(number_of_samples = 1024, &block) ⇒ Object
read specified number of complex samples from tuner into a block real and imaginary parts are normalized between [-1, 1]
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/turtleshell/device.rb', line 66 def read_samples_async(number_of_samples = 1024, &block) block = proc { } unless block_given? wrapped_block = proc do |raw_data| block.call(packed_bytes_to_complex(raw_data)) end number_of_bytes_to_read = 2 * number_of_samples begin TurtleShell::RTLSDR.read_async(@device, number_of_bytes_to_read, wrapped_block) rescue SignalException => e puts 'Caught signal, cancelling async callback.' TurtleShell::RTLSDR.end_async(@device) raise e end end |
#sample_rate ⇒ Object
27 28 29 |
# File 'lib/turtleshell/device.rb', line 27 def sample_rate TurtleShell::RTLSDR.get_sample_rate(@device) end |
#sample_rate=(rate) ⇒ Object
31 32 33 |
# File 'lib/turtleshell/device.rb', line 31 def sample_rate=(rate) TurtleShell::RTLSDR.set_sample_rate(@device, rate) end |