From db8995b5ca0636afe9cb845e127bd317e643f21b Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Thu, 12 Dec 2024 12:10:52 +0000 Subject: AirSpy: moved to use airspy device wrapper --- Radio/HW/AirSpy/AirSpy.swift | 62 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'Radio/HW/AirSpy') 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? = .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 = .allocate(capacity: 1) + ret = airspy_get_samplerates(dev, nscount, 0) + + let samplerates_buf:UnsafeMutableBufferPointer = .allocate(capacity: Int(nscount.pointee)) + let rawPointer = UnsafeMutablePointer?(samplerates_buf.baseAddress!) + ret = airspy_get_samplerates(dev, rawPointer, nscount.pointee) + + sample_rates = [] + for i in 0.. 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) } } -- cgit v1.2.3