-
Notifications
You must be signed in to change notification settings - Fork 3
/
pluto.cpp
150 lines (130 loc) · 3.66 KB
/
pluto.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Adalm Pluto Driver
* ==================
* Author: DJ0ABR
*
* (c) DJ0ABR
* www.dj0abr.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* =====================================================================
* the purpose of this driver is to have a very easy to use plattform
* for receiving and transmitting data via the Adalm-Pluto.
*
* This is a stand alone program. It connects to the pluto and handles
* all RX and TX.
* The final data are transfered to/from the application via an UDP port
* Your application itself has nothing to do with the Pluto, it just streams
* the data via UDP
* =====================================================================
*
*/
#include "pluto.h"
char *myIP;
char destIP[20] = {UDP_IPADDRESS};
char plutoid[100] = {PLUTO_ID};
int udpsock = 0;
int udpRXfifo = 0;
int crossbandrepeater = 0;
void udprxfunc(uint8_t *buffer, int len, struct sockaddr_in* fromsock)
{
push_udp_data(buffer,len);
}
void close_program()
{
printf("\nCtrl-C pressed\n");
keeprunning = 0;
}
int main ()
{
int res = 0;
install_signal_handler(close_program);
// read own IP address
if(strlen(destIP) >= 7)
{
myIP = destIP;
}
else
{
// use local IP
myIP = ownIP();
if(myIP == NULL || strlen(myIP) < 7)
{
printf("cannot get own IP adress. Network failure. Exit program\n");
exit(0);
}
}
// overwrite IP from info in config file
char *p = getConfigElement("UDP_IPADDRESS");
if(p && strlen(p) < 20)
{
printf("CONFIG file %s found, read values\n",CONFIGFILE);
strcpy(myIP,p);
}
printf("application IP adress: %s\n",myIP);
// find a pluto connected via USB or Ethernet
// overwrite the pluto_id with infos from a config file
p = getConfigElement("PLUTO_ID");
if(p && strlen(p) < 50)
{
strcpy(plutoid,p);
}
if(*plutoid != 'i')
{
// automatically search a pluto connected via USB
res = pluto_get_USB(plutoid);
if(!res)
{
printf("no Pluto found on USB, exit program\n");
exit(0);
}
}
else
strcpy(pluto_context_name,plutoid);
printf("Pluto IP/USB adress: %s\n",pluto_context_name);
p = getConfigElement("CROSSBANDREPEATER");
if(p && strlen(p) < 10)
{
if(*p == '1')
{
printf("crossband repeater mode: ON\n");
crossbandrepeater = 1;
}
}
udpRXfifo = create_fifo(50, BUFSIZE*4);
UdpRxInit(&udpsock,UDP_RXSAMPLEPORT,udprxfunc,&keeprunning);
printf("App->Pluto: UDP Port: %d\n",UDP_RXSAMPLEPORT);
printf("Pluto->App: UDP Port: %d\n",UDP_TXSAMPLEPORT);
printf("Status messages Port: %d\n",UDP_STATUSPORT);
create_interpolator();
pluto_setup();
printf("Starting RX/TX streaming (press Ctrl+C to cancel)\n");
while (keeprunning)
{
runloop();
}
if (rxbuf) iio_buffer_destroy(rxbuf);
if (txbuf) iio_buffer_destroy(txbuf);
if (rx0_i) iio_channel_disable(rx0_i);
if (rx0_q) iio_channel_disable(rx0_q);
if (tx0_i) iio_channel_disable(tx0_i);
if (tx0_q) iio_channel_disable(tx0_q);
if (ctx) iio_context_destroy(ctx);
destroy_interpolator();
printf("exit program\n");
exit(0);
return 0;
}