airspyInput

class airspyInput : public kotekan::Stage

Producer kotekan::Stage which streams radio data from an AirSpy SDR device into a Buffer.

This is a simple producer which initializes an AirSpy dongle (https://airspy.com) in streaming mode, filling samples into the provided kotekan buffer. It is agnostic about buffer framesize, simply filling in its data until a frame is full, marking it so, requesting a new one, and continuing. An internal sub-frame pointer is used to position data in subsequent callbacks within frames. A pthread mutex is used to ensure callbacks don’t clobber one another.

Samples are read in AIRSPY_SAMPLE_RAW mode (real 12-bit ADC values, packed in 16-bit shorts). On each completed frame the producer subtracts the 2048-count ADC offset and applies an alternating-sign multiplication to shift the spectrum into the first Nyquist zone, then marks the frame full.

This producer depends on libairspy.

Buffers

  • out_buf The kotekan buffer which will be fed; any size.

    • Format: Array of shorts (real samples, DC-corrected and Nyquist-shifted)

    • Metadata: none

REST endpoints (registered under @unique_name/)

  • GET /get_config — returns current gain/freq/samplerate as JSON.

  • GET /adcstat — triggers a one-shot ADC stats sample (mean, RMS, rail fraction).

  • GET /restart — stops, re-opens, and re-starts the airspy device.

  • POST /set_config — updates freq, gain_lna, gain_mix, gain_if, or add_lag.

Author

Keith Vanderlinde

Warning

If incoming USB transfers ever overlap, sample ordering becomes undefined.

Param freq:

Float (default 1420.0). LO tuning frequency, in MHz.

Param sample_bw:

Float (default 2.5). Sample rate (samples/s), in MHz. Must be a value reported by airspy_get_samplerates() for the connected device (typically 2.5 or 10).

Param gain_lna:

Int (default 5). Gain setting of the LNA, in the range 0-14.

Param gain_mix:

Int (default 5). Gain setting of the mixer amplifier, from 0-15.

Param gain_if:

Int (default 5). Gain setting of the IF amplifier, from 0-15.

Param biast_power:

Bool (default false). Enable 4.5V DC bias on the RF input.

Param dither_disable:

Bool (default false). Disable the R820T tuner’s fractional-N PLL dither (reg 0x12 bit 4) for coherent multi-unit operation: eliminates per-restart inter-unit LO drift at fractional tunes, at the cost of deterministic fractional-N spurs (common-mode in cross-products and absorbable into a per-unit complex g-cal). Leave at default (dither on) for single-dongle / autocorr work where the spurs are undesirable.

Param serial:

Long (default 0). Specific airspy serial-number to open; 0 = any.

Param airspy_file:

String (default “”). Read from this file instead of a real device; for offline testing. Ignored if serial is set.

Param autostart:

Bool (default true). Start streaming immediately. If false, the device is initialised but waits for a REST /restart to begin RX.

Public Functions

airspyInput(kotekan::Config &config, const std::string &unique_name, kotekan::bufferContainer &buffer_container)
~airspyInput() override
virtual void main_thread() override
struct airspy_device *init_device()

Initialises the airspy device. Also configures gains, LO tuning, samplerate, and sample type.

void airspy_producer(airspy_transfer_t *transfer)

Fills kotekan buffer frames from one USB transfer. See class doc.

void get_config_callback(kotekan::connectionInstance &conn)

REST callbacks.

void set_config_callback(kotekan::connectionInstance &conn, nlohmann::json &json_request)
void adcstat_callback(kotekan::connectionInstance &conn)
void restart_callback(kotekan::connectionInstance &conn)

Public Static Functions

static int airspy_callback(airspy_transfer_t *transfer)

libairspy DMA-callback trampoline; forwards to airspy_producer on the ctx instance.