diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-12-13 10:19:13 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-12-13 10:19:13 +0000 |
commit | 4a489b2f306c179e303567908a26e7e79ef5c0dd (patch) | |
tree | e6efd05a045cd972c7231a9f767503314d5683f8 /Radio | |
parent | db8995b5ca0636afe9cb845e127bd317e643f21b (diff) | |
download | PrySDR-4a489b2f306c179e303567908a26e7e79ef5c0dd.tar.gz PrySDR-4a489b2f306c179e303567908a26e7e79ef5c0dd.zip |
AirSpy: receives valid samples
Diffstat (limited to 'Radio')
-rw-r--r-- | Radio/HW/AirSpy/AirSpy.swift | 20 | ||||
-rw-r--r-- | Radio/Utils/AirSpyIQ/main.swift | 65 | ||||
-rw-r--r-- | Radio/Utils/BladeRFIQ/main.swift | 14 |
3 files changed, 94 insertions, 5 deletions
diff --git a/Radio/HW/AirSpy/AirSpy.swift b/Radio/HW/AirSpy/AirSpy.swift index d7916b2..25f5b0b 100644 --- a/Radio/HW/AirSpy/AirSpy.swift +++ b/Radio/HW/AirSpy/AirSpy.swift @@ -54,10 +54,30 @@ class AirSpy { return airspy_set_samplerate(dev, samplerate) } + func rfBias(_ rfbias: UInt8) -> Int32 { + return airspy_set_rf_bias(dev, rfbias) + } + + func VGAGain(_ vgagain: UInt8) -> Int32 { + return airspy_set_vga_gain(dev, vgagain) + } + + func mixerGain(_ gain: UInt8) -> Int32 { + return airspy_set_mixer_gain(dev, gain) + } + + func lnaGain(_ gain: UInt8) -> Int32 { + return airspy_set_lna_gain(dev, gain) + } + func startRx(_ callback: airspy_sample_block_cb_fn) -> Int32 { return airspy_start_rx(dev, callback, nil) } + func stopRx() -> Int32 { + return airspy_stop_rx(dev) + } + func setFrequency(_ freq: UInt32) -> Int32 { return airspy_set_freq(dev, freq) } diff --git a/Radio/Utils/AirSpyIQ/main.swift b/Radio/Utils/AirSpyIQ/main.swift index 7fea329..a643d5f 100644 --- a/Radio/Utils/AirSpyIQ/main.swift +++ b/Radio/Utils/AirSpyIQ/main.swift @@ -12,11 +12,11 @@ import libairspy //set the command line arguments struct CommandLineArgs: ParsableCommand { @Argument var file:String = "" - @Option(name:.shortAndLong) var serialno: UInt64 = 0 + @Option() var serial: 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 + @Option(name:.shortAndLong) var nsamples: Int = 65536 @Flag(help:"Version \(software_version)") var version: Bool = false @Flag(name: .shortAndLong) var verbose: Bool = false } @@ -43,6 +43,28 @@ if (ret != AIRSPY_SUCCESS.rawValue) { exit(1) } +//prepare file descriptor if args specify that +let currentExePath = Process().currentDirectoryPath +var fileDescriptor = FileManager.default +var fileArgUrl:URL? +var fileHandle:FileHandle? +if (args.file != "") { + fileArgUrl = URL(fileURLWithFileSystemRepresentation: args.file, isDirectory: false, relativeTo: nil) + if (checkIfFileExists(args.file)) { + //remove file + do { + try fileDescriptor.removeItem(atPath: fileArgUrl!.path()) + } catch { + print("Couldn't delete file that exists \(fileArgUrl!.path())") + } + } + + //create file + fileDescriptor.createFile(atPath: fileArgUrl!.path(), contents: nil) + try fileHandle = FileHandle(forWritingTo: fileArgUrl!) + try fileHandle?.seekToEnd() +} + var device:AirSpy? do { device = try AirSpy() @@ -53,14 +75,45 @@ do { let sample_rates = device?.getSampleRates() let _ = device?.setSampleRate(sample_rates![0]) +print("sample rate \(sample_rates![0])") -print("Here 5") +var sdr_run = true +var total_samples:Int32=0 func rf_callback(_ transffer: UnsafeMutablePointer<airspy_transfer_t>?) -> Int32 { let t = transffer!.pointee - print("Got \(t.sample_count) samples") + let rx_bufffer = t.samples + let sample_count = t.sample_count + //default value + + if (t.sample_type != AIRSPY_SAMPLE_FLOAT32_IQ) { + print("Unsupported sample type to write") + } + let bytes_to_write = sample_count*2*4 //IQ*float + + total_samples += sample_count + if total_samples > args.nsamples { + sdr_run = false + return 0 + } + + if let file = fileHandle { + let convertedData = Data(bytes: rx_bufffer!, count: Int(bytes_to_write)) + do { + try file.write(contentsOf: convertedData) + } catch { + print("Cant dump data to file") + } + } + + print("Got \(sample_count) samples") + return 0 } +let _ = device?.VGAGain(5) +let _ = device?.mixerGain(5) +let _ = device?.lnaGain(1) + let _ = device?.startRx(rf_callback) let _ = device?.setFrequency(UInt32(args.frequency)) @@ -68,12 +121,14 @@ let _ = device?.setFrequency(UInt32(args.frequency)) sleep(1) var count = 10 while ((device?.isStreaming() != AIRSPY_TRUE.rawValue) -&& (count>0)) { +&& (count>0) && (sdr_run)) { print("Streaming") sleep(1) count -= 1 } +let _ = device?.stopRx() + let _ = device?.close() airspy_exit() diff --git a/Radio/Utils/BladeRFIQ/main.swift b/Radio/Utils/BladeRFIQ/main.swift new file mode 100644 index 0000000..a4f2ffe --- /dev/null +++ b/Radio/Utils/BladeRFIQ/main.swift @@ -0,0 +1,14 @@ +// +// main.swift +// BladeRFIQ +// +// Created by Jacky Jack on 12/12/2024. +// + +import Foundation +import ArgumentParser +import libbladerf + +print("Hello, World!") + + |