-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
71 lines (57 loc) · 2.53 KB
/
Program.cs
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
using System;
using System.Runtime.InteropServices;
namespace bladedotnet
{
class Program
{
static void Main(string[] args)
{
var handle = GetDeviceHandle();
Console.WriteLine("Device handle: " + handle);
if (handle == IntPtr.Zero)
{
Console.WriteLine("No device detected");
return;
}
AttachXB200(handle);
var sampleRate = 5_000_000;
var srResult = SetSampleRate(handle, 0, (int)sampleRate);
Console.WriteLine("Set sample rate " + sampleRate + ": " + srResult);
var centerFreq = 107_500_000;
var cfResult = SetCenterFreq(handle, 0, (int)centerFreq);
Console.WriteLine("Set center frequency " + centerFreq + ": " + cfResult);
}
public static IntPtr GetDeviceHandle()
{
IntPtr handle;
BladeRFOpen(out handle, null);
return handle;
}
public static bool SetSampleRate(IntPtr handle, int channel, int sampleRate)
{
int current;
BladeRFSetSampleRate(handle, channel, sampleRate, out current);
return current == sampleRate;
}
public static bool SetCenterFreq(IntPtr handle, int channel, int centerFreq)
{
int result = BladeRFSetFrequency(handle, channel, centerFreq);
return result == 0;
}
public static void AttachXB200(IntPtr handle)
{
BladeRFExpansionAttach(handle, 2);
BladeRFXB200SetFilterbank(handle, 0, 3);
}
[DllImport(dllName: "libbladeRF", EntryPoint="bladerf_open")]
public static extern int BladeRFOpen(out IntPtr handle, string id);
[DllImport(dllName: "libbladeRF", EntryPoint="bladerf_set_sample_rate")]
public static extern int BladeRFSetSampleRate(IntPtr handle, int channel, int value, out int current);
[DllImport(dllName: "libbladeRF", EntryPoint="bladerf_set_frequency")]
public static extern int BladeRFSetFrequency(IntPtr handle, int channel, int value);
[DllImport(dllName: "libbladeRF", EntryPoint="bladerf_expansion_attach")]
public static extern int BladeRFExpansionAttach(IntPtr handle, int xb);
[DllImport(dllName: "libbladeRF", EntryPoint="bladerf_xb200_set_filterbank")]
public static extern int BladeRFXB200SetFilterbank(IntPtr handle, int channel, int filter);
}
}