-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (61 loc) · 1.82 KB
/
main.cpp
File metadata and controls
73 lines (61 loc) · 1.82 KB
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
73
#include <iostream>
#include "antsdrDevice.h"
#include "unistd.h"
#include "vector"
#include "matplotlibcpp.h"
std::vector<double> x_data,recv1_i,recv1_q;
pthread_mutex_t lock;
void get_rx_data(sdr_transfer *trans){
pthread_mutex_lock(&lock);
recv1_i.clear();
recv1_q.clear();
for(int i = 0; i < trans->length / trans->channels; i++){
recv1_i.push_back(trans->data[(2 * trans->channels) * i]);
recv1_q.push_back(trans->data[(2 * trans->channels) * i + 1]);
}
pthread_mutex_unlock(&lock);
}
namespace plt = matplotlibcpp;
int main() {
antsdrDevice device;
if(device.open() < 0){
return -1;
}
device.set_tx_samprate(3e6);
device.set_tx_freq(1e9);
//if(device.set_tx_attenuation(50))
device.start_tx(1 << 0);
device.set_rx_samprate(3e6);
device.set_rx_freq(1e9);
device.set_rx_gain(50, 1);
device.start_rx(get_rx_data, 1, NULL, 1024);
auto start_time = std::chrono::high_resolution_clock::now();
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff_time{};
diff_time = end_time - start_time;
for(int i = 0; i < 1024; i++){
x_data.push_back(i);
}
plt::figure_size(900, 300);
while(true){
pthread_mutex_lock(&lock);
diff_time = end_time - start_time;
end_time = std::chrono::high_resolution_clock::now();
if(diff_time.count() > 60){
break;
}
if(x_data.size() == recv1_i.size()){
plt::figure(1);
plt::clf();
plt::plot(x_data, recv1_i, "b");
plt::plot(x_data, recv1_q, "g");
plt::draw();
plt::pause(0.001);
}
pthread_mutex_unlock(&lock);
sleep(1);
}
device.stop_rx();
fprintf(stdout, "Exit Program.\n");
return 0;
}