summaryrefslogtreecommitdiff
path: root/hardware/r820.swift
blob: 63921d72b90306931d17bc8c3c9391a39925b5ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
//  r820.swift
//  r820sdr-init
//
//  Created by Jacky Jack on 15/03/2022.
//

import Foundation

public class R820API {
    
    
    func R820() {
        print("Start device API")
    }
    
    func getDeviceCount() -> UInt32 {
        return rtlsdr_get_device_count()
    }
    
    
    
}

public class R820Tuner {
    var deviceInitalized:Bool = false
    var dev:       OpaquePointer?  = nil
    
    /**
            Function to initialise tunner
        - Parameters:
            -
     */
    func R820Tuner() {
        print("Initialise tunner")
    }
    
    func open(index devId: UInt32) {
        let err = rtlsdr_open(&dev,devId)
        if (err != 0) {
            print("Error couldnt open device")
            return
        }
        deviceInitalized = true
    }
    
    func close() {
        if self.deviceInitalized {
            rtlsdr_close(dev);
            dev = nil
        }
    }
    
    func getCenterFrequency()->UInt32 {
        return rtlsdr_get_center_freq(dev)
    }
    
    func setCenterFrequency(freq: UInt32) -> Int32 {
        return rtlsdr_set_center_freq(dev, freq)
    }
    
    func getSampleRate() -> UInt32 {
        return rtlsdr_get_sample_rate(dev)
    }
    
    func setSampleRate(samplerate: UInt32) -> Int32 {
        return rtlsdr_set_sample_rate(dev, samplerate)
    }
    
    
    
}