Requires libairspy at least 1.0.6 already built and installed on your system.
Tests require an attached Airspy (otherwise there is not much to test!) and
must be run with RUST_TEST_THREADS=1
or the threads may stomp on each other.
The basic gist is:
- Make new Airspy object
- Configure it using
set_sample_rate
,set_freq
, etc - Create a MPSC channel for data transfer
- Use
start_rx<T>
to begin transfer to your channel, specifying desired sample type withT
(see below) - Call
rx.recv()
on your side to read in the data buffers - When your half of the channel is destroyed, the Airspy is stopped
Sample types are set by the T
in start_rx<T>
. It can be any of:
IQ<f32>
IQ<i16>
Real<f32>
Real<i16>
Real<u16>
The type is passed to libairspy which does the conversion from the native
Real<u16>
. Note that Real
types give you twice as many samples per time
period than IQ
. Also note that Real<T>
is just an alias for T
, and
IQ<T>
for Complex<T>
, so all the usual maths operations are available for
both types.
Simple usage example:
extern crate airspy;
use airspy::{Airspy,IQ};
use std::sync::mpsc;
// Open first available Airspy and configure for floating IQ samples,
// 10Msps, 434MHz (can also set gains, AGC, RF bias etc).
let mut dev = Airspy::new().unwrap();
dev.set_sample_rate(0).unwrap();
dev.set_freq(434000000).unwrap();
// Samples are sent back to us from the C thread by an MPSC channel
let (tx, rx) = mpsc::channel();
// Begin receiving data, ask for f32 IQ samples.
// This implies that the mpsc channel will have type Vec<IQ<f32>>.
dev.start_rx::<IQ<f32>>(tx).unwrap();
// Blocking receive samples, stop after 10M. When the `rx` object goes out of
// scope and is destroyed, the `tx` detects the hangup and tells libairspy to
// stop data reception.
let mut n_samples = 0usize;
while dev.is_streaming() {
let samples = rx.recv().unwrap();
n_samples += samples.len();
println!("Got {} samples so far", n_samples);
if n_samples > 10_000_000 {
break;
}
}
See src/bin/rx.rs
for a complete example of logging IQ data to file, or
asfmrs for an example application
(narrowband FM demodulation to audio output).