// // main.swift // AirSpyIQ // // Created by Jacky Jack on 02/12/2024. // import Foundation import ArgumentParser import libairspy //set the command line arguments struct CommandLineArgs: ParsableCommand { @Argument var file:String = "" @Option(name:.shortAndLong) var serialno: UInt64 = 0 @Option(name:.shortAndLong) var samplerate: Int = 3000000 @Option(name:.shortAndLong) var gain: Int = 0 @Option(name:.shortAndLong) var frequency: Int = 100000000 @Option(name:.shortAndLong) var nsamples: Int = 1024 @Flag(help:"Version \(software_version)") var version: Bool = false @Flag(name: .shortAndLong) var verbose: Bool = false } let args = CommandLineArgs.parseOrExit() if (args.version) { print("AirSpyIQ version \(software_version)") exit(0) } var libersion:airspy_lib_version_t = airspy_lib_version_t() airspy_lib_version(&libersion) print("libairspy \(libersion.major_version).\(libersion.minor_version).\(libersion.revision)") //detect number of devices var dev:UnsafeMutablePointer? = .allocate(capacity: 1) var ret:Int32 ret = airspy_init() if (ret != AIRSPY_SUCCESS.rawValue) { print("Couldnt init library") exit(1) } var device:AirSpy? do { device = try AirSpy() } catch { print("Cant attach to device") } let sample_rates = device?.getSampleRates() let _ = device?.setSampleRate(sample_rates![0]) print("Here 5") func rf_callback(_ transffer: UnsafeMutablePointer?) -> Int32 { let t = transffer!.pointee print("Got \(t.sample_count) samples") return 0 } let _ = device?.startRx(rf_callback) let _ = device?.setFrequency(UInt32(args.frequency)) sleep(1) var count = 10 while ((device?.isStreaming() != AIRSPY_TRUE.rawValue) && (count>0)) { print("Streaming") sleep(1) count -= 1 } let _ = device?.close() airspy_exit()