Module: RTLSDR::FFI

Extended by:
FFI::Library
Defined in:
lib/rtlsdr/ffi.rb

Overview

Note:

Most users should use the high-level RTLSDR::Device class instead of calling these FFI functions directly.

Low-level FFI bindings to librtlsdr

The FFI module provides direct 1:1 bindings to the librtlsdr C library, exposing all native functions with their original signatures and behaviors. This module handles library loading from multiple common locations and defines all necessary data types, constants, and function prototypes.

This is the foundation layer that the high-level Device class is built upon, but can also be used directly for applications that need complete control over the C API or want to implement custom abstractions.

Features:

  • Complete librtlsdr API coverage
  • Automatic library discovery and loading
  • Proper FFI type definitions and callbacks
  • Tuner type constants and helper functions
  • Memory management support for pointers

Examples:

Direct FFI usage

device_count = RTLSDR::FFI.rtlsdr_get_device_count
device_ptr = FFI::MemoryPointer.new(:pointer)
result = RTLSDR::FFI.rtlsdr_open(device_ptr, 0)
handle = device_ptr.read_pointer
RTLSDR::FFI.rtlsdr_set_center_freq(handle, 100_000_000)

Since:

  • 0.1.0

Constant Summary collapse

RTLSDR_TUNER_UNKNOWN =

Unknown or unsupported tuner type

Since:

  • 0.1.0

0
RTLSDR_TUNER_E4000 =

Elonics E4000 tuner (52 - 2200 MHz with gaps)

Since:

  • 0.1.0

1
RTLSDR_TUNER_FC0012 =

Fitipower FC0012 tuner (22 - 948 MHz)

Since:

  • 0.1.0

2
RTLSDR_TUNER_FC0013 =

Fitipower FC0013 tuner (22 - 1100 MHz)

Since:

  • 0.1.0

3
RTLSDR_TUNER_FC2580 =

FCI FC2580 tuner (146 - 308 MHz and 438 - 924 MHz)

Since:

  • 0.1.0

4
RTLSDR_TUNER_R820T =

Rafael Micro R820T tuner (24 - 1766 MHz)

Since:

  • 0.1.0

5
RTLSDR_TUNER_R828D =

Rafael Micro R828D tuner (24 - 1766 MHz)

Since:

  • 0.1.0

6

Class Method Summary collapse

Class Method Details

.tuner_type_name(tuner_type) ⇒ String

Convert tuner type constant to human-readable name

Examples:

Get tuner name

RTLSDR::FFI.tuner_type_name(RTLSDR::FFI::RTLSDR_TUNER_R820T)
# => "Rafael Micro R820T"

Parameters:

  • tuner_type (Integer)

    One of the RTLSDR_TUNER_* constants

Returns:

  • (String)

    Human-readable tuner name with chip details

Since:

  • 0.1.0



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rtlsdr/ffi.rb', line 160

def self.tuner_type_name(tuner_type)
  case tuner_type
  when RTLSDR_TUNER_UNKNOWN then "Unknown"
  when RTLSDR_TUNER_E4000 then "Elonics E4000"
  when RTLSDR_TUNER_FC0012 then "Fitipower FC0012"
  when RTLSDR_TUNER_FC0013 then "Fitipower FC0013"
  when RTLSDR_TUNER_FC2580 then "FCI FC2580"
  when RTLSDR_TUNER_R820T then "Rafael Micro R820T"
  when RTLSDR_TUNER_R828D then "Rafael Micro R828D"
  else "Unknown (#{tuner_type})"
  end
end