summaryrefslogtreecommitdiff
path: root/Radio/HW
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-11-28 11:37:28 +0000
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-11-28 11:37:28 +0000
commit77d1cfc27fb72e442b8d8e5cbe2be143723724e5 (patch)
treec42913e5fa3f2c0c23c9eeadd61c39f2a317a206 /Radio/HW
parentcf4444e7390365df43ecbd3d130015c1e06ef88f (diff)
downloadPrySDR-77d1cfc27fb72e442b8d8e5cbe2be143723724e5.tar.gz
PrySDR-77d1cfc27fb72e442b8d8e5cbe2be143723724e5.zip
RtlSdrIQ: read samples from device. Using command line arguments
Diffstat (limited to 'Radio/HW')
-rw-r--r--Radio/HW/RtlSdr/r820/r820.swift79
1 files changed, 51 insertions, 28 deletions
diff --git a/Radio/HW/RtlSdr/r820/r820.swift b/Radio/HW/RtlSdr/r820/r820.swift
index f5e1177..3f6d4a9 100644
--- a/Radio/HW/RtlSdr/r820/r820.swift
+++ b/Radio/HW/RtlSdr/r820/r820.swift
@@ -6,14 +6,45 @@
//
//https://www.kodeco.com/7181017-unsafe-swift-using-pointers-and-interacting-with-c
+// THis is just a wrapper for fun
+
import Foundation
-//import TestRtlSdr
import libr820
+
+/// Gets the number of rtlsdr's detected in system
+/// - Returns: return number of devices detected
+///
+func getDeviceCount() -> UInt32 {
+ return rtlsdr_get_device_count()
+}
+
+/// Search for device index from serial number
+/// - Parameters:
+/// - serial: serial string of device
+/// - Returns: return the index number if found, -1 if not found
+///
+func getIndexBySerial(serial: String) -> Int32
+{
+ return rtlsdr_get_index_by_serial(serial);//is this ok?
+}
+
+//TODO: investigate getDeviceName
+/*
+func getDeviceName(index: UInt32) -> String {
+ return rtlsdr_get_device_name(index)
+}*/
+
+//TODO: investigate getDeviceUsbString
+
+/*
+ func getDeviceUsbString() {
+ return rtlsdr_get_device_usb_strings();
+ }*/
+
+/// Wrapper for librtlsdr functions that's not operating on device
public class R820API {
-
-
func R820() {
print("Start device API")
}
@@ -21,24 +52,23 @@ public class R820API {
func getDeviceCount() -> UInt32 {
return rtlsdr_get_device_count()
}
-
-
-
}
+/// Wrapper for rtlsdr that works with device API
public class R820Tuner {
var deviceInitalized:Bool = false
var dev: OpaquePointer? = nil
/**
- Function to initialise tunner
- - Parameters:
- -
+ Function to initialise tunner, do nothing at the moment
*/
func R820Tuner() {
print("Initialise tunner")
}
+ /// open device by Index, checks if device allready were initialised within class
+ /// - Parameters:
+ /// - index: device index to open
func open(index devId: UInt32) {
let err = rtlsdr_open(&dev,devId)
if (err != 0) {
@@ -48,6 +78,7 @@ public class R820Tuner {
deviceInitalized = true
}
+ /// close device if it was opened before
func close() {
if self.deviceInitalized {
rtlsdr_close(dev);
@@ -55,25 +86,6 @@ public class R820Tuner {
}
}
- func getDeviceCount()->UInt32 {
- return rtlsdr_get_device_count();
- }
-
- /*
- func getDeviceName(index: UInt32) -> String {
- return rtlsdr_get_device_name(index)
- }
- */
-
- /*
- func getDeviceUsbString() {
- return rtlsdr_get_device_usb_strings();
- }*/
- func getIndexBySerial(serial: String) -> Int32
- {
- return rtlsdr_get_index_by_serial(serial);//is this ok?
- }
-
func setXtalFreq(rtlFreq: UInt32, tunnerFreq: UInt32) -> Int32 {
return rtlsdr_set_xtal_freq(dev, rtlFreq, tunnerFreq);
}
@@ -171,6 +183,15 @@ public class R820Tuner {
return rtlsdr_reset_buffer(dev)
}
+ /// Read the data from buffer in sync manner
+ /// - Parameters:
+ /// - buf: input buffer
+ /// - len: input buffer length
+ /// - n_read: number of bytes received
+ /// - Returns: -1 if there is no device, 0 on success or one of LIBUSB error
+ /// LIBUSB_ERROR_TIMEOUT, LIBUSB_ERROR_PIPE,LIBUSB_ERROR_OVERFLOW
+ /// LIBUSB_ERROR_NO_DEVICE, LIBUSB_ERROR_BUSY LIBUSB_ERROR_INVALID_PARAM
+ ///
func readSync(buf:UnsafeMutableRawPointer?,len: Int32,n_read:UnsafeMutablePointer<Int32>?) -> Int32 {
return rtlsdr_read_sync(dev, buf, len, n_read);
}
@@ -183,6 +204,8 @@ public class R820Tuner {
return rtlsdr_read_async(dev, cb, ctx, buf_num, buf_len)
}
+ /// Cancel async operation for sighandlders
+ /// to exit from callbacks
func cancelAsync() -> Int32 {
return rtlsdr_cancel_async(dev);
}