diff options
Diffstat (limited to 'Radio/Utils')
-rw-r--r-- | Radio/Utils/RtlSdrIQ/main.swift | 62 | ||||
-rw-r--r-- | Radio/Utils/TestRtlSdr/main.swift | 14 |
2 files changed, 72 insertions, 4 deletions
diff --git a/Radio/Utils/RtlSdrIQ/main.swift b/Radio/Utils/RtlSdrIQ/main.swift new file mode 100644 index 0000000..20573a9 --- /dev/null +++ b/Radio/Utils/RtlSdrIQ/main.swift @@ -0,0 +1,62 @@ +// +// main.swift +// RtlSdrIQ +// +// Created by Jacky Jack on 27/11/2024. +// + +import Foundation +import libr820 +import ArgumentParser + +//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 = 2048000 + @Option(name:.shortAndLong) var gain: Int = 0 + @Option(name: .shortAndLong) var frequency: Int = 100000000 + @Option(name:.shortAndLong) var nsamples: Int = 1024 + @Flag(name: .shortAndLong) var verbose: Bool = false + @Flag(name: .shortAndLong) var async: Bool = false +} + +let args = CommandLineArgs.parseOrExit() + +//check that there is any devices +let count = getDeviceCount() +if count < 1 { + print("There is not R820 tunner found on this machine") + exit(0) +} + +//check that argument index is withing range +if (args.device_idx < 0) || (args.device_idx > count-1) { + print("Index is out of range, devices found \(count)") + exit(0) +} + +//initialise structure without a connected driver +let device = R820Tuner() +device.open(index: UInt32(args.device_idx)) + +let _ = device.setSampleRate(samplerate: UInt32(args.samplerate)) +let _ = device.setCenterFreq(freq: UInt32(args.frequency)) +if args.gain == 0 { + let _ = device.setAgcMode(on: 1) +} else { + let _ = device.setTunerGain(gain: Int32(args.gain)) +} +let _ = device.resetBuffer() +let buf_ptr = UnsafeMutableRawPointer.allocate(byteCount: args.nsamples, alignment: 1) +var nbytes:Int32 = 0 +let r = device.readSync(buf: buf_ptr, len: Int32(args.nsamples), n_read: &nbytes) +print("Reading samples return code (\(r)) read \(nbytes) bytes\n") +for i in 0..<args.nsamples { + let offsetByte = buf_ptr + i + print("\(String(format:"%02hhX ",offsetByte.load(as: UInt8.self)))",terminator: "") +} +device.close() + +buf_ptr.deallocate() + diff --git a/Radio/Utils/TestRtlSdr/main.swift b/Radio/Utils/TestRtlSdr/main.swift index 7b10d05..39e1c06 100644 --- a/Radio/Utils/TestRtlSdr/main.swift +++ b/Radio/Utils/TestRtlSdr/main.swift @@ -8,8 +8,14 @@ import Foundation import libr820 -let rtldev = R820Tuner() -let count = rtldev.getDeviceCount() -rtldev.open(index: 0) -rtldev.close() + +let count = getDeviceCount() +print("Found \(count) r820 devices") +//rtldev.open(index: 0) +//rtldev.close() +for dev_idx in 0..<count { + let rtldev = R820Tuner() + rtldev.open(index: dev_idx) + rtldev.close() +} |