summaryrefslogtreecommitdiff
path: root/Radio/Utils/AirSpyIQ
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-12-12 09:51:24 +0000
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-12-12 09:51:24 +0000
commitf2ab0f6a053c7f8d4c5a3a227678a013e533ca90 (patch)
tree8214b263c26e83c756b0c580358d5bd86ca9674b /Radio/Utils/AirSpyIQ
parentabbe14bebb2935b017b980e6fc2bfc5e94052049 (diff)
downloadPrySDR-f2ab0f6a053c7f8d4c5a3a227678a013e533ca90.tar.gz
PrySDR-f2ab0f6a053c7f8d4c5a3a227678a013e533ca90.zip
AirSpy: basic receiving samples works, not tested actual data yet
Diffstat (limited to 'Radio/Utils/AirSpyIQ')
-rw-r--r--Radio/Utils/AirSpyIQ/main.swift94
1 files changed, 94 insertions, 0 deletions
diff --git a/Radio/Utils/AirSpyIQ/main.swift b/Radio/Utils/AirSpyIQ/main.swift
index 2d6f0fd..1fa6b04 100644
--- a/Radio/Utils/AirSpyIQ/main.swift
+++ b/Radio/Utils/AirSpyIQ/main.swift
@@ -9,3 +9,97 @@ import Foundation
import ArgumentParser
import libairspy
+//set the command line arguments
+struct CommandLineArgs: ParsableCommand {
+ @Argument var file:String = ""
+ @Option(name:.shortAndLong) var device_idx: Int = 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
+//let AIRSPY_MAX_DEVICES=32
+//var device:airspy_device_t = airspy_device_t()
+//var device:UnsafeMutablePointer<OpaquePointer?>?
+var dev:UnsafeMutablePointer<airspy_device_t>? = .allocate(capacity: 1)
+
+var ret:Int32
+ret = airspy_init()
+if (ret != AIRSPY_SUCCESS.rawValue) {
+ print("Couldnt init library")
+ exit(1)
+}
+
+print("Here")
+
+ret = airspy_open(&dev)
+
+let sample_rate_count: UnsafeMutablePointer<UInt32> = .allocate(capacity: 1)
+print("Here 2 \(sample_rate_count)")
+ret = airspy_get_samplerates(dev, sample_rate_count, 0)
+print("ret = \(ret)")
+print("Here 3")
+print("Number of supported sample rates \(sample_rate_count.pointee)")
+
+var samplerates:UnsafeMutableBufferPointer<UInt32> = .allocate(capacity: Int(sample_rate_count.pointee))
+let rawPointer = UnsafeMutablePointer<UInt32>?(samplerates.baseAddress!)
+ret = airspy_get_samplerates(dev, rawPointer, sample_rate_count.pointee)
+print("ret=\(ret)")
+for i in 0..<sample_rate_count.pointee {
+ print("sample rate \(i): \(samplerates[Int(i)])")
+}
+
+print("Here 4")
+ret = airspy_set_samplerate(dev, 3000000) //3M
+if (ret != AIRSPY_SUCCESS.rawValue) {
+ print("Couldnt set samplerate")
+}
+
+print("Here 5")
+func rf_callback(_ transffer: UnsafeMutablePointer<airspy_transfer_t>?) -> Int32 {
+ print("Got some samples")
+ return 0
+}
+
+print("Here 6")
+ret = airspy_start_rx(dev, rf_callback, nil)
+if (ret != AIRSPY_SUCCESS.rawValue) {
+ print("Couldn't start rf thread")
+}
+
+print("Here 7")
+ret = airspy_set_freq(dev, 100000000) //100M
+if (ret != AIRSPY_SUCCESS.rawValue) {
+ print("Couldn't set frequency")
+}
+
+print("Here 8")
+sleep(1)
+var count = 10
+while((airspy_is_streaming(dev) != AIRSPY_TRUE.rawValue)
+&& (count>0)) {
+ print("Streaming")
+ sleep(1)
+ count -= 1
+}
+print("Here 9")
+
+airspy_close(dev)
+airspy_exit()