-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplutocpp.cpp
122 lines (95 loc) · 3.25 KB
/
plutocpp.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//============================================================================
// Name : libiiocpp.cpp
// Author : Turner Titties
// Version :
// Copyright : Your copyright notice
// Description : PlutoSDR Example code from the link below
// URL : https://wiki.analog.com/university/tools/pluto/controlling_the_transceiver_and_transferring_data
//============================================================================
#include <stdio.h>
#include <iostream>
#include "iio.h"
// -- Print I/Q Data --------------------------------------------------------
void print(int16_t i, int16_t q){
//std::cout << "i = " << i << " | " << "q = " << q << std::endl;
// space = include sign
// 4 = 3 digits + sign
// i = integer
printf("i = % 4i", i);
printf(" | q = % 4i\n", q);
}
// -- Receiving data ----------------------------------------------------
//
// Get the RX capture device structure
// Get the IQ input channels
// Enable I and Q channel
// Create the RX buffer
// Fill the buffer
// Process samples
//this is a change
int receive(struct iio_context *ctx)
{
printf("receive reached\n");
struct iio_device *dev;
struct iio_channel *rx0_i, *rx0_q;
struct iio_buffer *rxbuf;
dev = iio_context_find_device(ctx, "cf-ad9361-lpc");
rx0_i = iio_device_find_channel(dev, "voltage0", 0);
rx0_q = iio_device_find_channel(dev, "voltage1", 0);
iio_channel_enable(rx0_i);
iio_channel_enable(rx0_q);
rxbuf = iio_device_create_buffer(dev, 4096, false);
if (!rxbuf) {
perror("Could not create RX buffer");
//shutdown();
}
bool track = false;
while (true) {
if(track == false){
printf("while loop reached\n");
track = true;
}
void *p_dat, *p_end, *t_dat;
ptrdiff_t p_inc;
iio_buffer_refill(rxbuf);
p_inc = iio_buffer_step(rxbuf);
p_end = iio_buffer_end(rxbuf);
for (p_dat = iio_buffer_first(rxbuf, rx0_i); p_dat < p_end; p_dat += p_inc, t_dat += p_inc) {
const int16_t i = ((int16_t*)p_dat)[0]; // Real (I)
const int16_t q = ((int16_t*)p_dat)[1]; // Imag (Q)
/* Process here */
print(i, q);
}
}
iio_buffer_destroy(rxbuf);
printf("receive finished");
}
// -- Controlling the Transceiver -----------------------------------------------------------------------
// The code snippet below is a minimalistic example without error checking. It shows how to control the
// AD936x transceiver via a remote connection.
//
// Create IIO IP Network context. Instead of ip:xxx.xxx.xxx.xxx it'll also accept usb:XX.XX.X
// Get the AD936x PHY device structure
// Set the TX LO frequency (see AD9361 device driver documentation)
// Set RX baseband rate
int main (int argc, char **argv)
{
std::cout << "pluto has compiled" << std::endl;
struct iio_context *ctx;
struct iio_device *phy;
ctx = iio_create_context_from_uri("ip:192.168.2.1");
phy = iio_context_find_device(ctx, "ad9361-phy");
iio_channel_attr_write_longlong(
iio_device_find_channel(phy, "altvoltage0", true),
"frequency",
2400000000); /* RX LO frequency 2.4GHz */
iio_channel_attr_write_longlong(
iio_device_find_channel(phy, "voltage0", false),
"sampling_frequency",
5000000); /* RX baseband rate 5 MSPS */
printf("about to call receive\n");
receive(ctx);
iio_context_destroy(ctx);
printf("context destroyed");
return 0;
}