From be866bf22b370f5d525b91dee6719394d5f7baa9 Mon Sep 17 00:00:00 2001 From: dianshi Date: Sat, 31 Dec 2022 13:09:00 +0000 Subject: wrapped all c calls --- hardware/r820.swift | 139 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 8 deletions(-) diff --git a/hardware/r820.swift b/hardware/r820.swift index 63921d7..366f784 100644 --- a/hardware/r820.swift +++ b/hardware/r820.swift @@ -5,6 +5,8 @@ // Created by Jacky Jack on 15/03/2022. // +//https://www.kodeco.com/7181017-unsafe-swift-using-pointers-and-interacting-with-c + import Foundation public class R820API { @@ -27,9 +29,9 @@ public class R820Tuner { var dev: OpaquePointer? = nil /** - Function to initialise tunner - - Parameters: - - + Function to initialise tunner + - Parameters: + - */ func R820Tuner() { print("Initialise tunner") @@ -51,22 +53,143 @@ public class R820Tuner { } } - func getCenterFrequency()->UInt32 { + func getDeviceCount()->UInt32 { + return rtlsdr_get_device_count(); + } + + /* + func getDeviceName(index: UInt32) -> String { + return rtlsdr_get_device_name(index) + } + */ + + /* + func getDeviceUsbString() { + return rtlsdr_get_device_usb_strings(); + }*/ + func getIndexBySerial(serial: String) -> Int32 + { + return rtlsdr_get_index_by_serial(serial);//is this ok? + } + + func setXtalFreq(rtlFreq: UInt32, tunnerFreq: UInt32) -> Int32 { + return rtlsdr_set_xtal_freq(dev, rtlFreq, tunnerFreq); + } + + func getXtalFreq(rtlFreq: UnsafeMutablePointer?, tunnerFreq: UnsafeMutablePointer?)->Int32{ + return rtlsdr_get_xtal_freq(dev, rtlFreq, tunnerFreq) + } + + func getUsbStrings(manufact: UnsafeMutablePointer?, product: UnsafeMutablePointer?, serial: UnsafeMutablePointer?) -> Int32{ + return rtlsdr_get_usb_strings(dev, manufact, product, serial) + } + + func writeEeprom(data: UnsafeMutablePointer?,offset: UInt8, len: UInt16) -> Int32 { + return rtlsdr_write_eeprom(dev, data, offset, len) + } + + func readEeprom(data: UnsafeMutablePointer?,offset: UInt8, len: UInt16) -> Int32 { + return rtlsdr_read_eeprom(dev, data, offset, len) + } + + func setCenterFreq(freq: UInt32) -> Int32{ + return rtlsdr_set_center_freq(dev, freq); + } + + func getCenterFreq()->UInt32 { return rtlsdr_get_center_freq(dev) } - func setCenterFrequency(freq: UInt32) -> Int32 { - return rtlsdr_set_center_freq(dev, freq) + func setFreqCorrection(ppm: Int32) -> Int32 { + return rtlsdr_set_freq_correction(dev, ppm) } - func getSampleRate() -> UInt32 { - return rtlsdr_get_sample_rate(dev) + func getFreqCorrection() -> Int32 { + return rtlsdr_get_freq_correction(dev) + } + + func getTunerType() -> rtlsdr_tuner { + return rtlsdr_get_tuner_type(dev) + } + + func getTunerGains(gains: UnsafeMutablePointer?) -> Int32 { + return rtlsdr_get_tuner_gains(dev, gains) + } + + func setTunerGain(gain: Int32) -> Int32 { + return rtlsdr_set_tuner_gain(dev,gain); + } + + func setTunnerBandwidth(bw: UInt32) -> Int32 { + return rtlsdr_set_tuner_bandwidth(dev, bw) + } + + func setTunerIfGain(stage: Int32, gain: Int32) -> Int32 { + return rtlsdr_set_tuner_if_gain(dev,stage,gain) + } + + func setTunerGainMode(manual: Int32) -> Int32 { + return rtlsdr_set_tuner_gain_mode(dev, manual) } func setSampleRate(samplerate: UInt32) -> Int32 { return rtlsdr_set_sample_rate(dev, samplerate) } + func getSampleRate() -> UInt32 { + return rtlsdr_get_sample_rate(dev) + } + + func setTestmode(on: Int32) -> Int32 { + return rtlsdr_set_testmode(dev, on); + } + + func setAgcMode(on: Int32) -> Int32 { + return rtlsdr_set_agc_mode(dev, on); + } + + func setDirectSampling(on: Int32) -> Int32 { + return rtlsdr_set_direct_sampling(dev, on) + } + + func getDirectSampling() -> Int32 { + return rtlsdr_get_direct_sampling(dev) + } + + func setOffsetTuning(on: Int32) -> Int32 { + return rtlsdr_set_offset_tuning(dev, on) + } + + func getOffsetTuning() -> Int32 { + return rtlsdr_get_offset_tuning(dev) + } + + func resetBuffer() -> Int32 { + return rtlsdr_reset_buffer(dev) + } + + func readSync(buf:UnsafeMutableRawPointer?,len: Int32,n_read:UnsafeMutablePointer?) -> Int32 { + return rtlsdr_read_sync(dev, buf, len, n_read); + } + + func waitAsync(cb: rtlsdr_read_async_cb_t?, ctx:UnsafeMutableRawPointer?) -> Int32{ + return rtlsdr_wait_async(dev,cb, ctx); + } + func readAsync(cb: rtlsdr_read_async_cb_t,ctx:UnsafeMutableRawPointer?, buf_num: UInt32, buf_len: UInt32) -> Int32 { + return rtlsdr_read_async(dev, cb, ctx, buf_num, buf_len) + } + + func cancelAsync() -> Int32 { + return rtlsdr_cancel_async(dev); + } + + func setBiasTee(on: Int32) -> Int32 { + return rtlsdr_set_bias_tee(dev, on) + } + + func setBiasTeeGpio(gpio: Int32, on: Int32) -> Int32 { + return rtlsdr_set_bias_tee_gpio(dev,gpio, on) + } } -- cgit v1.2.3