diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-12-12 12:10:52 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-12-12 12:10:52 +0000 |
commit | db8995b5ca0636afe9cb845e127bd317e643f21b (patch) | |
tree | fbf4997689bc746fbdecc3a028124bfbc9bdbc66 /Radio/HW/AirSpy/AirSpy.swift | |
parent | f2ab0f6a053c7f8d4c5a3a227678a013e533ca90 (diff) | |
download | PrySDR-db8995b5ca0636afe9cb845e127bd317e643f21b.tar.gz PrySDR-db8995b5ca0636afe9cb845e127bd317e643f21b.zip |
AirSpy: moved to use airspy device wrapper
Diffstat (limited to 'Radio/HW/AirSpy/AirSpy.swift')
-rw-r--r-- | Radio/HW/AirSpy/AirSpy.swift | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/Radio/HW/AirSpy/AirSpy.swift b/Radio/HW/AirSpy/AirSpy.swift index 5b1b109..d7916b2 100644 --- a/Radio/HW/AirSpy/AirSpy.swift +++ b/Radio/HW/AirSpy/AirSpy.swift @@ -6,9 +6,67 @@ // import libairspy +enum AirspyHFError: Error { + case InvalidDevice +} + /// Wrapper for libairspy library class AirSpy { - init() { - airspy_init() + + var dev:UnsafeMutablePointer<airspy_device_t>? = .allocate(capacity: 1) + var sample_rates:[UInt32] = [] + + init(serialno: UInt64) throws { + let ret = airspy_open_sn(&dev, serialno) + if (ret != AIRSPY_SUCCESS.rawValue) { + throw AirspyHFError.InvalidDevice + } + } + + /// will open first device it can find + init() throws { + let ret = airspy_open(&dev) + if ret != AIRSPY_SUCCESS.rawValue { + print("Couldnt open airspy device") + throw AirspyHFError.InvalidDevice + } + } + + func getSampleRates() -> [UInt32] { + if sample_rates.count == 0 { + + let nscount: UnsafeMutablePointer<UInt32> = .allocate(capacity: 1) + ret = airspy_get_samplerates(dev, nscount, 0) + + let samplerates_buf:UnsafeMutableBufferPointer<UInt32> = .allocate(capacity: Int(nscount.pointee)) + let rawPointer = UnsafeMutablePointer<UInt32>?(samplerates_buf.baseAddress!) + ret = airspy_get_samplerates(dev, rawPointer, nscount.pointee) + + sample_rates = [] + for i in 0..<Int(nscount.pointee) { + sample_rates.append(samplerates_buf[i]) + } + } + return sample_rates + } + + func setSampleRate(_ samplerate: UInt32 ) -> Int32 { + return airspy_set_samplerate(dev, samplerate) + } + + func startRx(_ callback: airspy_sample_block_cb_fn) -> Int32 { + return airspy_start_rx(dev, callback, nil) + } + + func setFrequency(_ freq: UInt32) -> Int32 { + return airspy_set_freq(dev, freq) + } + + func isStreaming() -> Int32 { + return airspy_is_streaming(dev) + } + + func close() -> Int32 { + return airspy_close(dev) } } |