Class: HackRF::Device::Radio

Inherits:
Object
  • Object
show all
Defined in:
lib/hackrf/device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Radio

Returns a new instance of Radio.



11
12
13
14
15
16
17
18
19
# File 'lib/hackrf/device.rb', line 11

def initialize(ptr)
  @ptr  = ptr
  @mode = nil

  @spiflash = HackRF::Internals::SPIFlash.new(self)
  @max2837  = HackRF::Internals::MAX2837.new(self)
  @si5351c  = HackRF::Internals::Si5351C.new(self)
  @rffc5071 = HackRF::Internals::RFFC5071.new(self)
end

Instance Attribute Details

#max2837Object (readonly)

Returns the value of attribute max2837.



9
10
11
# File 'lib/hackrf/device.rb', line 9

def max2837
  @max2837
end

#ptrObject (readonly)

Returns the value of attribute ptr.



9
10
11
# File 'lib/hackrf/device.rb', line 9

def ptr
  @ptr
end

#rffc5071Object (readonly)

Returns the value of attribute rffc5071.



9
10
11
# File 'lib/hackrf/device.rb', line 9

def rffc5071
  @rffc5071
end

#si5351cObject (readonly)

Returns the value of attribute si5351c.



9
10
11
# File 'lib/hackrf/device.rb', line 9

def si5351c
  @si5351c
end

#spiflashObject (readonly)

Returns the value of attribute spiflash.



9
10
11
# File 'lib/hackrf/device.rb', line 9

def spiflash
  @spiflash
end

Class Method Details

.finalize(device) ⇒ Object



36
37
38
# File 'lib/hackrf/device.rb', line 36

def self.finalize(device)
  HackRF
end

.openObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hackrf/device.rb', line 21

def self.open
  ptr = FFI::MemoryPointer.new(:pointer)

  HackRF.hackrf_open(ptr)

  device = new(ptr.read_pointer)

  if block_given?
    yield device
    device.close
  else
    return device
  end
end

Instance Method Details

#amp=(value) ⇒ Object



54
55
56
# File 'lib/hackrf/device.rb', line 54

def amp=(value)
  HackRF.hackrf_set_amp_enable(self,value)
end

#antenna=(value) ⇒ Object



70
71
72
# File 'lib/hackrf/device.rb', line 70

def antenna=(value)
  HackRF.hackrf_set_antenna_enable(self,value)
end

#baseband_filter_bandwidth=(bandwidth) ⇒ Object



40
41
42
# File 'lib/hackrf/device.rb', line 40

def baseband_filter_bandwidth=(bandwidth)
  HackRF.hackrf_set_baseband_filter_bandwidth(self,bandwidth)
end

#closeObject



109
110
111
112
113
114
# File 'lib/hackrf/device.rb', line 109

def close
  ret = HackRF.hackrf_close(self)
  @ptr = nil
  
  return ret
end

#closed?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/hackrf/device.rb', line 105

def closed?
  @ptr.nil?
end

#frequency=(freq) ⇒ Object Also known as: freq=



44
45
46
# File 'lib/hackrf/device.rb', line 44

def frequency=(freq)
  HackRF.hackrf_set_freq(self,freq)
end

#lna_gain=(gain) ⇒ Object



58
59
60
# File 'lib/hackrf/device.rb', line 58

def lna_gain=(gain)
  HackRF.hackrf_set_lna_gain(self,gain)
end

#rx(&block) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/hackrf/device.rb', line 78

def rx(&block)
  @mode = :rx
  @rx_callback = callback(&block)
  
  HackRF.hackrf_start_rx(self,@rx_callback,nil)
  
  @rx_callback = nil
  @mode = nil
end

#sample_rate=(rate) ⇒ Object



50
51
52
# File 'lib/hackrf/device.rb', line 50

def sample_rate=(rate)
  HackRF.hackrf_set_sample_rate(self,rate)
end

#stopObject



98
99
100
101
102
103
# File 'lib/hackrf/device.rb', line 98

def stop
  case @mode
  when :rx then HackRF.hackrf_stop_rx(self)
  when :tx then HackRF.hackrf_stop_tx(self)
  end
end

#streaming?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/hackrf/device.rb', line 74

def streaming?
  HackRF.hackrf_is_streaming(self) == :true
end

#to_ptrObject



116
117
118
# File 'lib/hackrf/device.rb', line 116

def to_ptr
  @ptr
end

#tx(&block) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/hackrf/device.rb', line 88

def tx(&block)
  @mode = :tx
  @tx_callback = callback(&block)
  
  HackRF.hackrf_start_tx(self,@tx_callback,nil)
  
  @tx_callback = nil
  @mode = nil
end

#txvga_gain=(gain) ⇒ Object



66
67
68
# File 'lib/hackrf/device.rb', line 66

def txvga_gain=(gain)
  HackRF.hackrf_set_txvga_gain(self,gain)
end

#vga_gain=(gain) ⇒ Object



62
63
64
# File 'lib/hackrf/device.rb', line 62

def vga_gain=(gain)
  HackRF.hackrf_set_vga_gain(self,gain)
end