diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-12-22 09:45:59 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-12-22 09:45:59 +0000 |
commit | b999f85d83728bd7034e85f2e038bb9a6454b16a (patch) | |
tree | 9a680554c7b89dc3f939b8082bee1eb0ccf7ebee /Radio | |
parent | 4a489b2f306c179e303567908a26e7e79ef5c0dd (diff) | |
download | PrySDR-main.tar.gz PrySDR-main.zip |
BladeRF: seems to receive datamain
Diffstat (limited to 'Radio')
-rw-r--r-- | Radio/HW/AirSpy/AirSpy.swift | 3 | ||||
-rw-r--r-- | Radio/Utils/AirSpyIQ/main.swift | 2 | ||||
-rw-r--r-- | Radio/Utils/BladeRFIQ/main.swift | 106 |
3 files changed, 110 insertions, 1 deletions
diff --git a/Radio/HW/AirSpy/AirSpy.swift b/Radio/HW/AirSpy/AirSpy.swift index 25f5b0b..61623c6 100644 --- a/Radio/HW/AirSpy/AirSpy.swift +++ b/Radio/HW/AirSpy/AirSpy.swift @@ -33,6 +33,9 @@ class AirSpy { } func getSampleRates() -> [UInt32] { + + var ret: Int32 = 0 + if sample_rates.count == 0 { let nscount: UnsafeMutablePointer<UInt32> = .allocate(capacity: 1) diff --git a/Radio/Utils/AirSpyIQ/main.swift b/Radio/Utils/AirSpyIQ/main.swift index a643d5f..5cfb048 100644 --- a/Radio/Utils/AirSpyIQ/main.swift +++ b/Radio/Utils/AirSpyIQ/main.swift @@ -111,7 +111,9 @@ func rf_callback(_ transffer: UnsafeMutablePointer<airspy_transfer_t>?) -> Int32 } let _ = device?.VGAGain(5) + let _ = device?.mixerGain(5) + let _ = device?.lnaGain(1) let _ = device?.startRx(rf_callback) diff --git a/Radio/Utils/BladeRFIQ/main.swift b/Radio/Utils/BladeRFIQ/main.swift index a4f2ffe..cc748f2 100644 --- a/Radio/Utils/BladeRFIQ/main.swift +++ b/Radio/Utils/BladeRFIQ/main.swift @@ -9,6 +9,110 @@ import Foundation import ArgumentParser import libbladerf -print("Hello, World!") +//set the command line arguments +struct CommandLineArgs: ParsableCommand { + @Argument var file:String = "" + @Option() var serial: UInt64 = 0 + @Option(name:.shortAndLong) var samplerate: Int = 200000 + @Option(name:.shortAndLong) var gain: Int = 0 + @Option(name:.shortAndLong) var frequency: Int = 100000000 + @Option(name:.shortAndLong) var nsamples: Int = 65536 + @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) +} + +//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 version: bladerf_version = bladerf_version() +bladerf_version(&version) +print(version.describe!) + +var device: OpaquePointer? + +var ret: Int32 + +ret = bladerf_open(&device,nil) +print("ret=\(ret)") + +var actual_samplerate: UnsafeMutablePointer<bladerf_sample_rate> = .allocate(capacity: 1) + +ret = bladerf_set_sample_rate(device, 0, UInt32(args.samplerate), actual_samplerate) +print("ret=\(ret)") + +ret = bladerf_set_frequency(device, 0, UInt64(args.frequency)) +print("ret=\(ret)") + + +let NUM_SAMPLES=8192 +let SYNC_TIMEOUT=500 +ret = bladerf_sync_config(device, bladerf_channel_layout(0), BLADERF_FORMAT_SC16_Q11, 16, UInt32(NUM_SAMPLES), 8, UInt32(SYNC_TIMEOUT)) +print("ret=\(ret)") + +ret = bladerf_enable_module(device, 0, true) +print("ret=\(ret)") + + + +let buf_ptr = UnsafeMutableRawPointer.allocate(byteCount: NUM_SAMPLES, alignment: 1) + +var total_samples:Int32=0 +//var count=100 +var done=false +while (!done) { + ret = bladerf_sync_rx(device, buf_ptr, UInt32(NUM_SAMPLES), nil, UInt32(SYNC_TIMEOUT)) + if (ret != 0) { + print("RX failed: \(ret)") + done=true + } else { + print("Received \(NUM_SAMPLES) bytes") + + if let file = fileHandle { + let convertedData = Data(bytes: buf_ptr, count: NUM_SAMPLES) + do { + try file.write(contentsOf: convertedData) + } catch { + print("Cant dump data to file") + } + } + + total_samples += Int32(NUM_SAMPLES) + if total_samples > args.nsamples { + done=true + } + } + //count -= 1 + print("ret=\(ret)") +} + +ret = bladerf_enable_module(device, 0, false) +print("bladerf_enable_module ret=\(ret)") + + +bladerf_close(device) |