summaryrefslogtreecommitdiff
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
parentabbe14bebb2935b017b980e6fc2bfc5e94052049 (diff)
downloadPrySDR-f2ab0f6a053c7f8d4c5a3a227678a013e533ca90.tar.gz
PrySDR-f2ab0f6a053c7f8d4c5a3a227678a013e533ca90.zip
AirSpy: basic receiving samples works, not tested actual data yet
-rw-r--r--PrySDR.xcodeproj/project.pbxproj22
-rw-r--r--Radio/HW/AirSpy/src/airspy.c41
-rw-r--r--Radio/HW/AirSpy/src/airspy.h46
-rw-r--r--Radio/Utils/AirSpyIQ/main.swift94
-rw-r--r--Radio/Utils/TestAirSpy/main.swift2
5 files changed, 160 insertions, 45 deletions
diff --git a/PrySDR.xcodeproj/project.pbxproj b/PrySDR.xcodeproj/project.pbxproj
index 5ae568c..415a2d0 100644
--- a/PrySDR.xcodeproj/project.pbxproj
+++ b/PrySDR.xcodeproj/project.pbxproj
@@ -42,6 +42,9 @@
8D4068552CFDBB6D0064C96D /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 8D4068542CFDBB6D0064C96D /* ArgumentParser */; };
8D4068562CFDBB740064C96D /* libairspyhf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5A5D9F2CD439360096CBD7 /* libairspyhf.a */; };
8D4068582CFDBB8F0064C96D /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 8D4068572CFDBB8F0064C96D /* ArgumentParser */; };
+ 8D4070082D08316E0064C96D /* libusb.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5A5DDA2CD4B9100096CBD7 /* libusb.a */; };
+ 8D4070092D0831730064C96D /* libairspy.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5A5D752CD436BC0096CBD7 /* libairspy.a */; };
+ 8D40700B2D0831760064C96D /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 8D40700A2D0831760064C96D /* ArgumentParser */; };
8D5A5DAD2CD439D70096CBD7 /* libairspy.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5A5D752CD436BC0096CBD7 /* libairspy.a */; };
8D5A5DAE2CD439DA0096CBD7 /* libairspyhf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5A5D9F2CD439360096CBD7 /* libairspyhf.a */; };
8D5A5DF02CD4B97E0096CBD7 /* libusb.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5A5DDA2CD4B9100096CBD7 /* libusb.a */; };
@@ -291,7 +294,7 @@
8D5A5E162CD4BEAF0096CBD7 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
8D5A5E182CD4BEB60096CBD7 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
8D5A5E1A2CD4BECD0096CBD7 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
- 8D876E5E2CD4CE890082EC54 /* test_airpsy */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_airpsy; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8D876E5E2CD4CE890082EC54 /* test_airspy */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_airspy; sourceTree = BUILT_PRODUCTS_DIR; };
8D876E772CD4DB8F0082EC54 /* test_airspyhf */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_airspyhf; sourceTree = BUILT_PRODUCTS_DIR; };
8D876FFD2CD4F1620082EC54 /* test_bladerf */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_bladerf; sourceTree = BUILT_PRODUCTS_DIR; };
8D87709D2CD6B4BB0082EC54 /* libbladerf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libbladerf.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -864,6 +867,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 8D40700B2D0831760064C96D /* ArgumentParser in Frameworks */,
+ 8D4070092D0831730064C96D /* libairspy.a in Frameworks */,
+ 8D4070082D08316E0064C96D /* libusb.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1007,7 +1013,7 @@
8D5A5DB42CD4B70D0096CBD7 /* libr820.a */,
8D5A5DDA2CD4B9100096CBD7 /* libusb.a */,
8D5A5E082CD4BAF10096CBD7 /* test_rtlsdr */,
- 8D876E5E2CD4CE890082EC54 /* test_airpsy */,
+ 8D876E5E2CD4CE890082EC54 /* test_airspy */,
8D876E772CD4DB8F0082EC54 /* test_airspyhf */,
8D876FFD2CD4F1620082EC54 /* test_bladerf */,
8D87709D2CD6B4BB0082EC54 /* libbladerf.a */,
@@ -1127,6 +1133,7 @@
);
name = AirSpyIQ;
packageProductDependencies = (
+ 8D40700A2D0831760064C96D /* ArgumentParser */,
);
productName = AirSpyIQ;
productReference = 8D4068452CFDA6B80064C96D /* airspy_iq */;
@@ -1248,7 +1255,7 @@
packageProductDependencies = (
);
productName = TestAirSpy;
- productReference = 8D876E5E2CD4CE890082EC54 /* test_airpsy */;
+ productReference = 8D876E5E2CD4CE890082EC54 /* test_airspy */;
productType = "com.apple.product-type.tool";
};
8D876E762CD4DB8F0082EC54 /* TestAirSpyHF */ = {
@@ -1884,7 +1891,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 53B26AJZ4Z;
ENABLE_HARDENED_RUNTIME = YES;
- PRODUCT_NAME = test_airpsy;
+ PRODUCT_NAME = test_airspy;
SWIFT_VERSION = 5.0;
};
name = Debug;
@@ -1895,7 +1902,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 53B26AJZ4Z;
ENABLE_HARDENED_RUNTIME = YES;
- PRODUCT_NAME = test_airpsy;
+ PRODUCT_NAME = test_airspy;
SWIFT_VERSION = 5.0;
};
name = Release;
@@ -2336,6 +2343,11 @@
package = 8D0349232CF70E180026DA77 /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
productName = ArgumentParser;
};
+ 8D40700A2D0831760064C96D /* ArgumentParser */ = {
+ isa = XCSwiftPackageProductDependency;
+ package = 8D0349232CF70E180026DA77 /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
+ productName = ArgumentParser;
+ };
/* End XCSwiftPackageProductDependency section */
};
rootObject = 8DD98C392CC592540062D678 /* Project object */;
diff --git a/Radio/HW/AirSpy/src/airspy.c b/Radio/HW/AirSpy/src/airspy.c
index 02c1542..8ca11fc 100644
--- a/Radio/HW/AirSpy/src/airspy.c
+++ b/Radio/HW/AirSpy/src/airspy.c
@@ -39,15 +39,9 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include "iqconverter_int16.h"
#include "filters.h"
-#ifndef bool
-typedef int bool;
-#define true 1
-#define false 0
-#endif
-
#define PACKET_SIZE (12)
#define UNPACKED_SIZE (16)
-#define RAW_BUFFER_COUNT (8)
+
#ifdef AIRSPY_BIG_ENDIAN
#define TO_LE(x) __builtin_bswap32(x)
@@ -76,39 +70,6 @@ typedef struct {
uint32_t freq_hz;
} set_freq_params_t;
-typedef struct airspy_device
-{
- libusb_context* usb_context;
- libusb_device_handle* usb_device;
- struct libusb_transfer** transfers;
- airspy_sample_block_cb_fn callback;
- volatile bool streaming;
- volatile bool stop_requested;
- pthread_t transfer_thread;
- pthread_t consumer_thread;
- bool transfer_thread_running;
- bool consumer_thread_running;
- pthread_cond_t consumer_cv;
- pthread_mutex_t consumer_mp;
- uint32_t supported_samplerate_count;
- uint32_t *supported_samplerates;
- uint32_t transfer_count;
- uint32_t buffer_size;
- uint32_t dropped_buffers;
- uint32_t dropped_buffers_queue[RAW_BUFFER_COUNT];
- uint16_t *received_samples_queue[RAW_BUFFER_COUNT];
- volatile int received_samples_queue_head;
- volatile int received_samples_queue_tail;
- volatile int received_buffer_count;
- void *output_buffer;
- uint16_t *unpacked_samples;
- bool packing_enabled;
- iqconverter_float_t *cnv_f;
- iqconverter_int16_t *cnv_i;
- void* ctx;
- enum airspy_sample_type sample_type;
-} airspy_device_t;
-
static const uint16_t airspy_usb_vid = 0x1d50;
static const uint16_t airspy_usb_pid = 0x60a1;
diff --git a/Radio/HW/AirSpy/src/airspy.h b/Radio/HW/AirSpy/src/airspy.h
index 573298b..3a778ee 100644
--- a/Radio/HW/AirSpy/src/airspy.h
+++ b/Radio/HW/AirSpy/src/airspy.h
@@ -26,7 +26,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#define __AIRSPY_H__
#include <stdint.h>
+#include "libusb.h"
#include "airspy_commands.h"
+#include "iqconverter_float.h"
+#include "iqconverter_int16.h"
#define AIRSPY_VERSION "1.0.12"
#define AIRSPY_VER_MAJOR 1
@@ -116,8 +119,51 @@ typedef struct {
uint32_t revision;
} airspy_lib_version_t;
+#ifndef bool
+typedef int bool;
+#define true 1
+#define false 0
+#endif
+
typedef int (*airspy_sample_block_cb_fn)(airspy_transfer* transfer);
+#define RAW_BUFFER_COUNT (8)
+
+typedef struct airspy_device
+{
+ libusb_context* usb_context;
+ libusb_device_handle* usb_device;
+ struct libusb_transfer** transfers;
+ airspy_sample_block_cb_fn callback;
+ volatile bool streaming;
+ volatile bool stop_requested;
+ pthread_t transfer_thread;
+ pthread_t consumer_thread;
+ bool transfer_thread_running;
+ bool consumer_thread_running;
+ pthread_cond_t consumer_cv;
+ pthread_mutex_t consumer_mp;
+ uint32_t supported_samplerate_count;
+ uint32_t *supported_samplerates;
+ uint32_t transfer_count;
+ uint32_t buffer_size;
+ uint32_t dropped_buffers;
+ uint32_t dropped_buffers_queue[RAW_BUFFER_COUNT];
+ uint16_t *received_samples_queue[RAW_BUFFER_COUNT];
+ volatile int received_samples_queue_head;
+ volatile int received_samples_queue_tail;
+ volatile int received_buffer_count;
+ void *output_buffer;
+ uint16_t *unpacked_samples;
+ bool packing_enabled;
+ iqconverter_float_t *cnv_f;
+ iqconverter_int16_t *cnv_i;
+ void* ctx;
+ enum airspy_sample_type sample_type;
+} airspy_device_t;
+
+
+
extern ADDAPI void ADDCALL airspy_lib_version(airspy_lib_version_t* lib_version);
/* airspy_init() deprecated */
extern ADDAPI int ADDCALL airspy_init(void);
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()
diff --git a/Radio/Utils/TestAirSpy/main.swift b/Radio/Utils/TestAirSpy/main.swift
index 13b37d2..091d979 100644
--- a/Radio/Utils/TestAirSpy/main.swift
+++ b/Radio/Utils/TestAirSpy/main.swift
@@ -11,3 +11,5 @@ import libairspy
print("Version \(software_version)")
airspy_init()
+
+